Bläddra i källkod

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

mlchen 6 dagar sedan
förälder
incheckning
dbfba867c3

+ 147 - 10
src/BIZComponents/inventoryTable.vue

@@ -267,6 +267,7 @@
               <el-form-item
                 :prop="'datasource.' + scope.$index + '.guaranteePeriod'"
                 :rules="{
+                  required: isDeadlineRequired && isDate == 1,
                   pattern: numberReg,
                   message: '请输入有效期',
                   trigger: 'blur'
@@ -445,16 +446,32 @@
         <template v-slot:headerProduceDeliveryDeadline="{ column }">
           <span
             :class="
-              isProduceDeliveryDeadline && isDate == 1 ? 'is-required' : ''
+              isDate == 1 && (isDeadlineRequired || isProduceDeliveryDeadline)
+                ? 'is-required'
+                : ''
             "
             >{{ column.label }}</span
           >
         </template>
+        <template v-slot:headerGuaranteePeriod="{ column }">
+          <span
+            :class="isDeadlineRequired && isDate == 1 ? 'is-required' : ''"
+            >{{ column.label }}</span
+          >
+        </template>
+        <template v-slot:headerGuaranteePeriodDeadline="{ column }">
+          <span
+            :class="isDeadlineRequired && isDate == 1 ? 'is-required' : ''"
+            >{{ column.label }}</span
+          >
+        </template>
         <template v-slot:produceDeliveryDeadline="scope">
           <el-form-item
             :prop="'datasource.' + scope.$index + '.produceDeliveryDeadline'"
             :rules="{
-              required: isProduceDeliveryDeadline && isDate == 1 ? true : false,
+              required:
+                isDate == 1 &&
+                (isDeadlineRequired || isProduceDeliveryDeadline),
               message: '选择生产交付交期',
               trigger: 'change'
             }"
@@ -524,6 +541,11 @@
         <template v-slot:guaranteePeriodDeadline="scope">
           <el-form-item
             :prop="'datasource.' + scope.$index + '.guaranteePeriodDeadline'"
+            :rules="{
+              required: isDeadlineRequired && isDate == 1,
+              message: '请选择有效期截止日期',
+              trigger: 'change'
+            }"
           >
             <el-date-picker
               style="width: 140px"
@@ -1289,6 +1311,13 @@
         default: false
       },
 
+      //销售订单物品清单:生产交付交期/有效期/有效期截止日期三项都必填。
+      //只由销售订单新增/编辑传 true,其它复用本组件的单据(报价单、合同、退货、发票等)行为不变
+      isDeadlineRequired: {
+        type: Boolean,
+        default: false
+      },
+
       isDrawer: {
         type: Boolean,
         default: false
@@ -1454,7 +1483,9 @@
           datasource: [],
           discountTotalPrice: 0
         },
-        isDate: 1,
+        // 交期必填开关,由系统参数 eom_inventoryTable_customerExpectDeliveryDeadline 下发(1 必填 / 0 不必填)。
+        // 初值取「不必填」:参数没配到或接口异常时不能反过来把必填打开
+        isDate: 0,
         pricingWayList,
         curIndex: '',
         rules: {},
@@ -1960,7 +1991,8 @@
             label: '生产交付交期',
             slot: 'produceDeliveryDeadline',
             headerSlot:
-              this.isDate == 1 && this.isProduceDeliveryDeadline
+              this.isDate == 1 &&
+              (this.isDeadlineRequired || this.isProduceDeliveryDeadline)
                 ? 'headerProduceDeliveryDeadline'
                 : '',
             isNone: this.contractBookType != 1,
@@ -1971,6 +2003,10 @@
             prop: 'guaranteePeriod',
             label: '有效期',
             slot: 'guaranteePeriod',
+            headerSlot:
+              this.isDeadlineRequired && this.isDate == 1
+                ? 'headerGuaranteePeriod'
+                : '',
             align: 'center',
             isNone: this.quoteType === 2
           },
@@ -1979,6 +2015,10 @@
             prop: 'guaranteePeriodDeadline',
             label: '有效期截止日期',
             slot: 'guaranteePeriodDeadline',
+            headerSlot:
+              this.isDeadlineRequired && this.isDate == 1
+                ? 'headerGuaranteePeriodDeadline'
+                : '',
             isNone: !this.isGuaranteePeriod || this.quoteType === 2,
             align: 'center'
           },
@@ -2088,11 +2128,20 @@
     created() {
       parameterGetByCode({
         code: 'eom_inventoryTable_customerExpectDeliveryDeadline'
-      }).then((res) => {
-        if (res.value) {
-          this.isDate = res.value;
-        }
-      });
+      })
+        .then((res) => {
+          // 参数缺失(null/空值)同样按「不必填」,只有明确下发 0/1 才覆盖初值
+          this.isDate =
+            res &&
+            res.value !== null &&
+            res.value !== undefined &&
+            res.value !== ''
+              ? res.value
+              : 0;
+        })
+        .catch(() => {
+          this.isDate = 0;
+        });
     },
     methods: {
       formatPrice,
@@ -3370,12 +3419,100 @@
         this.$set(parasm, 'quotationSubtotalTax', '');
       },
 
+      // 三项必填(isDeadlineRequired)缺失时按「行」聚合:一行一条、缺的字段用「、」并列,
+      // 逐字段摊平会挤成一长串,几十行明细里看不出到底是哪几行缺什么
+      groupDeadlineTips(invalidFields) {
+        const labelFallback = {
+          produceDeliveryDeadline: '生产交付交期',
+          guaranteePeriod: '有效期',
+          guaranteePeriodDeadline: '有效期截止日期'
+        };
+        const groups = {};
+        Object.keys(invalidFields || {}).forEach((path) => {
+          // 校验失败路径形如 datasource.0.guaranteePeriod
+          const match = path.match(
+            /^datasource\.(\d+)\.(produceDeliveryDeadline|guaranteePeriod|guaranteePeriodDeadline)$/
+          );
+          if (!match) return;
+          const index = +match[1];
+          // 字段名取列定义里的 label,保证和表头显示的文案一致
+          const column = (this.columns || []).find(
+            (item) => item.prop === match[2]
+          );
+          const label = (column && column.label) || labelFallback[match[2]];
+          if (!groups[index]) groups[index] = [];
+          groups[index].push(label);
+        });
+        return Object.keys(groups)
+          .map(Number)
+          .sort((a, b) => a - b)
+          .map((index) => {
+            const row = this.form.datasource[index] || {};
+            return {
+              index,
+              labels: groups[index],
+              name: row.productName || row.productCode || '未选择物品'
+            };
+          });
+      },
+      escapeHtml(text) {
+        const map = {
+          '&': '&amp;',
+          '<': '&lt;',
+          '>': '&gt;',
+          '"': '&quot;',
+          "'": '&#39;'
+        };
+        return String(text).replace(/[&<>"']/g, (char) => map[char]);
+      },
       validateForm(callback) {
         this.$refs.form.validate((valid, obj) => {
           if (obj) {
             console.log('validateForm', obj);
             let messages = Object.keys(obj).map((key) => obj[key][0]);
-            if (messages.length > 0) {
+            // 必填缺失优先给「一行一条」的提示:先报总行数/总项数,再逐行列缺的字段,
+            // 行数多时只展示前 3 行,其余折成一句汇总(避免几十行时提示刷屏)
+            const deadlineGroups = this.groupDeadlineTips(obj);
+            if (
+              deadlineGroups.length === 1 &&
+              deadlineGroups[0].labels.length === 1
+            ) {
+              // 只有一处缺失时用最短的一句,不必套「共 N 行 N 项」的壳
+              const single = deadlineGroups[0];
+              this.$message.warning(
+                `第${single.index + 1}行 物品「${single.name}」的「${
+                  single.labels[0]
+                }」未填写`
+              );
+            } else if (deadlineGroups.length > 0) {
+              const total = deadlineGroups.reduce(
+                (sum, group) => sum + group.labels.length,
+                0
+              );
+              const maxRows = 3;
+              const lines = deadlineGroups.slice(0, maxRows).map(
+                (group) =>
+                  // 物品名来自业务数据,拼进 HTML 提示前必须转义
+                  `第${group.index + 1}行 物品「${this.escapeHtml(
+                    group.name
+                  )}」:${group.labels.join('、')}`
+              );
+              if (deadlineGroups.length > maxRows) {
+                lines.push(
+                  `另有 ${deadlineGroups.length - maxRows} 行未填写完整(共 ${
+                    deadlineGroups.length
+                  } 行 / ${total} 项)`
+                );
+              }
+              this.$message.warning({
+                dangerouslyUseHTMLString: true,
+                showClose: true,
+                duration: 6000,
+                message: `物品清单共 ${
+                  deadlineGroups.length
+                } 行 ${total} 项必填未填写:<br/>${lines.join('<br/>')}`
+              });
+            } else if (messages.length > 0) {
               this.$message.warning(messages[0].message);
             }
           }

+ 1 - 0
src/views/saleManage/saleOrder/components/addDialogNew.vue

@@ -577,6 +577,7 @@
         :customerMark="customerMark"
         :isCustomerMark="false"
         :isProduceDeliveryDeadline="form.needProduce != 0"
+        :isDeadlineRequired="true"
         ref="inventoryTable"
         @setCountAmount="setCountAmount"
         :isContractId="!!form.contractId"