index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. >
  16. </template-page>
  17. <div v-if="~['add', 'edit'].indexOf(activeKey)">
  18. <div style="box-sizing: border-box; padding: 20px">
  19. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  20. <zj-form-module title="编辑" label-width="180px" :form-data="formData" :form-items="formItems">
  21. </zj-form-module>
  22. <zj-form-module title="添加辅材" label-width="0px" :form-data="formData" :form-items="formItems2">
  23. </zj-form-module>
  24. </zj-form-container>
  25. </div>
  26. <div slot="footer" style="box-sizing: border-box; padding-bottom: 20px; padding-right: 20px; text-align: right">
  27. <el-button size="mini" @click="data.removeTab()">取 消</el-button>
  28. <el-button size="mini" @click="formConfirm(data.removeTab)" type="primary">确 定</el-button>
  29. </div>
  30. <selectGoods
  31. v-if="formVisible"
  32. @close="close"
  33. @confirm="confirm"
  34. :guolvList="(formData.items || []).map(item => item.websitGoodsId)"
  35. />
  36. </div>
  37. </template>
  38. </zj-tab-page>
  39. </template>
  40. <script>
  41. import { newGetList, newGetListExport, getDetail, addMaterial, editMaterial } from '@/api/masterAuxiliaryMaterials'
  42. import selectGoods from './selectGoods.vue'
  43. import TemplatePage from '@/components/template/template-page-1.vue'
  44. import import_mixin from '@/components/template/import_mixin.js'
  45. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  46. import { materialCategoryTree } from '@/api/auxiliaryMaterialClass'
  47. import { getTypeList } from '@/api/auxiliaryFittings/attachmentProfile'
  48. import { commonTemplateDownload } from '@/api/common.js'
  49. import operation_mixin from '@/components/template/operation_mixin.js'
  50. import { downloadFiles } from '@/utils/util'
  51. export default {
  52. components: { TemplatePage, selectGoods },
  53. mixins: [import_mixin, operation_mixin],
  54. data() {
  55. return {
  56. // 表格属性
  57. tableAttributes: {
  58. // 启用勾选列
  59. selectColumn: true
  60. },
  61. // 表格事件
  62. tableEvents: {
  63. 'selection-change': this.selectionChange
  64. },
  65. // 勾选选中行
  66. recordSelected: [],
  67. /** 表单变量 */
  68. formDialogType: 0,
  69. formDialogTitles: ['新增', '编辑'],
  70. formDialog: false,
  71. formData: {
  72. companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  73. goodsCategoryId: '',
  74. companyWechatId: '',
  75. goodsCode: '',
  76. goodsId: '',
  77. goodsName: '',
  78. isSmall: true,
  79. items: [],
  80. remark: '',
  81. salesUnit: '',
  82. status: 'ON'
  83. },
  84. partsUnitList: [],
  85. materialCategoryTree: [],
  86. formType: 'add',
  87. formVisible: false
  88. }
  89. },
  90. computed: {
  91. // 事件组合
  92. optionsEvensGroup() {
  93. return [
  94. [
  95. [
  96. this.optionsEvensAuth('add', {
  97. click: () => {
  98. this.openForm('add')
  99. }
  100. })
  101. ]
  102. ],
  103. [
  104. [
  105. this.optionsEvensAuth('export2', {
  106. click: () => {
  107. this.exportSheet2()
  108. }
  109. })
  110. ]
  111. ]
  112. ]
  113. },
  114. // 更多参数
  115. moreParameters() {
  116. return []
  117. },
  118. formItems() {
  119. return [
  120. {
  121. md: 6,
  122. isShow: true,
  123. name: 'el-radio',
  124. options: [
  125. { label: '上架', value: 'ON' },
  126. { label: '下架', value: 'OFF' }
  127. ],
  128. attributes: {},
  129. formItemAttributes: {
  130. label: '状态',
  131. prop: 'status',
  132. rules: [...required]
  133. }
  134. },
  135. {
  136. md: 6,
  137. isShow: true,
  138. name: 'el-cascader',
  139. attributes: {
  140. style: 'width:100%',
  141. placeholder: '请输入',
  142. options: this.materialCategoryTree,
  143. 'show-all-levels': false,
  144. props: { value: 'categoryId', label: 'categoryName', children: 'child', emitPath: false },
  145. clearable: true
  146. },
  147. formItemAttributes: {
  148. label: '选择分类',
  149. prop: 'goodsCategoryId',
  150. rules: [...required]
  151. }
  152. },
  153. {
  154. md: 6,
  155. isShow: true,
  156. name: 'el-input',
  157. attributes: { placeholder: '请输入' },
  158. formItemAttributes: {
  159. label: '辅材名称',
  160. prop: 'goodsName',
  161. rules: [...required]
  162. }
  163. },
  164. {
  165. md: 6,
  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: 'salesUnit',
  175. rules: [...required]
  176. }
  177. },
  178. {
  179. md: 6,
  180. isShow: true,
  181. name: 'el-input',
  182. attributes: { placeholder: '请输入' },
  183. formItemAttributes: {
  184. label: '辅材代码',
  185. prop: 'goodsCode',
  186. rules: []
  187. }
  188. },
  189. {
  190. md: 6,
  191. isShow: true,
  192. name: 'el-radio',
  193. options: [
  194. { label: '是', value: true },
  195. { label: '否', value: false }
  196. ],
  197. attributes: {},
  198. formItemAttributes: {
  199. label: '是否小件',
  200. prop: 'isSmall',
  201. rules: [...required]
  202. }
  203. },
  204. {
  205. md: 24,
  206. isShow: true,
  207. name: 'el-input',
  208. attributes: { placeholder: '请输入', type: 'textarea', rows: 5 },
  209. formItemAttributes: {
  210. label: '备注',
  211. prop: 'remark',
  212. rules: []
  213. }
  214. }
  215. ]
  216. },
  217. formItems2() {
  218. return [
  219. {
  220. name: 'slot-component',
  221. md: 24,
  222. formItemAttributes: {
  223. 'label-width': '0px',
  224. label: '',
  225. prop: 'items',
  226. rules: [...required]
  227. },
  228. render: (h, { props }) => {
  229. return (
  230. <div>
  231. <div>
  232. <el-button
  233. size="mini"
  234. type="primary"
  235. onClick={() => {
  236. this.formVisible = true
  237. }}
  238. >
  239. 新增
  240. </el-button>
  241. </div>
  242. <zj-table
  243. columns={[
  244. {
  245. columnAttributes: {
  246. label: '大类名称',
  247. prop: 'parentCategoryName'
  248. }
  249. },
  250. {
  251. columnAttributes: {
  252. label: '小类名称',
  253. prop: 'goodsCategoryName'
  254. }
  255. },
  256. {
  257. columnAttributes: {
  258. label: '辅材名称',
  259. prop: 'websitGoodsName'
  260. }
  261. },
  262. {
  263. columnAttributes: {
  264. label: '单位',
  265. prop: 'goodsSalesUnit'
  266. }
  267. },
  268. {
  269. columnAttributes: {
  270. label: '辅材代码',
  271. prop: 'goodsCode'
  272. }
  273. },
  274. {
  275. columnAttributes: {
  276. label: '规格型号',
  277. prop: 'goodsSpecification'
  278. }
  279. },
  280. {
  281. columnAttributes: {
  282. label: '师傅库存',
  283. prop: 'manageWorkerStock'
  284. },
  285. render: (h, { row, column, index }) => {
  286. return <div style="padding: 0 10px">{row.manageWorkerStock}</div>
  287. }
  288. },
  289. {
  290. columnAttributes: {
  291. label: '操作',
  292. prop: ''
  293. },
  294. render: (h, { row, column, index }) => {
  295. return (
  296. <div style="padding: 0 10px">
  297. <el-button
  298. size="mini"
  299. type="text"
  300. onClick={() => {
  301. this.formData.items.splice(index, 1)
  302. }}
  303. >
  304. 删除
  305. </el-button>
  306. </div>
  307. )
  308. }
  309. }
  310. ]}
  311. table-data={this.formData.items || []}
  312. />
  313. </div>
  314. )
  315. }
  316. }
  317. ]
  318. }
  319. },
  320. methods: {
  321. // 列表请求函数
  322. getList: newGetList,
  323. // 列表导出函数
  324. exportList: newGetListExport,
  325. // 表格列解析渲染数据更改
  326. columnParsing(item, defaultData) {
  327. return defaultData
  328. },
  329. // 监听勾选变化
  330. selectionChange(data) {
  331. this.recordSelected = data
  332. },
  333. operation() {
  334. return this.operationBtn({
  335. edit: {
  336. click: ({ row, index, column }) => {
  337. this.openForm('edit', row.goodsId)
  338. }
  339. }
  340. })
  341. },
  342. openForm(type, id) {
  343. this.$refs.tabPage.addTab({
  344. // 对应显示的模块
  345. activeKey: type,
  346. // 唯一标识
  347. key: type,
  348. // 页签名称
  349. label: { edit: '编辑', add: '新增' }[type],
  350. // 打开时事件
  351. triggerEvent: () => {
  352. this.formCancel()
  353. this.$nextTick(() => {
  354. this.formType = type
  355. Promise.all([
  356. getTypeList({
  357. pageNum: 1,
  358. pageSize: -1,
  359. params: [
  360. { param: 'a.dict_type', compare: '=', value: `ASSIST_UNIT` },
  361. { param: 'a.status', compare: '=', value: 'ON' }
  362. ]
  363. }),
  364. materialCategoryTree({ state: 'ON' })
  365. ]).then(([res1, res2]) => {
  366. this.partsUnitList = res1.data.records
  367. this.materialCategoryTree = res2.data.filter(item => item.child && item.child.length > 0)
  368. this.formDialog = true
  369. })
  370. if (type == 'add') {
  371. this.formDialogType = 0
  372. } else if (type == 'edit') {
  373. this.formDialogType = 1
  374. getDetail({ id }).then(res => {
  375. Object.assign(this.formData, res.data)
  376. })
  377. }
  378. })
  379. },
  380. // 关闭时事件
  381. closeEvent: () => {
  382. this.formCancel()
  383. }
  384. })
  385. },
  386. formCancel() {
  387. this.formVisible = false
  388. this.$refs?.formRef?.resetFields()
  389. this.$data.formData = this.$options.data().formData
  390. },
  391. formConfirm(cancel) {
  392. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  393. if (valid) {
  394. ;[addMaterial, editMaterial][this.formDialogType](this.formData).then(res => {
  395. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  396. cancel('list')
  397. this.$refs.pageRef.refreshList()
  398. })
  399. }
  400. })
  401. },
  402. setNumber(val) {
  403. return Number(val.toFixed(2))
  404. },
  405. close() {
  406. this.formVisible = false
  407. },
  408. confirm(data) {
  409. data
  410. .filter(val => !~this.formData.items.map(item => item.websitGoodsId).indexOf(val.goodsId))
  411. .map(item => {
  412. this.formData.items.push({
  413. goodsCategoryId: item.goodsCategoryId,
  414. goodsCategoryName: item.categoryName,
  415. goodsCode: item.goodsCode,
  416. goodsSalesUnit: item.goodsStockUnit,
  417. goodsSpecification: item.goodsSpecification,
  418. parentCategoryId: item.parentCategoryId,
  419. parentCategoryName: item.parentCategoryName,
  420. websitGoodsId: item.goodsId,
  421. websitGoodsName: item.goodsName,
  422. workerGoodsId: '',
  423. workerGoodsName: '',
  424. manageWorkerStock: { YES: '是', NO: '否' }[item.manageWorkerStock]
  425. })
  426. })
  427. this.close()
  428. },
  429. // 导出
  430. exportSheet2() {
  431. downloadFiles('worker/goods/rela/export', {})
  432. }
  433. }
  434. }
  435. </script>
  436. <style lang="scss" scoped></style>