695593266@qq.com 4 днів тому
батько
коміт
e1114be33c

+ 43 - 2
src/views/produce/components/workPlan/components/addSample.vue

@@ -539,7 +539,6 @@
           {
             label: '名称',
             prop: 'categoryName',
-            width: '150',
             align: 'center',
             width: 120,
             showOverflowTooltip: true
@@ -831,6 +830,7 @@
       handleSampleSubmit() {
         // this.$refs.ruleForm.validate((valid) => {
         // if (valid) {
+        if (!this.validateSampleSubmit()) return;
         let params = {
           conditionType: this.form.conditionType,
           quantity: this.form.quantity,
@@ -845,13 +845,54 @@
         // });
       },
 
+      validateSampleSubmit() {
+        const isValidPositiveNumber = (value) => {
+          if (value === '' || value === null || value === undefined) {
+            return false;
+          }
+          const number = Number(value);
+          return Number.isFinite(number) && number > 0;
+        };
+
+        if (!this.form.conditionType) {
+          this.$message.warning('请选择请样类型');
+          return false;
+        }
+
+        if (this.form.conditionType == 2) {
+          if (!isValidPositiveNumber(this.form.quantity)) {
+            this.$message.warning('请输入大于0的请样数量');
+            return false;
+          }
+          if (!this.form.unit) {
+            this.$message.warning('请选择请样单位');
+            return false;
+          }
+          if (!isValidPositiveNumber(this.form.portion)) {
+            this.$message.warning('请输入大于0的请样条数');
+            return false;
+          }
+          return true;
+        }
+
+        if (!isValidPositiveNumber(this.form.portion)) {
+          this.$message.warning('请输入大于0的请样数量');
+          return false;
+        }
+        if (!this.form.packingUnit) {
+          this.$message.warning('请选择请样单位');
+          return false;
+        }
+        return true;
+      },
+
       async sampleFn(data, specifications) {
         this.sampleList = [];
         if (!this.selection || this.selection.length == 0) {
           this.$message.warning('请先选择来源清单!');
           return;
         }
-        const quantity = data.quantity || 1;
+        const quantity = Number(data.quantity || 1);
         const unit = data.sampleUnit;
         const sampleCount = Number(data.portion);
         try {