<template>
<!-- 制样室-留样 -->
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true">
        <el-form-item label="样品类型">
          <el-select
            v-model="search.sampleTypeCode"
            clearable
            filterable
            collapse-tags
            size="small"
            style="width: 150px"
            placeholder="请选择查询内容"
          >
            <el-option
              v-for="item in sampleTypeNameType"
              :key="item.baseCode"
              :label="item.baseName"
              :value="item.baseCode"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料名称">
          <el-input
            v-model="search.matName"
            @keyup.enter.native="searchData()"
            size="small"
            placeholder="请输入查询内容"
            style="width: 150px"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label='样品类型'>
          <el-select v-model="search.sampleTypeCode" clearable filterable collapse-tags size="small" style="width:150px;" placeholder="请选择查询内容">
            <el-option v-for="item in sampleTypeNameType" :key="item.baseCode" :label="item.baseName"
              :value="item.baseCode">
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="送样日期">
          <el-date-picker
            v-model="search.keepTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            size="small"
            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>
      </el-form>
    </div>
    <el-tabs type="border-card" v-model="activeName">
      <el-tab-pane label="待接" name="first">
        <span slot="label"
          >待接<el-badge
            :max="10"
            :hidden="page3.totalPage == 0"
            style="margin-top: -18px"
            :value="page3.totalPage"
          ></el-badge
        ></span>
        <div class="common-title-div">
          <div class="common-title-name">
            <img
              style="width: 25px; height: 25px"
              src="../../../../assets/img/imgScreen/logo.png"
            />
            待接信息
          </div>
          <div>
            <!-- <el-button icon="el-icon-check" type="goon" :loading='waitLoading' size="mini" @click="waiting">接收</el-button> -->
            <el-button
              icon="el-icon-check"
              type="goon"
              size="mini"
              v-privilege="activeMenu + 'keepSample'"
              @click="keepSampleData"
              >留样</el-button
            >
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom: 0">
          <el-table
            :data="table.list3"
            v-loading="dataLoading"
            ref="dataTable"
            border
            :height="height_top"
            @row-click="handleRow1"
            highlight-current-row
            :icore-filter-flag="icoreFilterFlag"
            :header-cell-style="tableHeaderCellStyle"
            :summary-method="getSummaries"
            show-summary
          >
            <el-table-column
              type="index"
              label="NO"
              align="center"
            ></el-table-column>
            <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="stateFlag1" label="状态" align="center"></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="120px"
              prop="matName"
              label="物料名称"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="140px"
              prop="sampleNo"
              label="样品号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="sampleNum"
              label="样品数量"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="sampleWgt"
              label="样品重量"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="sampleTypeName"
              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="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="pageSizeChange3"
            @current-change="pageCurrentChange3"
            :current-page="page3.pageNum"
            :page-sizes="[100, 200, 500, 800, 1000]"
            :page-size="page3.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page3.totalPage"
            background
          >
          </el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane label="样品留存" name="second">
        <span slot="label"
          >样品留存<el-badge
            :max="10"
            :hidden="page.totalPage == 0"
            style="margin-top: -18px"
            :value="page.totalPage"
          ></el-badge
        ></span>
        <div class="common-title-div">
          <div class="common-title-name">
            <img
              style="width: 25px; height: 25px"
              src="../../../../assets/img/imgScreen/logo.png"
            />
            样品留存信息
          </div>
          <div>
            <el-form :inline="true" @submit.native.prevent>
              <el-form-item>
                <el-button
                  icon="el-icon-remove-outline"
                  type="danger"
                  size="mini"
                  v-privilege="activeMenu + 'handle'"
                  @click="handleData"
                  >处置</el-button
                >
                <el-button
                  icon="el-icon-download"
                  type="goon"
                  size="mini"
                  :loading="tableExportLoading"
                  v-privilege="activeMenu + 'export'"
                  @click="doExport"
                  >导出</el-button
                >
              </el-form-item>
              <el-form-item prop="strNo" label="留样仓库">
                <el-cascader
                  size="small"
                  :options="options"
                  @change="handleChange"
                  change-on-select
                  :props="props"
                  v-model="selectedOptions"
                ></el-cascader>
                <!-- <el-select v-model="strNo" filterable style="width:100%" collapse-tags size="small">
                   <el-option v-for="(item,index) in trNameType" :key="index" :label="item.strName" :value="item.strNo">
                   </el-option>
                 </el-select> -->
              </el-form-item>
              <el-form-item label="扫码接样">
                <el-input
                  v-model="values"
                  ref="autoInput"
                  size="mini"
                  style="width：200px"
                  clearable
                  @input="autoSubmit()"
                  :disabled="inputLoading"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="common-table-div" id="mtable" style="margin-bottom: 0">
          <el-table
            id="excelTable"
            :data="table.list"
            v-loading="dataLoading"
            ref="dataTable"
            border
            :height="height_top"
            highlight-current-row
            @row-click="handleRow"
            :icore-filter-flag="icoreFilterFlag"
            :header-cell-style="tableHeaderCellStyle"
            :summary-method="getSummaries"
            show-summary
          >
            <el-table-column
              type="index"
              label="NO"
              align="center"
            ></el-table-column>
            <!-- <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="stateFlag1" label="状态" align="center"></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="140px"
              prop="expireTime"
              label="到期日期"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="120px"
              prop="matName"
              label="物料名称"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="140px"
              prop="sampleNo"
              label="样品号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="sampleNum"
              label="样品数量"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="sampleWgt"
              label="样品重量"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="sampleTypeName"
              label="样品类型"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="140px"
              prop="keepTime"
              label="留样时间"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="strName"
              label="留样仓库"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="strLocName"
              label="留样位置"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="keepNum"
              label="留样数量"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="keepNote"
              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="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="three">
        <span slot="label"
          >样品处置<el-badge
            :max="10"
            :hidden="page2.totalPage == 0"
            style="margin-top: -18px"
            :value="page2.totalPage"
          ></el-badge
        ></span>
        <div class="common-title-div">
          <div class="common-title-name">
            <img
              style="width: 25px; height: 25px"
              src="../../../../assets/img/imgScreen/logo.png"
            />
            样品处置信息
          </div>
          <div>
            <el-button
              icon="el-icon-remove-outline"
              type="danger"
              size="mini"
              :loading="cancelLoading"
              v-privilege="activeMenu + 'cancel'"
              @click="cancelData"
              >取消</el-button
            >
          </div>
        </div>
        <div class="common-table-div">
          <el-table
            v-loading="dataLoading2"
            ref="dataTable2"
            border
            :height="height_bot"
            highlight-current-row
            @selection-change="handleSelectionChange2"
            :data="table.list2"
            :icore-filter-flag="icoreFilterFlag"
            :header-cell-style="tableHeaderCellStyle"
            :summary-method="getSummaries"
            show-summary
          >
            <el-table-column
              type="index"
              label="NO"
              align="center"
            ></el-table-column>
            <el-table-column
              type="selection"
              width="55"
              align="center"
            ></el-table-column>
            <!-- <el-table-column sortable  :show-overflow-tooltip="true" min-width="80px" prop="stateFlag1" label="状态" align="center"></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="120px"
              prop="matName"
              label="物料"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="140px"
              prop="sampleNo"
              label="样品号"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="140px"
              prop="dealTime"
              label="处置时间"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="dealTypeName"
              label="处置类型"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="dealNum"
              label="处置数量"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="100px"
              prop="dealDesc"
              label="处置说明"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="dealMan"
              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="140px"
              prop="createTime"
              label="创建时间"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="updateMan"
              label="修改人"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="140px"
              prop="updateTime"
              label="修改时间"
              align="center"
            ></el-table-column>
          </el-table>
        </div>
        <div class="common-foot-style">
          <el-pagination
            @size-change="pageSizeChange2"
            @current-change="pageCurrentChange2"
            :current-page="page2.pageNum"
            :page-sizes="[100, 200, 500, 800, 1000]"
            :page-size="page2.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page2.totalPage"
            background
          >
          </el-pagination>
        </div>
      </el-tab-pane>
    </el-tabs>
    <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible">
      <div slot="title" class="titleBox">
        <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="margin-left: 10px; font-size: 18px">留样信息</span>
      </div>
      <el-form
        ref="baseData"
        label-width="80px"
        :rules="ruleValidate"
        :model="baseData"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item prop="matName" label="物料">
              <el-input
                v-model="baseData.matName"
                style="width: 100%"
                readonly
                disabled
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="strNo" label="留样仓库">
              <!-- <el-select
                v-model="baseData.strNo"
                filterable
                style="width: 100%"
                collapse-tags
                size="small"
              >
                <el-option
                  v-for="(item, index) in trNameType"
                  :key="index"
                  :label="item.strName"
                  :value="item.strNo"
                >
                </el-option>
              </el-select> -->
              <el-cascader
                size="small"
                :options="options"
                @change="selectChange"
                change-on-select
                :props="props"
                v-model="selectList"
              ></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item prop="expireTime" label="到期时间">
              <el-date-picker
                v-model="baseData.expireTime"
                type="date"
                placeholder="选择日期"
                size="small"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="留样位置">
              <el-input
                v-model="baseData.strLoc"
                style="width: 100%"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="留样数量">
              <el-input
                v-model="baseData.keepNum"
                style="width: 100%"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="留样原因">
              <el-input
                v-model="baseData.keepNote"
                style="width: 100%"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item prop="memo" label="备注">
              <el-input v-model="baseData.memo" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="goon"
          size="mini"
          icon="el-icon-check"
          :loading="sampleLoading"
          @click="modifyData()"
          >确定</el-button
        >
        <el-button
          size="mini"
          type="goon"
          icon="el-icon-remove-outline"
          @click="cancel"
          >取消</el-button
        >
      </span>
    </el-dialog>
    <el-dialog @close="closeDialog" :visible.sync="dialogTableVisible2">
      <div slot="title" class="titleBox">
        <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="margin-left: 10px; font-size: 18px">处置信息</span>
      </div>
      <el-form
        ref="formData"
        label-width="80px"
        :rules="ruleValidate2"
        :model="formData"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item prop="matName" label="物料">
              <el-input
                v-model="formData.matName"
                readonly
                disabled
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="dealTypeCode" label="处置类型">
              <el-select
                v-model="formData.dealTypeCode"
                filterable
                style="width: 100%"
                collapse-tags
                size="small"
              >
                <el-option
                  v-for="(item, index) in dealTypeData"
                  :key="index"
                  :label="item.baseName"
                  :value="item.baseCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item prop="dealDesc" label="处置说明">
              <el-input v-model="formData.dealDesc" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处置数量">
              <el-input v-model="formData.dealNum" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item prop="memo" label="备注">
              <el-input v-model="formData.memo" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button
          type="goon"
          size="mini"
          icon="el-icon-check"
          :loading="disposeLoading"
          @click="disposal()"
          >确定</el-button
        >
        <el-button
          size="mini"
          type="goon"
          icon="el-icon-remove-outline"
          @click="cancel"
          >取消</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getCookie,
  formatDate
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js'
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  data () {
    return {
      table: {
        list: [],
        list2: [],
        list3: []
      },
      props: {
        value: "strNo",
        label: "strName",
      },
      selectedOptions: [],
      options: [],
      isFixed: 'left',
      inputLoading: false,
      sampleLoading: false,
      disposeLoading: false,
      cancelLoading: false,
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      tableExportLoading: false,
      trNameType: [],
      saveRow: {},
      baseData: {},
      strNo: '',
      dialogTableVisible: false,
      ruleValidate: {
        strNo: [{ required: true, message: '该项不能为空', trigger: 'change' }],
        expireTime: [{ required: true, message: '该项不能为空', trigger: 'blur' }]
      },
      formData: {},
      dialogTableVisible2: false,
      dealTypeData: [],
      ruleValidate2: {
        dealTypeCode: [{ required: true, message: '该项不能为空', trigger: 'change' }],
        dealDesc: [{ required: true, message: '该项不能为空', trigger: 'blur' }]
      },
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      page3: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      list: [],
      planId: '',
      showFlag: false,
      Params: {},
      showFlag2: false,
      Params2: {},
      multipleSelection: [],
      sampleTypeNameType: [],
      sampleTypeNameType1: [],
      multipleSelection3: [],
      multipleSelection4: [],
      waitLoading: false,
      saveOneRow: {},
      search: {
        keepTime: '',
        sampleTypeCode: '480101',
        matName: '',
      },
      timeId: null,
      values: '',
      activeName: 'first',
      height_top: 0,
      height_bot: 0,
      activeMenu: '',
      waitRow: {},
      selectList: [],
      selectCode: '',
      selectName: ''
    }
  },
  created () {
    this.height_top = window.innerHeight - 220;
    this.height_bot = window.innerHeight - 240;
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
    this.search.keepTime = [this.getYNM(new Date()), this.getYNM(new Date())]
  },
  mounted () {
    this.axios.post('pass/baseManagement/v1/limsbasestorages/queryLimsBaseStorageTree').then(res => {
      res.data.forEach(item => {
        this.setNull(item)
      })
      this.options = res.data;
    })
    //留样库
    this.axios.post('pass/baseManagement/v1/limsbasestorages/queryLimsBaseStoragePage', { object: { strTypeCode: 483301, validFlag: 1 }, pageIndex: 1, pageSize: 9999 }, { individualType: 'json' }).then(res => {
      this.trNameType = res.data.list;
    })
    //处置类型 
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode", { validFlag: 1, baseCode: 4848 }, { individualType: 'json' }).then(res => {
      this.dealTypeData = res.data
    })
    //样品类型
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode", { validFlag: 1, baseCode: 4801 }, { individualType: 'json' }).then(res => {
      this.sampleTypeNameType = res.data
    })
    this.searchData();
    // this.addScreen();
    // this.addScreen2()
  },
  methods: {
    setNull (item) {
      if (item.children && item.children.length > 0) {
        item.children.forEach(inner => {
          this.setNull(inner)
        })
      } else {
        item.children = null
      }
    },
    // 弹窗仓库变化
    selectChange (list) {
      if (list.length > 0) {
        let selectCode = list[list.length - 1]
        this.baseData.strName = this.findName(this.options, selectCode);
        this.baseData.strNo = selectCode;
      }
    },
    findName (list, code) {
      let name = ''
      try {
        list.forEach(item => {
        if (item.strNo === code) {
          name = item.strName
          throw new Error(name)
        } else if (item.children) {
          name = this.findName(item.children, code)
          if (name !== '') {
            throw new Error(name)
          }
        }
      })
      } catch (e) {
        name = e.message
      }
      return name
    },
    getCode (code, arr, codeKey, nameKey) {
      if (!code) {
        return '';
      }
      let targetRow = arr.find(item => {
        return item[codeKey] === code;
      });
      return targetRow ? targetRow[nameKey] : '';
    },
    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;
    },
    autoSubmit (val) {
      if (this.selectedOptions.length === 0) {
        this.$message.warning('请先选择留样仓库！')
        this.values = ''
        return
      }
      if (!this.values) {
        this.$message.warning('请先用扫码枪扫描标签')
        return
      }
      let strNo = this.selectedOptions[this.selectedOptions.length - 1]
      let strName = this.findName(this.options, strNo);
      if (!this.timeId) {
        this.timeId = setTimeout(() => {
          this.inputLoading = true
          this.axios.post('pass/testManagement/v1/limssamplekeeps/saveLimsSampleKeep', { stateFlag: 2, strNo, strName, sampleNo: this.values,itemTypeCode : 484901 }, { individualType: 'json' }).then(res => {
            if (res.code == 0 || res.code == 200) {
              this.$message.success(res.message);
              this.searchData()
            } else {
              this.$message.error(res.message)
            }
            this.$nextTick(() => {
              this.$refs.autoInput.focus()
            })
            this.values = ''
            this.inputLoading = false
          }).catch(e => {
            this.$nextTick(() => {
              this.$refs.autoInput.focus()
            })
            this.values = ''
            this.inputLoading = false
          }).catch(e => {
            this.$nextTick(() => {
              this.$refs.autoInput.focus()
            })
            this.values = ''
            this.inputLoading = false
            this.$message.error(e.message)
          })
          this.timeId = null;
        }, 1000);
      }
    },
    handleChange () {
      console.log(111, '111');
      this.values = ''
    },
    //待接
    waiting () {
      if (this.multipleSelection.length < 1) {
        this.$message.warning('请勾选中您要留样的数据')
        return
      }
      let ids = []
      this.multipleSelection.forEach(item => {
        ids.push({ sampleNo: item.sampleNo, isAcpt: 1 })
      })
      this.waitLoading = true
      this.axios.post('pass/testManagement/v1/limssampleinfos/updateList', ids, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
        } else {
          this.$message.error(res.message)
        }
        this.waitLoading = false
      }).catch(e => {
        this.waitLoading = false
        this.$message.error(e.message)
      })
    },
    keepSampleData () {
      if (JSON.stringify(this.waitRow) === "{}") {
        this.$message.warning('请勾选中您要留样的数据')
        return
      }
      this.baseData = Object.assign({}, this.waitRow)
      this.dialogTableVisible = true
    },
    //留样确认
    modifyData () {
      this.$refs['baseData'].validate((valid) => {
        if (valid) {
          this.sampleLoading = true
          this.baseData.id = ''
          this.baseData.expireTime = formatDate(this.baseData.expireTime, "yyyy-MM-dd") + ' 23:59:59'
          this.baseData.strName = this.getCode(this.baseData.strNo, this.trNameType, 'strNo', 'strName')
          this.baseData.itemTypeCode = 484901
          this.baseData.stateFlag = 2
          this.axios.post('pass/testManagement/v1/limssamplekeeps/saveLimsSampleKeep', this.baseData, { individualType: 'json' }).then(res => {
            if (res.code == 0 || res.code == 200) {
              this.dialogTableVisible = false
              this.$message.success(res.message)
              this.searchData()
            } else {
              this.$message.error(res.message)
            }
            this.sampleLoading = false
          }).catch(e => {
            this.sampleLoading = false
            this.$message.error(e.message)
          })
        }
      })
    },
    //处置弹窗框
    handleData () {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请勾选中一条您要处置的数据')
        return
      }
      this.formData = Object.assign({}, this.saveRow)
      this.dialogTableVisible2 = true
    },
    //处置确认
    disposal () {
      this.$refs['formData'].validate((valid) => {
        if (valid) {
          this.disposeLoading = true
          this.formData.id = ''
          this.formData.dealTypeName = this.getCode(this.formData.dealTypeCode, this.dealTypeData, 'baseCode', 'baseName')
          this.formData.stateFlag = 4
          this.axios.post('pass/testManagement/v1/limssamplekeeps/disposal', this.formData, { individualType: 'json' }).then(res => {
            if (res.succeed) {
              this.dialogTableVisible2 = false
              this.$message.success(res.message)
              this.searchData()
            } else {
              this.$message.error(res.message)
            }
            this.disposeLoading = false
          }).catch(e => {
            this.disposeLoading = false
            this.$message.error(e.message)
          })
        }
      })
    },
    //取消弹窗
    cancel () {
      this.baseData = {}
      this.formData = {}
      this.sampleLoading = false
      this.disposeLoading = false
      this.dialogTableVisible = false
      this.dialogTableVisible2 = false
    },
    //关闭弹出窗
    closeDialog () {
      this.baseData = {}
      this.formData = {}
      this.sampleLoading = false
      this.disposeLoading = false
    },
    cancelData () {
      if (this.multipleSelection4.length < 1) {
        this.$message.warning('请勾选您要取消的数据！')
        return
      }
      let tempArr = []
      this.multipleSelection4.map(item => {
        tempArr.push(item.id)
      })
      this.cancelLoading = true
      this.axios.post('pass/testManagement/v1/limssamplekeeps/cancel', tempArr, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message);
          this.searchData()
        } else {
          this.$message.error(res.message)
        }
        this.cancelLoading = false
      }).catch(e => {
        this.cancelLoading = false
        this.$message.error(e.message)
      })
    },
    searchData () {
      this.page.pageNum = 1;
      this.page.pageSize = 100;
      this.page2.pageNum = 1;
      this.page2.pageSize = 100;
      this.page3.pageNum = 1;
      this.page3.pageSize = 100;
      this.mainData()
      this.leftmainData()
      this.getDataList2()
    },
    leftmainData () {
      this.saveOneRow = {}
      this.dataLoading = true;
      if (!this.search.keepTime) {
        this.startTime = null
        this.endTime = null
      } else {
        this.startTime = this.search.keepTime[0] + ' 00:00:00'
        this.endTime = this.search.keepTime[1] + ' 23:59:59'
      }
      let obj = {
        'object': {
          'matName': this.search.matName,
          'sampleTypeCode': '480101',
          stateFlag: 1,
          isAcpt: 0,
          // sampleNo:'',
          isKeep: 0
        },
        "pageSize": this.page3.pageSize,
        "pageIndex": this.page3.pageNum,
        'startTime': this.startTime,
        'endTime': this.endTime
      }
      this.axios.post('pass/testManagement/v1/limssampleinfos/queryLimsSampleInfosPage', obj, { individualType: 'json' }).then(res => {
        this.dataLoading = false;
        if (res.code == 0 || res.code == 200) {
          this.table.list3 = res.data.list;
          // this.table.list3.forEach(item =>{
          //   item.stateFlag1 = item.stateFlag === '0' ? '未留样' : item.stateFlag === '1' ? '已留样' : ''
          // })
          this.page3.totalPage = res.data.total;
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.dataLoading = false;
      });
    },
    mainData () {
      this.saveRow = {}
      this.dataLoading = true;
      if (!this.search.keepTime) {
        this.startTime = null
        this.endTime = null
      } else {
        this.startTime = this.search.keepTime[0] + ' 00:00:00'
        this.endTime = this.search.keepTime[1] + ' 23:59:59'
      }
      let obj = {
        'object': {
          'matName': this.search.matName,
          'sampleTypeCode': '480101',
          stateFlag: 2,
          // isAcpt: 1,
          isKeep: 0,
          'itemTypeCode':484901
        },
        "pageSize": this.page.pageSize,
        "pageIndex": this.page.pageNum,
        'startTime': this.startTime,
        'endTime': this.endTime
      }
      this.axios.post('pass/testManagement/v1/limssamplekeeps/queryLimsKeepsPage', obj, { individualType: 'json' }).then(res => {
        this.dataLoading = false;
        if (res.code == 0 || res.code == 200) {
          this.table.list = res.data.list;
          this.table.list.forEach(item => {
            item.strLocName = item.strLoc ? item.strLoc + '\xa0' : '' //导出成excel时，防止转换成日期格式
            item.stateFlag1 = item.stateFlag === '0' ? '未留样' : item.stateFlag === '1' ? '已留样' : ''
          })
          this.page.totalPage = res.data.total;
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.dataLoading = false;
      });
    },
    getDataList2 () {
      this.dataLoading2 = true;
      if (!this.search.keepTime) {
        this.startTime = null
        this.endTime = null
      } else {
        this.startTime = this.search.keepTime[0] + ' 00:00:00'
        this.endTime = this.search.keepTime[1] + ' 23:59:59'
      }
      let obj = {
        'object': {
          'matName': this.search.matName,
          'sampleTypeCode': '480101',
          stateFlag: 4,
          // isAcpt: 1,
          isKeep: 1,
          'itemTypeCode':484901
        },
        "pageSize": this.page.pageSize,
        "pageIndex": this.page.pageNum,
        'startTime': this.startTime,
        'endTime': this.endTime
      }
      this.axios.post('pass/testManagement/v1/limssamplekeeps/queryLimsKeepsPage', obj, { individualType: 'json' }).then(res => {
        this.dataLoading2 = false;
        this.table.list2 = res.data.list;
        this.table.list2.forEach(item => {
          item.stateFlag1 = item.stateFlag == 1 ? '已留样' : item.stateFlag == 2 ? '已处置' : ''
        })
        this.page2.totalPage = res.data.total;
      }).catch(e => {
        this.dataLoading2 = false;
      });
    },
    reset () {
      this.search.keepTime = [this.getYNM(new Date()), this.getYNM(new Date())]
      this.search.matName = '';
      this.search.sampleTypeCode = '';
      this.searchData();
    },
    handleRow1 (val) {
      this.waitRow = Object.assign({}, val);
    },
    handleRow (val) {
      this.saveRow = Object.assign({}, val);
    },
    pageSizeChange3 (size) {
      this.page3.pageSize = size;
      this.leftmainData();
    },
    pageCurrentChange3 (index) {
      this.page3.pageNum = index;
      this.leftmainData();
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.mainData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.mainData();
    },
    handlesaveData (val) {
      this.multipleSelection = val;
    },
    handleSelectionChange2 (val) {
      this.multipleSelection4 = val;
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getDataList2();
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getDataList2();
    },
    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);
      });
    },
    // 导出
    doExport () {
      if (this.table.list.length === 0) {
        this.$message.warning("表格无数据不能导出");
        return true;
      }
      this.tableExportLoading = true;
      this.isFixed = false;
      this.icoreFilterFlag = false;
      setTimeout(() => {
        let data = this.table.list;
        this.table.list = [];
        // 将大表控件bigDataShow改成[10000, 28];
        setTimeout(() => {
          // this.bigDataShow = [10000, 28];
          // this.isFixed = false;
          this.table.list = data;
          setTimeout(() => {
            this.tableExportLoading = false;
            this.doExport2();
          }, 0);
        }, 0);
      }, 0);
    },
    doExport2 () {
      // 将固定列去掉，否则导出的element-ui表格会有两个，因为element-ui固定列的实现原理是表格上面再套一层表格
      this.$nextTick(() => {
        let table = document.querySelector("#mtable .el-table");
        let header = document.querySelector(
          "#mtable .el-table .el-table__header"
        );
        let body = document.querySelector("#mtable .el-table .el-table__body");
        let footer = document.querySelector(
          "#mtable .el-table .el-table__footer"
        );
        let oTd = document.querySelectorAll("#mtable .el-table td");
        let oTh = document.querySelectorAll("#mtable .el-table th");
        // let tjTd = document.querySelectorAll('#power_table .el-table .el-table__footer td[rowspan="1"]');
        // 设置表格的border属性值为1，解决表格导出后无边框问题
        header.border = "1";
        body.border = "1";
        footer.border = "1";
        for (let item of Array.from(oTd)) {
          item.style.height = "27px";
          // item.setAttribute('style', 'height:27px;mso-number-format:"@"');
        }
        for (let item of Array.from(oTh)) {
          item.style.height = "27px";
        }
        // 处理表格底部合计统计样式问题
        // for (let item of Array.from(tjTd)) {
        //   item.setAttribute('rowspan', '2');
        // }
        let ex = '<th class="gutter" style="width: 10px; height: 27px;"></th>';
        let ex2 = '<th class="gutter" style="width: 0px; height: 27px;"></th>';
        ex = new RegExp(ex, "g").test(table.outerHTML) ? ex : ex2;
        // console.log(new RegExp(ex2, 'g').test(table.outerHTML), 'table.outerHTML', table.outerHTML);
        let bd = table.outerHTML.replace(new RegExp(ex, "g"), "");
        bd = bd.replace("正在整理数据", "");
        let html =
          '<html><head><meta charset="utf-8" /></head><body>' +
          bd +
          "</body></html>";
        let blob = new Blob([html], { type: "application/vnd.ms-excel" });
        let link = document.createElement("a");
        link.download = "留样管理分析室.xls";
        link.href = URL.createObjectURL(blob);
        // document.body.appendChild(link);
        link.click();
        // 导出之后将a标签移除掉，并将border属性设置为最初的0
        // document.body.removeChild(link)
        header.border = "0";
        body.border = "0";
        footer.border = "0";
        for (let item of Array.from(oTd)) {
          item.style.height = "";
        }
        for (let item of Array.from(oTh)) {
          item.style.height = "";
        }
        // for (let item of Array.from(tjTd)) {
        //   item.setAttribute('rowspan', '1');
        // }
        // this.bigDataShow = [4, 28];
        this.isFixed = true;
        this.icoreFilterFlag = true;
      });
    },
    tableRowClassName ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 1) {
        if (row.stateFlag === '1') {
          return 'error-green';
        }
        return '';
      }
      if (columnIndex === 2) {
        if (Date.parse(row.expireTime) < new Date()) {
          return 'error-row';
        }
        return '';
      }
    },
    tableRowClassName2 ({
      row, column, rowIndex, columnIndex
    }) {
      if (columnIndex === 2) {
        if (row.stateFlag === '2') {
          return 'error-row';
        }
        return '';
      }
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
