user-setting-matter-process.vue 12 KB

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