<!-- 检验委托-中控 -->
<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-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>
      </el-form>
    </div>
    <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-circle-plus-outline"
          type="goon"
          size="mini"
          v-privilege="activeMenu + 'add'"
          @click="addData"
          >新增</el-button
        >
        <el-button
          icon="el-icon-circle-plus-outline"
          type="goon"
          size="mini"
          :loading="copyLoading"
          v-privilege="activeMenu + 'copy'"
          @click="copyData"
          >复制</el-button
        >
        <!-- <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData">修改</el-button> -->
        <!-- <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="deleteData">删除</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData">启用</el-button> -->
        <el-button
          icon="el-icon-check"
          type="goon"
          size="mini"
          :loading="subLoading"
          v-privilege="activeMenu + 'submit'"
          @click="submitData"
          >提交</el-button
        >
        <el-button
          icon="el-icon-back"
          type="danger"
          size="mini"
          :loading="subLoading"
          v-privilege="activeMenu + 'submit'"
          @click="cancelData"
          >取消提交</el-button
        >
        <el-button
          icon="el-icon-back"
          type="danger"
          size="mini"
          :loading="subLoading"
          v-privilege="activeMenu + 'submit'"
          @click="disable"
          >停用</el-button
        >
        <el-button
          icon="el-icon-check"
          type="goon"
          size="mini"
          :loading="subLoading"
          v-privilege="activeMenu + 'submit'"
          @click="enable"
          >启用</el-button
        >
        <el-button
          icon="el-icon-printer"
          type="goon"
          size="mini"
          :loading="printLoading"
          @click="printQRCode"
          >打印标签</el-button
        >
        <el-button
          icon="el-icon-printer"
          type="goon"
          size="mini"
          :loading="printLoading"
          @click="printOtherQRCode"
          >分样打印</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"
        :cell-class-name="tableRowClassName"
        :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="100px"
          prop="stateFlag1"
          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="100px"
          prop="matName"
          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="160px"
          prop="entrTime1"
          label="委托日期"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="90px"
          prop="carNo"
          label="车号"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="90px"
          prop="smpDeliName"
          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="120px"
          prop="planCompanyName"
          label="委托单位"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="120px"
          prop="planDeptName"
          label="委托车间"
          align="center"
        ></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="90px"
          prop="sampleTypeName"
          label="样品类型"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="80px"
          prop="testTypeName"
          label="检验类型"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="120px"
          prop="suppName"
          label="发货单位"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="120px"
          prop="acceptName"
          label="收货单位"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="120px"
          prop="pointName"
          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="95px"
          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="95px"
          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="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>
    <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-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"
        highlight-current-row
        @row-click="saveData"
        :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
          sortable
          :show-overflow-tooltip="true"
          min-width="100px"
          prop="entrId"
          label="委托单号"
          align="center"
        ></el-table-column>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          min-width="140px"
          prop="testItemName"
          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="120px"
          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="120px"
          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
          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>
    </div>
    <!-- <div class="common-foot-style">
        <el-pagination @size-change="pageSizeChange2" @current-change="pageCurrentChange2"
          :current-page="page2.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="page2.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page2.totalPage" background>
        </el-pagination>
    </div> -->
    <div
      is="alertComponets"
      :showFlag="showFlag"
      :Params="Params"
      @refresh="refresh"
    ></div>
    <div
      is="alertComponets2"
      :showFlag2="showFlag2"
      :Params="Params"
      :Params2="Params2"
      @refresh="refresh2"
    ></div>
    <div
      id="printContainer2"
      style="margin-left: 20px; margin-top: 3px"
      v-show="false"
    >
      <div id="printContent">
        <div
          v-for="(item, index) in printData"
          :key="item.id"
          style="width: 394px; border: 1px solid #fff; position: relative"
        >
          <div style="margin-top: 10px">
            <div style="text-align: center; margin-top: 20px">
              <strong style="font-size: 20px">广西北港新材料有限公司</strong><br />
            </div>
            <div style="font-size: 20px; line-height: 24px; margin-left: 10px">
              物料名称：{{ item.matName }}
            </div>
            <div style="font-size: 19px; line-height: 24px; margin-left: 10px">
              车号：<span style="font-weight: 800; font-size: 18px">{{
                item.carNo
              }}</span>
            </div>
            <div style="font-size: 19px; line-height: 24px; margin-left: 10px">
              样品编号：<span style="font-weight: 800; font-size: 18px">{{
                item.sampleNo
              }}</span>
            </div>
            <div style="font-size: 19px; line-height: 24px; margin-left: 10px">
              制样时间：<span style="font-weight: 800; font-size: 18px">{{
                item.entrTime1
              }}</span>
            </div>
            <div
              v-if="item.anlyName && item.anlyName.length > 80"
              style="
                margin-left: 10px;
                line-height: 18px;
                word-wrap: break-word;
                word-break: normal;
                font-size: 17px;
                line-height: 20px;
              "
            >
              <span style="font-size: 22px">检验元素：</span>{{ item.anlyName }}
            </div>
            <div
              v-else
              style="
                margin-left: 10px;
                word-wrap: break-word;
                word-break: normal;
                line-height: 24px;
              "
              :id="'anlyName' + index"
            >
              <span style="font-size: 22px">检验元素：{{ item.anlyName ? item.anlyName : '' }}</span>
            </div>
          </div>
          <div style="text-align: center; margin-bottom: 0">
            <img width="88%" :id="`barcode${item.id}`" />
          </div>
          <div style="page-break-after: always"></div>
        </div>
      </div>
    </div>
  </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 JsBarcode from 'jsbarcode'
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: { alertComponets, alertComponets2 },
  data () {
    return {
      table: {
        list: [],
        list2: []
      },
      dataLoading: false,
      dataLoading2: false,
      subLoading: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      list: [],
      entrId: '',
      showFlag: false,
      saveRow: {},
      savaDep: {},
      Params: {},
      showFlag2: false,
      copyLoading: false,
      Params2: {},
      entrOrgNameType: [],
      entrOrgNameType1: [],
      sampleTypeNameType: [],
      multipleSelection3: [],
      multipleSelection4: [],
      search: {
        times: [],
        planCompanyName: '',
        matName: ''
      },
      height_top: 0,
      height_bot: 0,
      activeMenu: '',
      printData: [],
      printLoading: false,
      typeFlag: 'all'
    }
  },
  created () {
    this.height_top = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 110;
    this.height_bot = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 110;
    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.getDataList2();
    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);
    },
    getDate (strDate) {
      var st = strDate
      // var a = st.split(" ")
      // var b = a[0].split("-")
      var c = st.split(':')
      var date = new Date('2020', '8', '29', c[0], c[1], c[2]);
      return date
    },
    addData () {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    saveDataMain (row) {
      this.saveRow = Object.assign({}, row)
      console.log(1)
    },
    modifyData () {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请点击选中一条您要修改的数据')
        return
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning('数据已提交，不可进行修改')
        return
      }
      this.Params = this.saveRow
      this.showFlag = !this.showFlag;
    },
    deleteData () {
      let _this = this;
      if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要停用的数据！')
      } else {
        for (var j = 0; j < _this.multipleSelection3.length; j++) {
          if (_this.multipleSelection3[j].validFlag === '0') {
            this.$message.warning('请勾选状态为已启用的数据')
            return
          }
        }
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
          _this.multipleSelection3[i].updateMan = userName;
          _this.multipleSelection3[i].updateNo = userId
        }
        _this.axios.post('pass/testManagement/v1/limstestentrusts/abolish', _this.multipleSelection3, { individualType: 'json' }).then(res => {
          if (res.succeed) {
            this.$message.success('停用操作成功');
            _this.refresh()
          } else {
            this.$message.error(res.message)
          }
        }).catch(e => {
          this.$message.error(e.message)
        })
      }
    },
    recoverData () {
      let _this = this;
      if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要启用的数据！')
      } else {
        for (var j = 0; j < _this.multipleSelection3.length; j++) {
          if (_this.multipleSelection3[j].validFlag === '1') {
            this.$message.warning('请勾选状态为已停用的数据')
            return
          }
        }
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection3.length; i++) {
          _this.multipleSelection3[i].updateMan = userName;
          _this.multipleSelection3[i].updateNo = userId
        }
        _this.axios.post('pass/testManagement/v1/limstestentrusts/recover', _this.multipleSelection3, { individualType: 'json' }).then(res => {
          if (res.succeed) {
            this.$message.success('启用成功');
            _this.refresh()
          } else {
            this.$message.error(res.message)
          }
        }).catch(e => {
          this.$message.error(e.message)
        })
      }
    },
    //复制
    copyData () {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请点击选中一条您要提交的数据')
        return
      }
      this.copyLoading = true
      this.axios.post('pass/testManagement/v1/limstestentrusts/copyentrust', this.saveRow, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message);
          this.refresh()
        } else {
          this.$message.error(res.message)
        }
        this.copyLoading = false;
      }).catch(e => {
        this.copyLoading = false
        this.$message.error(e.message)
      })
    },
    enable () {//启用
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请点击选中一条您要启用的数据')
        return
      }
      if (this.saveRow.validFlag != 0) {
        this.$message.warning('数据未停用，不可启用！')
        return
      }
      this.subLoading = true
      this.axios.post('pass/testManagement/v1/limstestentrusts/enable', [this.saveRow.id], { 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.subLoading = false
      }).catch(e => {
        this.subLoading = false
        this.$message.error(e.message)
      })
    },
    disable () {//停用
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请点击选中一条您要停用的数据')
        return
      }
      this.subLoading = true
      this.axios.post('pass/testManagement/v1/limstestentrusts/disable', [this.saveRow.id], { 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.subLoading = false
      }).catch(e => {
        this.subLoading = false
        this.$message.error(e.message)
      })
    },
    cancelData () {//取消提交
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请点击选中一条您要取消提交的数据')
        return
      }
      if (this.saveRow.stateFlag != 1) {
        this.$message.warning('数据不是提交状态，不可取消提交！')
        return
      }
      this.subLoading = true
      this.axios.post('pass/testManagement/v1/limstestentrusts/cancel', [this.saveRow.id], { 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.subLoading = false
      }).catch(e => {
        this.subLoading = false
        this.$message.error(e.message)
      })
    },
    submitData () {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请点击选中一条您要提交的数据')
        return
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning('数据已提交，不可再次提交')
        return
      }
      this.subLoading = true
      this.axios.post('pass/testManagement/v1/limstestentrusts/submit', [this.saveRow.id], { 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.subLoading = false
      }).catch(e => {
        this.subLoading = false
        this.$message.error(e.message)
      })
    },
    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
    },
    modifyData2 () {
      let _this = this;
      if (_this.multipleSelection4.length !== 1) {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag2 = !_this.showFlag2;
        _this.Params2 = _this.multipleSelection4[0];
        _this.Params = null
      }
    },
    // 打印条形码
    printQRCode () {
      this.typeFlag = 'some'
      if (JSON.stringify(this.saveRow) === '{}') {
        this.$message.warning('请点击您要打印的数据')
        return
      }
      if (this.saveRow.stateFlag != 1) {
        this.$message.warning('未提交的数据不能进行打印操作，请选择已提交的数据')
        return
      }
      this.axios.post('pass/testManagement/v1/limssampleinfos/queryLimsSampleInfosPage', { object: { entrId: this.saveRow.entrId }, 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
            item.entrTime1 = this.saveRow.entrTime1
          })
          this.runPrint(this.printData)
          this.searchData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    // 根据sampleNo查询分样数据
    async getPartData (sampleNo) {

    },
    // 打印分样条形码
    printOtherQRCode () {
      this.typeFlag = 'all'
      if (JSON.stringify(this.saveRow) === '{}') {
        this.$message.warning('请点击您要打印的数据')
        return
      }
      if (this.saveRow.stateFlag != 1) {
        this.$message.warning('未提交的数据不能进行打印操作，请选择已提交的数据')
        return
      }
      this.axios.post('pass/testManagement/v1/limssampleinfos/queryLimsSampleInfosPage', { object: { entrId: this.saveRow.entrId }, pageIndex: 1, pageSize: 200 }, { individualType: 'json' }).then(res => {
        if (res.code == 0 || res.code == 200) {
          if (res.data.list && res.data.list.length > 0 && res.data.list[0]) {
            let sampleFlag = true
            // 根据返回数据里面的sampleNo查询分样信息
            this.axios.post('pass/testManagement/v1/limssamplepreps/saveLimsSamplePrepToScan', { scanCode: res.data.list[0].markNo, scanName: 'markNo' }, { individualType: 'json' }).then(async res => {
              if (res.code == 0 || res.code == 200) {
                this.$message.success(res.message);
                this.printData = res.data.limsSampleInfoDBySampleNo
                this.printData.forEach(item => {
                  // item.anlyName = res.data.limsTestEntrust.anlyName
                  item.carNo = this.saveRow.carNo
                  item.entrTime1 = this.saveRow.entrTime1
                  if (item.anlyName) {
                    if (item.anlyName.length < 80) {
                      item.printAnlyName = item.anlyName.split('').map(item => {
                        return `<span style="font-size: 23px;">${item}</span>`
                      }).join('')
                    } else {
                      item.printAnlyName = item.anlyName
                    }
                  } else {
                    sampleFlag = false
                  }
                })
                this.runPrint(this.printData)
                this.searchData()
                this.depData(res.data.limsSamplePreps.id)
              } else {
                this.$message.error(res.message)
              }
            })
          } else {
            return this.$message.warning('没有样品信息')
          }
        } else {
          this.$message.error(res.message)
        }
      })
    },
    runPrint (arr) {
      setTimeout(() => {
        arr.forEach(item => {
          item.createTime = item.createTime ? formatDate(item.createTime, 'yyyy-MM-dd') : '';
          let newStr = item.sampleNo.replace('-U', '(筛上)').replace('-D', '(筛下)').replace('-B', '(边)')
            .replace('-Z', '(中)').replace('-T', '(2mm)').replace('-H', '(合金)').replace('-R', '(熔渣)');
          item.newSampleNo = newStr
          JsBarcode(`#barcode${item.id}`, item.sampleNo, {
            format: 'CODE128',
            lineColor: '#000',
            background: '#fff',
            width: 1,
            height: 35,
            displayValue: false
          })
        })
        setTimeout(() => {
          this.printPage('printContent');
        }, 1500)
      }, 100);
    },
    deleteData2 () {
      if (JSON.stringify(this.savaDep) === "{}") {
        this.$message.warning('请点击选中一条检验委托信息数据')
        return
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning('数据已提交，不可进行删除')
        return
      }
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.post('pass/testManagement/v1/limstestentrustds/deleteLimsTestEntrustD?id=' + this.savaDep.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(() => { });
    },
    recoverData2 () {
      let _this = this;
      if (_this.multipleSelection4.length < 1) {
        this.$message.warning('请勾选您要启用的数据！')
      } else {
        for (var j = 0; j < _this.multipleSelection4.length; j++) {
          if (_this.multipleSelection4[j].validFlag === '1') {
            this.$message.warning('请勾选状态为已停用的数据！')
            return
          }
        }
        _this.dialogTableVisible2 = false;
        for (var i = 0; i < _this.multipleSelection4.length; i++) {
          _this.multipleSelection4[i].updateMan = userName;
          _this.multipleSelection4[i].updateNo = userId
        }
        _this.axios.post('pass/testManagement/v1/limstestentrustds/recover', _this.multipleSelection4, { individualType: 'json' }).then(res => {
          if (res.succeed) {
            this.$message.success('启用成功');
            _this.refresh2()
          } else {
            this.$message.error(res.message)
          }
        }).catch(e => {
          this.$message.error(e.message)
        })
      }
    },
    searchData () {
      this.page.pageNum = 1
      // this.page.pageSize = 200
      this.mainData()
    },
    mainData () {
      this.saveRow = {},
        this.tableLoading1 = 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: "480102",
          isBatch: '',
          entrOrgNo: this.search.planCompanyNo, // 委托单位
          matName: this.search.matName
        },
        '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;
        this.page.totalPage = res.data.total;
        this.table.list.forEach(item => {
          item.stateFlag1 = item.validFlag == '0' ? '已停用' : item.stateFlag === '0' ? '编辑' : item.stateFlag === '1' ? '提交' : ''
          item.entrTime1 = formatDate(item.entrTime, 'yyyy-MM-dd' + ' ' + 'HH:mm:ss')
        })
        if (this.table.list.length > 0) {
          this.$refs.dataTable.setCurrentRow(this.table.list[0])
          this.searchFollow(this.table.list[0])
        }
      }).catch(e => {
        this.dataLoading = false;
      });
    },
    searchFollow (row) {
      this.savaDep = {}
      this.saveRow = Object.assign({}, row)
      this.entrId = row.entrId ? row.entrId : ''
      this.page2.pageNum = 1
      this.page2.pageSize = 50
      this.depData(this.entrId)
    },
    depData (entrId) {
      this.savaDep = {}
      this.dataLoading2 = true;
      this.axios.post('pass/testManagement/v1/limstestentrustds/queryLimsTestEntrustDPage', { object: { entrId: entrId }, pageIndex: this.page2.pageNum, pageSize: this.page2.pageSize }, { individualType: 'json' }).then(res => {
        this.dataLoading2 = false;
        this.table.list2 = res.data.list;
        this.table.list2.forEach(item => {
          item.validFlag1 = item.validFlag === '0' ? '无效' : item.validFlag === '1' ? '有效' : ''
        })
        this.page2.totalPage = res.data.total;
      }).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();
      // this.getentrOrgNameTypeList()
    },
    handleSelectionChange (val) {
      this.multipleSelection3 = val;
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.mainData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.mainData();
    },
    handleSelectionChange2 (val) {
      this.multipleSelection4 = val;
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.depData(this.entrId);
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.depData(this.entrId);
    },
    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);
      });
    },
    // getentrOrgNameTypeList () {
    //    this.axios.get('pass/testManagement/v1/limstestentrusts/' + '?sampleTypeCode=480102&sampleTypeName=中控样')
    //         .then(res => {
    //           this.dataLoading = false;
    //           this.entrOrgNameType1 = res.data.list;
    //           for (let i = 0; i < this.entrOrgNameType1.length; i++) {
    //             let flag = true;
    //             for (let j = 0; j < this.entrOrgNameType.length; j++) {
    //               if (this.entrOrgNameType[j].planCompanyName === this.entrOrgNameType1[i].planCompanyName) {
    //                 flag = false;
    //               }
    //             }
    //             if (flag === true) {
    //                this.entrOrgNameType.push(this.entrOrgNameType1[i])
    //             }
    //           }
    //         })
    // },
    tableRowClassName ({
      row, column, rowIndex, columnIndex
    }) {
      // if (columnIndex === 13) {
      //   if (row.validFlag !== '1') {
      //     return 'error-row';
      //   }
      // }
      if (columnIndex === 1) {
        if (row.validFlag === '0') {
          return 'error-row';
        } else {
          if (row.stateFlag === '1') {
            return 'error-green';
          }
        }
        return '';
      }
    },
    tableRowClassName2 ({
      row, column, rowIndex, columnIndex
    }) {
      if (columnIndex === 5) {
        if (row.validFlag !== '1') {
          return 'error-row';
        }
        return '';
      }
      // if (columnIndex === 10 || columnIndex === 9) {
      //   return 'erroe-bule2'
      // } 
      // if (columnIndex === 12) {
      // if (Date.parse(row.startTime) > new Date ()) {
      //   return 'error-green2';
      // } 
      // return '';
      // }
      // if (columnIndex === 13) {
      // if (Date.parse(row.endTime) < new Date ()) {
      //   return 'error-yellow2';
      // } 
      // return '';
      // }
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
