index.vue 15 KB

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