index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
  3. :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters" :column-parsing="columnParsing"
  4. :operation="operation" :exportList="exportList">
  5. <el-dialog title="" width="860px" custom-class="diy-dialog" append-to-body :modal="true" :visible.sync="formDialog"
  6. :show-close="true" :close-on-click-modal="false" :modal-append-to-body="false" :before-close="formCancel">
  7. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  8. <zj-form-module :title="formDialogTitles[formDialogType]" label-width="120px" :showPackUp="false"
  9. :form-data="formData" :form-items="formItems">
  10. </zj-form-module>
  11. </zj-form-container>
  12. <div slot="footer" class="dialog-footer">
  13. <el-button size="mini" @click="formCancel">取 消</el-button>
  14. <el-button size="mini" @click="formConfirm" type="primary">确 定</el-button>
  15. </div>
  16. </el-dialog>
  17. </template-page>
  18. </template>
  19. <script>
  20. import TemplatePage from '@/components/template/template-page-1.vue'
  21. import import_mixin from '@/components/template/import_mixin.js'
  22. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  23. import { materialNormList, materialNormListExport, materialNormAdd, materialNormEdit, materialNormDetail, materialNormBatchUpdateStatus } from "@/api/auxiliaryChargeManagement";
  24. import { materialCategoryTree } from "@/api/auxiliaryMaterialClass";
  25. import { getTypeList } from "@/api/auxiliaryFittings/attachmentProfile";
  26. export default {
  27. components: { TemplatePage },
  28. mixins: [import_mixin],
  29. data() {
  30. return {
  31. // 事件组合
  32. optionsEvensGroup: [
  33. [
  34. [
  35. {
  36. name: '新建',
  37. isRole: true,
  38. click: this.addData
  39. }
  40. ],
  41. ],
  42. [
  43. [
  44. {
  45. name: '批量上架',
  46. isRole: true,
  47. click: () => {
  48. if (this.recordSelected.length) {
  49. this.setRowStatus("ON")
  50. } else {
  51. this.$message({
  52. type: 'warning',
  53. message: `请先勾选需要设置的数据!`,
  54. });
  55. }
  56. }
  57. }
  58. ],
  59. [
  60. {
  61. name: '批量下架',
  62. isRole: true,
  63. click: () => {
  64. if (this.recordSelected.length) {
  65. this.setRowStatus("OFF")
  66. } else {
  67. this.$message({
  68. type: 'warning',
  69. message: `请先勾选需要设置的数据!`,
  70. });
  71. }
  72. }
  73. }
  74. ],
  75. ],
  76. ],
  77. // 表格属性
  78. tableAttributes: {
  79. // 启用勾选列
  80. selectColumn: true
  81. },
  82. // 表格事件
  83. tableEvents: {
  84. 'selection-change': this.selectionChange
  85. },
  86. // 勾选选中行
  87. recordSelected: [],
  88. /** 表单变量 */
  89. formDialogType: 0,
  90. formDialogTitles: ["新增", "编辑"],
  91. formDialog: false,
  92. formData: {
  93. companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  94. "categoryId": "",
  95. "companyWechatId": "",
  96. "createBy": "",
  97. "createTime": "",
  98. "normAmount": 0,
  99. "normCode": "",
  100. "normId": "",
  101. "normName": "",
  102. "normType": "",
  103. "outWebsitAmount": 0,
  104. "outWorkerAmount": 0,
  105. "parentCategoryId": "",
  106. "remark": "",
  107. "selfWebsitAmount": 0,
  108. "selfWorkerAmount": 0,
  109. "specification": "",
  110. "status": "ON",
  111. "unit": "",
  112. },
  113. partsUnitList: [],
  114. materialCategoryTree: []
  115. }
  116. },
  117. computed: {
  118. // 更多参数
  119. moreParameters() {
  120. return []
  121. },
  122. formItems() {
  123. return [{
  124. md: 12,
  125. isShow: true,
  126. name: 'el-input',
  127. attributes: { placeholder: '请输入', disabled: true },
  128. formItemAttributes: {
  129. label: '所属商户',
  130. prop: 'companyWechatName',
  131. rules: [...required]
  132. }
  133. }, {
  134. md: 12,
  135. isShow: true,
  136. name: 'el-radio',
  137. options: [{ label: "上架", value: "ON" }, { label: "下架", value: "OFF" }],
  138. attributes: {},
  139. formItemAttributes: {
  140. label: '状态',
  141. prop: 'status',
  142. rules: [...required]
  143. },
  144. }, {
  145. md: 12,
  146. isShow: true,
  147. name: 'el-cascader',
  148. attributes: { style: "width:100%", placeholder: '请输入', options: this.materialCategoryTree, 'show-all-levels': false, props: { value: "categoryId", label: "categoryName", children: "child", emitPath: false }, clearable: true },
  149. formItemAttributes: {
  150. label: '选择分类',
  151. prop: 'categoryId',
  152. rules: [...required]
  153. }
  154. }, {
  155. md: 12,
  156. isShow: true,
  157. name: 'el-input',
  158. attributes: { placeholder: '请输入' },
  159. formItemAttributes: {
  160. label: '辅材名称',
  161. prop: 'normName',
  162. rules: [...required]
  163. }
  164. }, {
  165. md: 12,
  166. isShow: true,
  167. name: 'el-select-add',
  168. labelKey: 'dictValue',
  169. valueKey: 'dictValue',
  170. options: this.partsUnitList,
  171. attributes: { placeholder: '请选择单位', filterable: true, clearable: true },
  172. formItemAttributes: {
  173. label: '单位',
  174. prop: 'unit',
  175. rules: [...required]
  176. }
  177. }, {
  178. md: 12,
  179. isShow: true,
  180. name: 'el-input',
  181. attributes: { placeholder: '请输入' },
  182. formItemAttributes: {
  183. label: '商品代码',
  184. prop: 'normCode',
  185. rules: []
  186. }
  187. }, {
  188. md: 12,
  189. isShow: true,
  190. name: 'el-input',
  191. attributes: { placeholder: '请输入' },
  192. formItemAttributes: {
  193. label: '规格型号',
  194. prop: 'specification',
  195. rules: []
  196. }
  197. }, {
  198. md: 12,
  199. isShow: true,
  200. name: 'el-radio',
  201. options: [{ label: "物料收费", value: "M" }, { label: "服务收费", value: "S" }],
  202. attributes: {},
  203. formItemAttributes: {
  204. label: '收费类型',
  205. prop: 'normType',
  206. rules: [...required]
  207. },
  208. }, {
  209. md: 12,
  210. isShow: true,
  211. name: 'el-input',
  212. attributes: { placeholder: '请输入', type: "number" },
  213. formItemAttributes: {
  214. label: '收费标准',
  215. prop: 'normAmount',
  216. rules: [...required]
  217. },
  218. events: {
  219. input: (val) => {
  220. this.formData.selfWorkerAmount = ""
  221. this.formData.outWorkerAmount = ""
  222. this.$nextTick(() => {
  223. this.formData.selfWebsitAmount = this.setNumber(
  224. this.formData.normAmount - (this.formData.selfWorkerAmount || 0)
  225. )
  226. this.formData.outWebsitAmount = this.setNumber(
  227. this.formData.normAmount - (this.formData.outWorkerAmount || 0)
  228. )
  229. })
  230. }
  231. },
  232. }, {
  233. md: 12,
  234. isShow: true,
  235. name: 'slot-component',
  236. attributes: { placeholder: '请输入' },
  237. formItemAttributes: {
  238. label: '',
  239. prop: '',
  240. 'label-width': "0px"
  241. },
  242. render: (h, { props, onInput }) => {
  243. var { value } = props
  244. return (
  245. <div style="color:red">注:分账金额需扣除手续费0.6%</div>
  246. )
  247. }
  248. }, {
  249. md: 12,
  250. isShow: true,
  251. name: 'el-input',
  252. attributes: { placeholder: '请输入', type: "number", disabled: !this.formData.normAmount, },
  253. formItemAttributes: {
  254. label: '自有库存师傅(分账金额)',
  255. prop: 'selfWorkerAmount',
  256. rules: [...required]
  257. },
  258. events: {
  259. input: (val) => {
  260. if (Number(val) > this.formData.normAmount) {
  261. this.formData.selfWorkerAmount = this.setNumber(
  262. this.formData.normAmount
  263. )
  264. }
  265. this.formData.selfWebsitAmount = this.setNumber(
  266. this.formData.normAmount - this.formData.selfWorkerAmount
  267. )
  268. }
  269. },
  270. slots: {
  271. append: (h, { props, onInput }) => {
  272. return <div>元</div>
  273. }
  274. }
  275. }, {
  276. md: 12,
  277. isShow: true,
  278. name: 'el-input',
  279. attributes: { placeholder: '请输入', type: "number", disabled: !this.formData.normAmount, },
  280. formItemAttributes: {
  281. label: '外购辅材师傅(分账金额)',
  282. prop: 'outWorkerAmount',
  283. rules: [...required]
  284. },
  285. events: {
  286. input: (val) => {
  287. if (Number(val) > this.formData.normAmount) {
  288. this.formData.outWorkerAmount = this.setNumber(
  289. this.formData.normAmount
  290. )
  291. }
  292. this.formData.outWebsitAmount = this.setNumber(
  293. this.formData.normAmount - this.formData.outWorkerAmount
  294. )
  295. }
  296. },
  297. slots: {
  298. append: (h, { props, onInput }) => {
  299. return <div>元</div>
  300. }
  301. }
  302. }, {
  303. md: 12,
  304. isShow: true,
  305. name: 'el-input',
  306. attributes: { placeholder: '请输入', disabled: true, type: "number", },
  307. formItemAttributes: {
  308. label: '自有库存网点(分账金额)',
  309. prop: 'selfWebsitAmount',
  310. rules: [...required]
  311. },
  312. slots: {
  313. append: (h, { props, onInput }) => {
  314. return <div>元</div>
  315. }
  316. }
  317. }, {
  318. md: 12,
  319. isShow: true,
  320. name: 'el-input',
  321. attributes: { placeholder: '请输入', disabled: true, type: "number", },
  322. formItemAttributes: {
  323. label: '外购辅材网点(分账金额)',
  324. prop: 'outWebsitAmount',
  325. rules: [...required]
  326. },
  327. slots: {
  328. append: (h, { props, onInput }) => {
  329. return <div>元</div>
  330. }
  331. }
  332. }, {
  333. md: 24,
  334. isShow: true,
  335. name: 'el-input',
  336. attributes: { placeholder: '请输入', type: "textarea" },
  337. formItemAttributes: {
  338. label: '备注',
  339. prop: 'remark',
  340. rules: []
  341. }
  342. }]
  343. }
  344. },
  345. methods: {
  346. // 列表请求函数
  347. getList: materialNormList,
  348. // 列表导出函数
  349. exportList: materialNormListExport,
  350. // 表格列解析渲染数据更改
  351. columnParsing(item, defaultData) {
  352. return defaultData
  353. },
  354. // 监听勾选变化
  355. selectionChange(data) {
  356. this.recordSelected = data
  357. },
  358. // 表格操作列
  359. operation(h, { row, index, column }) {
  360. return (
  361. <div class='operation-btns'>
  362. <el-button type="text" onClick={() => {
  363. materialNormDetail({ id: row.normId }).then(res => {
  364. Object.assign(this.formData, res.data)
  365. this.formDialogType = 1
  366. this.openForm()
  367. })
  368. }}>编辑</el-button>
  369. </div>
  370. )
  371. },
  372. addData() {
  373. this.formDialogType = 0
  374. this.openForm()
  375. },
  376. openForm() {
  377. Promise.all([
  378. getTypeList({ "pageNum": 1, "pageSize": -1, "params": [{ "param": "a.dict_type", "compare": "=", "value": `PARTS_UNIT` }, { "param": "a.status", "compare": "=", "value": "ON" }] }),
  379. materialCategoryTree()
  380. ]).then(([res1, res2]) => {
  381. this.partsUnitList = res1.data.records
  382. this.materialCategoryTree = res2.data.filter(item => (item.child && item.child.length > 0))
  383. this.formDialog = true;
  384. })
  385. },
  386. formCancel() {
  387. this.$refs.formRef.$refs.inlineForm.clearValidate()
  388. this.$data.formData = this.$options.data().formData
  389. this.formDialog = false
  390. },
  391. formConfirm() {
  392. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  393. if (valid) {
  394. ([materialNormAdd, materialNormEdit][this.formDialogType])(this.formData).then(res => {
  395. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  396. this.formCancel()
  397. this.$refs.pageRef.refreshList()
  398. })
  399. }
  400. })
  401. },
  402. setRowStatus(type) {
  403. materialNormBatchUpdateStatus({
  404. ids: this.recordSelected.map(item => item.normId).join(','),
  405. stateEnum: type
  406. }).then(res => {
  407. this.$message({ type: 'success', message: `设置成功!` })
  408. this.$refs.pageRef.refreshList()
  409. })
  410. },
  411. setNumber(val) {
  412. return Number(val.toFixed(2))
  413. }
  414. }
  415. }
  416. </script>
  417. <style lang="scss" scoped></style>