xwt
2025-09-18 688505dded0a49ee685abcb980bd0dc521df4241
pages/QC/RKJ/Add.vue
@@ -35,21 +35,17 @@
      <view class="material-info">
         <view class="info-block">
            <view class="info-label">生产线别:</view>
            <view class="info-value" v-if="!isUpdate">{{formData.lineNo}}</view>
            <superwei-combox v-if="isUpdate" :candidates="DAA020List" placeholder="请选择或输入"
               v-model="formData.lineNo" @select="onDaa020Change" class="modern-picker"></superwei-combox>
            <view class="info-value">{{formData.daa015 || '暂无'}}</view>
         </view>
         <view class="info-block">
            <view class="info-label">送检批次号:</view>
            <view class="info-value" v-if="!isUpdate">{{formData.billNo}}</view>
            <superwei-combox v-if="isUpdate" :candidates="DAA001List" placeholder="请选择或输入"
               v-model="formData.billNo" @select="onDaa001Change" class="modern-picker"></superwei-combox>
            <view class="info-value">{{formData.billNo}}</view>
         </view>
         <view class="info-block">
            <view class="info-label">物料编码:</view>
            <view class="info-value">{{formData.itemNo}}</view>
         </view>
         <view class="info-block">
         <view class="info-block" v-if="formData.taskNo">
            <view class="info-label">任务单号:</view>
            <view class="info-value">{{formData.taskNo}}</view>
         </view>
@@ -58,7 +54,7 @@
            <view class="info-value">{{formData.itemName}}</view>
         </view>
         <view class="info-block">
            <view class="info-label">送检数量:</view>
            <view class="info-label">工单数量:</view>
            <view class="info-value highlight">{{formData.quantity}}</view>
         </view>
         <view class="info-block" v-if="formData.remarks">
@@ -67,14 +63,10 @@
         </view>
      </view>
      <!-- 操作按钮区 - 检验项目获取 -->
      <view class="action-buttons" v-if="isShowTable && current">
         <button class="secondary-btn" @click="getTable">获取检验项目</button>
         <button class="primary-btn" v-if="isUpdate" @click="saveTable">生成检验项目</button>
      </view>
      <!-- 操作按钮区 - 已移除创建功能 -->
      <!-- 检验项目表格 -->
      <view class="inspection-table" v-if="!isShowTable">
      <view class="inspection-table">
         <!-- 表格头部统计信息 -->
         <view class="table-header-stats">
            <view class="stats-left">
@@ -96,7 +88,7 @@
               </view>
            </view>
         </view>
         <table>
         <table v-if="tableData.length > 0">
            <thead>
               <tr>
                  <th width="15%" style="text-align: center;">检验项目</th>
@@ -119,7 +111,7 @@
                  <td>
                     <view v-if="item.result=='合格'" class="watermark approved">合格</view>
                     <view v-if="item.result=='不合格'" class="watermark rejected">不合格</view>
                     <view v-if="item.result=='未完成'" class="watermark pending">待确认</view>
                     <view v-if="item.result=='未完成'" class="watermark pending">待检验</view>
                     <view class="description-text">{{ item.itemMod }}</view>
                  </td>
                  <td>
@@ -137,23 +129,30 @@
               </tr>
            </tbody>
         </table>
         <!-- 空状态显示 -->
         <view v-else class="empty-state">
            <view class="empty-icon">📋</view>
            <view class="empty-text">暂无检验项目</view>
            <view class="empty-desc">该检验单还没有检验项目</view>
         </view>
      </view>
      <!-- 主操作按钮区 -->
      <!-- 主操作按钮区 - 只保留查看和提交功能 -->
      <view class="action-buttons">
         <button v-if="isUpdate && !isShowTable && current" class="primary-btn" @click="getItem">生成检验单</button>
         <button v-if="!isUpdate && !isShowTable" class="secondary-btn" @click="toImage">图片管理</button>
         <button v-if="!isUpdate && !isShowTable" class="secondary-btn" @click="fetchItems">获取检验项目</button>
         <button v-if="!isUpdate && !isShowTable" class="secondary-btn" @click="saveRemarks">添加描述</button>
         <button v-if="!isUpdate && !isShowTable" class="secondary-btn" @click="showTablePopup = true">查看数据</button>
         <button v-if="!isUpdate && !isShowTable && current" class="primary-btn" @click="submitInspection">检验提交</button>
         <button v-if="!isUpdate && !isShowTable && current && !formData.fcheckResu" class="danger-btn" @click="removeXJ">删除单据</button>
         <!-- 未提交状态:显示所有操作按钮 -->
         <button v-if="!isUpdate && (formData.fsubmit === null || formData.fsubmit !== 1)" class="secondary-btn" @click="generateInspectionItems">获取检验项目</button>
         <button v-if="!isUpdate && (formData.fsubmit === null || formData.fsubmit !== 1)" class="secondary-btn" @click="toImage">上传/查看图片</button>
         <button v-if="!isUpdate && (formData.fsubmit === null || formData.fsubmit !== 1)" class="secondary-btn" @click="saveRemarks">填写不良描述</button>
         <button v-if="!isUpdate && current && (formData.fsubmit === null || formData.fsubmit !== 1)" class="primary-btn" @click="submitInspection">检验提交</button>
         <!-- 已提交状态:只显示查看图片按钮 -->
         <button v-if="formData.fsubmit === 1" class="secondary-btn" @click="toImage">查看图片</button>
      </view>
      <!-- 弹出层 -->
      <view v-if="showPopup" class="overlay">
         <view class="popup">
            <h3>修改不合格描述</h3>
            <h3>填写不良描述</h3>
            <form>
               <view class="form-group">
                  <label class="form-label">不合格描述:</label>
@@ -161,43 +160,12 @@
               </view>
               <view class="popup-buttons">
                  <button class="primary-btn" @click="edit">修改</button>
                  <button class="secondary-btn" @click="showPopup = !showPopup">取消</button>
                  <button class="secondary-btn" @click="closePopup">取消</button>
               </view>
            </form>
         </view>
      </view>
      <!-- 表格弹出层 -->
      <view v-if="showTablePopup" class="overlay">
         <view class="popup table-popup">
            <h3>详细数据表格</h3>
            <view class="table-container">
               <table>
                  <thead>
                     <tr>
                        <th>序号</th>
                        <th>项目名称</th>
                        <th>检验标准</th>
                        <th>检验结果</th>
                     </tr>
                  </thead>
                  <tbody>
                     <tr v-for="(item, index) in popupTableData" :key="index">
                        <td>{{ index + 1 }}</td>
                        <td>{{ item.projName }}</td>
                        <td>{{ item.standard || '标准值' }}</td>
                        <td :class="item.result === '合格' ? 'text-success' : item.result === '不合格' ? 'text-danger' : ''">
                           {{ item.result }}
                        </td>
                     </tr>
                  </tbody>
               </table>
            </view>
            <view class="popup-buttons">
               <button class="secondary-btn" @click="showTablePopup = false">关闭</button>
            </view>
         </view>
      </view>
   </view>
</template>
@@ -224,31 +192,18 @@
               itemModel:"",
            },
            DAA020List: [],
            DAA001List: [],
            BillNoList: [],
            lineList: [],
            lineNo: "",
            // 下拉框数据已移除 - 不再支持编辑功能
            tableData: [],
            isSubmit: true,
            isUpdate: true,
            isShowTable: false,
            isUpdate: false, // 不再支持编辑功能
            remarks: "",
            showPopup: false,
            showTablePopup: false,
            popupTableData: [],
            
            current: true, // 标记当前用户是否有操作权限
            msgId: 0
@@ -279,57 +234,20 @@
            //getQaItemXj02
            this.init();
         } else {
            //初始化检验单号
            this.$post({
               url: "/RKJ/getMaxReleaseNo"
            }).then(res => {
               this.formData.releaseNo = res.data.tbBillList;
               this.formData.createBy = this.$loginInfo.account;
               this.formData.createDate = this.$getDate("yyyy-mm-dd");
            // 不再支持创建新单据,跳转到列表页
            uni.showModal({
               title: '提示',
               content: '请从列表中选择检验单进行查看',
               showCancel: false,
               confirmText: '确定',
               success: () => {
                  uni.navigateBack();
               }
            });
            //车间下拉框的初始化
            this.$post({
               url: "/XJ/getLineAll"
            }).then(res => {
               this.lineList = res.data.tbBillList;
               this.DAA020List = res.data.tbBillList.map(item => item.lineName);
            })
         }
         
         // 初始化弹窗表格数据示例
         this.initPopupTableData();
      },
      methods: {
         // 手动获取现有检验项目(调用 /RKJ/getItems)
         fetchItems() {
            if (!this.formData.id) {
               this.$showMessage("请先生成或打开检验单");
               return;
            }
            this.$post({
               url: "/RKJ/getItems",
               data: { pid: this.formData.id }
            }).then(res1 => {
               let tableData = res1.data.tbBillList;
               // 排序与 init 保持一致
               tableData.sort((a, b) => {
                  if (a.result === '未完成' && b.result === '合格') {
                     return -1;
                  } else if (a.result === '合格' && b.result === '未完成') {
                     return 1;
                  } else {
                     return 0;
                  }
               });
               this.tableData = tableData;
               this.isShowTable = this.tableData.length === 0;
               // 为每一项添加 current 属性
               this.tableData.forEach((item) => {
                  this.$set(item, 'current', this.current);
               });
            });
         },
         // 获取合格项目数量
         getPassedCount() {
            return this.tableData.filter(item => item.result === '合格').length;
@@ -347,184 +265,119 @@
            const statusMap = {
               '合格': '合格',
               '不合格': '不合格',
               '未完成': '待确认'
               '未完成': '待检验'
            }
            return statusMap[status] || '待确认';
            return statusMap[status] || '待检验';
         },
         
         // 初始化弹窗表格数据
         initPopupTableData() {
            // 这里可以从API获取数据,这里使用示例数据
            this.popupTableData = [
               { projName: '外观检查', standard: '无明显划痕', result: '合格' },
               { projName: '尺寸检查', standard: '10±0.5mm', result: '合格' },
               { projName: '功能测试', standard: '正常工作', result: '不合格' },
               { projName: '电气性能', standard: '5V±0.1V', result: '合格' },
               { projName: '耐压测试', standard: '≥1000V', result: '未完成' }
            ];
         },
         
         // 检验提交
         submitInspection() {
            // 校验是否有检验项目
            if (!Array.isArray(this.tableData) || this.tableData.length === 0) {
               this.$showMessage("没有检验项目,无法提交");
               return;
            }
            // 校验检验项目是否全部完成
            const unfinishedItems = [];
            const hasUnfinished = this.tableData.some(it => {
               const checkedCount = Number(it?.isCheck ?? 0);
               const requiredCount = Number(it?.levelNum ?? 0);
               // 允许提交的前提:已检次数需达到要求次数
               if (checkedCount < requiredCount) {
                  unfinishedItems.push(it.projName);
                  return true;
               }
               return false;
            });
            if (hasUnfinished) {
               const message = unfinishedItems.length > 0
                  ? `以下检验项目未完成,不能提交:\n${unfinishedItems.join('、')}`
                  : "存在未完成的检验项目,不能提交";
               this.$showMessage(message);
               return;
            }
            // 校验是否所有检验项目都有结果
            const itemsWithoutResult = this.tableData.filter(it =>
               !it.result || it.result === '未完成' || it.result === '未检测'
            );
            if (itemsWithoutResult.length > 0) {
               const itemNames = itemsWithoutResult.map(it => it.projName);
               this.$showMessage(`以下检验项目没有检验结果,不能提交:\n${itemNames.join('、')}`);
               return;
            }
            // 显示确认弹窗
            uni.showModal({
               title: '确认提交',
               content: '确定要提交检验结果吗?提交后将无法修改。',
               confirmText: '确定提交',
               cancelText: '取消',
               success: (res) => {
                  if (res.confirm) {
                     // 用户确认提交
                     this.doSubmitInspection();
                  }
               }
            });
         },
         // 执行提交检验
         doSubmitInspection() {
            this.$post({
               url: "/RKJ/IqcQaSubmit",
               url: "/RKJ/RKJQaSubmit",
               data: {
                  gid: this.formData.id, // 检验单主表ID
                  submitBy: this.$loginInfo.account // 提交人
                  userNo: this.$loginInfo.account // 提交人
               }
            }).then(res => {
               if (res.status == 0) {
                  uni.showToast({
                     title: res.message.toString(),
                     icon: 'success',
                     duration: 2000
                  })
                  // 如果有页面跳转,需要用定时器延迟
                  setTimeout(() => {
                     uni.navigateTo({
                        url: 'List'
                     });
                  }, 2000); // 保持与 duration 相同的时长
               if (res.status === 0) {
                  // 显示成功提示框
                  uni.showModal({
                     title: '提交成功',
                     content: res.message || '检验提交成功!',
                     confirmText: '确定',
                     showCancel: false,
                     success: () => {
                        // 更新本地状态,隐藏提交按钮
                        this.formData.fsubmit = 1;
                        this.formData.fsubmitBy = this.$loginInfo.account;
                        this.formData.fsubmitDate = new Date().toLocaleString();
                        // 刷新页面数据
                        this.init();
                     }
                  });
               } else {
                  uni.showModal({
                     title: "提示",
                     content: res.message.toString(),
                     content: res.message || "提交失败",
                     confirmText: "确定",
                     showCancel: false,
                     success: (res) => {
                     }
                  })
                     showCancel: false
                  });
               }
            })
            }).catch(error => {
               uni.showModal({
                  title: "错误",
                  content: "提交失败,请重试",
                  confirmText: "确定",
                  showCancel: false
               });
            });
         },
         
         removeXJ() {
            if (this.formData.id) {
               this.$post({
                  url: "/RKJ/removeXJ",
                  data: {
                     id: this.formData.id
                  }
               }).then(res => {
                  if (res.data.tbBillList > 0) {
                     this.$showMessage("删除成功");
                     //关闭当前页面,返回上一页面或多级页面
                     uni.navigateBack();
                  } else {
                     this.$showMessage("删除失败");
                  }
               });
            } else {
               this.$showMessage("请先选择检验单号");
            }
         },
         getItem() {
            if (!this.formData.billNo) {
               this.$showMessage("请选择送检批次号");
               return;
            }
            if (this.isSubmit) {
               this.$showMessage("此物料无启用的检验项目,请维护!");
               return;
            }
            this.$post({
               url: "/RKJ/save",
               data: {
                  from: this.formData,
                  userNo: this.$loginInfo.account,
                  //moidNum: this.formData.moidNum
                  items: this.tableData
               }
            }).then(res => {
               this.formData.id = res.data.tbBillList;
               this.$showMessage("生成检验项目成功");
               this.init();
               this.isUpdate = false;
            });
         },
         //生产线别选择并初始话工单号
         onDaa020Change(event) {
            //获取生产线别的下标地址
            this.formData.lineName = event;
            this.lineNo = this.lineList[this.DAA020List.indexOf(event)].lineNo;
            this.formData.line = this.lineNo;
            this.$post({
               url: "/RKJ/getDaa001",
               data: {
                  lineNo: this.lineNo
               }
            }).then(res => {
               this.BillNoList = res.data.tbBillList;
               this.DAA001List = res.data.tbBillList.map(s => s.billNo);
               this.formData.billNo = "";
               this.formData.mocode = "";
               this.formData.boardModel = "";
               this.formData.taskNo = "";
               this.formData.itemNo = "";
               this.formData.boardName = "";
               this.formData.quantity = "";
               this.tableData = [];
            })
         },
         //选取工单填充物料号和其他信息
         onDaa001Change(e) {
            this.formData.billNo = e;
            let data = this.BillNoList[this.DAA001List.indexOf(e)];
            //当返回的结果集为空时置空原有的值
            if (!data) {
               this.formData.billNo = "";
               this.formData.mocode = "";
               this.formData.boardModel = "";
               this.formData.taskNo = "";
               this.formData.itemNo = "";
               this.formData.boardName = "";
               this.formData.quantity = "";
               this.tableData = [];
               return;
            }
            //不为空时赋值
            this.formData.billNo = data.billNo;
            this.formData.mocode = data.mocode;
            this.formData.boardModel = data.boardModel;
            this.formData.taskNo = data.taskNo;
            this.formData.itemNo = data.itemNo;
            this.formData.boardName = data.boardName;
            this.formData.quantity = data.quantity;
            this.$post({
               url: "/RKJ/setJYItem",
               data: {
                  itemId: this.formData.itemId,
                  quantity: this.formData.quantity
               }
            }).then(res => {
               this.tableData = res.data.tbBillList;
               if (this.tableData.length === 0) {
                  this.$showMessage("该物料没有检验项目");
                  this.isSubmit = true;
                  this.tableData = [];
               } else {
                  this.isSubmit = false;
               }
            });
         },
         // removeXJ方法已移除 - 不再支持删除单据
         // getItem方法已移除 - 不再支持创建检验单
         // onDaa020Change方法已移除 - 不再支持编辑功能
         // onDaa001Change方法已移除 - 不再支持编辑功能
         init() {
            let userName = this.$loginInfo.account;
            
            this.$post({
               url: "/RKJ/getPage",
               url: "/RKJ/GetPage",
               data: {
                  id: this.formData.id,
                  pageIndex: 1,
@@ -541,7 +394,6 @@
                        pid: this.formData.id
                     }
                  }).then(res1 => {
                     let tableData = res1.data.tbBillList
                     //当已检验个数都不为空时按照检测结构排序
@@ -556,11 +408,7 @@
                     });
                     this.tableData = tableData;
                     if (this.tableData.length === 0) {
                        this.isShowTable = true; // 无检验项目,显示获取按钮
                     } else {
                        this.isShowTable = false; // 有检验项目,显示表格
                     }
                     // 直接显示表格,不再使用isShowTable控制
                     
                     // 为每一项添加current属性,表示是否可编辑
                     this.tableData.forEach((item, index) => {
@@ -589,86 +437,86 @@
            });
         },
         saveRemarks() {
            this.showPopup = !this.showPopup;
            this.remarks = this.formData.remarks;
            this.showPopup = true;
            this.remarks = this.formData.remarks || '';
         },
         // 关闭弹窗
         closePopup() {
            this.showPopup = false;
            this.remarks = '';
         },
         edit() {
            if (this.remarks) {
               //saveRemarksGid
               this.$post({
                  url: "/RKJ/saveRemarksGid",
                  data: {
                     gid: this.formData.id,
                     remarks: this.remarks
                  }
               }).then(res => {
                  if (res.data.tbBillList > 0) {
                     this.formData.remarks = this.remarks;
                     this.showPopup = !this.showPopup;
                     this.$showMessage("保存成功");
                  }
               })
            } else {
               // 允许清空描述
               this.$post({
                  url: "/RKJ/saveRemarksGid",
                  data: {
                     gid: this.formData.id,
                     remarks: '',
                     releaseNo: this.formData.releaseNo
                  }
               }).then(res => {
                  if (res.data.tbBillList > 0) {
                     this.formData.remarks = '';
                     this.showPopup = !this.showPopup;
                     this.$showMessage("保存成功");
                  }
               })
            }
         },
         getTable() {
            // 先关闭弹窗
            this.showPopup = false;
            // 保存描述
            this.$post({
               url: "/RKJ/setJYItem",
               data: {
                  //itemId: this.formData.itemId,
                  itemNo: this.formData.itemNo,
                  quantity: this.formData.quantity
               }
            }).then(res => {
               this.tableData = res.data.tbBillList;
               if (this.tableData.length === 0) {
                  this.$showMessage("该物料条码没有检验项目");
                  this.isSubmit = true;
                  this.tableData = [];
                  this.isShowTable = true; // 保持为true,显示按钮,因为没有检验项目
                  this.isUpdate = false;
               } else {
                  this.isSubmit = false;
                  this.isShowTable = false; // 设为false,以显示表格,因为有检验项目
                  this.isUpdate = true;
               }
            });
         },
         saveTable() {
            if (this.tableData.length === 0) {
               return;
            }
            this.$post({
               url: "/RKJ/saveItem",
               url: "/RKJ/saveRemarksGid",
               data: {
                  gid: this.formData.id,
                  items: this.tableData,
                  remarks: this.remarks || '',
                  releaseNo: this.formData.releaseNo
               }
            }).then(res => {
               if (res.status === 0 && res.data.affectedRows > 0) {
                  this.$showMessage("保存成功");
                  // 刷新表单数据
                  this.refreshFormData();
               } else {
                  this.$showMessage("保存失败");
               }
            }).catch(error => {
               this.$showMessage("保存失败,请重试");
            });
         },
         // 刷新表单数据
         refreshFormData() {
            // 只刷新主表单数据,不重新加载检验项目
            this.$post({
               url: "/RKJ/GetPage",
               data: {
                  id: this.formData.id,
                  pageIndex: 1,
                  limit: 1,
               }
            }).then(res => {
               let data = res.data.tbBillList[0];
               if (data) {
                  this.formData = data;
               }
            }).catch(error => {
               console.error('刷新表单数据失败:', error);
            });
         },
         // 获取检验项目
         generateInspectionItems() {
            this.$post({
               url: "/RKJ/GenUpdateRKJ",
               data: {
                  id: this.formData.id,
                  no: this.formData.billNo,
                  userNo: this.$loginInfo.account
               }
            }).then(res => {
               this.formData.id = res.data.tbBillList;
               this.isShowTable = false; // 确保表格显示
               this.isUpdate = false;
               this.init();
            })
               if (res.status === 0) {
                  this.$showMessage("生成/获取检验项目成功");
                  // 成功后刷新检验项目
                  this.$post({
                     url: "/RKJ/getItems",
                     data: { pid: this.formData.id }
                  }).then(r => {
                     this.tableData = r.data.tbBillList || [];
                  });
               } else {
                  this.$showMessage(res.message || "生成失败");
               }
            }).catch(error => {
               this.$showMessage("网络错误,请重试");
            });
         },
         // getTable和saveTable方法已移除 - 不再支持创建检验项目
      },
      onShow() {
         //每次进入页面都会执行的方法
@@ -1018,6 +866,17 @@
  background-color: #2980b9;
}
.white-btn {
  background-color: white;
  color: #2c3e50;
  border: 2px solid #3498db;
}
.white-btn:hover {
  background-color: #f8f9fa;
  border-color: #2980b9;
}
.secondary-btn {
  background-color: #ecf0f1;
  color: #7f8c8d;
@@ -1084,15 +943,15 @@
/* 水印样式 */
.watermark {
  position: absolute;
  font-size: 32px;
  font-size: 28px;
  font-weight: bold;
  opacity: 0.4;
  opacity: 0.3;
  z-index: 3;
  pointer-events: none;
  bottom: 8px;
  right: 8px;
  transform: rotate(-15deg);
  transform-origin: bottom right;
  top: 50%;
  right: 12px;
  transform: translateY(-50%) rotate(-15deg);
  transform-origin: center;
  text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
  min-width: 60px;
  text-align: center;
@@ -1253,9 +1112,8 @@
  /* 移动端水印样式调整 */
  .watermark {
    font-size: 24px;
    bottom: 4px;
    right: 4px;
    font-size: 20px;
    right: 8px;
  }
  /* 移动端表格头部统计 */
@@ -1314,9 +1172,8 @@
/* 平板设备样式 */
@media (min-width: 501px) and (max-width: 768px) {
  .watermark {
    font-size: 28px;
    bottom: 6px;
    right: 6px;
    font-size: 24px;
    right: 10px;
  }
  .inspection-table th, 
@@ -1335,6 +1192,38 @@
  }
}
/* 空状态样式 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  background-color: #fafafa;
  border-radius: 8px;
  margin: 20px 0;
}
.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}
.empty-text {
  font-size: 18px;
  font-weight: 600;
  color: #666;
  margin-bottom: 8px;
}
.empty-desc {
  font-size: 14px;
  color: #999;
  line-height: 1.5;
}
/* 大屏设备优化 */
@media (min-width: 1200px) {
  .inspection-table {
@@ -1342,9 +1231,8 @@
  }
  .watermark {
    font-size: 36px;
    bottom: 10px;
    right: 10px;
    font-size: 32px;
    right: 16px;
  }
}
</style>