spring
2025-04-02 b34e4348df3f9f697fcb4da64ee7ff11deca3170
src/components/view/b1-inspect-order-plan.vue
@@ -1,182 +1,276 @@
<style scoped>
   .ins-order-plan-main .title {
      font-size: 20px;
      color: #3A7BFA
   }
.ins-order-plan-main .title {
  font-size: 20px;
  color: #3A7BFA
}
   .search {
      background-color: #fff;
      height: 80px;
      display: flex;
      align-items: center;
   }
.search {
  background-color: #fff;
  height: 80px;
  display: flex;
  align-items: center;
}
   .search_thing {
      display: flex;
      align-items: center;
      height: 50px;
   }
.search_thing {
  display: flex;
  align-items: center;
  height: 50px;
}
   .search_label {
      width: 120px;
      font-size: 14px;
      text-align: right;
   }
.search_label {
  width: 120px;
  font-size: 14px;
  text-align: right;
}
   .search_input {
      width: calc(100% - 120px);
   }
.search_input {
  width: calc(100% - 120px);
}
   .ins-order-plan-main .search {
      width: 100%;
      margin-bottom: 10px;
      height: 80px;
      background-color: #fff;
      border-radius: 3px;
   }
.ins-order-plan-main .search {
  width: 100%;
  margin-bottom: 10px;
  height: 80px;
  background-color: #fff;
  border-radius: 3px;
}
   .search .form-inline {
      height: 50px;
      padding-top: 20px;
      padding-left: 50px;
   }
.search .form-inline {
  height: 50px;
  padding-top: 20px;
  padding-left: 50px;
}
   .ins-order-plan-main .center {
      width: calc(100% - 40px);
      height: calc(100% - 60px - 80px - 40px);
      background-color: #fff;
      border-radius: 3px;
      padding: 20px;
   }
.ins-order-plan-main .center {
  width: calc(100% - 40px);
  height: calc(100% - 60px - 80px - 40px);
  background-color: #fff;
  border-radius: 3px;
  padding: 20px;
}
   .ins-order-plan-main .center .value-table {
      width: 100%;
      height: calc(100% - 68px);
   }
.ins-order-plan-main .center .value-table {
  width: 100%;
  height: calc(100% - 68px);
}
   .tab {
      list-style-type: none;
      display: flex;
   }
.tab {
  list-style-type: none;
  display: flex;
}
   .tab li {
      line-height: 24px;
      padding: 6px 14px;
      font-size: 14px;
      color: #333333;
      border: 1px solid #EEEEEE;
      cursor: pointer;
   }
.tab li {
  line-height: 24px;
  padding: 6px 14px;
  font-size: 14px;
  color: #333333;
  border: 1px solid #EEEEEE;
  cursor: pointer;
}
   .tab li:nth-child(1) {
      border-radius: 8px 0 0 8px;
   }
.tab li:nth-child(1) {
  border-radius: 8px 0 0 8px;
}
   .tab li:nth-last-child(1) {
      border-radius: 0 8px 8px 0;
   }
.tab li:nth-last-child(1) {
  border-radius: 0 8px 8px 0;
}
   .tab li.active {
      border-color: #3A7BFA;
      color: #3A7BFA;
   }
.tab li.active {
  border-color: #3A7BFA;
  color: #3A7BFA;
}
   .center .center-options .center-title {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: right;
   }
.center .center-options .center-title {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: right;
}
   .center .center-options .center-title span:last-child {
      color: #3A7BFA;
      font-size: 23px;
      font-weight: 400;
   }
.center .center-options .center-title span:last-child {
  color: #3A7BFA;
  font-size: 23px;
  font-weight: 400;
}
   .view-self-checkbox {
      margin-left: 50px;
   }
.view-self-checkbox {
  margin-left: 50px;
}
.draggable-row {
  cursor: move;
  position: relative;
}
.node_i {
  color: orange;
  font-size: 18px;
}
.custom-tree-node .el-button {
  opacity: 0;
}
.custom-tree-node:hover .el-button {
  opacity: 1;
}
.el-dialog {
  position: relative;
}
</style>
<style>
   .ins-order-plan-main .el-form-item__label{
      color: #000;
   }
.ins-order-plan-main .el-form-item__label {
  color: #000;
}
  .ins-order-plan-main .el-table th.el-table__cell>.cell{
    height: 46px;
    line-height: 30px;
  }
.ins-order-plan-main .el-table th.el-table__cell>.cell {
  height: 46px;
  line-height: 30px;
}
</style>
<template>
   <div class="ins-order-plan-main">
      <div v-show="activeFace == 0&&state==0" style="height: 100%;">
         <p style="font-size: 16px;padding-left: 20px;text-align: left;height: 60px;line-height: 60px;">检验任务</p>
         <div class="search">
            <div class="search_thing">
               <div class="search_label">委托编号:</div>
               <div class="search_input"><el-input size="small" placeholder="请输入" clearable
                     v-model="componentData.entity.entrustCode" @keyup.enter.native="refreshTable()"></el-input></div>
            </div>
            <div class="search_thing">
               <div class="search_label">检验状态:</div>
               <div class="search_input">
                  <el-select size="small" v-model="componentData.entity.insState" style="width: 100%;" @change="refreshTable()">
                     <el-option v-for="(a, i) in insStateList" :key="i" :label="a.label" :value="a.value"></el-option>
                  </el-select>
               </div>
            </div>
            <div class="search_thing" style="padding-left: 30px;">
               <el-button size="small" @click="refresh()">重 置</el-button>
               <el-button size="small" type="primary" @click="refreshTable()">查 询</el-button>
            </div>
         </div>
         <div class="center">
            <div class="center-options">
               <el-row>
                  <el-col :span="21">
                     <div style="display: flex;align-items: center;margin-bottom: 10px;">
                        <ul class="tab">
                           <li v-for="(m,i) in tabList" :key="i" :class="{active:i==tabIndex}" @click="handleTab(m,i)">{{m.label.replace('试验室','')}}
                           </li>
                        </ul>
                        <div>
                           <el-checkbox @change="changeCheckBox" class="view-self-checkbox"
                              v-model="alone"><span>我的任务</span></el-checkbox>
                        </div>
                     </div>
                  </el-col>
                  <el-col :span="3">
                     <div class="center-title">
                        <span>总计任务数量:</span>
                        <span v-if="$refs.insOrderPlan != undefined">{{$refs.insOrderPlan.total}}</span>
                     </div>
                  </el-col>
               </el-row>
            </div>
            <ValueTable :tableRowClassName="changeRowClass" class="value-table" ref="insOrderPlan"
  <div class="ins-order-plan-main">
    <div v-show="activeFace == 0 && state == 0" style="height: 100%;">
      <p style="font-size: 16px;padding-left: 20px;text-align: left;height: 60px;line-height: 60px;">检验任务</p>
      <div class="search">
        <div class="search_thing">
          <div class="search_label">委托编号:</div>
          <div class="search_input"><el-input size="small" placeholder="请输入" clearable
              v-model="componentData.entity.entrustCode" @keyup.enter.native="refreshTable()"></el-input></div>
        </div>
        <div class="search_thing">
          <div class="search_label">检验状态:</div>
          <div class="search_input">
            <el-select size="small" v-model="componentData.entity.insState" style="width: 100%;"
              @change="refreshTable()">
              <el-option v-for="(a, i) in insStateList" :key="i" :label="a.label" :value="a.value"></el-option>
            </el-select>
          </div>
        </div>
        <div class="search_thing">
          <div class="search_label">样品编号:</div>
          <div class="search_input">
            <el-input size="small" placeholder="请输入" clearable v-model="componentData.entity.sampleCOde"
              @keyup.enter.native="refreshTable()"></el-input>
          </div>
        </div>
        <div class="search_thing" style="padding-left: 30px;">
          <el-button size="small" @click="refresh()">重 置</el-button>
          <el-button size="small" type="primary" @click="refreshTable()">查 询</el-button>
        </div>
      </div>
      <div class="center">
        <div class="center-options">
          <el-row>
            <el-col :span="18">
              <div style="display: flex;align-items: center;margin-bottom: 10px;">
                <ul class="tab">
                  <li v-for="(m, i) in tabList" :key="i" :class="{ active: i == tabIndex }" @click="handleTab(m, i)">
                    {{ m.label.replace('试验室', '') }}
                  </li>
                </ul>
                <div>
                  <el-checkbox @change="changeCheckBox" class="view-self-checkbox"
                    v-model="alone"><span>我的任务</span></el-checkbox>
                </div>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="center-title">
                <el-button size="small" type="primary" @click="qrCodeVisible = true"
                  v-if="selectWarehouse">扫码报检</el-button>
                <el-button size="small" type="primary" @click="exportVisible = true" style="margin-right: 16px;"
                  v-if="selectWarehouse">出库</el-button>
                <span>总计任务数量:</span>
                <span>{{ total }}</span>
              </div>
            </el-col>
          </el-row>
        </div>
        <!-- <ValueTable :tableRowClassName="changeRowClass" class="value-table" ref="insOrderPlan"
                    :isColumnWidth="true"
               :url="$api.insOrderPlan.selectInsOrderPlanList" :upUrl="$api.user.updateUser" :componentData="componentData" @handleInspection="handleInspection"
               :key="upIndex"/>
         </div>
      </div>
      <el-dialog title="提示" :visible.sync="claimVisible" width="400px">
         是否认领委托编号<span style="color:#33C130">{{sampleUserForm.entrustCode}}</span>的任务
         <span slot="footer" class="dialog-footer">
            <el-button @click="claimVisible = false">取 消</el-button>
            <el-button type="primary" @click="confirmClaim" :loading="loading">确 定</el-button>
         </span>
      </el-dialog>
               :key="upIndex"/> -->
        <el-table :data="tableData" ref="table0" border style="width: 100%;" height="calc(100% - 80px)"
          :row-class-name="rowClassName" v-loading="tableLoading" row-key="orderStateId" @sort-change="sortChange">
          <el-table-column prop="entrustCode" label="委托编号" width="140px">
            <template slot-scope="scope">
              <el-button @click="selectAllByOne(scope.row)" type="text" size="small">{{ scope.row.entrustCode
                }}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="sample" label="样品名称" width="100px"></el-table-column>
          <el-table-column prop="sampleCode" label="样品编号" width="170px"></el-table-column>
          <el-table-column prop="type" label="紧急程度" width="100px">
            <template slot-scope="scope">
              <el-tag
                :type="typeList.find(m => m.value == scope.row.type) ? typeList.find(m => m.value == scope.row.type).type : ''"
                size="small">{{
                  typeList.find(m => m.value == scope.row.type) ? typeList.find(m => m.value == scope.row.type).label : ''
                }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="insState" label="状态" width="100px">
            <template slot-scope="scope">
              <el-tag :type="insStateList.find(m => m.value == scope.row.insState).type" size="small">{{
                insStateList.find(m => m.value == scope.row.insState).label }}</el-tag>
            </template></el-table-column>
          <el-table-column prop="userName" label="检验人" width="140px"></el-table-column>
          <el-table-column prop="checkName" label="复核人" width="100px"></el-table-column>
          <el-table-column prop="createTime" label="报检时间" width="120px" sortable></el-table-column>
          <el-table-column prop="appointed" label="约定时间" width="120px" sortable></el-table-column>
          <el-table-column prop="sendTime" label="下发时间" width="160px" sortable></el-table-column>
          <el-table-column prop="insTime" label="检验开始时间" width="160px" sortable></el-table-column>
          <el-table-column prop="submitTime" label="检验结束时间" width="160px" sortable></el-table-column>
          <el-table-column prop="verifyTell" label="理由" width="150px"></el-table-column>
          <el-table-column fixed="right" align="center" label="操作" width="340px">
            <template slot-scope="scope">
              <el-button @click="handleDataLook(scope.row)" type="text" size="small">数据查看</el-button>
              <el-button @click="handleInspection(scope.row)" type="text" size="small"
                :disabled="scope.row.userName == null || scope.row.insState == 3 || scope.row.insState == 5 || scope.row.insState == 6 || (scope.row.userName && !scope.row.userName.includes(userName))"
                v-if="inspection">检验</el-button>
              <el-button @click="handleConnect(scope.row)" type="text" size="small"
                :disabled="scope.row.userName == null || scope.row.insState == 5 || scope.row.insState == 3 || scope.row.insState == 6 || (scope.row.userName && !scope.row.userName.includes(userName))"
                v-if="connect">交接</el-button>
              <el-button @click="cancelSubmitPlan(scope.row)" type="text" size="small"
                :disabled="scope.row.userName == null || scope.row.insState != 3 || (scope.row.userName && !scope.row.userName.includes(userName))"
                v-if="inspection">撤销</el-button>
              <el-button @click="handleReview(scope.row)" type="text" size="small"
                :disabled="scope.row.userName == null || scope.row.insState != 3 || (scope.row.checkName && !scope.row.checkName.includes(userName))"
                v-if="review">复核</el-button>
              <el-button @click="handleReview0(scope.row)" type="text" size="small"
                :disabled="scope.row.userName == null || (scope.row.insState != 4 && scope.row.insState != 5 && scope.row.insState != 6)"
                v-if="verifyPlan2">纠正复核</el-button>
              <el-button @click="claimFun(scope.row)" type="text" size="small"
                :disabled="scope.row.userName != null || scope.row.checkName != null" v-if="claim">认领</el-button>
              <el-button @click="lookHistory0(scope.row)" type="text" size="small">查看记录</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="display: flex;justify-content: flex-end;width: 100%;margin-top: 10px;">
          <span></span>
          <el-pagination @size-change="m => refreshTable('size', m)" @current-change="m => refreshTable('current', m)"
            :current-page="page.current" :page-sizes="[10, 20, 30, 50, 100]" :page-size="page.size"
            layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </div>
      </div>
    </div>
    <el-dialog title="提示" :visible.sync="claimVisible" width="400px">
      是否认领委托编号<span style="color:#33C130">{{ sampleUserForm.entrustCode }}</span>的任务
      <span slot="footer" class="dialog-footer">
        <el-button @click="claimVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmClaim" :loading="loading">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="检验交接" :visible.sync="connectVisible" width="400px">
         <div class="search_thing">
      <div class="search_thing">
        <div class="search_label" style="width:90px"><span class="required-span">* </span>交接人员:</div>
        <div class="search_input">
          <el-select v-model="connect.connectPerson" placeholder="请选择" style="width: 100%;" filterable>
            <el-option
              v-for="item in personList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            <el-option v-for="item in personList" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
@@ -194,483 +288,1033 @@
          </el-select>
        </div>
      </div> -->
         <span slot="footer" class="dialog-footer">
            <el-button @click="connectVisible = false">取 消</el-button>
            <el-button type="primary" @click="confirmConnect" :loading="loading">确 定</el-button>
         </span>
      </el-dialog>
      <div style="width: 100%;height: 100%;" v-if="activeFace >0">
         <Add :active="activeFace" :currentId="currentId" :examine="examine"/>
      </div>
    <Inspection v-if="state>0" @goback="goback" :orderId="orderId" :inspectorList="inspectorList" :sonLaboratory="componentData.entity.sonLaboratory" :state="state"/>
      <el-dialog title="数据查看" :visible.sync="dataDialogVisible" width="80%">
            <div style="height: 70vh;overflow-y: auto;" v-if="dataDialogVisible">
               <ValueTable ref="ValueTableDataLook" :rowKey="'insProductId'" :url="$api.insOrder.selectSampleAndProductByOrderId"
                  :componentData="componentDataDataLook"/>
            </div>
         </el-dialog>
      <span slot="footer" class="dialog-footer">
        <el-button @click="connectVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmConnect" :loading="loading">确 定</el-button>
      </span>
    </el-dialog>
    <div style="width: 100%;height: 100%;" v-if="activeFace > 0">
      <Add :active="activeFace" :currentId="currentId" :examine="examine" />
    </div>
    <Inspection v-if="state > 0" @goback="goback" :orderId="orderId" :inspectorList="inspectorList"
      :sonLaboratory="componentData.entity.sonLaboratory" :state="state" :orderStateId="orderStateId" :version="version"
      :isLook="isLook" :num1="num1" :orderId0="orderId0" :userInfo="userInfo" ref="Inspection" />
    <el-dialog title="数据查看" :visible.sync="dataDialogVisible" width="80%">
      <div style="height: 70vh;overflow-y: auto;" v-if="dataDialogVisible">
        <ValueTable ref="ValueTableDataLook" :rowKey="'insProductId'"
          :url="$api.insOrder.selectSampleAndProductByOrderId" :componentData="componentDataDataLook" />
      </div>
    </el-dialog>
    <el-dialog title="查看记录" :visible.sync="historyDialogVisible" width="50%">
      <el-table :data="historyList" border style="width: 100%">
        <el-table-column prop="submitTime" label="提交日期" min-width="150">
        </el-table-column>
        <el-table-column prop="submitUserName" label="提交人" min-width="90">
        </el-table-column>
        <el-table-column prop="term" label="实验阶段" min-width="120">
        </el-table-column>
        <el-table-column prop="note" label="实验操作" min-width="120">
        </el-table-column>
        <el-table-column prop="tell" label="再次检验原因" min-width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作" min-width="100">
          <template slot-scope="scope">
            <el-button @click="lookHistory(scope.row)" type="text" size="small">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog title="扫码检验" :visible.sync="qrCodeVisible" width="400px">
      <el-row>
        <el-col class="search_thing" :span="24">
          <div class="search_label" style="width: 90px"><span class="required-span">* </span>样品编号:</div>
          <div class="search_input">
            <el-input v-model="sampleCode" size="small" clearable :disabled="sampleCodeBtnDisabled">
              <el-tooltip :content="sampleCodeBtnDisabled ? '手动输入' : '扫码枪输入'" placement="top" slot="append">
                <el-button type="primary" icon="el-icon-edit"
                  @click="sampleCodeBtnDisabled = !sampleCodeBtnDisabled"></el-button>
              </el-tooltip>
            </el-input>
          </div>
        </el-col>
        <el-col class="search_thing" :span="24">
          <div class="search_label" style="width: 90px"><span class="required-span">* </span>订单编号:</div>
          <div class="search_input">
            <el-input v-model="entrustCode" size="small" clearable :disabled="sampleCodeBtnDisabled">
            </el-input>
          </div>
        </el-col>
      </el-row>
      <el-tree :data="storageList" ref="tree" :props="{ children: 'warehouseShelfList', label: 'name' }" node-key="id"
        :filter-node-method="filterNode" @node-click="handleNodeClick" highlight-current @node-expand="nodeOpen"
        @node-collapse="nodeClose" :default-expanded-keys="expandedKeys" v-if="qrCodeVisible" empty-text="暂无数据">
        <div class="custom-tree-node" slot-scope="{ node, data }">
          <el-row>
            <el-col :span="24">
              <span><i
                  :class="`node_i ${data.warehouseShelfList != undefined ? 'el-icon-folder-opened' : 'el-icon-tickets'}`"></i>
                {{ data.name }}</span>
            </el-col>
          </el-row>
        </div>
      </el-tree>
      <span slot="footer" class="dialog-footer">
        <el-button @click="qrCodeVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmStorage" :loading="upLoadStorage">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="出库" :visible.sync="exportVisible" width="400px">
      <el-row>
        <el-col class="search_thing" :span="24">
          <div class="search_label" style="width: 90px"><span class="required-span">* </span>样品编号:</div>
          <div class="search_input">
            <el-input v-model="sampleCode" size="small" clearable :disabled="sampleCodeBtnDisabled">
              <el-tooltip :content="sampleCodeBtnDisabled ? '手动输入' : '扫码枪输入'" placement="top" slot="append">
                <el-button type="primary" icon="el-icon-edit"
                  @click="sampleCodeBtnDisabled = !sampleCodeBtnDisabled"></el-button>
              </el-tooltip>
            </el-input>
          </div>
        </el-col>
        <el-col class="search_thing" :span="24">
          <div class="search_label" style="width: 90px"><span class="required-span">* </span>委托编号:</div>
          <div class="search_input">
            <el-input v-model="entrustCode" size="small" clearable :disabled="sampleCodeBtnDisabled">
            </el-input>
          </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="exportVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmExport" :loading="upLoadExport">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="纠正复核" :visible="upInsReviewDia" width="600px" :close-on-click-modal="false" :show-close="false">
      <el-radio-group v-model="verifyPlanInfo.type" style="display: flex;flex-direction: column" v-if="upInsReviewDia">
        <el-radio :label="1" style="margin: 10px 0; " :inert="false">继续测试下一个样品或其他站点任务</el-radio>
        <el-radio :label="0" style="margin: 10px 0; " :inert="false">再次检验该样品</el-radio>
        <el-radio :label="2" style="margin: 10px 0; " :inert="false">此委托单结束</el-radio>
        <p style="font-size: 12px;color:red">
          慎重:如果还有其他样品在检,点击结束可能会中断,请确保所有样品都检验且复核完成再点击
        </p>
      </el-radio-group>
      <p style="margin-top: 16px;margin-bottom: 6px;"><span style="color:red;margin-right: 4px;">*</span>纠正原因:</p>
      <el-input type="textarea" :rows="2" placeholder="请输入" v-model="verifyPlanInfo.tell">
      </el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="upInsReviewDia = false">取 消</el-button>
        <el-button type="primary" @click="upInsReview" :loading="reviewLoading">确 定</el-button>
      </span>
    </el-dialog>
    <input id="ScanCodeInfo" v-model="codeInfo" @keyup.enter="keyup"
      style="opacity: 0;height: 0px;margin: 0px;padding: 0px;position: absolute;top: 0;"></input>
  </div>
</template>
<script>
   import ValueTable from '../tool/value-table.vue'
     import Inspection from '../do/b1-inspect-order-plan/Inspection.vue'
   import {
      getYearAndMonthAndDays
   } from '../../util/date'
   import Add from '../do/b1-ins-order/add.vue'
import { CellGroup } from 'iview'
   export default {
      components: {
         ValueTable,
      Inspection,
         Add
      },
      data() {
         return {
            examine: null,
        inspectorList: [],//检验人员列表
            alone: false,
            sampleUserForm: {
               entrustCode: null,
               insSampleId: null,
               userId: null
            },
            claimVisible: false,
            tabList: [],
            active: 1,
            tabIndex: 0,
        componentDataDataLook: {
               entity: {
                  id: 0,
                  orderBy: {
                     field: 'sampleCode',
                     order: 'asc'
                  }
               },
               isIndex: false,
               showSelect: false,
               select: false,
               do: [],
               tagField: {
                  insState: {
                     select: []
                  },
                  insResult: {
                     select: [{
                        value: 1,
                        label: '合格',
                        type: 'success'
                     },{
                        value: 0,
                        label: '不合格',
                        type: 'danger'
                     },{
                        value: 3,
                        label: '不判定',
                        type: ''
                     }]
                  }
               },
               selectField: {},
          spanConfig:{
            rows:[
              {
                name:'sampleCode',
                index:0
              },
              {
                name:'sample',
                index:1
              },
              {
                name:'model',
                index:5
              }
            ]
          },
               requiredAdd: [],
               requiredUp: []
            },
        dataDialogVisible: false,
            componentData: {
               entity: {
                  sonLaboratory: null,
                  insState: null,
                  userId: null
               },
               isIndex: true,
               showSelect: false,
               select: false,
               init: false,
          needSort: ['createTime', 'sendTime', 'type', 'appointed', 'insState'],
               do: [{
                  id: '',
                  font: '数据查看',
                  type: 'text',
                  method: 'handleDataLook',
            //disabFun: (row, index) => {
              //const user = JSON.parse(localStorage.getItem('user'))
             // let currentUserName = ''
             // if(user){
              //  currentUserName = user.name
              //}
                     //return row.userName.indexOf(currentUserName)<0 && row.checkName.indexOf(currentUserName)<0
                  //}
               },{
                     id: '',
                     font: '检验',
                     type: 'text',
                     method: 'handleInspection',
                     disabFun: (row, index) => {
                        return row.userName == null || row.insState == 3 || row.insState == 5||row.insState == 6||(row.userName&&!row.userName.includes(JSON.parse(localStorage.getItem("user")).name))
                     }
              // disabFun: (row, index) => {
                     //    return row.userId == null || row.insState == 3 || row.insState == 5
                     // }
                  }, {
                     id: '',
                     font: '交接',
                     type: 'text',
                     method: 'handleConnect',
                     disabFun: (row, index) => {
                        return row.userName == null || row.insState == 5  || row.insState == 3||row.insState == 6||(row.userName&&!row.userName.includes(JSON.parse(localStorage.getItem("user")).name))
                     }
                  },
                  {
                     id: '',
                     font: '复核',
                     type: 'text',
                     method: 'handleReview',
                     disabFun: (row, userName) => {
                        return row.userName == null || row.insState != 3 ||(row.checkName&&!row.checkName.includes(JSON.parse(localStorage.getItem("user")).name))
                     }
                  }, {
                     id: '',
                     font: '认领',
                     type: 'text',
                     method: 'claimFun',
                     disabFun: (row, index) => {
                        return row.userName != null || row.checkName!=null
                     }
                  }
               ],
               linkEvent: {
                  entrustCode: {
                     method: 'selectAllByOne'
                  }
               },
               tagField: {
                  type: {
                     select: []
                  },
                  insState: {
                     select: []
                  },
                  insResult: {
                     select: [{
                        value: 0,
                        label: '不合格',
                        type: 'danger'
                     },{
                        value: 1,
                        label: '合格',
                        type: 'success'
                     },{
                        value: '',
                        label: '未出结果',
                        type: 'info'
                     }]
                  }
               },
               selectField: {},
               requiredAdd: [],
               requiredUp: []
            },
            upIndex: 0,
            planTotal: 0,
            insStateList: [],
        state:0,//0:台账页,1:检验页面,2检验页面(复核),默认为0
            activeFace: 0, //1:下单,2:查看,3:审核,默认为0
            currentId: null,
            entityCopy: {},
            orderId: 0,
        personList:[],
        connectVisible:false,
        connect:{
          connectPerson:'',
          // sonLaboratory:''
import ValueTable from '../tool/value-table.vue'
import Inspection from '../do/b1-inspect-order-plan/Inspection.vue'
import {
  getYearAndMonthAndDays
} from '../../util/date'
import Add from '../do/b1-ins-order/add.vue'
import Sortable from 'sortablejs';
export default {
  components: {
    ValueTable,
    Inspection,
    Add
  },
  data() {
    return {
      currentHistory: {},
      historyDialogVisible: false,
      historyList: [],
      orderStateId: null,
      version: null,
      examine: null,
      inspectorList: [],//检验人员列表
      alone: false,
      sampleUserForm: {
        entrustCode: null,
        insSampleId: null,
        userId: null
      },
      claimVisible: false,
      tabList: [],
      active: 1,
      tabIndex: 0,
      componentDataDataLook: {
        entity: {
          id: 0,
          orderBy: {
            field: 'sampleCode',
            order: 'asc'
          }
        },
        loading:false,
        currentTime: null,
        sonLaboratoryList:[]
         }
      },
      created() {
         this.getLaboratoryDicts()
         this.getTypeDicts()
         this.getInsStateDicts()
      this.getAuthorizedPerson()
      this.currentTime = getYearAndMonthAndDays()
      },
      mounted() {
         this.entityCopy = this.HaveJson(this.componentData.entity)
      this.getPower()
      },
      methods: {
         // 数据查看
         handleDataLook(row) {
            this.componentDataDataLook.entity.id = row.id
            this.dataDialogVisible = true;
         },
      // 权限分配
         getPower(radio) {
            let power = JSON.parse(sessionStorage.getItem('power'))
            let inspection = false
            let connect = false
            let review = false
        let claim = false
            for (var i = 0; i < power.length; i++) {
               if (power[i].menuMethod == 'doInsOrder') {
                  inspection = true
               }
               if (power[i].menuMethod == 'upPlanUser') {
                  connect = true
               }
               if (power[i].menuMethod == 'verifyPlan') {
                  review = true
               }
          if (power[i].menuMethod == 'claimInsOrderPlan') {
                  claim = true
               }
            }
            if (!claim) {
               this.componentData.do.splice(3, 1)
            }
            if (!review) {
               this.componentData.do.splice(2, 1)
            }
        if (!connect) {
               this.componentData.do.splice(1, 1)
            }
            if (!inspection) {
               this.componentData.do.splice(0, 1)
            }
         },
         changeCheckBox(val) {
            this.componentData.entity.userId = val?0:null
            this.refreshTable()
         },
         refresh() {
            this.componentData.entity = this.HaveJson(this.entityCopy)
            if(this.tabList.length>0){
               this.tabIndex = 0
               this.componentData.entity.sonLaboratory = this.tabList[0].value
            }
            this.refreshTable()
         },
         claimFun(row) {
            if (row) {
               this.sampleUserForm = {
                  entrustCode: row.entrustCode,
                  insSampleId: row.id,
            sonLaboratory: row.sonLaboratory,
               }
               this.claimVisible = true
            }
         },
         confirmClaim() {
        this.loading = true;
            this.$axios.post(this.$api.insOrderPlan.claimInsOrderPlan, this.sampleUserForm, {
               headers: {
                  'Content-Type': 'application/json'
               }
            }).then(res => {
               if (res.code === 200 && res.data) {
            this.loading = false;
                  this.$message.success("认领成功")
                  this.claimVisible = false
                  this.refreshTable('page')
               }
            }).catch(error => {
               console.error(error)
          this.loading = false;
            })
         },
         refreshTable(e) {
            this.$refs.insOrderPlan.selectList(e)
         },
         changeRowClass({
            row,
            rowIndex
         }) {
            if (this.currentTime == row.appointed) {
               return 'highlight-warning-row-border'
            } else if (this.currentTime > row.appointed) {
               return 'highlight-danger-row-border'
            }
            return ''
         },
         onReset() {
            this.searchForm = {
               sampleName: null,
               state: null,
            }
            this.componentData.entity.insState = null
            this.componentData.entity.sampleName = null
            this.refreshTable()
         },
         onSubmit() {
            this.componentData.entity.insState = this.searchForm.state
            this.componentData.entity.sampleName = this.searchForm.sampleName
            this.$nextTick(() => {
               this.refreshTable()
            })
         },
         handleTab(m, i) {
            this.tabIndex = i;
            this.componentData.entity.sonLaboratory = m.value
            this.refreshTable()
         },
         getTypeDicts() {
            this.$axios.post(this.$api.enums.selectEnumByCategory, {
               category: "紧急程度"
            }).then(res => {
               let data = res.data
               data.forEach(ele => {
                  if (ele.value === '0') {
                     ele.type = 'success'
                  } else if (ele.value === '1') {
                     ele.type = 'warning'
                  } else if (ele.value === '2') {
                     ele.type = 'danger'
                  }
               })
               this.componentData.tagField.type.select = data
            })
         },
         getInsStateDicts() {
            this.$axios.post(this.$api.enums.selectEnumByCategory, {
               category: "检验任务状态"
            }).then(res => {
               let data = res.data
               this.insStateList = data
               data.forEach(ele => {
                  //0:待检验 1:检验中 2:已检验 3:待复核 4:复核未通过 5:复核通过
                  if (['2', '5'].includes(ele.value)) {
                     ele.type = 'success'
                  } else if (['1', '3'].includes(ele.value)) {
                     ele.type = 'warning'
                  } else if (['0', '4'].includes(ele.value)) {
                     ele.type = 'danger'
                  }
               })
               this.componentData.tagField.insState.select = data
            })
         },
         getLaboratoryDicts() {
            this.$axios.post(this.$api.enums.selectEnumByCategory, {
               category: "子实验室"
            }).then(res => {
               this.tabList = res.data.map(ele => {
                  return {
                     label: ele.label,
                     value: ele.value
                  }
               })
               if(this.tabList.length>0){
                  this.componentData.entity.sonLaboratory = this.tabList[0].value
               }
               this.refreshTable()
            })
         },
         selectAllByOne(row) {
            this.activeFace = 2;
            this.examine = 1;
            this.currentId = parseInt(row.id)
         },
         playOrder(num) {
            this.activeFace = num
         },
         goback() {
            this.state = 0
            this.refreshTable('page')
         },
      handleInspection(row){
        //当前检验任务的检验人列表
        let inspectorList = []
        if(row.userName){
          inspectorList = row.userName.split(',')
        }
        let user = JSON.parse(localStorage.getItem('user'))
        if(user){
          inspectorList.push(user.name)
        }
        this.inspectorList = inspectorList
        this.state = 1;
            this.orderId = row.id
        isIndex: false,
        showSelect: false,
        select: false,
        do: [],
        tagField: {
          insState: {
            select: []
          },
          insResult: {
            select: [{
              value: 1,
              label: '合格',
              type: 'success'
            }, {
              value: 0,
              label: '不合格',
              type: 'danger'
            }, {
              value: 3,
              label: '不判定',
              type: ''
            }]
          }
        },
        selectField: {},
        spanConfig: {
          rows: [
            {
              name: 'sampleCode',
              index: 0
            },
            {
              name: 'sample',
              index: 1
            },
            {
              name: 'model',
              index: 5
            }
          ]
        },
        requiredAdd: [],
        requiredUp: []
      },
      handleConnect(row){
        this.orderId = row.id
        this.connect = {}
        this.connectVisible=true;
        // this.$axios.post(this.$api.insOrderPlan.upPlanUser2, {
        //     orderId:this.orderId,
        //   }).then(res => {
            //    if (res.code === 200&&res.data.length>0) {
        //     this.sonLaboratoryList = [];
        //     res.data.forEach(m=>{
        //       this.sonLaboratoryList.push({
        //         value:m,
        //         label:m
        //       })
        //     })
        //     // this.connect.sonLaboratory = this.sonLaboratoryList[0].value
            //    }
            // })
      dataDialogVisible: false,
      componentData: {
        entity: {
          sonLaboratory: null,
          insState: null,
          userId: null,
          sampleCode: null,
          orderBy: {
            field: 'createTime,appointed,sendTime,insTime,submitTime',
            order: 'asc'
          }
        },
        sortable: true,
        isIndex: true,
        showSelect: false,
        select: false,
        init: false,
        needSort: ['createTime', 'sendTime', 'type', 'appointed', 'insState'],
        do: [{
          id: '',
          font: '数据查看',
          type: 'text',
          method: 'handleDataLook',
          //disabFun: (row, index) => {
          //const user = JSON.parse(localStorage.getItem('user'))
          // let currentUserName = ''
          // if(user){
          //  currentUserName = user.name
          //}
          //return row.userName.indexOf(currentUserName)<0 && row.checkName.indexOf(currentUserName)<0
          //}
        }, {
          id: '',
          font: '检验',
          type: 'text',
          method: 'handleInspection',
          disabFun: (row, index) => {
            return row.userName == null || row.insState == 3 || row.insState == 5 || row.insState == 6 || (row.userName && !row.userName.includes(JSON.parse(localStorage.getItem("user")).name))
          }
          // disabFun: (row, index) => {
          //    return row.userId == null || row.insState == 3 || row.insState == 5
          // }
        }, {
          id: '',
          font: '交接',
          type: 'text',
          method: 'handleConnect',
          disabFun: (row, index) => {
            return row.userName == null || row.insState == 5 || row.insState == 3 || row.insState == 6 || (row.userName && !row.userName.includes(JSON.parse(localStorage.getItem("user")).name))
          }
        },
        {
          id: '',
          font: '复核',
          type: 'text',
          method: 'handleReview',
          disabFun: (row, userName) => {
            return row.userName == null || row.insState != 3 || (row.checkName && !row.checkName.includes(JSON.parse(localStorage.getItem("user")).name))
          }
        }, {
          id: '',
          font: '认领',
          type: 'text',
          method: 'claimFun',
          disabFun: (row, index) => {
            return row.userName != null || row.checkName != null
          }
        }, {
          id: '',
          font: '查看记录',
          type: 'text',
          method: 'claimFun',
          disabFun: (row, index) => {
            return !row.num1 || row.num1 < 2
          }
        }
        ],
        linkEvent: {
          entrustCode: {
            method: 'selectAllByOne'
          }
        },
        tagField: {
          type: {
            select: []
          },
          insState: {
            select: []
          },
          insResult: {
            select: [{
              value: 0,
              label: '不合格',
              type: 'danger'
            }, {
              value: 1,
              label: '合格',
              type: 'success'
            }, {
              value: '',
              label: '未出结果',
              type: 'info'
            }]
          }
        },
        selectField: {},
        requiredAdd: [],
        requiredUp: []
      },
      confirmConnect(){
        if(this.connect.connectPerson==null||this.connect.connectPerson==''||this.connect.connectPerson==undefined){
          this.$message.error('未选择交接人员')
      userName: JSON.parse(localStorage.getItem("user")).name,
      upIndex: 0,
      planTotal: 0,
      insStateList: [],
      state: 0,//0:台账页,1:检验页面,2检验页面(复核),默认为0
      activeFace: 0, //1:下单,2:查看,3:审核,默认为0
      currentId: null,
      entityCopy: {},
      orderId: null,
      orderId0: null,
      personList: [],
      connectVisible: false,
      connect: {
        connectPerson: '',
        // sonLaboratory:''
      },
      loading: false,
      currentTime: null,
      sonLaboratoryList: [],
      tableData: [],
      page: {
        current: 1,
        size: 20,
      },
      total: 0,
      tableLoading: false,
      jumpTeam: false,
      insResultList: [{
        value: 0,
        label: '不合格',
        type: 'danger'
      }, {
        value: 1,
        label: '合格',
        type: 'success'
      }, {
        value: '',
        label: '未出结果',
        type: 'info'
      }],
      typeList: [],
      getInsProduct2: false,
      claim: false,
      review: false,
      verifyPlan2: false,
      connect: false,
      inspection: false,
      isLook: false,//是否是查看历史页面
      num1: null,
      codeInfo: null,
      startTime: null,
      scanInsOrderState: false,
      qrCodeVisible: false,
      sampleCode: '',
      entrustCode: '',
      storageList: [],
      expandedKeys: [],
      selectTree: [],
      upLoadStorage: false,
      exportVisible: false,
      upLoadExport: false,
      selectWarehouse: false,
      userInfo: {
        name: [],
        ids: []
      },
      sampleCodeBtnDisabled: true,
      upInsReviewDia: false,
      verifyPlanInfo: {
        tell: null,
        type: null
      },
      reviewLoading: false
    }
  },
  watch: {
    qrCodeVisible(newVal) {
      if (newVal) {
        // this.$message.success('扫码:打开')
        this.selectList()
        this.sampleCode = null
        this.entrustCode = null
        let input = document.getElementById('ScanCodeInfo');
        input.focus();
        this.startTime = setInterval(() => {
          input.focus()
        }, 1000)
      } else {
        // this.$message.warning('扫码:关闭')
        clearInterval(this.startTime)
        this.sampleCodeBtnDisabled = true
      }
    },
    exportVisible(newVal) {
      if (newVal) {
        // this.$message.success('扫码:打开')
        this.sampleCode = null
        this.entrustCode = null
        let input = document.getElementById('ScanCodeInfo');
        input.focus();
        this.startTime = setInterval(() => {
          input.focus()
        }, 1000)
      } else {
        // this.$message.warning('扫码:关闭')
        clearInterval(this.startTime)
        this.sampleCodeBtnDisabled = true
      }
    },
    sampleCodeBtnDisabled(val) {
      if (!val) {
        this.startTime && clearInterval(this.startTime)
      } else if (this.exportVisible || this.qrCodeVisible) {
        // this.sampleCode = null
        // this.entrustCode = null
        let input = document.getElementById('ScanCodeInfo');
        input.focus();
        this.startTime = setInterval(() => {
          input.focus()
        }, 1000)
      }
    }
  },
  created() {
    this.getLaboratoryDicts()
    this.getTypeDicts()
    this.getInsStateDicts()
    this.getAuthorizedPerson()
    this.currentTime = getYearAndMonthAndDays()
  },
  mounted() {
    this.entityCopy = this.HaveJson(this.componentData.entity)
    this.getPower()
    if (this.jumpTeam) {
      this.initializeSortable();
    }
  },
  methods: {
    selectList() {
      this.$axios.get(this.$api.warehouse.selectWarehouse).then(res => {
        this.warehouse = res.data
        this.storageList = this.HaveJson(res.data).map(item => {
          item.warehouseShelfList && item.warehouseShelfList.length > 0 && item.warehouseShelfList.map(m => {
            let warehouseShelfList = [];
            let warehouseShelfList0 = []
            let warehouseCellList = m.warehouseCellList ? m.warehouseCellList : []
            warehouseCellList.forEach(a => {
              if (warehouseShelfList.find(n => n.id == a.row)) {
                warehouseShelfList0.push({
                  name: a.col + '列',
                  id: a.col
                })
              } else if (warehouseShelfList.length == 0) {
                warehouseShelfList.push({
                  name: a.row + '层',
                  id: a.row
                })
                warehouseShelfList0.push({
                  name: a.col + '列',
                  id: a.col
                })
              } else if (!warehouseShelfList.find(n => n.id == a.row)) {
                warehouseShelfList[warehouseShelfList.length - 1].warehouseShelfList = JSON.parse(JSON.stringify(warehouseShelfList0))
                warehouseShelfList0 = []
                warehouseShelfList.push({
                  name: a.row + '层',
                  id: a.row
                })
                warehouseShelfList0.push({
                  name: a.col + '列',
                  id: a.col
                })
              }
            })
            warehouseShelfList[warehouseShelfList.length - 1].warehouseShelfList = JSON.parse(JSON.stringify(warehouseShelfList0))
            m.warehouseShelfList = warehouseShelfList;
            return m;
          })
          return item;
        })
      })
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    handleNodeClick(val, node, el) { //树的值
      this.selectTree[node.level - 1] = val.id;
    },
    nodeOpen(data, node, el) {
      $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder-opened')
      this.selectTree[node.level - 1] = data.id;
    },
    nodeClose(data, node, el) {
      $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder')
    },
    // 扫码报检
    confirmStorage() {
      if (!this.sampleCode) {
        this.$message.error('请填写样品编号')
        return
      }
      if (!this.entrustCode) {
        this.$message.error('请填写订单编号')
        return
      }
      if (this.selectTree.length < 4) {
        this.$message.error('请选择样品入库位置')
        return
      }
      this.upLoadStorage = true;
      this.$axios.post(this.$api.insOrderPlan.scanInsOrderState, {
        trees: this.selectTree.join('-'),
        sampleCode: this.sampleCode,
        entrustCode: this.entrustCode,
        sonLaboratory: this.componentData.entity.sonLaboratory
      }).then(res => {
        this.upLoadStorage = false;
        this.qrCodeVisible = false
        this.sampleCode = '';
        this.entrustCode = '';
        this.selectTree = []
        if (res.code == 201) {
          this.$message.error('添加失败')
          return
        }
        // if(this.connect.sonLaboratory==null||this.connect.sonLaboratory==''||this.connect.sonLaboratory==undefined){
        //   this.$message.error('未选择试验室')
        //   return
        this.$message.success('添加成功')
        this.refreshTable()
      })
    },
    // 确认出库
    confirmExport() {
      if (!this.sampleCode) {
        this.$message.error('请填写样品编号')
        return
      }
      if (!this.entrustCode) {
        this.$message.error('请填写订单编号')
        return
      }
      this.upLoadExport = true;
      this.$axios.post(this.$api.insOrderPlan.outInsOrderState, {
        sampleCode: this.sampleCode,
        entrustCode: this.entrustCode,
        sonLaboratory: this.componentData.entity.sonLaboratory
      }).then(res => {
        this.upLoadExport = false;
        this.exportVisible = false
        this.sampleCode = '';
        this.entrustCode = '';
        if (res.code == 201) {
          this.$message.error('出库失败')
          return
        }
        this.$message.success('出库成功')
        this.handleShelf(this.entity.shelfId)
      })
    },
    // 扫码枪按下
    keyup(e) {
      var codeInfo = null
      try {
        console.log(2222, this.codeInfo)
        codeInfo = JSON.parse(this.codeInfo)
        if (!codeInfo || codeInfo.sampleCode == undefined || codeInfo.entrustCode == undefined) {
          this.$message.error('该二维码有误')
        } else {
          this.sampleCode = codeInfo.sampleCode
          this.entrustCode = codeInfo.entrustCode
        }
      } catch (e) {
        this.$message.error('请调至英文键盘')
        console.log(e)
      }
      this.codeInfo = null
    },
    // 拖拽
    initializeSortable() {
      const tableBody = this.$refs.table0.$el.querySelector('.el-table__body-wrapper > table > tbody');
      if (tableBody) {
        Sortable.create(tableBody, {
          handle: '.el-table__row', // 拖动手柄
          animation: 200,
          onEnd: this.handleSortEnd,
        });
      } else {
        console.error('Table body not found.');
      }
    },
    handleSortEnd(evt) {
      const oldIndex = evt.oldIndex;
      const newIndex = evt.newIndex;
      const movedItem = this.tableData[oldIndex];
      if (oldIndex !== newIndex) {
        this.tableData.splice(oldIndex, 1);
        this.tableData.splice(newIndex, 0, movedItem);
      }
      this.upIndex++
      this.$axios.post(this.$api.insOrderPlan.jumpTeam,
        {
          id: movedItem.orderStateId,
          sort: newIndex + 1,
          ...this.page
        }, {
        headers: {
          'Content-Type': 'application/json'
        }
      }
      ).then(res => {
      })
    },
    rowClassName({ row, rowIndex }) {
      return 'draggable-row';
    },
    // 数据查看
    handleDataLook(row) {
      this.componentDataDataLook.entity.id = row.id
      this.dataDialogVisible = true;
    },
    // 权限分配
    getPower(radio) {
      let power = JSON.parse(sessionStorage.getItem('power'))
      let inspection = false
      let connect = false
      let review = false
      let claim = false
      let jumpTeam = false
      let verifyPlan2 = false
      // let getInsProduct2 = false
      // let getInsOrderUserList = false
      for (var i = 0; i < power.length; i++) {
        if (power[i].menuMethod == 'doInsOrder') {
          inspection = true
        }
        if (power[i].menuMethod == 'upPlanUser') {
          connect = true
        }
        if (power[i].menuMethod == 'verifyPlan') {
          review = true
        }
        if (power[i].menuMethod == 'verifyPlan2') {
          verifyPlan2 = true
        }
        if (power[i].menuMethod == 'claimInsOrderPlan') {
          claim = true
        }
        if (power[i].menuMethod == 'jumpTeam') {
          jumpTeam = true
        }
        // if (power[i].menuMethod == 'getInsProduct2') {
        //    getInsProduct2 = true
        // }
        this.loading = true;
          this.$axios.post(this.$api.insOrderPlan.upPlanUser, {
            orderId:this.orderId,
            userId:this.connect.connectPerson,
            sonLaboratory:this.componentData.entity.sonLaboratory,
          }).then(res => {
               if (res.code === 200) {
            this.loading = false;
                  this.$message.success("操作成功")
                  this.refreshTable('page')
               }
          this.connectVisible = false
            }).catch(error => {
               console.error(error)
        if (power[i].menuMethod == 'scanInsOrderState') {
          this.scanInsOrderState = true
        }
        if (power[i].menuMethod == 'scanInsOrderState') {
          this.selectWarehouse = true
        }
      }
      // if (!getInsProduct2) {
      //    this.componentData.do.splice(5, 1)
      // }
      // if (!claim) {
      //    this.componentData.do.splice(4, 1)
      // }
      // if (!review) {
      //    this.componentData.do.splice(3, 1)
      // }
      // if (!connect) {
      //    this.componentData.do.splice(2, 1)
      // }
      // if (!inspection) {
      //    this.componentData.do.splice(1, 1)
      // }
      // this.getInsProduct2 = getInsProduct2
      this.claim = claim
      this.review = review
      this.verifyPlan2 = verifyPlan2
      this.connect = connect
      this.inspection = inspection
      this.jumpTeam = jumpTeam
    },
    changeCheckBox(val) {
      this.componentData.entity.userId = val ? 0 : null
      this.refreshTable()
    },
    refresh() {
      this.componentData.entity = this.HaveJson(this.entityCopy)
      if (this.tabList.length > 0) {
        this.tabIndex = 0
        this.componentData.entity.sonLaboratory = this.tabList[0].value
      }
      this.refreshTable()
    },
    claimFun(row) {
      if (row) {
        this.sampleUserForm = {
          entrustCode: row.entrustCode,
          insSampleId: row.sampleId,
          sonLaboratory: row.sonLaboratory,
        }
        this.claimVisible = true
      }
    },
    confirmClaim() {
      this.loading = true;
      // this.sampleUserForm.insSampleId = this.orderId
      this.$axios.post(this.$api.insOrderPlan.claimInsOrderPlan, this.sampleUserForm, {
        headers: {
          'Content-Type': 'application/json'
        },
        noQs: true
      },).then(res => {
        if (res.code === 200 && res.data) {
          this.loading = false;
            })
      },
      handleReview(row){
        this.state = 2;
            this.orderId = row.id
      },
      getAuthorizedPerson() {
            this.$axios.get(this.$api.user.getUserMenu).then(res => {
               let data = []
               res.data.forEach(a => {
                  data.push({
                     label: a.name,
                     value: a.id
                  })
               })
               this.personList = data
            })
         },
      }
   }
          this.$message.success("认领成功")
          this.claimVisible = false
          this.refreshTable()
        } else {
          this.loading = false;
        }
      }).catch(error => {
        console.error(error)
        this.loading = false;
      })
    },
    refreshTable(type, val) {
      if (type && val) {
        this.page[type] = val;
      }
      this.tableLoading = true
      this.$axios.post(this.$api.insOrderPlan.selectInsOrderPlanList, {
        entity: this.componentData.entity,
        page: this.page
      }, {
        headers: {
          'Content-Type': 'application/json'
        }
      }).then((res) => {
        this.tableLoading = false
        this.total = res.data.body.total
        this.tableData = res.data.body.records
        // this.$refs.table0.doLayout()
      })
    },
    changeRowClass({
      row,
      rowIndex
    }) {
      if (this.currentTime == row.appointed) {
        return 'highlight-warning-row-border'
      } else if (this.currentTime > row.appointed) {
        return 'highlight-danger-row-border'
      }
      return ''
    },
    onReset() {
      this.searchForm = {
        sampleName: null,
        state: null,
      }
      this.componentData.entity.insState = null
      this.componentData.entity.sampleName = null
      this.refreshTable()
    },
    onSubmit() {
      this.componentData.entity.insState = this.searchForm.state
      this.componentData.entity.sampleName = this.searchForm.sampleName
      this.$nextTick(() => {
        this.refreshTable()
      })
    },
    handleTab(m, i) {
      this.tabIndex = i;
      this.componentData.entity.sonLaboratory = m.value
      this.refreshTable()
    },
    getTypeDicts() {
      this.$axios.post(this.$api.enums.selectEnumByCategory, {
        category: "紧急程度"
      }).then(res => {
        let data = res.data
        data.forEach(ele => {
          if (ele.value === '0') {
            ele.type = 'success'
          } else if (ele.value === '1') {
            ele.type = 'warning'
          } else if (ele.value === '2') {
            ele.type = 'danger'
          }
        })
        this.componentData.tagField.type.select = data
        this.typeList = data
      })
    },
    getInsStateDicts() {
      this.$axios.post(this.$api.enums.selectEnumByCategory, {
        category: "检验任务状态"
      }).then(res => {
        let data = res.data
        this.insStateList = data
        data.forEach(ele => {
          //0:待检验 1:检验中 2:已检验 3:待复核 4:复核未通过 5:复核通过
          if (['2', '5'].includes(ele.value)) {
            ele.type = 'success'
          } else if (['1', '3'].includes(ele.value)) {
            ele.type = 'warning'
          } else if (['0', '4'].includes(ele.value)) {
            ele.type = 'danger'
          }
        })
        this.componentData.tagField.insState.select = data
      })
    },
    getLaboratoryDicts() {
      this.$axios.post(this.$api.enums.selectEnumByCategory, {
        category: "子实验室"
      }).then(res => {
        this.tabList = res.data.map(ele => {
          return {
            label: ele.label,
            value: ele.value
          }
        })
        if (this.tabList.length > 0) {
          this.componentData.entity.sonLaboratory = this.tabList[0].value
        }
        this.refreshTable()
      })
    },
    selectAllByOne(row) {
      this.activeFace = 2;
      this.examine = 1;
      this.currentId = parseInt(row.id)
    },
    playOrder(num) {
      this.activeFace = num
    },
    goback() {
      this.state = 0
      this.refreshTable('page')
    },
    handleInspection(row) {
      //当前检验任务的检验人列表
      let inspectorList = []
      if (row.userName) {
        inspectorList = row.userName.split(',')
      }
      let user = JSON.parse(localStorage.getItem('user'))
      if (user) {
        inspectorList.push(user.name)
      }
      this.inspectorList = inspectorList
      this.orderId = row.sampleId
      this.orderId0 = row.id
      this.version = row.version
      this.orderStateId = row.orderStateId
      this.state = 1;
      this.userInfo.name = row.userName.split(',')
      this.userInfo.ids = row.userNameId.split(',')
      this.isLook = false
    },
    handleConnect(row) {
      this.orderId = row.sampleId
      this.orderId0 = row.id
      this.connect = {}
      this.connectVisible = true;
      // this.$axios.post(this.$api.insOrderPlan.upPlanUser2, {
      //     orderId:this.orderId,
      //   }).then(res => {
      //    if (res.code === 200&&res.data.length>0) {
      //     this.sonLaboratoryList = [];
      //     res.data.forEach(m=>{
      //       this.sonLaboratoryList.push({
      //         value:m,
      //         label:m
      //       })
      //     })
      //     // this.connect.sonLaboratory = this.sonLaboratoryList[0].value
      //    }
      // })
    },
    cancelSubmitPlan(row) {
      this.$confirm('确定撤销此次检验提交?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$axios.post(this.$api.insOrderPlan.cancelSubmitPlan, {
          orderStateId: row.orderStateId
        }).then(res => {
          if (res.code == 201) {
            return
          }
          this.$message.success("操作成功")
          this.refreshTable('page')
        }).catch(() => { })
      }).catch(() => { })
    },
    confirmConnect() {
      if (this.connect.connectPerson == null || this.connect.connectPerson == '' || this.connect.connectPerson == undefined) {
        this.$message.error('未选择交接人员')
        return
      }
      // if(this.connect.sonLaboratory==null||this.connect.sonLaboratory==''||this.connect.sonLaboratory==undefined){
      //   this.$message.error('未选择试验室')
      //   return
      // }
      this.loading = true;
      this.$axios.post(this.$api.insOrderPlan.upPlanUser, {
        sampleId: this.orderId,
        userId: this.connect.connectPerson,
        sonLaboratory: this.componentData.entity.sonLaboratory,
      }).then(res => {
        if (res.code === 200) {
          this.loading = false;
          this.$message.success("操作成功")
          this.refreshTable('page')
        }
        this.connectVisible = false
      }).catch(error => {
        console.error(error)
        this.loading = false;
      })
    },
    handleReview(row) {
      this.state = 2;
      this.orderId = row.sampleId
      this.orderId0 = row.id
      this.version = row.version
      this.orderStateId = row.orderStateId
      this.isLook = false
    },
    getAuthorizedPerson() {
      this.$axios.get(this.$api.user.getUserMenu).then(res => {
        let data = []
        res.data.forEach(a => {
          data.push({
            label: a.name,
            value: a.id
          })
        })
        this.personList = data
      })
    },
    lookHistory0(row) {
      this.currentHistory = row
      this.$axios.post(this.$api.insOrderPlan.getInsOrderUserList, {
        insOrderStateId: row.orderStateId,
      }).then(res => {
        this.historyList = res.data
        this.historyDialogVisible = true
      })
    },
    lookHistory(row) {
      this.isLook = true
      this.state = 2;
      this.orderId = this.currentHistory.sampleId
      this.orderId0 = this.currentHistory.id
      this.version = this.currentHistory.version
      this.orderStateId = this.currentHistory.orderStateId
      this.num1 = row.num
      this.historyDialogVisible = false
    },
    // 纠正复核
    upInsReview() {
      if (this.verifyPlanInfo.type != 0 && this.verifyPlanInfo.type != 1 && this.verifyPlanInfo.type != 2) {
        return this.$message.error("请选择复核状态");
      }
      if (!this.verifyPlanInfo.tell) {
        return this.$message.error("请输入纠正复核的原因");
      }
      this.reviewLoading = true;
      this.$axios
        .post(this.$api.insOrderPlan.verifyPlan2, {
          sampleId: this.verifyPlanInfo.sampleId,
          type: this.verifyPlanInfo.type,
          laboratory: this.componentData.entity.sonLaboratory,
          tell: this.verifyPlanInfo.tell
        })
        .then(res => {
          if (res.code === 200) {
            this.$message.success("操作成功");
            this.upInsReviewDia = false;
            this.refreshTable()
          }
          this.reviewLoading = false;
        })
        .catch(error => {
          console.error(error);
          this.reviewLoading = false;
        });
    },
    handleReview0(row) {
      this.verifyPlanInfo = JSON.parse(JSON.stringify(row));
      this.$set(this.verifyPlanInfo, 'tell', null)
      this.$set(this.verifyPlanInfo, 'type', null)
      this.upInsReviewDia = true
    },
    sortChange(ob) {
      this.componentData.entity.orderBy = {}
      this.componentData.entity.orderBy.field = ob.prop
      if (ob.order == 'ascending') {
        this.componentData.entity.orderBy.order = 'asc'
      } else if (ob.order == 'descending') {
        this.componentData.entity.orderBy.order = 'desc'
      }
      this.refreshTable()
    }
  }
}
</script>