user-setting-matter-process.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div>
  3. <ele-pro-table
  4. ref="table"
  5. :columns="bankColumns"
  6. :datasource="datasource"
  7. :need-page="false"
  8. class="table_list"
  9. @refresh="getMatterList"
  10. cache-key="user-setting-matter-process-2510181058"
  11. >
  12. <template v-slot:toolbar>
  13. <el-button
  14. size="small"
  15. type="primary"
  16. icon="el-icon-plus"
  17. class="ele-btn-icon"
  18. @click="openAddMatter"
  19. >
  20. 新建
  21. </el-button>
  22. </template>
  23. <!-- 操作列 -->
  24. <template v-slot:action="{ row }">
  25. <el-popconfirm
  26. class="ele-action"
  27. title="确定要删除此事项吗?"
  28. @confirm="delMatter(row)"
  29. >
  30. <template v-slot:reference>
  31. <el-link type="danger" :underline="false" icon="el-icon-delete">
  32. 删除
  33. </el-link>
  34. </template>
  35. </el-popconfirm>
  36. <el-link
  37. type="primary"
  38. :underline="false"
  39. icon="el-icon-view"
  40. @click="openEditMatter(row)"
  41. >
  42. 详情
  43. </el-link>
  44. <el-link
  45. type="primary"
  46. :underline="false"
  47. icon="el-icon-edit"
  48. @click="openEditInfo(row)"
  49. >
  50. 修改
  51. </el-link>
  52. </template>
  53. </ele-pro-table>
  54. <userSettingMatterAdd
  55. ref="userSettingMatterAddRef"
  56. @addMatter="addMatter"
  57. @editMatter="editMatter"
  58. notProduceTaskConfig
  59. />
  60. <ProductModal
  61. ref="ProductModalCorrelationRef"
  62. @changeProduct="changeRelateProduct"
  63. multiple
  64. ></ProductModal>
  65. <permitAdd ref="permitAddRef" @processSave="processSave"></permitAdd>
  66. </div>
  67. </template>
  68. <script>
  69. import {
  70. produceTaskRecordRules,
  71. produceTaskRecordRulesBatchSave,
  72. produceTaskRecordRulesGetById
  73. } from '@/api/producetaskrecordrules';
  74. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  75. import dictMixins from '@/mixins/dictMixins';
  76. import userSettingMatterAdd from './user-setting-matter-add.vue';
  77. import { mapGetters } from 'vuex';
  78. import { getTreeByPid } from '@/api/classifyManage';
  79. import ProductModal from '@/components/selectProduct/ProductModal.vue';
  80. import permitAdd from '@/views/rulesManagement/releaseRules/components/permitAdd.vue';
  81. export default {
  82. name: 'UserSettingMatter',
  83. mixins: [dictMixins, tableColumnsMixin],
  84. components: { userSettingMatterAdd, ProductModal, permitAdd },
  85. props: {
  86. // 工序id
  87. produceTaskId: {
  88. type: String,
  89. required: true
  90. },
  91. // 工序名称
  92. produceTaskName: {
  93. type: String,
  94. required: true
  95. },
  96. // 工序code
  97. produceTaskCode: {
  98. type: String,
  99. required: false,
  100. default: ''
  101. },
  102. bomCategoryId: {
  103. type: String,
  104. required: true
  105. }
  106. },
  107. watch: {
  108. produceTaskId: {
  109. immediate: true,
  110. handler() {
  111. if (this.produceTaskId) {
  112. this.getMatterList();
  113. }
  114. }
  115. },
  116. bomCategoryId: {
  117. immediate: true,
  118. handler() {
  119. if (this.bomCategoryId) {
  120. this.getMatterList();
  121. }
  122. }
  123. }
  124. },
  125. data() {
  126. return {
  127. // 记录规则报工类型 产前、过程、产后
  128. reportWorkType: '2',
  129. // 事项列表
  130. matterList: [],
  131. // 表格列
  132. bankColumns: [
  133. {
  134. columnKey: 'index',
  135. type: 'index',
  136. width: 45,
  137. align: 'center'
  138. },
  139. {
  140. prop: 'itemType',
  141. label: '类型',
  142. align: 'center',
  143. formatter: (row) => {
  144. return this.getDictValue('记录规则事项类型', row.itemType);
  145. }
  146. },
  147. {
  148. prop: 'executeMethod',
  149. label: '执行方式',
  150. align: 'center',
  151. formatter: (row) => {
  152. return this.getDictValue('记录规则执行方式', row.executeMethod);
  153. }
  154. },
  155. {
  156. prop: 'rulesName',
  157. label: '名称',
  158. align: 'center',
  159. formatter: (row) => {
  160. return row.rulesName || row.itemTaskName;
  161. }
  162. },
  163. {
  164. columnKey: 'action',
  165. label: '操作',
  166. align: 'center',
  167. slot: 'action'
  168. }
  169. ],
  170. // 添加事项列表
  171. addPOs: [],
  172. deletedIds: [],
  173. updatePOs: [],
  174. butLoading: false,
  175. relateProductMethod: null,
  176. params: {
  177. categoryLevels: [],
  178. products: []
  179. },
  180. relateProductMethodOpeions: [
  181. { label: '不关联', value: 0 },
  182. { label: '关联分类', value: 1 },
  183. { label: '关联产品', value: 2 }
  184. ],
  185. // 产品分类
  186. productCategory: [],
  187. currentEditRow: null
  188. };
  189. },
  190. computed: {
  191. ...mapGetters(['dict']),
  192. // 根据报工类型过滤事项
  193. datasource() {
  194. return this.matterList.filter(
  195. (item) => item.reportWorkType == this.reportWorkType
  196. );
  197. },
  198. tabPaneList() {
  199. const list = this.dict['record_rules_report_work_type'] || [];
  200. // 只显示过程监测
  201. return list.filter((item) => item.dictCode + '' == '2');
  202. },
  203. productColumns() {
  204. return [
  205. {
  206. columnKey: 'index',
  207. type: 'index',
  208. width: 45,
  209. align: 'center',
  210. reserveSelection: true
  211. },
  212. {
  213. prop: 'code',
  214. label: '产品编码'
  215. },
  216. {
  217. prop: 'name',
  218. label: '产品名称',
  219. showOverflowTooltip: true
  220. },
  221. {
  222. prop: 'brandNum',
  223. label: '牌号'
  224. },
  225. {
  226. prop: 'modelType',
  227. label: '型号'
  228. },
  229. {
  230. prop: 'measuringUnit',
  231. label: '计量单位'
  232. },
  233. {
  234. prop: 'packingUnit',
  235. label: '包装单位'
  236. },
  237. {
  238. columnKey: 'action',
  239. label: '操作',
  240. width: 110,
  241. align: 'center',
  242. resizable: false,
  243. slot: 'action',
  244. fixed: 'right'
  245. }
  246. ];
  247. }
  248. },
  249. created() {
  250. this.getProductCategory();
  251. },
  252. methods: {
  253. // 获取产品分类
  254. async getProductCategory() {
  255. let { data } = await getTreeByPid(9);
  256. console.log('产品分类', data);
  257. this.productCategory = data;
  258. },
  259. // 查询事项数据
  260. async getMatterList() {
  261. const { list } = await produceTaskRecordRules({
  262. // 工序id
  263. produceTaskId: this.produceTaskId,
  264. bomCategoryId: this.bomCategoryId,
  265. pageNum: 1,
  266. size: 9999,
  267. reportWorkType: this.reportWorkType
  268. });
  269. // 表格数据
  270. this.matterList = list.map((i) => {
  271. if (!i.produceTaskConfigRuleDetails.length) {
  272. i.produceTaskConfigRuleDetails = Object.values(
  273. i.produceTaskConfigRuleDetailMap
  274. ).flat();
  275. }
  276. return i;
  277. });
  278. console.log('list', this.matterList);
  279. },
  280. // 删除事项
  281. async delMatter(row) {
  282. if (row.isUsing) {
  283. return this.$message.warning('事项正在使用中,无法删除');
  284. }
  285. // 事项列表过滤
  286. this.matterList = this.matterList.filter((item) => item.id !== row.id);
  287. // 如果是临时id,直接前端删除
  288. if (row.id.includes('tem')) {
  289. this.addPOs = this.addPOs.filter((item) => item.id !== row.id);
  290. } else {
  291. this.deletedIds.push(row.id);
  292. }
  293. // updatePOs 过滤
  294. this.updatePOs = this.updatePOs.filter((item) => item.id !== row.id);
  295. },
  296. // 打开添加事项
  297. openAddMatter() {
  298. this.$refs.userSettingMatterAddRef.openAdd(
  299. this.reportWorkType,
  300. this.produceTaskId
  301. );
  302. },
  303. openEditMatter(row) {
  304. this.$refs.userSettingMatterAddRef.openEdit(row);
  305. },
  306. addMatter(matter, rules) {
  307. const id = 'tem' + new Date().getTime();
  308. console.log('matter', matter, rules);
  309. if (matter.itemType == '2') {
  310. // 判断是否存在
  311. const exists = this.matterList.some(
  312. (item) => item.rulesId === matter.rulesId
  313. );
  314. if (exists) {
  315. return this.$message.warning('规则已存在,请勿重复添加');
  316. }
  317. }
  318. // 处理detials
  319. if (rules && rules.isExecuteMethod) {
  320. matter.produceTaskConfigRuleDetails = Object.values(
  321. rules.detailMap
  322. ).flat();
  323. } else {
  324. matter.produceTaskConfigRuleDetails = rules?.details || [];
  325. }
  326. // 添加事项
  327. this.matterList.push({
  328. ...matter,
  329. id: id,
  330. produceTaskId: this.produceTaskId,
  331. produceTaskName: this.produceTaskName,
  332. reportWorkType: this.reportWorkType
  333. });
  334. this.addPOs.push({
  335. ...matter,
  336. id: id,
  337. produceTaskId: this.produceTaskId,
  338. produceTaskName: this.produceTaskName,
  339. reportWorkType: this.reportWorkType
  340. });
  341. console.log('this.matterList', this.matterList);
  342. this.handleSort();
  343. },
  344. editMatter(matter) {
  345. console.log('matter', matter);
  346. // 编辑事项
  347. this.matterList = this.matterList.map((item) => {
  348. if (item.id === matter.id) {
  349. return {
  350. ...item,
  351. ...matter
  352. };
  353. }
  354. return item;
  355. });
  356. // 如果不是临时id,加入updatePOs
  357. if (!matter.id.includes('tem')) {
  358. // 先过滤掉之前的
  359. this.updatePOs = this.updatePOs.filter(
  360. (item) => item.id !== matter.id
  361. );
  362. this.updatePOs.push({
  363. ...matter
  364. });
  365. } else {
  366. // 如果是临时id,直接更新addPOs
  367. this.addPOs = this.addPOs.map((item) => {
  368. if (item.id === matter.id) {
  369. return {
  370. ...item,
  371. ...matter
  372. };
  373. }
  374. return item;
  375. });
  376. }
  377. this.handleSort();
  378. },
  379. // 事项排序 根据matterList的顺序
  380. handleSort() {
  381. this.matterList = this.matterList.map((item, index) => {
  382. item.sortNum = index;
  383. return item;
  384. });
  385. this.addPOs = this.addPOs.map((item) => {
  386. const matter = this.matterList.find((m) => m.id === item.id);
  387. if (matter) {
  388. return {
  389. ...item,
  390. sortNum: matter.sortNum
  391. };
  392. }
  393. return item;
  394. });
  395. this.updatePOs = this.updatePOs.map((item) => {
  396. const matter = this.matterList.find((m) => m.id === item.id);
  397. if (matter) {
  398. return {
  399. ...item,
  400. sortNum: matter.sortNum
  401. };
  402. }
  403. return item;
  404. });
  405. },
  406. // 确定保存事项
  407. async saveMatterList() {
  408. console.log('this.matterList', this.matterList);
  409. try {
  410. this.butLoading = true;
  411. await produceTaskRecordRulesBatchSave({
  412. addPOs: this.addPOs.map((i) => {
  413. return {
  414. ...i,
  415. id: null,
  416. bomCategoryId: this.bomCategoryId
  417. };
  418. }),
  419. deletedIds: this.deletedIds,
  420. updatePOs: this.updatePOs.map((i) => {
  421. return {
  422. ...i,
  423. bomCategoryId: this.bomCategoryId
  424. };
  425. })
  426. });
  427. this.handleClose();
  428. this.butLoading = false;
  429. } catch (error) {
  430. this.butLoading = false;
  431. }
  432. },
  433. // 关闭弹窗、清空数据
  434. handleClose() {
  435. this.getMatterList();
  436. this.addPOs = [];
  437. this.deletedIds = [];
  438. this.updatePOs = [];
  439. this.butLoading = false;
  440. this.reportWorkType = '2';
  441. },
  442. // 关联产品
  443. relateProductSelect() {
  444. this.$refs.ProductModalCorrelationRef.open(this.params.products);
  445. },
  446. changeRelateProduct(array) {
  447. console.log('paroduct list ', array);
  448. this.params.products = [
  449. ...this.params.products,
  450. ...array.filter(
  451. (i) => !this.params.products.some((cat) => cat.id === i.id)
  452. )
  453. ];
  454. },
  455. openEditInfo(row) {
  456. console.log('row', row);
  457. this.currentEditRow = row;
  458. this.$refs.permitAddRef.open(row, 'processEdit', '修改记录规则');
  459. },
  460. processSave(info) {
  461. console.log('info', info);
  462. info.details = info.details.map((i) => {
  463. if (!i.rulesId) {
  464. i.rulesId = this.currentEditRow.rulesId;
  465. }
  466. return i;
  467. });
  468. // 更新当前行数据
  469. this.matterList = this.matterList.map((item) => {
  470. if (item.id === this.currentEditRow.id) {
  471. item.produceTaskConfigRuleDetails = info.details;
  472. }
  473. return item;
  474. });
  475. if (!this.currentEditRow.id.includes('tem')) {
  476. // updatePOs 是否存在 当前行
  477. const exists = this.updatePOs.some(
  478. (item) => item.id === this.currentEditRow.id
  479. );
  480. if (!exists) {
  481. // 不存在,加入updatePOs
  482. this.updatePOs.push({
  483. ...this.currentEditRow,
  484. produceTaskConfigRuleDetails: info.details
  485. });
  486. } else {
  487. // 存在,更新
  488. // 更新updatePOs
  489. this.updatePOs = this.updatePOs.map((item) => {
  490. if (item.id === this.currentEditRow.id) {
  491. item.produceTaskConfigRuleDetails = info.details;
  492. }
  493. return item;
  494. });
  495. }
  496. } else {
  497. // 更新addPOs
  498. this.addPOs = this.addPOs.map((item) => {
  499. if (item.id === this.currentEditRow.id) {
  500. item.produceTaskConfigRuleDetails = info.details;
  501. }
  502. return item;
  503. });
  504. }
  505. }
  506. }
  507. };
  508. </script>
  509. <style scoped></style>