yijing 1 год назад
Родитель
Сommit
c2b70fc799

+ 95 - 61
src/views/inspectionPlan/components/edit.vue

@@ -24,24 +24,34 @@
               </el-dropdown>
             </template>
             <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2 && conditionType == 2">
-              <div>
-                <div style="display: flex;align-items: center;">
-                  <el-input v-model="formData.number" style="width: 120px;" placeholder="请输入" size="mini"
-                    @change="handleInputNumber"></el-input>
-                  <DictSelection dictName="计量单位" clearable v-model="formData.sampleUnit" size="mini"
-                    style="width: 120px;margin-left: 12px;" @change="changeSamUnit">
-                  </DictSelection>
-                </div>
-              </div>
-              <div>
-                <div style="margin-left: 12px;display: flex;align-items: center;">
-                  <div>数量:</div>
-                  <el-input v-model="formData.portion" style="width: 120px;margin:0 12px;" placeholder="请输入" size="mini"
-                    @change="handleInput" :disabled="conditionType == 1"></el-input>
-                  <el-button type="primary" size="mini" @click="handleSampleSubmit"
-                    style="margin-right: 12px;">确认</el-button>
-                </div>
-              </div>
+              <el-row>
+                <el-form ref="ruleForm" :model="formData" label-width="60px" size="mini" :rules="rules" class="flex"
+                  :show-message="false">
+                  <el-col :span="6">
+                    <el-form-item prop="number" label-width="0" style="margin-bottom: 0;">
+                      <el-input v-model="formData.number" placeholder="请输入" size="mini"
+                        @change="handleInputNumber"></el-input>
+                    </el-form-item>
+                  </el-col>
+                  <el-col :span="6">
+                    <el-form-item prop="sampleUnit" label-width="0" style="margin: 0;">
+                      <DictSelection dictName="计量单位" clearable v-model="formData.sampleUnit" size="mini"
+                        @change="changeSamUnit">
+                      </DictSelection>
+                    </el-form-item>
+                  </el-col>
+                  <el-col :span="8">
+                    <el-form-item prop="portion" label="数量" style="margin: 0;">
+                      <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput"
+                        :disabled="conditionType == 1"></el-input>
+                    </el-form-item>
+                  </el-col>
+                  <el-col :span="4" style="text-align: right;">
+                    <el-button type="primary" size="mini" @click="handleSampleSubmit"
+                      style="margin-right: 12px;">确认</el-button>
+                  </el-col>
+                </el-form>
+              </el-row>
             </template>
           </ele-pro-table>
         </el-tab-pane>
@@ -128,6 +138,7 @@ import {
   outInRecordsPage,
   getBatchInfoData
 } from '@/api/inspectionPlan/index.js';
+import { rules } from 'eslint-config-prettier';
 export default {
   components: {
     baseInfo
@@ -254,6 +265,30 @@ export default {
         sampleUnit: '',
         portion: null
       },
+      rules: {
+        number: [
+          {
+            required: true,
+            message: '请输入',
+            trigger: 'blur'
+          },
+        ],
+        sampleUnit: [
+          {
+            required: true,
+            message: '请选择样品单位',
+            trigger: 'change'
+          }
+        ],
+        portion: [
+          {
+            required: true,
+            message: '请输入',
+            trigger: 'blur'
+          }
+        ]
+
+      },
       isConsumable: '',
       conditionType: null,
 
@@ -666,9 +701,6 @@ export default {
         const data1 = this.$refs.table12.getData()
         this.$set(this.formData, 'sampleUnit', data1[0]?.measureUnit);
         this.$set(this.baseForm, 'sampleMeasureUnit', data1[0]?.measureUnit);
-
-        // this.formData.sampleUnit = data1[0]?.measureUnit;
-        // this.baseForm.sampleMeasureUnit = data1[0].measureUnit
       }
     },
 
@@ -836,40 +868,40 @@ export default {
     },
     handleInputNumber(val) {
       let packingList = this.$refs.table12.getData()
-      if (packingList.length > 1) {
-        if (val > packingList.length) {
-          this.$message.warning('数量不能大于来源清单数量!');
-          return;
-        }
-      } else {
-        if (packingList.length == 1) {
-          if (val > packingList[0].measureQuantity) {
-            this.$message.warning('数量不能大于计量数量!');
-            return;
-          }
-        }
+
+      const maxValue = packingList.length > 1 ? packingList.length : packingList[0].measureQuantity;
+
+      if (val > maxValue) {
+        this.$message.warning('数量不能大于计量数量!');
+        this.formData.number = maxValue;
+        return;
       }
     },
-    handleInput() {
-      if (this.formData.portion == null || this.formData.portion == '' || this.formData.portion == 0) {
-        this.$message.warning('生成取样数量不能为空!');
+    handleInput(val) {
+      if (val == 0 || val == '' || val == null) {
         this.$refs.table12.clearSelection();
+        return
+      }
+      let packingList = this.$refs.table12.getData();
+      if (!packingList || packingList.length === 0) {
         return;
       }
-      let packingList = this.$refs.table12.getData()
-      console.log(this.isCheck, 'this.isCheck')
+
+      const portion = Number(this.formData.portion);
       if (this.isCheck) {
-        if (this.formData.portion > packingList.length) {
+        if (portion > packingList.length) {
           this.$message.warning('取样数量不能大于来源清单数量!');
+          this.formData.portion = packingList.length;
           return;
         }
-        const rows = packingList.slice(0, this.formData.portion);
-        rows.forEach((row) => {
+        packingList.slice(0, this.formData.portion).forEach(row => {
           this.$refs.table12.toggleRowSelection(row);
         });
       } else {
-        if (this.formData.portion > packingList[0].measureQuantity) {
+        const maxQuantity = Number(packingList[0].measureQuantity);
+        if (portion > maxQuantity) {
           this.$message.warning('取样数量不能大于计量数量!');
+          this.formData.portion = maxQuantity;
           return;
         }
       }
@@ -879,31 +911,28 @@ export default {
       this.isConsumable = val.isConsumable;
     },
     changeSamUnit(val) {
-      console.log(val, 'dddd')
       this.$refs.baseInfoRefs.getsampleMeasureUnit(val)
     },
     handleSampleSubmit() {
-      this.sampleList = []
-      if (this.formData.portion == null || this.formData.portion == 0 || this.formData.number == '' || this.formData.number == null) {
-        this.$message.warning('计量数量或者取样数量不能为空!');
-        return;
-      }
-      this.baseForm.sampleMeasureUnit = this.formData.sampleUnit
+      this.$refs.ruleForm.validate((valid) => {
+        if (valid) {
+          this.sampleList = []
+          this.baseForm.sampleMeasureUnit = this.formData.sampleUnit
 
-      console.log(this.conditionType, 'conditionType')
-      console.log(this.selectedList, '.conditionType')
+          if (this.conditionType == 1) {
+            this.sampleList = this.selectedList
+          } else {
+            let measureQ = this.formData.number;
+            let unit = this.formData.sampleUnit;
+            let nums = Number(this.formData.portion);
 
-      if (this.conditionType == 1) {
-        this.sampleList = this.selectedList
-      } else {
-        let measureQ = this.formData.number;
-        let unit = this.formData.sampleUnit;
-        let nums = Number(this.formData.portion);
+            console.log(measureQ, unit, nums, 'measureQ, unit, nums')
+            this.getNewSampleList(measureQ, unit, nums)
+          }
+          this.activeName = '2'
+        }
+      });
 
-        console.log(measureQ, unit, nums, 'measureQ, unit, nums')
-        this.getNewSampleList(measureQ, unit, nums)
-      }
-      this.activeName = '2'
 
     },
     getNewSampleList(measureQ, unit, nums) {
@@ -979,4 +1008,9 @@ export default {
   border: 1px solid#ebeef5;
   border-top: none;
 }
+
+.flex {
+  display: flex;
+  align-items: center;
+}
 </style>

+ 100 - 62
src/views/inspectionWork/components/QualityContentTabs.vue

@@ -11,7 +11,7 @@
       <!--  -->
       <el-tab-pane label="来源清单" name="1">
         <ele-pro-table ref="sourceTable" :columns="tableColumns1" :datasource="datasource"
-          @selection-change="$emit('selection-change', $event)" :initLoad="false" :pagination="true">
+          @selection-change="handleSelectionChange" :initLoad="false" :pagination="true">
 
           <template v-slot:toolbar v-if="form.qualityMode == 2">
             <el-dropdown trigger="click" @command="handleSampleNumber">
@@ -23,24 +23,34 @@
             </el-dropdown>
           </template>
           <template v-slot:toolkit v-if="form.qualityMode == 2 && conditionType == 2">
-            <div>
-              <div style="display: flex;align-items: center;">
-                <el-input v-model="formData.number" style="width: 120px;" placeholder="请输入" size="mini"
-                  @change="handleInputNumber"></el-input>
-                <DictSelection dictName="计量单位" clearable v-model="formData.sampleUnit" size="mini"
-                  style="width: 120px;margin-left: 12px;" @change="changeSamUnit">
-                </DictSelection>
-              </div>
-            </div>
-            <div>
-              <div style="margin-left: 12px;display: flex;align-items: center;">
-                <div>数量:</div>
-                <el-input v-model="formData.portion" style="width: 120px;margin:0 12px;" placeholder="请输入" size="mini"
-                  @change="handleInput" :disabled="conditionType == 1"></el-input>
-                <el-button type="primary" size="mini" @click="handleSampleSubmit"
-                  style="margin-right: 12px;">确认</el-button>
-              </div>
-            </div>
+            <el-row>
+              <el-form ref="ruleForm" :model="formData" label-width="60px" size="mini" :rules="rules" class="flex"
+                :show-message="false">
+                <el-col :span="6">
+                  <el-form-item prop="number" label-width="0" style="margin-bottom: 0;">
+                    <el-input v-model="formData.number" placeholder="请输入" size="mini"
+                      @change="handleInputNumber"></el-input>
+                  </el-form-item>
+                </el-col>
+                <el-col :span="6">
+                  <el-form-item prop="sampleUnit" label-width="0" style="margin: 0;">
+                    <DictSelection dictName="计量单位" clearable v-model="formData.sampleUnit" size="mini"
+                      @change="changeSamUnit">
+                    </DictSelection>
+                  </el-form-item>
+                </el-col>
+                <el-col :span="8">
+                  <el-form-item prop="portion" label="数量" style="margin: 0;">
+                    <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput"
+                      :disabled="conditionType == 1"></el-input>
+                  </el-form-item>
+                </el-col>
+                <el-col :span="4" style="text-align: right;">
+                  <el-button type="primary" size="mini" @click="handleSampleSubmit"
+                    style="margin-right: 12px;">确认</el-button>
+                </el-col>
+              </el-form>
+            </el-row>
           </template>
 
           <template v-slot:materielDesignation="{ row }">
@@ -239,6 +249,30 @@ export default {
         sampleUnit: '',
         portion: null
       },
+      rules: {
+        number: [
+          {
+            required: true,
+            message: '请输入',
+            trigger: 'blur'
+          },
+        ],
+        sampleUnit: [
+          {
+            required: true,
+            message: '请选择样品单位',
+            trigger: 'change'
+          }
+        ],
+        portion: [
+          {
+            required: true,
+            message: '请输入',
+            trigger: 'blur'
+          }
+        ]
+
+      },
     }
   },
 
@@ -357,10 +391,20 @@ export default {
       console.log('清空勾选')
       this.$refs.sourceTable.clearSelection();
     },
+    handleSelectionChange(selection) {
+      this.formData.portion = selection.length;
+      this.formData.sampleUnit = selection[0]?.measureUnit;
+
+      this.$set(this.form, 'sampleNumber', selection.length);
+      this.$set(this.form, 'sampleMeasureUnit', selection[0]?.measureUnit);
+
+      this.$emit('handleSelectionChange', selection)
+    },
 
     handleSampleNumber(val) {
       console.log(val, 'val')
       this.conditionType = val;
+      this.$emit('getConditionType', val)
 
       //取整样
       let data = this.$refs.sourceTable.getData()
@@ -377,40 +421,42 @@ export default {
     },
     handleInputNumber(val) {
       let packingList = this.$refs.sourceTable.getData()
-      if (packingList.length > 1) {
-        if (val > packingList.length) {
-          this.$message.warning('数量不能大于来源清单数量!');
-          return;
-        }
-      } else {
-        if (packingList.length == 1) {
-          if (val > packingList[0].measureQuantity) {
-            this.$message.warning('数量不能大于计量数量!');
-            return;
-          }
-        }
+
+      const maxValue = packingList.length > 1 ? packingList.length : packingList[0].measureQuantity;
+
+      if (val > maxValue) {
+        this.$message.warning('数量不能大于计量数量!');
+        this.formData.number = maxValue;
+        return;
       }
     },
-    handleInput() {
-      if (this.formData.portion == null || this.formData.portion == '' || this.formData.portion == 0) {
-        this.$message.warning('生成取样数量不能为空!');
-        this.tableSelClear();
+    handleInput(val) {
+      if (val == 0 || val == '' || val == null) {
+        this.$refs.table12.clearSelection();
+        return
+      }
+
+      let packingList = this.$refs.sourceTable.getData();
+      if (!packingList || packingList.length === 0) {
         return;
       }
-      let packingList = this.$refs.sourceTable.getData()
+
+      const portion = Number(this.formData.portion);
 
       if (packingList.length > 1) {
-        if (this.formData.portion > packingList.length) {
+        if (portion > packingList.length) {
           this.$message.warning('取样数量不能大于来源清单数量!');
+          this.formData.portion = packingList.length;
           return;
         }
-        const rows = packingList.slice(0, this.formData.portion);
-        rows.forEach((row) => {
-          this.$refs.sourceTable.toggleRowSelection(row);
+        packingList.slice(0, this.formData.portion).forEach(row => {
+          this.$refs.table12.toggleRowSelection(row);
         });
       } else {
-        if (this.formData.portion > packingList[0].measureQuantity) {
+        const maxQuantity = Number(packingList[0].measureQuantity);
+        if (portion > maxQuantity) {
           this.$message.warning('取样数量不能大于计量数量!');
+          this.formData.portion = maxQuantity;
           return;
         }
       }
@@ -420,28 +466,20 @@ export default {
       this.$emit('changeSamUnit', val)
     },
     handleSampleSubmit() {
-      if (this.formData.portion == null || this.formData.portion == 0) {
-        this.$message.warning('生成取样数量不能为空!');
-        return;
-      }
-      //取小样 赋值右上角单位
-      this.changeSamUnit(this.formData.sampleUnit)
-
-      console.log(this.formData.number, 'this.formData.number')
-      console.log(this.formData.sampleUnit, 'this.formData.sampleUnit')
+      this.$refs.ruleForm.validate((valid) => {
+        if (valid) {
+          //取小样 赋值右上角单位
+          this.changeSamUnit(this.formData.sampleUnit)
 
-      if (this.formData.number == null || this.formData.sampleUnit == '') {
-        this.$message.warning('请先选择取样的数量和单位!');
-        return;
-      }
-
-      let params = {
-        conditionType: this.conditionType,
-        measureQ: this.formData.number,
-        sampleUnit: this.formData.sampleUnit,
-        portion: this.formData.portion
-      }
-      this.$emit('handleSampleSubmit', params)
+          let params = {
+            conditionType: this.conditionType,
+            measureQ: this.formData.number,
+            sampleUnit: this.formData.sampleUnit,
+            portion: this.formData.portion
+          }
+          this.$emit('handleSampleSubmit', params)
+        }
+      })
     },
 
 

+ 10 - 7
src/views/inspectionWork/edit.vue

@@ -10,10 +10,10 @@
         @changeModel="changeModel" @changeNumber="changeNumber"></base-info>
 
       <quality-content-tabs ref="tabsRef" :type="type" :ids="this.$route.query.id" :sample-list="sampleList"
-        :scheme-list="schemeList" :loading="loading" :form="form" @selection-change="handleSelectionChange1"
+        :scheme-list="schemeList" :loading="loading" :form="form" @handleSelectionChange="handleSelectionChange1"
         @batch-quality="batchQuality" @batch-dispose="batchDispose" @handleDetail="handleDetail"
         @inputWeight="inputWeight" @handleDispose="handleDispose" @changeSamUnit="changeSamUnit"
-        @handleSample1="handleSample1" @handleSampleSubmit="handleSampleSubmit" />
+        @handleSample1="handleSample1" @handleSampleSubmit="handleSampleSubmit" @getConditionType="getConditionType" />
     </el-card>
 
     <sampleListDialog ref="detailRef" @handleConfirm="handleConfirm" @handleDispose="handleDispose"></sampleListDialog>
@@ -76,7 +76,8 @@ export default {
         qualityTimeStart: '',
         qualityTimeEnd: '',
 
-        sampleMeasureUnit: ''
+        sampleMeasureUnit: '',
+        conditionType: null
       };
     };
     return {
@@ -276,14 +277,12 @@ export default {
     },
     //来源清单勾选事件
     handleSelectionChange1(selection) {
-      console.log(selection, '勾选列表');
-      this.form.sampleNumber = selection.length;
+
       if (this.form.qualityMode === 2) {
         this.selectedList = selection;
 
         if (this.schemeList.length == 0) {
           for (let i = 0; i < selection.length; i++) {
-            console.log(selection[i], 'selection[i]')
             this.$set(selection[i], 'qualityStatus', 2)
             // 遍历新数组设置 qualityResults 默认值
             this.schemeList.forEach(item => {
@@ -295,6 +294,7 @@ export default {
             this.$set(selection[i], 'qualitySampleTemplateList', JSON.parse(JSON.stringify(this.schemeList)))
           }
         }
+
         this.sampleList = selection;
         //赋值取样数量
         this.form.sampleNumber = selection.length;
@@ -435,7 +435,9 @@ export default {
       console.log(res, '质检方案');
       this.schemeList = res.list;
     },
-
+    getConditionType(val) {
+      this.form.conditionType = val;
+    },
 
     /* 保存编辑 */
     save() {
@@ -560,6 +562,7 @@ export default {
 
         this.form.qualityTimeEnd = new Date(this.getNowTime())
         this.form.qualityTimeStart = new Date(this.qualityTimeStart)
+
         let params = {
           ...this.form,
           sampleList: this.sampleList,