<!-- 检验委托-成品 -->
<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true">
        <el-form-item label="委托单位">
          <el-select v-model="search.planCompanyNo" clearable filterable collapse-tags size="small"
            style="width: 200px; margin-right: 10px" placeholder="请选择查询内容">
            <el-option v-for="item in entrOrgNameType" :key="item.baseName" :label="item.orgName" :value="item.orgCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料名称">
          <el-input v-model="search.matName" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容"
            style="width: 200px; margin-right: 10px"></el-input>
        </el-form-item>
        <el-form-item label="批次号">
          <el-input v-model="search.batchNo" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容"
            style="width: 200px; margin-right: 10px"></el-input>
        </el-form-item>
        <el-form-item label="委托编号">
          <el-input v-model="search.carNo" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容"
            style="width: 200px; margin-right: 10px" clearable></el-input>
        </el-form-item>
        <el-form-item label="中心编号">
          <el-input v-model="search.sampleNo" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容"
            style="width: 200px; margin-right: 10px" clearable></el-input>
        </el-form-item>
        <el-form-item label="委托日期">
          <el-date-picker v-model="search.times[0]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="开始日期" size="mini" style="width: 140px">
          </el-date-picker>
          <span>至</span>
          <el-date-picker v-model="search.times[1]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="结束日期" size="mini" style="width: 140px">
          </el-date-picker>
          <!-- <el-date-picker
            v-model="search.times"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="small"
            style="width: 300px"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker> -->
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="reset">重置</el-button>
        </el-form-item>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <el-input v-model="values" ref="autoInput" size="mini" style="display: inline-block; width: 150px"
          @input="autoSubmit()" placeholder="扫码接收" clearable :disabled="inputLoading"></el-input>
      </el-form>
    </div>
    <el-row>
      <el-col :span="14">
        <el-tabs v-model="activeName" type="border-card">
          <el-tab-pane label="有效委托" name="first">
            <div class="common-title-div" style="height: auto; margin-top: -10px">
              <div class="common-title-name" style="width: 280px">
                <img style="width: 25px; height: 25px" src="../../../../assets/img/imgScreen/logo.png" />
                检验委托信息
              </div>
              <el-button icon="el-icon-search" style="height: 100%; margin-left: -220px; margin-top: 28px" type="goon"
                size="mini" @click="countList">物料统计</el-button>
              <div>
                <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" v-privilege="activeMenu + 'add'"
                  @click="addData" style="border: 3px">新增</el-button>
                <!-- <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData">修改</el-button> -->
                <el-button icon="el-icon-check" type="goon" size="mini" :loading="subLoading"
                  v-privilege="activeMenu + 'submit'" @click="submitData" style="border: 3px">提交</el-button>
                <el-button icon="el-icon-edit" type="goon" size="mini" v-privilege="activeMenu + 'PUT'"
                  @click="modifyData" style="border: 3px">修改</el-button>
                <el-button icon="el-icon-check" type="goon" size="mini" :loading="subLoading8" @click="updateSampleNo"
                  style="border: 3px">修改委托编号</el-button>
                <el-button icon="el-icon-back" type="danger" size="mini" :loading="subLoading"
                  v-privilege="activeMenu + 'submit'" @click="cancelData" style="margin-top: 2px">取消提交</el-button>
                <el-button icon="el-icon-back" type="danger" size="mini" :loading="subLoading"
                  v-privilege="activeMenu + 'submit'" @click="disable" style="border: 3px">停用</el-button>
                <el-button icon="el-icon-download" type="goon" size="mini" :loading="exportFileLoading"
                  @click="exportFile">导出检测委托书</el-button>
                <el-button icon="el-icon-edit-outline" type="goon" size="mini" :loading="false"
                  @click="showQRCodeInfo">编辑二维码</el-button>
                <el-button icon="el-icon-printer" type="goon" size="mini" :loading="printLoading" @click="printQRCode"
                  style="border: 3px">打印标签</el-button>
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom: 0; margin-top: 0">
              <el-table id="excelTable" v-loading="dataLoading" ref="dataTable" border :height="height_top"
                highlight-current-row @row-click="saveDataMain" :data="table.list" :icore-filter-flag="icoreFilterFlag"
                :header-cell-style="tableHeaderCellStyle" @cell-click="searchFollow" @selection-change="selectRow"
                :cell-class-name="tableRowClassName" :summary-method="getSummaries" show-summary>
                <el-table-column type="index" label="NO" fixed="left" width="35" align="center"></el-table-column>
                <el-table-column type="selection" width="45" fixed="left" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="60px" prop="stateFlag1" label="状态"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="carNo" label="委托编号"
                  align="center">
                  <template slot-scope="{ row }">
                    <el-input v-model="row.carNo" size="small" style="width: 100%">
                    </el-input>
                  </template>
                </el-table-column>
                <!-- <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="entrId" label="委托编号" align="center"></el-table-column> -->
                <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="sampleNo" label="中心编号"
                  align="center"></el-table-column>
                <!-- <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="id" label="编号" align="center"></el-table-column> -->
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="planCompanyName" label="委托单位"  align="center"></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="125px" prop="matName" label="物料名称"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="entrTime1" label="委托日期"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="memo" label="备注"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="planCompanyName"
                  label="生产单位" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="planDeptName"
                  label="生产车间" align="center"></el-table-column>
                <!-- <el-table-column
                    sortable
                    :show-overflow-tooltip="true"
                    min-width="150px"
                    prop="batchNo"
                    label="批次号"
                    align="center"
                  >
                    <template slot-scope="{ row }">
                      <el-input
                        v-if="row.stateFlag == '0'"
                        v-model="row.batchNo"
                        size="small"
                        style="width: 100%"
                      >
                      </el-input>
                      <span v-else>{{ row.batchNo }}</span>
                    </template>
                  </el-table-column> -->
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="entrTypeName" label="委托类型"  align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sampleTypeName" label="样品类型" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="gradeName" label="牌号" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="matClassName" label="物料分类"  align="center"></el-table-column> -->

                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="testTypeName"
                  label="检验类型" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpDeliName"
                  label="取样频次" align="center"></el-table-column>
                <!-- <el-table-column
                    sortable
                    :show-overflow-tooltip="true"
                    min-width="80px"
                    prop="gradeName"
                    label="牌号"
                    align="center"
                  ></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="matShapeName"
                  label="试样形状" align="center"></el-table-column>
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemName" label="分析项目"  align="center"></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="companyName"
                  label="检验单位" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="deptName" label="检验车间"
                  align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="sectionName"
                  label="检验班组" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpCompanyName"
                  label="取样单位" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpDeptName"
                  label="取样车间" align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="smpSectionName"
                  label="取样班组" align="center"></el-table-column>
                <!-- <el-table-column
                    sortable
                    :show-overflow-tooltip="true"
                    min-width="100px"
                    prop="spec"
                    label="规格"
                    align="center"
                  ></el-table-column> -->
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="rollNo" label="轧批号" align="center"></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="createMan" label="创建人"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="updateMan" label="修改人"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="updateTime" label="修改时间"
                  align="center"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination @size-change="pageSizeChange" @current-change="pageCurrentChange"
                :current-page="page.pageNum" :page-sizes="[100, 200, 500, 800, 1000]" :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="page.totalPage" background>
              </el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="停用委托" name="first1">
            <div class="common-title-div" style="height: auto; margin-top: -10px">
              <div class="common-title-name" style="width: 280px">
                <img style="width: 25px; height: 25px" src="../../../../assets/img/imgScreen/logo.png" />
                检验委托信息
              </div>
              <div>
                <el-button icon="el-icon-check" type="goon" size="mini" :loading="subLoadingq"
                  v-privilege="activeMenu + 'submit'" @click="enable" style="border: 3px">启用</el-button>
                <el-button icon="el-icon-check" type="goon" size="mini" :loading="subLoadingq"
                  v-privilege="activeMenu + 'submit'" @click="removeNumber"
                  style="border: 3px; margin-top: 3px">清除编号</el-button>
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom: 0; margin-top: 0">
              <el-table id="invalidTable" v-loading="invalidLoading" ref="dataTable" border :height="height_top"
                highlight-current-row @row-click="saveDataMain" :data="table.list1" :icore-filter-flag="icoreFilterFlag"
                :header-cell-style="tableHeaderCellStyle" @cell-click="searchFollow" @selection-change="selectRow1"
                :cell-class-name="tableRowClassName" :summary-method="getSummaries" show-summary>
                <el-table-column type="index" label="NO" fixed="left" width="35" align="center"></el-table-column>
                <el-table-column type="selection" width="45" fixed="left" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="60px" prop="stateFlag1" label="状态"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="carNo" label="委托编号"
                  align="center">
                  <template slot-scope="{ row }">
                    <el-input v-model="row.carNo" size="small" style="width: 100%">
                    </el-input>
                  </template>
                </el-table-column>
                <!-- <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="entrId" label="委托编号" align="center"></el-table-column> -->
                <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="sampleNo" label="中心编号"
                  align="center"></el-table-column>
                <!-- <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="id" label="编号" align="center"></el-table-column> -->
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="planCompanyName" label="委托单位"  align="center"></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="125px" prop="matName" label="物料名称"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="entrTime1" label="委托日期"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="memo" label="备注"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="planCompanyName"
                  label="生产单位" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="planDeptName"
                  label="生产车间" align="center"></el-table-column>
                <!-- <el-table-column
                    sortable
                    :show-overflow-tooltip="true"
                    min-width="150px"
                    prop="batchNo"
                    label="批次号"
                    align="center"
                  >
                    <template slot-scope="{ row }">
                      <el-input
                        v-if="row.stateFlag == '0'"
                        v-model="row.batchNo"
                        size="small"
                        style="width: 100%"
                      >
                      </el-input>
                      <span v-else>{{ row.batchNo }}</span>
                    </template>
                  </el-table-column> -->
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="entrTypeName" label="委托类型"  align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sampleTypeName" label="样品类型" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="gradeName" label="牌号" align="center"></el-table-column>
                  <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="matClassName" label="物料分类"  align="center"></el-table-column> -->

                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="testTypeName"
                  label="检验类型" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpDeliName"
                  label="取样频次" align="center"></el-table-column>
                <!-- <el-table-column
                    sortable
                    :show-overflow-tooltip="true"
                    min-width="80px"
                    prop="gradeName"
                    label="牌号"
                    align="center"
                  ></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="matShapeName"
                  label="试样形状" align="center"></el-table-column>
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemName" label="分析项目"  align="center"></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="companyName"
                  label="检验单位" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="deptName" label="检验车间"
                  align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="sectionName"
                  label="检验班组" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpCompanyName"
                  label="取样单位" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="smpDeptName"
                  label="取样车间" align="center"></el-table-column>
                <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="smpSectionName"
                  label="取样班组" align="center"></el-table-column>
                <!-- <el-table-column
                    sortable
                    :show-overflow-tooltip="true"
                    min-width="100px"
                    prop="spec"
                    label="规格"
                    align="center"
                  ></el-table-column> -->
                <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="rollNo" label="轧批号" align="center"></el-table-column> -->
                <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="createMan" label="创建人"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="updateMan" label="修改人"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="updateTime" label="修改时间"
                  align="center"></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-col>
      <el-col :span="10">
        <el-tabs v-model="activeName2" type="border-card" class="testManagement_left">
          <el-tab-pane label="检验项目" name="first">
            <div class="common-title-div" style="height: 75px; margin-top: 25px">
              <div class="common-title-name">
                <img style="width: 25px; height: 25px" src="../../../../assets/img/imgScreen/logo.png" />
                计划检验项目表
              </div>
              <div>
                <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini"
                  v-privilege="activeMenu + 'addDep'" @click="addData2">新增</el-button>
                <el-button icon="el-icon-remove-outline" type="danger" size="mini"
                  v-privilege="activeMenu + 'deleteDep'" @click="deleteData2">删除</el-button>
              </div>
            </div>
            <div class="common-table-div" style="margin-bottom: 0; margin-top: 0">
              <el-table v-loading="dataLoading2" ref="dataTable2" border :height="height_bot" @row-click="saveData"
                highlight-current-row @selection-change="selectData" :data="table.list2"
                :icore-filter-flag="icoreFilterFlag" :header-cell-style="tableHeaderCellStyle"
                :cell-class-name="tableRowClassName2" :summary-method="getSummaries" show-summary>
                <el-table-column type="index" label="NO" fixed="left" align="center"></el-table-column>
                <el-table-column type="selection" width="45" fixed="left" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="anlyItemNo"
                  label="分析项目编号" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="anlyItemName"
                  label="分析项目" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="minSign" label="下限符"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="minValue" label="最小值"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="maxSign" label="上限符"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="maxValue" label="最大值"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="memo" label="备注"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="createMan" label="创建人"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间"
                  align="center"></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <el-tab-pane label="接收电文" name="second">
            <div class="common-title-div" style="height: 75px; margin-top: 25px">
              <div class="common-title-name">
                <img style="width: 25px; height: 25px" src="../../../../assets/img/imgScreen/logo.png" />
                接收电文
              </div>
              <div></div>
            </div>
            <div class="common-table-div" style="margin-bottom: 0; margin-top: 0">
              <el-table v-loading="dataLoading3" ref="dataTable3" border :height="height_bot" highlight-current-row
                :data="table.list3" :icore-filter-flag="icoreFilterFlag" :header-cell-style="tableHeaderCellStyle"
                :cell-class-name="tableRowClassName2" :summary-method="getSummaries" show-summary>
                <el-table-column type="index" label="NO" fixed="left" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="400px" prop="msgSource" label="电文内容"
                  align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="createDate" label="创建时间"
                  align="center"></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <el-tab-pane label="发送电文" name="three">
            <div class="common-title-div" style="height: 75px; margin-top: 25px">
              <div class="common-title-name">
                <img style="width: 25px; height: 25px" src="../../../../assets/img/imgScreen/logo.png" />
                发送电文
              </div>
              <div></div>
            </div>
            <div class="common-table-div" style="margin-bottom: 0; margin-top: 0">
              <el-table v-loading="dataLoading4" ref="dataTable2" border :height="height_bot" highlight-current-row
                :data="table.list4" :icore-filter-flag="icoreFilterFlag" :header-cell-style="tableHeaderCellStyle"
                :cell-class-name="tableRowClassName2" :summary-method="getSummaries" show-summary>
                <el-table-column type="index" label="NO" fixed="left" align="center"></el-table-column>
                <el-table-column sortable :show-overflow-tooltip="true" min-width="600px" prop="msgSource" label="电文内容"
                  align="center"></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh="refresh"></div>
    <div is="alertComponets2" :showFlag2="showFlag2" :Params="Params" :Params2="Params2" @refresh="refresh2"></div>
    <div is="alertComponets3" :showFlag="showFlag3" :Params="Params3" @refresh="refresh3"></div>
    <el-dialog @close="closeDialog" :visible.sync="dialogTableCount" width="80%">
      <el-table id="excelTable3" ref="dataTable3" border :data="tableCount">
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="MAT_NAME" label="物料编号"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="COUNT" label="个数"
          align="center"></el-table-column>
      </el-table>
    </el-dialog>
    <div id="printContainer2" style="margin-left: 20px; margin-top: 3px" v-show="false">
      <div id="printContent">
        <div v-for="item in printData" :key="item.id" style="width: 439px; border: 1px solid #fff; position: relative">
          <div>
            <div v-for="subItem in item.list" :key="subItem.id" style="font-size: 15px">
              {{ subItem.fieldKeyName }}：{{ subItem.fieldValue }}
            </div>
            <div :id="`Qrcode${item.id}`" style="margin-top: 20px"></div>
            <div v-if="printData.length > 1" style="page-break-after: always"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- 二维码编辑 -->
    <el-dialog title="二维码信息详情" :visible.sync="isShowQrCodeInfo" width="70%">
      <el-button type="goon" size="mini" @click="addQrCodeInfo" style="margin-bottom: 10px">新增</el-button>
      <el-button type="goon" size="mini" @click="resetQrCodeInfo" style="margin-bottom: 10px">重置</el-button>
      <el-table ref="qrCodeInfoTable" :data="qrCodeInfoData" stripe border tooltip-effect="dark" height="500"
        @selection-change="handleQrCodeInfoSelectionChange">
        <el-table-column type="selection" width="55" align="center">
        </el-table-column>
        <el-table-column label="字段名" align="center" prop="fieldKeyName">
        </el-table-column>
        <el-table-column prop="fieldValue" label="字段值" align="center">
        </el-table-column>
        <el-table-column label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button @click="editQrCodeInfoRow(scope.$index, scope.row)" type="text" size="small">
              编辑
            </el-button>
            <el-button v-if="scope.row.fieldKey != 'sampleNo'" @click="delQrCodeInfoRow(scope.$index, scope.row)"
              type="text" size="small">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <div style="
            display: flex;
            align-items: center;
            justify-content: space-between;
          ">
          <div>
            <el-pagination @size-change="pageSizeChange3" @current-change="pageCurrentChange3"
              :current-page="page3.pageNum" :page-sizes="[10, 20, 30, 50, 100]" :page-size="page3.pageSize"
              layout="total, sizes, prev, pager, next, jumper" :total="page3.totalPage" background>
            </el-pagination>
          </div>
          <div>
            <el-button size="mini" @click="isShowQrCodeInfo = false">取消</el-button>
            <el-button size="mini" icon="el-icon-printer" type="primary" @click="saveQRCode">保存</el-button>
            <el-button size="mini" icon="el-icon-printer" type="primary" @click="saveAndPrintQRCode">保存打印二维码</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
    <!-- 新增二维码字段 -->
    <el-dialog title="新增二维码字段信息" :visible.sync="isShowAddQrCodeInfo" width="30%">
      <el-form :model="addQrCodeInfoForm">
        <el-form-item label="字段名">
          <el-input v-model="addQrCodeInfoForm.fieldKeyName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="字段值">
          <el-input v-model="addQrCodeInfoForm.fieldValue" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isShowAddQrCodeInfo = false">取消</el-button>
        <el-button size="mini" type="primary" @click="confirmAddQrCodeInfo">确定</el-button>
      </div>
    </el-dialog>
    <!-- 编辑二维码字段 -->
    <el-dialog title="编辑二维码字段信息" :visible.sync="isShowEditQrCodeInfo" width="30%">
      <el-form :model="editQrCodeInfoForm">
        <el-form-item label="字段名">
          <el-input v-model="editQrCodeInfoForm.fieldKeyName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="字段值">
          <el-input v-model="editQrCodeInfoForm.fieldValue" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isShowEditQrCodeInfo = false">取消</el-button>
        <el-button size="mini" type="primary" @click="confirmEditQrCodeInfo">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getCookie, formatDate } from "@/utils/util.js";
import { cookieUserId, cookieUserName } from "@/config/config.js";
import alertComponets from "./alertComponents";
import alertComponets2 from "./alertComponents2";
import alertComponets3 from "./alertComponents3";
import JsBarcode from "jsbarcode";
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: { alertComponets, alertComponets2, alertComponets3 },
  data() {
    return {
      table: {
        list: [],
        list1: [],
        list2: [],
        list3: [],
        list4: [],
      },
      activeName: "first",
      activeName2: "first",
      dataLoading: false,
      invalidLoading: false,
      dataLoading2: false,
      dataLoading3: false,
      dataLoading4: false,
      subLoading: false,
      subLoading1: false,
      subLoading2: false,
      subLoading3: false,
      subLoadingq: false,
      icoreFilterFlag: true,
      values: "",
      inputLoading: false,
      timeId: null,
      page: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0,
      },
      page3: {
        pageSize: 10,
        pageNum: 1,
        totalPage: 0,
      },
      saveRow: {},
      savaDep: {},
      list: [],
      entrId: "",
      showFlag: false,
      showFlag3: false,
      Params3: {},
      Params: {},
      showFlag2: false,
      Params2: {},
      entrOrgNameType: [],
      entrOrgNameType1: [],
      selectDataList: [],
      sampleTypeNameType: [],
      multipleSelection3: [],
      multipleSelection4: [],
      tableCount: [],
      dialogTableCount: false,
      search: {
        batchNo: "",
        entrTime: "",
        times: [],
        planCompanyName: "",
        matName: "",
        carNo:"",
        sampleNo:""
        
      },
      height_top: 0,
      height_bot: 0,
      activeMenu: "",
      piciIndex: "",
      printData: [],
      printLoading: false,
      exportFileLoading: false,
      // editRow: {},
      selectRows: [],
      selectRow1s: [],
      subLoading8: false,

      isShowQrCodeInfo: false,
      qrCodeInfoData: [],
      isShowAddQrCodeInfo: false,
      addQrCodeInfoForm: {},
      isShowEditQrCodeInfo: false,
      editQrCodeInfoForm: {},
      editQrCodeInfoIndex: 0,
      deleteIds: [],
      isSetDefault: false,
    };
  },
  created() {
    this.height_top = window.innerHeight - 200;
    this.height_bot = window.innerHeight - 200;
    this.search.times = [this.getYNM(new Date()), this.getYNM(new Date())];
    this.activeMenu = window.top.localStorage.getItem("activeMenu");
  },
  mounted() {
    this.axios
    
      .post(
        "pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll",
        {},
        { individualType: "json" }
      )
      .then((response) => {
        this.entrOrgNameType = response.data;
      });
    this.searchData();
    this.addScreen();
    this.addScreen2();
  },
  methods: {
    getYNM(date) {
      let year = date.getFullYear().toString();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      return `${year}-${month}-${day}`;
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
        }
        if (index === 1) {
          sums[index] = data.length;
        }
      });
      return sums;
    },
    refresh() {
      this.mainData();
    },
    refresh2() {
      this.depData(this.entrId);
    },
    refresh3() {
      this.mainData();
    },
    saveDataMain(row) {
      this.piciIndex = row.id;
      this.saveRow = Object.assign({}, row);
    },
    addData() {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    modifyData() {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning("请点击选中一条您要修改的数据");
        return;
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning("数据已提交，不可进行修改");
        return;
      }
      this.Params3 = this.saveRow;
      this.showFlag3 = !this.showFlag3;
    },
    update() {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning("请点击选中一条您要提交的数据");
        return;
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning("请选择编辑状态！");
        return;
      }
      let index = this.table.list.findIndex((arr) => arr.id == this.piciIndex);
      let arr = this.table.list[index];
      this.subLoading2 = true;
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/updateEntrustBatchNo",
          arr,
          { individualType: "json" }
        )
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.$message.success(res.message);
            this.mainData();
          } else {
            this.$message.error(res.message);
          }
          this.subLoading2 = false;
        })
        .catch((e) => {
          this.subLoading2 = false;
          this.$message.error(e.message);
        });
    },
    //清除中心编号的生成规则的记录
    removeNumber() {
      this.subLoadingq = true;
      this.axios
        .post("pass/testManagement/v1/api/reflection/removeMapPkALL")
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.subLoadingq = false;
            this.$message.success(res.message);
          } else {
            this.subLoadingq = false;
            this.$message.error(res.message);
          }
        });
    },
    updateSampleNo() {
      if (this.selectRows.length == 0) {
        return this.$message.warning("请至少勾选一条您要修改的数据!");
      }
      this.subLoading8 = true;
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/saveLimsTestEntrustList",
          this.selectRows,
          { individualType: "json" }
        )
        .then((res) => {
          if (res.succeed) {
            this.subLoading8 = false;
            this.$message.success("修改成功");
            this.searchData();
          } else {
            this.subLoading8 = false;
            this.$message.error(res.message);
          }
        })
        .catch((e) => {
          this.subLoading8 = false;
          this.$message.error(e.message);
        });
    }, //扫码提交
    autoSubmit() {
      if (!this.values) {
        this.$message.warning("请先用扫码枪扫描标签");
        return;
      }
      if (!this.timeId) {
        this.timeId = setTimeout(() => {
          this.inputLoading = true;
          this.axios
            .post(
              "pass/testManagement/v1/limstestentrusts/scanningSubmit",
              { carNo: this.values },
              { individualType: "json" }
            )
            .then((res) => {
              if (res.code == 0 || res.code == 200) {
                this.$nextTick(() => {
                  this.$refs.autoInput.focus();
                });
                this.values = "";
                this.inputLoading = false;
                this.$message.success("操作成功！");
                this.mainData();
              } else {
                this.$nextTick(() => {
                  this.$refs.autoInput.focus();
                });
                this.values = "";
                this.inputLoading = false;
                this.$message.error(res.message);
              }
            })
            .catch((e) => {
              this.$nextTick(() => {
                this.$refs.autoInput.focus();
              });
              this.values = "";
              this.inputLoading = false;
              this.$message.error(e.message);
            });
          this.timeId = null;
        }, 1000);
      }
    },
    exportFile() {
      if (this.selectRows.length == 0) {
        this.$message.warning("请勾选您要导出的一条数据!");
        return;
      }
      this.exportFileLoading = true;
      let str = [];
      this.selectRows.forEach((s) => {
        str.push(s.entrId);
      });
      this.axios
        .get(
          "pass/testManagement/v1/limstestentrusts/newJywts/" + str,
          { responseType: "blob" },
          { headers: { "content-type": "application/x-www-form-urlencoded" } }
        )
        .then((res) => {
          let blob = new Blob([res]);
          let elink = document.createElement("a");
          elink.download = "BBWXCLJC-4-08-03.docx";
          elink.style.display = "none";
          elink.target = "_blank";
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL对象
          document.body.removeChild(elink);
          this.exportFileLoading = false;
        })
        .catch((e) => {
          this.exportFileLoading = false;
          return this.$message.error(e.message);
        });
    },
    // 打印二维码
    // printQRCode() {
    //   if (this.selectRows.length == 0) {
    //     this.$message.warning("请勾选您要打印的数据");
    //     return;
    //   }
    //   let flag = this.selectRows.some((u) => u.stateFlag != 1);
    //   if (flag) {
    //     return this.$message.warning(
    //       "未提交数据不允许进行打印，请重新进行勾选"
    //     );
    //   }
    //   let entrIds = [];
    //   this.selectRows.forEach((p) => {
    //     entrIds.push(p.entrId);
    //   });
    //   this.axios
    //     .post(
    //       "pass/testManagement/v1/limssampleinfos/queryLimsSampleInfosPage",
    //       { object: { entrIds }, pageIndex: 1, pageSize: 200 },
    //       { individualType: "json" }
    //     )
    //     .then((res) => {
    //       if (res.code == 0 || res.code == 200) {
    //         this.$message.success(res.message);
    //         this.printData = res.data.list;
    //         this.printData.forEach((item) => {
    //           item.carNo = this.saveRow.carNo;
    //         });
    //         this.runPrint(this.printData);
    //         this.searchData();
    //       } else {
    //         this.$message.error(res.message);
    //       }
    //     });
    // },
    // runPrint(arr) {
    //   console.log("arr", arr);
    //   setTimeout(() => {
    //     arr.forEach((item) => {
    //       const qrcode = document.getElementById(`Qrcode${item.id}`);
    //       qrcode.innerHTML = "";
    //       new QRCode(qrcode, {
    //         text: item.sampleNo,
    //         width: 100,
    //         height: 100,
    //         colorDark: "#000000",
    //         colorLight: "#ffffff",
    //       });
    //     });
    //     setTimeout(() => {
    //       this.printPage("printContent");
    //     }, 1500);
    //   }, 100);
    // },

    // 打印条形码
    async printQRCode() {
      if (this.selectRows.length == 0) {
        this.$message.warning("请勾选您要打印的数据");
        return;
      }
      let flag = this.selectRows.some((u) => u.stateFlag != 1);
      if (flag) {
        return this.$message.warning(
          "未提交数据不允许进行打印，请重新进行勾选"
        );
      }
      let entrIds = [];
      this.selectRows.forEach((p) => {
        entrIds.push(p.entrId);
      });

      const list0 = [];
      entrIds.forEach((item) => {
        list0.push(this.initQrCode(item));
      });

      await Promise.all(list0);

      const list = [];
      entrIds.forEach((item) => {
        list.push(this.getQrCodeInfoListById(item));
      });

      Promise.all(list).then((res) => {
        this.printData = res.map((item, index) => {
          if (item.code == 0 || item.code == 200) {
            return {
              id: entrIds[index],
              list: item.data.list.filter((subItem) => subItem.isCheck === 1),
            };
          } else {
            return {
              id: entrIds[index],
              list: [],
            };
          }
        });
        console.log("this.printData");
        console.log(this.printData);
        this.runPrint(this.printData);
      });
    },
    runPrint(arr) {
      setTimeout(() => {
        arr.forEach((item) => {
          const qrcode = document.getElementById(`Qrcode${item.id}`);
          qrcode.innerHTML = "";

          let sampleNo = "";
          for (let i = 0; i < item.list.length; i++) {
            if (item.list[i].fieldKey === "sampleNo") {
              sampleNo = item.list[i].fieldValue;
              break;
            }
          }
          new QRCode(qrcode, {
            text: sampleNo,
            width: 100,
            height: 100,
            colorDark: "#000000",
            colorLight: "#ffffff",
          });
        });
        setTimeout(() => {
          this.printPage("printContent");
        }, 1500);
      }, 100);
    },
    getpici() {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning("请点击选中一条您要提交的数据");
        return;
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning("请选择编辑状态！");
        return;
      }
      this.subLoading1 = true;
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/getNextBacthNoToRule",
          this.saveRow,
          { individualType: "json" }
        )
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            let index = this.table.list.findIndex(
              (arr) => arr.id == this.piciIndex
            );
            if (res.data != null) {
              this.table.list[index].batchNo = res.data;
            }
            this.saveRow.batchNo = res.data;
          } else {
            this.$message.error(res.message);
          }
          this.subLoading1 = false;
        })
        .catch((e) => {
          this.subLoading1 = false;
          this.$message.error(e.message);
        });
    },
    async submitData() {
      if (this.selectRows.length == 0) {
        return this.$message.warning("请至少勾选一条数据进行提交!");
      }
      let ids = [];
      for (let i = 0; i < this.selectRows.length; i++) {
        let item = this.selectRows[i];
        if (item.stateFlag === "1") {
          return this.$message.warning(
            "委托编号为[" + item.id + "]的数据已经提交，无法再次进行提交!"
          );
        }
        if (item.validFlag === "1") {
          ids.push(item.id);
        }
      }
      this.subLoading = true;
      for (let i = 0; i < this.selectRows.length; i++) {
        let item = this.selectRows[i];
        const str = await this.axios.post(
          "pass/testManagement/v1/limstestentrusts/saveLimsTestEntrust",
          item,
          { individualType: "json" }
        );
        if (str.succeed) {
          const str1 = await this.axios.post(
            "pass/testManagement/v1/limstestentrusts/submit",
            [item.entrId],
            { individualType: "json" }
          );
          if (str1.code == 0 || str1.code == 200) {
            this.$message.success(str1.message);
          } else {
            this.$message.error(str1.message);
          }
        } else {
          this.$message.error(str.message);
        }
      }
      this.subLoading = false;
      this.refresh();
    },
    selectData(val) {
      this.selectDataList = val;
    },
    saveData(row) {
      this.savaDep = Object.assign({}, row);
    },
    addData2() {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning("请点击选中一条检验委托信息数据");
        return;
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning("数据已提交，不可进行新增");
        return;
      }
      this.showFlag2 = !this.showFlag2;
      this.Params2 = null;
      this.Params = this.saveRow;
    },
    enable() {
      //启用
      if (this.selectRow1s.length < 1) {
        this.$message.warning("请至少勾选一条您要启用的数据");
        return;
      }
      // if (this.saveRow.validFlag != 0) {
      //   this.$message.warning('数据未停用，不可启用！')
      //   return
      // }
      let ids = [];
      for (let i = 0; i < this.selectRow1s.length; i++) {
        let item = this.selectRow1s[i];
        if (item.validFlag === "1") {
          return this.$message.warning(
            "委托编号为[" + item.id + "]的数据为启用状态，无法进行启用!"
          );
        }
        if (item.validFlag === "0") {
          ids.push(item.id);
        }
      }
      this.subLoadingq = true;
      this.axios
        .post("pass/testManagement/v1/limstestentrusts/enable", ids, {
          individualType: "json",
        })
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.mainData();
            this.mainData1();
            this.subLoadingq = false;
            this.$message.success(res.message);
          } else {
            this.subLoadingq = false;
            this.$message.error(res.message);
          }
        })
        .catch((e) => {
          this.subLoadingq = false;
          this.$message.error(e.message);
        });
    },
    disable() {
      //停用
      if (this.selectRows.length < 1) {
        this.$message.warning("请至少勾选一条您要停用的数据");
        return;
      }
      let ids = [];
      for (let i = 0; i < this.selectRows.length; i++) {
        let item = this.selectRows[i];
        if (item.validFlag === "0") {
          return this.$message.warning(
            "委托编号为[" + item.id + "]的数据为停用状态，无法进行停用!"
          );
        }
        if (item.validFlag === "1") {
          ids.push(item.id);
        }
      }
      this.subLoading = true;
      this.axios
        .post("pass/testManagement/v1/limstestentrusts/disable", ids, {
          individualType: "json",
        })
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.$message.success(res.message);
            this.mainData();
            this.mainData1();
            this.subLoading = false;
          } else {
            this.subLoading = false;
            this.$message.error(res.message);
          }
        })
        .catch((e) => {
          this.subLoading = false;
          this.$message.error(e.message);
        });
    },
    cancelData() {
      //取消提交
      if (this.selectRows.length < 1) {
        this.$message.warning("请至少勾选一条您要取消提交的数据");
        return;
      }
      // if (this.saveRow.stateFlag != 1) {
      //   this.$message.warning('数据不是提交状态，不可取消提交！')
      //   return
      // }
      let ids = [];
      for (let i = 0; i < this.selectRows.length; i++) {
        let item = this.selectRows[i];
        if (item.stateFlag === "0") {
          return this.$message.warning(
            "委托编号为[" + item.id + "]的数据为编辑状态，无法进行取消提交!"
          );
        }
        if (item.validFlag === "1") {
          ids.push(item.id);
        }
      }
      this.subLoading = true;
      this.axios
        .post("pass/testManagement/v1/limstestentrusts/cancel", ids, {
          individualType: "json",
        })
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.$message.success(res.message);
            this.removeNumber();
            this.mainData();
            this.mainData1();
            this.subLoading = false;
          } else {
            this.$message.error(res.message);
          }
          this.subLoading = false;
        })
        .catch((e) => {
          this.subLoading = false;
          this.$message.error(e.message);
        });
    },
    deleteData2() {
      if (this.selectDataList.length == 0) {
        this.$message.warning("请选中计划检验项目信息数据！");
        return;
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning("数据已提交，不可进行删除");
        return;
      }
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          for (let i = 0; i < this.selectDataList.length; i++) {
            this.axios
              .post(
                "pass/testManagement/v1/limstestentrustds/deleteLimsTestEntrustD?id=" +
                this.selectDataList[i].id,
                { individualType: "json" }
              )
              .then((res) => {
                if (res.succeed) {
                  this.dialogTableVisible = false;
                  this.$message.success("删除成功");
                  this.depData(this.entrId);
                } else {
                  this.$message.error(res.message);
                }
              })
              .catch((e) => {
                this.$message.error(e.message);
              });
          }
        })
        .catch(() => { });
    },
    searchData() {
      this.page.pageNum = 1;
      this.page.pageSize = 200;
      this.mainData();
      this.mainData1();
    },
    closeDialog() {
      this.dialogTableCount = false;
      this.tableCount = [];
    },
    countList() {
      let startTime = "";
      let endTime = "";
      if (!this.search.times) {
        startTime = "";
        endTime = "";
      } else {
        startTime =
          formatDate(this.search.times[0], "yyyy-MM-dd") + " 00:00:00";
        endTime = formatDate(this.search.times[1], "yyyy-MM-dd") + " 23:59:59";
      }
      let obj = {
        object: {
          entrOrgNo: this.search.planCompanyNo, // 委托单位
          sampleTypeCode: 480103,
          matName: this.search.matName,
          batchNo: this.search.batchNo,
          validFlag: "1",
          stateFlag: "1",
        },
        startTime: startTime,
        endTime: endTime,
      };
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/queryLimsTestEntrustCount",
          obj,
          { individualType: "json" }
        )
        .then((res) => {
          this.tableCount = res.data;
          this.dialogTableCount = true;
        })
        .catch((e) => {
          this.$message.error("查询错误!");
        });
    },
    mainData() {
      (this.saveRow = {}), (this.dataLoading = true);
      let startTime = "";
      let endTime = "";
      if (!this.search.times) {
        startTime = "";
        endTime = "";
      } else {
        startTime =
          formatDate(this.search.times[0], "yyyy-MM-dd") + " 00:00:00";
        endTime = formatDate(this.search.times[1], "yyyy-MM-dd") + " 23:59:59";
      }
      let tempobj = {
        object: {
          sampleTypeCode: "480103",
          isBatch: "",
          entrOrgNo: this.search.planCompanyNo, // 委托单位
          matName: this.search.matName,
          batchNo: this.search.batchNo,
          carNo: this.search.carNo,
          validFlag: "1",
        },
        sampleNo: this.search.sampleNo,
        pageIndex: this.page.pageNum,
        pageSize: this.page.pageSize,
        startTime: startTime,
        endTime: endTime,
      };
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/queryLimsTestEntrustPage/",
          tempobj,
          { individualType: "json" }
        )
        .then((res) => {
          this.dataLoading = false;
          this.table.list = res.data.list;
          if (this.table.list.length > 0) {
            this.$refs.dataTable.setCurrentRow(this.table.list[0]);
            this.searchFollow(this.table.list[0]);
          }
          this.table.list.forEach((item) => {
            item.stateFlag1 =
              item.validFlag == "0"
                ? "已停用"
                : item.stateFlag === "0"
                  ? "编辑"
                  : item.stateFlag === "1"
                    ? "提交"
                    : "";
            item.entrTime1 = formatDate(item.entrTime, "yyyy-MM-dd");
          });
          this.page.totalPage = res.data.total;
        })
        .catch((e) => {
          this.dataLoading = false;
        });
    },
    mainData1() {
      (this.saveRow = {}), (this.invalidLoading = true);
      let startTime = "";
      let endTime = "";
      if (!this.search.times) {
        startTime = "";
        endTime = "";
      } else {
        startTime =
          formatDate(this.search.times[0], "yyyy-MM-dd") + " 00:00:00";
        endTime = formatDate(this.search.times[1], "yyyy-MM-dd") + " 23:59:59";
      }
      let tempobj = {
        object: {
          sampleTypeCode: "480103",
          isBatch: "",
          entrOrgNo: this.search.planCompanyNo, // 委托单位
          matName: this.search.matName,
          batchNo: this.search.batchNo,
          carNo: this.search.carNo,
          validFlag: "0",
        },
        sampleNo: this.search.sampleNo,
        pageIndex: this.page.pageNum,
        pageSize: this.page.pageSize,
        startTime: startTime,
        endTime: endTime,
      };
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/queryLimsTestEntrustPage/",
          tempobj,
          { individualType: "json" }
        )
        .then((res) => {
          this.invalidLoading = false;
          this.table.list1 = res.data.list;
          this.table.list1.forEach((item) => {
            item.stateFlag1 =
              item.validFlag == "0"
                ? "已停用"
                : item.stateFlag === "0"
                  ? "编辑"
                  : item.stateFlag === "1"
                    ? "提交"
                    : "";
            item.entrTime1 = formatDate(item.entrTime, "yyyy-MM-dd");
          });
        })
        .catch((e) => {
          this.invalidLoading = false;
        });
    },
    searchFollow(row) {
      this.saveRow = Object.assign({}, row);
      // this.editRow = row
      this.entrId = row.entrId ? row.entrId : "";
      this.depData(this.entrId);
      this.getRevMsg(this.entrId);
      this.getSendMsg(this.entrId);
    },
    selectRow(val) {
      this.selectRows = val;
    },
    selectRow1(val) {
      this.selectRow1s = val;
    },
    getRevMsg(entrId) {
      if (!entrId) {
        return this.$message.warning("获取接收电文参数错误! entrId为空!");
      }
      this.dataLoading3 = true;
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/queryMsgByEntrId",
          { object: { entrId: entrId }, pageIndex: 1, pageSize: 999 },
          { individualType: "json" }
        )
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.dataLoading3 = false;
            this.table.list3 = res.data.list;
          } else {
            this.dataLoading3 = false;
            return this.$message.warning(res.message);
          }
        })
        .catch((e) => {
          this.dataLoading3 = false;
          return this.$message.error(e.message);
        });
    },
    getSendMsg(entrId) {
      if (!entrId) {
        return this.$message.warning("获取发送电文参数错误! entrId为空!");
      }
      this.dataLoading4 = true;
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrusts/queryMsgByEntrIdAndSampleNo",
          { object: { entrId: entrId }, pageIndex: 1, pageSize: 999 },
          { individualType: "json" }
        )
        .then((res) => {
          if (res.code == 0 || res.code == 200) {
            this.dataLoading4 = false;
            this.table.list4 = res.data.list;
          } else {
            this.dataLoading4 = false;
            return this.$message.warning(res.message);
          }
        })
        .catch((e) => {
          this.dataLoading4 = false;
          return this.$message.error(e.message);
        });
    },
    depData(entrId) {
      (this.savaDep = {}), (this.dataLoading2 = true);
      this.axios
        .post(
          "pass/testManagement/v1/limstestentrustds/queryLimsTestEntrustDPage",
          { object: { entrId: entrId }, pageIndex: 1, pageSize: 999 },
          { individualType: "json" }
        )
        .then((res) => {
          this.dataLoading2 = false;
          this.table.list2 = res.data.list;
          this.table.list2.forEach((item) => {
            item.stateFlag1 =
              item.stateFlag === "0"
                ? "编辑"
                : item.stateFlag === "1"
                  ? "提交"
                  : "";
            item.entrTime1 = formatDate(item.entrTime, "yyyy-MM-dd");
          });
        })
        .catch((e) => {
          this.dataLoading2 = false;
        });
    },
    reset() {
      this.search.times = [this.getYNM(new Date()), this.getYNM(new Date())];
      this.search.planCompanyNo = "";
      this.search.matName = "";
      this.searchData();
    },
    handleSelectionChange(val) {
      this.multipleSelection3 = val;
    },
    pageSizeChange(size) {
      this.page.pageSize = size;
      this.mainData();
    },
    pageCurrentChange(index) {
      this.page.pageNum = index;
      this.mainData();
    },
    async pageSizeChange3(size) {
      this.page3.pageSize = size;
      await this.getQrCodeInfoListAndSetDefault();
    },
    async pageCurrentChange3(index) {
      this.page3.pageNum = index;
      await this.getQrCodeInfoListAndSetDefault();
    },
    handleSelectionChange2(val) {
      this.multipleSelection4 = val;
    },
    addScreen() {
      this.$nextTick(() => {
        let ss = document.createElement("div");
        ss.innerHTML = "筛选";
        ss.style = "text-align: center;";
        this.$refs.dataTable.$el
          .getElementsByClassName("el-table__fixed")[0]
          .getElementsByTagName("td")[0]
          .appendChild(ss);
      });
    },
    addScreen2() {
      this.$nextTick(() => {
        let ss = document.createElement("div");
        ss.innerHTML = "筛选";
        ss.style = "text-align: center;";
        this.$refs.dataTable2.$el
          .getElementsByClassName("el-table__fixed")[0]
          .getElementsByTagName("td")[0]
          .appendChild(ss);
      });
    },
    tableRowClassName({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 13) {
        if (row.validFlag !== "1") {
          return "error-row";
        }
      }
      if (columnIndex === 2) {
        if (row.validFlag !== "1") {
          return "error-row";
        }
        if (row.stateFlag === "1") {
          return "error-green";
        }
        return "";
      }
    },
    tableRowClassName2({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 5) {
        if (row.validFlag !== "1") {
          return "error-row";
        }
        return "";
      }
    },
    tableHeaderCellStyle() {
      return "color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;";
    },

    // 1 显示编辑二维码弹窗
    async showQRCodeInfo() {
      if (this.selectRows.length === 0) {
        this.$message.warning("请勾选您要编辑二维码的数据");
        return;
      }
      if (this.selectRows.length > 1) {
        this.$message.warning("一次只能编辑一个二维码");
        return;
      }
      let flag = this.selectRows.some((u) => u.stateFlag != 1);
      if (flag) {
        return this.$message.warning(
          "未提交数据不允许进行打印，请重新进行勾选"
        );
      }
      this.isShowQrCodeInfo = true;

      let entrIds = [];
      this.selectRows.forEach((p) => {
        entrIds.push(p.entrId);
      });
      // 2 初始化二维码信息
      await this.initQrCode(this.selectRows[0].id);
      // 3 获取二维码信息
      await this.getQrCodeInfoListAndSetDefault();
    },
    // 初始化二维码信息
    async initQrCode(id) {
      await this.axios.get(
        "pass/testManagement/v1/limssampleprints/initData/" + id,
        {
          params: {
            dataType: 1,
            isReset: 0,
          },
        },
        { individualType: "json" }
      );
    },
    // 获取二维码信息
    async getQrCodeInfoList() {
      const res = await this.axios.get(
        "pass/testManagement/v1/limssampleprints/",
        {
          params: {
            pageNum: this.page3.pageNum,
            pageSize: this.page3.pageSize,
            dataSourceId: this.selectRows[0].id,
            isDelete: 0,
          },
        },
        { individualType: "json" }
      );
      if (res.code == 0 || res.code == 200) {
        this.qrCodeInfoData = res.data.list || [];
        this.page3.totalPage = res.data.total;
      } else {
        this.$message.error(res.message);
      }
      return res;
    },
    // 获取二维码信息
    async getQrCodeInfoListById(dataSourceId) {
      const res = await this.axios.get(
        "pass/testManagement/v1/limssampleprints/",
        {
          params: {
            pageNum: 1,
            pageSize: 999,
            dataSourceId,
          },
        },
        { individualType: "json" }
      );
      return res;
    },
    handleQrCodeInfoSelectionChange(val) {
      console.log("handleQrCodeInfoSelectionChange");
      console.log(this.qrCodeInfoData);
      // 初始化勾选期间不进行操作
      if (!this.isSetDefault) {
        this.qrCodeInfoData.forEach((item) => {
          item.isCheck = 0;
        });
        val.forEach((item) => {
          item.isCheck = 1;
        });
      }
    },
    // 打开新增弹窗
    addQrCodeInfo() {
      this.isShowAddQrCodeInfo = true;
    },
    // 设置默认选中
    setDefaultSelected() {
      console.log("setDefaultSelected");
      this.isSetDefault = true;
      this.qrCodeInfoData.forEach((item) => {
        if (item.isCheck === 1) {
          console.log(item);
          this.$refs.qrCodeInfoTable.toggleRowSelection(item, true);
        }
      });
      this.isSetDefault = false;
    },
    // 确认添加
    confirmAddQrCodeInfo() {
      this.qrCodeInfoData.push({
        ...this.addQrCodeInfoForm,
        fieldKey: Date.now(),
        dataSourceId: this.selectRows[0].id,
        isCheck: 0,
        isDelete: 0,
        dataSourceType: 1, // 0 原料 1 成品 2 临时
      });
      this.isShowAddQrCodeInfo = false;
    },
    // 打开编辑窗口
    editQrCodeInfoRow(index, row) {
      this.editQrCodeInfoForm = row;
      console.log("editQrCodeInfoRow");
      console.log(this.editQrCodeInfoForm);
      this.editQrCodeInfoIndex = index;
      this.isShowEditQrCodeInfo = true;
    },
    // 删除二维码字段
    delQrCodeInfoRow(index, row) {
      this.qrCodeInfoData.splice(index, 1);
      if (row.id) {
        this.deleteIds.push(row.id);
      }
    },
    // 确认编辑
    confirmEditQrCodeInfo() {
      this.$set(
        this.qrCodeInfoData,
        this.editQrCodeInfoIndex,
        this.editQrCodeInfoForm
      );
      this.isShowEditQrCodeInfo = false;
    },
    // 重置二维码信息
    resetQrCodeInfo() {
      this.$confirm("确定重置二维码信息吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        await this.axios.get(
          "pass/testManagement/v1/limssampleprints/initData/" +
          this.selectRows[0].id,
          {
            params: {
              dataType: 1,
              isReset: 1,
            },
          },
          { individualType: "json" }
        );
        // 获取二维码信息
        const res = await this.getQrCodeInfoListAndSetDefault();
        this.$message.success(res.message);
      });
    },
    // 保存二维码
    async saveQRCode() {
      console.log(this.qrCodeInfoData);
      // 批量删除
      const res = await this.axios.post(
        "pass/testManagement/v1/limssampleprints/batchDelete/",
        this.deleteIds,
        { individualType: "json" }
      );
      if (res.code == 0 || res.code == 200) {
        this.deleteIds = [];
      }
      // 批量更新
      const res2 = await this.axios.post(
        "pass/testManagement/v1/limssampleprints/batchUpdate/",
        this.qrCodeInfoData,
        { individualType: "json" }
      );
      if (res2.code == 0 || res2.code == 200) {
        this.$message.success(res2.message);
        await this.getQrCodeInfoListAndSetDefault();
        // this.isShowQrCodeInfo = false;
      }
    },
    async getQrCodeInfoListAndSetDefault() {
      this.isSetDefault = true;
      await this.getQrCodeInfoList();
      this.$nextTick(async () => {
        // 设置默认选中
        this.setDefaultSelected();
      });
    },
    // 保存并打印二维码
    async saveAndPrintQRCode() {
      await this.saveQRCode();
      this.printQRCode();
    },
  },
};
</script>
<style scoped></style>
