Răsfoiți Sursa

提交修改 质检计划,质检工单bug

PC-202503171525\Administrator 1 an în urmă
părinte
comite
7a7bfe93f4

+ 1 - 1
src/views/inspectionPlan/components/baseInfo.vue

@@ -471,7 +471,7 @@ export default {
       const data = await getDetailInfo(val)
       this.categoryInfo = data.category
 
-      // this.$emit('getCategoryInfo', data)
+      this.$emit('getCategoryInfo', data)
     },
     getsampleMeasureUnit(val) {
       this.$set(this.form, 'sampleMeasureUnit', val);

+ 187 - 69
src/views/inspectionPlan/components/edit.vue

@@ -23,30 +23,38 @@
                 </el-dropdown-menu>
               </el-dropdown>
             </template>
-            <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2 && conditionType == 2">
+            <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2 ">
               <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-col :span="6" v-if="conditionType == 2">
                     <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-col :span="6" v-if="conditionType == 2">
                     <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-col :span="8" v-if="conditionType == 2">
                     <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-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput" clearable></el-input>
                     </el-form-item>
                   </el-col>
-                  <el-col :span="4" style="text-align: right;">
+                  <el-col :span="24" v-if="conditionType == 1 && !isCheck ">
+                    <el-form-item prop="portion" label="数量" style="margin: 0;">
+                      <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput" clearable></el-input>
+                    </el-form-item>
+                  </el-col>
+                  <el-col :span="4" style="text-align: right;" v-if="conditionType == 1 && !isCheck ">
+                    <el-button type="primary" size="mini" @click="handleSampleSubmit"
+                      style="margin-right: 12px;">确认</el-button>
+                  </el-col>
+                  <el-col :span="4" style="text-align: right;" v-if="conditionType == 2 ">
                     <el-button type="primary" size="mini" @click="handleSampleSubmit"
                       style="margin-right: 12px;">确认</el-button>
                   </el-col>
@@ -232,7 +240,7 @@ export default {
 
       activeName: '1',
       selectedList: [],
-      isCheck: false,
+      isCheck: false, // 是否拆包  false 不拆包 true 拆包
 
       rowIds: '',
       formData: {
@@ -265,6 +273,7 @@ export default {
 
       },
       isConsumable: '',
+      netWeight: '',// 净重
       conditionType: null,
 
       sampleListCode: ''
@@ -370,11 +379,11 @@ export default {
   methods: {
     async datasource({ page, limit, where }) {
       const res = await getInventoryListByPlanId({ ...where, page, limit });
-      if (res.list.length > 1) {
-        this.isCheck = true
-      } else {
-        this.isCheck = false
-      }
+      // if (res.list.length > 1) {
+      //   this.isCheck = true
+      // } else {
+      //   this.isCheck = false
+      // }
       this.packingList = res.list;
       return res.list;
     },
@@ -428,6 +437,11 @@ export default {
       // 如果是编辑或者详情,则查询物料清单、质检方案和样品列表
       if (row.id) {
         this.rowIds = row.id;
+        if (row.isUnpack === 1) {
+          this.isCheck = true
+        } else {
+          this.isCheck = false
+        }
         //操作行点击时查询清单
         // await this.getInventoryList();
         await this.reload({ planId: row.id });
@@ -527,7 +541,6 @@ export default {
         this.packingList = _arr1;
         this.$refs.table12.setData(_arr1);//赋值
         const _arr2 = this.$refs.table12.getData();
-
         if (_arr2.length > 1) {
           this.baseForm.productNumber = _arr2.length;
         } else {
@@ -545,21 +558,22 @@ export default {
       if (this.baseForm.qualityMode == 1) {
         this.sampleList = [];
         console.log(this.baseForm, '---isUnpack---')
-        if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
-          //拆包
-          if (this.baseForm.isUnpack == 1) {
-            await this.handleUnpackCase(packingList);
-          } else if (this.baseForm.isUnpack == 0) {
-            await this.updatePackingList(packingList);
-          }
-        } else {
-          console.log(this.isCheck, 'this.isCheck')
-          if (!this.isCheck) {
-            await this.handleUnpackCase(packingList);
-          } else {
-            await this.updatePackingList(packingList);
-          }
-        }
+        await this.handleUnpackCase(packingList);
+        // if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
+        //   //拆包
+        //   if (this.baseForm.isUnpack == 1) {
+        //     await this.handleUnpackCase(packingList);
+        //   } else if (this.baseForm.isUnpack == 0) {
+        //     await this.updatePackingList(packingList);
+        //   }
+        // } else {
+        //   console.log(this.isCheck, 'this.isCheck')
+        //   if (!this.isCheck) {
+        //     await this.handleUnpackCase(packingList);
+        //   } else {
+        //     await this.updatePackingList(packingList);
+        //   }
+        // }
       } else {
         this.sampleList = [];
       }
@@ -591,13 +605,25 @@ export default {
         const newMeasureQuantity = oldItem.measureQuantity / this.baseForm.productNumber;
         const newWeight = parseFloat((oldItem.weight / this.baseForm.productNumber).toFixed(2))
 
+        // 将 measureQuantity 转换为数字
+        const measureQuantity = Number(oldItem.measureQuantity);
+        // 判断是否有小数部分
+        const hasDecimal = measureQuantity % 1 !== 0;
+        let roundedQuantity;
+        if (hasDecimal) {
+          // 有小数部分,向上取整
+          roundedQuantity = Math.ceil(measureQuantity);
+        } else {
+          roundedQuantity = measureQuantity;
+        }
+
         delete oldItem.id;
 
-        for (let i = 0; i < num; i++) {
+        for (let i = 0; i < roundedQuantity; i++) {
           data.push({
             ...oldItem,
-            measureQuantity: newMeasureQuantity,
-            weight: newWeight
+            measureQuantity: 1,
+            weight: this.netWeight || 0
           });
         }
       });
@@ -649,13 +675,19 @@ export default {
     handleSelectionChange(selection) {
       console.log(selection, '勾选')
       this.selectedList = selection;
-      this.formData.portion = selection.length;
-      this.baseForm.sampleNumber = selection.length;
       //如果取小样
       if (this.conditionType == 2) {
+        if (this.isCheck){
+          this.formData.portion = selection.length;
+          this.baseForm.sampleNumber = selection.length;
+        }else{
+          this.baseForm.sampleNumber = this.formData.portion;
+        }
         const data1 = this.$refs.table12.getData()
         this.$set(this.formData, 'sampleUnit', data1[0]?.measureUnit);
         this.$set(this.baseForm, 'sampleMeasureUnit', data1[0]?.measureUnit);
+      }else if (this.conditionType == 1){
+        this.baseForm.sampleNumber = this.formData.portion;
       }
     },
     //取样方式选择
@@ -670,18 +702,48 @@ export default {
         if (this.selectedList.length == 0) {
           this.$message.warning('请先选择样品!');
         } else {
-          for (let i = 0; i < this.selectedList.length; i++) {
-            this.selectedList[i].sampleCode = await this.getSampleCode();
+          if (this.isCheck){
+            for (let i = 0; i < this.selectedList.length; i++) {
+              for (let j = 0; j < this.selectedList[i].measureQuantity; j++){
+                // this.selectedList[i].sampleCode = await this.getSampleCode();
+                this.sampleList.push({
+                  ...this.selectedList[i],
+                  sampleCode: await this.getSampleCode(),
+                  measureQuantity: 1,
+                  weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
+                });
+              }
+            }
+          }else{
+            for (let i = 0; i < this.selectedList.length; i++) {
+              let forNum = 0;
+              if (this.formData.portion != null && this.formData.portion != '') {
+                forNum = this.formData.portion;
+              }else{
+                forNum = this.selectedList[i].measureQuantity;
+              }
+              for (let j = 0; j < forNum; j++){
+                // this.selectedList[i].sampleCode = await this.getSampleCode();
+                this.sampleList.push({
+                  ...this.selectedList[i],
+                  sampleCode: await this.getSampleCode(),
+                  measureQuantity: 1,
+                  weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
+                });
+              }
+            }
+
           }
-          this.sampleList = this.selectedList;
-          this.formData.portion = this.selectedList.length;
+
+          // this.sampleList = this.selectedList;
+          this.formData.portion = this.sampleList.length;
           this.activeName = '2';
           this.$message.success('取样成功!');
         }
       } else if (val == 2) {
         this.formData.sampleUnit = dataS[0].measureUnit;
 
-        this.$refs.table12.clearSelection();
+        // this.$refs.table12.clearSelection();
         //小样
         if (this.selectedList.length == 0) {
           this.$message.warning('请先选择样品!');
@@ -713,30 +775,51 @@ export default {
       if (!packingList || packingList.length === 0) {
         return;
       }
-
+      // 计算 packingList 中 measureQuantity 字段的总和
+      const measureQuantitySum = packingList.reduce((sum, item) => {
+        const quantity = Number(item.measureQuantity) || 0;
+        return sum + quantity;
+      }, 0);
       const portion = Number(this.formData.portion);
-      if (this.isCheck) {
-        if (portion > packingList.length) {
-          this.$message.warning('取样数量不能大于来源清单数量!');
-          this.formData.portion = packingList.length;
-          return;
+      // 清空当前选中
+      this.$refs.table12.clearSelection();
+      if (this.conditionType == 2){ // 取小样
+        // 确保 portion 不超过数据列表长度
+        const safePortion = Math.min(portion, packingList.length);
+        if (this.isCheck) { // 是否拆包  false 不拆包
+          if (portion > packingList.length) {
+            this.$message.warning('取样数量不能大于来源清单数量!');
+            this.formData.portion = packingList.length;
+          }
+        } else {
+          const maxQuantity = Number(packingList[0].measureQuantity);
+          if (portion > maxQuantity) {
+            this.$message.warning('取样数量不能大于计量数量!');
+            this.formData.portion = maxQuantity;
+          }
         }
-        packingList.slice(0, this.formData.portion).forEach(row => {
-          this.$refs.table12.toggleRowSelection(row);
+        // 选中前 safePortion 行
+        packingList.slice(0, safePortion).forEach(row => {
+          this.$refs.table12.toggleRowSelection(row, true);
         });
-      } else {
-        const maxQuantity = Number(packingList[0].measureQuantity);
-        if (portion > maxQuantity) {
+      }else if (this.conditionType == 1){
+        // 确保 portion 不超过数据列表长度
+        const safePortion = Math.min(portion, measureQuantitySum);
+        if (portion > measureQuantitySum) {
           this.$message.warning('取样数量不能大于计量数量!');
-          this.formData.portion = maxQuantity;
-          return;
+          this.formData.portion = measureQuantitySum;
         }
+        // 选中前 safePortion 行
+        packingList.slice(0, safePortion).forEach(row => {
+          this.$refs.table12.toggleRowSelection(row, true);
+        });
       }
     },
     getCategoryInfo(val) {
       // this.baseForm.isUnpack = val.categoryWms.isUnpack;
 
       this.isConsumable = val.category.isConsumable;
+      this.netWeight = val.category.netWeight;
     },
     changeSamUnit(val) {
       this.$refs.baseInfoRefs.getsampleMeasureUnit(val);
@@ -747,35 +830,70 @@ export default {
         if (valid) {
           this.sampleList = []
           this.baseForm.sampleMeasureUnit = this.formData.sampleUnit
+          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)
-          }
+          console.log(measureQ, unit, nums, 'measureQ, unit, nums')
+          this.getNewSampleList(measureQ, unit, nums)
+          // 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'
         }
       });
     },
     //更新计量数量、单位后重新生成样品列表数据
-    getNewSampleList(measureQ, unit, nums) {
+    async getNewSampleList(measureQ, unit, nums) {
       this.sampleList = [];
       if (!this.selectedList || this.selectedList.length == 0) {
         this.$message.warning('请先选择样品!');
         return;
       }
 
-      this.sampleList = this.selectedList.map(oldItem => {
-        const newItem = JSON.parse(JSON.stringify(oldItem));
-        newItem.measureQuantity = measureQ;
-        newItem.measureUnit = unit;
-        return newItem;
-      });
+      if (!this.isCheck) {
+        let measureQuantity = 1;
+        if (this.conditionType == 2) {
+          measureQuantity = this.formData.number;
+        }
+        for (let i = 0; i < nums; i++) {
+          this.sampleList.push({
+            ...this.selectedList[0],
+            sampleCode: await this.getSampleCode(),
+            measureQuantity: measureQuantity,
+            measureUnit: unit,
+            weight: this.netWeight || 0
+          });
+        }
+      } else {
+        if (this.conditionType == 1) {
+          measureQ = 1;
+        }
+        for (let i = 0; i < this.selectedList.length; i++) {
+          this.sampleList.push({
+            ...this.selectedList[i],
+            sampleCode: await this.getSampleCode(),
+            measureQuantity: measureQ,
+            measureUnit: unit,
+            weight: this.netWeight || 0
+          });
+        }
+
+      }
+      // this.sampleList = this.selectedList.map(async oldItem => {
+      //   const newItem = JSON.parse(JSON.stringify(oldItem));
+      //   newItem.sampleCode = await this.getSampleCode();
+      //   newItem.measureQuantity = measureQ;
+      //   newItem.measureUnit = unit;
+      //   return newItem;
+      // });
     },
     //监听类型变化
     resetTable() {

+ 102 - 32
src/views/inspectionWork/components/QualityContentTabs.vue

@@ -13,7 +13,7 @@
         <ele-pro-table ref="sourceTable" :columns="tableColumns1" :datasource="datasource"
           @selection-change="handleSelectionChange" :initLoad="false" :pagination="true">
 
-          <template v-slot:toolbar v-if="form.qualityMode == 2 && type != 'detail'">
+          <template v-slot:toolbar v-if="form.qualityMode == 2 && form.qualityType == 2 && type != 'detail'">
             <el-dropdown trigger="click" @command="handleSampleNumber">
               <el-link type="primary" icon="el-icon-plus">取样</el-link>
               <el-dropdown-menu slot="dropdown">
@@ -22,30 +22,38 @@
               </el-dropdown-menu>
             </el-dropdown>
           </template>
-          <template v-slot:toolkit v-if="form.qualityMode == 2 && conditionType == 2">
+          <template v-slot:toolkit v-if="form.qualityMode == 2 && form.qualityType == 2 ">
             <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-col :span="6" v-if="conditionType == 2">
+                  <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;">
+                <el-col :span="6" v-if="conditionType == 2">
+                  <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-col :span="8" v-if=" conditionType == 2">
                   <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-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput"></el-input>
                   </el-form-item>
                 </el-col>
-                <el-col :span="4" style="text-align: right;">
+                <el-col :span="20" v-if="form.isUnpack == 2 && conditionType == 1">
+                  <el-form-item prop="portion" label="数量" style="margin: 0;">
+                    <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput"></el-input>
+                  </el-form-item>
+                </el-col>
+                <el-col :span="4" style="text-align: right;" v-if=" conditionType == 2">
+                  <el-button type="primary" size="mini" @click="handleSampleSubmit"
+                    style="margin-right: 12px;">确认</el-button>
+                </el-col>
+                <el-col :span="4" style="text-align: right;" v-if="form.isUnpack == 2 && conditionType == 1">
                   <el-button type="primary" size="mini" @click="handleSampleSubmit"
                     style="margin-right: 12px;">确认</el-button>
                 </el-col>
@@ -184,11 +192,12 @@ export default {
     schemeList: Array,
     loading: Boolean,
     form: Object,
-    ids: String
+    ids: String,
+    activeName:String
   },
   data() {
     return {
-      activeName: '2',
+      activeName: this.activeName,
       samplePagination: { currentPage: 1, pageSize: 10 },
       schemePagination: { currentPage: 1, pageSize: 10 },
 
@@ -397,24 +406,43 @@ export default {
       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);
+      debugger
+      if (this.form.conditionType == 2){
+        if (this.form.isUnpack == 2){
+          this.$set(this.form, 'sampleNumber', this.formData.portion);
+        }else{
+          this.formData.portion = selection.length;
+          this.$set(this.form, 'sampleNumber', selection.length);
+        }
+        this.formData.sampleUnit = selection[0]?.measureUnit;
+        this.$set(this.form, 'sampleMeasureUnit', selection[0]?.measureUnit);
+      }else if (this.form.conditionType == 1){
+        this.$set(this.form, 'sampleNumber', this.formData.portion);
+      }
+      // 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) {
+      debugger
+      console.log('取样方式选择',this.form.isUnpack)
       console.log(val, 'val')
       this.conditionType = val;
       this.$emit('getConditionType', val)
 
       //取整样
       let data = this.$refs.sourceTable.getData()
+      // this.$emit('getSelectedList')
+      // if (this.selectedList.length == 0) {
+      //   this.$message.warning('请先选择样品!');
+      // }
       if (val == 1) {
-        this.activeName = '2'
+        // this.activeName = '2'
         this.$emit('handleSample1', val, data)
       } else if (val == 2) {
         this.tableSelClear();
@@ -433,8 +461,9 @@ export default {
       }
     },
     handleInput(val) {
+      debugger
       if (val == 0 || val == '' || val == null) {
-        this.$refs.table12.clearSelection();
+        this.$refs.sourceTable.clearSelection();
         return
       }
 
@@ -442,26 +471,64 @@ export default {
       if (!packingList || packingList.length === 0) {
         return;
       }
-
+      // 计算 packingList 中 measureQuantity 字段的总和
+      const measureQuantitySum = packingList.reduce((sum, item) => {
+        const quantity = Number(item.measureQuantity) || 0;
+        return sum + quantity;
+      }, 0);
       const portion = Number(this.formData.portion);
+      // 清空当前选中
+      this.$refs.sourceTable.clearSelection();
+      debugger
+      if (this.form.conditionType==2){
+        // 确保 portion 不超过数据列表长度
+        const safePortion = Math.min(portion, packingList.length);
+        if (this.form.isUnpack == 2){
+          const maxQuantity = Number(packingList[0].measureQuantity);
+          if (portion > maxQuantity) {
+            this.$message.warning('取样数量不能大于计量数量!');
+            this.formData.portion = maxQuantity;
+          }
 
-      if (packingList.length > 1) {
-        if (portion > packingList.length) {
-          this.$message.warning('取样数量不能大于来源清单数量!');
-          this.formData.portion = packingList.length;
-          return;
+        }else if (this.form.isUnpack == 1){
+          if (portion > packingList.length) {
+            this.$message.warning('取样数量不能大于来源清单数量!');
+            this.formData.portion = packingList.length;
+          }
         }
-        packingList.slice(0, this.formData.portion).forEach(row => {
-          this.$refs.table12.toggleRowSelection(row);
+        packingList.slice(0, safePortion).forEach(row => {
+          this.$refs.sourceTable.toggleRowSelection(row);
         });
-      } else {
-        const maxQuantity = Number(packingList[0].measureQuantity);
-        if (portion > maxQuantity) {
+      }else if (this.form.conditionType==1){
+        // 确保 portion 不超过数据列表长度
+        const safePortion = Math.min(portion, measureQuantitySum);
+        if (portion > measureQuantitySum) {
           this.$message.warning('取样数量不能大于计量数量!');
-          this.formData.portion = maxQuantity;
-          return;
+          this.formData.portion = measureQuantitySum;
         }
+        // 选中前 safePortion 行
+        packingList.slice(0, safePortion).forEach(row => {
+          this.$refs.sourceTable.toggleRowSelection(row, true);
+        });
       }
+
+      // if (packingList.length > 1) {
+      //   if (portion > packingList.length) {
+      //     this.$message.warning('取样数量不能大于来源清单数量!');
+      //     this.formData.portion = packingList.length;
+      //     return;
+      //   }
+      //   packingList.slice(0, this.formData.portion).forEach(row => {
+      //     this.$refs.table12.toggleRowSelection(row);
+      //   });
+      // } else {
+      //   const maxQuantity = Number(packingList[0].measureQuantity);
+      //   if (portion > maxQuantity) {
+      //     this.$message.warning('取样数量不能大于计量数量!');
+      //     this.formData.portion = maxQuantity;
+      //     return;
+      //   }
+      // }
     },
     changeSamUnit(val) {
       console.log(val, 'dddd')
@@ -493,6 +560,9 @@ export default {
     tabsChange(val) {
       this.activeName = val
     },
+    tabsConditionType(val) {
+      this.conditionType = val
+    },
     checkSelectable(row, index) {
       // 只有当质检方式为抽检(qualityMode=2)时   类型不是生产检验  才可选
       return this.form.qualityType != 2 && this.form.qualityMode === 2;

+ 203 - 35
src/views/inspectionWork/edit.vue

@@ -9,11 +9,11 @@
       <base-info ref="baseInfoRefs" v-if="form" :form="form" :btnType="type" :qualityType1="qualityType"
         @changeModel="changeModel" @changeNumber="changeNumber"></base-info>
 
-      <quality-content-tabs ref="tabsRef" :type="type" :ids="this.$route.query.id" :sample-list="sampleList"
+      <quality-content-tabs ref="tabsRef" :type="type" :ids="this.$route.query.id" :sample-list="sampleList" :activeName="activeName"
         :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" @getConditionType="getConditionType" />
+        @handleSample1="handleSample1" @handleSampleSubmit="handleSampleSubmit" @getConditionType="getConditionType"/>
     </el-card>
 
     <sampleListDialog ref="detailRef" @handleConfirm="handleConfirm" @handleDispose="handleDispose"></sampleListDialog>
@@ -99,6 +99,7 @@ export default {
       packingList: [],
       sampleList: [],
       schemeList: [],
+      activeName: null,
 
       isValid: true,
       isStatus: true,
@@ -129,14 +130,17 @@ export default {
   methods: {
     //切换检验方式
     changeModel(val, flag) {
+      debugger
 
       this.$refs.tabsRef.tableSelClear()
       this.sampleList = [];
       this.$refs.tabsRef.tabsChange('1')
+      this.$refs.tabsRef.tabsConditionType(null)
 
       this.form.qualityMode = val;
       //检验方式 全检
       if (this.form.qualityMode == 1) {
+        this.activeName = '2';
         this.form.sampleNumber = ''
         const sData = this.$refs.tabsRef.$refs.sourceTable.getData()
         if (sData.length == 0) {
@@ -148,19 +152,21 @@ export default {
         this.getProSamList(sData)
 
       } else {
+        this.activeName = '1';
         if (!flag) {
           this.sampleList = [];
         }
       }
     },
     //根据类型判断样品清单现实列表数据
-    getProSamList(list) {
+    async getProSamList(list) {
+      debugger
       //生产检验
       if (this.qualityType == 2) {
         if (this.form.qualityMode != null) {
           const ProductSampleList = [];
           console.log(list, 'list')
-          list.forEach(oldItem => {
+          for (const oldItem of list) {
             const count = oldItem.measureQuantity;
             const newMeasureQuantity = oldItem.measureQuantity / count;
             const newWeight = parseFloat((oldItem.weight / count).toFixed(2))
@@ -186,6 +192,7 @@ export default {
                   ...oldItem,
                   measureQuantity: newMeasureQuantity,
                   weight: newWeight,
+                  sampleCode: await this.getSampleCode(),
                   qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList))
                 });
               }
@@ -195,8 +202,24 @@ export default {
                 return sum + Number(item.weight || 0);
               }, 0);
               this.form.totalWeight = parseFloat(pNum.toFixed(2));
+            }else{
+              for (let i = 0; i < count; i++) {
+                ProductSampleList.push({
+                  ...oldItem,
+                  measureQuantity: newMeasureQuantity,
+                  weight: newWeight,
+                  sampleCode: await this.getSampleCode(),
+                  qualitySampleTemplateList: JSON.parse(JSON.stringify(oldItem.qualitySampleTemplateList))
+                });
+              }
+              console.log(ProductSampleList, 'ProductSampleList')
+              this.sampleList = ProductSampleList;
+              const pNum = ProductSampleList.reduce((sum, item) => {
+                return sum + Number(item.weight || 0);
+              }, 0);
+              this.form.totalWeight = parseFloat(pNum.toFixed(2));
             }
-          });
+          }
         }
       } else {
         this.sampleList = list;
@@ -277,10 +300,11 @@ export default {
     },
     //来源清单勾选事件
     handleSelectionChange1(selection) {
+debugger
 
       if (this.form.qualityMode === 2) {
         this.selectedList = selection;
-
+        this.activeName = "1";
         if (this.schemeList.length == 0) {
           for (let i = 0; i < selection.length; i++) {
             this.$set(selection[i], 'qualityStatus', 2)
@@ -295,7 +319,7 @@ export default {
           }
         }
 
-        this.sampleList = selection;
+        // this.sampleList = selection;
         //赋值取样数量
         this.form.sampleNumber = selection.length;
 
@@ -368,11 +392,66 @@ export default {
     changeSamUnit(val) {
       this.$set(this.form, 'sampleMeasureUnit', val)
     },
-    handleSample1(val, data) {
+    async handleSample1(val, data) {
+      debugger
       this.sampleList = []
+      if (this.selectedList == undefined || this.selectedList.length == 0) {
+        this.activeName = "1";
+        this.$message.warning('请先选择样品!');
+        return;
+      }
       if (val == 1) {
+        this.activeName = '2';
+        if (this.form.isUnpack == 1) {
+          for (let i = 0; i < this.selectedList.length; i++) {
+            for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
+              // 不拆计算每个重量
+              let newWeight = parseFloat((this.selectedList[i].weight / this.selectedList[i].measureQuantity).toFixed(4));
+              if (this.selectedList[i].qualitySampleTemplateList == undefined || this.selectedList[i].qualitySampleTemplateList == null || this.selectedList[i].qualitySampleTemplateList.length == 0) {
+                this.sampleList.push({
+                  ...this.selectedList[i],
+                  sampleCode: await this.getSampleCode(),
+                  measureQuantity: 1,
+                  qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList)),
+                  weight: newWeight || 0,
+                });
+              } else {
+                this.sampleList.push({
+                  ...this.selectedList[i],
+                  sampleCode: await this.getSampleCode(),
+                  measureQuantity: 1,
+                  qualitySampleTemplateList: JSON.parse(JSON.stringify(this.selectedList[i].qualitySampleTemplateList)),
+                  weight: newWeight || 0,
+                });
+              }
+            }
+          }
+        } else if (this.form.isUnpack == 2) {
+          // 不拆计算每个重量
+          let newWeight = parseFloat((this.selectedList[0].weight / this.selectedList[0].measureQuantity).toFixed(4));
+
+          for (let i = 0; i < this.selectedList[0].measureQuantity; i++) {
+            if (this.selectedList[0].qualitySampleTemplateList == undefined || this.selectedList[0].qualitySampleTemplateList == null || this.selectedList[0].qualitySampleTemplateList.length == 0){
+              this.sampleList.push({
+                ...this.selectedList[0],
+                sampleCode: await this.getSampleCode(),
+                measureQuantity: 1,
+                qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList)),
+                weight: newWeight || 0,
+              });
+            }else {
+              this.sampleList.push({
+                ...this.selectedList[0],
+                sampleCode: await this.getSampleCode(),
+                measureQuantity: 1,
+                qualitySampleTemplateList: JSON.parse(JSON.stringify(this.selectedList[0].qualitySampleTemplateList)),
+                weight: newWeight || 0,
+              });
+            }
+          }
+        }
         //取整样=勾选数据
-        this.sampleList = this.selectedList;
+        // this.sampleList = this.selectedList;
         this.$message.success('取样成功!');
       } else if (val == 2) {
         console.log(data, 'datadatadatadataxiaoyang')
@@ -381,20 +460,32 @@ export default {
     },
     handleSampleSubmit(data) {
       console.log(data, 'data123确认')
-
-      if (data.conditionType == 1) {
-        this.sampleList = this.selectedList
-      } else {
-        let measureQ = data.measureQ;
-        let unit = data.sampleUnit;
-        let nums = Number(data.portion);
-        console.log(measureQ, '计量数量')
-        console.log(unit, '所选单位')
-        console.log(nums, '数量')
-        this.getNewSampleList(measureQ, unit, nums)
-      }
+debugger
+      // if (data.conditionType == 1) {
+      //   this.sampleList = this.selectedList
+      // } else {
+      //   let measureQ = data.measureQ;
+      //   let unit = data.sampleUnit;
+      //   let nums = Number(data.portion);
+      //   console.log(measureQ, '计量数量')
+      //   console.log(unit, '所选单位')
+      //   console.log(nums, '数量')
+      //   this.getNewSampleList(measureQ, unit, nums)
+      // }
+      let measureQ = data.measureQ;
+      let unit = data.sampleUnit;
+      let nums = Number(data.portion);
+      console.log(measureQ, '计量数量')
+      console.log(unit, '所选单位')
+      console.log(nums, '数量')
+      this.getNewSampleList(measureQ, unit, nums)
     },
-    getNewSampleList(measureQ, unit, nums) {
+    //获取样品编码
+    async getSampleCode() {
+      return await getCode('sample_code');
+    },
+    async getNewSampleList(measureQ, unit, nums) {
+      debugger
       this.sampleList = [];
 
       console.log(this.selectedList, 'this.selectedList')
@@ -402,13 +493,74 @@ export default {
         this.$message.warning('请先选择来源清单!');
         return;
       }
+      this.activeName = '2';
+      if (this.form.isUnpack == 1) { // 1 拆包 2 不拆
+        let measureQuantity = 1;
+        if (this.form.conditionType == 2) {
+          measureQuantity = measureQ;
+        }
+        for (let i = 0; i < this.selectedList.length; i++) {
+          if (this.selectedList[i].qualitySampleTemplateList == undefined || this.selectedList[i].qualitySampleTemplateList == null || this.selectedList[i].qualitySampleTemplateList.length == 0){
+            this.sampleList.push({
+              ...this.selectedList[i],
+              sampleCode: await this.getSampleCode(),
+              measureQuantity: measureQuantity,
+              qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList)),
+              measureUnit: unit,
+            });
+          }else{
+            this.sampleList.push({
+              ...this.selectedList[i],
+              sampleCode: await this.getSampleCode(),
+              measureQuantity: measureQuantity,
+              qualitySampleTemplateList: JSON.parse(JSON.stringify(this.selectedList[i].qualitySampleTemplateList)),
+              measureUnit: unit,
+            });
+          }
 
-      this.sampleList = this.selectedList.map(oldItem => {
-        const newItem = JSON.parse(JSON.stringify(oldItem));
-        newItem.measureQuantity = measureQ;
-        newItem.measureUnit = unit;
-        return newItem;
-      });
+        }
+      }else if (this.form.isUnpack == 2) {
+        if (this.form.conditionType == 1) {
+          measureQ = 1;
+        }
+        // 不拆计算每个重量
+        let newWeight = parseFloat((this.selectedList[0].weight / this.selectedList[0].measureQuantity).toFixed(4));
+
+        for (let i = 0; i < nums; i++) {
+          if (this.selectedList[0].qualitySampleTemplateList == undefined || this.selectedList[0].qualitySampleTemplateList == null || this.selectedList[0].qualitySampleTemplateList.length == 0){
+            this.sampleList.push({
+              ...this.selectedList[0],
+              sampleCode: await this.getSampleCode(),
+              measureQuantity: measureQ,
+              qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList)),
+              measureUnit: unit,
+              weight: newWeight || 0,
+            });
+          }else {
+            this.sampleList.push({
+              ...this.selectedList[0],
+              sampleCode: await this.getSampleCode(),
+              measureQuantity: measureQ,
+              qualitySampleTemplateList: JSON.parse(JSON.stringify(this.selectedList[0].qualitySampleTemplateList)),
+              measureUnit: unit,
+              weight: newWeight || 0,
+            });
+            // this.sampleList.push({
+            //   ...this.selectedList[0],
+            //   sampleCode: await this.getSampleCode(),
+            //   measureQuantity: measureQ,
+            //   measureUnit: unit,
+            //   weight: newWeight || 0,
+            // });
+          }
+        }
+      }
+      // this.sampleList = this.selectedList.map(oldItem => {
+      //   const newItem = JSON.parse(JSON.stringify(oldItem));
+      //   newItem.measureQuantity = measureQ;
+      //   newItem.measureUnit = unit;
+      //   return newItem;
+      // });
 
       this.$refs.tabsRef.tabsChange('2')
     },
@@ -610,6 +762,7 @@ export default {
     //确认质检
     handleConfirm(list, index) {
       console.log(list)
+      debugger
 
       // 检查有效性
       // for (const item of list) {
@@ -624,13 +777,27 @@ export default {
       // }
       console.log(list, 'listlistlistlist')
       list.forEach((item) => {
-        if (item.qualitySampleTemplateList.some(child => child.qualityResults === 2)) {
-          item.isValid = false;
-          item.qualityResults = 2;
-        }
-        else {
-          item.isValid = true;
-          item.qualityResults = 1;
+        if (item.qualitySampleTemplateList.length == 1){
+          if (item.qualitySampleTemplateList.some(child => child.qualityResults === 3)) { // 如果质检项只有一条而且结果为让步接收那么整个就是让步接收
+            item.isValid = false;
+            item.qualityResults = 3;
+          }else if (item.qualitySampleTemplateList.some(child => child.qualityResults === 2)) {
+            item.isValid = false;
+            item.qualityResults = 2;
+          }
+          else {
+            item.isValid = true;
+            item.qualityResults = 1;
+          }
+        }else{
+          if (item.qualitySampleTemplateList.some(child => child.qualityResults === 2)) {
+            item.isValid = false;
+            item.qualityResults = 2;
+          }
+          else {
+            item.isValid = true;
+            item.qualityResults = 1;
+          }
         }
         item.qualityStatus = 1;
       })
@@ -639,6 +806,7 @@ export default {
       } else {
         this.$set(this.sampleList, null, list);
       }
+      this.activeName = '2';
       console.log(this.sampleList, '222表')
 
     },