llj
2026-01-27 bbae990ed1f4574fa954753faeae159052d03fba
pages/MJGL/shangmudan/MouldUpperBill.vue
@@ -14,6 +14,7 @@
         <view class="tabs">
            <view :class="tabs == 0 ? 'on':''" @tap="() => { tabs = 0; reFocusBarCode(); }">单据信息</view>
            <view :class="tabs == 1 ? 'on':''" @tap="() => { tabs = 1; reFocusBarCode(); }">模具信息</view>
            <view :class="tabs == 2 ? 'on':''" @tap="() => { tabs = 2; reFocusBarCode(); }">制单信息</view>
         </view>
         <!-- 单据信息 -->
@@ -89,15 +90,44 @@
         </view>
         <!-- 模具信息 -->
         <view v-if="tabs == 1">
            <zb-table id="list-table" :checked-highlight="true" :fit="true"
               :style="{height: `${listTableHeight}px`}" :columns="columns" :data="listData" :show-header="true"
               :border="true" :row-key="row => row.index" @toggleRowSelection="handleSelect"
               @toggleAllSelection="handleSelectAll" @rowClick="onTableRowClickHandler" />
            <view class="card-list" :style="{height: `${listTableHeight}px`, overflow: 'auto'}">
               <!-- 卡片列表 -->
               <view v-for="(item, index) in listData" :key="index" class="card-item">
                  <uni-card style="margin: 10rpx 0;">
                     <view class="card-content">
                        <view class="card-row">
                           <text class="label">序号:</text>
                           <text class="value">{{ index + 1 }}</text>
                        </view>
                        <view class="card-row">
                           <text class="label">器具编码:</text>
                           <text class="value">{{ item.器具编码 }}</text>
                        </view>
                        <view class="card-row">
                           <text class="label">器具名称:</text>
                           <text class="value">{{ item.器具名称 }}</text>
                        </view>
                        <view class="card-row">
                           <text class="label">器具型号:</text>
                           <text class="value">{{ item.器具型号 }}</text>
                        </view>
                        <view class="card-row">
                           <text class="label">器具条码:</text>
                           <text class="value">{{ item.器具条码 }}</text>
                        </view>
                        <view class="card-row">
                           <text class="label">器具数量:</text>
                           <text class="value">{{ item.器具数量 }}</text>
                        </view>
                     </view>
                  </uni-card>
               </view>
               <view class="over" v-if="listData.length == 0">暂无模具数据</view>
            </view>
         </view>
         <view class="tab_area"></view>
         <view v-if="showmore">
         <view v-if="tabs == 2">
            <view class="form-item">
               <view class="title">制单人:</view>
               <view class="righton">
@@ -139,16 +169,6 @@
            </view>
         </view>
         <view class="other">
            <view v-if="!showmore" @tap="showmore = true">
               展开其他信息<uni-icons color="#1890FF" style="margin-left: 8rpx;" type="bottom"></uni-icons>
            </view>
            <view v-if="showmore" @tap="showmore = false">
               折叠其他信息<uni-icons color="#1890FF" style="margin-left: 8rpx;" type="top"></uni-icons>
            </view>
         </view>
         <view class="tab_area"></view>
         <view class="bottom-btn">
            <button v-if="btnType == 1 && !isEdit" class="btn-a" size="mini" @tap="submit">提交</button>
@@ -193,51 +213,6 @@
            listOption: [], // 列表选项
            listData: [], // 表格数据
            selectedRows: [], // 表格选中的数据
            // 在columns配置中添加操作列
            columns: [ // 表格列配置
               {
                  type: 'selection',
                  fixed: true,
                  width: 50
               },
               {
                  name: 'index',
                  label: '序号',
                  width: 60,
                  hidden: true
               },
               {
                  name: 'HMouldID',
                  label: 'HMouldID',
                  width: 100,
                  hidden: true
               },
               {
                  name: '器具数量',
                  label: '器具数量',
                  width: 120
               },
               {
                  name: '器具编码',
                  label: '器具编码',
                  width: 150
               },
               {
                  name: '器具名称',
                  label: '器具名称',
                  width: 120
               },
               {
                  name: '器具型号',
                  label: '器具型号',
                  width: 120
               },
               {
                  name: '器具条码',
                  label: '器具条码',
                  width: 120
               }
            ],
            hform: {
               HInterID: '',
@@ -248,8 +223,8 @@
               HDeptID: uni.getStorageSync('HDeptID'),
               HEmpName: uni.getStorageSync('HEmpName'),
               HEmpID: uni.getStorageSync('HEmpID'),
               HMangerName: uni.getStorageSync('HEmpName'),
               HMangerID: uni.getStorageSync('HEmpID'),
               HMangerName: uni.getStorageSync('HMangerName'),
               HMangerID: uni.getStorageSync('HMangerID'),
               HSourceName: '',
@@ -336,75 +311,16 @@
               this.HBarCodeFocus = true;
            });
         },
         // 表格行点击处理
         onTableRowClickHandler(row, index) {
            if (!this.listData[index].checked) {
               this.$set(this.listData[index], 'checked', true)
            } else {
               this.listData[index].checked = !this.listData[index].checked
            }
         },
         // 表格选择处理
         handleSelect(selected, array) {
            this.selectedRows = array
         },
         // 表格全选处理
         handleSelectAll(selected, array) {
            this.selectedRows = array
         },
         // 表格行删除
         deleteSelected() {
            if (this.selectedRows.length === 0) {
               uni.showToast({
                  title: '请先选择要删除的模具',
                  icon: 'none'
               })
               return
            }
            // 显示确认对话框
            uni.showModal({
               title: '确认删除',
               content: `确定要删除选中的${this.selectedRows.length}条数据吗?`,
               success: (res) => {
                  if (res.confirm) {
                     // 获取选中行的HMouldID集合
                     const selectedIds = this.selectedRows.map(row => row.HMouldID)
                     // 过滤掉选中的数据
                     this.listData = this.listData.filter(item =>
                        !selectedIds.includes(item.HMouldID)
                     )
                     // 重新计算序号
                     this.listData.forEach((item, index) => {
                        item.index = index + 1
                     })
                     // 清空选中状态
                     this.selectedRows = []
                     uni.showToast({
                        title: '删除成功',
                        icon: 'success'
                     })
                  }
               }
            })
         },
         //日期
         HDateChange(e) {
            console.log(e.detail.value)
            this.hform.HDate = e.detail.value
         },
         getHBarCodeData(HBarCode) {
            if (uni.getStorageSync('Organization') == "杭州斯莫尔磁性材料有限公司") {
            if (uni.getStorageSync('Organization') != "事业一处") {
               if (!this.hform.HSourceName) {
                  uni.showToast({
                     title: '请先选择生产资源',
                     title: '请先选择或扫描生产资源',
                     icon: 'none'
                  });
                  return;
@@ -445,12 +361,9 @@
                  HBillType: HBillType
               },
               success: (res) => {
                  console.log(2, res.data);
                  if (res.data.code == 1) {
                     var data = res.data.data[0];
                     console.log(3, data);
                     var num = data.Num;
                     console.log(4, num);
                     switch (num) {
                        case 1:
                           this.hform.HSourceID = data.HItemID;
@@ -479,84 +392,28 @@
                              });
                              return;
                           }
                           // 根据组织条件决定是否进行校验
                           const isSpecialOrg = uni.getStorageSync('OrganizationID') == "100007" &&
                              uni.getStorageSync('Organization') == "事业一处";
                           // 先调用模具档案检查,校验通过后才添加数据
                           this.getMould_FC().then(isValid => {
                              if (isValid) {
                                 this.tabs = 1;
                                 // 检查模具是否已存在于表格中
                                 const existingIndex = this.listData.findIndex(item =>
                                    item.HMouldID === data.hmainid
                                 );
                                 if (uni.getStorageSync('OrganizationID') == "100007" && uni
                                    .getStorageSync('Organization') == "事业一处") {
                                    if (existingIndex === -1) {
                                       // 如果不存在,添加到表格
                                       uni.showToast({
                                          title: '当前检具不在当前物料的检具清单中',
                                          icon: 'none',
                                          duration: 1500
                                       });
                                       this.refreshBarCodeState();
                                    } else {
                                       // 如果已存在,检查器具数量
                                       if (this.listData[existingIndex].器具数量 === 0) {
                                          // 器具数量为0,更新条码并将数量变为1
                                          this.listData[existingIndex].器具条码 = this.hform
                                             .HBarCode;
                                          this.listData[existingIndex].器具数量 = 1;
                                          uni.showToast({
                                             title: '扫描成功',
                                             icon: 'success',
                                             duration: 1500
                                          });
                                          this.refreshBarCodeState();
                                       } else {
                                          // 器具数量已为1,提示不允许重复扫描
                                          uni.showToast({
                                             title: '该模具已扫描,不允许重复扫描',
                                             icon: 'none',
                                             duration: 1500
                                          });
                                          this.refreshBarCodeState();
                                       }
                                    }
                           if (isSpecialOrg) {
                              // 特殊组织:需要调用模具档案检查
                              this.getMould_FC().then(isValid => {
                                 if (isValid) {
                                    this.handleMouldData(data);
                                 } else {
                                    if (existingIndex === -1) {
                                       // 如果不存在,添加到表格
                                       const newRow = {
                                          index: this.listData.length + 1,
                                          HMouldID: data.hmainid,
                                          器具编码: data.模具编号,
                                          器具名称: data.模具名称,
                                          器具型号: data.模具型号,
                                          器具条码: this.hform.HBarCode,
                                          器具数量: 1,
                                          checked: false // 默认不选中
                                       };
                                       this.listData.push(newRow);
                                       this.refreshBarCodeState();
                                    } else {
                                       // 如果已存在,提示用户
                                       uni.showToast({
                                          title: '该模具已扫描',
                                          icon: 'none',
                                          duration: 1500
                                       });
                                       this.refreshBarCodeState();
                                    }
                                    // 校验不通过,清空条码但不添加数据
                                    this.refreshBarCodeState();
                                 }
                              } else {
                                 // 校验不通过,清空条码但不添加数据
                              }).catch(error => {
                                 console.log('校验失败:', error);
                                 this.refreshBarCodeState();
                              }
                           }).catch(error => {
                              console.log('校验失败:', error);
                              this.refreshBarCodeState();
                           });
                              });
                           } else {
                              // 其他组织:直接处理模具数据
                              this.handleMouldData(data);
                           }
                           break;
                        case 4:
                           this.hform.HProcExchBillNo = data.单据号;
                           this.hform.HProcExchInterID = data.hmainid;
@@ -595,6 +452,80 @@
                  })
               },
            });
         },
         handleMouldData(data) {
            this.tabs = 1;
            // 检查模具是否已存在于表格中
            const existingIndex = this.listData.findIndex(item =>
               item.HMouldID === data.hmainid
            );
            const isSpecialOrg = uni.getStorageSync('OrganizationID') == "100007" &&
               uni.getStorageSync('Organization') == "事业一处";
            if (isSpecialOrg) {
               // 特殊组织:检查物料器具清单
               if (existingIndex === -1) {
                  // 如果不存在,说明不在当前物料的检具清单中
                  uni.showToast({
                     title: '当前检具不在当前物料的检具清单中',
                     icon: 'none',
                     duration: 1500
                  });
                  this.refreshBarCodeState();
               } else {
                  // 如果已存在,检查器具数量
                  if (this.listData[existingIndex].器具数量 === 0) {
                     // 器具数量为0,更新条码并将数量变为1
                     this.listData[existingIndex].器具条码 = this.hform.HBarCode;
                     this.listData[existingIndex].器具数量 = 1;
                     uni.showToast({
                        title: '扫描成功',
                        icon: 'success',
                        duration: 1500
                     });
                     this.refreshBarCodeState();
                  } else {
                     // 器具数量已为1,提示不允许重复扫描
                     uni.showToast({
                        title: '该模具已扫描,不允许重复扫描',
                        icon: 'none',
                        duration: 1500
                     });
                     this.refreshBarCodeState();
                  }
               }
            } else {
               // 其他组织:直接处理
               if (existingIndex === -1) {
                  // 如果不存在,添加到表格
                  const newRow = {
                     index: this.listData.length + 1,
                     HMouldID: data.hmainid,
                     器具编码: data.模具编号,
                     器具名称: data.模具名称,
                     器具型号: data.模具型号,
                     器具条码: this.hform.HBarCode,
                     器具数量: 1,
                     checked: false // 默认不选中
                  };
                  this.listData.push(newRow);
                  uni.showToast({
                     title: '扫描成功',
                     icon: 'success',
                     duration: 1500
                  });
                  this.refreshBarCodeState();
               } else {
                  // 如果已存在,提示用户
                  uni.showToast({
                     title: '该模具已扫描',
                     icon: 'none',
                     duration: 1500
                  });
                  this.refreshBarCodeState();
               }
            }
         },
         //获取使用部门数据
         getHDeptList() {
@@ -833,7 +764,7 @@
               success: (res) => {
                  if (res.data.code == 1 && res.data.data && res.data.data.length > 0) {
                     this.listData = [];
                     this.tabs=1;
                     this.tabs = 1;
                     res.data.data.forEach((item, index) => {
                        this.listData.push({
                           index: index + 1,
@@ -845,7 +776,7 @@
                           器具数量: 0
                        });
                     });
                     this.selectedRows = [...this.listData];
                  } else {
                     uni.showToast({
@@ -941,21 +872,21 @@
            // 如果是事业一处组织,校验器具数量
            if (uni.getStorageSync('OrganizationID') === "100007" && uni.getStorageSync('Organization') === "事业一处") {
               const zeroQtyItem = this.listData.find(item => {
                 // 考虑0、null、undefined等异常情况
                 const qty = Number(item.器具数量) || 0;
                 return qty <= 0;
                  // 考虑0、null、undefined等异常情况
                  const qty = Number(item.器具数量) || 0;
                  return qty <= 0;
               });
               if (zeroQtyItem) {
                 // 找到第一个数量异常项的位置(索引+1)
                 const index = this.listData.indexOf(zeroQtyItem) + 1;
                 const code = zeroQtyItem.器具编码 || '未知编码';
                 uni.showToast({
                   title: `第${index}行【${code}】器具数量为0,请检查`,
                   icon: 'none',
                   duration: 3000
                 });
                 return;
                  // 找到第一个数量异常项的位置(索引+1)
                  const index = this.listData.indexOf(zeroQtyItem) + 1;
                  const code = zeroQtyItem.器具编码 || '未知编码';
                  uni.showToast({
                     title: `第${index}行【${code}】器具数量为0,请检查`,
                     icon: 'none',
                     duration: 3000
                  });
                  return;
               }
            }
            if (!this.hform.HEmpName) {
@@ -1187,7 +1118,7 @@
      }
      .btn-c {
         background-color: #acacac;
         background-color: #FFA500;
         color: #fff;
         position: absolute;
         right: 120rpx;
@@ -1219,4 +1150,5 @@
         border-bottom: 3px solid #3a78ff;
      }
   }
</style>