Ver código fonte

修改质检工单的bug

wsx 11 meses atrás
pai
commit
df1b11dbd6

+ 2 - 2
src/views/inspectionWork/components/baseInfo.vue

@@ -587,8 +587,8 @@
       // 人员选择
       changeExecutor(val) {
         if (val) {
-          this.form.executeId = val;
-          this.form.executeName = this.executorList.filter(
+          this.form.qualityId = val;
+          this.form.qualityName = this.executorList.filter(
             (item) => item.id === val
           )[0].name;
         }

+ 22 - 13
src/views/inspectionWork/components/newQualityContentTabs.vue

@@ -715,6 +715,8 @@
       },
       // 分页后的样品列表
       paginatedSampleList() {
+        console.log(this.sampleList);
+
         const { currentPage, pageSize } = this.samplePagination;
         const start = (currentPage - 1) * pageSize;
         const end = start + pageSize;
@@ -973,26 +975,33 @@
         const strings = this.templateList.map((item) => JSON.stringify(item));
         const removeDupList = [...new Set(strings)];
         const result = removeDupList.map((item) => JSON.parse(item));
-        this.templateList = result.map(item=>{
-          item['qualityResults']=1
-          return item
+        this.templateList = result.map((item) => {
+          item['qualityResults'] = 1;
+          return item;
         });
         // console.log(this.templateList);
-        this.sampleList.forEach((item,index)=>{
-          this.$set(this.sampleList[index],'qualitySampleTemplateList',this.templateList)
-        })
+        this.sampleList.forEach((item, index) => {
+          this.$set(
+            this.sampleList[index],
+            'qualitySampleTemplateList',
+            this.templateList
+          );
+        });
         this.schemePagination.total = this.templateList.length;
       },
       handDel(index) {
         console.log(index);
         this.templateList.splice(index, 1);
-        this.sampleList.forEach((item,index)=>{
-          this.$set(this.sampleList[index],'qualitySampleTemplateList',this.templateList.map(item=>{
-            item['qualityResults']=1
-          return item
-          }))
-
-        })
+        this.sampleList.forEach((item, index) => {
+          this.$set(
+            this.sampleList[index],
+            'qualitySampleTemplateList',
+            this.templateList.map((item) => {
+              item['qualityResults'] = 1;
+              return item;
+            })
+          );
+        });
       }
     }
   };

+ 133 - 16
src/views/inspectionWork/edit.vue

@@ -193,28 +193,17 @@
       //切换检验方式
       changeModel(val, flag) {
         console.log('切换检验方式');
-        
+
         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) {
-            for (let i = 0; i < sData.length; i++) {
-              this.$set(sData[i], 'qualityStatus', 2);
-            }
-          }
-          console.log(
-            this.$refs.tabsRef.$refs.sourceTable.getData(),
-            'packingList'
-          );
-          this.getProSamList(sData);
+          this.changeGetSampleList(this.inventoryList);
         } else {
           this.activeName = '1';
           if (!flag) {
@@ -299,6 +288,129 @@
           this.sampleList = this.addStatus;
         }
       },
+      // 创建计量数量为1的样品清单函数,用于计数类型的
+      async createSampleList(list) {
+        if (this.form.qualityMode != null) {
+          const ProductSampleList = [];
+          console.log(list, 'list');
+          for (const oldItem of list) {
+            const count = oldItem.measureQuantity;
+            const newMeasureQuantity = oldItem.measureQuantity / count;
+            const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
+
+            console.log(typeof oldItem.qualitySampleTemplateList, 'ssssss');
+
+            // 遍历新数组设置 qualityResults 默认值
+            this.schemeList.forEach((item) => {
+              if (typeof item === 'object' && item !== null) {
+                item.qualityResults = 1; // 设置默认值
+              }
+              delete item.id;
+            });
+
+            console.log(oldItem, 'oldItem');
+            console.log(count, newMeasureQuantity, newWeight);
+            delete oldItem.id;
+
+            if (
+              oldItem.qualitySampleTemplateList == undefined ||
+              oldItem.qualitySampleTemplateList == null ||
+              oldItem.qualitySampleTemplateList.length == 0
+            ) {
+              oldItem.qualitySampleTemplateList = JSON.parse(
+                JSON.stringify(this.schemeList)
+              );
+              for (let i = 0; i < count; i++) {
+                ProductSampleList.push({
+                  ...oldItem,
+                  measureQuantity: newMeasureQuantity,
+                  weight: newWeight,
+                  sampleCode: await this.getSampleCode(),
+                  qualitySampleTemplateList: JSON.parse(
+                    JSON.stringify(this.schemeList)
+                  )
+                });
+              }
+              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 {
+              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));
+            }
+          }
+        }
+      },
+      // 全检计量计重的样品清单函数
+      async updatePackingList(list, sampleCount) {
+        // for (let i = 0; i < list.length; i++) {
+        //   list[i].sampleCode = await this.getSampleCode();
+        // }
+
+        const dataList = [];
+        let currentNum = sampleCount - list.length;
+        let currentNum1 = sampleCount;
+        // console.log(this.selectedList);
+
+        for (const item of list) {
+          const qualitySampleTemplateList = item.qualitySampleTemplateList
+            ?.length
+            ? JSON.parse(JSON.stringify(item.qualitySampleTemplateList))
+            : JSON.parse(
+                JSON.stringify(
+                  this.schemeList.map((item) => {
+                    item['qualityResults'] = 1;
+                    return item;
+                  })
+                )
+              );
+
+          if (sampleCount >= list.length) {
+            dataList.push({
+              ...item,
+              measureQuantity: item.measureQuantity, //作为计量数量
+              sampleCode: await this.getSampleCode(),
+              qualitySampleTemplateList
+            });
+          }
+        }
+
+        this.sampleList = dataList;
+        this.sampleNumber = this.sampleList.length;
+      },
+      // 切换检验方式为全检后生成样品
+      changeGetSampleList(list) {
+        console.log(list);
+        console.log(this.form.total);
+
+        // 计量类型1是数量,2是重量
+        if (this.form.inspectionStandards == 1) {
+          this.createSampleList(list);
+        }
+        if (this.form.inspectionStandards == 2) {
+          this.updatePackingList(list, this.form.total);
+          // this.handleWeightFullSample(this.form.total);
+        }
+      },
+
       //输入取样数量
       changeNumber(val) {
         if (this.form.qualityMode !== 2) {
@@ -470,6 +582,7 @@
         // await this.queryQualityInventory()
         // 质检方案
         await this.queryQualityTempleContent();
+        // 样品清单
         await this.queryQualitySamplContent();
         // 来源清单
         await this.getQueryQualityInventory();
@@ -615,7 +728,7 @@
             console.log(222222222222222222);
             await this.handleWeightFullSample(sampleCount);
           }
-        this.activeName = '2';
+          this.activeName = '2';
 
           this.$refs.tabsRef.tabsChange('2');
         } catch (error) {
@@ -798,8 +911,7 @@
           delete this.form['qualityTimeEnd'];
 
           console.log(this.sampleList);
-          // return
-          
+         
 
           let params = {
             ...this.form,
@@ -810,6 +922,7 @@
             qualityInventoryList: this.inventoryList
           };
           console.log(params, 'params ----');
+        
           URL(params)
             .then((msg) => {
               this.loading = false;
@@ -1301,9 +1414,13 @@
       },
 
       async handleWeightFullSample(sampleCount) {
+        console.log(sampleCount);
+
         const dataList = [];
         let currentNum = sampleCount - this.selectedList.length;
         let currentNum1 = sampleCount;
+        console.log(this.selectedList);
+
         for (const item of this.selectedList) {
           const qualitySampleTemplateList = item.qualitySampleTemplateList
             ?.length

+ 4 - 2
src/views/inspectionWork/index.vue

@@ -423,7 +423,9 @@
         return getList({
           ...where,
           pageNum: page,
-          size: limit
+          size: limit,
+          // status: 0,
+          // qualityMode:'02'
         });
       },
       search(where) {
@@ -449,7 +451,7 @@
                 const id = type !== 'add' ? row.id : '';
                 const qualityType = type !== 'add' ? row.qualityType : null;
                 const qualityTimeStart = row.qualityTimeStart || '';
-
+                // qualityType是质检类型 来料,生产
                 this.$router.push({
                   path: '/inspectionWork/edit',
                   query: {