Преглед на файлове

fix(productionPlan): 临时计划所属工厂列回显工厂名称而非原始ID

lihaiting преди 3 седмици
родител
ревизия
f25507443a
променени са 1 файла, в които са добавени 59 реда и са изтрити 2 реда
  1. 59 2
      src/views/productionPlan/components/factoryAdd/index.vue

+ 59 - 2
src/views/productionPlan/components/factoryAdd/index.vue

@@ -381,10 +381,10 @@
 
             <template v-slot:factoriesId="{ row, $index }">
               <el-select
+                v-if="!factoriesId"
                 v-model="row.factoriesId"
                 :key="row.factoriesId"
                 @change="(e) => selectFactory(e, row)"
-                :disabled="!!factoriesId"
               >
                 <el-option
                   v-for="item of factoryList"
@@ -393,6 +393,12 @@
                   :value="item.id"
                 ></el-option>
               </el-select>
+              <el-input
+                v-else
+                :value="factoryLabel(row)"
+                style="width: 100%"
+                disabled
+              ></el-input>
             </template>
 
             <!-- <el-table-column label="所属工厂" width="140" align="center" prop="factoriesId">
@@ -937,6 +943,47 @@
         this.$set(row, 'factoriesName', data.name);
       },
 
+      // 所属工厂展示名称,避免下拉匹配不到时露出原始ID
+      factoryLabel(row) {
+        if (row.factoriesName) {
+          return row.factoriesName;
+        }
+        // 行上没名字时,从工艺路线列表里取(bomRoutingList 会带回工厂名)
+        const routing = (row.routingList || []).find(
+          (item) => String(item.id) === String(row.produceRoutingId)
+        );
+        if (
+          routing &&
+          routing.factoriesName &&
+          (!row.factoriesId ||
+            String(row.factoriesId) === String(routing.factoriesId))
+        ) {
+          return routing.factoriesName;
+        }
+        const hit = this.factoryList.find(
+          (item) => String(item.id) === String(row.factoriesId)
+        );
+        return hit ? hit.name : row.factoriesId || '';
+      },
+
+      // 工艺路线接口(bomRoutingList)会带回 factoriesId/factoriesName,用它补全所属工厂名称
+      applyRoutingFactoryName(row, routing) {
+        if (!row || !routing || !routing.factoriesName) {
+          return;
+        }
+        if (row.factoriesName) {
+          return;
+        }
+        // 行的工厂与工艺路线上的工厂一致时才补,避免显示成别的工厂
+        if (
+          row.factoriesId &&
+          String(row.factoriesId) !== String(routing.factoriesId)
+        ) {
+          return;
+        }
+        this.$set(row, 'factoriesName', routing.factoriesName);
+      },
+
       async getPlannedReleaseRequire(code) {
         parameterGetByCode({ code }).then((res) => {
           if (res) {
@@ -961,6 +1008,7 @@
         this.$set(data, 'productType', '');
         this.$set(data, 'produceRoutingName', item.name);
         this.$set(data, 'produceRoutingId', item.id);
+        this.applyRoutingFactoryName(data, item);
         this.$set(data, 'selectionRowShow', true);
         // this.selectionRowShow = true;
       },
@@ -1102,7 +1150,10 @@
             this.$set(
               productList[index],
               'factoriesName',
-              this.factoryList?.find((f) => f.id === this.factoriesId)?.name
+              productList[index].factoriesName ||
+                this.factoryList?.find(
+                  (f) => String(f.id) === String(this.factoriesId)
+                )?.name
             );
           }
           this.$set(productList[index], 'producedList', list);
@@ -1333,6 +1384,11 @@
             if (arr.length == 0) {
               row.produceRoutingId = '';
             }
+            // 编辑回显时后台不会返回所属工厂名称,用工艺路线上的工厂信息补全
+            const hit = arr.find(
+              (item) => String(item.id) === String(row.produceRoutingId)
+            );
+            this.applyRoutingFactoryName(row, hit);
             resolve(arr);
           });
         });
@@ -1353,6 +1409,7 @@
             row.produceVersionName = arr[0].version;
             row.produceRoutingId = arr[0].id;
             row.routingList = arr;
+            this.applyRoutingFactoryName(row, arr[0]);
             if (typeChange) {
               this.$set(this.form.productInfoList[index], 'routingList', arr);
               this.$set(