index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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="120px"
  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. websitGoodsmImport,
  43. materialNormList,
  44. materialNormListExport,
  45. materialNormAdd,
  46. materialNormEdit,
  47. materialNormDetail,
  48. materialNormBatchUpdateStatus
  49. } from '@/api/auxiliaryPriceManagement'
  50. import { materialCategoryTree } from '@/api/auxiliaryMaterialClass'
  51. import { getTypeList } from '@/api/auxiliaryFittings/attachmentProfile'
  52. import { commonTemplateDownload } from '@/api/common.js'
  53. import operation_mixin from '@/components/template/operation_mixin.js'
  54. export default {
  55. components: { TemplatePage },
  56. mixins: [import_mixin, operation_mixin],
  57. data() {
  58. return {
  59. // 表格属性
  60. tableAttributes: {
  61. // 启用勾选列
  62. selectColumn: true
  63. },
  64. // 表格事件
  65. tableEvents: {
  66. 'selection-change': this.selectionChange
  67. },
  68. // 勾选选中行
  69. recordSelected: [],
  70. /** 表单变量 */
  71. formDialogType: 0,
  72. formDialogTitles: ['新增', '编辑'],
  73. formDialog: false,
  74. formData: {
  75. companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  76. convertBitScale: '',
  77. cost: '',
  78. createBy: '',
  79. createTime: '',
  80. goodsBarcodeId: '',
  81. goodsCategoryId: '',
  82. goodsCode: '',
  83. goodsId: '',
  84. goodsImage: '',
  85. goodsName: '',
  86. goodsSalesConvertQty: '',
  87. goodsSalesUnit: '',
  88. goodsSpecification: '',
  89. goodsSpell: '',
  90. goodsStockUnit: '',
  91. goodsType: 'M',
  92. manageWorkerStock: '',
  93. marketPrice: '',
  94. normAmount: '',
  95. normType: '',
  96. outWebsitAmount: '',
  97. outWorkerAmount: '',
  98. parentCategoryId: '',
  99. remark: '',
  100. selfWebsitAmount: '',
  101. selfWorkerAmount: '',
  102. status: 'ON'
  103. },
  104. partsUnitList: [],
  105. materialCategoryTree: [],
  106. formType: 'add',
  107. formVisible: false
  108. }
  109. },
  110. computed: {
  111. // 事件组合
  112. optionsEvensGroup() {
  113. return [
  114. [
  115. [
  116. this.optionsEvensAuth('add', {
  117. click: () => {
  118. this.openForm('add')
  119. }
  120. })
  121. ],
  122. [
  123. this.optionsEvensAuth(['imp', 'template'], {
  124. name: '导入辅材',
  125. click: () => {}
  126. }),
  127. this.optionsEvensAuth('imp', ({ moduleName }) => {
  128. return {
  129. name: moduleName,
  130. render: () => {
  131. return this.importButton(websitGoodsmImport, moduleName)
  132. }
  133. }
  134. }),
  135. this.optionsEvensAuth('template', {
  136. click: () => {
  137. commonTemplateDownload({ name: '辅材模板.xlsx' }, `辅材模板`)
  138. .then(res => {
  139. this.$message({
  140. message: '下载成功',
  141. type: 'success'
  142. })
  143. })
  144. .catch(err => {
  145. this.$message.error('下载失败')
  146. })
  147. }
  148. })
  149. ]
  150. ],
  151. [
  152. [
  153. this.optionsEvensAuth('batchLaunch', {
  154. click: () => {
  155. if (this.recordSelected.length) {
  156. this.setRowStatus('ON')
  157. } else {
  158. this.$message({
  159. type: 'warning',
  160. message: `请先勾选需要设置的数据!`
  161. })
  162. }
  163. }
  164. })
  165. ],
  166. [
  167. this.optionsEvensAuth('batchRemoval', {
  168. click: () => {
  169. if (this.recordSelected.length) {
  170. this.setRowStatus('OFF')
  171. } else {
  172. this.$message({
  173. type: 'warning',
  174. message: `请先勾选需要设置的数据!`
  175. })
  176. }
  177. }
  178. })
  179. ]
  180. ]
  181. ]
  182. },
  183. // 更多参数
  184. moreParameters() {
  185. return []
  186. },
  187. formItems() {
  188. return [
  189. {
  190. md: 6,
  191. isShow: true,
  192. name: 'el-input',
  193. attributes: { placeholder: '请输入', disabled: true },
  194. formItemAttributes: {
  195. label: '所属商户',
  196. prop: 'companyWechatName',
  197. rules: [...required]
  198. }
  199. },
  200. {
  201. md: 6,
  202. isShow: true,
  203. name: 'el-radio',
  204. options: [
  205. { label: '上架', value: 'ON' },
  206. { label: '下架', value: 'OFF' }
  207. ],
  208. attributes: {},
  209. formItemAttributes: {
  210. label: '状态',
  211. prop: 'status',
  212. rules: [...required]
  213. }
  214. },
  215. {
  216. md: 6,
  217. isShow: true,
  218. name: 'el-cascader',
  219. attributes: {
  220. style: 'width:100%',
  221. placeholder: '请输入',
  222. options: this.materialCategoryTree,
  223. 'show-all-levels': false,
  224. props: { value: 'categoryId', label: 'categoryName', children: 'child', emitPath: false },
  225. clearable: true
  226. },
  227. formItemAttributes: {
  228. label: '选择分类',
  229. prop: 'goodsCategoryId',
  230. rules: [...required]
  231. },
  232. events: {
  233. change: val => {
  234. this.$refs.formRef.validateField(['goodsCategoryId'], (valid, invalidFields, errLabels) => {})
  235. }
  236. }
  237. },
  238. {
  239. md: 6,
  240. isShow: true,
  241. name: 'el-input',
  242. attributes: { placeholder: '请输入' },
  243. formItemAttributes: {
  244. label: '辅材名称',
  245. prop: 'goodsName',
  246. rules: [...required]
  247. }
  248. },
  249. {
  250. md: 6,
  251. isShow: true,
  252. name: 'el-select-add',
  253. labelKey: 'dictValue',
  254. valueKey: 'dictValue',
  255. options: this.partsUnitList,
  256. attributes: { placeholder: '请选择单位', filterable: true, clearable: true },
  257. formItemAttributes: {
  258. label: '单位',
  259. prop: 'goodsStockUnit',
  260. rules: [...required]
  261. },
  262. events: {
  263. change: val => {
  264. this.$refs.formRef.validateField(['goodsStockUnit'], (valid, invalidFields, errLabels) => {})
  265. }
  266. }
  267. },
  268. {
  269. md: 6,
  270. isShow: true,
  271. name: 'el-input',
  272. attributes: { placeholder: '请输入' },
  273. formItemAttributes: {
  274. label: '商品代码',
  275. prop: 'goodsCode',
  276. rules: []
  277. }
  278. },
  279. {
  280. md: 6,
  281. isShow: true,
  282. name: 'el-input',
  283. attributes: { placeholder: '请输入' },
  284. formItemAttributes: {
  285. label: '规格型号',
  286. prop: 'goodsSpecification',
  287. rules: []
  288. }
  289. },
  290. {
  291. md: 6,
  292. isShow: true,
  293. name: 'el-input',
  294. attributes: { placeholder: '请输入', type: 'number' },
  295. formItemAttributes: {
  296. label: '采购价格',
  297. prop: 'cost',
  298. rules: []
  299. }
  300. },
  301. {
  302. md: 6,
  303. isShow: true,
  304. name: 'el-input',
  305. attributes: { placeholder: '请输入', type: 'number' },
  306. formItemAttributes: {
  307. label: '销售价格',
  308. prop: 'marketPrice',
  309. rules: [...required]
  310. }
  311. },
  312. {
  313. md: 6,
  314. isShow: true,
  315. name: 'slot-component',
  316. attributes: { placeholder: '请输入' },
  317. formItemAttributes: {
  318. label: '',
  319. prop: '',
  320. 'label-width': '0px'
  321. },
  322. render: (h, { props, onInput }) => {
  323. var { value } = props
  324. return <div style="color:red">注:销售价格即网点销售给师傅的辅材价格</div>
  325. }
  326. },
  327. {
  328. md: 24,
  329. isShow: true,
  330. name: 'el-input',
  331. attributes: { placeholder: '请输入', type: 'textarea' },
  332. formItemAttributes: {
  333. label: '备注',
  334. prop: 'remark',
  335. rules: []
  336. }
  337. }
  338. ]
  339. }
  340. },
  341. methods: {
  342. // 列表请求函数
  343. getList: materialNormList,
  344. // 列表导出函数
  345. exportList: materialNormListExport,
  346. // 表格列解析渲染数据更改
  347. columnParsing(item, defaultData) {
  348. return defaultData
  349. },
  350. // 监听勾选变化
  351. selectionChange(data) {
  352. this.recordSelected = data
  353. },
  354. operation() {
  355. return this.operationBtn({
  356. edit: {
  357. click: ({ row, index, column }) => {
  358. this.openForm('edit', row.goodsId)
  359. }
  360. }
  361. })
  362. },
  363. openForm(type, id) {
  364. this.$refs.tabPage.addTab({
  365. // 对应显示的模块
  366. activeKey: type,
  367. // 唯一标识
  368. key: type,
  369. // 页签名称
  370. label: { edit: '编辑', add: '新增' }[type],
  371. // 打开时事件
  372. triggerEvent: () => {
  373. this.formCancel()
  374. this.$nextTick(() => {
  375. this.formType = type
  376. this.formVisible = true
  377. Promise.all([
  378. getTypeList({
  379. pageNum: 1,
  380. pageSize: -1,
  381. params: [
  382. { param: 'a.dict_type', compare: '=', value: `ASSIST_UNIT` },
  383. { param: 'a.status', compare: '=', value: 'ON' }
  384. ]
  385. }),
  386. materialCategoryTree({ state: 'ON' })
  387. ]).then(([res1, res2]) => {
  388. this.partsUnitList = res1.data.records
  389. this.materialCategoryTree = res2.data.filter(item => item.child && item.child.length > 0)
  390. this.formDialog = true
  391. })
  392. if (type == 'add') {
  393. this.formDialogType = 0
  394. } else if (type == 'edit') {
  395. this.formDialogType = 1
  396. materialNormDetail({ id }).then(res => {
  397. Object.assign(this.formData, res.data)
  398. })
  399. }
  400. })
  401. },
  402. // 关闭时事件
  403. closeEvent: () => {
  404. this.formCancel()
  405. }
  406. })
  407. },
  408. formCancel() {
  409. this.formVisible = false
  410. this.$refs?.formRef?.resetFields()
  411. this.$data.formData = this.$options.data().formData
  412. },
  413. formConfirm(cancel) {
  414. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  415. if (valid) {
  416. ;[materialNormAdd, materialNormEdit][this.formDialogType]({ ...this.formData, goodsType: 'M' }).then(res => {
  417. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  418. cancel('list')
  419. this.$refs.pageRef.refreshList()
  420. })
  421. }
  422. })
  423. },
  424. setRowStatus(type) {
  425. materialNormBatchUpdateStatus({
  426. ids: this.recordSelected.map(item => item.goodsId).join(','),
  427. stateEnum: type
  428. }).then(res => {
  429. this.$message({ type: 'success', message: `设置成功!` })
  430. this.$refs.pageRef.refreshList()
  431. })
  432. }
  433. }
  434. }
  435. </script>
  436. <style lang="scss" scoped></style>