fcx
5 天以前 dbfb045ad92072e880104e13fddb4dc7574499a1
pages/QC/XJ/Add.vue
@@ -3,14 +3,14 @@
    <!-- 头部信息 -->
    <view class="sheet-header">
      <h1>巡检单</h1>
      <view class="inspection-number">检验单号:{{ formData.billNo }}</view>
      <view class="inspection-number">巡检单号:{{ formData.releaseNo }}</view>
    </view>
    <!-- 基本信息区 -->
    <view class="basic-info">
      <view class="info-row">
        <span class="info-label">创建时间:</span>
        <span class="info-value">{{ formData.createTime }}</span>
        <span class="info-value">{{ formData.createDate }}</span>
        <span class="info-label">检验人:</span>
        <span class="info-value">{{ formData.statusUser }}</span>
      </view>
@@ -29,7 +29,7 @@
        <view class="info-label">物料编码:</view>
        <view v-if="!isUpdate" class="info-value">{{ formData.itemNo }}</view>
        <superwei-combox v-else v-model="formData.itemNo" :candidates="boardItems" :isJSON="true"
                         class="picker info-value-input" keyName="itemName" placeholder="请选择或输入"
                         class="picker info-value-input" keyName="itemNo" placeholder="请选择或输入"
                         @select="onItemChange"></superwei-combox>
      </view>
      <view class="info-block">
@@ -60,8 +60,8 @@
    <!-- 操作按钮区 -->
    <view class="action-buttons">
      <button v-if="current" class="secondary-btn" @click="getTable">获取检验项目</button>
      <button v-if="formData.billNo" class="secondary-btn" @click="closeInspection">关闭此次检验</button>
      <button v-if="current && !isUpdate" class="secondary-btn" @click="getTable">获取检验项目</button>
      <button v-if="formData.billNo && !isUpdate" class="secondary-btn" @click="closeInspection">关闭此次检验</button>
    <!-- <button v-if="isShowTable && isUpdate" class="primary-btn" @click="saveTable">生成检验项目</button> --> 
    </view>
@@ -101,7 +101,7 @@
    <!-- 操作按钮区 -->
    <view class="action-buttons">
      <button v-if="isUpdate && !isShowTable" class="secondary-btn" @click="getItem">创建检验单并生成部分默认值</button>
      <button v-if="isUpdate && !isShowTable" class="secondary-btn" @click="getItem1">创建检验单并生成部分默认值</button>
      <button v-if="!isUpdate && !isShowTable" class="secondary-btn" @click="uploadImages">查看所有图片</button>
      <button v-if="!isUpdate && !isShowTable" class="secondary-btn" @click="addDefectDescription">查看不良描述</button>
      <!--  <button v-if="!isUpdate && !formData.statusUser && !isShowTable" class="secondary-btn" @click="removeXJ">
@@ -133,9 +133,10 @@
  data() {
    return {
      formData: {
        createTime: "",
        createDate: "",
        id: "",
        billNo: "",
        releaseNo: "", // 添加巡检单号字段
        itemNo: "",
        itemName: "",
        workshopCode: "",
@@ -192,11 +193,12 @@
        this.isUpdate = false;
        // ⭐⭐⭐ 新增:必须保存到 this.id,后续接口才能使用
        this.id = params["id"];         // ←←← 必须加这一句!!!
        this.id = params["id"];
        // 原来你的逻辑保持不动
        this.formData.id = params["id"];
        this.formData.releaseNo = params["releaseNo"]; // 保存巡检单号
        this.formData.billNo = params["billNo"];
        // 初始化明细
@@ -209,7 +211,7 @@
            url: "/XJ/getMaxReleaseNo"
        }).then(res => {
            this.formData.billNo = res.data.tbBillList;
            this.formData.createTime = this.$getDate("yyyy-mm-dd");
            this.formData.createDate = this.$getDate("yyyy-mm-dd");
        });
        // 产品编码下拉框初始化
@@ -288,7 +290,8 @@
        url: "/XJ/XJQaSubmit",
        data: {
          userNo: this.$loginInfo.account,
          gid: this.formData.id
          gid: this.formData.id,
          releaseNo: this.formData.releaseNo
        }
      }).then(res => {
@@ -297,9 +300,16 @@
        console.log("Status Code的值:", res.statusCode);
        console.log("返回的数据:", res.data);
        
        // 检查多种成功条件
        if (res.statusCode === 200 || res.status === 0 || res.data === true || res.data.tbBillList === true) {
        // 检查tbBillList中的错误消息
        if (res.data && res.data.tbBillList) {
          const errorMsg = res.data.tbBillList.data || res.data.tbBillList.message;
          if (typeof errorMsg === 'string' && errorMsg) {
            this.$showMessage(errorMsg);
            return;
          }
        }
        if (res.statusCode === 200 || res.status === 0 || res.data === true || res.data.tbBillList === true) {
          this.$showMessage("成功提交检验");
          // 提交成功后跳转到列表页面
          setTimeout(() => {
@@ -395,9 +405,66 @@
      })
    },
    getItem1() {
      // 验证必填字段
      if (!this.formData.line) {
        this.$showMessage("请先选择生产线别");
        return;
      }
      if (!this.formData.itemNo) {
        this.$showMessage("请先选择物料编码");
        return;
      }
      if (!this.formData.daa001) {
        this.$showMessage("请先选择工单编号");
        return;
      }
      // 调用后端接口创建检验单
      this.$post({
        url: "/XJ/createInspection",
        data: {
          lineNo: this.formData.line,        // 生产线别
          itemNo: this.formData.itemNo,      // 物料编码
          daa001: this.formData.daa001,       // 工单编号
          account: this.$loginInfo.account  // 登录账号
        }
      }).then(res => {
        console.log("创建检验单完整响应:", res);
        console.log("返回的数据:", res.data);
        // 优先检查tbBillList中的message字段,存在则为失败
        if (res.data && res.data.tbBillList && res.data.tbBillList.message) {
          this.$showMessage(res.data.tbBillList.message);
          return;
        }
        // 检查res.data是否为字符串错误消息
        if (typeof res.data === 'string' && res.data) {
          this.$showMessage(res.data);
          return;
        }
        // 检查res.data是否有有效数据,存在Daa001等字段表示成功
        if (res.data && (res.data.Daa001 || res.data.ItemNo)) {
          this.$showMessage("创建检验单成功");
          // 根据后端返回的数据更新页面
          // 可以在这里处理返回的检验单信息
        } else {
          // 其他失败情况,尝试提取错误消息
          const errorMsg = res.data?.message || "创建失败";
          this.$showMessage(errorMsg);
        }
      }).catch(err => {
        console.log("创建检验单出错:", err);
        this.$showMessage("创建检验单失败,请重试");
      });
    },
    onItemChange(event) {
      this.formData.itemNo = event.itemNo;
      this.formData.itemName = event.itemName;
      this.formData.itemModel = event.itemModel;
      this.$post({
        url: "/XJ/getDaa001",
@@ -468,12 +535,14 @@
  const billNo = this.formData.billNo || '';
  const gid = this.formData.id || '';
  const itemIndex = index != null ? index : 0;
  const currentStatus = this.current ? 'A' : 'B'; // 添加current参数
  uni.navigateTo({
    url: 'detail?id=' + encodeURIComponent(itemId) + 
         '&billNo=' + encodeURIComponent(billNo) + 
         '&gid=' + encodeURIComponent(gid) + 
         '&index=' + encodeURIComponent(itemIndex)
         '&index=' + encodeURIComponent(itemIndex) +
         '&current=' + currentStatus // 传递current状态
  });
},
    getTable() {
@@ -494,7 +563,8 @@
      this.$post({
        url: "/XJ/setJYItem",
        data: {
          itemNo: this.formData.itemNo
          itemNo: this.formData.itemNo,
          releaseNo: this.formData.releaseNo  // 传递巡检单号
        }
      }).then(res => {
        if (res.data && res.data.tbBillList && res.data.tbBillList.length > 0) {