瀏覽代碼

fix:720【销售订单】客户期望交期、生产交付交期、有效期需要设置成必填项

mlchen 1 天之前
父節點
當前提交
69ac6aa6ea
共有 1 個文件被更改,包括 224 次插入 和 22 次删除
  1. 224 22
      src/views/warehouseManagement/stockManagement/add.vue

+ 224 - 22
src/views/warehouseManagement/stockManagement/add.vue

@@ -156,6 +156,7 @@
           >
             <ele-pro-table
               ref="table"
+              :key="'productTable' + formData.bizType"
               :columns="columns"
               :datasource="productList"
               :needPage="false"
@@ -212,6 +213,12 @@
               <template v-slot:headerBatchNo="{ column }">
                 <span class="is-required">{{ column.label }}</span>
               </template>
+              <template v-slot:headerDetailProductionDate="{ column }">
+                <span class="required-star">{{ column.label }}</span>
+              </template>
+              <template v-slot:headerDetailExpireDate="{ column }">
+                <span class="required-star">{{ column.label }}</span>
+              </template>
               <template v-slot:batchNo="{ row, $index }">
                 <template v-if="row.isSave">
                   {{ row.batchNo }}
@@ -433,16 +440,21 @@
                 <template v-if="row.isSave">
                   {{ row.detailProductionDate }}
                 </template>
-                <el-date-picker
+                <el-form-item
                   v-else
-                  :disabled="row.isPack"
-                  size="small"
-                  v-model="row.detailProductionDate"
-                  type="datetime"
-                  value-format="yyyy-MM-dd HH:mm:ss"
-                  placeholder="选择日期"
+                  :prop="`productList.${$index}.detailProductionDate`"
+                  :required="isProductionInbound"
                 >
-                </el-date-picker>
+                  <el-date-picker
+                    :disabled="row.isPack"
+                    size="small"
+                    v-model="row.detailProductionDate"
+                    type="datetime"
+                    value-format="yyyy-MM-dd HH:mm:ss"
+                    placeholder="选择日期"
+                  >
+                  </el-date-picker>
+                </el-form-item>
               </template>
               <template v-slot:detailPurchaseDate="{ row, $index }">
                 <template v-if="row.isSave">
@@ -463,16 +475,21 @@
                 <template v-if="row.isSave">
                   {{ row.detailExpireDate }}
                 </template>
-                <el-date-picker
+                <el-form-item
                   v-else
-                  :disabled="row.isPack"
-                  size="small"
-                  v-model="row.detailExpireDate"
-                  type="datetime"
-                  value-format="yyyy-MM-dd HH:mm:ss"
-                  placeholder="选择日期"
+                  :prop="`productList.${$index}.detailExpireDate`"
+                  :required="isProductionInbound"
                 >
-                </el-date-picker>
+                  <el-date-picker
+                    :disabled="row.isPack"
+                    size="small"
+                    v-model="row.detailExpireDate"
+                    type="datetime"
+                    value-format="yyyy-MM-dd HH:mm:ss"
+                    placeholder="选择日期"
+                  >
+                  </el-date-picker>
+                </el-form-item>
               </template>
               <template v-slot:action="{ row, $index }">
                 <el-button
@@ -1095,6 +1112,10 @@
       clientEnvironmentId() {
         return this.$store.state.user.info.clientEnvironmentId;
       },
+      // 生产入库(入库类型=1):产品信息行「生产日期」「失效日期」必填
+      isProductionInbound() {
+        return String(this.formData.bizType) === '1';
+      },
       columns() {
         // 当columnsVersion变化时会重新计算
         const version = this.columnsVersion;
@@ -1345,7 +1366,11 @@
             slot: 'detailProductionDate',
             showOverflowTooltip: true,
             width: 220,
-            align: 'center'
+            align: 'center',
+            // 生产入库时该列必填,表头补红星(其它入库类型不注册表头插槽)
+            ...(this.isProductionInbound
+              ? { headerSlot: 'headerDetailProductionDate' }
+              : {})
           },
           {
             label: '采购日期',
@@ -1361,7 +1386,11 @@
             slot: 'detailExpireDate',
             showOverflowTooltip: true,
             width: 220,
-            align: 'center'
+            align: 'center',
+            // 生产入库时该列必填,表头补红星(其它入库类型不注册表头插槽)
+            ...(this.isProductionInbound
+              ? { headerSlot: 'headerDetailExpireDate' }
+              : {})
           },
           {
             columnKey: 'action',
@@ -1381,6 +1410,13 @@
         if (String(newValue) !== '2') {
           this.clearInboundRequestId();
         }
+        // 切换入库类型后清掉上一类型留下的必填标红(只有生产入库校验日期)
+        this.$nextTick(() => {
+          const productForm = this.$refs.productListRef;
+          if (productForm && typeof productForm.clearValidate === 'function') {
+            productForm.clearValidate();
+          }
+        });
       },
       packingList: {
         handler(newVal) {
@@ -2442,6 +2478,18 @@
               this.$message.warning('请先保存所有产品信息');
               return;
             }
+            // 生产入库:入库前生产日期/失效日期必须已填写(含已保存的行)
+            if (this.isProductionInbound) {
+              const dateGroups = this.buildRequiredGroups(
+                null,
+                true,
+                this.dateFileds()
+              );
+              if (dateGroups.length) {
+                this.showRequiredMessage(dateGroups);
+                return;
+              }
+            }
             // 处理包装数据
             this.packingList = this.packingList.map((packingItem) => {
               if (packingItem.modelKey) {
@@ -2898,6 +2946,127 @@
         this.productList = this.productList.concat(productList);
         console.log('this.productList--------', this.productList);
       },
+      // 产品信息行的必填字段(生产入库额外要求生产日期/失效日期)
+      requiredFileds() {
+        const fileds = [
+          {
+            prop: 'batchNo',
+            label: '批次号'
+          },
+          {
+            prop: 'quantity',
+            label: '数量'
+          },
+          {
+            prop: 'unit',
+            label: '单位'
+          },
+          {
+            prop: 'warehouseId',
+            label: '仓库'
+          }
+        ];
+        if (this.isProductionInbound) {
+          fileds.push(...this.dateFileds());
+        }
+        return fileds;
+      },
+      // 生产入库才校验的两个日期字段
+      dateFileds() {
+        return [
+          {
+            prop: 'detailProductionDate',
+            label: '生产日期'
+          },
+          {
+            prop: 'detailExpireDate',
+            label: '失效日期'
+          }
+        ];
+      },
+      // 与 el-form required 同口径:undefined/null/空串算未填,0 算已填
+      isBlank(value) {
+        return value === undefined || value === null || value === '';
+      },
+      // 必填缺项按「行」聚合:一行一条、缺的字段用「、」并列,
+      // 逐字段摊平在几十行明细里看不出到底哪几行缺什么
+      buildRequiredGroups(indexes, includeSaved, fileds) {
+        const rowIndexes =
+          indexes || this.productList.map((item, index) => index);
+        const fieldList = fileds || this.requiredFileds();
+        const groups = [];
+        rowIndexes.forEach((index) => {
+          const row = this.productList[index];
+          if (!row || (!includeSaved && row.isSave)) {
+            return;
+          }
+          const labels = fieldList
+            .filter((item) => this.isBlank(row[item.prop]))
+            .map((item) => item.label);
+          if (labels.length) {
+            groups.push({
+              index,
+              labels,
+              name: row.categoryName || row.categoryCode || '未选择物品'
+            });
+          }
+        });
+        return groups;
+      },
+      escapeHtml(text) {
+        const map = {
+          '&': '&amp;',
+          '<': '&lt;',
+          '>': '&gt;',
+          '"': '&quot;',
+          "'": '&#39;'
+        };
+        return String(text).replace(/[&<>"']/g, (char) => map[char]);
+      },
+      // 必填缺项提示:先给总行数/总项数,再一行一条;超过 3 行只列前 3 行,
+      // 只有一处缺失时退回最短的一句
+      showRequiredMessage(groups) {
+        if (!groups.length) {
+          this.$message.error('请填入必填项!');
+          return;
+        }
+        if (groups.length === 1 && groups[0].labels.length === 1) {
+          const single = groups[0];
+          this.$message.warning(
+            `第${single.index + 1}行 物品「${single.name}」的「${
+              single.labels[0]
+            }」未填写`
+          );
+          return;
+        }
+        const total = groups.reduce(
+          (sum, group) => sum + group.labels.length,
+          0
+        );
+        const maxRows = 3;
+        const lines = groups.slice(0, maxRows).map(
+          (group) =>
+            // 物品名来自业务数据,拼进 HTML 提示前必须转义
+            `第${group.index + 1}行 物品「${this.escapeHtml(
+              group.name
+            )}」:${group.labels.join('、')}`
+        );
+        if (groups.length > maxRows) {
+          lines.push(
+            `另有 ${groups.length - maxRows} 行未填写完整(共 ${
+              groups.length
+            } 行 / ${total} 项)`
+          );
+        }
+        this.$message.warning({
+          dangerouslyUseHTMLString: true,
+          showClose: true,
+          duration: 6000,
+          message: `产品信息共 ${
+            groups.length
+          } 行 ${total} 项必填未填写:<br/>${lines.join('<br/>')}`
+        });
+      },
       // 物品保存验证表单(批量)
       validateForm() {
         return new Promise(async (resolve, reject) => {
@@ -2908,6 +3077,12 @@
               `productList.${index}.unit`,
               `productList.${index}.warehouseId`
             ];
+            if (this.isProductionInbound) {
+              fileds.push(
+                `productList.${index}.detailProductionDate`,
+                `productList.${index}.detailExpireDate`
+              );
+            }
             console.log(fileds);
             if (row.isSave) {
               return Promise.resolve(true);
@@ -2935,8 +3110,13 @@
             })
             .catch((err) => {
               console.log('保存失败!');
-              this.$message.error('请填入必填项!');
-              reject(err);
+              // 必填缺项按行聚合提示(行号 + 物品 + 缺的字段)
+              this.showRequiredMessage(this.buildRequiredGroups());
+              // 已给出必填提示时不再叠加批量保存的兜底文案
+              reject({
+                ...(err && typeof err === 'object' ? err : {}),
+                requiredTips: true
+              });
             });
         });
       },
@@ -2950,6 +3130,12 @@
             `productList.${index}.unit`,
             `productList.${index}.warehouseId`
           ];
+          if (this.isProductionInbound) {
+            fileds.push(
+              `productList.${index}.detailProductionDate`,
+              `productList.${index}.detailExpireDate`
+            );
+          }
           Promise.all(
             fileds.map(
               (item) =>
@@ -2968,7 +3154,8 @@
               resolve();
             })
             .catch(() => {
-              this.$message.error('请填入必填项!');
+              // 必填缺项按行聚合提示(行号 + 物品 + 缺的字段)
+              this.showRequiredMessage(this.buildRequiredGroups([index]));
             });
         });
       },
@@ -3025,7 +3212,10 @@
             }
           }
         } catch (error) {
-          this.$message.error('批量保存失败,请检查必填项');
+          // 必填缺项已由 validateForm 逐行提示,不再叠加兜底文案
+          if (!error || !error.requiredTips) {
+            this.$message.error('批量保存失败,请检查必填项');
+          }
         }
       },
 
@@ -3065,6 +3255,11 @@
           try {
             await this.validateFormIndividually(index);
 
+            // 必填缺项时不保存该行(提示已由校验方法弹出)
+            if (this.buildRequiredGroups([index]).length) {
+              return resolve();
+            }
+
             if (row.packingSpecificationLabel?.length < 1) {
               this.$message.error('请到主数据维护包装组信息!');
               return;
@@ -3866,6 +4061,13 @@
     color: red;
   }
 
+  // 生产入库必填列表头红星
+  .required-star::before {
+    content: '*';
+    color: #f56c6c;
+    margin-right: 4px;
+  }
+
   .wareHouse_style {
     text-overflow: ellipsis;
     overflow: hidden;