<template>
  <div class="process-inspection">
    <el-dialog
      title="过程检验"
      :close-on-click-modal="false"
      v-drag
      :visible.sync="visible"
      width="1400px"
      :append-to-body="true"
      @close="handleClose">

      <!-- 查询条件 -->
      <el-form :inline="true" label-position="top" :model="searchData">
        <el-form-item label=" ">
          <el-button type="primary" @click="addModal">新增</el-button>
          <el-button type="primary" @click="submitResult">审核</el-button>
          <el-button type="primary" @click="deleteModal">删除</el-button>
        </el-form-item>
      </el-form>

      <!-- 检验记录展示列表 -->
      <el-table
        :height="400"
        :data="dataList"
        border
        ref="IPQCTable"
        @row-click="IPQCClickRow"
        @selection-change="selectionIPQC"
        style="width: 100%;">
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          :selectable="selectFlag"
          width="50">
        </el-table-column>
        <el-table-column
          prop="state"
          header-align="center"
          align="center"
          label="状态">
          <template slot-scope="scope">
            <div :style="{fontWeight:'bold', color: scope.row.state =='待检验' ? 'red' : scope.row.state =='待审核' ? '#ffa500e0' : scope.row.state =='已完成' ? '#3ac252' : ''}">
              {{ scope.row.state }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          v-for="(item,index) in columnList1" :key="index"
          v-if="!item.columnHidden"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed==''?false:item.fixed"
          :min-width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnImage"> {{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="130"
          label="操作">
          <template slot-scope="scope">
            <el-link style="cursor: pointer" v-if="!authDetail && scope.row.state === '未开始'" @click="actionModal(scope.row)">开始检验</el-link>
            <el-link style="cursor: pointer" v-if="!authDetail && scope.row.state !== '未开始'" @click="detailModal(scope.row)">检验单</el-link>
            <el-link style="cursor: pointer" v-if="!authFile" @click="getFileContentData(scope.row)">工作文件</el-link>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        style="margin-top: 0px"
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[20, 50, 100, 200, 500]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>

      <!-- 新增检验记录弹窗 -->
      <el-dialog title="新增检验记录" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="495px" :append-to-body="true">
        <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="BU" prop="bu" :rules="rules.bu">
            <el-select v-model="modalData.bu" placeholder="请选择" @change="buChange" style="width: 221px">
              <el-option
                v-for="i in userBuList"
                :key="i.buNo"
                :label="i.sitename"
                :value="i.buNo">
                <span style="float: left;width: 100px">{{ i.sitename }}</span>
                <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;width: 60px">
                  {{ i.buDesc }}
                </span>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="标签号">
            <el-input v-if="this.modalData.specialTaskFlag === 'Y'" disabled v-model="modalData.rollNo" style="width: 221px"></el-input>
            <el-input v-else v-model="modalData.rollNo" @keyup.native.enter="rollNoEnter" clearable style="width: 221px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px">
          <el-form-item v-if="this.modalData.specialTaskFlag !== 'Y' && (this.modalData.rollNo === '' || this.modalData.rollNo == null)" prop="orderNo" :rules="rules.seqNoType">
            <span style="cursor: pointer" slot="label" @click="getBaseList(1052)"><a herf="#">派工单号</a></span>
            <el-input v-model="modalData.seqNo" style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item v-if="this.modalData.specialTaskFlag !== 'Y' && this.modalData.rollNo !== '' && this.modalData.rollNo != null" prop="orderNo" :rules="rules.seqNoType">
            <span slot="label">派工单号</span>
            <el-input v-model="modalData.seqNo" disabled style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item v-if="this.modalData.specialTaskFlag === 'Y'" prop="orderNo" :rules="rules.seqNoType">
            <span slot="label">派工单号</span>
            <el-input v-model="modalData.seqNo" disabled style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item label="工单号" prop="orderNo" :rules="rules.orderNoType">
            <el-input v-model="modalData.orderNo" style="width: 221px" disabled></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px">
          <el-form-item label="工序" prop="operationDesc" :rules="rules.operationDescType">
            <el-select v-model="modalData.operationDesc" placeholder="请选择" style="width: 221px">
              <el-option
                v-for="i in operationList"
                :key="i.operationNo"
                :label="i.operationDesc"
                :value="i.operationDesc">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="this.modalData.specialTaskFlag === 'Y'">
            <span style="cursor: pointer" slot="label" @click="getBaseList(505)"><a herf="#">机台</a></span>
            <el-input v-model="modalData.resourceDesc" style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item v-else label="机台" prop="resourceId" :rules="rules.resourceIdType">
            <el-input v-model="modalData.resourceDesc" style="width: 221px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px">
          <el-form-item v-if="this.modalData.specialTaskFlag === 'Y'" :model="modalData">
            <span style="cursor: pointer" slot="label" @click="queryPartList"><a herf="#">物料编码</a></span>
            <el-input v-model="modalData.partNo" style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item v-else label="物料编码" prop="partNo" :rules="rules.partNoType">
            <el-input v-model="modalData.partNo" readonly style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item label="物料名称">
            <el-input v-model="modalData.partDesc" readonly style="width: 221px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px">
          <el-form-item label="物料类别">
            <el-input v-model="modalData.invdefinetype" readonly style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item label="SKU">
            <el-input v-model="modalData.sku" readonly style="width: 221px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px">
          <el-form-item label="检验类型" prop="inspectionTypeNo" :rules="rules.inspectionTypeNoType">
            <el-select v-model="modalData.inspectionTypeNo" style="width: 221px">
              <el-option label="首件检" value="首件检"></el-option>
              <el-option label="自检" value="自检"></el-option>
              <el-option label="巡检" value="巡检"></el-option>
              <el-option label="末件检" value="末件检"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="送检数量" prop="rollQty" :rules="rules.rollQtyType">
            <el-input v-model="modalData.rollQty" type="number" style="width: 103px"></el-input>
          </el-form-item>
          <el-form-item label="单位" prop="umId" :rules="rules.umIdType">
            <el-select v-model="modalData.umId" placeholder="请选择" style="width: 103px">
              <el-option
                v-for="i in umList"
                :key="i.umId"
                :label="i.umName"
                :value="i.umId">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px">
          <el-form-item prop="templateId" :rules="rules.templateId">
            <span style="cursor: pointer" v-if="this.controlData.baseData === '控制'" slot="label" @click="queryTemplateList"><a>检验模板</a></span>
            <span v-else slot="label">检验模板</span>
            <el-input v-model="modalData.templateName" disabled style="width: 221px"></el-input>
          </el-form-item>
          <el-form-item label="送检总数">
            <el-input v-model="modalData.sjzs" disabled style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item label=" ">
            <input type="checkbox" id="specialTask" name="specialTask" v-model="checked" @click="changeSpecialTask"/> <label for="specialTask">无工单检验</label>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px">
          <el-form-item label="老卷号">
            <el-input v-model="modalData.batchRollNo" style="width: 456px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px">
          <el-form-item label="特殊要求">
            <el-input type="textarea" v-model="modalData.specialRequirements" :rows="3" resize='none' show-word-limit style="width: 456px;height: 30px"></el-input>
          </el-form-item>
        </el-form>
        <el-footer style="height:40px;margin-top: 55px;text-align:center">
          <el-button type="primary" :loading="saveLoading" @click="saveData">保存</el-button>
          <el-button @click="modalFlag = false">关闭</el-button>
        </el-footer>
      </el-dialog>

      <!-- 派工单号弹出框 -->
      <el-dialog title="派工单号" @close="closeSeqDialog" :close-on-click-modal="false" v-drag :visible.sync="seqDetailFlag" width="952px" :append-to-body="true">
        <el-form :inline="true" label-position="top" :model="seqDetailData" style="margin-left: 7px;margin-top: -5px;">
          <el-form-item label="工单号">
            <el-input v-model="seqDetailData.orderNo" clearable style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item label="派工单号">
            <el-input v-model="seqDetailData.seqNo" clearable style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item label="SKU">
            <el-input v-model="seqDetailData.sku" clearable style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item label="物料编码">
            <el-input v-model="seqDetailData.partNo" clearable style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item label="物料名称">
            <el-input v-model="seqDetailData.partDesc" clearable style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item label="工序">
            <el-input v-model="seqDetailData.operationDesc" clearable style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item label=" ">
            <el-button type="primary" @click="searchSeqInfo" style="margin-top: 24px">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :height="400"
          :data="seqInfoList"
          @row-dblclick="getRowData1"
          border
          style="width: 100%;">
          <el-table-column
            v-for="(item,index) in seqDetailColumnList" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
        </el-table>
        <el-footer style="height:40px;margin-top: 20px;text-align:center">
          <el-button type="primary" @click="seqDetailFlag=false">关闭</el-button>
        </el-footer>
      </el-dialog>

      <!-- 检验模板弹出框 -->
      <el-dialog title="检验模板清单" :close-on-click-modal="false" v-drag :visible.sync="templateModelFlag" width="520px" :append-to-body="true">
        <div class="rq">
          <el-form :inline="true" label-position="top" :model="templateData">
            <el-form-item :label="'模板编码'">
              <el-input v-model="templateData.templateId" clearable style="width: 120px"></el-input>
            </el-form-item>
            <el-form-item :label="'模板名称'">
              <el-input v-model="templateData.templateName" clearable style="width: 120px"></el-input>
            </el-form-item>
            <el-form-item :label="' '">
              <el-button type="primary" @click="queryTemplateList">查询</el-button>
            </el-form-item>
          </el-form>
          <el-table
            :height="300"
            :data="templateList"
            @row-dblclick="getRowData"
            border
            style="width: 100%;">
            <el-table-column
              v-for="(item,index) in templateDetailList" :key="index"
              :sortable="item.columnSortable"
              :prop="item.columnProp"
              :header-align="item.headerAlign"
              :show-overflow-tooltip="item.showOverflowTooltip"
              :align="item.align"
              :fixed="item.fixed==''?false:item.fixed"
              :min-width="item.columnWidth"
              :label="item.columnLabel">
              <template slot-scope="scope">
                <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
                <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <el-footer style="height:40px;margin-top: 20px;text-align:center">
          <el-button type="primary" @click="templateModelFlag=false">关闭</el-button>
        </el-footer>
      </el-dialog>

      <!-- 检验单详情对话框 -->
      <el-dialog
        title="检验明细清单"
        :close-on-click-modal="false"
        v-drag
        :visible.sync="detailInformationFlag"
        width="1200px"
        top="2vh"
        :append-to-body="true"
        custom-class="ipqc-inspection-dialog">

        <!-- 单据信息卡片 -->
        <div class="inspection-info-card">
          <div class="info-section">
            <div class="section-title">
              <i class="el-icon-document"></i>
              <span>检验单信息</span>
            </div>
            <!-- 第一行：物料信息 + 人员信息 -->
            <el-row :gutter="12" class="info-row">
              <el-col :span="3">
                <div class="info-item">
                  <label>物料编码</label>
                  <el-input v-model="detailData.partNo" disabled size="small"></el-input>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="info-item">
                  <label>物料类别</label>
                  <el-input v-model="detailData.invdefinetype" readonly size="small"></el-input>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="info-item">
                  <label>物料名称</label>
                  <el-input v-model="detailData.partDesc" disabled size="small"></el-input>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="info-item">
                  <label>规格型号</label>
                  <el-input v-model="detailData.spec" disabled size="small"></el-input>
                </div>
              </el-col>
              <el-col :span="2">
                <div class="info-item">
                  <label>单位</label>
                  <el-input v-model="detailData.umName" disabled size="small"></el-input>
                </div>
              </el-col>
              <el-col :span="3">
                <div class="info-item">
                  <label>
                    <span v-if="detailData.submitFlag === 'Y'">协同人员</span>
                    <a v-else style="cursor: pointer" @click="getOperatorListModal">协同人员</a>
                  </label>
                  <el-input v-model="detailData.operatorName" readonly size="small"></el-input>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="info-item">
                  <label>
                    <span v-if="detailData.submitFlag === 'Y'">责任人</span>
                    <a v-else style="cursor: pointer" @click="getResponsiblePersonListModal">责任人</a>
                  </label>
                  <el-input v-model="detailData.responsiblePersonName" readonly size="small"></el-input>
                </div>
              </el-col>
            </el-row>
            <!-- 第二行：数量信息 -->
            <el-row :gutter="12" class="info-row" style="margin-top: 12px">
              <el-col :span="4">
                <div class="info-item">
                  <label>送检数量</label>
                  <el-input-number :controls="false" :step="0" v-model="detailData.rollQty" size="small" style="width: 100%"></el-input-number>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="info-item">
                  <label>抽样数量</label>
                  <el-input-number :controls="false" :step="0" v-model="detailData.samplingQty" size="small" style="width: 100%"></el-input-number>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="info-item">
                  <label>合格数量</label>
                  <el-input-number :controls="false" :step="0" min="0" v-if="detailData.submitFlag === 'Y'" v-model="detailData.passQty" disabled size="small" style="width: 100%"></el-input-number>
                  <el-input-number :controls="false" :step="0" min="0" v-else v-model="detailData.passQty" size="small" style="width: 100%"></el-input-number>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="info-item">
                  <label>不合格数量</label>
                  <el-input-number :controls="false" :step="0" min="0" v-model="detailData.notPassQty" disabled size="small" style="width: 100%"></el-input-number>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="info-item">
                  <label>不合格项目数量</label>
                  <el-input-number :controls="false" :step="0" v-if="detailData.submitFlag === 'Y'" v-model="detailData.unqualifiedQty" disabled size="small" style="width: 100%"></el-input-number>
                  <el-input-number :controls="false" :step="0" v-else v-model="detailData.unqualifiedQty" size="small" style="width: 100%"></el-input-number>
                </div>
              </el-col>
              <el-col :span="4">
                <div class="info-item">
                  <label>批次合格数</label>
                  <el-input-number :controls="false" :step="0" min="0" v-model="detailData.batchQualifiedQty" disabled size="small" style="width: 100%"></el-input-number>
                </div>
              </el-col>
            </el-row>
          </div>

          <div class="info-section" style="margin-top: 10px">
            <div class="section-title">
              <i class="el-icon-finished"></i>
              <span>检验结论</span>
            </div>
            <el-row :gutter="12" class="info-row">
              <el-col :span="3">
                <div class="info-item">
                  <label>检验结论</label>
                  <el-select v-if="detailData.submitFlag === 'Y'" v-model="detailData.inspectionResult" disabled size="small" placeholder="请选择" style="width: 100%">
                    <el-option label="合格" value="合格"></el-option>
                    <el-option label="不合格" value="不合格"></el-option>
                  </el-select>
                  <el-select v-else v-model="detailData.inspectionResult" @change="resultChange" size="small" placeholder="请选择" style="width: 100%">
                    <el-option label="合格" value="合格"></el-option>
                    <el-option label="不合格" value="不合格"></el-option>
                  </el-select>
                </div>
              </el-col>
              <el-col :span="7">
                <div class="info-item">
                  <label>质检备注</label>
                  <el-input v-if="detailData.submitFlag === 'Y'" v-model="detailData.inspectionRemark" disabled size="small"></el-input>
                  <el-input v-else v-model="detailData.inspectionRemark" size="small"></el-input>
                </div>
              </el-col>
              <el-col :span="3" v-show="detailData.inspectionResult === '不合格'">
                <div class="info-item">
                  <label>处置措施</label>
                  <el-select v-if="detailData.submitFlag === 'Y'" clearable v-model="detailData.disposalMeasures" disabled size="small" style="width: 100%">
                    <el-option
                      v-for="i in disposalMeasuresOptions"
                      :key="i.id"
                      :label="i.disposalMeasures"
                      :value="i.disposalMeasures">
                    </el-option>
                  </el-select>
                  <el-select v-else clearable v-model="detailData.disposalMeasures" size="small" style="width: 100%">
                    <el-option
                      v-for="i in disposalMeasuresOptions"
                      :key="i.id"
                      :label="i.disposalMeasures"
                      :value="i.disposalMeasures">
                    </el-option>
                  </el-select>
                </div>
              </el-col>
              <el-col :span="7" v-show="detailData.inspectionResult === '不合格'">
                <div class="info-item">
                  <label>处置说明</label>
                  <el-input v-if="detailData.submitFlag === 'Y'" v-model="detailData.disposalRemark" disabled size="small"></el-input>
                  <el-input v-else v-model="detailData.disposalRemark" size="small"></el-input>
                </div>
              </el-col>
            </el-row>
          </div>

          <!-- 操作按钮区域 -->
          <div class="action-buttons">
            <div class="left-actions">
              <el-button v-if="detailData.submitFlag !== 'Y'" type="primary" size="small" :loading="loadFlag" @click="handleDataAcquisition" icon="el-icon-download">
                数据采集
              </el-button>
              <el-button type="info" size="small" @click="getFileContentData(detailData)" icon="el-icon-folder-opened">
                文件清单
              </el-button>
            </div>
            <div class="right-actions">
              <el-button type="success" size="small" @click="openItemOperationDialog" icon="el-icon-setting">
                项目导入
              </el-button>
              <el-button type="primary" size="small" @click="openTemplateImportDialog" icon="el-icon-download">
                模板导入
              </el-button>
            </div>
          </div>
        </div>

        <!-- 检验项目列表 -->
        <div class="inspection-table-wrapper">
          <div class="table-header">
            <span class="table-title">
              <i class="el-icon-tickets"></i>
              检验项目明细
            </span>
          </div>
          <el-table
            :height="435"
            :data="detailList"
            border
            stripe
            style="width: 100%;"
            class="inspection-table">
            <el-table-column
              prop=""
              header-align="center"
              align="center"
              width="80"
              label="操作">
              <template slot-scope="scope">
                <el-button icon="el-icon-edit-outline" type="success" size="mini" :loading="loadFlag" @click="dataAcquisitionByItemHandle(scope.row)" title="数据采集"></el-button>
              </template>
            </el-table-column>
            <el-table-column
              prop="itemNo"
              header-align="center"
              align="center"
              min-width="80"
              label="项目编号">
            </el-table-column>
            <el-table-column
              prop="itemDesc"
              header-align="center"
              align="left"
              min-width="150"
              show-overflow-tooltip
              label="项目名称">
            </el-table-column>
            <el-table-column
              prop="defaultValue"
              header-align="center"
              align="center"
              min-width="100"
              label="标准值">
              <template slot-scope="scope">
                <el-input v-model="scope.row.defaultValue" style="height: 11px; width: 98%"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="minValue"
              header-align="center"
              align="center"
              min-width="80"
              label="下限值">
              <template slot-scope="scope">
                <el-input v-model="scope.row.minValue" style="height: 11px; width: 98%"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="maxValue"
              header-align="center"
              align="center"
              min-width="80"
              label="上限值">
              <template slot-scope="scope">
                <el-input v-model="scope.row.maxValue" style="height: 11px; width: 98%"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop=""
              header-align="center"
              align="right"
              min-width="80"
              label="实测值">
              <template slot-scope="scope">
                <el-input :ref="`textValue${scope.$index}`" v-if="scope.row.valueTypeDb === 'N'" v-model="scope.row.numberValue" @keyup.enter.native="focusNextInput(scope.$index, 'textValue')" type="number" @change="updateItemResult(scope.row)" style="height: 11px; width: 98%"></el-input>
                <el-input :ref="`textValue${scope.$index}`" v-else v-model="scope.row.textValue" @keyup.enter.native="focusNextInput(scope.$index, 'textValue')" style="height: 11px; width: 98%"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop=""
              header-align="center"
              align="right"
              min-width="80"
              label="抽样数量">
              <template slot-scope="scope">
                <el-input-number :controls="false" :step="0" v-if="detailData.submitFlag === 'Y'" v-model="scope.row.samplingQty" disabled style="height: 11px; width:98%"></el-input-number>
                <el-input-number :controls="false" :step="0" v-else :ref="`samplingQty${scope.$index}`" v-model="scope.row.samplingQty" @keyup.enter.native="focusNextInput(scope.$index, 'samplingQty')" style="height: 11px; width: 98%"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column
              prop=""
              header-align="center"
              align="right"
              min-width="80"
              label="不合格数量">
              <template slot-scope="scope">
                <el-input-number :controls="false" :step="0" v-if="detailData.submitFlag === 'Y'" v-model="scope.row.unqualifiedQuantity" disabled style="height: 11px; width:98%"></el-input-number>
                <el-input-number :controls="false" :step="0" v-else :ref="`unqualifiedQuantity${scope.$index}`" v-model="scope.row.unqualifiedQuantity" @keyup.enter.native="focusNextInput(scope.$index, 'unqualifiedQuantity')" style="height: 11px; width: 98%"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column
              prop=""
              header-align="center"
              align="right"
              min-width="90"
              label="项目检验结论">
              <template slot-scope="scope">
                <el-select :class="{redElSelect:scope.row.itemResult === 'N', greenElSelect:scope.row.itemResult === 'Y'}" v-if="detailData.submitFlag === 'Y'" v-model="scope.row.itemResult" disabled style="height: 11px;padding: 0px">
                  <el-option label="合格" value="Y" style="color: green"></el-option>
                  <el-option label="不合格" value="N" style="color: red"></el-option>
                </el-select>
                <el-select :class="{redElSelect:scope.row.itemResult === 'N', greenElSelect:scope.row.itemResult === 'Y'}" v-else v-model="scope.row.itemResult" style="height: 11px;padding: 0px" placeholder="合格">
                  <el-option label="合格" value="Y" style="color: green"></el-option>
                  <el-option label="不合格" value="N" style="color: red"></el-option>
                </el-select>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 底部操作按钮 -->
        <div class="dialog-footer">
          <el-button v-if="detailData.state === '待检验'" type="primary" :loading="transferLoadFlag" @click="Transfer('1')">应用</el-button>
          <el-button v-if="detailData.state === '待检验' || detailData.state === '待审核'" type="primary" :loading="transferLoadFlag" @click="Transfer('2')">保存</el-button>
          <el-button @click="detailInformationFlag=false">关闭</el-button>
        </div>
      </el-dialog>

      <!-- 人员清单弹窗 -->
      <el-dialog title="人员清单" :close-on-click-modal="false" v-drag :visible.sync="operatorModelFlag" width="820px" :append-to-body="true">
        <div class="rq">
          <el-form :inline="true" label-position="top" :model="operatorData">
            <el-form-item v-if="operatorData.flag !== '2'" :label="'所属角色'">
              <el-select v-model="operatorData.roleId" placeholder="请选择" style="width: 120px">
                <el-option
                  v-for="i in roleList"
                  :key="i.roleId"
                  :label="i.roleName"
                  :value="i.roleId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="'用户编码'">
              <el-input v-model="operatorData.adminID" clearable style="width: 120px"></el-input>
            </el-form-item>
            <el-form-item :label="'用户姓名'">
              <el-input v-model="operatorData.adminName" clearable style="width: 120px"></el-input>
            </el-form-item>
            <el-form-item :label="' '">
              <el-button type="primary" @click="getOperatorList2">查询</el-button>
            </el-form-item>
          </el-form>
          <el-table
            :height="300"
            :data="operatorList"
            ref="operatorTable"
            @row-click="operatorClickRow"
            @selection-change="selectionChangeHandle2"
            border
            style="width: 100%;">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              v-for="(item,index) in operatorDetailList" :key="index"
              :sortable="item.columnSortable"
              :prop="item.columnProp"
              :header-align="item.headerAlign"
              :show-overflow-tooltip="item.showOverflowTooltip"
              :align="item.align"
              :fixed="item.fixed==''?false:item.fixed"
              :min-width="item.columnWidth"
              :label="item.columnLabel">
              <template slot-scope="scope">
                <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
                <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <el-footer style="height:40px;margin-top: 20px;text-align:center">
          <el-button type="primary" @click="confirmOperator">确认</el-button>
          <el-button type="primary" @click="operatorModelFlag = false">关闭</el-button>
        </el-footer>
      </el-dialog>

      <!-- 项目操作对话框 -->
      <el-dialog
        title="检验项目操作"
        @close="refreshInspectionDetailList"
        :close-on-click-modal="false"
        v-drag
        :visible.sync="itemOperationDialogFlag"
        width="1200px"
        :append-to-body="true"
        custom-class="item-operation-dialog">
        <!-- 查询区域 -->
        <div class="search-container">
          <el-form :inline="true" size="small">
            <el-form-item label="项目编码">
              <el-input
                v-model="itemOperationQuery.itemNo"
                placeholder="请输入项目编码"
                clearable
                prefix-icon="el-icon-search"
                style="width: 160px">
              </el-input>
            </el-form-item>
            <el-form-item label="项目名称">
              <el-input
                v-model="itemOperationQuery.itemDesc"
                placeholder="请输入项目名称"
                clearable
                prefix-icon="el-icon-search"
                style="width: 200px">
              </el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="searchIPQCItems" size="small">查询</el-button>
              <el-button icon="el-icon-refresh" @click="resetItemQuery" size="small">重置</el-button>
            </el-form-item>
          </el-form>
        </div>

        <!-- 主内容区域 -->
        <div class="item-operation-content">
          <!-- 可选项目 -->
          <div class="item-panel available-panel">
            <div class="panel-header">
              <i class="el-icon-s-unfold"></i>
              <span class="panel-title">可选项目</span>
              <span class="item-count">({{ availableItemList.length }})</span>
            </div>
            <el-table
              height="420px"
              :data="availableItemList"
              ref="availableItemTable"
              @row-click="availableItemClickRow"
              @selection-change="availableItemSelectionChange"
              highlight-current-row
              class="operation-table"
              :header-cell-style="{background: '#f5f7fa', color: '#606266', fontWeight: '500'}">
              <el-table-column
                type="selection"
                width="45"
                align="center">
              </el-table-column>
              <el-table-column
                prop="itemNo"
                align="center"
                width="100"
                label="编码">
              </el-table-column>
              <el-table-column
                prop="itemDesc"
                align="left"
                min-width="140"
                show-overflow-tooltip
                label="名称">
              </el-table-column>
              <el-table-column
                prop="defaultValue"
                align="center"
                width="80"
                show-overflow-tooltip
                label="标准值">
              </el-table-column>
              <el-table-column
                align="center"
                width="100"
                label="范围">
                <template slot-scope="scope">
                  <span v-if="scope.row.minValue || scope.row.maxValue" style="font-size: 12px; color: #909399;">
                    {{ scope.row.minValue || '-' }} ~ {{ scope.row.maxValue || '-' }}
                  </span>
                </template>
              </el-table-column>
            </el-table>
          </div>

          <!-- 操作按钮 -->
          <div class="operation-buttons">
            <el-tooltip content="添加选中项目" placement="left">
              <el-button
                type="primary"
                icon="el-icon-d-arrow-right"
                circle
                @click="addInspectionItems"
                :disabled="!availableItemSelections || availableItemSelections.length === 0">
              </el-button>
            </el-tooltip>
            <el-tooltip content="移除选中项目" placement="right">
              <el-button
                type="danger"
                icon="el-icon-d-arrow-left"
                circle
                @click="deleteInspectionItems"
                :disabled="!selectedItemSelections || selectedItemSelections.length === 0">
              </el-button>
            </el-tooltip>
          </div>

          <!-- 已有项目 -->
          <div class="item-panel selected-panel">
            <div class="panel-header">
              <i class="el-icon-s-check"></i>
              <span class="panel-title">已有项目</span>
              <span class="item-count">({{ selectedItemList.length }})</span>
            </div>
            <el-table
              height="420px"
              :data="selectedItemList"
              ref="selectedItemTable"
              @row-click="selectedItemClickRow"
              @selection-change="selectedItemSelectionChange"
              highlight-current-row
              class="operation-table"
              :header-cell-style="{background: '#f5f7fa', color: '#606266', fontWeight: '500'}">
              <el-table-column
                type="selection"
                width="45"
                align="center">
              </el-table-column>
              <el-table-column
                prop="itemNo"
                align="center"
                width="100"
                label="编码">
              </el-table-column>
              <el-table-column
                prop="itemDesc"
                align="left"
                min-width="200"
                show-overflow-tooltip
                label="名称">
              </el-table-column>
            </el-table>
          </div>
        </div>

        <!-- 底部按钮 -->
        <div slot="footer" class="dialog-footer">
          <el-button @click="itemOperationDialogFlag = false" size="small" style="width: 80px;">关闭</el-button>
        </div>
      </el-dialog>

      <!-- 模板导入对话框 -->
      <el-dialog
        title="检验模板导入"
        :close-on-click-modal="false"
        v-drag
        :visible.sync="templateImportDialogFlag"
        width="800px"
        :append-to-body="true"
        custom-class="template-import-dialog">
        <!-- 查询区域 -->
        <div class="search-container">
          <el-form :inline="true" size="small">
            <el-form-item label="模板编码">
              <el-input
                v-model="templateQuery.templateId"
                placeholder="请输入模板编码"
                clearable
                prefix-icon="el-icon-search"
                style="width: 160px">
              </el-input>
            </el-form-item>
            <el-form-item label="模板名称">
              <el-input
                v-model="templateQuery.templateDesc"
                placeholder="请输入模板名称"
                clearable
                prefix-icon="el-icon-search"
                style="width: 200px">
              </el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="searchIPQCTemplates" size="small">查询</el-button>
              <el-button icon="el-icon-refresh" @click="resetTemplateQuery" size="small">重置</el-button>
            </el-form-item>
          </el-form>
        </div>

        <!-- 模板列表 -->
        <div class="template-list-container">
          <el-table
            height="400px"
            :data="templateImportList"
            ref="templateTable"
            @row-click="templateClickRow"
            @selection-change="templateSelectionChange"
            highlight-current-row
            class="template-table"
            :header-cell-style="{background: '#f5f7fa', color: '#606266', fontWeight: '500'}">
            <el-table-column
              type="selection"
              width="50"
              align="center">
            </el-table-column>
            <el-table-column
              prop="templateId"
              align="center"
              width="150"
              label="模板编码">
            </el-table-column>
            <el-table-column
              prop="templateName"
              align="left"
              min-width="200"
              show-overflow-tooltip
              label="模板名称">
            </el-table-column>
            <el-table-column
              prop="inspectionTypeName"
              align="center"
              width="120"
              label="检验类型">
            </el-table-column>
          </el-table>
        </div>

        <!-- 底部按钮 -->
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" :loading="importLoading" @click="confirmImportTemplate" size="small">确认导入</el-button>
          <el-button @click="templateImportDialogFlag = false" size="small">关闭</el-button>
        </div>
      </el-dialog>

    </el-dialog>

    <!-- 文件清单对话框 -->
    <el-dialog title="文件清单" :close-on-click-modal="false" :visible.sync="fileFlag" width="900px" append-to-body>
      <el-tabs v-model="fileActiveTab" type="border-card">
        <el-tab-pane label="QC检验文件" name="qcFile">
          <el-table :height="350" :data="fileContentList" border v-loading="fileLoading" style="width: 100%;">
            <el-table-column prop="fileName" header-align="center" align="left" label="文件名称" min-width="200" show-overflow-tooltip></el-table-column>
            <el-table-column prop="createdBy" header-align="center" align="center" label="上传人" width="120"></el-table-column>
            <el-table-column prop="createDate" header-align="center" align="center" label="上传时间" width="160"></el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="SOP文件" name="sopFile">
          <el-table :data="sopFileList" border v-loading="sopFileLoading" height="350" style="width: 100%;">
            <el-table-column prop="sopName" header-align="center" align="left" label="文件名称" min-width="200" show-overflow-tooltip></el-table-column>
            <el-table-column prop="fileType" header-align="center" align="center" label="文件类型" width="100"></el-table-column>
            <el-table-column prop="version" header-align="center" align="center" label="版本号" width="80"></el-table-column>
            <el-table-column prop="createdBy" header-align="center" align="center" label="上传人" width="100"></el-table-column>
            <el-table-column prop="creationDate" header-align="center" align="center" label="上传时间" width="150"></el-table-column>
            <el-table-column fixed="right" header-align="center" align="center" width="80" label="操作">
              <template slot-scope="scope">
                <el-link type="primary" @click="previewSopFile(scope.row)">预览</el-link>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <el-footer style="height:35px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="fileFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

  </div>
</template>

<script>
import {
  qcIPQCInspectionSearch, // 查询IPQC的检验记录
  ipqcRecordDelete, // 删除检验记录
  saveOsInspection, // 新增检验记录
  saveIPQCSubmitResult, // 审核
  getSiteAndBuByUserName, // 获取用户BU列表
  ipqcDetailSearch, // 查询IPQC的检验明细
  actionIPQCInspection, // 开始检验
  getIPQCItemObjectList, // 查询项目设备
  getOperationList, // 查询工序列表
  queryController, // 检查动控
  umSearch, // 查询单位列表
  queryTemplateList, // 获取检验模板列表
  queryPartList, // 查询物料集合
  rollNoEnter as rollNoEnterAPI, // 标签号回车事件
  searchSeqInfo, // 派工单号查询
  getSiteAndBuByUserName2, // 获取BU列表
  saveIPQCDetailedRecord, // 保存检验明细记录
  getSpecialOperationList, // 获取特殊工序列表
  inspectionTypeSearch, // 搜索所有检验类型
  disposalMeasuresSearch, // 获取处置措施列表
  getUserRoleList, // 获取用户角色列表
  getOperatorList, // 获取协同人员列表
  getResponsibleOperatorList, // 获取责任人列表
  dataAcquisition, // 数据采集
  dataAcquisitionByItem, // 按项目数据采集
  getIPQCItemList, // 获取IPQC检验项目列表
  addIPQCItemDetails, // 添加检验项目
  deleteIPQCItemDetails, // 删除检验项目
  getIPQCTemplateList, // 获取IPQC模板列表
  importIPQCTemplateItems, // 导入模板项目
} from "@/api/qc/qc.js"
import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
import { getInspectionFile } from '@/api/eam/eam_object_list.js'
import { searchQcSopFileList, downloadSopFile } from '@/api/qc/qc.js'

export default {
  name: 'ComProcessInspection',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    orderNo: {
      type: String,
      default: ''
    },
    resourceId: {
      type: String,
      default: ''
    },
    seqNo: {
      type: String,
      default: ''
    },
    site: {
      type: String,
      default: ''
    },
    buNo: {
      type: String,
      default: ''
    },
    rollNo: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 查询参数
      searchData: {
        userName: this.$store.state.user.name,
        buNo: '',
        inspectionNo: '',
        partNo: '',
        sku: '',
        partDesc: '',
        inspectionResult: '',
        inspectionTypeNo: '',
        inspectionTypeNos: ['首件检', '巡检'], // 过程检验只展示首件检和巡检
        cinvSourceCode: '',
        orderNo: '',
        seqNo: '',
        operationDesc: '',
        states: [],
        startDate2: '',
        endDate2: '',
        startDate: '',
        endDate: '',
        limit: 20,
        page: 1
      },
      searchLoading: false,
      // 列表数据
      dataList: [],
      IPQCSelections: [],
      // 分页
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      // BU列表
      buList: [],
      userBuList: [],
      // 列配置
      columnList1: [
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1BuDesc',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'buDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1InspectionNo',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'inspectionNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '检验单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1InspectionResult',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'inspectionResult',
          headerAlign: "center",
          align: "center",
          columnLabel: '检验结论',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1DisposalMeasures',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'disposalMeasures',
          headerAlign: "center",
          align: "center",
          columnLabel: '处置措施',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1InspectionTypeNo',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'inspectionTypeNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '检验类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1TaskDate',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'taskDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '送检日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 130,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1InspectionCycle',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'inspectionCycle',
          headerAlign: "center",
          align: "right",
          columnLabel: '检验周期(h)',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1SeqNo',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'seqNo',
          headerAlign: "center",
          align: "left",
          columnLabel: '派工单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1PartNo',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'partNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
          showOverflowTooltip: true
        },
        {
          userId: this.$store.state.user.name,
          functionId: 301014,
          serialNumber: '301014Table1PartDesc',
          tableId: "301014Table1",
          tableName: "IPQC检验记录表",
          columnProp: 'partDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300,
          showOverflowTooltip: true
        },
      ],
      // 新增弹窗
      modalFlag: false,
      modalData: {
        flag: '1',
        site: '',
        bu: '',
        rollNo: '',
        seqNo: '',
        orderNo: '',
        operationDesc: '',
        operationNo: '',
        resourceId: '',
        resourceDesc: '',
        workCenterNo: '',
        partNo: '',
        partDesc: '',
        invdefinetype: '',
        sku: '',
        cinvSourceCode: '',
        inspectionTypeNo: '',
        rollQty: '',
        umId: '',
        umName: '',
        templateId: '',
        templateName: '',
        sjzs: '',
        batchRollNo: '',
        specialRequirements: '',
        specialTaskFlag: 'N'
      },
      saveLoading: false,
      checked: false,
      // 下拉列表数据
      operationList: [],
      umList: [],
      controlData: { baseData: '' },
      // 权限控制
      authDetail: false,
      authFile: false,
      // 详情弹窗相关
      detailInformationFlag: false,
      detailData: {
        site: '',
        buNo: '',
        inspectionNo: '',
        partNo: '',
        partDesc: '',
        spec: '',
        rollQty: '',
        samplingQty: '',
        unqualifiedQty: '',
        unqualifiedQuantity: '',
        submitFlag: '',
        disposalMeasures: '',
        disposalRemark: '',
        inspectionResult: '',
        inspectorNo: '',
        inspectorName: '',
        inspectionRemark: '',
        cinvSourceCode: '',
        sku: '',
        invdefinetype: '',
        umId: '',
        umName: '',
        operator: '',
        operatorName: '',
        responsiblePerson: '',
        responsiblePersonName: '',
        state: '',
        passQty: '',
        notPassQty: '',
        batchQualifiedQty: '',
        orderNo: '',
        templateId: ''
      },
      // 处置措施选项
      disposalMeasuresOptions: [],
      // 协同人员/责任人相关
      roleList: [],
      operatorModelFlag: false,
      operatorData: {
        flag: '',
        site: '',
        bu: '',
        adminID: '',
        adminName: '',
        roleName: '',
        roleId: '',
        userName: ''
      },
      operatorList: [],
      operatorDetailList: [
        {
          columnProp: 'adminID',
          headerAlign: "center",
          align: "center",
          columnLabel: '用户编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        },
        {
          columnProp: 'adminName',
          headerAlign: "center",
          align: "center",
          columnLabel: '用户姓名',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        },
        {
          columnProp: 'roleName',
          headerAlign: "center",
          align: "center",
          columnLabel: '角色',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 150,
          showOverflowTooltip: true
        }
      ],
      dataListSelections2: [],
      // 数据采集loading
      loadFlag: false,
      // 项目导入相关
      itemOperationDialogFlag: false,
      itemOperationQuery: {
        itemNo: '',
        itemDesc: ''
      },
      availableItemList: [],
      selectedItemList: [],
      availableItemSelections: [],
      selectedItemSelections: [],
      // 模板导入相关
      templateImportDialogFlag: false,
      templateQuery: {
        templateId: '',
        templateDesc: ''
      },
      templateImportList: [],
      templateSelections: [],
      importLoading: false,
      detailList: [],
      transferLoadFlag: false,
      saveInformationData: {
        site: '',
        buNo: '',
        inspectionNo:'',
        detailList: [],
        type: ''
      },
      // 开始检验相关
      ItemObjectModelFlag: false,
      actionData: {
        site: '',
        buNo: '',
        inspectionNo: ''
      },
      itemObjectList: [],
      // 工作文件相关
      fileFlag: false,
      fileContentList: [],
      fileLoading: false,
      fileActiveTab: 'qcFile',
      sopFileList: [],
      sopFileLoading: false,
      currentFileRow: null,
      // 派工单号相关
      seqDetailFlag: false,
      seqInfoList: [],
      seqDetailData: {
        orderNo: '',
        seqNo: '',
        sku: '',
        partNo: '',
        partDesc: '',
        operationDesc: '',
        status: ''
      },
      seqDetailColumnList: [
        {
          columnProp: 'orderNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '工单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'seqNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '派工单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'sku',
          headerAlign: "center",
          align: "center",
          columnLabel: 'SKU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'partNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'partDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'lotsize',
          headerAlign: "center",
          align: "right",
          columnLabel: '批量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'qtyrequired',
          headerAlign: "center",
          align: "right",
          columnLabel: '需求数量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'sjzs',
          headerAlign: "center",
          align: "right",
          columnLabel: '送检总数',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        },
        {
          columnProp: 'operationDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '工序',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 80,
          showOverflowTooltip: true
        }
      ],
      // 检验模板相关
      templateModelFlag: false,
      templateData: {
        site: '',
        bu: '',
        templateId: '',
        templateName: '',
        inspectionTypeNo: '',
        inspectionTypeName: ''
      },
      templateList: [],
      templateDetailList: [
        {
          columnProp: 'templateId',
          headerAlign: "center",
          align: "center",
          columnLabel: '模板编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 120,
          showOverflowTooltip: true
        },
        {
          columnProp: 'templateName',
          headerAlign: "center",
          align: "center",
          columnLabel: '模板名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 200,
          showOverflowTooltip: true
        },
        {
          columnProp: 'inspectionTypeName',
          headerAlign: "center",
          align: "center",
          columnLabel: '检验类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          fixed: '',
          columnWidth: 100,
          showOverflowTooltip: true
        }
      ],
      rules: {
        bu: [{ required: true, message: '请选择BU', trigger: ['blur','change']}],
        seqNoType: [{ required: true, message: '请输入派工单号', trigger: ['blur','change'] }],
        orderNoType: [{ required: true, message: '请输入工单号', trigger: ['blur','change'] }],
        operationDescType: [{ required: true, message: '请选择工序', trigger: ['blur','change'] }],
        resourceIdType: [{ required: true, message: '请输入机台', trigger: ['blur','change'] }],
        partNoType: [{ required: true, message: '请输入物料编码', trigger: ['blur','change'] }],
        inspectionTypeNoType: [{ required: true, message: '请选择检验类型', trigger: ['blur','change'] }],
        rollQtyType: [{ required: true, message: '请输入送检数量', trigger: ['blur','change'] }],
        umIdType: [{ required: true, message: '请选择单位', trigger: ['blur','change'] }],
        templateId: [{ required: true, message: '请选择检验模板', trigger: ['blur','change'] }]
      },
      typeOptions: [],
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.init()
      }
    }
  },
  methods: {
    // 初始化
    init() {
      // 设置订单号参数
      if (this.orderNo) {
        this.searchData.orderNo = this.orderNo
      }
      // // 设置机台ID参数
      // if (this.resourceId) {
      //   this.searchData.resourceId = this.resourceId
      // }
      if (this.seqNo) {
        this.searchData.seqNo = this.seqNo
      }
      this.getDataList()
      this.getSiteAndBuByUserName2()
      this.getUmList()
      // 查看 质量任务生成规则控制 动控是否开启
      this.queryController()
      this.inspectionTypeSearch()
      // 获取处置措施列表
      this.getDisposalMeasuresOptions()
      // 获取用户角色列表
      this.getUserRoleListData()
    },

    // 查询检验类型
    inspectionTypeSearch () {
      let tempData = {
        site: this.site
      }
      inspectionTypeSearch(tempData).then(({data}) => {
        if (data.code === 0) {
          this.typeOptions = data.rows
          this.typeOptions.forEach(val => {
            if (val.inspectionTypeName.includes('IPQC')) {
              this.templateData.inspectionTypeNo = val.inspectionTypeNo
              this.templateData.inspectionTypeName = val.inspectionTypeName
            }
          })
        }
      })
    },

    // 检查动控是否开启
    queryController () {
      let tempData = {
        controlNo: '10004',
        site: this.site,
      }
      queryController(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.controlData = data.rows
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    // 获取用户BU列表
    getSiteAndBuByUserName2() {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.userBuList = data.rows
          if (this.userBuList.length > 0) {
            this.modalData.bu = this.userBuList[0].buNo
          }
        }
      })
      getSiteAndBuByUserName2(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.buList = data.rows
        }
      })
    },


    // 获取数据列表
    getDataList() {
      this.searchLoading = true
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      qcIPQCInspectionSearch(this.searchData).then(({data}) => {
        if (data.code === 0) {
          this.dataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          this.searchLoading = false
        } else {
          this.$message.error(data.msg)
        }
      }).catch(() => {
        this.searchLoading = false
      })
    },

    // 行点击事件
    IPQCClickRow(row) {
      console.log('点击行:', row)
    },

    // 选择变化事件
    selectionIPQC(selection) {
      this.IPQCSelections = selection
    },

    // 选择标志
    selectFlag(row, index) {
      return true
    },

    // 分页大小变化
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },

    // 当前页变化
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },

    // 新增弹窗
    addModal() {
      // 判断是否有当前卷号（排除"暂无卷号"的情况）
      const hasCurrentRollNo = this.rollNo && this.rollNo !== '' && this.rollNo !== '暂无卷号';
      
      this.modalData = {
        flag: '1',
        site: '',
        bu: this.userBuList.length > 0 ? this.userBuList[0].buNo : '',
        rollNo: hasCurrentRollNo ? this.rollNo : '',
        seqNo: hasCurrentRollNo ? '' : this.seqNo,
        orderNo: '',
        operationDesc: '',
        operationNo: '',
        resourceId: '',
        resourceDesc: '',
        workCenterNo: '',
        partNo: '',
        partDesc: '',
        invdefinetype: '',
        sku: '',
        cinvSourceCode: '',
        inspectionTypeNo: '',
        rollQty: '',
        umId: this.umList.length > 0 ? this.umList[0].umId : '',
        umName: this.umList.length > 0 ? this.umList[0].umName : '',
        templateId: '',
        templateName: '',
        sjzs: '',
        batchRollNo: '',
        specialRequirements: '',
        specialTaskFlag: 'N'
      }
      this.operationList = []
      this.checked = false
      this.modalFlag = true
      
      // 打开弹窗后自动查询信息
      this.$nextTick(() => {
        if (hasCurrentRollNo) {
          // 有当前卷号，通过标签号查询信息
          this.rollNoEnter();
        } else if (this.seqNo && this.seqNo !== '') {
          // 没有当前卷号但有派工单号，通过派工单号查询信息
          this.seqNoDirectSearch();
        }
      });
    },

    // BU变化事件
    buChange() {
      if (this.modalData.specialTaskFlag !== 'Y') { // 正常检验
        this.modalData.templateId = ''
        this.modalData.templateName = ''
      } else { // 无工单检验
        this.modalData.partNo = ''
        this.modalData.partDesc = ''
        this.modalData.invdefinetype = ''
        this.modalData.sku = ''
        this.modalData.templateId = ''
        this.modalData.templateName = ''
      }
    },

    // 标签号回车事件
    rollNoEnter() {
      if (this.modalData.rollNo) {
        rollNoEnterAPI(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            const rollData = data.rows[0]
            this.modalData.seqNo = rollData.seqNo
            this.modalData.orderNo = rollData.orderNo
            this.modalData.partNo = rollData.partNo
            this.modalData.partDesc = rollData.partDesc
            this.modalData.invdefinetype = rollData.invdefinetype
            this.modalData.sku = rollData.sku
            this.modalData.operationDesc = rollData.operationDesc
            this.modalData.resourceDesc = rollData.resourceDesc
            this.getOperationList()
          } else {
            this.$message.error(data.msg || '标签号查询失败')
          }
        }).catch(() => {
          this.$message.error('标签号查询失败')
        })
      }
    },

    // 获取工序列表
    getOperationList() {
      getOperationList(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.operationList = data.rows
          if (data.rows.length > 0) {
            this.modalData.operationDesc = data.rows[0].operationDesc
            this.modalData.workCenterNo = data.rows[0].workCenterNo
            this.modalData.resourceId = data.rows[0].resourceId
            this.modalData.resourceDesc = data.rows[0].resourceDesc
          }
        }
      })
    },

    // 获取单位列表
    getUmList() {
      let tempData = {
        site: this.site,
        active: 'Y'
      }
      umSearch(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.umList = data.rows
        }
      })
    },

    // 获取基础列表
    getBaseList(type) {
      this.$nextTick(() => {
        if (type === 1052) {
          this.searchSeqInfo()
          this.seqDetailFlag = true
        }
        if (type === 505) {
          // 机台选择逻辑
          console.log('机台选择:', type)
        }
      })
    },

    // 查询物料列表
    queryPartList() {
      console.log('查询物料列表')
    },

    // 查询检验模板列表
    queryTemplateList() {
      this.templateData.bu = this.modalData.bu
      // 查询所有检验模板
      queryTemplateList(this.templateData).then(({data}) => {
        if (data && data.code === 0) {
          this.templateList = data.rows
          this.templateModelFlag = true
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    // 选中检验模板
    getRowData(row) {
      this.modalData.templateId = row.templateId
      this.modalData.templateName = row.templateName
      this.templateModelFlag = false
    },

    // 派工单号查询
    searchSeqInfo() {
      let tempData = {
        bu: this.modalData.bu,
        seqNo: this.seqDetailData.seqNo,
        orderNo: this.seqDetailData.orderNo,
        sku: this.seqDetailData.sku,
        partDesc: this.seqDetailData.partDesc,
        partNo: this.seqDetailData.partNo,
        operationDesc: this.seqDetailData.operationDesc,
        status: this.seqDetailData.status
      }
      if (!this.seqDetailData.seqNo && !this.seqDetailData.orderNo && !this.seqDetailData.sku && !this.seqDetailData.partNo && !this.seqDetailData.partDesc && !this.seqDetailData.operationDesc){
        this.seqInfoList = []
      } else {
        searchSeqInfo(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.seqInfoList = data.rows
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    },

    // 选中派工单号
    getRowData1(row) {
      this.modalData.seqNo = row.seqno || row.seqNo
      this.modalData.orderNo = row.orderno || row.orderNo
      this.modalData.partNo = row.partNo
      this.modalData.partDesc = row.partDesc
      this.modalData.sku = row.sku
      this.modalData.operationDesc = row.operationDesc
      this.modalData.sjzs = row.sjzs
      this.seqDetailFlag = false
      this.getOperationList()
    },

    // 关闭派工单号弹窗
    closeSeqDialog() {
      this.seqDetailData = {
        seqNo: '',
        orderNo: '',
        sku: '',
        partNo: '',
        partDesc: '',
        operationDesc: '',
        status: ''
      }
      this.seqInfoList = []
    },

    // 派工单号直接查询（新增时自动调用）
    seqNoDirectSearch() {
      if (!this.modalData.seqNo) return;
      
      let tempData = {
        bu: this.modalData.bu,
        seqNo: this.modalData.seqNo,
        orderNo: '',
        sku: '',
        partDesc: '',
        partNo: '',
        operationDesc: '',
        status: ''
      }
      searchSeqInfo(tempData).then(({data}) => {
        if (data && data.code === 0 && data.rows && data.rows.length > 0) {
          // 自动选取第一条记录并赋值
          const row = data.rows[0];
          this.modalData.seqNo = row.seqno || row.seqNo;
          this.modalData.orderNo = row.orderno || row.orderNo;
          this.modalData.partNo = row.partNo;
          this.modalData.partDesc = row.partDesc;
          this.modalData.sku = row.sku;
          this.modalData.operationDesc = row.operationDesc;
          this.modalData.sjzs = row.sjzs;
          this.getOperationList();
        }
      }).catch(() => {
        // 查询失败静默处理
      });
    },

    // 无工单检验变化
    changeSpecialTask() {
      // 先重置数据
      this.modalData = {
        flag: '1',
        site: '',
        bu: this.userBuList.length > 0 ? this.userBuList[0].buNo : '',
        rollNo: '',
        seqNo: '',
        orderNo: '',
        operationDesc: '',
        operationNo: '',
        resourceId: '',
        resourceDesc: '',
        workCenterNo: '',
        partNo: '',
        partDesc: '',
        invdefinetype: '',
        sku: '',
        cinvSourceCode: '',
        inspectionTypeNo: '',
        rollQty: '',
        umId: this.umList.length > 0 ? this.umList[0].umId : '',
        umName: this.umList.length > 0 ? this.umList[0].umName : '',
        templateId: '',
        templateName: '',
        sjzs: '',
        batchRollNo: '',
        specialRequirements: '',
        specialTaskFlag: ''
      }
      // 获取选中框
      let obj = document.getElementsByName('specialTask')
      // 判断是否打勾
      if (obj[0].checked) {
        let tempData = {
          site: '',
          bu: this.modalData.bu
        }
        this.modalData.specialTaskFlag = 'Y'
        // 获取特殊工序列表
        getSpecialOperationList(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.operationList = data.rows
          } else {
            this.$message.error(data.msg)
          }
        })
        // 派工单和工单号赋值
        this.modalData.seqNo = '000#1TSGD'
        this.modalData.orderNo = '000#1'
      } else {
        this.operationList = []
        this.modalData.specialTaskFlag = ''
      }
    },

    // 保存数据
    saveData() {
      // 验证 BU
      if (this.modalData.bu === '' || this.modalData.bu == null) {
        this.$message.warning('请选择BU！')
        return
      }
      // 验证派工单号
      if (this.modalData.seqNo === '' || this.modalData.seqNo == null) {
        this.$message.warning('请选择派工单！')
        return
      }
      // 验证工单号
      if (this.modalData.orderNo === '' || this.modalData.orderNo == null) {
        this.$message.warning('请选择工单！')
        return
      }
      // 验证检验类型
      if (this.modalData.inspectionTypeNo === '' || this.modalData.inspectionTypeNo == null) {
        this.$message.warning('请选择检验类型！')
        return
      }
      // 验证物料编码（非无工单检验）
      if (this.modalData.specialTaskFlag !== 'Y' && (this.modalData.partNo === '' || this.modalData.partNo == null)) {
        this.$message.warning('请选择物料！')
        return
      }
      // 验证工序
      if (this.modalData.operationDesc === '' || this.modalData.operationDesc == null) {
        this.$message.warning('请选择工序！')
        return
      }
      // 验证机台（非无工单检验）
      if (this.modalData.specialTaskFlag !== 'Y' && (this.modalData.resourceId === '' || this.modalData.resourceId == null)) {
        this.$message.warning('请选择机台！')
        return
      }
      // 验证送检数量
      if (this.modalData.rollQty === '' || this.modalData.rollQty == null) {
        this.$message.warning('请填写送检数量！')
        return
      }
      // 验证单位
      if (this.modalData.umId === '' || this.modalData.umId == null) {
        this.$message.warning('请选择单位！')
        return
      }
      // 验证检验模板（动控开启时）
      if (this.controlData.baseData === '控制' && (this.modalData.templateId == null || this.modalData.templateId === '')) {
        this.$message.warning('请选择检验模板！')
        return
      }

      this.saveLoading = true
      if (this.modalData.flag === '1') {
        saveOsInspection(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.operationList = []
            this.modalFlag = false
            this.$message.success('操作成功')
          } else {
            this.$message.error(data.msg)
          }
          this.saveLoading = false
        }).catch(() => {
          this.saveLoading = false
        })
      }
    },

    // 删除
    deleteModal() {
      if (this.IPQCSelections.length === 0) {
        this.$alert('请勾选要删除的检验单！', '提示', {
          confirmButtonText: '确定'
        })
        return false
      }
      this.$confirm(`是否删除该 ${this.IPQCSelections.length} 条检验记录?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let tempData = {
          submitList: this.IPQCSelections
        }
        ipqcRecordDelete(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.IPQCSelections = []
            this.$message.success('操作成功')
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    },

    // 审核
    submitResult() {
      if (this.IPQCSelections.length === 0) {
        this.$alert('请勾选要审核的检验单！', '提示', {
          confirmButtonText: '确定'
        })
        return false
      }
      // 校验单据状态，必须是'待审核'才可以审核
      const invalidRecords = this.IPQCSelections.filter(item => item.state !== '待审核')
      if (invalidRecords.length > 0) {
        this.$alert('只能审核状态为"待审核"的检验单！', '提示', {
          confirmButtonText: '确定'
        })
        return false
      }
      this.$confirm(`是否审核该 ${this.IPQCSelections.length} 条检验记录?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let tempData = {
          submitList: this.IPQCSelections
        }
        saveIPQCSubmitResult(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.IPQCSelections = []
            this.$message.success('操作成功')
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    },

    // 开始检验
    actionModal(row) {
      this.actionData = {
        site: row.site,
        buNo: row.buNo,
        inspectionNo: row.inspectionNo
      }
      getIPQCItemObjectList(this.actionData).then(({data}) => {
        if (data && data.code === 0) {
          if (data.rows.length === 0) {
            this.actionModal2()
          } else {
            this.itemObjectList = data.rows
            this.ItemObjectModelFlag = true
          }
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    // 开始检验确认
    actionModal2() {
      this.$confirm(`确认开始检验?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let tempData = {
          site: this.actionData.site,
          buNo: this.actionData.buNo,
          inspectionNo: this.actionData.inspectionNo,
          actionBy: this.$store.state.user.name,
          state: '待检验',
          equipmentList: this.itemObjectList
        }
        actionIPQCInspection(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.$message.success('操作成功')
            this.ItemObjectModelFlag = false
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    },

    // 明细记录信息查询
    detailModal(row) {
      this.detailData.site = row.site
      this.detailData.buNo = row.buNo
      this.detailData.inspectionNo = row.inspectionNo
      this.detailData.partNo = row.partNo
      this.detailData.partDesc = row.partDesc
      this.detailData.spec = row.spec || ''
      this.detailData.rollQty = row.rollQty
      this.detailData.samplingQty = row.samplingQty
      this.detailData.unqualifiedQty = row.unqualifiedQty
      this.detailData.unqualifiedQuantity = row.unqualifiedQuantity
      this.detailData.submitFlag = row.submitFlag
      this.detailData.disposalMeasures = row.disposalMeasures || ''
      this.detailData.disposalRemark = row.disposalRemark || ''
      this.detailData.inspectionResult = row.inspectionResult
      this.detailData.inspectorNo = row.inspectorNo
      this.detailData.inspectorName = row.inspectorName
      this.detailData.inspectionRemark = row.inspectionRemark
      this.detailData.cinvSourceCode = row.cinvSourceCode
      this.detailData.sku = row.sku
      this.detailData.invdefinetype = row.invdefinetype
      this.detailData.umId = row.umId
      this.detailData.umName = row.umName
      this.detailData.operator = row.operator || ''
      this.detailData.operatorName = row.operatorName || ''
      this.detailData.responsiblePerson = row.responsiblePerson || ''
      this.detailData.responsiblePersonName = row.responsiblePersonName || ''
      this.detailData.state = row.state
      this.detailData.orderNo = row.orderNo || ''
      this.detailData.templateId = row.templateId || ''
      if (row.state === '待检验') {
        this.detailData.passQty = row.samplingQty
      } else {
        this.detailData.passQty = row.passQty
        this.detailData.notPassQty = row.notPassQty
      }
      this.detailData.batchQualifiedQty = row.batchQualifiedQty
      this.getInspectionFormData()
      this.detailInformationFlag = true
    },

    // 检验单明细
    getInspectionFormData() {
      ipqcDetailSearch(this.detailData).then(({data}) => {
        if (data && data.code === 0) {
          this.detailList = data.rows
        } else {
          this.detailList = []
        }
      })
    },

    // 刷新派设备文档的列表
    getFileContentData(row) {
      this.currentFileRow = row
      this.fileActiveTab = 'qcFile'
      let currentData = {
        orderRef1: row.site,
        orderRef2: row.inspectionNo,
        orderRef4: row.buNo,
        partNo: row.partNo
      }
      this.fileLoading = true
      getInspectionFile(currentData).then(({data}) => {
        if (data && data.code === 0) {
          this.fileContentList = data.rows
        } else {
          this.fileContentList = []
        }
        this.fileLoading = false
      }).catch(()=>{
        this.fileLoading = false
      })
      this.getSopFileList(row)
      this.fileFlag = true
    },

    // 获取SOP文件列表（过程检验传所有条件：site, partNo, operationDesc, workcenterNo, orderNo）
    getSopFileList(row) {
      this.sopFileLoading = true
      this.sopFileList = []
      searchQcSopFileList({
        site: row.site,
        partNo: row.partNo || '',
        operationDesc: row.operationDesc || '',
        workcenterNo: row.workCenterNo || '',
        orderNo: row.orderNo || ''
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.sopFileList = data.rows || []
        } else {
          this.sopFileList = []
        }
        this.sopFileLoading = false
      }).catch(() => {
        this.sopFileList = []
        this.sopFileLoading = false
      })
    },

    previewSopFile(row) {
      if (!row.sopUrl) { this.$message.warning('该文件暂无预览路径'); return }
      const fileName = row.sopName || row.sopUrl
      let fileSuffix = fileName.includes('.') ? fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase() : ''
      const officeTypes = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx']
      if (officeTypes.includes(fileSuffix)) { this.$message.warning(`暂不支持在线预览${fileSuffix.toUpperCase()}文件`); return }
      let mimeType = 'application/octet-stream'
      if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileSuffix)) { mimeType = 'image/' + fileSuffix }
      else if (['mp4', 'avi', 'mov', 'wmv', 'flv'].includes(fileSuffix)) { mimeType = 'video/' + fileSuffix }
      else if (fileSuffix === 'pdf') { mimeType = 'application/pdf' }
      else if (fileSuffix === 'txt') { mimeType = 'text/plain' }
      downloadSopFile(row.sopUrl).then(({ data }) => {
        const blob = new Blob([data], { type: mimeType })
        window.open(URL.createObjectURL(blob), '_blank')
      }).catch(() => { this.$message.error('文件预览失败，请稍后重试') })
    },

    // 保存检验明细（应用/保存）
    Transfer(type) {
      // 保存时校验
      if (type === '2') {
        if (this.detailData.inspectionResult === '' || this.detailData.inspectionResult == null) {
          this.$message.warning('请选择检验结论！')
          return
        }
        if (this.detailData.inspectionResult === '不合格' && (this.detailData.disposalMeasures == null || this.detailData.disposalMeasures === '')) {
          this.$message.warning('请选择处置措施！')
          return
        }
        if (this.detailList.length > 0 && this.detailData.inspectionResult === '不合格') {
          const flag = this.detailList.some(item => item.itemResult === 'N')
          if (!flag) {
            this.$message.warning('请选择不合格项目！')
            return
          }
        }
        if (this.detailData.inspectionResult !== '不合格') {
          this.detailData.disposalMeasures = ''
          this.detailData.disposalRemark = ''
        }
      }
      this.saveDetailInformation(type)
    },

    // 保存检验明细信息
    saveDetailInformation(type) {
      this.saveInformationData.site = this.detailData.site
      this.saveInformationData.buNo = this.detailData.buNo
      this.saveInformationData.inspectionNo = this.detailData.inspectionNo
      this.saveInformationData.disposalMeasures = this.detailData.disposalMeasures
      this.saveInformationData.disposalRemark = this.detailData.disposalRemark
      this.saveInformationData.inspectorNo = this.$store.state.user.name
      this.saveInformationData.inspectionResult = this.detailData.inspectionResult
      this.saveInformationData.inspectionRemark = this.detailData.inspectionRemark
      this.saveInformationData.rollQty = this.detailData.rollQty
      this.saveInformationData.samplingQty = this.detailData.samplingQty
      this.saveInformationData.unqualifiedQty = this.detailData.unqualifiedQty
      this.saveInformationData.partNo = this.detailData.partNo
      this.saveInformationData.partDesc = this.detailData.partDesc
      this.saveInformationData.operator = this.detailData.operator
      this.saveInformationData.responsiblePerson = this.detailData.responsiblePerson
      this.saveInformationData.itemList = JSON.parse(JSON.stringify(this.detailList))
      this.saveInformationData.passQty = this.detailData.passQty == null ? 0 : this.detailData.passQty
      this.saveInformationData.notPassQty = this.detailData.notPassQty == null ? 0 : this.detailData.notPassQty
      this.saveInformationData.batchQualifiedQty = this.detailData.batchQualifiedQty == null ? 0 : this.detailData.batchQualifiedQty
      this.saveInformationData.type = type
      this.transferLoadFlag = true
      saveIPQCDetailedRecord(this.saveInformationData).then(({data}) => {
        if (data && data.code === 0) {
          this.getDataList()
          this.detailInformationFlag = false
          this.$message.success('操作成功')
        } else {
          this.$message.error(data.msg)
        }
        this.transferLoadFlag = false
      }).catch(() => {
        this.transferLoadFlag = false
      })
    },

    // 检验结论变化事件
    resultChange() {
      if (this.detailData.inspectionResult !== '不合格') {
        this.detailData.disposalMeasures = ''
        this.detailData.disposalRemark = ''
      }
    },

    // 获取处置措施列表
    getDisposalMeasuresOptions() {
      let tempData = {
        inspectionTypeNo: '101'
      }
      disposalMeasuresSearch(tempData).then(({data}) => {
        if (data.code === 0) {
          this.disposalMeasuresOptions = data.rows
        }
      })
    },

    // 获取用户角色列表
    getUserRoleListData() {
      getUserRoleList().then(({data}) => {
        if (data.code === 0) {
          this.roleList = data.rows
        } else {
          this.roleList = []
        }
      })
    },

    // 获取协同人员列表
    getOperatorListModal() {
      this.operatorData.flag = '1'
      this.operatorData.bu = this.detailData.site + '_' + this.detailData.buNo
      this.operatorData.userName = this.$store.state.user.name
      if (this.roleList.length > 0) {
        let filterList = this.roleList.filter(item => item.roleName === '机修人员')
        if (filterList.length > 0) {
          this.operatorData.roleId = filterList[0].roleId
        } else {
          this.operatorData.roleId = this.roleList[0].roleId
        }
      } else {
        this.operatorData.roleId = ''
      }
      // 先清空缓存选中
      this.$nextTick(() => {
        if (this.$refs.operatorTable) {
          this.$refs.operatorTable.clearSelection()
        }
      })
      // 拿到选中的人员编号
      let tempDataList = (this.detailData.operator == null ? '' : this.detailData.operator).split(';')
      getOperatorList(this.operatorData).then(({data}) => {
        if (data && data.code === 0) {
          this.operatorList = data.rows
          this.operatorList.forEach(val => {
            // 回显选中
            if (tempDataList.includes(val.adminID)) {
              this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
            }
          })
          this.operatorModelFlag = true
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    // 获取责任人员列表
    getResponsiblePersonListModal() {
      this.operatorData.flag = '2'
      this.operatorData.bu = this.detailData.site + '_' + this.detailData.buNo
      this.operatorData.userName = this.$store.state.user.name
      // 先清空缓存选中
      this.$nextTick(() => {
        if (this.$refs.operatorTable) {
          this.$refs.operatorTable.clearSelection()
        }
      })
      // 拿到选中的人员编号
      let tempDataList = (this.detailData.responsiblePerson == null ? '' : this.detailData.responsiblePerson).split(';')
      getResponsibleOperatorList(this.operatorData).then(({data}) => {
        if (data && data.code === 0) {
          this.operatorList = data.rows
          this.operatorList.forEach(val => {
            // 回显选中
            if (tempDataList.includes(val.adminID)) {
              this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
            }
          })
          this.operatorModelFlag = true
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    // 查询人员列表
    getOperatorList2() {
      if (this.operatorData.flag === '1') {
        // 拿到选中的人员编号
        let tempDataList = (this.detailData.operator == null ? '' : this.detailData.operator).split(';')
        getOperatorList(this.operatorData).then(({data}) => {
          if (data && data.code === 0) {
            this.operatorList = data.rows
            this.operatorList.forEach(val => {
              // 回显选中的部门
              if (tempDataList.includes(val.adminID)) {
                this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
              }
            })
          } else {
            this.operatorList = []
          }
        })
      } else {
        // 拿到选中的人员编号
        let tempDataList = (this.detailData.responsiblePerson == null ? '' : this.detailData.responsiblePerson).split(';')
        getResponsibleOperatorList(this.operatorData).then(({data}) => {
          if (data && data.code === 0) {
            this.operatorList = data.rows
            this.operatorList.forEach(val => {
              // 回显选中的部门
              if (tempDataList.includes(val.adminID)) {
                this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
              }
            })
          } else {
            this.operatorList = []
          }
        })
      }
    },

    // 点击行选中复选框
    operatorClickRow(row) {
      this.$refs.operatorTable.toggleRowSelection(row)
    },

    // 多选
    selectionChangeHandle2(val) {
      this.dataListSelections2 = val
    },

    // 确认多选协同人员
    confirmOperator() {
      if (this.dataListSelections2.length === 0) {
        this.$message.warning('请勾选人员！')
        return
      }
      if (this.operatorData.flag === '1') {
        for (let i = 0; i < this.dataListSelections2.length; i++) {
          if (!this.detailData.operator.split(';').includes(this.dataListSelections2[i].adminID)) {
            this.detailData.operatorName = this.detailData.operatorName + ";" + this.dataListSelections2[i].adminName
            this.detailData.operator = this.detailData.operator + ";" + this.dataListSelections2[i].adminID
          }
        }
        if (this.detailData.operator.charAt(0) === ';') {
          this.detailData.operator = this.detailData.operator.substring(1)
          this.detailData.operatorName = this.detailData.operatorName.substring(1)
        }
      } else {
        for (let i = 0; i < this.dataListSelections2.length; i++) {
          if (!this.detailData.responsiblePerson.split(';').includes(this.dataListSelections2[i].adminID)) {
            this.detailData.responsiblePersonName = this.detailData.responsiblePersonName + ";" + this.dataListSelections2[i].adminName
            this.detailData.responsiblePerson = this.detailData.responsiblePerson + ";" + this.dataListSelections2[i].adminID
          }
        }
        if (this.detailData.responsiblePerson.charAt(0) === ';') {
          this.detailData.responsiblePerson = this.detailData.responsiblePerson.substring(1)
          this.detailData.responsiblePersonName = this.detailData.responsiblePersonName.substring(1)
        }
      }
      this.operatorData = {
        flag: '',
        site: '',
        bu: '',
        adminID: '',
        adminName: '',
        roleName: '',
        roleId: '',
        userName: this.$store.state.user.name
      }
      this.operatorModelFlag = false
    },

    // 数据采集
    handleDataAcquisition() {
      this.loadFlag = true
      let tempDate = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        inspectionNo: this.detailData.inspectionNo,
        flag: 'ipqc'
      }
      dataAcquisition(tempDate).then(({data}) => {
        if (data.code === 0) {
          this.changeMyString(data.rows)
          this.$message.success('数据采集成功')
        } else {
          this.$message.error(data.msg)
        }
        this.loadFlag = false
      })
    },

    // 根据项目数据采集
    dataAcquisitionByItemHandle(row) {
      this.loadFlag = true
      let tempDate = {
        site: row.site,
        buNo: row.buNo,
        inspectionNo: row.inspectionNo,
        templateId: row.templateId,
        itemNo: row.itemNo,
        flag: 'ipqc'
      }
      dataAcquisitionByItem(tempDate).then(({data}) => {
        if (data.code === 0) {
          this.changeMyString(data.rows)
          this.$message.success('数据采集成功')
        } else {
          this.$message.error(data.msg)
        }
        this.loadFlag = false
      })
    },

    // 更新检验明细列表数据
    changeMyString(rows) {
      if (rows && rows.length > 0) {
        rows.forEach(row => {
          const index = this.detailList.findIndex(item => item.itemNo === row.itemNo)
          if (index !== -1) {
            if (row.valueTypeDb === 'N') {
              this.detailList[index].numberValue = row.numberValue
            } else {
              this.detailList[index].textValue = row.textValue
            }
          }
        })
      }
    },

    // 根据实测值更新项目检验结论
    updateItemResult(row) {
      if (row.valueTypeDb === 'N' && row.numberValue !== '' && row.numberValue != null) {
        const numValue = parseFloat(row.numberValue)
        const minValue = row.minValue != null ? parseFloat(row.minValue) : null
        const maxValue = row.maxValue != null ? parseFloat(row.maxValue) : null
        if (minValue != null && maxValue != null) {
          row.itemResult = (numValue >= minValue && numValue <= maxValue) ? 'Y' : 'N'
        }
      }
    },

    // 焦点跳转到下一个输入框
    focusNextInput(currentIndex, fieldType) {
      const nextIndex = currentIndex + 1
      if (nextIndex < this.detailList.length) {
        this.$nextTick(() => {
          const ref = this.$refs[`${fieldType}${nextIndex}`]
          if (ref) {
            if (Array.isArray(ref)) {
              ref[0].focus()
            } else {
              ref.focus()
            }
          }
        })
      }
    },

    // ======================== 项目操作相关方法 ========================
    // 打开项目操作对话框
    openItemOperationDialog() {
      this.itemOperationQuery = {
        itemNo: '',
        itemDesc: '',
      }
      this.searchIPQCItems()
      this.itemOperationDialogFlag = true
    },

    // 查询IPQC类型的检验项目
    async searchIPQCItems() {
      try {
        const {data} = await getIPQCItemList({
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          inspectionNo: this.detailData.inspectionNo,
          templateId: this.detailData.templateId,
          itemNo: this.itemOperationQuery.itemNo,
          itemDesc: this.itemOperationQuery.itemDesc,
        })
        if (data && data.code === 0) {
          this.availableItemList = data.row1 || []
          this.selectedItemList = data.row2 || []
        } else {
          this.$message.error(data.msg || '查询失败')
        }
      } catch (error) {
        this.$message.error('查询失败，请检查')
      }
    },

    // 重置查询条件
    resetItemQuery() {
      this.itemOperationQuery = {
        itemNo: '',
        itemDesc: '',
      }
      this.searchIPQCItems()
    },

    // 可选项目行点击
    availableItemClickRow(row) {
      this.$refs.availableItemTable.toggleRowSelection(row)
    },

    // 可选项目选择变化
    availableItemSelectionChange(selection) {
      this.availableItemSelections = selection
    },

    // 已有项目行点击
    selectedItemClickRow(row) {
      this.$refs.selectedItemTable.toggleRowSelection(row)
    },

    // 已有项目选择变化
    selectedItemSelectionChange(selection) {
      this.selectedItemSelections = selection
    },

    // 添加检验项目
    async addInspectionItems() {
      if (!this.availableItemSelections || this.availableItemSelections.length === 0) {
        this.$message.warning('请选择可选项目！')
        return
      }

      try {
        const {data} = await addIPQCItemDetails({
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          inspectionNo: this.detailData.inspectionNo,
          templateId: this.detailData.templateId,
          orderNo: this.detailData.orderNo,
          itemList: this.availableItemSelections,
        })
        if (data && data.code === 0) {
          this.$message.success('添加成功')
          this.searchIPQCItems()
          this.availableItemSelections = []
        } else {
          this.$message.error(data.msg || '添加失败')
        }
      } catch (error) {
        this.$message.error('添加失败，请检查')
      }
    },

    // 删除检验项目
    async deleteInspectionItems() {
      if (!this.selectedItemSelections || this.selectedItemSelections.length === 0) {
        this.$message.warning('请选择已有项目！')
        return
      }

      this.$confirm('确定删除选中的检验项目吗？删除后将同时删除该项目的子明细数据。', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        try {
          const {data} = await deleteIPQCItemDetails({
            site: this.detailData.site,
            buNo: this.detailData.buNo,
            inspectionNo: this.detailData.inspectionNo,
            templateId: this.detailData.templateId,
            itemList: this.selectedItemSelections,
          })
          if (data && data.code === 0) {
            this.$message.success('删除成功')
            this.searchIPQCItems()
            this.selectedItemSelections = []
          } else {
            this.$message.error(data.msg || '删除失败')
          }
        } catch (error) {
          this.$message.error('删除失败，请检查')
        }
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },

    // 刷新检验明细列表
    refreshInspectionDetailList() {
      if (this.detailInformationFlag) {
        this.getInspectionFormData()
      }
    },

    // ======================== 模板导入相关方法 ========================
    // 打开模板导入对话框
    openTemplateImportDialog() {
      this.templateQuery = {
        templateId: '',
        templateDesc: '',
      }
      this.searchIPQCTemplates()
      this.templateImportDialogFlag = true
    },

    // 查询IPQC检验模板
    async searchIPQCTemplates() {
      try {
        const {data} = await getIPQCTemplateList({
          site: this.detailData.site,
          buNo: this.detailData.buNo,
          templateId: this.templateQuery.templateId,
          templateDesc: this.templateQuery.templateDesc,
        })
        if (data && data.code === 0) {
          this.templateImportList = data.rows || []
        } else {
          this.$message.error(data.msg || '查询失败')
        }
      } catch (error) {
        this.$message.error('查询失败，请检查')
      }
    },

    // 重置模板查询条件
    resetTemplateQuery() {
      this.templateQuery = {
        templateId: '',
        templateDesc: '',
      }
      this.searchIPQCTemplates()
    },

    // 模板行点击
    templateClickRow(row) {
      this.$refs.templateTable.toggleRowSelection(row)
    },

    // 模板选择变化
    templateSelectionChange(selection) {
      this.templateSelections = selection
    },

    // 确认导入模板
    async confirmImportTemplate() {
      if (!this.templateSelections || this.templateSelections.length === 0) {
        this.$message.warning('请选择要导入的模板！')
        return
      }

      this.$confirm(`确定要导入选中的 ${this.templateSelections.length} 个模板吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        this.importLoading = true
        try {
          const {data} = await importIPQCTemplateItems({
            site: this.detailData.site,
            buNo: this.detailData.buNo,
            inspectionNo: this.detailData.inspectionNo,
            orderNo: this.detailData.orderNo,
            templateList: this.templateSelections.map(t => ({
              templateId: t.templateId,
              templateName: t.templateName
            }))
          })
          if (data && data.code === 0) {
            this.$message.success(`导入成功！共导入 ${data.importCount || 0} 个检验项目`)
            this.templateImportDialogFlag = false
            this.templateSelections = []
            // 刷新检验明细列表
            this.getInspectionFormData()
          } else {
            this.$message.error(data.msg || '导入失败')
          }
        } catch (error) {
          this.$message.error('导入失败，请检查')
        } finally {
          this.importLoading = false
        }
      }).catch(() => {
        this.$message.info('已取消导入')
      })
    },

    // 关闭弹窗
    handleClose() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style scoped>
.process-inspection {

}

.demo-form-inline .el-form-item {
  margin-bottom: 10px;
}

/* ==================== 检验单对话框样式 ==================== */
/deep/ .ipqc-inspection-dialog .el-dialog__header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px 24px;
  border-radius: 8px 8px 0 0;
}

/deep/ .ipqc-inspection-dialog .el-dialog__title {
  color: #ffffff;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/deep/ .ipqc-inspection-dialog .el-dialog__headerbtn .el-dialog__close {
  color: #ffffff;
  font-size: 20px;
}

/deep/ .ipqc-inspection-dialog .el-dialog__body {
  padding: 0;
  background: #f5f7fa;
}

/* 单据信息卡片 */
.inspection-info-card {
  background: #ffffff;
  padding: 0px 0px;
}

.info-section {
  margin-bottom: 0;
  background: #f9fafb;
  border-radius: 6px;
  padding: 12px;
  border: 1px solid #e8eaed;
  transition: all 0.3s ease;
}

.info-section:hover {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border-color: #d0d4d9;
}

.info-section:last-child {
  margin-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e8eaed;
  font-size: 14px;
  font-weight: 600;
  color: #303133;
}

.section-title i {
  font-size: 18px;
  margin-right: 8px;
  color: #667eea;
}

.info-row {
  margin-bottom: 0 !important;
}

.info-item {
  margin-bottom: 0;
}

.info-item label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #606266;
}

.info-item label a {
  color: #409eff;
  text-decoration: none;
  transition: color 0.3s;
}

.info-item label a:hover {
  color: #66b1ff;
  text-decoration: underline;
}

.info-item /deep/ .el-input--small .el-input__inner,
.info-item /deep/ .el-input-number--small .el-input__inner {
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  transition: all 0.3s;
}

.info-item /deep/ .el-input--small .el-input__inner:focus,
.info-item /deep/ .el-input-number--small .el-input__inner:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.info-item /deep/ .el-select {
  width: 100%;
}

/* 操作按钮区域 */
.action-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #e8eaed;
  margin-top: 10px;
}

.left-actions,
.right-actions {
  display: flex;
  gap: 10px;
}

.action-buttons .el-button {
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.action-buttons .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 检验项目列表 */
.inspection-table-wrapper {
  background: #ffffff;
  padding: 0px 0px;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  margin-top: 10px;
  border-bottom: 2px solid #e8eaed;
}

.table-title {
  font-size: 15px;
  font-weight: 600;
  color: #303133;
  display: flex;
  align-items: center;
}

.table-title i {
  font-size: 18px;
  margin-right: 8px;
  color: #667eea;
}

.inspection-table {
  border-radius: 8px;
  overflow: hidden;
}

.inspection-table /deep/ .el-table__header-wrapper th {
  background: linear-gradient(135deg, #f5f7fa 0%, #e8eaed 100%);
  color: #606266;
  font-weight: 500;
}

/* 底部操作按钮 */
.dialog-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #ffffff;
}

.dialog-footer .el-button {
  min-width: 100px;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.dialog-footer .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dialog-footer .el-button--success {
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  border: none;
}

.dialog-footer .el-button--success:hover {
  background: linear-gradient(135deg, #15b39d 0%, #4af58e 100%);
}

/* 项目检验结论颜色 */
/deep/ .redElSelect .el-input--suffix .el-input__inner {
  color: red;
  font-weight: bold;
}
/deep/ .greenElSelect .el-input--suffix .el-input__inner {
  color: rgb(103,194,58);
  font-weight: bold;
}

/* 表格单元格高度修复 */
.inspection-table /deep/ .cell {
  height: auto;
  line-height: 1.5;
}

.inspection-table /deep/ .el-table__body-wrapper .el-table__row {
  transition: all 0.3s ease;
}

.inspection-table /deep/ .el-table__body-wrapper .el-table__row:hover {
  background: #f5f7fa;
}

.inspection-table /deep/ .el-table__body-wrapper .el-table__row.el-table__row--striped {
  background: #fafbfc;
}

.inspection-table /deep/ .el-table__body-wrapper .el-table__row.el-table__row--striped:hover {
  background: #f0f2f5;
}

.inspection-table /deep/ .el-button--mini {
  padding: 7px 10px;
  border-radius: 4px;
  font-size: 12px;
}

.inspection-table /deep/ .el-table__header-wrapper th {
  background: linear-gradient(135deg, #f5f7fa 0%, #e8eaed 100%);
  color: #303133;
  font-weight: 600;
  font-size: 13px;
  padding: 12px 0;
}

/* ==================== 项目操作对话框样式 ==================== */
/deep/ .item-operation-dialog {
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/deep/ .item-operation-dialog .el-dialog__header {
  background: linear-gradient(135deg, #9ac3d0 20%, #b6c7dd 80%);
  padding: 20px 24px;
  border-radius: 8px 8px 0 0;
}

/deep/ .item-operation-dialog .el-dialog__title {
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/deep/ .item-operation-dialog .el-dialog__headerbtn .el-dialog__close {
  color: #ffffff;
  font-size: 20px;
  font-weight: bold;
}

/deep/ .item-operation-dialog .el-dialog__headerbtn:hover .el-dialog__close {
  color: #f0f0f0;
}

/deep/ .item-operation-dialog .el-dialog__body {
  padding: 24px;
  background: #f8f9fa;
}

/* 查询区域样式 */
.search-container {
  background: #ffffff;
  padding: 16px 20px;
  border-radius: 6px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.search-container .el-form-item {
  margin-bottom: 0;
}

.search-container .el-form-item__label {
  font-weight: 500;
  color: #606266;
}

/* 主内容区域 */
.item-operation-content {
  display: flex;
  gap: 16px;
  align-items: stretch;
}

/* 项目面板 */
.item-panel {
  flex: 1;
  background: #ffffff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  transition: all 0.3s ease;
}

.item-panel:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.available-panel {
  flex: 1.5;
}

.selected-panel {
  flex: 1;
}

/* 面板头部 */
.panel-header {
  padding: 8px 16px;
  background: linear-gradient(135deg, #9ac3d0 20%, #b6c7dd 80%);
  border-bottom: 2px solid #9ac3d0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header i {
  font-size: 18px;
  color: #ffffff;
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.5px;
}

.item-count {
  margin-left: auto;
  font-size: 12px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.25);
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 500;
}

/* 表格样式优化 */
.operation-table {
  border: none !important;
}

.operation-table /deep/ .el-table__body tr:hover > td {
  background-color: #f0f7ff !important;
}

.operation-table /deep/ .el-table__row.current-row > td {
  background-color: #e6f2ff !important;
}

.operation-table /deep/ td {
  border-bottom: 1px solid #f0f0f0;
}

.operation-table /deep/ .el-table__body {
  font-size: 13px;
}

/* 操作按钮区域 */
.operation-buttons {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 0 8px;
}

.operation-buttons .el-button {
  width: 48px;
  height: 48px;
  font-size: 20px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.operation-buttons .el-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.operation-buttons .el-button.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.operation-buttons .el-button--primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
}

.operation-buttons .el-button--danger {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  border: none;
}

/* ==================== 模板导入对话框样式 ==================== */
/deep/ .template-import-dialog {
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/deep/ .template-import-dialog .el-dialog__header {
  background: linear-gradient(135deg, #9ac3d0 20%, #b6c7dd 80%);
  padding: 20px 24px;
  border-radius: 8px 8px 0 0;
}

/deep/ .template-import-dialog .el-dialog__title {
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/deep/ .template-import-dialog .el-dialog__headerbtn .el-dialog__close {
  color: #ffffff;
  font-size: 20px;
  font-weight: bold;
}

/deep/ .template-import-dialog .el-dialog__headerbtn:hover .el-dialog__close {
  color: #f0f0f0;
}

/deep/ .template-import-dialog .el-dialog__body {
  padding: 24px;
  background: #f8f9fa;
}

/* 模板列表容器 */
.template-list-container {
  background: #ffffff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  transition: all 0.3s ease;
}

.template-list-container:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* 模板表格 */
.template-table {
  border: none !important;
}

.template-table /deep/ .el-table__body tr:hover > td {
  background-color: #f0f7ff !important;
}

.template-table /deep/ .el-table__row.current-row > td {
  background-color: #e6f2ff !important;
}

.template-table /deep/ td {
  border-bottom: 1px solid #f0f0f0;
}

.template-table /deep/ .el-table__body {
  font-size: 13px;
}
</style>
