<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model:page="page"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <!-- <template #woCode="{ row }">{{ row.prWorkPlan.prWorkOrder.woCode }}</template> -->
      <!-- <template #partCode="{ row }">{{
        row.prWorkPlan.prWorkOrder.pjYieldOrder.partCode
      }}</template>
      <template #prodIdent="{ row }">{{
        row.prWorkPlan.prWorkOrder.pjYieldOrder.prodIdent
      }}</template>
      <template #cardNo="{ row }">{{ row.prWorkPlan.prWorkOrder.cardNo }}</template>
      <template #needDept="{ row }">{{ row.prWorkPlan.prWorkOrder.pjYieldOrder.useDept }}</template>
      <template #batchNo="{ row }">{{ row.prWorkPlan.prWorkOrder.pjYieldOrder.batchNo }}</template>
      <template #subBatchNo="{ row }">{{ row.prWorkPlan.prWorkOrder.batchNo }}</template>
      <template #ppsName="{ row }">{{ row.prWorkPlan.procedureSet.ppsName }}</template>
      <template #poArea="{ row }">{{ row.prWorkPlan.prWorkOrder.pjYieldOrder.poArea }}</template>
      <template #totalArea="{ row }">{{ row.prWorkPlan.prWorkOrder.totalArea }}</template>
      <template #nextWorkPlan="{ row }">{{
        row.prWorkPlan.nextWorkPlan.procedureSet.ppsName
      }}</template>
      <template #makeQty="{ row }">{{ row.prWorkPlan.prWorkOrder.makeQty }}</template>
      <template #factStartTime="{ row }">{{ row.prWorkPlan.factStartTime }}</template> -->
      <template #menu="{ row }">
        <!-- <el-button type="text">生产监控</el-button> -->
        <el-button type="text" @click="handleResult(row)">检验结果</el-button>
      </template>
      <template #menu-left>
        <el-button type="primary" @click="handleCreate">生成</el-button>
      </template>
    </avue-crud>

    <el-dialog append-to-body title="检验结果" width="90%" v-model="showDialog" fullscreen @close="handleClose">
      <div style="display: flex; align-items: center; justify-content: space-between">
        <el-descriptions title="订单信息" :column="5" border style="width: 100%" :label-width="110">
          <el-descriptions-item label="车间订单号" class="fixed-width-item">{{
            dialogData.woCode
          }}</el-descriptions-item>
          <el-descriptions-item label="产品号">{{ dialogData.prodCode }}</el-descriptions-item>
          <el-descriptions-item label="产品型号">{{
            dialogData.prodType
          }}</el-descriptions-item>
          <el-descriptions-item label="生产标识">{{
            dialogData.prodIdent
          }}</el-descriptions-item>
          <el-descriptions-item label="批次号">{{ dialogData.batchNo }}</el-descriptions-item>
          <el-descriptions-item label="产品名称">{{
            dialogData.prodName
          }}</el-descriptions-item>
          <el-descriptions-item label="生产数量">{{ dialogData.poQty }}</el-descriptions-item>
          <el-descriptions-item label="面积(dm²)">{{
            dialogData.area
          }}</el-descriptions-item>
          <el-descriptions-item label="镀种信息">{{ dialogData.platingInfo }}</el-descriptions-item>
          <el-descriptions-item label="工艺路线">{{
            dialogData.process
          }}</el-descriptions-item>
          <el-descriptions-item label="试验数量">{{ dialogData.orderCheckQty }}</el-descriptions-item>
          <el-descriptions-item label="消耗数量">{{ dialogData.orderLossQty }}</el-descriptions-item>
          <el-descriptions-item label="报废数量">{{ dialogData.orderScrapQty }}</el-descriptions-item>
          <el-descriptions-item label="硬度">{{ dialogData.hardness }}</el-descriptions-item>
          <el-descriptions-item label="工艺规程"> {{dialogData.processSpec}}</el-descriptions-item>
          <el-descriptions-item label="关键信息" :span="5">{{dialogData.keyInfo}}</el-descriptions-item>
          <el-descriptions-item label="备注" :span="5">{{ dialogData.remark }}</el-descriptions-item>
          <el-descriptions-item label="提醒内容" :span="5">
            <p v-for="item in remindMsgList" :key="item.id">{{item.remindContent}}</p>
            <!-- <p>1、提醒内容1</p>
            <p>2、提醒内容2</p> -->
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <el-descriptions
        title="检验信息"
        :column="5"
        border
        style="margin-top: 24px"
      ></el-descriptions>
      <el-form :model="form" label-width="auto">
        <el-row>
          <el-col :span="7">
            <!-- <el-form-item label="备注:">
              <el-input
                v-model="textarea"
                :rows="3"
                type="textarea"
                placeholder="请输入"
                style="width: 1040px"
              />
            </el-form-item> -->
          </el-col>
          <el-col :span="17">
            <div style="float: right;display: flex;align-items: center;">
              <el-checkbox style="color:#284c89;margin-right:10px;font-seze:14px;">同步同炉/同槽</el-checkbox>
              <el-button
                @click="gainYDValue"
                link
                type="primary"
                size="large"
                :title="'重新获取硬度检测值'"
                >获取硬度检测值</el-button
              >
              <el-button
                @click="goQuality"
                link
                type="primary"
                size="large"
                :title="'外协质量记录'"
                >质量记录</el-button
              >
              <el-button @click="goQualified" link type="primary" size="large" :title="'外协合格证'"
                >合格证</el-button
              >
            </div>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :data="vxeTableData"
        show-overflow-tooltip
        :row-class-name="getRowClass"
        row-key="id"
        :expand-row-keys="expandedRowKeys"
        @expand-change="handleExpandChange"
        :default-expand-all="false"
      >
      <!--  && vxeTableData.find(item => item.item.name == '尺寸检测').wpItemDetailList &&
              vxeTableData.find(item => item.item.name == '尺寸检测').wpItemDetailList.length > 0 -->
        <el-table-column type="expand" 
          v-if="dialogData.ppsName != '烧结包装防护' &&
          (
            (
              vxeTableData.find(item => item.item.name == '尺寸检测') 
            ) ||
            vxeTableData.find(item => item.item.name == '厚度检测')
          )">
          <!-- && scope.row.wpItemDetailList && scope.row.wpItemDetailList.length > 0 -->
          <template #default="scope">
            <el-table
              :data="scope.row.wpItemDetailList"
              show-overflow-tooltip
              v-if="scope.row.item.name == '尺寸检测'"
              style="margin: 12px"
            >
              <el-table-column width="57px">
                <template #header>
                  <div style="display: flex;align-items: center;">
                      <img src="@/assets/add.png" style="cursor:pointer;" alt="" @click="addRules(scope.row.wpItemDetailList)">
                  </div>
                </template>
                <template #default="subScope">
                  <el-button
                    circle
                    type="danger"
                    icon="el-icon-delete"
                    @click="removeRules(scope.row.wpItemDetailList,subScope.$index, subScope.row)"
                  />
                </template>
              </el-table-column>
              <el-table-column label="镀前镀后" prop="testType" align="center">
                <template #default="scope">
                  <el-input v-model="scope.row.testType" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="尺寸" prop="ruleSize" align="center">
                <template #default="scope">
                  <el-input v-model="scope.row.ruleSize" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="量具" prop="tools" align="center">
                <template #default="scope">
                  <!-- {{scope.row.mtName}} -->
                  <el-input v-model="scope.row.mtName" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="量具编号" prop="trialNo" align="center">
                <template #default="scope1">
                  <!-- {{scope.row}} -->
                  <el-select v-model="scope1.row.actMtId" placeholder="请输入" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' ">
                    <el-option v-for="item in measureList" :key="item.id" :label="item.mcName" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="测量值1" prop="gaugeValue1" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue1" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="测量值2" prop="gaugeValue2" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue2" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="测量值3" prop="gaugeValue3" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue3" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="测量值4" prop="gaugeValue4" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue4" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="测量值5" prop="gaugeValue5" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue5" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="测量值6" prop="gaugeValue6" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue6" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="测量值7" prop="gaugeValue7" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue7" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="测量值8" prop="gaugeValue8" align="center">
                <template #default="scope1">
                  <el-input v-model="scope1.row.gaugeValue8" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
            </el-table>
            <el-table
              :data="thicknessData"
              show-overflow-tooltip
              v-if="scope.row.item.name == '厚度检测'"
              style="margin: 12px"
            >
              <el-table-column width="57px">
                <template #header>
                  <div style="display: flex;align-items: center;">
                    <!-- <el-button
                      circle
                      type="primary"
                      icon="el-icon-plus"
                      @click="addSpecimen()"
                    /> -->
                    <!-- <div> -->
                      <img src="@/assets/add.png" style="cursor:pointer;" alt="" @click="addSpecimen()">
                      
                    <!-- </div> -->
                  </div>
                  
                </template>
                <template #default="subScope">
                  <el-button
                    circle
                    type="danger"
                    icon="el-icon-delete"
                    @click="removeSpecimen(subScope.$index, subScope.row)"
                  />
                </template>
              </el-table-column>
              <el-table-column label="程式编号" prop="gaugeValue7" align="center">
                <template #header>
                  <div style="display: flex;align-items: center;">
                    <img style="margin-right: 15px;cursor:pointer;" v-if="!isStart"  @click="searchThinkData" src="@/assets/pause.png" alt="">
                    <img style="margin-right: 15px;cursor:pointer;" v-if="isStart" @click="searchThinkData" src="@/assets/play.png" alt="">
                    <span>程式编号</span>
                  </div>
                </template>
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue7" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="名称1" prop="gaugeValue1" align="center">
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue1" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="参数1(um)" prop="gaugeValue2" align="center">
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue2" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="名称2" prop="gaugeValue3" align="center">
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue3" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="参数2(um)" prop="gaugeValue4" align="center">
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue4" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="名称3" prop="gaugeValue5" align="center">
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue5" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="参数3(um)" prop="gaugeValue6" align="center">
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue6" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="设备编码" prop="gaugeValue8" align="center">
                <template #default="subScope">
                  <el-input v-model="subScope.row.gaugeValue8" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
                </template>
              </el-table-column>
              <el-table-column label="检测时间" prop="updateTime" align="center" width="260">
                <template #default="subScope">
                  <el-date-picker type="datetime" style="width:90%" v-model="subScope.row.updateTime" 
                  format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择时间" 
                  :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-date-picker>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column
          label="项目编号"
          prop="itemCode"
          width="130px"
          align="center"
        >
          <template #default="scope"> {{scope.row.item.code}} </template>
        </el-table-column>
        <el-table-column label="项目" prop="itemName" align="center">
          <template #default="scope"> {{scope.row.item.name}} </template>
        </el-table-column>
        <el-table-column label="检验类型" prop="trialType" align="center">
          <template #default="scope"> {{scope.row.item.itemTypeName}} </template>
        </el-table-column>
        <el-table-column
          label="检验标准"
          prop="standardName"
          width="200px"
          align="center"
        >
          <template #default="scope"> {{scope.row.standard && scope.row.standard.name}} </template>
        </el-table-column>
        <el-table-column label="标准值" prop="trialStandard" align="center" width="150px">
          <template #default="scope">
            <!-- {{scope.row.standard && scope.row.standard.standardValue}}  
            {{'(' + scope.row.standard && scope.row.standard.downValue + '~' + scope.row.standard && scope.row.standard.upValue+ ')'}}  -->
            <span v-if="scope.row.standard">
              {{scope.row.standard.standardValue}} 
              <span v-if="scope.row.standard.downValue &&  scope.row.standard.upValue">{{'(' +  scope.row.standard.downValue + '~' +  scope.row.standard.upValue+ ')'}}</span>
            </span>
            <span v-else></span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="上下限" prop="trialStandard"  align="center"></el-table-column>、
        <el-table-column label="下限" prop="trialStandard"  align="center"></el-table-column> -->
        <el-table-column
          v-if="dialogData.ppsName != '烧结包装防护'"
          label="测试值"
          prop="checkValue"
          align="center"
          width="150px"
        >
          <template #default="scope">
            <div v-if="scope.row.item.name == '厚度检测'">
              <el-button @click="testMeasurementData(scope.row, scope.$index)" link type="primary">
                <!-- {{!isStart ? '测厚数据' : '结束查询'}} -->
                测厚数据
              </el-button>
            </div>
            <!-- && scope.row.item.wpItemDetailList && scope.row.item.wpItemDetailList.length > 0 -->
            <div v-else-if="scope.row.item.name == '尺寸检测'">
              <el-button @click="testValue(scope.row, scope.$index)" link type="primary"
                >测试值填写</el-button
              >
            </div>
            <div v-else>
              <!-- {{scope.row.checkUserRealName != null  && scope.row.checkUserRealName != ''}} -->
              <el-input v-model="scope.row.checkValue" :disabled="scope.row.checkUserRealName != null && scope.row.checkUserRealName !== '' "></el-input>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          v-if="dialogData.ppsName != '烧结包装防护'"
          label="试验数量"
          prop="testQty"
          width="100px"
          align="center"
        >
          <template #default="scope">
            <el-input v-model="scope.row.testQty" :disabled=" scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
          </template>
        </el-table-column>
        <el-table-column
          v-if="dialogData.ppsName != '烧结包装防护'"
          label="消耗数量"
          prop="lossQty"
          width="100px"
          align="center"
        >
          <template #default="scope">
            <el-input v-model="scope.row.lossQty" :disabled=" scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
          </template>
        </el-table-column>
        <el-table-column label="检验数量" prop="checkQty" width="100px" align="center">
          <template #default="scope">
            <el-input v-model="scope.row.checkQty" :disabled=" scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "></el-input>
          </template>
        </el-table-column>
        <el-table-column label="检验结果" prop="checkResult" width="300px" align="center">
          <template #default="scope">
            <el-radio-group
              v-model="scope.row.checkResult"
              @change="val => changeQty(val, scope.$index)"
              :disabled=" scope.row.checkUserRealName != null && scope.row.checkUserRealName != '' "
            >
              <el-radio :label="1">合格</el-radio>
              <el-radio :label="2">不合格</el-radio>
              <el-radio :label="3">NA</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
        <el-table-column label="检验人" prop="checkUserRealName" align="center"></el-table-column>
        <el-table-column label="检验时间" prop="checkDate" align="center"></el-table-column>
      </el-table>

      <el-descriptions
        title="同槽/同炉信息"
        :column="5"
        border
        style="margin-top: 24px"
      ></el-descriptions>
      <el-table :data="vxeTableData2" show-overflow-tooltip>
        <el-table-column label="同槽/同炉编号" prop="sameNo" align="center"></el-table-column>
        <el-table-column label="订单编码" prop="woCode" align="center"></el-table-column>
        <el-table-column label="零件号" prop="partCode" align="center"></el-table-column>
        <el-table-column label="批次号" prop="batchNo" align="center"></el-table-column>
        <el-table-column label="生产标识" prop="prodIdent" align="center"></el-table-column>
        <el-table-column label="数量" prop="poQty" align="center"></el-table-column>
        <el-table-column label="面积(d㎡)" prop="area" align="center"></el-table-column>
        <el-table-column label="总面积(d㎡)" prop="areaTotal" align="center"></el-table-column>
        <el-table-column label="材料" prop="material" align="center"></el-table-column>
        <el-table-column fixed="right" align="center" label="操作" width="120">
          <template #default="scope">
            <el-button link type="primary" @click="handleView(scope.row)">查看</el-button>
            <el-button link type="primary" v-if="vxeTableData.find(item => item.checkUserRealName == '')" @click="handleUse(scope.row)">应用</el-button>
          </template>
        </el-table-column>
      </el-table>
<!--  -->
      <el-descriptions v-if="dialogData.ppsName == '烧结包装防护'"  title="子件" :column="5" border style="margin-top: 24px"></el-descriptions>
      <el-table v-if="dialogData.ppsName == '烧结包装防护'"  :data="vxeTableData1" show-overflow-tooltip>
        <el-table-column label="子件号" prop="partCode" align="center"></el-table-column>
        <el-table-column label="子件名称" prop="partName" align="center"></el-table-column>
        <el-table-column label="数量" prop="qty" align="center"></el-table-column>
        <el-table-column label="产品型号" prop="productType" align="center"></el-table-column>
        <el-table-column label="子件类型" prop="sinTerType" align="center"></el-table-column>
        <el-table-column label="镀种" prop="plate" align="center"></el-table-column>
        <el-table-column label="材料" prop="material" align="center"></el-table-column>
        <el-table-column label="面积(d㎡)" prop="area" align="center"></el-table-column>
        <el-table-column label="总面积(d㎡)" prop="totalArea" align="center"> </el-table-column>
        <el-table-column label="镀层代码" prop="matCode" align="center"></el-table-column>
        <el-table-column label="镀层厚度" prop="plateThickness" align="center"></el-table-column>
        <el-table-column label="备注" prop="remarks" align="center"></el-table-column>
        <el-table-column label="修改人" prop="lastUpdateUser" align="center"></el-table-column>
      </el-table>

      <template #footer>
        <span class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="submit">确 定</el-button>
        </span>
      </template>
    </el-dialog>
    <sametank-view
      v-if="openView"
      :showDialog="openView"
      :tankId="tankId"
      @closeDialog="closeDialog"
    ></sametank-view>
  </basic-container>
</template>

<script>
import {dateFormat} from '@/utils/date'
import {createInspection,getInspectionList,getInspectionDetail,fillInspection,getSameLotList,applySameLot,
refreshHardness,getThicknessList,goQualityRecord,goCertificate,getSubPackageList, getSupplierList,getMeasurement} from '@/api/qualityManagement/productionTesting/productionQuality.js'
import sametankView from './components/sametankView.vue';
export default {
  components: { sametankView },
  data() {
    return{
      query: {},
      openView: false,
      loading: false,
      tankId: '',
      isStart:false,
      startTime:'',
      firstInterval:null,
      secondInderval:null,
      form: {},
      getDChyData:[],
      showDialog: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      ydInterval:null,
      checkedId:'',
      dialogData: {},
      data: [],
      detailInfo:{},
      expandedRowKeys: [],
      vxeTableData: [],
      vxeTableData5: [],
      vxeTableData2: [],
      remindMsgList:[], //提醒信息列表
      thicknessData:[],
      measureList:[],
      option: {
        tip: false,
        height: 'auto',
        calcHeight: 32,
        columnSort: true,
        // simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        editBtnText: '修改',
        viewBtnText: '详情',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        labelWidth: '200px',
        dialogWidth: 600,
        dialogClickModal: false,
        searchEnter: true,
        filterBtn: true,
        searchShowBtn: false,
        excelBtn: true,
        showOverflowTooltip: true,
        align: 'center',
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: 'left',
        gridBtn: false,
        searchMenuPosition: 'right',
        menuWidth: 100,
        column: [
          {
            label: '流程卡号',
            prop: 'tpProject',
            search: true,
            hide: true,
            addDisplay: false,
            viewDisplay: false,
            editDisplay: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 200,
          },
          {
            label: '主加工单位',
            prop: 'mainProcessingUnit',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 160,
          },
          {
            label: '主加工单位-班组',
            prop: 'mainProcessingUnit',
            search: true,
            type: 'select',
            searchLabelWidth: 120,
            sortable: true,
            filter: true,
            hide: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 200,
            dicUrl: '/api/blade-desk/BA/TeamSet/listForSelect',
            props: {
              label: 'tsName',
              value: 'id',
            },
          },
          {
            label: '主加工单位-供应商',
            prop: 'mainProcessingSupplier',
            searchLabelWidth: 140,
            search: true,
            type: 'select',
            sortable: true,
            filter: true,
            hide: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 200,
            dicUrl: '/api/blade-desk/BA/Oem/listForSelect',
            props: {
              label: 'ocName',
              value: 'id',
            },
          },
          {
            label: '车间订单号',
            prop: 'woCode',
            search: true,
            searchLabelWidth: 90,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 160,
            rules: [
              {
                required: true,
                message: '请输入车间订单号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '零件号',
            prop: 'partCode',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 145,
            rules: [
              {
                required: true,
                message: '请输入零件号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '生产标识',
            prop: 'prodIdent',
            type: 'select',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 105,
            rules: [
              {
                required: true,
                message: '请输入生产标识',
                trigger: 'blur',
              },
            ],
            dicUrl:"/api/blade-desk/BA/ProdMark/listForSelect",
            props:{label:"name",value:"id"}
          },
          {
            label: '流程卡号',
            prop: 'cardNo',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 110,
            rules: [
              {
                required: true,
                message: '请输入流程卡号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '需求部门',
            prop: 'needDeptName',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 120,
            rules: [
              {
                required: true,
                message: '请输入需求部门',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '批次号',
            prop: 'batchNo',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 120,
            rules: [
              {
                required: true,
                message: '请输入批次号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '分批号',
            prop: 'poBatchNo',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 120,
            rules: [
              {
                required: true,
                message: '请输入分批号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '工序',
            prop: 'currentProcessId',
            search: true,
            type: 'select',
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 110,
            rules: [
              {
                required: true,
                message: '工序',
                trigger: 'blur',
              },
            ],
            dicUrl:'/api/blade-desk/bsProcessSet/list?curtent=1&size=99999',
            props: {
              label: 'name',
              value: 'id',
              res: 'data.records',
            },
          },
          // {
          //   label: '下序',
          //   prop: 'nextProcessId',
          //   search: true,
          //   type: 'select',
          //   sortable: true,
          //   filter: true,

          //   addDisplay: false,
          //   editDisplay: false,
          //   viewDisplay: false,
          //   span: 24,
          //   width: 110,
          //   rules: [
          //     {
          //       required: true,
          //       message: '请输入下序',
          //       trigger: 'blur',
          //     },
          //   ],
          //   dicUrl:'/api/blade-desk/bsProcessSet/list?curtent=1&size=99999',
          //   props: {
          //     label: 'name',
          //     value: 'id',
          //     res: 'data.records',
          //   },
          // },
          // {
          //   label: '状态',
          //   prop: 'status',
          //   search: true,
          //   type: 'select',
          //   sortable: true,
          //   filter: true,
          //   addDisplay: false,
          //   editDisplay: false,
          //   viewDisplay: false,
          //   span: 24,
          //   width: 90,
          //   rules: [
          //     {
          //       required: true,
          //       message: '请输入状态',
          //       trigger: 'blur',
          //     },
          //   ],
          //   props:{
          //     label:'dictValue',
          //     value:'dictKey',
          //   },
          //   dicUrl:'/api/blade-system/dict/dictionary?code=InspectionTask-Status', //字典中取值
          //   // dicData: [
          //   //   {
          //   //     value: 1,
          //   //     label: '合格',
          //   //   },
          //   //   {
          //   //     value: 2,
          //   //     label: '不合格',
          //   //   },
          //   //   {
          //   //     value: 3,
          //   //     label: 'NA(不检验)',
          //   //   },
          //   //   {
          //   //     value: -1,
          //   //     label: '未检验',
          //   //   },
          //   // ],
          // },
          {
            label: '面积(dm²)',
            prop: 'area',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 120,
            rules: [
              {
                required: true,
                message: '请输入面积(dm²)',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '总面积(dm²)',
            prop: 'areaTotal',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,

            viewDisplay: false,
            span: 24,
            width: 150,
            rules: [
              {
                required: true,
                message: '请输入总面积(dm²)',
                trigger: 'blur',
              },
            ],
          },

          {
            label: '生产数量',
            prop: 'poQty',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,

            viewDisplay: false,
            span: 24,
            width: 110,
            rules: [
              {
                required: true,
                message: '请输入生产数量',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '接收时间',
            prop: 'receiveDate',
            search: true,
            type: 'date',
            format:"YYYY-MM-DD",
            valueFormat:"YYYY-MM-DD",
            searchRange: true,
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间',

            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 200,
            rules: [
              {
                required: true,
                message: '请输入接收时间',
                trigger: 'blur',
              },
            ],
          },
        ],
      },
      label_style: {
        'text-align': 'center', //文本居中
        'font-weight': '600',
        height: '60px',
        width: '30%',
        'word-break': 'keep-all',
      },
      content_style: {
        'text-align': 'center',
        width: '200px',
        'word-break': 'break-all', //过长时自动换行
      },
    };
  },
  mounted() {
    
  },
  methods: {
    addSpecimen(){
      this.thicknessData.push({})
    },
    removeSpecimen(index,row){
      this.thicknessData.splice(index,1)
      let arr = this.getDChyData.filter(item => JSON.stringify(item) === JSON.stringify(row))
      console.log('arr=============',arr)
      this.getDChyData = arr
    },
    addRules(data){
      console.log('data=============',data)
      data.push({
        isDel:2
      })
    },
    removeRules(data,index,row){
      if(row.isDel != 1){
        data.splice(index,1)
      }else{
        this.$message.error('该数据不可删除')
        return
      }
    },
    handleCreate(){
      createInspection({}).then(res => { 
        if(res.data.code == 200){
          this.onLoad()
        }
      });
    },
    // 跳转至外协质量记录
    goQuality(){
      goQualityRecord({
        id:this.checkedId
      }).then(res =>{
        window.open(res.data.data)
      })
    },
    // 跳转合格证
    goQualified(){
      goCertificate({
        id:this.checkedId
      }).then(res =>{
        window.open(res.data.data)
      })
    },
    getRowClass(row, index) {
      let res = [];
      if (row.row.item.name != '尺寸检测' && row.row.item.name != '厚度检测'){
        return 'row-expand-cover';
      }
      // else if(
      //   row.row.item.name == '尺寸检测' && 
      //   (!row.row.wpItemDetailList || row.row.wpItemDetailList.length === 0)
      // ){
      //   return 'row-expand-cover';
      // }
      return '';
     
    },
    testMeasurementData(row, index) {
      const itemDetail = {
        // tools: row.trialItem,
        // testType: '镀后测厚',
        // ruleSize: row.trialStandard,
        // prWorkPlanItem: { wpiId: row.wpiId },
        gaugeValue7: null,
        gaugeValue8: null
      };
      
      // if()
      let tmp = this.expandedRowKeys.find(item => item == row.id);
      if (!tmp) {
        this.expandedRowKeys = [...this.expandedRowKeys, row.id];
      }
      if((row.checkUserId != -1 || row.checkUserRealName != '')){
        this.thicknessData = row.wpItemDetailList ? row.wpItemDetailList : []
        return
      }
    },
    searchThinkData(){
      const itemDetail = {
        // tools: row.trialItem,
        // testType: '镀后测厚',
        // ruleSize: row.trialStandard,
        // prWorkPlanItem: { wpiId: row.wpiId },
        gaugeValue7: null,
        gaugeValue8: null
      };
      this.isStart = !this.isStart;
      if(this.isStart){
        this.thicknessData = this.thicknessData.length > 0 ? this.thicknessData : []
        this.startTime = dateFormat(new Date(),'yyyy-MM-dd hh:mm:ss')
        this.firstInterval = setInterval(() =>{
          this.getThickness(0,true,dateFormat(new Date(),'yyyy-MM-dd hh:mm:ss'),itemDetail)
        },10 * 1000)
        let i = 1;
        this.secondInderval = setInterval(() => {
            console.log("i =", i);
            this.getThickness(i,false,dateFormat(new Date(),'yyyy-MM-dd hh:mm:ss'),itemDetail)
            if (i === 10) {
                i = 1; // 重置为1，继续循环
            } else {
                i++;
            }
        }, 2200); // 每2秒执行一次
      }else{
        clearInterval(this.firstInterval)
        clearInterval(this.secondInderval)
      }
    },
    getValue(value) {
      if (value == '/') {
        return value;
      }
      if (value > 0) {
        const strList = value.split('.');
        return Number(value).toFixed(3 - strList[0].length);
      } else {
        return value;
      }
    },
    provingObjIsNull() {
      let index = null;
      for (var i = 0; i < this.thicknessData.length; i++) {
        const item = this.thicknessData[i];
        if (
          item.gaugeValue1 == null &&
          item.gaugeValue2 == null &&
          item.gaugeValue3 == null &&
          item.gaugeValue4 == null &&
          item.gaugeValue5 == null &&
          item.gaugeValue6 == null
        ) {
          index = i;
          i = this.thicknessData.length;
        }
      }
      return index;
    },
    getThickness(val,allData,endTime,itemDetail){
      
      getThicknessList({
        // startTime:this.startTime,
        // endTime:endTime, 
        allData,
        // count:val
      }).then(res =>{
        console.log('res111111111111',res)
        if (res.data.data != null) {
          const resultList = res.data.data;
          
          // const resultList = [{
          //   IP:"10.15.3.26",
          //   devCode:"Ni/CuZn59",
          //   devId:"LG020029",
          //   fi1etime: "2025/11/21 16:38:32",
          //   measurings: [
          //     {unit: "um", name: "Ni", value: "8.92142"}, 
          //     {unit: "/", name: "Cu", value: "/"},
          //     {unit: "/", name: "Cu", value: "/"}
          //   ]
          // }]
          console.log('resultList--------------',resultList)
          console.log('getDChyData--------------',this.getDChyData)
          if (resultList.length > 0) {
            resultList.forEach((item) => {
              let isExist = false;
              this.getDChyData.forEach((items) => {
                if (item.filetime === items.filetime) {
                  isExist = true;
                }
              });
              if (isExist) return;
              console.log('item------------',item)
              const { measurings, devId, devCode, filetime } = item;
              const obj1 = { ...itemDetail };
              // this.devCode = devCode;
              obj1.gaugeValue7 = devCode;
              obj1.gaugeValue8 = devId;
              if (measurings.length > 0) {
                obj1['gaugeValue1'] = measurings[0].name;
                obj1['gaugeValue2'] = this.getValue(measurings[0].value);
              }
              if (measurings.length > 1) {
                obj1['gaugeValue3'] = measurings[1].name;
                obj1['gaugeValue4'] = this.getValue(measurings[1].value);
              }
              if (measurings.length > 2) {
                obj1['gaugeValue5'] = measurings[2].name;
                obj1['gaugeValue6'] = this.getValue(measurings[2].value);
              }
              console.log('obj1------------',obj1)
              if (item.measurings.length > 0) {
                obj1.updateTime = dateFormat(new Date(),'yyyy-MM-dd hh:mm:ss');
                // obj1.updateTime = filetime;
                const index = this.provingObjIsNull();
                if (index != null) {
                  const obj2 = this.thicknessData[index];
                  obj2.gaugeValue1 = obj1['gaugeValue1'];
                  obj2.gaugeValue2 = obj1['gaugeValue2'];
                  obj2.gaugeValue3 = obj1['gaugeValue3'];
                  obj2.gaugeValue4 = obj1['gaugeValue4'];
                  obj2.gaugeValue5 = obj1['gaugeValue5'];
                  obj2.gaugeValue6 = obj1['gaugeValue6'];
                  obj2.gaugeValue7 = devCode;
                  obj2.gaugeValue8 = devId;
                  obj2.updateTime = obj1.updateTime;
                  // this.$set(this.thicknessData[index], obj2);
                  this.thicknessData[index] = obj2;
                } else {
                  this.thicknessData.push(obj1);
                }
              }
            })
          }
          console.log('this.thicknessData',this.thicknessData)
          console.log('resultList',resultList)
          const arr = [...this.getDChyData, ...resultList];
          const obj = {};
          this.getDChyData = arr.reduce((cur, next) => {
            obj[next.filetime]
              ? ''
              : (obj[next.filetime] = true && cur.push(next));
            return cur;
          }, []);
          const map = new Map();
          for (const item of this.getDChyData) {
            map.set(item.filetime, item);
          }
          this.getDChyData = [...map.values()];
          console.log('this.getDChyData',this.getDChyData)
        }
      })
    },
    testValue(row, index) {
      let tmp = this.expandedRowKeys.find(item => item == row.id);
      if (!tmp) {
        this.expandedRowKeys = [...this.expandedRowKeys, row.id];
      }
    },
    // 监听展开/收起事件（可选）
    handleExpandChange(row, expandedRows) {
      console.log('当前展开的行:', expandedRows);
      // 如果使用 .sync，也可以在这里更新 expandedRowKeys
      this.expandedRowKeys = expandedRows.map(r => r.id);
    },
    changeQty(val, index) {
      if (
        val == 1 &&
        (this.vxeTableData[index].checkValue == '不合格' || !this.vxeTableData[index].checkValue)
      ) {
        this.vxeTableData[index].checkValue = '合格';
      }
      if (
        val == 2 &&
        (this.vxeTableData[index].checkValue == '合格' || !this.vxeTableData[index].checkValue)
      ) {
        this.vxeTableData[index].checkValue = '不合格';
      }
      if (val == 3) {
        this.vxeTableData[index].checkValue = null;
      }
    },
    gainYDValue(){
      this.vxeTableData.forEach(item => {
        console.log('item---------------------',item)
        if ((item.item.name == '硬度检测') && (item.checkUserRealName == '')) {
          refreshHardness().then(res =>{
            console.log('refre--------------',res)
            if(res.data.data.length > 0){
              item.checkValue = JSON.parse(res.data.data[0].data).formatted_hardness
              clearInterval(this.ydInterval)
            }
          })
        }
      })
    },
    // 关闭弹窗
    handleClose(){
      console.log('111111111111111111111')
      this.expandedRowKeys = []
      this.showDialog = false
      this.isStart = false
      this.getDChyData = []
      clearInterval(this.ydInterval)
      clearInterval(this.firstInterval)
      clearInterval(this.secondInderval)
    },
    // 提交
    submit(){
      let params = {}
      this.detailInfo.wpItemList.map(item =>{
        if(item.item.name == '厚度检测'){
          item.wpItemDetailList = [...this.thicknessData]
        }
      })
      console.log('detailInfo------------------',this.detailInfo)
      fillInspection(this.detailInfo).then(res =>{
        if(res.data.code == 200){
          this.$message.success('保存成功')
          this.showDialog = false
          this.isStart = false
          this.getDChyData = []
          clearInterval(this.ydInterval)
          clearInterval(this.firstInterval)
          clearInterval(this.secondInderval)
          this.onLoad()
        }
      })
    },
    
    // 点击应用按钮
    handleUse(row) {
      this.$confirm('是否应用此同槽检测结果?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        getInspectionDetail({
        id:row.id,
      }).then(res => {
        console.log('res----------------', res);
        res.data.data.wpItemList.map(item =>{
            this.vxeTableData.map(item1 =>{
              if(item1.checkUserRealName == ''){
                if(item.item.name == item1.item.name){
                  if(item.item.name != '厚度检测' && item.item.name != '硬度检测' && item.item.name != '尺寸检测'){
                    item1.checkValue = item.checkValue
                  }
                  item1.testQty = item.testQty
                  item1.lossQty = item.lossQty
                  item1.checkQty = item.checkQty
                  item1.checkResult = item.checkResult
                }
              }
            })
          
        })
        // this.dialogData = res.data.data.orderInfo;
        // this.remindMsgList = res.data.data.remindMsgList;
        // this.vxeTableData = res.data.data.wpItemList;
        // console.log('this.vxeTableData', this.vxeTableData);
      });
        // applySameLot({
        //   sourceId:row.id,
        //   targetId:this.detailInfo.id
        // }).then(res =>{
        //   if(res.data.code == 200){
        //     getInspectionDetail({id:this.checkedId}).then(res =>{
        //       this.detailInfo = res.data.data
        //       this.dialogData = {
        //         ...res.data.data.orderInfo,
        //         ppsName:res.data.data.processName
        //       };
        //       console.log('pps------------------',this.dialogData)
        //       this.remindMsgList = res.data.data.remindMsgList;
        //       this.vxeTableData = res.data.data.wpItemList;
        //     })
        //   }
        // })
      });
    },
    // 点击查看按钮
    handleView(row) {
      this.tankId = row.id;
      this.openView = true;
      console.log('oprn---------------', this.openView);
    },
    closeDialog() {
      this.openView = false;
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.query.receiveDateStart = params.receiveDate && params.receiveDate.length > 0 && params.receiveDate[0]
      this.query.receiveDateEnd = params.receiveDate && params.receiveDate.length > 0 && params.receiveDate[0]
      this.onLoad();
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    getSameList(val){
      getSameLotList({
        id:val
      }).then(res =>{
        console.log('res1-------------------------',res)
        this.vxeTableData2 = res.data.data
      })
    },
    // 查看详情
    handleResult(row) {
      console.log('row------------------',row)
      this.checkedId = row.id
      getMeasurement().then(res =>{
        this.measureList = res.data.data
      })
      getInspectionDetail({
        id: row.id,
      }).then(res => { 
        console.log('res-------------------------',res)
        this.detailInfo = res.data.data
        this.dialogData = res.data.data.orderInfo;
        this.dialogData.ppsName = res.data.data.processName;
        this.remindMsgList = res.data.data.remindMsgList;
        // res.data.data.wpItemList[0].standard = {
        //   standardValue:null,
        //   downValue:null
        // }
        // res.data.data.wpItemList[0].item.name = '厚度检测'
        // res.data.data.wpItemList[0].checkUserRealName = null
        this.vxeTableData = res.data.data.wpItemList;
        this.getSameList(row.id)
        if(this.dialogData.ppsName != '烧结包装防护'){
          this.vxeTableData.forEach(item =>{
            console.log('item--------------',item)
            if(item.item.name == '硬度检测' && (item.checkUserId == -1 || item.checkUserRealName == '')){
              // this.ydInterval = setInterval(() =>{
                refreshHardness().then(res =>{
                  console.log('res2--------------------------',res)
                  if (res.data.data.length > 0) {
                    item.checkValue = res.data.data[0].formatted_hardness
                    // clearInterval(this.ydInterval)
                  }
                })
              // },window.YINGDU_Trigger)
            }
            if(item.item.name == '厚度检测'){
              console.log('item------------------',item)
              this.thicknessData = item.wpItemDetailList ? item.wpItemDetailList : []
            }
            if(item.item.name == '尺寸检测'){
              if(item.wpItemDetailList && item.wpItemDetailList.length > 0){
                let tmp = item.wpItemDetailList.find(item => item.isDel)
                if(!tmp){
                  item.wpItemDetailList.map(item =>{
                    item.isDel = 1
                  })
                }
              }else{
                item.wpItemDetailList = []
              }
            }
          })
        }
        

        if(this.dialogData.ppsName === '烧结包装防护'){
          getSubPackageList({
            yoId:res.data.data.orderInfo.yoId
          }).then(res3 =>{
            this.vxeTableData1 = res3.data.data
            console.log('vxeTableData1------------------',this.vxeTableData1)
          })
        }
        
        
        this.showDialog = true
      });
    },
    onLoad() {
      console.log('query----------------',this.query)
      this.loading = true
      if(this.query.receiveDate){
        delete this.query.receiveDate
      }
      getInspectionList({
        current:this.page.currentPage,
        size:this.page.pageSize,
        ...this.query
      }).then(res =>{
        res.data.data.records.map(item =>{
          item.status = item.status + ''
        })
        this.data = res.data.data.records
        this.page.total = res.data.data.total
        this.loading = false
      })
    },
  },
};
</script>

<style lang="scss" scoped>
.fixed-width-item {
  width: 120px;
}

:deep(.is-bordered-content) {
  width: 300px;
}
:deep(.row-expand-cover .el-table__expand-column .el-icon) {
  visibility: hidden;
}
</style>