user-setting-matter-process.vue 14 KB

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