From 7609c865e80fea169c5c393c55631628aef2f6ed Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 24 九月 2025 17:15:04 +0800
Subject: [PATCH] 核磅录入创建核磅单的创建逻辑修改/重复扫码相同数据添加多条问题修复

---
 pages/wareHouse/nuclearScale/index.vue |  153 +++++++++++++++++++++++++++++++++------------------
 1 files changed, 99 insertions(+), 54 deletions(-)

diff --git a/pages/wareHouse/nuclearScale/index.vue b/pages/wareHouse/nuclearScale/index.vue
index cedb44e..61643e5 100644
--- a/pages/wareHouse/nuclearScale/index.vue
+++ b/pages/wareHouse/nuclearScale/index.vue
@@ -170,7 +170,7 @@
                   <view class="_label-name">鐩橀噸锛�</view>
                 </view>
                 <view class="_content">
-                  {{ item.trayWeight }}
+                  {{ item.tareWeight }}
                 </view>
               </view>
               <view class="row-list">
@@ -186,7 +186,7 @@
         </u-cell-group>
       </scroll-view>
     </view>
-    <!-- 瀵间綋 -->
+    <!-- 閾滄潌 -->
     <u-modal
       v-model="showModal"
       title=""
@@ -216,7 +216,7 @@
               <view class="packing-registration-param-item-right">
                 <u-input
                   class="item-one item-two"
-                  v-model="modalList.suppliedQuantity"
+                  v-model="modalList.forkliftWeight"
                 />
               </view>
             </view>
@@ -224,7 +224,12 @@
         </view>
       </view>
     </u-modal>
-    <u-button type="primary" class="bottom-button" @click="submit"
+    <u-button
+      type="primary"
+      class="bottom-button"
+      @click="submit"
+      :disabled="ScanCodeRecord.length == 0"
+      v-show="form.productType != 'TG01'"
       >鎻愪氦</u-button
     >
     <u-modal
@@ -233,11 +238,7 @@
       content="鏄惁纭鎻愪氦"
       show-cancel-button
     ></u-modal>
-    <saveForm
-      ref="saveForm"
-      :operationTaskList="this.form"
-      @update="handleUpdate"
-    />
+    <saveForm ref="saveForm" :operationTaskList="form" @update="handleUpdate" />
     <scan></scan>
   </div>
 </template>
@@ -269,19 +270,7 @@
         backgroundRepeat: "no-repeat",
       },
       show: false,
-      form: {
-        value0: "",
-        verificationNo: "",
-        productType: "",
-        licensePlate: "",
-        shippingNoticeNo1: "",
-        customerName1: "",
-        weighingOperator: "",
-        forkliftOperator: "",
-        value8: "",
-        shippingNoticeNo2: "",
-        customerName2: "",
-      },
+      form: {},
       rules: {
         verificationNo: [
           {
@@ -313,26 +302,33 @@
       console.log("椤甸潰鎵爜缁撴灉锛�", data.code);
       if (data.code) {
         let codeInfo = JSON.parse(data.code);
-        // try {
-        // } catch (e) {
-        // 	uni.showToast({
-        // 		icon: "none",
-        // 		title: "鎵爜鏁版嵁瑙f瀽澶辫触锛岃閲嶈瘯锛�",
-        // 		duration: 2 * 1000,
-        // 	});
-        // 	return;
-        // }
+
+        // 娣诲姞閲嶅鎵爜妫�鏌�
+        const batchNo = codeInfo.BN;
+        const isDuplicate = that.ScanCodeRecord.some(
+          (item) => item.outBatchNo === batchNo
+        );
+
+        if (isDuplicate) {
+          uni.showToast({
+            icon: "none",
+            title: "璇峰嬁閲嶅鎵爜锛�",
+            duration: 2 * 1000,
+          });
+          return;
+        }
+
         let ScanCodeRecordList = {
           outBatchNo: codeInfo.BN,
           netWeight: codeInfo.NW,
           tareWeight: codeInfo.TR, // 鐨噸
           partNo: codeInfo.PN,
           grossWeight: codeInfo.TW,
-          partNo: codeInfo.partNo,
           partName: codeInfo.ST,
           originalLength: codeInfo.LN, // 闀垮害
           palletNo: codeInfo.PNO, // 鐩樺彿
           waivDevRejNo: codeInfo.WDR ? codeInfo.WDR : "*", // wdr鍙�
+          productType: that.form.productType,
         };
         if (codeInfo.CN != that.form.customerName1) {
           // 鎵弿鎶ュ伐鍗曚簩缁寸爜
@@ -341,11 +337,22 @@
             content:
               "瀹㈡埛涓嶄竴鑷达細" + codeInfo.CN + "||" + that.form.customerName1,
             showCancel: true,
-            success: function () {
-              if (that.form.productType == "TG01") {
-                that.$refs.saveForm.open(ScanCodeRecordList);
+            success: function (res) {
+              const isDuplicate = that.ScanCodeRecord.some(
+                (item) => item.outBatchNo === codeInfo.BN
+              );
+              if (!isDuplicate) {
+                if (that.form.productType == "TG01") {
+                  that.$refs.saveForm.open(ScanCodeRecordList);
+                } else {
+                  that.ScanCodeRecord.push(ScanCodeRecordList);
+                }
               } else {
-                that.ScanCodeRecord.push(ScanCodeRecordList);
+                uni.showToast({
+                  icon: "none",
+                  title: "璇峰嬁閲嶅鎵爜锛�",
+                  duration: 2 * 1000,
+                });
               }
             },
           });
@@ -379,22 +386,31 @@
     },
     // 瀵间綋鎻愪氦
     confirmDt() {
+      // 璁$畻grossWeight鎬诲拰
+      let grossWeightSum = 0;
+      // 纭繚ScanCodeRecord鏄暟缁�
+      if (Array.isArray(this.ScanCodeRecord)) {
+        this.ScanCodeRecord.forEach((item) => {
+          grossWeightSum += Number(item.grossWeight) || 0;
+        });
+      }
+      // 浣跨敤姝g‘鐨勫瓧娈靛悕suppliedQuantity锛岃�屼笉鏄痸oltage
       const magnetic =
-        Number(this.form.verificationWeight) -
-        Number(this.form.voltage) -
-        Number(this.form.reelWeight);
-      console.log("淇濆瓨", this.form.verificationNo);
+        Number(this.modalList.verificationWeight) -
+        Number(this.modalList.forkliftWeight) -
+        grossWeightSum;
+      this.form.verificationWeight = this.modalList.verificationWeight;
+      this.form.forkliftWeight = this.modalList.forkliftWeight;
       switch (this.form.productType) {
-        case "瀵间綋":
-          if (magnetic > 0 && magnetic < 3) {
+        case "DT01":
+          if (magnetic >= 0 && magnetic <= 3) {
             this.allSubmit();
-            // this.ScanCodeRecord.push(this.form);
           } else {
             this.$u.toast("鐢熶骇鏍告煡");
           }
           break;
-        case "瀵间綋2.6":
-          if (magnetic > -0.5 && magnetic < 0.5) {
+        case "DT02":
+          if (magnetic >= -0.5 && magnetic <= 0.5) {
             // this.ScanCodeRecord.push(this.form);
             this.allSubmit();
           } else {
@@ -404,22 +420,29 @@
       }
     },
     allSubmit() {
+      this.ScanCodeRecord.forEach((item) => {
+        item.batchNo = item.outBatchNo;
+      });
       this.form = {
         ...this.form,
         weighingVerificationList: this.ScanCodeRecord,
+        verificationWeight: this.modalList.verificationWeight,
+        forkliftWeight: this.modalList.forkliftWeight,
       };
+      console.log("11111111111", this.form);
       // 澶勭悊鎻愪氦閫昏緫
       this.$u.api.NuclearScaleEntry.createDetail(this.form)
         .then((res) => {
-          if (res.success) {
-            this.$u.toast("鎻愪氦鎴愬姛");
-          } else {
-            this.$u.toast(res.message || "鎻愪氦澶辫触");
-          }
+          this.$u.toast("鎻愪氦鎴愬姛");
+          this.ScanCodeRecord = [];
         })
-        .catch(() => {
+        .catch((err) => {
           uni.hideLoading();
-          this.$u.toast("缃戠粶寮傚父锛岃閲嶈瘯");
+          uni.showToast({
+            title: err.message || "缃戠粶寮傚父锛岃閲嶈瘯",
+            icon: "none",
+          });
+          // this.$u.toast(err.message || "缃戠粶寮傚父锛岃閲嶈瘯");
         });
     },
 
@@ -428,11 +451,31 @@
       this.showModal = false;
     },
     handleUpdate(Obj) {
-      this.ScanCodeRecord.push(Obj);
+      console.log("1111111111111111閾滄潌", Obj);
+      Obj.batchNo = Obj.outBatchNo;
+      this.form = {
+        ...this.form,
+        weighingVerificationList: [Obj],
+        verificationWeight: Obj.verificationWeight,
+        forkliftWeight: Obj.forkliftWeight,
+      };
+      console.log("11111111111", this.form);
+      // 澶勭悊鎻愪氦閫昏緫
+      this.$u.api.NuclearScaleEntry.createDetail(this.form)
+        .then((res) => {
+          this.$u.toast("鎻愪氦鎴愬姛");
+          this.ScanCodeRecord.push(Obj);
+          this.$refs.saveForm.cancel();
+        })
+        .catch(() => {
+          uni.hideLoading();
+          this.$refs.saveForm.cancel();
+          this.$u.toast("缃戠粶寮傚父锛岃閲嶈瘯");
+        });
     },
     // 鎻愪氦鎸夐挳
     submit() {
-      if (that.form.productType != "TG01") {
+      if (this.form.productType != "TG01") {
         this.showModal = true;
       } else {
         this.allSubmit();
@@ -442,6 +485,7 @@
     confirm() {
       console.log("淇濆瓨", this.form.verificationNo);
       // 璇锋眰鎺ュ彛锛屾牴鎹伐鍗曞彿鏌ヨ鍏朵粬淇℃伅骞惰祴鍊�
+      // this.allSubmit();
     },
     // 閫夋嫨璁㈠崟鍙�
     openList() {
@@ -466,6 +510,7 @@
     // 瀛樿鍗曞彿
     setNo(val) {
       this.form = val;
+      this.ScanCodeRecord = [];
     },
     // 鍥炴樉鎵爜鐨勪俊鎭�-鎶ュ伐鍗�
     // saveForm(val) {

--
Gitblit v1.9.3