<!-- 湿法测试 -->
<template>
  <div class="examination"> 
    <div class="common-head-search">
      <el-form  :inline="true" @submit.native.prevent ref="searchForm" :model="searchForm" class="demo-form-inline sui-search-form">
        <el-form-item label="样品名称">
          <el-input v-model="searchForm.matName" @keyup.enter.native="searchData()" size="small" placeholder="请输入查询内容" style="width: 150px;"></el-input>
        </el-form-item>
        <el-form-item label="样品类型">
         <el-select v-model="searchForm.sampleTypeCode" clearable filterable collapse-tags size="small" style="width:150px;" placeholder="请选择查询内容">
            <el-option v-for="item in sampleTypeNameType" :key="item.baseName" :label="item.baseName"
              :value="item.baseCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="送样日期">
          <el-date-picker
           v-model="searchForm.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="resetData">重置</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-check" type="goon" :loading='submitLoading' @click="subData" v-privilege="activeMenu + 'submit'" size="mini">提交</el-button>
            <!-- <el-button icon="el-icon-check" type="goon" @click="retest" size="mini">重测</el-button>
            <el-button icon="el-icon-check" type="goon" @click="collectData" size="mini">数据采集</el-button> -->
          </div>
          <div>
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
           <el-table v-loading="tableLoading2" ref="table2" :cell-class-name="tableRowClassName" @selection-change="SelectionValues" border @row-click="searchAnalyze" :height="theight2" highlight-current-row  :data="tableData2" :icore-filter-flag="icoreFilterFlag"
           :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries2" show-summary>
            <el-table-column type="index" label="NO" align="center"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="id" label="编号"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="matName" label="物料名称"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="80" align='center' prop="sampleTypeName" label="样品类型" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="80" align="center" prop="stateFlagName" label="状态"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="80" align='center' prop="testItemName" label="任务名称" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="120" align='center' prop="sampleNo" label="样品号" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="testItemName" label="任务名称"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="stdName" label="方法" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="eqpName" label="仪器类型" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="testPostName" label="分析岗位" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="testDirection" label="测试部门" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align='center' prop="testOrder" label="测试顺序" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="memo" label="备注" ></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="createMan" label="创建人" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="createTime" label="创建时间" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="updateMan" label="修改人" align="center"></el-table-column>
            <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="updateTime" label="修改时间" align="center"></el-table-column>
          </el-table>
          <div class="common-foot-style">
            <el-pagination
              @size-change="handleSizeChangeDep"
              @current-change="handleCurrentChangeDep"
              :current-page="pageIndex_dep"
              :page-sizes="[10, 20, 30, 40, 100 , 200]"
              :page-size="pageSize_dep"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total_dep"
              background
            ></el-pagination>
          </div>
        </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-check" :loading='saveLoading' @click="saveData" type="goon" size="mini">保存</el-button> -->
            <!-- <el-button icon="el-icon-check" type="goon" size="mini" @click="oldRecord">原始记录</el-button> -->
          </div>
          <div>
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
           <el-table v-loading="tableLoading3"  border :height="theight3" highlight-current-row  :data="tableData3" :icore-filter-flag="icoreFilterFlag"
           :header-cell-style="tableHeaderCellStyle" @row-click="selectAnalyze" @row-dblclick='showCell' :row-class-name="tableRowName" :summary-method="getSummaries2" show-summary>
            <el-table-column type="index" label="NO" align="center"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="testItemName" label="任务名称" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="anlyItemName" label="分析项目" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="anlyValue" label="报出值" >
              <template slot-scope="{row}">
                <el-input :disabled='analyzeVal.stateFlag != 0' type='number' :min="0" :controls="false" oninput ="value=value.replace(/[^0-9.]/g,'')" v-if="row.index === tabClickIndex" @blur="saveCell" v-model="row.anlyValue" @keyup.enter.native="saveCell" size="small" style="width: 100%;"></el-input>
                <span v-else>{{row.anlyValue}}</span>
              </template>
            </el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="dasValue" label="采集值" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="cptValue" label="计算值" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="reviseValue" label="修约值" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="unitName" label="单位"></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="formulaName" label="计算公式" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="reviseRuleName" label="修约规则" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="isReportName" label="是否报出" ></el-table-column>
            <el-table-column :show-overflow-tooltip="true" sortable min-width="100" align="center" prop="isAlarmName" label="是否报警" ></el-table-column>
          </el-table>
        </div>
      </el-col>  
    </el-row>
    <el-dialog :close-on-click-modal='false' @close="closeTest" width='80%' :visible.sync="testShow">
        <div slot="title" class="titleBox">
        <i class='el-icon-document' style="font-size: 20px"></i>
        <span style="margin-left:10px;font-size:18px">重测</span>
        </div>
        <el-row>
          <el-col :span='24'>
            <div class="common-title-name">
                <img style="width: 25px; height: 25px; margin-left: 20px" src='../../../assets/img/imgScreen/logo.png' />
                 任务名称
                <el-input v-model="testItemName2" size="small" placeholder="请输入查询内容" @keyup.enter.native="getDataLists2()" style="width: 150px"></el-input>
            </div>
            <el-table v-loading="dataLoading" ref="dataTable" border @row-click='clickResetData' :height="heightTop" highlight-current-row :data="table.listTests"
            :header-cell-style="tableHeaderCellStyle" :icore-filter-flag="icoreFilterFlag">
             <el-table-column type="index" label="NO" align="center"></el-table-column>
             <el-table-column min-width="120px" :show-overflow-tooltip="true" sortable prop="testItemName" label="测试名称" align="center"></el-table-column>
             <el-table-column min-width="120px" :show-overflow-tooltip="true" sortable prop="itemTypeName" label="项目类型" align="center"></el-table-column>
            </el-table>
            <div style="margin-top: 20px; margin-left: 10px">
                <el-pagination style="float:right" @size-change="SizeTest" @current-change="pageChangeTest"
                  :current-page="pageTests.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="pageTests.pageSize" layout="total, sizes, prev, pager, next"
                  :total="pageTests.totalPage" background>
                </el-pagination>
            </div>
          </el-col>
        </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" :loading='addRetestLoading' icon="el-icon-check" @click="addtestData()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="testCancel">取消</el-button>
      </span>
    </el-dialog>
    <!-- 数据采集 -->
    <el-dialog :close-on-click-modal='false' @close="CollectionCancel" width='90%' :visible.sync="collectionShow">
        <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 :inline='true' :model="collet" ref="collet" :rules='ruleData'>
          <el-form-item prop='eqpTypeCode' label='设备类型'>
            <el-select v-model="collet.eqpTypeCode" @change='selectFaclity' filterable collapse-tags size="small" style="width:200px;" placeholder="">
              <el-option
              v-for="item in facilityType"
              :key="item.baseCode"
              :label="item.baseName"
              :value="item.baseCode">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop='eqpNo' label='设备名称'>
            <el-select v-model="collet.eqpNo" clearable filterable collapse-tags size="small" style="width:200px;" placeholder="">
              <el-option
              v-for="item in eqpType"
              :key="item.eqpNo"
              :label="item.eqpName + ` (${item.memo})`"
              :value="item.eqpNo">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="goon" size="mini" :loading='collectionLoading' @click="searchcollection">查询</el-button>
          </el-form-item>
        </el-form> 
        <el-row :gutter='10'>
          <el-col :span='8'>
            <div class="common-title-name">
              <img style="width: 25px; height: 25px; margin-left: 20px" src='../../../assets/img/imgScreen/logo.png' />
              <span>数据采集</span>
            </div>
            <el-table ref="dataTable" border :height="heightTop" @selection-change="SelectionCllotData" highlight-current-row :data="table.collectionData"
            :header-cell-style="tableHeaderCellStyle" :icore-filter-flag="icoreFilterFlag" :summary-method="getSummaries2" show-summary>
              <el-table-column type="index" label="NO" align="center"></el-table-column>
              <el-table-column width="50px" :show-overflow-tooltip="true" label="操作" align="center">
                <template slot-scope="scope">
                  <el-button type="text" style="padding:0" @click="moveRight(scope.$index, scope.row)">右移</el-button>
                </template>
              </el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="collSampleNo" label="采集样号" align="center"></el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="createTime" label="采集时间" align="center"></el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="eqpName" label="采集设备" align="center"></el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="pointName" label="采集位置" align="center"></el-table-column>
              <el-table-column min-width="80px" :show-overflow-tooltip="true" prop="stateFlagName" label="状态" align="center"></el-table-column>
            </el-table>
          </el-col>
          <el-col :span='8'>
            <div class="common-title-name">
              <img style="width: 25px; height: 25px; margin-left: 20px" src='../../../assets/img/imgScreen/logo.png' />
              <span>采集信息</span>
            </div>
            <el-table border :height="heightTop" highlight-current-row :data="table.selectCollectionData"
            :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries2" show-summary>
              <el-table-column type="index" label="NO" align="center"></el-table-column>
              <el-table-column width="120px" :show-overflow-tooltip="true" label="操作" align="center">
                <template slot-scope="scope">
                  <el-button type="text" style="padding:0" :disabled="scope.$index == 0" @click="moveUpward(scope.row, scope.$index)">上移</el-button>
                  <el-button type="text" style="padding:0" :disabled="(scope.$index + 1) == table.selectCollectionData.length" @click="moveDown(scope.row, scope.$index)">下移</el-button>
                  <el-button type="text" style="padding:0" @click="moveleft(scope.$index, scope.row)">删除</el-button>
                </template>
              </el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="collSampleNo" label="采集样号" align="center"></el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="createTime" label="采集时间" align="center"></el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="eqpName" label="采集设备" align="center"></el-table-column>
              <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="pointName" label="采集位置" align="center"></el-table-column>
              <el-table-column min-width="80px" :show-overflow-tooltip="true" prop="stateFlagName" label="状态" align="center"></el-table-column>
            </el-table>
          </el-col>
          <el-col :span='8'>
            <div class="common-title-name">
              <img style="width: 25px; height: 25px; margin-left: 20px" src='../../../assets/img/imgScreen/logo.png' />
              <span>样品信息</span>
            </div>
            <el-table ref="dataTable" border :height="heightTop" highlight-current-row :data="table.sampleData" :summary-method="getSummaries2" show-summary
            :header-cell-style="tableHeaderCellStyle">
             <el-table-column type="index" label="NO" align="center"></el-table-column>
             <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="sampleNo" label="样号" align="center"></el-table-column>
             <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="matName" label="物料名称" align="center"></el-table-column>
             <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="testItemName" label="任务名称" align="center"></el-table-column>
             <el-table-column min-width="120px" :show-overflow-tooltip="true" prop="" label="测试顺序" align="center"></el-table-column>
            </el-table>
          </el-col>
        </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="goon" size="mini" :loading='addCollectionLoading' icon="el-icon-check" @click="addCollection()">确定</el-button>
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="CollectionCancel">取消</el-button>
      </span>
    </el-dialog>
    <el-dialog  width='80%' :visible.sync="dialogTableVisible">
      <div slot="title" class="titleBox">
        <i class="el-icon-document" style="font-size: 20px"></i>
        <span style="color:#fff;font-size:16px">新增原始记录</span>
        <span style="margin-left:40px">检验方法</span>
        <el-input v-model="func" size="small" style="width: 150px;"></el-input>
      </div>
      <el-table v-loading="tableLoading4" ref="dataTable4" border  height="350" highlight-current-row  :data="tableData4" :icore-filter-flag="icoreFilterFlag"
           :header-cell-style="tableHeaderCellStyle" @selection-change="selectTest" :summary-method="getSummaries2" 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 prop="eqpName" label="仪器名称" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="eqpNo" label="仪器编号" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="collSampleNo" label="采集样号" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="createTime" label="创建时间" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="anlyItemNo" label="分析项目编号" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="anlyItemName" label="分析项目名称" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="" label="分析值" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="" label="显示顺序" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="" label="度量单位" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="formulaName" label="计算公式" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="" label="修约规则" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="" label="输出类型" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="" label="分析值" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
          </el-table>
          <div slot="footer" class="dialog-footer">
            <el-button icon="el-icon-check" type="goon" size="mini" @click="dialogFormVisible = false">确定</el-button>
            <el-button size="mini" @click="cancel">取消</el-button>
          </div>
    </el-dialog>
  </div>
</template>
<script>
import {getCookie,formatDate} from '@/utils/util.js';
import {cookieUserId,cookieUserName} from '@/config/config.js'
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  data () {
    return {
      searchForm: {
        times: '',
        matName: '',
        sampleTypeCode:'',
        eqpNo:''
      },
      collet:{
        eqpTypeCode:'',
        eqpNo:''
      },
      ruleData: {
        eqpTypeCode: [{ required: true, message: '不能为空', trigger: 'change' },],
        eqpNo: [{ required: true, message: '不能为空', trigger: 'change' }],
      },
      table:{
        listTests:[],
        collectionData:[],
        selectCollectionData:[],
        sampleData:[]
      },
      collectionLoading: false,
      eqpType:[],
      facilityType:[],
      selectVal:[],
      testShow:false,
      checked:true,
      saveValue:'',
      saveMainData:[],
      cllotData:[],
      addRetestLoading:false,
      dataLoading:false,
      sampleLoading:false,
      saveLoading:false,
      submitLoading:false,
      sampleTypeNameType: [],
      analyzeVal:{},
      analyzeValues:{},
      dialogTableVisible:false,
      theight1: 0,
      theight2: 0,
      theight3: 0,
      testItemName2:'',
      pageTests: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      collectionShow:false,
      addCollectionLoading:false,
      tableLoading1:false,
      tableLoading2:false,
      tableLoading3:false,
      tableLoading4:false,
      tabClickIndex:null,
      func:'',
      originalData:[],
      tableData1:[],
      tableData2:[],
      tableData3:[],
      tableData4:[],
      pageIndex: 1,
      pageSize:100,
      total_main:0,
      pageIndex_dep: 1,
      pageSize_dep:100,
      total_dep:0,
      icoreFilterFlag: true,
      heightTop:0,
      activeMenu:''
    }
  },
  created() {
    this.theight2 = window.innerHeight / 2 - 110 < 249 ? 249 : window.innerHeight / 2 - 110;
    this.theight3 = window.innerHeight / 2 - 110 < 249 ? 249 : window.innerHeight / 2 - 110;
    this.theight1 = window.innerHeight / 2 - 110 < 249 ? this.theight2 *2 + 40 : window.innerHeight - 155;
    this.heightTop = window.innerHeight/2 - 130 < 249 ? 249 : window.innerHeight/2 - 130
    this.searchForm.times = [this.getYNM(new Date()), this.getYNM(new Date())]
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
  },
  mounted () {
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4801}, {individualType: 'json'}).then(res => {
      this.sampleTypeNameType = res.data
    })
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4808}, {individualType: 'json'}).then(res => {
      this.facilityType = res.data
    })
    this.searchData()
    this.getDataLists2()
  },
  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}`;
    },
    getSummaries2(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
        }
        if (index === 1) {
          sums[index] = data.length;
        } else if (column.property === "quantity") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].quantity ? data[i].quantity : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        } else if (column.property === "factweight") {
          let val = 0;
          for (let i in data) {
            val = this.floatComputed(
              data[i].factweight ? data[i].factweight : 0,
              val,
              "+"
            );
          }
          sums[index] = val;
        }
      });
      return sums;
    },
    selectFaclity(val){
        this.eqpType = []
        this.collet.clearFlag ? '' : this.collet.eqpNo = ''
        if (!val) {
          return 
      }
      this.axios.post('pass/baseManagement/v1/limslrceqpinfos/queryeqpName',{object:{validFlag:1,eqpTypeCode:val},pageIndex:1,pageSize:99999},{individualType: 'json'}).then(res => {
        this.eqpType = res.data;
      })
    },
    resetData(){
      this.searchForm.matName = ''
      this.searchForm.sampleTypeCode = ''
      this.searchForm.eqpNo = ''
      this.searchForm.times = [this.getYNM(new Date()), this.getYNM(new Date())]
      this.searchData()
    },
    SelectionValues(val){
      this.selectVal = val
    },
    //点击选中样品信息数据
    searchFollow(val){
      this.saveMainData = val
    },
    //接样
    recSample(){
      if (this.saveMainData.length < 1) {
        this.$message.warning('请先勾选您要接样的数据')
        return
      }
      this.sampleLoading = true
      this.axios.post('pass/testManagement/v1/limssampletests/pickUpSample',this.saveMainData,{individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
        }else{
          this.$message.error(res.message)
        }
        this.sampleLoading = false
      }).catch(err =>{
        this.sampleLoading = false
        this.$message.error(err.message)
      })
    },
    //提交
    subData(){
      if (JSON.stringify(this.analyzeVal)==="{}") {
        this.$message.warning("请先点击选中一条测试项目数据");
        return;
      }
      if (this.analyzeVal.stateFlag == 3) {
        this.$message.warning("已提交的数据不能进行提交操作,请选择状态为未处理的数据进行操作");
        return;
      }
      this.submitLoading = true
      this.axios.post('pass/testManagement/v1/limssampletests/submit?stId=' + this.analyzeVal.stId,{individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
        }else{
          this.$message.error(res.message)
        }
        this.submitLoading = false
      }).catch(err =>{
        this.submitLoading = false
        this.$message.error(err.message)
      })
    },
    closeTest(){
      this.table.addTest = []
      this.addList = []
      this.testShow = false
      this.addRetestLoading = false
      this.ResetData = {}
      this.getDataLists2()
    },
    //关闭弹窗
    testCancel(){
      this.table.addTest = []
      this.addList = []
      this.testShow = false
      this.addRetestLoading = false
      this.ResetData = {}
    },
    //重测打开弹窗
    retest(){
      if (JSON.stringify(this.analyzeVal)==="{}") {
        this.$message.warning("请先点击选中一条测试项目数据");
        return
      }
      if (this.analyzeVal.stateFlag == 3) {
        this.$message.warning("已提交的数据不能进行重测操作,请选择状态为未处理的数据进行操作");
        return;
      }
      this.testShow = true
    },
    //点击选中重测弹窗中的数据
    clickResetData(val){
      this.ResetData = val
    },
    //重测确定操作
    addtestData(){
      if (JSON.stringify(this.ResetData)==="{}") {
        this.$message.warning("请先点击选中一条数据进行重测");
        return
      }
      this.addRetestLoading = true
      this.axios.post('pass/testManagement/v1/limssampletests/resurvey/'+this.analyzeVal.id,this.ResetData,{individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
          this.testCancel()
        }else{
          this.$message.error(res.message)
        }
        this.addRetestLoading = false
      }).catch(err =>{
        this.addRetestLoading = false
        this.$message.error(err.message)
      })
    },
    //查询采集数据
    searchcollection(){
      this.$refs.collet.validate((valid) => {
        if (valid) {
          this.table.collectionData = []
          this.table.selectCollectionData = []
          let obj = {
            object:{
              eqpTypeCode:this.collet.eqpTypeCode,
              eqpNo:this.collet.eqpNo,
              stateFlag:0
            },
            pageIndex:1,
            pageSize:999
          }
          this.collectionLoading = true
          this.axios.post('pass/testManagement/v1/limsdataparses/querylimsDataPase',obj,{individualType: 'json'}).then(res =>{
            if (res.code == 0 || res.code == 200) {
              this.table.collectionData = res.data.list
              this.table.collectionData.forEach(item =>{
                item.stateFlagName = item.stateFlag == 0 ? '未读' : item.stateFlag == 1 ? '已读' : ''
              })
            }else{
              this.$message.error(res.message)
            }
            this.collectionLoading = false
          }).catch(err =>{
            this.collectionLoading = false
            this.$message.error(err.message)
          })
        }
      })
    },
    collectData(){
      if (this.selectVal.length < 1) {
        this.$message.warning('请勾选测试项目的数据')
        return
      }
      this.table.sampleData = JSON.parse(JSON.stringify(this.selectVal))
      this.collectionShow = true
    },
    //勾选数据采集信息数据
    SelectionCllotData(val){
      this.cllotData = val
    },
    //右移
    moveRight(index,row){
      // 在数据采集表中删除,添加到选中的采集信息表中
      this.table.collectionData.splice(index,1)
      this.table.selectCollectionData.push(row)
    },
    //上移
    moveUpward(row, index) {
      if (index > 0) {
          let upData = this.table.selectCollectionData[index - 1];
          this.table.selectCollectionData.splice(index - 1, 1);
          this.table.selectCollectionData.splice(index, 0, upData);
      } else {
        this.$message({message: '已经是第一条，上移失败',type: 'warning'});
      }
    },
    //下移
    moveDown(row, index) {
      if ((index + 1) == this.table.selectCollectionData.length) {
          this.$message({message: '已经是最后一条，下移失败',type: 'warning' });
      } else {
          let downData = this.table.selectCollectionData[index + 1];
          this.table.selectCollectionData.splice(index + 1, 1);
          this.table.selectCollectionData.splice(index, 0, downData);
      }
    },
    //删除
    moveleft(index,row){
      // 在采集信息表表中删除,添加到选中的数据采集表中
      this.table.selectCollectionData.splice(index,1)
      this.table.collectionData.push(row)
    },
    //采集信息确定
    addCollection(){
      if (this.table.sampleData.length  !== this.table.selectCollectionData.length ) {
        this.$message.warning('样品信息表中的数据与采集信息表中的数据不相等，请按照顺序对应上')
        return
      }
      let tempArr = []
      this.table.sampleData.map((item,index) =>{
        tempArr.push({
          stId:item.stId,
          sampleNo:item.sampleNo,
          psId:this.table.selectCollectionData[index].psId
          })
      })
      this.addCollectionLoading = true
      this.axios.post('pass/testManagement/v1/limssampletests/datagather',tempArr,{individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.CollectionCancel()
          this.searchcollection()
          this.searchData()
        }else{
          this.$message.error(res.message)
        }
        this.addCollectionLoading = false
      }).catch(err =>{
        this.addCollectionLoading = false
        this.$message.error(err.message)
      })
    },
    //采集信息取消
    CollectionCancel(){
      this.collectionShow = false
      this.addCollectionLoading = false
      this.table.sampleData = []
      this.table.selectCollectionData = []
    },
    //保存
    saveData(){
      if (this.tableData3.length < 1) {
        this.$message.warning("表格中无数据，无法进行保存");
        return;
      }
      if (this.analyzeVal.stateFlag == 3) {
        this.$message.warning("已提交的数据不能进行保存,请选择状态为未处理的数据进行操作");
        return;
      }
      this.saveLoading = true
      this.axios.post('pass/testManagement/v1/limssampletestds/updateLimsSampleTestDList',this.tableData3,{individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
        }else{
          this.$message.error(res.message)
        }
        this.saveLoading = false
      }).catch(err =>{
        this.saveLoading = false
        this.$message.error(err.message)
      })
    },
    //查询操作
    searchData (){
      this.pageIndex = 1
      this.pageSize = 100
      this.pageSize_dep = 100
      this.pageIndex_dep = 1
      this.dataMain()
      this.dataDep()
    },
    //查询样品信息表格
    dataMain () {
      // this.saveMainData = {} 
      let startTime = ''
      let endTime = ''
      if (!this.searchForm.times) {
        startTime = null
        endTime = null
      }else{
        startTime = this.searchForm.times[0] + ' 00:00:00'
        endTime = this.searchForm.times[1] + ' 23:59:59'
      }
      let obj = {
        'object':{
          'matName': this.searchForm.matName,
          'sampleTypeCode': this.searchForm.sampleTypeCode,
          'functionCode':'484017',
          'isCtrl':1,
          'stateFlag':1,
          'optNo':userId
        },
        "pageSize": this.pageSize,
        "pageIndex": this.pageIndex,
        'startTime': startTime,
        'endTime':  endTime 
      }
      this.tableLoading1 = true;
      this.axios.post('pass/testManagement/v1/limstasktests/queryLimsTaskTestPage',obj,{individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.tableData1 = res.data.list
          this.total_main = res.data.total
        }else{
          this.$message.error(res.message)
        }
        this.tableLoading1 = false;
      }).catch(err =>{
        this.tableLoading1 = false;
        this.$message.error(err.message)
      })
    },
    //查询测试项目表格
    dataDep () { 
      this.tableData3 = []
      let startTime = ''
      let endTime = ''
      if (!this.searchForm.times) {
        startTime = ''
        endTime = ''
      }else{
        startTime = this.searchForm.times[0] + ' 00:00:00'
        endTime = this.searchForm.times[1] + ' 23:59:59'
      }
      let obj = {
        'object':{
          'matName': this.searchForm.matName,
          'sampleTypeCode': this.searchForm.sampleTypeCode,
          'isCtrl':1,
          'createNo':userId
        },
        'list':[0,3],
        'list2':[484017],
        "pageSize": this.pageSize_dep,
        "pageIndex": this.pageIndex_dep,
        'startTime': startTime,
        'endTime':  endTime 
      }
      this.tableLoading2 = true;
      this.axios.post('pass/testManagement/v1/limssampletests/queryLimsSampleTestPage',obj,{individualType: 'json'}).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.tableData2 = res.data.list
          this.total_dep = res.data.total
          this.tableData2.forEach(item =>{
            item.stateFlagName = item.stateFlag == '0' ? '未处理' : item.stateFlag == '3' ? '已提交' : ''
          })
          
          if (this.tableData2.length > 0) {
            this.$refs.table2.setCurrentRow(this.tableData2[0])
            this.searchAnalyze(this.tableData2[0])
          }
        }else{
          this.$message.error(res.message)
        }
        this.tableLoading2 = false;
      }).catch(err =>{
        this.tableLoading2 = false;
        this.$message.error(err.message)
      })
    },
    //点击测试项目，查询分析项目
    searchAnalyze(row){
      //保存点击的样品信息数据，保存、提交操作时刷新
      this.analyzeVal = row
      this.tableLoading3 = true;
      this.axios.post('pass/testManagement/v1/limssampletestds/queryLimsSampleTestDList?stId='+this.analyzeVal.id).then(res =>{
        if (res.code == 0 || res.code == 200) {
          this.tableData3 = res.data
          this.tableData3.forEach(item =>{
            item.anlyValue = item.anlyValue ? item.anlyValue : item.defaultValue
            item.isReportName = item.isReport == 0 ? '否' : item.isReport == 1 ? '是' : ''
            item.isAlarmName = item.isAlarm == 0 ? '否' : item.isAlarm == 1 ? '是' : ''
          })
        }else{
          this.$message.error(res.message)
        }
        this.tableLoading3 = false;
      }).catch(err =>{
        this.tableLoading3 = false;
        this.$message.error(err.message)
      })
    },
    //表格数据右移
    rightData2 (row) {
      //新增的数据清空id
      row.cretNoD = ''
      this.table.addTest.push(row)
    },
    //查询重测数据
    getDataLists2() {
      this.pageTests.pageNum = 1
      this.getDataListTest2()
    },
    //重测数据接口
    getDataListTest2 () {
      let obj = {
        object:{
          validFlag:1,
          testItemName:this.testItemName2,
        },
        pageIndex:this.pageTests.pageNum,
        pageSize:this.pageTests.pageSize
      }
      this.dataLoading = true;
      this.axios.post('pass/baseManagement/v1/limsstdtestitems/queryLimsStdTestItemPage',obj,{individualType: 'json'}).then(res => {
        this.dataLoading = false;
        this.table.listTests = res.data.list;
        this.pageTests.totalPage = res.data.total;
      }).catch(e => {
        this.dataLoading = false;
      });
    },
    //点击选中分析项目的值
    selectAnalyze(val){
      this.analyzeValues = val
      this.saveValue = this.analyzeValues.reviseValue
    },
    showCell(row){
      this.tabClickIndex = row.index
    },
    saveCell(row){
      this.tabClickIndex = null
    },
    tableRowName({row, rowIndex}){
      row.index = rowIndex
    },
    //原始记录
    oldRecord(){
     this.dialogTableVisible = true
     this.tableLoading4 = true;
     this.axios.get('pass/testManagement/v1/limsdatacollects/').then(res =>{
        this.tableLoading4 = false;
        this.tableData4 = res.data.list
      }).catch(err =>{
        this.tableLoading4 = false;
      })
    },
    //选择原始记录数据
    selectTest(val){
      this.originalData = val
    },
    cancel(){
      this.dialogTableVisible = false
    },
    handleSizeChangeMain(pageSize) {
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.dataMain();
    },
    handleCurrentChangeMain(pageIndex) {
      this.pageIndex = pageIndex;
      this.dataMain();
    },
    handleSizeChangeDep(pageSize) {
      this.pageIndex_dep = 1;
      this.pageSize_dep = pageSize;
      this.dataDep();
    },
    handleCurrentChangeDep() {
      this.pageIndex_dep = pageIndex;
      this.dataDep();
    },
    SizeTest (size) {
      this.pageTests.pageSize = size;
      this.getDataListTest2();
    },
    pageChangeTest (index) {
      this.pageTests.pageNum = index;
      this.getDataListTest2();
    },
    tableRowClassName ({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 4) {
      if (row.stateFlag === '3') {
        return 'error-green';
      }
      return '';
      }
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
