н¨Îļþ¼Ð/PDA/pages/stash/CheckFinish.vue
@@ -16,12 +16,18 @@
                  </uni-forms-item>
                  <uni-forms-item :label="order_qty">
                  </uni-forms-item>
                  <uni-forms-item label="待扫物料编码:">
                  <uni-easyinput type="text" placeholder="请扫描物料编码" ref='materialInput'
                     :focus="step === 1" v-model="materialCode"
                     @confirm="materialCodeInput"
                     @blur="materialCodeInput" />
                  </uni-forms-item>
                  <uni-forms-item label="库位编号:">
                     <uni-easyinput type="text" placeholder="请扫描库位编号" ref='midInput' :focus="!focus"
                     <uni-easyinput type="text" placeholder="请扫描库位编号" ref='midInput' :focus="step === 2"
                        v-model="barcode" @confirm="barcodeInput" />
                  </uni-forms-item>
                  <uni-forms-item label="实盘数量:">
                     <uni-easyinput type="text" placeholder="请输入实盘数量" ref='midInput' :focus="focus"
                     <uni-easyinput type="text" placeholder="请输入实盘数量" ref='midInput' :focus="step === 3"
                        v-model="materSn" @confirm="snInput" />
                  </uni-forms-item>
@@ -37,7 +43,7 @@
                     <view style="display: flex;justify-content: space-around;margin-top: 2%;">
                        <!-- <button @click="reset" type="default" size="default"
                           style="width: 160rpx;border: 1rpx solid #007aff;color: #007aff;">重置</button> -->
                        <button @click="submit" type="primary" size="default" style="width: 200rpx;">盘点完成</button>
                        <button @click="submit" type="primary" size="default" style="width: 250rpx;">盘点完成</button>
                     </view>
                  </uni-forms-item>
               </uni-forms>
@@ -167,7 +173,10 @@
            Testcheck: false,
            pkmaterSn: "",
            pkmatInfos: [],
            addressdisabled: false
            addressdisabled: false,
            materialCode: "", // æ–°å¢žï¼šæ‰«æçš„物料编码
            materialCodeValid: false, // æ–°å¢žï¼šç‰©æ–™ç¼–码验证状态
            step: 1, // æ–°å¢žï¼š1-物料编码,2-库位编号,3-入库数量
         }
      },
      onShow() {},
@@ -185,9 +194,60 @@
         this.order_qty="账面数量:"+res.stockQuantity;
         this.order_Inqty="物料名称:"+res.materielName;
         this.goods_no="物料编号:"+res.materielCode;
         this.materielCode = res.materielCode;  // è®¾ç½®ç”¨äºŽéªŒè¯çš„物料编码
         // this.getData();
      },
      methods: {
         // ç‰©æ–™ç¼–码验证
materialCodeInput() {
    console.log("materialCodeInput è¢«è§¦å‘");
    console.log("输入值:", this.materialCode);
    this.$nextTick(() => {
        if (this.materialCode.trim() !== "") {
            const scannedCode = this.materialCode.trim();
            const expectedCode = this.materielCode;
            console.log("扫描编码:", scannedCode);
            console.log("期望编码(materielCode):", expectedCode);
            if (scannedCode === expectedCode) {
                this.materialCodeValid = true;
                console.log("✅ ç‰©æ–™ç¼–码验证成功");
                // éªŒè¯æˆåŠŸåŽä¸æ¸…ç©ºå€¼ï¼Œç›´æŽ¥åˆ‡æ¢åˆ°ä¸‹ä¸€æ­¥
                this.step = 2;
                this.$refs.uToast.show({
                    title: "物料编码验证成功",
                    type: "success"
                });
                // ä½¿ç”¨ $nextTick ç¡®ä¿ç„¦ç‚¹åˆ‡æ¢åœ¨ DOM æ›´æ–°åŽæ‰§è¡Œ
                this.$nextTick(() => {
                    // è®©åº“位编号输入框获得焦点
                    this.$refs.midInput.focus();
                });
            } else {
                this.materialCodeValid = false;
                console.log("❌ ç‰©æ–™ç¼–码验证失败");
                this.$refs.uToast.show({
                    title: `物料编码不匹配`,
                    type: "error"
                });
                // éªŒè¯å¤±è´¥æ—¶æ¸…空值并保持焦点在物料编码输入框
                setTimeout(() => {
                    this.materialCode = "";
                    this.step = 1;
                    // ç¡®ä¿ç„¦ç‚¹å›žåˆ°ç‰©æ–™ç¼–码输入框
                    this.$nextTick(() => {
                        this.$refs.materialInput.focus();
                    });
                }, 500);
            }
        }
    });
},
         // voiceSpeech(src) {
         //    innerAudioContext.src = src; // '../../static/success.mp3';
         //    innerAudioContext.play();
@@ -234,19 +294,23 @@
            }
         },
         barcodeInput() {
            this.$nextTick(function(x) {
            this.$nextTick(() => {
               if (this.barcode.length > 0) {
                  // if (this.barcode.substring(0, 1) == 'A' || this.barcode.substring(0, 2) == 'TP') {
                  this.focus = true;
                  // } else {
                  //    this.$refs.uToast.show({
                  //       title: "扫码错误,请扫描托盘码",
                  //       type: "error"
                  //    })
                  // }
                  this.step = 3; // åˆ‡æ¢åˆ°å…¥åº“数量
                  this.$refs.uToast.show({
                     title: "库位编号扫描成功",
                     type: "success"
                  });
                  // æ·»åŠ å»¶æ—¶ç¡®ä¿æ‰«ç å®Œæˆ
                  setTimeout(() => {
                     this.$nextTick(() => {
                        this.$refs.midInput.focus();
                     });
                  }, 100);
               }
            })
         },
         snInput() {
            this.$nextTick(() => {
               if (this.materSn != "") {
@@ -438,56 +502,160 @@
               }
            })
         },
         submit() {
            if (this.barcode == "") {
               this.$refs.uToast.show({
                  title: "请扫描货位编号",
                  type: 'error'
               })
               return;
            }
            if (this.materSn.length == 0) {
               this.$refs.uToast.show({
                  title: "请输入实盘数量",
                  type: 'error'
               })
               return;
            }
         // submit() {
         //    if (this.barcode == "") {
         //       this.$refs.uToast.show({
         //          title: "请扫描货位编号",
         //          type: 'error'
         //       })
         //       return;
         //    }
         //    if (this.materSn.length == 0) {
         //       this.$refs.uToast.show({
         //          title: "请输入实盘数量",
         //          type: 'error'
         //       })
         //       return;
         //    }
         //    this.$u.post('/api/DeliveryOrder/CheckFinish', {
         //       MainData: {
         //          "locationCode": this.barcode,
         //          "taskId":this.taskId,
         //          // "warehouseCode": this.warehouseId,
         //          // "orderNo": this.orderNo,
         //          "qty": this.materSn,
         //          // "batchNo": this.batchNo,
         //       },
         //       // DelKeys: this.sns
         //    }).then(res => {
         //       this.Testcheck = false;
         //       if (res.status) {
         //          this.$refs.uToast.show({
         //             title: "盘点成功",
         //             type: "success"
         //          })
         //          // this.Inqty=res.message;
         //          // this.order_Inqty="已出库数量:"+this.Inqty;
         //          this.barcode="";
         //          // uni.setStorageSync('checkTask',true);
         //    //关键修改:使用 getCurrentPages èŽ·å–å‰ä¸€ä¸ªé¡µé¢å¹¶ç›´æŽ¥è°ƒç”¨å…¶æ–¹æ³•   Y
         //    const pages = getCurrentPages();
         //    const prevPage = pages[pages.length - 2]; // èŽ·å–ä¸Šä¸€ä¸ªé¡µé¢å®žä¾‹
         //    console.log('前一个页面:', prevPage);
         //    if (prevPage && prevPage.refreshData) {
         //       // ç›´æŽ¥è°ƒç”¨ä¸Šä¸€ä¸ªé¡µé¢çš„刷新方法
         //       prevPage.refreshData();
         //       console.log('已调用前一个页面的盘点刷新方法');
         //    }
         //    setTimeout(() => {
         //              uni.navigateBack({
         //                  delta: 1
         //              });
         //          }, 300);
         //          // this.materSn="";
         //       } else {
         //          this.$refs.uToast.show({
         //             title: res.message,
         //             type: "error"
         //          })
         //       }
         //    })
         // }
      submit() {
      if (!this.materialCodeValid) {
         this.$refs.uToast.show({
         title: "请先扫描并验证物料编码",
         type: 'error'
         });
         return;
      }
      if (this.barcode == "") {
         this.$refs.uToast.show({
         title: "请扫描货位编号",
         type: 'error'
         })
         return;
      }
      if (this.materSn.length == 0) {
         this.$refs.uToast.show({
         title: "请输入实盘数量",
         type: 'error'
         })
         return;
      }
      // æ–°å¢žäºŒæ¬¡ç¡®è®¤é€»è¾‘
      uni.showModal({
         title: '确认盘点',
         content: '您确定要提交盘点信息吗?',
         success: (res) => {
         if (res.confirm) {
            // æ˜¾ç¤ºåŠ è½½ä¸­
            uni.showLoading({
            title: '提交中...',
            mask: true
            });
            this.$u.post('/api/DeliveryOrder/CheckFinish', {
               MainData: {
                  "locationCode": this.barcode,
                  "taskId":this.taskId,
                  // "warehouseCode": this.warehouseId,
                  // "orderNo": this.orderNo,
                  "qty": this.materSn,
                  // "batchNo": this.batchNo,
               },
               // DelKeys: this.sns
            MainData: {
               "locationCode": this.barcode,
               "taskId": this.taskId,
               "qty": this.materSn,
            },
            }).then(res => {
               this.Testcheck = false;
               if (res.status) {
                  this.$refs.uToast.show({
                     title: "盘点成功",
                     type: "success"
                  })
                  // this.Inqty=res.message;
                  // this.order_Inqty="已出库数量:"+this.Inqty;
                  this.barcode="";
                  // uni.setStorageSync('checkTask',true);
                  setTimeout(() => {
                      uni.navigateBack({
                          delta: 1
                      });
                  }, 300);
                  // this.materSn="";
               } else {
                  this.$refs.uToast.show({
                     title: res.message,
                     type: "error"
                  })
               }
            })
            uni.hideLoading();
            this.Testcheck = false;
            if (res.status) {
               this.$refs.uToast.show({
               title: "盘点成功",
               type: "success"
               })
               // æ‰‹åŠ¨æ¸…ç©ºæ‰€æœ‰è¾“å…¥æ•°æ®
               this.materialCode = "";
               this.materialCodeValid = false;
               this.barcode = "";
               this.materSn = "";
               this.step = 1;  // é‡ç½®æ­¥éª¤åˆ°ç¬¬ä¸€æ­¥
               // è®¾ç½®ç›˜ç‚¹ä¸“用的刷新标记
               uni.setStorageSync('needRefreshCheck', true);
               // å»¶è¿Ÿè¿”回,让B页面刷新数据
               setTimeout(() => {
               uni.navigateBack({
                  delta: 1
               });
               }, 500);
               // ä½¿ç”¨ $nextTick ç¡®ä¿ç„¦ç‚¹è®¾ç½®åœ¨ DOM æ›´æ–°åŽæ‰§è¡Œ
               this.$nextTick(() => {
               // ç¡®ä¿ç‰©æ–™ç¼–码输入框获得焦点
               this.$refs.materialInput.focus();
               });
            } else {
               this.$refs.uToast.show({
               title: res.message,
               type: "error"
               })
            }
            }).catch(err => {
            uni.hideLoading();
            this.$refs.uToast.show({
               title: "请求失败,请重试",
               type: "error"
            });
            });
         }
         }
      });
      }
      }
   }
</script>