src/views/business/inspectionTask/inspection.vue
@@ -1,22 +1,7 @@
<template>
  <div v-loading="loading" class="inspection" style="background-color: rgb(245, 247, 251);">
    <el-row class="title">
      <el-col v-if="insOrder.ifsOrderType!=='02wg'" :span="8" style="text-align: left">
        <el-form :inline="true" :model="currentOtherForm" class="form-inline" label-width="50px"
          style="text-align: right; padding-top: 0; display: inline">
          <el-form-item label="温度:" style="margin-bottom: 0">
            <el-input v-model="currentOtherForm.temperature" :disabled="state > 1" placeholder="" size="small"
              style="width: 90px; line-height: 60px" @change="(m) => subOtherForm(m, 'temperature')"></el-input>
            <span style="margin-left: 4px">℃</span>
          </el-form-item>
          <el-form-item label="湿度:" style="margin-bottom: 0">
            <el-input v-model="currentOtherForm.humidity" :disabled="state > 1" placeholder="" size="small"
              style="width: 90px; line-height: 60px" @change="(m) => subOtherForm(m, 'humidity')"></el-input>
            <span style="margin-left: 4px">%RH</span>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="insOrder.ifsOrderType!=='02wg'?16:24" style="text-align: right">
      <el-col :span="24" style="text-align: right">
        <el-button v-if="insOrder.ifsOrderType && insOrder.ifsOrderType==='02wg'" size="small" type="primary" @click="showMaterialPropsDialog">IFS物料属性更新</el-button>
        <el-button size="small" type="primary" @click="refreshView">刷新</el-button>
        <el-button v-if="typeSource == 1" size="small" type="primary" @click="openPurchase">进货验证</el-button>
@@ -106,8 +91,9 @@
        </template>
        <template v-else>
          <el-descriptions-item label="委托编号">{{ insOrder.entrustCode }}</el-descriptions-item>
          <el-descriptions-item label="检测依据">{{ insOrder.sample || '-' }}</el-descriptions-item>
          <el-descriptions-item label="样品名称">{{ insOrder.sampleView || '-' }}</el-descriptions-item>
          <el-descriptions-item label="样品编号">{{ currentSample.sampleCode }}</el-descriptions-item>
          <el-descriptions-item label="样品名称">{{ currentSample.sample }}</el-descriptions-item>
          <el-descriptions-item label="样品数量">{{ insOrder.testQuantity }}</el-descriptions-item>
          <el-descriptions-item label="下发时间">{{ insOrder.sendTime }}</el-descriptions-item>
          <el-descriptions-item label="紧急程度">{{ insOrder.typeName }}</el-descriptions-item>
@@ -117,18 +103,6 @@
        <el-descriptions-item label="备注">
          <el-input v-model="insOrder.remark" :disabled="state != 1" clearable placeholder="请输入" size="small"
                    @blur="subOtherForm(insOrder.remark, 'remark')"></el-input>
        </el-descriptions-item>
        <el-descriptions-item v-if="isDirectTemplateOrder()" label="设备" :span="2">
          <el-select v-model="selectedDeviceIds" multiple filterable clearable size="small" placeholder="请选择设备"
            :disabled="state != 1" @change="saveOverviewDevices">
            <el-option v-for="device in orderDeviceOptions" :key="device.id" :label="device.label" :value="device.id" />
          </el-select>
        </el-descriptions-item>
        <el-descriptions-item label="检验结论">
          <el-radio-group v-model="reviewInsResult" :disabled="state != 2">
            <el-radio :label="1">合格</el-radio>
            <el-radio :label="0">不合格</el-radio>
          </el-radio-group>
        </el-descriptions-item>
      </el-descriptions>
    </div>
@@ -200,6 +174,50 @@
            @click="dataAcquisitionEidtAble = !dataAcquisitionEidtAble">{{ dataAcquisitionEidtAble ? "关闭编辑" : "编辑数采"
            }}</el-button>
        </div>
      </div>
      <!-- 当前检验模板的检测条件与检验结论 -->
      <div class="template-panel">
        <el-form v-if="showTemplateConditions" :inline="true" :model="currentOtherForm" class="form-inline"
          size="small" label-width="84px">
          <el-form-item v-if="insOrder.ifsOrderType!=='02wg'" label="温度:">
            <el-input v-model="currentOtherForm.temperature" :disabled="state > 1" placeholder="" size="small"
              style="width: 90px" @change="(m) => subOtherForm(m, 'temperature')"></el-input>
            <span class="template-panel__unit">℃</span>
          </el-form-item>
          <el-form-item v-if="insOrder.ifsOrderType!=='02wg'" label="湿度:">
            <el-input v-model="currentOtherForm.humidity" :disabled="state > 1" placeholder="" size="small"
              style="width: 90px" @change="(m) => subOtherForm(m, 'humidity')"></el-input>
            <span class="template-panel__unit">%RH</span>
          </el-form-item>
          <el-form-item v-if="insOrder.ifsOrderType!=='02wg'" label="检测时间:">
            <el-date-picker v-model="currentOtherForm.detectionTime" :disabled="state > 1" type="date"
              value-format="yyyy-MM-dd" placeholder="请选择日期" size="small" style="width: 160px"
              @change="(m) => subOtherForm(m, 'detectionTime')"></el-date-picker>
          </el-form-item>
          <el-form-item v-if="insOrder.ifsOrderType!=='02wg'" label="检测地点:">
            <el-input v-model="currentOtherForm.detectionPlace" :disabled="state > 1" clearable placeholder="请输入检测地点"
              size="small" style="width: 200px" @change="(m) => subOtherForm(m, 'detectionPlace')"></el-input>
          </el-form-item>
          <el-form-item v-if="isDirectTemplateOrder()" label="设备:">
            <el-select v-model="currentOtherForm.deviceIds" :disabled="state != 1" multiple filterable clearable
              size="small" placeholder="请选择设备" style="width: 360px"
              @change="(m) => subOtherForm(m, 'deviceIds')">
              <el-option v-for="device in orderDeviceOptions" :key="device.id" :label="device.label" :value="device.id" />
            </el-select>
          </el-form-item>
        </el-form>
        <!-- 复核时才能选 -->
        <el-form :inline="true" :model="currentOtherForm"
          :class="['form-inline', { 'template-panel__conclusion--divided': showTemplateConditions }]"
          size="small" label-width="84px">
          <el-form-item label="检验结论:">
            <el-radio-group v-model="currentOtherForm.insResult" :disabled="state != 2"
              @change="(m) => subOtherForm(m, 'insResult')">
              <el-radio :label="1">合格</el-radio>
              <el-radio :label="0">不合格</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <!-- 常规检验原始记录 -->
      <div id="nav" v-loading="tableLoading" class="center-box">
@@ -583,8 +601,6 @@
  submitPlan,
  saveInsContext,
  saveTemplateContext,
  getOrderDevices,
  saveOrderDevices,
  selectUserCondition,
  downFile,
  getFileList,
@@ -668,11 +684,9 @@
      excelMethodList: [],
      equipOptions: [],
      orderDeviceOptions: [],
      selectedDeviceIds: [],
      reviewLoading: false,
      reviewDia: false,
      noReason: "",
      reviewInsResult: null,
      tableWidth: 1000,
      currentTable: null,
      tableLists: [],
@@ -689,7 +703,7 @@
        inspectionItem: 1,
        inspectionItemSubclass: "20(常温)",
      },
      // 温度、湿度按模板 id 分组:{ [templateId]: { temperature, humidity } }
      // 检测条件与检验结论按模板 id 分组:{ [templateId]: { temperature, humidity, detectionTime, detectionPlace, deviceIds, insResult } }
      otherForm: {},
      equipForm: {
        value0: null,
@@ -843,14 +857,22 @@
    action() {
      return this.javaApi + "/insOrderPlan/uploadFile";
    },
    // 当前模板对应的温度、湿度
    // 当前模板对应的检测条件与检验结论
    currentOtherForm() {
      return (
        this.otherForm[this.currentTable] || {
          temperature: null,
          humidity: null,
          detectionTime: null,
          detectionPlace: null,
          deviceIds: [],
          insResult: null,
        }
      );
    },
    // 02wg 单没有温湿度;新聚直接绑定模板的单只有设备
    showTemplateConditions() {
      return this.insOrder.ifsOrderType !== "02wg" || this.isDirectTemplateOrder();
    },
  },
  created() {
@@ -926,7 +948,7 @@
              this.tableList = this.tableLists.filter(
                (m) => m.templateId == val1
              );
              // 模板集合可能变化,补齐温度、湿度槽位
              // 模板集合可能变化,补齐检测条件槽位
              this.tableLists.forEach((m) => this.ensureOtherForm(m.templateId));
              // 对模板进行处理
              this.handleTableData();
@@ -1094,7 +1116,6 @@
        laboratory: this.sonLaboratory,
      }).then(async (res) => {
        this.insOrder = res.data.insOrder;
        this.reviewInsResult = this.insOrder.insResult;
        if(res.data.insOrder.ifsOrderType==='02wg'){
          //查询零件属性
          this.getPartProps(res.data.insOrder.ifsInventoryId)
@@ -1115,12 +1136,16 @@
        this.sampleProduct = res.data.sampleProduct;
        this.currentSample = this.HaveJson(this.sampleProduct[0]);
        let insProduct = this.HaveJson(this.currentSample.insProduct);
        // 温度、湿度赋值:按模板 id 分组回显
        // 检测条件与检验结论赋值:按模板 id 分组回显
        this.otherForm = {};
        (this.insOrder.templateConditions || []).forEach((item) => {
          this.$set(this.otherForm, item.templateId, {
            temperature: item.temperature != null ? item.temperature : null,
            humidity: item.humidity != null ? item.humidity : null,
            detectionTime: item.detectionTime != null ? item.detectionTime : null,
            detectionPlace: item.detectionPlace != null ? item.detectionPlace : null,
            deviceIds: Array.isArray(item.deviceIds) ? [...item.deviceIds] : [],
            insResult: item.insResult != null ? item.insResult : null,
          });
        });
        this.tableLists.forEach((m) => this.ensureOtherForm(m.templateId));
@@ -1130,7 +1155,7 @@
        }
        this.getEquipOptions(1);
        if (this.sonLaboratory === "新聚") {
          this.loadOverviewDevices();
          this.loadDeviceOptions();
        }
        // 获取当前样品的检验项
        let list = await this.getCurrentProduct(this.currentSample.id, 0);
@@ -1629,24 +1654,34 @@
        this.worker0 = null;
      }
    },
    // 保证模板的温度、湿度槽位存在
    // 保证模板的检测条件与检验结论槽位存在
    ensureOtherForm(templateId) {
      if (templateId == null) return;
      if (!this.otherForm[templateId]) {
        this.$set(this.otherForm, templateId, {
          temperature: null,
          humidity: null,
          detectionTime: null,
          detectionPlace: null,
          deviceIds: [],
          insResult: null,
        });
      }
    },
    // 保存当前模板的温度、湿度;备注是单据级,不带模板
    // 保存当前模板的检测条件与检验结论;备注是单据级,不带模板
    subOtherForm(m, type) {
      const payload = { id: this.insOrder.id };
      if (type === "remark") {
        payload.remark = m;
      } else {
        payload.templateId = this.currentTable;
        payload[type] = Number(m);
        if (type === "deviceIds") {
          payload.deviceIds = Array.isArray(m) ? [...m] : [];
        } else if (type === "detectionTime" || type === "detectionPlace") {
          payload[type] = m === "" || m == null ? null : m;
        } else {
          payload[type] = Number(m);
        }
      }
      write(payload).then((res) => {
        this.$message.success("保存成功");
@@ -1815,7 +1850,7 @@
        this.tableList = null;
        this.tableList = [this.tableLists[0]];
        this.currentTable = this.tableLists[0].templateId;
        // 补齐每个模板的温度、湿度槽位
        // 补齐每个模板的检测条件槽位
        this.tableLists.forEach((m) => this.ensureOtherForm(m.templateId));
        // 处理页面列表数据
        this.handleTableData();
@@ -2214,8 +2249,15 @@
    upInsReview(e) {
      if (e == 1) {
        // 通过
        if (this.reviewInsResult !== 0 && this.reviewInsResult !== 1) {
          this.$message.error("请选择检验结论");
        // 每个模板都要有结论;全部合格才算整单合格
        const insResults = this.tableLists.map(
          (m) => (this.otherForm[m.templateId] || {}).insResult
        );
        const missingIndex = insResults.findIndex((r) => r !== 0 && r !== 1);
        if (missingIndex > -1) {
          this.$message.error(
            `请选择「${this.tableLists[missingIndex].templateName}」的检验结论`
          );
          return;
        }
        this.reviewLoading = true;
@@ -2225,7 +2267,7 @@
          laboratory: this.sonLaboratory,
          tell: null,
          userId: this.checkUser,
          insResult: this.reviewInsResult,
          insResult: insResults.every((r) => r === 1) ? 1 : 0,
        }).then((res) => {
          if (res.code === 200) {
            this.$message.success("操作成功");
@@ -2298,23 +2340,22 @@
        this.$message.error("请指定复核人员");
        return;
      }
      if (this.isDirectTemplateOrder() && (!this.selectedDeviceIds || this.selectedDeviceIds.length === 0)) {
        this.$message.error("请选择设备");
        return;
      }
      if (this.insOrder.ifsOrderType !== "02wg") {
        const labels = { temperature: "温度", humidity: "湿度" };
        const missing = [];
        this.tableLists.forEach((m) => {
          const form = this.otherForm[m.templateId] || {};
          ["temperature", "humidity"].forEach((key) => {
            if (!form[key]) missing.push(`「${m.templateName}」的${labels[key]}`);
          });
        });
        if (missing.length > 0) {
          this.$message.error(`请填写${missing[0]}`);
          return;
      const missing = [];
      this.tableLists.forEach((m) => {
        const form = this.otherForm[m.templateId] || {};
        if (this.insOrder.ifsOrderType !== "02wg") {
          if (!form.temperature) missing.push(`请填写「${m.templateName}」的温度`);
          if (!form.humidity) missing.push(`请填写「${m.templateName}」的湿度`);
          if (!form.detectionTime) missing.push(`请选择「${m.templateName}」的检测时间`);
          if (!form.detectionPlace) missing.push(`请填写「${m.templateName}」的检测地点`);
        }
        if (this.isDirectTemplateOrder() && (!form.deviceIds || form.deviceIds.length === 0)) {
          missing.push(`请选择「${m.templateName}」的设备`);
        }
      });
      if (missing.length > 0) {
        this.$message.error(missing[0]);
        return;
      }
      if (!this.insOrder.lotPartId && this.insOrder.ifsOrderType==='02wg') {
        this.$message.error("请填写IFS库存物料批次属性");
@@ -2540,18 +2581,13 @@
      return this.sonLaboratory === "新聚" && this.currentSample &&
        (this.currentSample.insProduct || []).some((product) => product.templateRowIndex != null);
    },
    loadOverviewDevices() {
      Promise.all([search({ status: 0 }), getOrderDevices({ orderId: this.orderId })]).then(([devices, selected]) => {
    loadDeviceOptions() {
      search({ status: 0 }).then((devices) => {
        this.orderDeviceOptions = (devices.data || []).map((device) => ({
          id: device.id,
          label: `${device.deviceName}--${device.managementNumber}`,
        }));
        this.selectedDeviceIds = selected.data || [];
      });
    },
    saveOverviewDevices() {
      return saveOrderDevices({ orderId: this.orderId, deviceIds: this.selectedDeviceIds })
        .then(() => this.$message.success("设备已保存"));
    },
    getAuthorizedPerson() {
      selectUserCondition({ type: 1 }).then((res) => {
@@ -2724,6 +2760,37 @@
  text-align: left;
}
/* 当前检验模板的检测条件与检验结论 */
.template-panel {
  background-color: #f8f9fb;
  border: 1px solid #ebeef5;
  border-radius: 3px;
  padding: 16px 16px 4px;
  margin-bottom: 12px;
  text-align: left;
}
/* form-item 用 inline-flex 保证 label 与控件同行,不依赖行盒宽度推算 */
.template-panel>>>.el-form-item {
  display: inline-flex;
  align-items: center;
  margin-bottom: 12px;
}
.template-panel>>>.el-form-item__label {
  flex: none;
}
.template-panel__unit {
  margin-left: 4px;
  color: #606266;
}
.template-panel__conclusion--divided {
  border-top: 1px dashed #e4e7ed;
  padding-top: 12px;
}
.center {
  width: 100%;
  /* max-height: 580px; */