processModal.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="70%"
  10. >
  11. <el-card shadow="never">
  12. <user-search @search="reload" />
  13. <!-- 数据表格 -->
  14. <ele-pro-table
  15. ref="table"
  16. :columns="columns"
  17. :datasource="datasource"
  18. :selection.sync="selection"
  19. @cell-click="cellClick"
  20. row-key="id"
  21. >
  22. <!-- 表头工具栏 -->
  23. <template v-slot:action="{ row }">
  24. <el-radio
  25. :disabled="
  26. selectWorkingProcess.taskParam.some((item) => item.id == row.id)
  27. "
  28. class="radio"
  29. v-model="radio"
  30. :label="row.id"
  31. ><i></i
  32. ></el-radio>
  33. </template>
  34. </ele-pro-table>
  35. </el-card>
  36. <div class="btns">
  37. <el-button type="primary" size="small" @click="selected">选择</el-button>
  38. <el-button size="small" @click="handleClose">关闭</el-button>
  39. </div>
  40. </el-dialog>
  41. </template>
  42. <script>
  43. import {
  44. workingProcedureSave,
  45. workingProcedureUpdate
  46. } from '@/api/material/BOM';
  47. import producetask from '@/api/technology/production';
  48. import userSearch from './user-search.vue';
  49. export default {
  50. components: {
  51. userSearch
  52. },
  53. data() {
  54. return {
  55. visible: false,
  56. title: '添加工序',
  57. type: '新增',
  58. // 表格列配置
  59. columns: [
  60. {
  61. prop: 'code',
  62. label: '工序编码',
  63. // sortable: 'custom',
  64. showOverflowTooltip: true,
  65. align: 'center',
  66. minWidth: 110
  67. },
  68. {
  69. prop: 'name',
  70. label: '工序名称',
  71. showOverflowTooltip: true,
  72. align: 'center',
  73. minWidth: 110
  74. },
  75. {
  76. align: 'center',
  77. prop: 'controlName',
  78. label: '工序控制码',
  79. showOverflowTooltip: true,
  80. minWidth: 110
  81. },
  82. {
  83. prop: 'workCenterName',
  84. label: '所属工作中心',
  85. align: 'center',
  86. showOverflowTooltip: true,
  87. minWidth: 110
  88. }
  89. ],
  90. // 表格选中数据
  91. selection: [],
  92. processData: {},
  93. selectWorkingProcess: {},
  94. currentRow: {},
  95. current: {},
  96. radio: null,
  97. id: null
  98. };
  99. },
  100. methods: {
  101. /* 表格数据源 */
  102. async datasource({ page, limit, where, order }) {
  103. const res = await parameter.list({
  104. ...where,
  105. ...order,
  106. pageNum: page,
  107. size: limit
  108. });
  109. return res;
  110. },
  111. initColumns() {
  112. this.columns = [
  113. {
  114. prop: 'code',
  115. label: '工序编码',
  116. // sortable: 'custom',
  117. showOverflowTooltip: true,
  118. align: 'center',
  119. minWidth: 110
  120. },
  121. {
  122. prop: 'name',
  123. label: '工序名称',
  124. showOverflowTooltip: true,
  125. align: 'center',
  126. minWidth: 110
  127. },
  128. {
  129. align: 'center',
  130. prop: 'controlName',
  131. label: '工序控制码',
  132. showOverflowTooltip: true,
  133. minWidth: 110
  134. },
  135. {
  136. prop: 'workCenterName',
  137. label: '所属工作中心',
  138. align: 'center',
  139. showOverflowTooltip: true,
  140. minWidth: 110
  141. }
  142. ];
  143. },
  144. open(item, selectWorkingProcess, type, currentRow) {
  145. this.type = type;
  146. this.selectWorkingProcess = selectWorkingProcess;
  147. this.currentRow = currentRow;
  148. this.processData = item;
  149. this.initColumns();
  150. this.current = {};
  151. this.radio = null;
  152. if (type === '新增') {
  153. this.columns = [
  154. {
  155. columnKey: 'selection',
  156. type: 'selection',
  157. width: 45,
  158. align: 'center',
  159. selectable: (row, index) => {
  160. return !this.selectWorkingProcess.taskParam.some(
  161. (item) => item.id == row.id
  162. );
  163. },
  164. reserveSelection: true,
  165. fixed: 'left'
  166. }
  167. ].concat(this.columns);
  168. } else {
  169. this.columns = [
  170. {
  171. action: 'action',
  172. slot: 'action',
  173. align: 'center',
  174. label: '选择'
  175. }
  176. ].concat(this.columns);
  177. }
  178. this.visible = true;
  179. },
  180. // 单击获取id
  181. cellClick(row) {
  182. if (
  183. !this.selectWorkingProcess.taskParam.some((item) => item.id == row.id)
  184. ) {
  185. this.current = row;
  186. this.radio = row.id;
  187. }
  188. },
  189. /* 表格数据源 */
  190. async datasource({ page, limit, where, order }) {
  191. const res = await producetask.list({
  192. ...where,
  193. ...order,
  194. pageNum: page,
  195. size: limit
  196. });
  197. return res;
  198. },
  199. /* 刷新表格 */
  200. reload(where) {
  201. this.$refs.table.reload({ page: 1, where: where });
  202. },
  203. handleClose() {
  204. this.visible = false;
  205. this.$refs.table.setSelectedRows([]);
  206. this.selection = [];
  207. },
  208. selected() {
  209. if (this.type === '新增') {
  210. if (!this.selection.length) {
  211. this.$message.error('请至少选择一条数据');
  212. return;
  213. }
  214. } else {
  215. if (!this.current) {
  216. this.$message.error('请至少选择一条数据');
  217. return;
  218. }
  219. }
  220. if (this.selectWorkingProcess.taskParam.length > 0) {
  221. let taskParam = [];
  222. if (this.type === '新增') {
  223. taskParam = this.selection
  224. .map((item) => {
  225. return {
  226. ...item,
  227. versions: this.processData.versions,
  228. status: this.processData.status
  229. };
  230. })
  231. .concat(this.selectWorkingProcess.taskParam);
  232. } else {
  233. taskParam = this.selectWorkingProcess.taskParam.map((item) => {
  234. if (item.id === this.currentRow.id) {
  235. return {
  236. ...this.current,
  237. versions: this.processData.versions,
  238. status: this.processData.status
  239. };
  240. } else {
  241. return item;
  242. }
  243. });
  244. }
  245. workingProcedureUpdate({
  246. id: this.selectWorkingProcess.id,
  247. categoryId: this.processData.categoryId,
  248. bomCategoryId: this.processData.id,
  249. categoryCode: this.processData.categoryCode,
  250. taskParam
  251. }).then((data) => {
  252. this.$message.success('添加成功');
  253. this.$emit('chooseProcess');
  254. this.handleClose();
  255. });
  256. } else {
  257. workingProcedureSave({
  258. categoryId: this.processData.categoryId,
  259. bomCategoryId: this.processData.id,
  260. categoryCode: this.processData.categoryCode,
  261. taskParam: this.selection.map((item) => {
  262. return {
  263. ...item,
  264. versions: this.processData.versions,
  265. status: this.processData.status
  266. };
  267. })
  268. }).then((data) => {
  269. this.$message.success('添加成功');
  270. this.$emit('chooseProcess');
  271. this.handleClose();
  272. });
  273. }
  274. }
  275. }
  276. };
  277. </script>
  278. <style lang="scss" scoped>
  279. .btns {
  280. text-align: center;
  281. padding: 10px 0;
  282. }
  283. </style>