pages/wareHouse/inventory/index.vue
@@ -1,10 +1,20 @@
<template>
   <view class="page">
      <view class="packing-registration-bg" />
      <u-navbar title="库存盘点" :background="background" :border-bottom="false" :title-bold="true" title-color="#000"
         back-icon-color="#000">
    <u-navbar
      title="库存盘点"
      :background="background"
      :border-bottom="false"
      :title-bold="true"
      title-color="#000"
      back-icon-color="#000"
    >
         <template #right>
            <text style="font-size:14px;margin-right:14px;font-weight:bold"  @click="goSubmit">提交</text>
        <text
          style="font-size: 14px; margin-right: 14px; font-weight: bold"
          @click="goSubmit"
          >提交</text
        >
         </template>
      </u-navbar>
      <view class="packing-registration-param">
@@ -14,10 +24,16 @@
                  <text class="item-one">盘点报告号</text>
               </view>
               <view class="packing-registration-param-item-right">
                  <text class="item-one item-two" @click="seachPersonnelNo()">{{ registerInfo.value1 == '' ?
                     "点击选择" : registerInfo.value1 }}</text>
                  <u-icon name="arrow-right" color="#687792" size="28" @click="seachPersonnelNo()"
                     v-show="registerInfo.value1 == ''"></u-icon>
            <text class="item-one item-two" @click="seaRchPersonnelNo()">{{
              registerInfo.invListNo == "" ? "点击选择" : registerInfo.invListNo
            }}</text>
            <u-icon
              name="arrow-right"
              color="#687792"
              size="28"
              @click="seaRchPersonnelNo()"
              v-show="registerInfo.invListNo == ''"
            ></u-icon>
               </view>
            </view>
            <view class="packing-registration-param-item param-extra">
@@ -25,7 +41,9 @@
                  <text class="item-one">仓库</text>
               </view>
               <view class="packing-registration-param-item-right">
                  <text class="item-one item-two">{{ registerInfo.value2 }}</text>
            <text class="item-one item-two">{{
              registerInfo.warehouseId
            }}</text>
               </view>
            </view>
            <view class="packing-registration-param-item param-extra">
@@ -34,45 +52,83 @@
               </view>
               <view class="packing-registration-param-item-right">
                  <view class="item-one item-two" @click="openPN()">
                     <text>{{ registerInfo.value6 == '' ? "点击输入" : registerInfo.value6 }}</text>
              <text>{{
                registerInfo.partNo == "" ? "点击输入" : registerInfo.partNo
              }}</text>
                  </view>
                  <u-icon name="arrow-right" color="#687792" size="28"
                     v-show="registerInfo.value6 == ''"></u-icon>
            <u-icon
              name="arrow-right"
              color="#687792"
              size="28"
              v-show="registerInfo.partNo == ''"
            ></u-icon>
               </view>
            </view>
            <view class="packing-registration-param-item param-extra">
               <view class="packing-registration-param-item-left">
                  <text class="item-one">批次号</text>
               </view>
               <view class="packing-registration-param-item-right" @click="openBatch()">
                  <text
                     class="item-one item-two">{{ registerInfo.value3 == '' ? "点击输入" : registerInfo.value3 }}</text>
                  <u-icon name="arrow-right" color="#687792" size="28"
                     v-show="registerInfo.value3 == ''"></u-icon>
          <view
            class="packing-registration-param-item-right"
            @click="openBatch()"
          >
            <text class="item-one item-two">{{
              registerInfo.ifsBatchNo == ""
                ? "点击输入"
                : registerInfo.ifsBatchNo
            }}</text>
            <u-icon
              name="arrow-right"
              color="#687792"
              size="28"
              v-show="registerInfo.ifsBatchNo == ''"
            ></u-icon>
               </view>
            </view>
            <view class="packing-registration-param-item param-extra">
               <view class="packing-registration-param-item-left">
                  <text class="item-one">库位号</text>
               </view>
               <view class="packing-registration-param-item-right" @click="openLocation()">
          <view
            class="packing-registration-param-item-right"
            @click="openLocation()"
          >
                  <view class="item-one item-two">
                     <text>{{ registerInfo.value4 == '' ? "点击输入" : registerInfo.value4 }}</text>
              <text>{{
                registerInfo.locationNo == ""
                  ? "点击输入"
                  : registerInfo.locationNo
              }}</text>
                  </view>
                  <u-icon name="arrow-right" color="#687792" size="28"
                     v-show="registerInfo.value4 == ''"></u-icon>
            <u-icon
              name="arrow-right"
              color="#687792"
              size="28"
              v-show="registerInfo.locationNo == ''"
            ></u-icon>
               </view>
            </view>
            <view class="packing-registration-param-item param-extra">
               <view class="packing-registration-param-item-left">
                  <text class="item-one">盘点数量</text>
               </view>
               <view class="packing-registration-param-item-right" @click="openPhysicalInventory()">
          <view
            class="packing-registration-param-item-right"
            @click="openPhysicalInventory()"
          >
                  <view class="item-one item-two">
                     <text>{{ registerInfo.value5 == '' ? "点击输入" : registerInfo.value5 }}</text>
              <text>{{
                registerInfo.qtyAvailable == ""
                  ? "点击输入"
                  : registerInfo.qtyAvailable
              }}</text>
                  </view>
                  <u-icon name="arrow-right" color="#687792" size="28"
                     v-show="registerInfo.value4 == ''"></u-icon>
            <u-icon
              name="arrow-right"
              color="#687792"
              size="28"
              v-show="registerInfo.qtyAvailable == ''"
            ></u-icon>
               </view>
            </view>
            <view class="packing-registration-param-item param-extra">
@@ -84,11 +140,21 @@
      </view>
      <view class="wrap">
         <scroll-view class="packing-registration-scroll-list" scroll-y="true">
            <u-cell-group class="packing-registration-scroll-list-group" :border="false">
        <u-cell-group
          class="packing-registration-scroll-list-group"
          :border="false"
        >
               <!-- <div class="tip" style="text-align: center;" v-if="hasScanSnList.length==0">-请扫码-</div> -->
               <view class="content" v-for="(item, index) in hasScanSnList" :key="index" :index="index">
          <view
            class="content"
            v-for="(item, index) in hasScanSnList"
            :key="index"
            :index="index"
          >
                  <view class="content-header">
                     <view class="content-header-title">{{ index + 1 }}</view>
              <view class="content-header-title">{{
                hasScanSnList.length - index
              }}</view>
                  </view>
                  <view class="content-body">
                     <view class="row-list">
@@ -96,7 +162,7 @@
                           <view class="_label-name">零件号:</view>
                        </view>
                        <view class="_content">
                           {{ item.value0 }}
                  {{ item.partNo }}
                        </view>
                     </view>
                     <view class="row-list">
@@ -104,7 +170,7 @@
                           <view class="_label-name">批次号:</view>
                        </view>
                        <view class="_content">
                           {{ item.value1 }}
                  {{ item.ifsBatchNo }}
                        </view>
                     </view>
                     <view class="row-list">
@@ -112,7 +178,7 @@
                           <view class="_label-name">库位号:</view>
                        </view>
                        <view class="_content">
                           {{ item.value0 }}
                  {{ item.locationNo }}
                        </view>
                     </view>
                     <view class="row-list">
@@ -120,7 +186,7 @@
                           <view class="_label-name">盘点数量:</view>
                        </view>
                        <view class="_content">
                           {{ item.value1 }}
                  {{ item.qtyAvailable }}
                        </view>
                     </view>
                  </view>
@@ -130,73 +196,115 @@
         <scan></scan>
         <!-- 零件号 -->
         <modalBg ref="openPN" :confirm="confirmPN">
            <u-field v-model="registerInfo.value6" label="零件号:" placeholder="请输入" :border-bottom="false">
        <u-field
          v-model="registerInfo.partNo"
          label="零件号:"
          placeholder="请输入"
          :border-bottom="false"
        >
            </u-field>
         </modalBg>
         <!-- 批次号 -->
         <modalBg ref="openBatch" :confirm="confirmBatch">
            <u-field v-model="registerInfo.value3" label="批次号:" placeholder="请输入" :border-bottom="false">
        <u-field
          v-model="registerInfo.ifsBatchNo"
          label="批次号:"
          placeholder="请输入"
          :border-bottom="false"
        >
            </u-field>
         </modalBg>
         <!-- 库位号 -->
         <modalBg ref="openLocation" :confirm="confirmLocation">
            <u-field v-model="registerInfo.value4" label="库位号:" placeholder="请输入" :border-bottom="false">
        <u-field
          v-model="registerInfo.locationNo"
          label="库位号:"
          placeholder="请输入"
          :border-bottom="false"
        >
            </u-field>
         </modalBg>
         <!-- 盘点数量 -->
         <modalBg ref="openPhysicalInventory" :confirm="confirmPhysicalInventory">
            <u-field v-model="registerInfo.value5" label="盘点数量:" label-width="140" placeholder="请输入"
               :border-bottom="false">
        <u-field
          v-model="registerInfo.qtyAvailable"
          label="盘点数量:"
          label-width="140"
          placeholder="请输入"
          :border-bottom="false"
        >
            </u-field>
         </modalBg>
      </view>
   </view>
</template>
<script>
   import modalBg from '@/components/modal/modal-bg.vue'
import modalBg from "@/components/modal/modal-bg.vue";
   import scan from "@/components/scan/scan.vue";
   import content_bg from '@/static/custom/packing/backBg.png'
import content_bg from "@/static/custom/packing/backBg.png";
   export default {
      components: {
         scan,
         modalBg
    modalBg,
      },
      data() {
         return {
            background: {
               backgroundImage: `url(${content_bg})`,
               backgroundAttachment: 'fixed',
               backgroundSize: '100% auto',
               backgroundRepeat: 'no-repeat',
        backgroundAttachment: "fixed",
        backgroundSize: "100% auto",
        backgroundRepeat: "no-repeat",
            },
            labelStyle: {
               fontSize: '32rpx',
               whiteSpace: 'nowrap'
        fontSize: "32rpx",
        whiteSpace: "nowrap",
            },
            registerInfo: {},
      registerInfo: {
        invListNo: "",
        warehouseId: "",
        partNo: "",
        ifsBatchNo: "",
        locationNo: "",
        qtyAvailable: "",
      },
            hasScanSnList: [],
            delContent: null,
            staffList: [],
      submitList: {},
      scanHandleList: {},
         };
      },
      onLoad(option) {},
      onShow() {
    let that = this;
         let that = this
    uni.$off("scan"); // 每次进来先 移除全局自定义事件监听器
         uni.$off('scan') // 每次进来先 移除全局自定义事件监听器
         uni.$on('scan', function(data) {
            console.log('onscan');
    uni.$on("scan", function (data) {
      if (that.registerInfo.invListNo == "") {
        uni.showToast({
          title: "请先选择盘点报告号",
          icon: "none",
        });
        return;
      }
      console.log("onscan");
            //扫码成功后的回调,你可以写自己的逻辑代码在这里
            console.log('扫码结果:', data.code);
            that.scanHandle(data.code)
            that.$forceUpdate();
         })
      console.log("扫码结果:", data.code);
      if (data.code) {
        let codeInfo = JSON.parse(data.code);
        // if (codeInfo.BN) {
        // 扫描报工单二维码
        that.scanHandleList = codeInfo;
        that.scanHandle(codeInfo);
        // that.$forceUpdate();
        // }
      }
    });
      },
      onNavigationBarButtonTap() {
         this.goScan()
      },
  //   onNavigationBarButtonTap() {
  //     this.goScan();
  //   },
      onReady() {},
      methods: {
         //零件号
@@ -205,7 +313,7 @@
         },
         // 弹框保存
         confirmPN() {
            console.log('保存', this.registerInfo.value6);
      console.log("保存", this.registerInfo.partNo);
            // 请求接口,根据工单号查询其他信息并赋值
         },
         //批次号
@@ -214,7 +322,7 @@
         },
         // 弹框保存
         confirmBatch() {
            console.log('保存', this.registerInfo.value3);
      console.log("保存", this.registerInfo.ifsBatchNo);
            // 请求接口,根据工单号查询其他信息并赋值
         },
         //库位号
@@ -223,7 +331,7 @@
         },
         // 弹框保存
         confirmLocation() {
            console.log('保存', this.registerInfo.value4);
      console.log("保存", this.registerInfo.locationNo);
            // 请求接口,根据工单号查询其他信息并赋值
         },
         //盘点数量
@@ -232,108 +340,182 @@
         },
         // 弹框保存
         confirmPhysicalInventory() {
            console.log('保存', this.registerInfo.value5);
      console.log("保存", this.registerInfo.qtyAvailable);
      // this.registerInfo.qtyAvailable = Number(this.registerInfo.qtyAvailable);
            // 请求接口,根据工单号查询其他信息并赋值
         },
         setNo(val) {
            console.log('11111', val)
            this.registerInfo.value1 = val.value1
            this.registerInfo.value2 = val.value2
      console.log("val", val);
      this.registerInfo.invListNo = val.INV_LIST_NO;
      this.registerInfo.warehouseId = val.WAREHOUSE_ID;
         },
         //盘点报告号
         seachPersonnelNo() {
            console.log('11111')
    seaRchPersonnelNo() {
            uni.navigateTo({
               url: '/pages/wareHouse/inventory/orderList'
            })
         },
         goScan() {
            uni.scanCode({
               scanType: ['qrCode'],
               success: res => {
                  try {
                     console.log('扫码结果:', res);
                     this.scanHandle(res.result)
                  } catch (e) {}
               }
        url: "/pages/wareHouse/inventory/orderList",
            });
         },
         scanHandle(scanresult) {
            scanresult = scanresult.replace(/[\r\n]/g, "")
            if (scanresult.indexOf('{') > -1) {
               //二维码
               const result = JSON.parse(scanresult)
               //增加SN校验
               if (result.sn_no && result.sn_no != null && result.sn_no != '') {
                  if (this.hasScanSnList.length > 0) {
                     let hasScanSnIndex = this.hasScanSnList.indexOf(result.sn_no)
                     if (hasScanSnIndex < 0) {
                        this.hasScanSnList.push(result.sn_no)
                     } else {
                        this.$u.toast('请勿重复扫描')
    scanHandle(val) {
      this.submitList = {};
      const { PN, BN, NW } = val;
      this.$u.api.shiftingParking
        .selPartInfoPDA({ outBatchNo: BN })
        .then((res) => {
          console.log("res", res);
          this.submitList = res.data;
          // 检查是否已盘点
          if (this.hasScanSnList && this.hasScanSnList.length > 0) {
            // 查找是否已存在相同的 ifsBatchNo
            const isAlreadyScanned = this.hasScanSnList.some(
              (item) => item.ifsBatchNo === this.submitList.ifsBatchNo
            );
            if (isAlreadyScanned) {
              uni.showModal({
                title: "提示",
                content: "当前库存已盘点,请勿重复盘点",
                showCancel: false,
                confirmText: "确定",
              });
              return;
                     }
          }
          this.registerInfo = {
            ...this.registerInfo,
            partNo: this.submitList.partNo,
            ifsBatchNo: this.submitList.ifsBatchNo,
            // locationNo: this.registerInfo.locationNo,
            qtyAvailable: this.submitList.qtyAvailable,
          };
          this.goSubmit();
        })
        .catch((err) => {
          console.log("err", err);
          uni.showModal({
            title: "提示",
            content: err.message || "网络异常,请重试",
            showCancel: true,
            success: function (res) {},
          });
          return;
        });
    },
    getDifferentFields(obj1, obj2, mapping) {
      const differences = {};
      for (const [key1, mapRule] of Object.entries(mapping)) {
        let value2;
        if (typeof mapRule === "string") {
          value2 = obj2[mapRule];
        } else if (
          mapRule &&
          typeof mapRule === "object" &&
          "fixed" in mapRule
        ) {
          value2 = mapRule.fixed;
                  } else {
                     this.hasScanSnList.push(result.sn_no)
          continue;
        }
        if (obj1[key1] !== value2) {
          differences[key1] = {
            value1: obj1[key1],
            value2,
          };
                  }
               }
            } else {
               //增加SN校验
               if (this.hasScanSnList.length > 0) {
                  let hasScanSnIndex = this.hasScanSnList.indexOf(scanresult)
                  if (hasScanSnIndex < 0) {
                     this.hasScanSnList.push(scanresult)
                  } else {
                     this.$u.toast('请勿重复扫描')
                  }
               } else {
                  this.hasScanSnList.push(scanresult)
               }
            }
      return differences;
         },
  // 点击提交按钮的事件处理函数
  goSubmit() {
    if (!this.registerInfo.value1) {
      this.$u.toast('请选择盘点报告号');
      if (!this.registerInfo.invListNo) {
        this.$u.toast("请选择盘点报告号");
      return;
    }
    if (!this.registerInfo.value5) {
      this.$u.toast('请输入盘点数量');
      const diff = this.getDifferentFields(
        this.registerInfo,
        this.scanHandleList,
        {
          partNo: { fixed: this.scanHandleList.PN },
          // qtyAvailable: { fixed: Number(this.scanHandleList.NW) },
          ifsBatchNo: { fixed: this.scanHandleList.BN },
        }
      );
      console.log("差异字段:", diff);
      console.log("是否有差异:", Object.keys(diff).length > 0);
      if (this.registerInfo.locationNo !== this.submitList.locationNo) {
        uni.showModal({
          title: "提示",
          content: "扫描库位号与系统数据不一致",
          showCancel: true,
          success: function (res) {},
        });
      return;
      }
      if (Object.keys(diff).length > 0) {
        if (diff.partNo) {
          uni.showModal({
            title: "提示",
            content: "扫描零件号与系统数据不一致",
            showCancel: true,
            success: function (res) {},
          });
          return;
        }
        if (diff.ifsBatchNo) {
          uni.showModal({
            title: "提示",
            content: "扫描批次号与系统数据不一致",
            showCancel: true,
            success: function (res) {},
          });
          return;
        }
        if (diff.qtyAvailable) {
          uni.showModal({
            title: "提示",
            content: "扫描盘点数量与系统数据不一致",
            showCancel: true,
            success: function (res) {},
          });
          return;
        }
    }
    uni.showLoading({
      mask: true,
      title: "提交中...",
    });
      console.log("提交的数据", this.submitList);
    // 处理提交逻辑
    this.$u.api.workReporting
      .operationTask({
        inventoryNo: this.registerInfo.value1,
        warehouse: this.registerInfo.value2,
        partNo: this.registerInfo.value6,
        batchNo: this.registerInfo.value3,
        location: this.registerInfo.value4,
        quantity: this.registerInfo.value5,
        scanList: this.hasScanSnList
      this.$u.api.inventoryVerification
        .erpInventorySubmit({
          ...this.submitList,
          invListNo: this.registerInfo.invListNo,
      })
      .then((res) => {
        uni.hideLoading();
        if (res.success) {
          this.$u.toast('提交成功');
          this.registerInfo = {};
          this.hasScanSnList = [];
        } else {
          this.$u.toast(res.message || '提交失败');
        }
          // uni.hideLoading();
          this.$u.toast("提交成功");
          !this.hasScanSnList.some(
            (item) => item.ifsBatchNo === this.registerInfo.ifsBatchNo
          ) && this.hasScanSnList.unshift(this.registerInfo);
          // this.registerInfo = {};
      })
      .catch(() => {
        uni.hideLoading();
        this.$u.toast('网络异常,请重试');
        .catch((err) => {
          console.log("err", err);
          // uni.hideLoading();
          uni.showModal({
            title: "提示",
            content: err.message || "网络异常,请重试",
            showCancel: true,
            success: function (res) {},
          });
      });
  },
      }
  },
   };
</script>
<style lang="scss" scoped>
@@ -341,8 +523,8 @@
border: none;
}
   .packing-registration-bg {
      background-color: #F6F9FF;
      background-image: url('~@/static/custom/packing/backBg.png');
  background-color: #f6f9ff;
  background-image: url("~@/static/custom/packing/backBg.png");
      padding: 0 20rpx;
      background-attachment: fixed;
      background-size: 100% auto;
@@ -367,7 +549,7 @@
            margin-left: 14rpx;
            font-size: 34rpx;
            font-weight: bold;
            color: #283E65;
      color: #283e65;
         }
      }
@@ -380,7 +562,7 @@
         .packing-registration-param-item {
            height: 90rpx;
            border: 1px solid #ADC8E4;
      border: 1px solid #adc8e4;
            line-height: 90rpx;
            display: flex;
            justify-content: space-between;
@@ -405,20 +587,20 @@
               .item-two {
                  font-size: 30rpx;
                  color: #A6B4CC;
          color: #a6b4cc;
                  margin-right: 6rpx;
               }
               .item-three {
                  font-size: 30rpx;
                  color: #214DED;
          color: #214ded;
                  margin-right: 6rpx;
               }
            }
         }
         .param-extra {
            border-bottom: 1px solid #EDEDED;
      border-bottom: 1px solid #ededed;
         }
      }
   }
@@ -446,10 +628,10 @@
         align-items: center;
         .content-header {
            width: 40rpx;
            height: 90rpx;
            display: flex;
            align-items: center;
      max-width: 300rpx;
            .content-header-icon {
               background-image: url("~@/static/custom/moveWareHouse/header_icon.png");
@@ -457,13 +639,19 @@
               background-repeat: no-repeat;
               height: 28rpx;
               width: 28rpx;
        flex-shrink: 0;
            }
            .content-header-title {
        flex: 1;
        min-width: 0;
        white-space: pre-wrap;
               margin-left: 11rpx;
               font-size: 26rpx;
        font-size: 20rpx;
               font-weight: bold;
               color: #626369;
        word-wrap: break-word;
        overflow-wrap: break-word;
            }
         }
@@ -520,10 +708,10 @@
      .btn {
         flex: 1;
         margin: 10rpx;
         background: #214DED;
    background: #214ded;
         box-shadow: 0rpx 6rpx 8rpx 0rpx rgba(4, 49, 212, 0.3);
         font-weight: bold;
         color: #FEFEFE;
    color: #fefefe;
         font-family: PingFang SC;
      }
   }