<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:120px;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: 120px;margin-right: 10px;"></el-input>
        </el-form-item>
        <el-form-item label='合同号'>
          <el-input v-model="search.contractNo" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容" style="width: 120px;margin-right: 10px;"></el-input>
        </el-form-item>
        <el-form-item label='供应商'>
          <el-input v-model="search.suppName" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容" style="width: 120px;margin-right: 10px;"></el-input>
        </el-form-item>
        <el-form-item label="计划日期">
          <el-date-picker
           v-model="search.planDate"
           type="daterange"
           range-separator="至"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           size="small"
           style="width:270px"
           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-row>
      <el-col :span='24'>
          <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-edit" type="goon" size="mini" v-privilege="activeMenu + 'modify'" @click="modifyData">修改</el-button>
           <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-privilege="activeMenu + 'delete'" @click="deleteData">删除</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='returnSubLoading'  @click="returnSubmit">取消提交</el-button>
           <el-button icon="el-icon-audit" type="goon" size="mini" :loading='subLoading1' v-privilege="activeMenu + 'shenhe'" @click="audit">审核</el-button>
           <el-button icon="el-icon-noaudit" type="danger" size="mini" :loading='returnSubLoading1' v-privilege="activeMenu + 'shenhe'" @click="noaudit">取消审核</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 @row-click='saveDataMain' :height="height_top" highlight-current-row :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="80px"  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="planDate1" label="计划日期" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="contractNo" label="合同号"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="matName" label="物料名称" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="gradeName" label="牌号/等级" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="suppName" label="供货单位"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="lotsNo" 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="acceptName" label="收货单位"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sampleTypeName" label="样品类型" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="smpDeliName" label="取样频次" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="transportTypeName" label="运输类型"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="sendPlace" 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="100px" prop="entrTypeName" label="委托类型" align="center"></el-table-column>
              <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="packTypeName" 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="140px" prop="matClassName" label="物料分类" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="matShapeName" 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="100px" prop="spec" label="规格"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="netWgt" label="重量(t)"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sampleNum" label="客户样量"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="sampleWgt" label="样品重量"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="unloadPlace" label="卸货地点"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="entTime" label="进厂时间"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="testCost" label="检测费用"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="cnsnContactMan1" label="是否检验"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="isCiq1" label="是否商检"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="isBatch1" label="是否配批"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="isSmp1" label="是否取样"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="isPrep1" label="是否组合"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="isCheck1" label="是否加权"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="isMater1" label="是否计量"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="cnsnOrgName" label="业务类型"  align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="cnsnOrgAddr" 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="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-column sortable :show-overflow-tooltip="true" min-width="95px"  prop="auditManName" label="审核人" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="auditTime" 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="changeData">修改</el-button>
           <el-button icon="el-icon-remove-outline" type="danger" size="mini" v-privilege="activeMenu + 'deleteDep'" @click="deleteData2">删除</el-button>
           <el-button icon="el-icon-check" type="goon" size="mini" :loading='extractLoading' @click="extract">提取分析项目</el-button>
           </div>
         </div>
         <div class="common-table-div" style="margin-bottom:0;margin-top:0">
            <el-table v-loading="dataLoading2" ref="dataTable2" border :height="height_bot" @row-click='saveData' highlight-current-row  :data="table.list2" :icore-filter-flag="icoreFilterFlag"
            :header-cell-style="tableHeaderCellStyle" :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="160px" prop="anlyItemName" label="分析项目" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="minSign" label="下限符" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="minValue" label="最小值" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="maxSign" label="上限符" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="maxValue" label="最大值" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="memo" label="备注" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="createMan" label="创建人" align="center"></el-table-column>
             <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间" align="center"></el-table-column>
           </el-table>
         </div>
         <!-- <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-col>
    </el-row>
    <el-dialog @close="cancel" :visible.sync="dialogTableVisible">
      <div slot="title" class="titleBox">
        <i class="el-icon-edit-outline" style="font-size: 20px"></i>
        <!-- <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/more.png' /> -->
        <span style="margin-left:10px;font-size:18px">修改</span>
      </div>
      <el-form ref="baseData" label-width="80px" :model="baseData">
        <el-row>
          <el-col :span="12">
            <el-form-item label="上限符">
              <el-select v-model="baseData.maxSign" filterable collapse-tags size="small">
                <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" size="small" style="width: 100%;" oninput ="value=value.replace(/[^0-9.]/g,'')" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="下限符">
              <el-select v-model="baseData.minSign" filterable collapse-tags size="small">
                <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" size="small" oninput ="value=value.replace(/[^0-9.]/g,'')" style="width: 100%;" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="baseData.memo" size="small" style="width: 100%;" placeholder="请输入"></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='modifyLoading' @click="modify()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel">取消</el-button>
      </span>
    </el-dialog>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" :Params2="Params2" @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: [],
        list3: []
      },
      extractLoading:false,
      dialogTableVisible:false,
      baseData:{},
      saveRow:{},
      returnSubLoading:false,
      returnSubLoading1:false,
      dataLoading: false,
      dataLoading2: false,
      dataLoading3: false,
      subLoading:false,
      subLoading1:false,
      icoreFilterFlag: true,
      minSignType: [
        {minSign: '>='},
        {minSign: '>'}
      ],
      maxSignType: [
        {maxSign: '<='},
        {maxSign: '<'}
      ],
      page: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      page3: {
        pageSize: 200,
        pageNum: 1,
        totalPage: 0
      },
      modifyLoading:false,
      savaDep:{},
      list: [],
      planId: '',
      showFlag: false,
      Params: {},
      showFlag2: false,
      Params2: {},
      entrOrgNameType: [],
      entrOrgNameType1: [],
      sampleTypeNameType: [],
      search: {
        planDate: [],
        planCompanyNo: 'G31500000',
        matName:'',
        contractNo:'',
        suppName:''
      },
      height_top:0,
      height_bot:0,
      height_top2:0,
      contractData:{},
      activeMenu:''
    }
  },
  created() {
    this.height_top = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;
    this.height_bot = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;
    this.height_top2 = window.innerHeight - 130 < 500 ? 500 : window.innerHeight - 130
    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.entrOrgNameType = response.data
    });
    this.searchData();
    this.mainData()
    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;
        } 
        if (column.property === "netWgt") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].netWgt ? data[i].netWgt : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } 
      });
      return sums;   
    },
    refresh () {
      this.mainData();
    },
    refresh2 () {
      this.depData(this.planId);
    },
    addData () {
      this.showFlag = !this.showFlag;
      this.Params = null;
      this.Params2 = {}
    },//修改
    modifyData () {
      if (JSON.stringify(this.saveRow)==="{}") {
        this.$message.warning('请点击选中一条您要修改的数据')
        return
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning('数据已提交，不可进行修改')
        return
      }
      if (this.saveRow.stateFlag == 4) {
        this.$message.warning('数据已审核，不可进行修改')
        return
      }
      this.Params = this.saveRow
      this.showFlag = !this.showFlag;
    },//删除
    deleteData () {
       if (JSON.stringify(this.saveRow)==="{}") {
        this.$message.warning('请点击选中一条您要删除的数据')
        return
       }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning('数据已提交，不可进行删除')
        return
      }
       if (this.saveRow.stateFlag == 4) {
        this.$message.warning('数据已审核，不可进行删除')
        return
      }
      this.subLoading = true
      this.axios.delete('pass/testManagement/v1/limstestplans/deleteplan/' + this.saveRow.planId).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)
      })
    },//审核
    audit () {
      if (JSON.stringify(this.saveRow)==="{}") {
        this.$message.warning('请点击选中一条您要审核的数据')
        return
      }
      if (this.saveRow.stateFlag != 4) {
        this.$message.warning('数据不需要审核，不可进行审核操作')
        return
      }
      if (this.saveRow.cnsnContactMan == '0'){
        this.$message.warning('数据不要检验，不可进行审核操作')
        return
      }
      this.subLoading1 = true
      this.saveRow.stateFlag = 1
      this.axios.post('pass/testManagement/v1/limstestplans/JLsaveLimsTestPlan', this.saveRow,{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.subLoading1 = false
      }).catch(e => {
        this.subLoading1 = false
       this.$message.error(e.message)
      })
    },//取消审核
    noaudit () {
      if (JSON.stringify(this.saveRow)==="{}") {
        this.$message.warning('请点击选中一条您要取消审核的数据')
        return
      }
      if (this.saveRow.stateFlag != 1) {
        this.$message.warning('数据未提交，不可进行取消审核操作')
        return
      }

      this.saveRow.stateFlag = 4
      this.returnSubLoading = true
      this.axios.post('pass/testManagement/v1/limstestplans/cancelSaveLimsTestPlan', this.saveRow,{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.returnSubLoading = false
      }).catch(e => {
        this.returnSubLoading = false
       this.$message.error(e.message)
      })
    },
    //提交
    submitData () {
      if (JSON.stringify(this.saveRow)==="{}") {
        this.$message.warning('请点击选中一条您要提交的数据')
        return
      }
      if (this.saveRow.stateFlag != 0) {
        this.$message.warning('数据不是编辑状态，不可进行提交操作')
        return
      }
      this.subLoading = true
      //表示需要检验
      if (this.saveRow.cnsnContactMan == '1' || this.saveRow.cnsnContactMan == ''){
        if (this.table.list2.length < 1) {
          this.$message.warning('分析项目表格中无数据，无法进行提交操作，请先新增分析项目数据')
          this.subLoading = false
          return
        }
        this.axios.post('pass/testManagement/v1/limstestplans/resultLimsTestPlan', this.saveRow,{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)
        })
      }else{
        this.saveRow.stateFlag = 1
        this.axios.post('pass/testManagement/v1/limstestplans/JLsaveLimsTestPlan', this.saveRow,{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)
        })
      }
    },
    // 取消提交
    returnSubmit () {
       if (JSON.stringify(this.saveRow)==="{}") {
        this.$message.warning('请点击选中一条您要取消提交的数据')
        return
       }
      if (this.saveRow.cnsnContactMan == '1'){
        if (this.saveRow.stateFlag == 1) {
          this.$message.warning('检验数据，先取消审核')
          return
        }
        if (this.saveRow.stateFlag != 4) {
          this.$message.warning('数据未提交，不可进行取消提交操作')
          return
        }
        this.returnSubLoading = true
        this.axios.post('pass/testManagement/v1/limstestplans/noResultLimsTestPlan', this.saveRow,{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.returnSubLoading = false
        }).catch(e => {
          this.returnSubLoading = false
        this.$message.error(e.message)
        })
        this.returnSubLoading = false
      }else{
        this.saveRow.stateFlag = 0
        this.axios.post('pass/testManagement/v1/limstestplans/cancelSaveLimsTestPlan', this.saveRow,{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.returnSubLoading = false
          }).catch(e => {
            this.returnSubLoading = false
          this.$message.error(e.message)
        })
      }
    },
    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
    },
    // 检验项目修改功能弹窗
    changeData(){
      if (JSON.stringify(this.savaDep)==="{}") {
        this.$message.warning('请点击选中一条检验项目数据')
        return
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning('数据已提交，不可进行删除')
        return
      }
      this.baseData = Object.assign({},this.savaDep)
      this.dialogTableVisible = true
    },
    //修改确认操作
    modify(){
      this.modifyLoading = true
      this.axios.post('pass/testManagement/v1/limstestplands/saveLimsTestPlanD',this.baseData,{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message);
          this.cancel()
          this.depData(this.planId)
        } else {
         this.$message.error(res.message)
        }
        this.modifyLoading = false
      }).catch(e => {
        this.modifyLoading = false
        this.$message.error(e.message)
      })
    },
    cancel(){
      this.modifyLoading = false
      this.dialogTableVisible = false
    },
    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/limstestplands/deleteLimsTestPlanD?id='+this.savaDep.id,{individualType: 'json'}).then(res => {
            if (res.succeed) {
             this.$message.success('删除成功');
             this.depData(this.planId)
            } else {
             this.$message.error(res.message)
            }
            }).catch(e => {
             this.$message.error(e.message)
           })
        }).catch(() => {});
    },
    //提取分析项目
    extract(){
      if (JSON.stringify(this.saveRow)==="{}") {
        this.$message.warning("请先点击选中一条原检计划信息数据");
        return;
      }
      if (this.saveRow.stateFlag == 1) {
        this.$message.warning('数据已提交，不可进行操作')
        return
      }
      this.extractLoading = true
      this.axios.get('pass/testManagement/v1/limstestplands/batchsaveLimsPlanDByMatNo',{params:{matNo:this.saveRow.matNo,planId:this.saveRow.planId}},{individualType: 'json'}).then(res => {
        if (res.code== 0 || res.code == 200) {
          this.$message.success(res.message);
          this.depData(this.planId)
        } else {
         this.$message.error(res.message)
        }
        this.extractLoading = false
      }).catch(e => {
        this.extractLoading = false
        this.$message.error(e.message)
      })
    },
    searchData(){
      this.mainData()
    },
    mainData () {
      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'
      }
      let obj = {
        object:{
          planCompanyNo:this.search.planCompanyNo,
          matName:this.search.matName,
          planTypeCode:481704,
          contractNo:this.search.contractNo,
          suppName:this.search.suppName
        },
        'startTime': this.startTime,
        'endTime':this.endTime,
        pageIndex:this.page.pageNum,
        pageSize:this.page.pageSize
      }
      this.saveRow = {}
      this.dataLoading = true;
      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.stateFlag1 = item.stateFlag === '0' ? '编辑' : item.stateFlag === '1' ? '已审核' : item.stateFlag === '4' ? '待审核' : ''
          item.cnsnContactMan1 = item.cnsnContactMan === '0' ? '否' : item.cnsnContactMan === '1' ? '是' : ''
          item.isCiq1 = item.isCiq === '0' ? '否' : item.isCiq === '1' ? '是' : ''
          item.isBatch1 = item.isBatch === '0' ? '否' : item.isBatch === '1' ? '是' : ''
          item.isSmp1 = item.isSmp === '0' ? '否' : item.isSmp === '1' ? '是' : ''
          item.isPrep1 = item.isPrep === '0' ? '否' : item.isPrep === '1' ? '是' : ''
          item.isCheck1 = item.isCheck === '0' ? '否' : item.isCheck === '1' ? '是' : ''
          item.isMater1 = item.isMater === '0' ? '否' : item.isMater === '1' ? '是' : ''
          item.planDate1 = formatDate(item.planDate, 'yyyy-MM-dd')
        })
        if (this.table.list.length > 0) {
          this.$refs.dataTable.setCurrentRow(this.table.list[0])
          this.searchFollow(this.table.list[0])  
        }
        this.page.totalPage = res.data.total;
        }).catch(e => {
          this.dataLoading = false;
        });
    },
    searchFollow(row) {
      this.saveRow = row
      this.planId = row.planId ? row.planId : ''
      this.page2.pageNum = 1
      this.page2.pageSize = 50
      this.depData(this.planId)
    },
    depData(planId){
      this.savaDep = {}
      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.validFlag1 = 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.planCompanyNo = 'G31500000';
      this.search.matName = ''
      this.search.suppName = ''
      this.search.contractNo = ''
      this.searchData();
    },
    saveDataMain(row){
      this.saveRow = Object.assign({},row)
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.mainData();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.mainData();
    },
    saveData(row){
      this.savaDep = Object.assign({},row)
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.depData(this.planId);
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.depData(this.planId);
    },
    // saveContractData (val) {
    //   this.contractData = val
    // },
    addScreen () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    addScreen2 () {
     this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable2.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    tableRowClassName ({
        row, column, rowIndex, columnIndex
      }) {
        if (columnIndex === 13) {
        if (row.validFlag !== '1') {
          return 'error-row';
        }
        }
        if (columnIndex === 1) {
        if (row.stateFlag === '1') {
          return 'error-green';
        }
        return '';
        }
      },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
