Browse Source

feat: 支持多选工序,更新任务ID处理逻辑

xieyong 1 month ago
parent
commit
e7825eb1a1
1 changed files with 35 additions and 9 deletions
  1. 35 9
      src/views/entrust/components/create.vue

+ 35 - 9
src/views/entrust/components/create.vue

@@ -231,12 +231,13 @@
           </el-input>
         </template>
 
-        <template v-slot:taskId="{ row, $index }">
+        <template v-slot:taskIds="{ row, $index }">
           <el-select
             clearable
+            multiple
             filterable
             style="width: 100%"
-            v-model="row.taskId"
+            v-model="row.taskIds"
             placeholder="请选择"
             @change="taskListChange(row, $index)"
             :disabled="type == 'detail'"
@@ -566,8 +567,8 @@
             }
           },
           {
-            prop: 'taskId',
-            slot: 'taskId',
+            prop: 'taskIds',
+            slot: 'taskIds',
             label: '工序',
             align: 'center',
             minWidth: 150,
@@ -732,6 +733,9 @@
             taskList: []
           };
 
+          // 后端 taskIds 是逗号分隔的字符串,多选 el-select 需要数组才能正常显示
+          newData.taskIds = this.parseTaskIdsToArray(newData.taskIds);
+
           this.orderList.push(newData);
 
           await this.getOrderTaskList();
@@ -801,6 +805,7 @@
             describes: '',
             totalCount: copy.formingNum,
             taskList: [],
+            taskIds: [], // 多选数组,空数组保证 el-select multiple 正常绑定
             beEntrustedFactoriesId: '',
             beEntrustedFactoriesName: '',
             status: '',
@@ -842,8 +847,11 @@
 
           let { list } = res;
           if (list.length) {
+            // 过滤掉 taskId == -2 的项;下拉项是单条任务,字段是 taskId
             list = list.filter((it) => it.taskId != -2);
-            let arr = list.findIndex((it) => it.id == item.taskId);
+            // row.taskIds 现在是数组,查找第一个被选中的索引
+            const ids = Array.isArray(item.taskIds) ? item.taskIds : [];
+            let arr = list.findIndex((it) => ids.includes(it.id));
 
             if (arr != -1) {
               list.splice(0, arr);
@@ -870,10 +878,22 @@
         }, result);
       },
 
-      taskListChange(item, index) {
-        const data = item.taskList.filter((it) => it.id == item.taskId);
+      // 后端 taskIds 是逗号分隔字符串,转成数组供 el-select multiple 使用
+      parseTaskIdsToArray(value) {
+        if (Array.isArray(value)) return value;
+        if (typeof value === 'string' && value.trim()) {
+          return value.split(',').filter(Boolean);
+        }
+        return [];
+      },
 
-        this.orderList[index].taskName = data[0].name;
+      taskListChange(item, index) {
+        // item.taskIds 是数组,遍历得到所有选中工序的名称
+        const ids = Array.isArray(item.taskIds) ? item.taskIds : [];
+        const names = item.taskList
+          .filter((it) => ids.includes(it.id))
+          .map((it) => it.name);
+        this.orderList[index].taskName = names.join('、');
       },
 
       save(type) {
@@ -891,7 +911,8 @@
               return this.$message.warning('请托数量不能为空');
             }
 
-            if (!item.taskId) {
+            const ids = Array.isArray(item.taskIds) ? item.taskIds : [];
+            if (ids.length === 0) {
               return this.$message.warning('工序不能为空');
             }
 
@@ -951,6 +972,11 @@
             item.type = formType;
             item.status = status;
             item.approvalStatus = item.approvalStatus ?? (type == 1 ? 0 : 1);
+            // 后端要求 taskIds 是逗号分隔字符串,多选数组 → 字符串
+            if (Array.isArray(item.taskIds)) {
+              item.taskIds = item.taskIds.join(',');
+              item.taskIdList = this.parseTaskIdsToArray(item.taskIds);
+            }
           });
           let URL;