user-setting-matter-process.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. <ele-pro-table
  23. ref="table"
  24. :columns="bankColumns"
  25. :datasource="datasource"
  26. :need-page="false"
  27. class="table_list"
  28. >
  29. <template v-slot:toolbar>
  30. <el-button
  31. size="small"
  32. type="primary"
  33. icon="el-icon-plus"
  34. class="ele-btn-icon"
  35. @click="openAddMatter"
  36. >
  37. 新建
  38. </el-button>
  39. </template>
  40. <!-- 操作列 -->
  41. <template v-slot:action="{ row }">
  42. <el-popconfirm
  43. class="ele-action"
  44. title="确定要删除此事项吗?"
  45. @confirm="delMatter(row)"
  46. >
  47. <template v-slot:reference>
  48. <el-link type="danger" :underline="false" icon="el-icon-delete">
  49. 删除
  50. </el-link>
  51. </template>
  52. </el-popconfirm>
  53. <el-link
  54. type="primary"
  55. :underline="false"
  56. icon="el-icon-edit"
  57. @click="openEditMatter(row)"
  58. >
  59. 详情
  60. </el-link>
  61. </template>
  62. </ele-pro-table>
  63. <template v-slot:footer>
  64. <el-button type="primary" @click="saveMatterList" :loading="butLoading">
  65. 确定
  66. </el-button>
  67. <el-button @click="handleClose">取消</el-button>
  68. </template>
  69. <userSettingMatterAdd
  70. ref="userSettingMatterAddRef"
  71. @addMatter="addMatter"
  72. @editMatter="editMatter"
  73. />
  74. </ele-modal>
  75. </template>
  76. <script>
  77. import {
  78. produceTaskRecordRules,
  79. produceTaskRecordRulesBatchSave
  80. } from '@/api/producetaskrecordrules';
  81. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  82. import dictMixins from '@/mixins/dictMixins';
  83. import userSettingMatterAdd from './user-setting-matter-add.vue';
  84. import { mapGetters } from 'vuex';
  85. import { addMaterial } from '@/api/material/list';
  86. export default {
  87. name: 'UserSettingMatter',
  88. mixins: [dictMixins, tableColumnsMixin],
  89. components: { userSettingMatterAdd },
  90. data() {
  91. return {
  92. visible: false,
  93. // 记录规则报工类型 产前、过程、产后
  94. reportWorkType: '2',
  95. // 事项列表
  96. matterList: [],
  97. // 表格列
  98. bankColumns: [
  99. {
  100. columnKey: 'index',
  101. type: 'index',
  102. width: 45,
  103. align: 'center'
  104. },
  105. {
  106. prop: 'itemType',
  107. label: '类型',
  108. align: 'center',
  109. formatter: (row) => {
  110. return this.getDictValue('记录规则事项类型', row.itemType);
  111. }
  112. },
  113. {
  114. prop: 'executeMethod',
  115. label: '执行方式',
  116. align: 'center',
  117. formatter: (row) => {
  118. return this.getDictValue('记录规则执行方式', row.executeMethod);
  119. }
  120. },
  121. {
  122. prop: 'rulesName',
  123. label: '名称',
  124. align: 'center',
  125. formatter: (row) => {
  126. return row.rulesName || row.itemTaskName;
  127. }
  128. },
  129. {
  130. columnKey: 'action',
  131. label: '操作',
  132. align: 'center',
  133. slot: 'action'
  134. }
  135. ],
  136. // 当前行数据
  137. currentRow: null,
  138. // 添加事项列表
  139. addPOs: [],
  140. deletedIds: [],
  141. updatePOs: [],
  142. butLoading: false
  143. };
  144. },
  145. computed: {
  146. ...mapGetters(['dict']),
  147. // 根据报工类型过滤事项
  148. datasource() {
  149. return this.matterList.filter(
  150. (item) => item.reportWorkType == this.reportWorkType
  151. );
  152. },
  153. tabPaneList() {
  154. const list = this.dict['record_rules_report_work_type'] || [];
  155. // 只显示过程监测
  156. return list.filter((item) => item.dictCode + '' == '2');
  157. }
  158. },
  159. created() {},
  160. methods: {
  161. updateVisible(val) {
  162. this.visible = val;
  163. },
  164. openSetting(row) {
  165. console.log('row', row);
  166. this.currentRow = row;
  167. this.visible = true;
  168. this.getMatterList(row);
  169. },
  170. // 查询事项数据
  171. async getMatterList() {
  172. const { list } = await produceTaskRecordRules({
  173. produceTaskId: this.currentRow.id,
  174. pageNum: 1,
  175. size: 9999
  176. // reportWorkType: this.reportWorkType
  177. });
  178. console.log('list', list);
  179. // 表格数据
  180. this.matterList = list;
  181. },
  182. // 删除事项
  183. async delMatter(row) {
  184. if (row.isUsing) {
  185. return this.$message.warning('事项正在使用中,无法删除');
  186. }
  187. // 事项列表过滤
  188. this.matterList = this.matterList.filter((item) => item.id !== row.id);
  189. // 如果是临时id,直接前端删除
  190. if (row.id.includes('tem')) {
  191. this.addPOs = this.addPOs.filter((item) => item.id !== row.id);
  192. } else {
  193. this.deletedIds.push(row.id);
  194. }
  195. // updatePOs 过滤
  196. this.updatePOs = this.updatePOs.filter((item) => item.id !== row.id);
  197. },
  198. // 打开添加事项
  199. openAddMatter() {
  200. this.$refs.userSettingMatterAddRef.openAdd();
  201. },
  202. openEditMatter(row) {
  203. this.$refs.userSettingMatterAddRef.openEdit(row);
  204. },
  205. addMatter(matter) {
  206. console.log('matter', matter);
  207. const id = 'tem' + new Date().getTime();
  208. // 添加事项
  209. this.matterList.push({
  210. ...matter,
  211. id: id,
  212. produceTaskId: this.currentRow.id,
  213. produceTaskName: this.currentRow.name,
  214. reportWorkType: this.reportWorkType
  215. });
  216. this.addPOs.push({
  217. ...matter,
  218. id: id,
  219. produceTaskId: this.currentRow.id,
  220. produceTaskName: this.currentRow.name,
  221. reportWorkType: this.reportWorkType
  222. });
  223. this.handleSort();
  224. },
  225. editMatter(matter) {
  226. console.log('matter', matter);
  227. // 编辑事项
  228. this.matterList = this.matterList.map((item) => {
  229. if (item.id === matter.id) {
  230. return {
  231. ...item,
  232. ...matter
  233. };
  234. }
  235. return item;
  236. });
  237. // 如果不是临时id,加入updatePOs
  238. if (!matter.id.includes('tem')) {
  239. // 先过滤掉之前的
  240. this.updatePOs = this.updatePOs.filter(
  241. (item) => item.id !== matter.id
  242. );
  243. this.updatePOs.push({
  244. ...matter,
  245. produceTaskId: this.currentRow.id,
  246. produceTaskName: this.currentRow.name,
  247. reportWorkType: this.reportWorkType
  248. });
  249. } else {
  250. // 如果是临时id,直接更新addPOs
  251. this.addPOs = this.addPOs.map((item) => {
  252. if (item.id === matter.id) {
  253. return {
  254. ...item,
  255. ...matter
  256. };
  257. }
  258. return item;
  259. });
  260. }
  261. this.handleSort();
  262. },
  263. // 事项排序 根据matterList的顺序
  264. handleSort() {
  265. this.matterList = this.matterList.map((item, index) => {
  266. item.sortNum = index;
  267. return item;
  268. });
  269. this.addPOs = this.addPOs.map((item) => {
  270. const matter = this.matterList.find((m) => m.id === item.id);
  271. if (matter) {
  272. return {
  273. ...item,
  274. sortNum: matter.sortNum
  275. };
  276. }
  277. return item;
  278. });
  279. this.updatePOs = this.updatePOs.map((item) => {
  280. const matter = this.matterList.find((m) => m.id === item.id);
  281. if (matter) {
  282. return {
  283. ...item,
  284. sortNum: matter.sortNum
  285. };
  286. }
  287. return item;
  288. });
  289. },
  290. // 确定保存事项
  291. async saveMatterList() {
  292. console.log('this.matterList', this.matterList);
  293. try {
  294. this.butLoading = true;
  295. await produceTaskRecordRulesBatchSave({
  296. addPOs: this.addPOs,
  297. deletedIds: this.deletedIds,
  298. produceTaskId: this.currentRow.id,
  299. produceTaskName: this.currentRow.name,
  300. updatePOs: this.updatePOs
  301. });
  302. this.$message.success('保存成功');
  303. this.handleClose();
  304. this.butLoading = false;
  305. } catch (error) {
  306. this.butLoading = false;
  307. }
  308. },
  309. // 关闭弹窗、清空数据
  310. handleClose() {
  311. this.visible = false;
  312. this.matterList = [];
  313. this.addPOs = [];
  314. this.deletedIds = [];
  315. this.updatePOs = [];
  316. this.butLoading = false;
  317. this.reportWorkType = '2';
  318. }
  319. }
  320. };
  321. </script>
  322. <style scoped></style>