user-setting-matter-process.vue 11 KB

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