<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true">
        <el-form-item label='计划单位'>
          <el-select v-model="search.companyNo" filterable clearable style="width:100%" collapse-tags size="small">
            <el-option v-for="item in companyNameType" :key="item.orgCode" :label="item.orgName" :value="item.orgCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label='计划日期'>
          <el-date-picker v-model="search.planDate[0]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="开始日期" size="mini" style="width: 150px">
          </el-date-picker>
          <span>至</span>
          <el-date-picker v-model="search.planDate[1]" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"
            placeholder="结束日期" size="mini" style="width: 150px">
          </el-date-picker>
          <!-- <el-date-picker
         v-model="search.planDate"
         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>
    <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" v-privilege="activeMenu + 'ADD'" size="mini"
          @click="addData">新增</el-button>
        <el-button icon="el-icon-edit" type="goon" size="mini" v-privilege="activeMenu + 'PUT'"
          @click="modifyData">修改</el-button>
        <el-button icon="el-icon-remove-outline" type="danger" v-privilege="activeMenu + 'disable'" size="mini"
          @click="deleteData">停用</el-button>
        <el-button icon="el-icon-check" type="goon" size="mini" v-privilege="activeMenu + 'effectivity'"
          @click="recoverData">启用</el-button>
        <el-button icon="el-icon-check" type="goon" size="mini" v-privilege="activeMenu + 'submit'"
          @click="submitData">提交</el-button>
        <el-button icon="el-icon-back" type="danger" size="mini" :loading='returnSubLoading'
          v-privilege="activeMenu + 'submit'" @click="returnSubmit">取消提交</el-button>
        <el-button icon="el-icon-audit" type="goon" size="mini" :loading='subLoading1'
          v-privilege="activeMenu + 'shenhe'" @click="checkData">审核</el-button>
        <el-button icon="el-icon-noaudit" type="danger" size="mini" :loading='returnSubLoading1'
          v-privilege="activeMenu + 'shenhe'" @click="uncheckData">取消审核</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 @selection-change="handleSelectionChange" :data="table.list"
        :icore-filter-flag="icoreFilterFlag" :header-cell-style="tableHeaderCellStyle" @cell-click='searchFollow'
        :cell-class-name="tableCellClassName" :row-class-name="tableRowClassName" :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 :show-overflow-tooltip="true" sortable min-width="90px" prop="validFlag1" label="数据状态"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable 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 :show-overflow-tooltip="true" sortable min-width="100px" prop="planDate1" label="计划日期"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="entrTypeName" label="委托类型"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="planCompanyName" label="计划单位"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="planDeptName" label="计划车间"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="100px" prop="planName" label="计划名称"
          align="center"></el-table-column>
        <!-- <el-table-column sortable width="140px" prop="deptName" label="计划车间" align="center"></el-table-column> -->
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="sampleTypeName" label="样品类型"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="matName" label="物料名称"
          align="center"></el-table-column>
        <!-- <el-table-column sortable width="140px" prop="planDate1" label="计划日期" align="center"></el-table-column> -->
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="companyName" label="检验单位"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="deptName" label="检验车间"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="sectionName" label="检验班组"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="smpCompanyName" label="取样单位"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="smpDeptName" label="取样车间"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="smpSectionName" label="取样班组"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="smpDeliName" label="送样频次"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="200px" prop="pointName" label="取样地点"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="200px" prop="planName" label="计划名称"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="200px" prop="planDesc" label="计划说明"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="testLimit" label="测试时限(小时)"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="isSmp1" label="是否取样"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="isBatch1" label="是否组批"
          align="center"></el-table-column>
        <!-- <el-table-column sortable width="100px" prop="testTime1" label="测试起始时间" align="center"></el-table-column>
        <el-table-column sortable width="130px" prop="durTime" label="间隔时间（小时）" align="center"></el-table-column> -->
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="planCompanyName" label="委托单位"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="120px" prop="testTypeName" label="检验类型"
          align="center"></el-table-column>
        <!-- <el-table-column sortable width="90px"  prop="validFlag1" label="状态" align="center"></el-table-column> -->
        <!-- <template slot-scope="scope">
              <span v-if="scope.row.validFlag == 1">已启用</span>
              <span v-else-if="scope.row.validFlag == 0">已停用</span>
          </template> -->
        <el-table-column :show-overflow-tooltip="true" sortable min-width="200px" prop="memo" label="备注"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="95px" prop="createMan" label="创建人"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="160px" prop="createTime" 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-edit" type="goon" size="mini" v-privilege="activeMenu + 'modifyDep'"
          @click="modifyData2">修改</el-button>
        <!-- <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="copyData2">复制</el-button> -->
        <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-privilege="activeMenu + 'delete'"
          @click="deleteData2">删除</el-button>
        <!-- <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData2">启用</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.slice((this.page2.pageNum - 1) * this.page2.pageSize, this.page2.pageNum * this.page2.pageSize)"
        :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 :show-overflow-tooltip="true" sortable min-width="140px" prop="validFlag" label="状态"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="planIdD" label="计划单子号"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="planId" label="计划单号"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="160px" prop="anlyItemName" label="分析项目"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="90px" prop="maxSign" label="上限符"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="90px" prop="maxValue" label="上限值"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="90px" prop="minSign" label="下限符"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="90px" prop="minValue" label="下限值"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="90px" prop="createMan" label="创建人"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="90px" prop="createTime" label="创建时间"
          align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" sortable min-width="140px" prop="memo" 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> -->
    <el-dialog @close="fxcloseDialog" :close-on-click-modal='false' :visible.sync="fxdialogTableVisible">
      <div slot="title" class="titleBox">
        <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px;margin-right:20px">修改计划检验项目信息</span>
      </div>
      <el-form label-width="80px">
        <el-row>
          <el-col :span='12'>
            <el-form-item prop="maxSignTypeIndex" label="上限符">
              <el-select v-model="baseData.maxSign" filterable collapse-tags size="small" style="width:100%">
                <el-option v-for="(item, index) in maxSignType" :key="index" :label="item.maxSign"
                  :value="item.maxSign">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span='12'>
            <el-form-item label="最大值">
              <el-input v-model="baseData.maxValue" style="width:100%" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span='12'>
            <el-form-item prop="minSignTypeIndex" label="下限符">
              <el-select v-model="baseData.minSign" filterable collapse-tags size="small" style="width:100%">
                <el-option v-for="(item, index) in minSignType" :key="index" :label="item.minSign"
                  :value="item.minSign">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span='12'>
            <el-form-item label="最小值">
              <el-input v-model="baseData.minValue" style="width:100%" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="goon" icon="el-icon-check" size="mini" @click="fxaddData()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="fxcloseDialog">取消</el-button>
      </span>
    </el-dialog>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div>
    <div is="alertComponets2" :showFlag2="showFlag2" :Params="Params" :Params2="Params2" @refresh='refresh2'></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';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: { alertComponets, alertComponets2 },
  data() {
    return {
      table: {
        list: [],
        list2: []
      },
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      fxdialogTableVisible: false,
      minSignType: [{ minSign: ">=" }, { minSign: ">" }],
      maxSignType: [{ maxSign: "<=" }, { maxSign: "<" }],
      baseData: {},
      page: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      list: [],
      planSave: {},
      saveRow: {},
      planId: '',
      showFlag: false,
      Params: {},
      showFlag2: false,
      Params2: {},
      height_top: 0,
      height_bot: 0,
      companyNameType: [],
      companyNameType1: [],
      sampleTypeNameType: [],
      multipleSelection3: [],
      multipleSelection4: [],
      returnSubLoading: false,
      subLoading1: false,
      returnSubLoading1: false,
      search: {
        planDate: [],
        companyName: ''
      },
      activeMenu: ''
    }
  },
  created() {
    this.height_top = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 110;
    this.height_bot = window.innerHeight / 2 - 140 < 249 ? 249 : window.innerHeight / 2 - 110;
    this.search.planDate = [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.companyNameType = 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.saveRow.planId)
    },
    saveData(row) {
      this.planSave = Object.assign({}, row)
    },
    addData() {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    modifyData() {
      let _this = this;
      if (_this.multipleSelection3.length !== 1) {
        this.$message.warning('请勾选您要修改的一条数据！')
        return
      }
      if (this.multipleSelection3[0].stateFlag === '1') {
        this.$message.warning('已提交的数据不可以进行修改！')
        return
      }
      this.showFlag = !this.showFlag;
      this.Params = this.multipleSelection3[0]
    },
    deleteData() {
      let _this = this;
      if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要停用的数据！')
        return
      }
      let tempArr = []
      this.multipleSelection3.map(item => {
        tempArr.push(item.id)
      })
      _this.axios.post('pass/testManagement/v1/limstestplans/disable', tempArr, { individualType: 'json' }).then(res => {
        if (res.succeed) {
          _this.dialogTableVisible = false;
          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('请勾选您要启用的数据！')
        return
      }
      let tempArr = []
      this.multipleSelection3.map(item => {
        tempArr.push(item.id)
      })
      _this.axios.post('pass/testManagement/v1/limstestplans/enabled', tempArr, { individualType: 'json' }).then(res => {
        if (res.succeed) {
          this.dialogTableVisible = false;
          this.$message.success('启用成功');
          _this.refresh()
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    submitData() {
      if (this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要提交的数据！')
        return
      }
      for (let item of this.multipleSelection3) {
        if (item.stateFlag != 0) {
          this.$message.warning('数据不是编辑状态，不可提交！')
          return
        }
        if (item.validFlag == 0) {
          this.$message.warning('无效状态的数据，不可以提交!')
          return
        }
      }
      this.axios.post('pass/testManagement/v1/limstestplans/check', 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)
      })
    },
    returnSubmit() {//取消提交
      if (this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要取消提交的数据！')
        return
      }
      for (let item of this.multipleSelection3) {
        if (item.stateFlag != 4) {
          this.$message.warning('数据不是待审核状态，不可取消提交！')
          return
        }
        if (item.validFlag == 0) {
          this.$message.warning('无效状态的数据，不可以提交!')
          return
        }
      }
      this.axios.post('pass/testManagement/v1/limstestplans/returnSubmit', 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)
      })
    },
    checkData() {//审核
      if (this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要审核的数据！')
        return
      }
      let flag = false;
      this.multipleSelection3.forEach(item => {
        if (item.stateFlag != 4) {
          this.$message.warning('请勾选状态为待审核的数据')
          flag = true
        }
      })
      if (flag) {
        return
      }
      this.axios.post('pass/testManagement/v1/limstestplans/checkInterPlan', this.multipleSelection3, { individualType: 'json' }).then(res => {
        if (res.succeed) {
          this.$message.success('审核成功');
          this.searchData()
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    uncheckData() {//取消审核
      let _this = this;
      if (_this.multipleSelection3.length < 1) {
        this.$message.warning('请勾选您要取消审核的数据！')
        return
      } else {
        for (var j = 0; j < _this.multipleSelection3.length; j++) {
          if (_this.multipleSelection3[j].stateFlag != '1') {
            this.$message.warning('请勾选状态为审核的数据')
            return
          }
        }
        _this.axios.post('pass/testManagement/v1/limstestplans/uncheck', _this.multipleSelection3, { individualType: 'json' }).then(res => {
          if (res.succeed) {
            this.$message.success('取消成功');
            _this.searchData()
          } else {
            this.$message.error(res.message)
          }
        }).catch(e => {
          this.$message.error(e.message)
        })
      }
    },
    addData2() {
      if (JSON.stringify(this.saveRow) === "{}") {
        this.$message.warning('请点击选中一条固定计划信息数据！')
        return
      }
      if (this.saveRow.stateFlag == 2) {
        this.$message.warning('数据已提交，不可再新增')
        return
      }
      this.showFlag2 = !this.showFlag2;
      this.Params2 = null;
      this.Params = this.saveRow
    },
    modifyData2() {
      let _this = this;
      if (JSON.stringify(this.planSave) === "{}") {
        this.$message.warning('请点击选中一条需要修改的数据')
        return
      }
      if (this.saveRow.stateFlag == 2) {
        this.$message.warning('数据已提交，不可再修改')
        return
      }
      this.baseData = Object.assign({}, this.planSave)
      this.fxdialogTableVisible = true
    },
    fxcloseDialog() {
      this.fxdialogTableVisible = false
      this.baseData = {}
    },
    fxaddData() {
      this.axios.post('pass/testManagement/v1/limstestplands/saveLimsTestPlanD', this.baseData, { individualType: 'json' }).then(res => {
        if (res.succeed) {
          this.fxdialogTableVisible = false;
          this.$message.success(res.message)
          this.depData(this.saveRow.planId)
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    copyData2() {
      let _this = this;
      if (_this.multipleSelection4.length < 1) {
        this.$message.warning('请勾选您要复制的数据！')
      } else {
        _this.axios.post('pass/testManagement/v1/limstestplands/', _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)
        })
      }
    },
    deleteData2() {
      if (JSON.stringify(this.planSave) === "{}") {
        this.$message.warning('请点击选中一条需要删除的数据')
        return
      }
      if (this.saveRow.stateFlag == 2) {
        this.$message.warning('数据已提交，不可再删除')
        return
      }
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.post('pass/testManagement/v1/limstestplands/deleteLimsTestPlanD?id=' + this.planSave.id, { individualType: 'json' }).then(res => {
          if (res.succeed) {
            this.$message.success('删除操作成功');
            this.depData(this.saveRow.planId)
          } 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()
    },
    mainData() {
      this.saveRow = {}
      this.table.list2 = []
      if (!this.search.planDate) {
        this.startTime = ''
        this.endTime = ''
      } else {
        this.startTime = this.search.planDate[0] + ' 00:00:00'
        this.endTime = this.search.planDate[1] + ' 23:59:59'
      }
      this.dataLoading = true;
      let obj = {
        object: {
          companyNo: this.search.companyNo,
          planTypeCode: 481702
        },
        list: [0, 4, 1],
        startTime: this.startTime,
        endTime: this.endTime,
        pageIndex: this.page.pageNum,
        pageSize: this.page.pageSize
      }
      this.axios.post('pass/testManagement/v1/limstestplans/queryLimsTestPlanPage', obj, { individualType: 'json' }).then(res => {
        this.dataLoading = false;
        this.table.list = res.data.list;
        this.table.list.forEach(item => {
          item.validFlag1 = item.validFlag == '0' ? '无效' : item.validFlag == '1' ? '有效' : ''
          item.stateFlag1 = item.stateFlag == '0' ? '编辑' : item.stateFlag == '1' ? '已审核' : item.stateFlag == '4' ? '待审核' : ''
          item.isSmp1 = item.isSmp == '0' ? '否' : item.isSmp == '1' ? '是' : ''
          item.isBatch1 = item.isBatch == '0' ? '否' : item.isBatch == '1' ? '是' : ''
          item.planDate1 = formatDate(item.planDate, 'yyyy-MM-dd')
        })
        this.page.totalPage = res.data.total;
        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.saveRow = row
      this.page2.pageNum = 1
      this.page2.pageSize = 50
      this.depData(this.saveRow.planId)
    },
    depData(planId) {
      this.planSave = {}
      this.dataLoading2 = true
      let planIds = planId ? planId : ''
      this.axios.post('pass/testManagement/v1/limstestplands/queryLimsTestPlanDByPlanId?planId=' + planIds, { individualType: 'json' }).then(res => {
        this.dataLoading2 = false;
        this.table.list2 = res.data;
        this.table.list2.forEach(item => {
          item.validFlag = item.validFlag == '0' ? '无效' : item.validFlag == '1' ? '有效' : ''
        })
        this.page2.totalPage = res.data.total;
      }).catch(e => {
        this.dataLoading2 = false;
      });
    },
    reset() {
      this.search.planDate = [this.getYNM(new Date()), this.getYNM(new Date())]
      this.search.companyNo = '';
      this.searchData();
    },
    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;
    },
    pageCurrentChange2(index) {
      this.page2.pageNum = index;
    },
    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, rowIndex }) {
      if (row.validFlag !== '1') {
        return 'error-row';
      }
      return '';
    },
    tableCellClassName({
      row, column, rowIndex, columnIndex
    }) {
      // if (columnIndex === 24) {
      // if (row.validFlag !== '1') {
      //   return 'error-row';
      // }
      // }
      if (columnIndex === 2) {
        if (row.stateFlag === '2') {
          return 'error-green';
        }
        return '';
      }
    },
    tableRowClassName2({
      row, column, rowIndex, columnIndex
    }) {
      // if (columnIndex === 6) {
      // 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>
