index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <template>
  2. <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title + '-列表', essential: true }]">
  3. <template slot-scope="{ activeKey, data }">
  4. <template-page
  5. v-if="activeKey == 'list'"
  6. ref="pageRef"
  7. :get-list="getList"
  8. :table-attributes="tableAttributes"
  9. :table-events="tableEvents"
  10. :options-evens-group="optionsEvensGroup"
  11. :moreParameters="moreParameters"
  12. :column-parsing="columnParsing"
  13. :operation="operation()"
  14. :exportList="exportList"
  15. :operationColumnWidth="80"
  16. >
  17. </template-page>
  18. <div v-if="~['add', 'edit'].indexOf(activeKey)">
  19. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  20. <zj-form-module
  21. title=""
  22. label-width="180px"
  23. :showPackUp="false"
  24. :form-data="formData"
  25. :form-items="formItems"
  26. >
  27. </zj-form-module>
  28. </zj-form-container>
  29. <div slot="footer" class="dialog-footer">
  30. <el-button size="mini" @click="data.removeTab()">取 消</el-button>
  31. <el-button size="mini" @click="formConfirm(data.removeTab)" type="primary">确 定</el-button>
  32. </div>
  33. </div>
  34. </template>
  35. </zj-tab-page>
  36. </template>
  37. <script>
  38. import TemplatePage from '@/components/template/template-page-1.vue'
  39. import import_mixin from '@/components/template/import_mixin.js'
  40. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  41. import {
  42. materialNormList,
  43. materialNormListExport,
  44. materialNormAdd,
  45. materialNormEdit,
  46. materialNormDetail,
  47. materialNormBatchUpdateStatus,
  48. materialNormImport2,
  49. materialNormImport
  50. } from '@/api/auxiliaryChargeManagement'
  51. import { materialCategoryTree } from '@/api/auxiliaryMaterialClass'
  52. import { getTypeList } from '@/api/auxiliaryFittings/attachmentProfile'
  53. import { commonTemplateDownload } from '@/api/common.js'
  54. import operation_mixin from '@/components/template/operation_mixin.js'
  55. export default {
  56. components: { TemplatePage },
  57. mixins: [import_mixin, operation_mixin],
  58. data() {
  59. return {
  60. // 表格属性
  61. tableAttributes: {
  62. // 启用勾选列
  63. selectColumn: true
  64. },
  65. // 表格事件
  66. tableEvents: {
  67. 'selection-change': this.selectionChange
  68. },
  69. // 勾选选中行
  70. recordSelected: [],
  71. /** 表单变量 */
  72. formDialogType: 0,
  73. formDialogTitles: ['新增', '编辑'],
  74. formDialog: false,
  75. formData: {
  76. companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  77. categoryId: '',
  78. companyWechatId: '',
  79. createBy: '',
  80. createTime: '',
  81. normAmount: 0,
  82. normCode: '',
  83. normId: '',
  84. normName: '',
  85. normType: '',
  86. outWebsitAmount: 0,
  87. outWorkerAmount: 0,
  88. parentCategoryId: '',
  89. remark: '',
  90. selfWebsitAmount: 0,
  91. selfWorkerAmount: 0,
  92. specification: '',
  93. status: 'ON',
  94. unit: '',
  95. manualAmount: 0
  96. },
  97. partsUnitList: [],
  98. materialCategoryTree: [],
  99. formType: 'add',
  100. formVisible: false
  101. }
  102. },
  103. computed: {
  104. // 事件组合
  105. optionsEvensGroup() {
  106. return [
  107. [
  108. [
  109. this.optionsEvensAuth('add', {
  110. click: () => {
  111. this.openForm('add')
  112. }
  113. })
  114. ],
  115. [
  116. this.optionsEvensAuth(['imp', 'template'], {
  117. name: '导入物料',
  118. click: () => {}
  119. }),
  120. this.optionsEvensAuth('imp', ({ moduleName }) => {
  121. return {
  122. name: moduleName,
  123. render: () => {
  124. return this.importButton(materialNormImport, moduleName)
  125. }
  126. }
  127. }),
  128. this.optionsEvensAuth('template', {
  129. click: () => {
  130. commonTemplateDownload({ name: '辅材收费标准模板(物料收费).xlsx' }, `辅材收费标准模板(物料收费)`)
  131. .then(res => {
  132. this.$message({
  133. message: '下载成功',
  134. type: 'success'
  135. })
  136. })
  137. .catch(err => {
  138. this.$message.error('下载失败')
  139. })
  140. }
  141. })
  142. ],
  143. [
  144. this.optionsEvensAuth(['Import', 'downloadTemplate'], {
  145. name: '导入服务',
  146. click: () => {}
  147. }),
  148. this.optionsEvensAuth('Import', ({ moduleName }) => {
  149. return {
  150. name: moduleName,
  151. render: () => {
  152. return this.importButton(materialNormImport2, moduleName)
  153. }
  154. }
  155. }),
  156. this.optionsEvensAuth('downloadTemplate', {
  157. click: () => {
  158. commonTemplateDownload({ name: '辅材收费标准模板(服务收费).xlsx' }, `辅材收费标准模板(服务收费)`)
  159. .then(res => {
  160. this.$message({
  161. message: '下载成功',
  162. type: 'success'
  163. })
  164. })
  165. .catch(err => {
  166. this.$message.error('下载失败')
  167. })
  168. }
  169. })
  170. ]
  171. ],
  172. [
  173. [
  174. this.optionsEvensAuth('batchLaunch', {
  175. click: () => {
  176. if (this.recordSelected.length) {
  177. this.setRowStatus('ON')
  178. } else {
  179. this.$message({
  180. type: 'warning',
  181. message: `请先勾选需要设置的数据!`
  182. })
  183. }
  184. }
  185. })
  186. ],
  187. [
  188. this.optionsEvensAuth('batchRemoval', {
  189. click: () => {
  190. if (this.recordSelected.length) {
  191. this.setRowStatus('OFF')
  192. } else {
  193. this.$message({
  194. type: 'warning',
  195. message: `请先勾选需要设置的数据!`
  196. })
  197. }
  198. }
  199. })
  200. ]
  201. ]
  202. ]
  203. },
  204. // 更多参数
  205. moreParameters() {
  206. return []
  207. },
  208. formItems() {
  209. return [
  210. {
  211. md: 6,
  212. isShow: true,
  213. name: 'el-input',
  214. attributes: { placeholder: '请输入', disabled: true },
  215. formItemAttributes: {
  216. label: '所属商户',
  217. prop: 'companyWechatName',
  218. rules: [...required]
  219. }
  220. },
  221. {
  222. md: 6,
  223. isShow: true,
  224. name: 'el-radio',
  225. options: [
  226. { label: '上架', value: 'ON' },
  227. { label: '下架', value: 'OFF' }
  228. ],
  229. attributes: {},
  230. formItemAttributes: {
  231. label: '状态',
  232. prop: 'status',
  233. rules: [...required]
  234. }
  235. },
  236. {
  237. md: 6,
  238. isShow: true,
  239. name: 'el-cascader',
  240. attributes: {
  241. style: 'width:100%',
  242. placeholder: '请输入',
  243. options: this.materialCategoryTree,
  244. 'show-all-levels': false,
  245. props: { value: 'categoryId', label: 'categoryName', children: 'child', emitPath: false },
  246. clearable: true
  247. },
  248. formItemAttributes: {
  249. label: '选择分类',
  250. prop: 'categoryId',
  251. rules: [...required]
  252. }
  253. },
  254. {
  255. md: 6,
  256. isShow: true,
  257. name: 'el-input',
  258. attributes: { placeholder: '请输入' },
  259. formItemAttributes: {
  260. label: '辅材名称',
  261. prop: 'normName',
  262. rules: [...required]
  263. }
  264. },
  265. {
  266. md: 6,
  267. isShow: true,
  268. name: 'el-select-add',
  269. labelKey: 'dictValue',
  270. valueKey: 'dictValue',
  271. options: this.partsUnitList,
  272. attributes: { placeholder: '请选择单位', filterable: true, clearable: true },
  273. formItemAttributes: {
  274. label: '单位',
  275. prop: 'unit',
  276. rules: [...required]
  277. }
  278. },
  279. {
  280. md: 6,
  281. isShow: true,
  282. name: 'el-input',
  283. attributes: { placeholder: '请输入' },
  284. formItemAttributes: {
  285. label: '商品代码',
  286. prop: 'normCode',
  287. rules: []
  288. }
  289. },
  290. {
  291. md: 6,
  292. isShow: true,
  293. name: 'el-input',
  294. attributes: { placeholder: '请输入' },
  295. formItemAttributes: {
  296. label: '规格型号',
  297. prop: 'specification',
  298. rules: []
  299. }
  300. },
  301. {
  302. md: 6,
  303. isShow: true,
  304. name: 'el-radio',
  305. options: [
  306. { label: '物料收费', value: 'M' },
  307. { label: '服务收费', value: 'S' }
  308. ],
  309. attributes: {},
  310. formItemAttributes: {
  311. label: '收费类型',
  312. prop: 'normType',
  313. rules: [...required]
  314. }
  315. },
  316. {
  317. md: 6,
  318. isShow: true,
  319. name: 'el-input',
  320. attributes: { placeholder: '请输入', type: 'number' },
  321. formItemAttributes: {
  322. label: '收费标准',
  323. prop: 'normAmount',
  324. rules: [...required]
  325. },
  326. events: {
  327. input: val => {
  328. this.formData.selfWorkerAmount = ''
  329. this.formData.outWorkerAmount = ''
  330. this.$nextTick(() => {
  331. this.formData.selfWebsitAmount = this.setNumber(
  332. this.formData.normAmount - (this.formData.selfWorkerAmount || 0)
  333. )
  334. this.formData.outWebsitAmount = this.setNumber(
  335. this.formData.normAmount - (this.formData.outWorkerAmount || 0)
  336. )
  337. })
  338. }
  339. }
  340. },
  341. {
  342. md: 6,
  343. isShow: true,
  344. name: 'slot-component',
  345. attributes: { placeholder: '请输入' },
  346. formItemAttributes: {
  347. label: '',
  348. prop: '',
  349. 'label-width': '0px'
  350. },
  351. render: (h, { props, onInput }) => {
  352. var { value } = props
  353. return <div style="color:red">注:分账金额需扣除手续费0.6%</div>
  354. }
  355. },
  356. {
  357. md: 6,
  358. isShow: true,
  359. name: 'el-input',
  360. attributes: { placeholder: '请输入', type: 'number', disabled: !this.formData.normAmount },
  361. formItemAttributes: {
  362. label: '自有库存师傅(分账金额)',
  363. prop: 'selfWorkerAmount',
  364. rules: [...required]
  365. },
  366. events: {
  367. input: val => {
  368. if (Number(val) > this.formData.normAmount) {
  369. this.formData.selfWorkerAmount = this.setNumber(this.formData.normAmount)
  370. }
  371. this.formData.selfWebsitAmount = this.setNumber(this.formData.normAmount - this.formData.selfWorkerAmount)
  372. }
  373. },
  374. slots: {
  375. append: (h, { props, onInput }) => {
  376. return <div>元</div>
  377. }
  378. }
  379. },
  380. {
  381. md: 6,
  382. isShow: true,
  383. name: 'el-input',
  384. attributes: { placeholder: '请输入', type: 'number', disabled: !this.formData.normAmount },
  385. formItemAttributes: {
  386. label: '外购辅材师傅(分账金额)',
  387. prop: 'outWorkerAmount',
  388. rules: [...required]
  389. },
  390. events: {
  391. input: val => {
  392. if (Number(val) > this.formData.normAmount) {
  393. this.formData.outWorkerAmount = this.setNumber(this.formData.normAmount)
  394. }
  395. this.formData.outWebsitAmount = this.setNumber(this.formData.normAmount - this.formData.outWorkerAmount)
  396. }
  397. },
  398. slots: {
  399. append: (h, { props, onInput }) => {
  400. return <div>元</div>
  401. }
  402. }
  403. },
  404. {
  405. md: 6,
  406. isShow: true,
  407. name: 'el-input',
  408. attributes: { placeholder: '请输入', disabled: true, type: 'number' },
  409. formItemAttributes: {
  410. label: '自有库存商户(分账金额)',
  411. prop: 'selfWebsitAmount',
  412. rules: [...required]
  413. },
  414. slots: {
  415. append: (h, { props, onInput }) => {
  416. return <div>元</div>
  417. }
  418. }
  419. },
  420. {
  421. md: 6,
  422. isShow: true,
  423. name: 'el-input',
  424. attributes: { placeholder: '请输入', disabled: true, type: 'number' },
  425. formItemAttributes: {
  426. label: '外购辅材商户(分账金额)',
  427. prop: 'outWebsitAmount',
  428. rules: [...required]
  429. },
  430. slots: {
  431. append: (h, { props, onInput }) => {
  432. return <div>元</div>
  433. }
  434. }
  435. },
  436. {
  437. md: 6,
  438. isShow: true,
  439. name: 'el-input',
  440. attributes: { placeholder: '请输入', type: 'number' },
  441. formItemAttributes: {
  442. label: '师傅手工费用',
  443. prop: 'manualAmount',
  444. rules: [...required]
  445. }
  446. },
  447. {
  448. md: 24,
  449. isShow: true,
  450. name: 'el-input',
  451. attributes: { placeholder: '请输入', type: 'textarea', rows: 5 },
  452. formItemAttributes: {
  453. label: '备注',
  454. prop: 'remark',
  455. rules: []
  456. }
  457. }
  458. ]
  459. }
  460. },
  461. methods: {
  462. // 列表请求函数
  463. getList: materialNormList,
  464. // 列表导出函数
  465. exportList: materialNormListExport,
  466. // 表格列解析渲染数据更改
  467. columnParsing(item, defaultData) {
  468. return defaultData
  469. },
  470. // 监听勾选变化
  471. selectionChange(data) {
  472. this.recordSelected = data
  473. },
  474. operation() {
  475. return this.operationBtn({
  476. edit: {
  477. click: ({ row, index, column }) => {
  478. this.openForm('edit', row.normId)
  479. }
  480. }
  481. })
  482. },
  483. openForm() {},
  484. openForm(type, id) {
  485. this.$refs.tabPage.addTab({
  486. // 对应显示的模块
  487. activeKey: type,
  488. // 唯一标识
  489. key: type,
  490. // 页签名称
  491. label: { edit: '编辑', add: '新增' }[type],
  492. // 打开时事件
  493. triggerEvent: () => {
  494. this.formCancel()
  495. this.$nextTick(() => {
  496. this.formType = type
  497. this.formVisible = true
  498. Promise.all([
  499. getTypeList({
  500. pageNum: 1,
  501. pageSize: -1,
  502. params: [
  503. { param: 'a.dict_type', compare: '=', value: `ASSIST_UNIT` },
  504. { param: 'a.status', compare: '=', value: 'ON' }
  505. ]
  506. }),
  507. materialCategoryTree({ state: 'ON' })
  508. ]).then(([res1, res2]) => {
  509. this.partsUnitList = res1.data.records
  510. this.materialCategoryTree = res2.data.filter(item => item.child && item.child.length > 0)
  511. this.formDialog = true
  512. })
  513. if (type == 'add') {
  514. this.formDialogType = 0
  515. } else if (type == 'edit') {
  516. this.formDialogType = 1
  517. materialNormDetail({ id }).then(res => {
  518. Object.assign(this.formData, res.data)
  519. })
  520. }
  521. })
  522. },
  523. // 关闭时事件
  524. closeEvent: () => {
  525. this.formCancel()
  526. }
  527. })
  528. },
  529. formCancel() {
  530. this.formVisible = false
  531. this.$refs?.formRef?.resetFields()
  532. this.$data.formData = this.$options.data().formData
  533. },
  534. formConfirm(cancel) {
  535. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  536. if (valid) {
  537. ;[materialNormAdd, materialNormEdit][this.formDialogType](this.formData).then(res => {
  538. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  539. cancel('list')
  540. this.$refs.pageRef.refreshList()
  541. })
  542. }
  543. })
  544. },
  545. setRowStatus(type) {
  546. materialNormBatchUpdateStatus({
  547. ids: this.recordSelected.map(item => item.normId).join(','),
  548. stateEnum: type
  549. }).then(res => {
  550. this.$message({ type: 'success', message: `设置成功!` })
  551. this.$refs.pageRef.refreshList()
  552. })
  553. },
  554. setNumber(val) {
  555. return Number(val.toFixed(2))
  556. }
  557. }
  558. }
  559. </script>
  560. <style lang="scss" scoped></style>