<!-- 成品判定管理页面 -->
<template>
  <div class="examination decide">
    <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-select
            v-model="searchForm.deptNo"
            filterable
            style="width:100%"
            clearable
            collapse-tags
            @clear="clearSelect"
            @change='selectClass'
            size="small"
          >
            <el-option
              v-for="item in sectionNameType"
              :key="item.orgCode"
              :label="item.orgName"
              :value="item.orgCode"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检验班组">
          <el-select
            v-model="searchForm.sectionNo"
            filterable
            style="width:100%"
            clearable
            collapse-tags
            size="small"
          >
            <el-option
              v-for="item in sectionClassType"
              :key="item.orgCode"
              :label="item.orgName"
              :value="item.orgCode"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料名称">
          <el-input v-model="searchForm.matName" @keyup.enter.native="searchData()" size="small" placeholder="请输入查询内容"
                    style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label="批次号">
          <el-input v-model="searchForm.batchNo" @keyup.enter.native="searchData()" size="small" placeholder="请输入查询内容"
                    style="width: 200px;"></el-input>
        </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='12'>
        <el-tabs type="border-card" v-model="activeName" class="testManagement_left">
          <el-tab-pane label="待判数据" name="first">
            <span slot="label">待判数据<el-badge :max="10" :hidden='total_main11 == 0' style="margin-top:-18px"
                                             :value="total_main11"></el-badge></span>
            <div class="common-title-div" style="height:auto">
              <div class="common-title-name" style="margin-right:10px">
                <img style="width: 25px; height: 25px" src='../../../assets/img/imgScreen/logo.png'/>
                待判定
              </div>
              <div>
                <el-form :inline='true' @submit.native.prevent>
                  <el-form-item style="margin-bottom:0">
                    <el-button icon="el-icon-check" type="goon" size="mini" :loading='buttonLoading1' @click="judge">
                      判定
                    </el-button>
                    <el-button icon="el-icon-check" type="goon" size="mini" :loading='buttonLoading1'
                               @click="changeJudge">更改判定
                    </el-button>
                    <el-button icon="el-icon-check" type="danger" size="mini" :loading='buttonLoadingAbolish'
                               @click="abolish">停用
                    </el-button>
                  </el-form-item>
                </el-form>
              </div>
            </div>
            <div class="common-table-div">
              <el-table ref="tableMain11" :height="theight1"
                        v-loading="tableLoading11"
                        :data="tableData11"
                        @selection-change="searchFollow1"
                        highlight-current-row
                        @row-click="handleCurrentChange11"
                        :header-cell-style="tableHeaderCellStyle"
                        :summary-method="getSummaries"
                        show-summary
                        border
                        style="width: 100%"
                        :icorePanelShown="100"
                        :icore-filter-flag="icoreFilterFlag"
              >
                <el-table-column type="index" width="45" label="NO" fixed="left" align="center"></el-table-column>
                <el-table-column type="selection" width="45" fixed="left" align="center"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="120" align="center" prop="matName"
                                 label="物料名称"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="90" align='center' prop="gradeName"
                                 label="计划牌号"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="100" align='center' prop="batchNo"
                                 label="批次号"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="115" align='center' prop="sampleNo"
                                 label="样品编号"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="115" align='center' prop="sampleNo"
                                 label="原始记录">
                  <template slot-scope="props">
                    <span @click.stop="showDataSource(props.row)" style="color:rgb(3,176,157)">{{sourceFlag}}</span>
                  </template>
                </el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="100px" prop="createMan" label="创建人"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="130px" prop="createTime" label="创建时间"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="100px" prop="deptName" label="车间"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="130px" prop="sectionName" label="班组"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="130px" prop="memo" label="备注"
                                 align="center"></el-table-column>
              </el-table>
            </div>
            <div class="common-foot-style">
              <el-pagination
                @size-change="handleSizeChangeMain11"
                @current-change="dataMain11()"
                :current-page.sync="pageIndex11"
                :page-sizes="[10, 20, 30, 40, 100 , 200]"
                :page-size="pageSize11"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total_main11"
                background
              ></el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="已判数据" name="second">
            <div class="common-title-div" style="height:auto">
              <div class="common-title-name" style="margin-right:10px">
                <img style="width: 25px; height: 25px" src='../../../assets/img/imgScreen/logo.png'/>
                已判定
              </div>
              <div class="buttons">
                <el-button icon="el-icon-back" type="danger" size="mini" :loading='buttonLoading1' @click="backDecide">
                  撤回
                </el-button>
                <el-button icon="el-icon-check" type="danger" size="mini" :loading='buttonLoadingAbolish'
                           @click="abolish1">停用
                </el-button>
              </div>
            </div>
            <div class="common-table-div">
              <el-table ref="table12" :height="theight1"
                        v-loading="tableLoading12"
                        :data="tableData12"
                        @selection-change="searchFollow2"
                        border
                        @row-click="handleCurrentChange12"
                        highlight-current-row
                        :icore-filter-flag="icoreFilterFlag"
                        :header-cell-style="tableHeaderCellStyle"
                        :summary-method="getSummaries" show-summary>
                <el-table-column type="index" width="45" label="NO" fixed="left" align="center"></el-table-column>
                <el-table-column type="selection" width="45" fixed="left" align="center"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="120" align="center" prop="matName"
                                 label="物料名称"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="90" align='center' prop="gradeName"
                                 label="计划牌号"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="90" align='center' prop="gradeNameJd"
                                 label="判定牌号"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="100" align='center' prop="batchNo"
                                 label="批次号"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="115" align='center' prop="sampleNo"
                                 label="样品编号"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="100px" prop="stdName" label="标准"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="80px" prop="auditMan" label="判定人"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="130px" prop="auditTime" label="判定时间"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="100px" prop="deptName" label="车间"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="130px" prop="sectionName" label="班组"
                                 align="center"></el-table-column>
                <el-table-column sortable show-overflow-tooltip min-width="130px" prop="memo" label="备注"
                                 align="center"></el-table-column>
              </el-table>
              <div class="common-foot-style">
                <el-pagination
                  @size-change="handleSizeChangeMain12"
                  @current-change="dataMain12()"
                  :current-page.sync="pageIndex12"
                  :page-sizes="[10, 20, 30, 40, 100 , 200]"
                  :page-size="pageSize12"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total_main12"
                  background
                ></el-pagination>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-col>
      <el-col :span='12'>
        <el-tabs type="border-card" v-model="activeName2">
          <el-tab-pane
            :label="click_main.matName ? '【 ' + click_main.matName + ' 】 - 【 ' + (click_main.gradeName ? click_main.gradeName : '无计划牌号') +' 】' : '未选择数据'"
            name="first2">
            <div style="height:auto;" class="common-title-div">
              <div class="common-title-name" style="margin-right:10px">
                <img style="width: 25px; height: 25px" src='../../../assets/img/imgScreen/logo.png'/>
                分析项目 - 系统判定结果：{{ gradeNameJd }}
                <span></span>
              </div>
              <div class="buttons">
                <!-- <el-button icon="el-icon-check" type="goon" size="mini" :loading='buttonLoading1' @click="judge">判定</el-button> -->
              </div>
            </div>
            <div class="common-table-div">
              <el-table v-loading="tableLoading21"
                        :data="tableData21"
                        ref="resultTable"
                        border :height="theight2" highlight-current-row
                        :icore-filter-flag="icoreFilterFlag"
                        :header-cell-style="tableHeaderCellStyle"
                        :row-class-name="changeRowColor"
                        :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 sortable min-width="160" fixed="left" align="center"
                                 prop="ANLY_ITEM_NAME" label="分析项目"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="120" align="center" prop="anlyValue"
                                 label="报出值"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="120" align="center" prop="gradeNameJd"
                                 label="质量等级"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="90" align="center" prop="minVal"
                                 label="最小值"></el-table-column>
                <el-table-column show-overflow-tooltip sortable min-width="90" align="center" prop="maxVal"
                                 label="最大值"></el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>
    <!-- 原始数据 -->
    <el-dialog :close-on-click-modal='false' @close="closebatch" width='100%' :visible.sync="batchShow" top="0">
      <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>
      <div class="common-title-name" style="padding-bottom: 3px;">
      </div>
<!--  TODO 原始记录    -->
      <el-table ref="table13" border :height="theight13" highlight-current-row :data="tableData13"
                :span-method="arraySpanMethod13"
                :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" width="45" fixed align="center"></el-table-column>
        <el-table-column type="selection" width="45" fixed align="center"></el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="118" fixed align='center' prop="SAMPLE_NO" label="样品号">
          <template slot-scope="scope">
            <div style="white-space: pre-wrap;word-wrap: break-word;"
                 :class="{'color-danger': scope.row.ERR == '1'&&!scope.row.SUB, 'color-warning': scope.row.SUB == '1'}">{{scope.row.SAMPLE_NO}}</div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="125" fixed align="center" prop="MAT_NAME" label="物料名称">
          <template slot-scope="scope">
            <div style="white-space: pre-wrap;word-wrap: break-word;"
                 :class="{'color-danger': scope.row.ERR == '1'&&!scope.row.SUB, 'color-warning': scope.row.SUB == '1'}">{{scope.row.MAT_NAME}}</div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="110" fixed align='center' prop="TEST_ITEM_NAME" label="测试项目" >
          <template slot-scope="scope">
            <div style="white-space: pre-wrap;word-wrap: break-word;"
                 :class="{'color-danger': scope.row.ERR == '1'&&!scope.row.SUB, 'color-warning': scope.row.SUB == '1'}">{{scope.row.TEST_ITEM_NAME}}</div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip sortable width="80" fixed align="center" prop="CHECK_TIME" label="提交时间">
          <template slot-scope="scope">
            <div style="white-space: pre-wrap;word-wrap: break-word;"
                 :class="{'color-danger': scope.row.ERR == '1'&&!scope.row.SUB, 'color-warning': scope.row.SUB == '1'}">{{scope.row.CHECK_TIME}}</div>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip sortable min-width="80" fixed align="center" prop="CREATE_MAN" label="提交人">
          <template slot-scope="scope">
            <span :class="{'color-danger': scope.row.ERR == '1'&&!scope.row.SUB, 'color-warning': scope.row.SUB == '1'}">
              {{scope.row.CREATE_MAN}}
            </span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip min-width="180" align="center" prop="ANLY_ITEM_NAME" label="分析项目"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="ANLY_VALUE" label="报出值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="DAS_VALUE" label="采集值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="CPT_VALUE" label="计算值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="REVISE_VALUE" label="修约值"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="90" align="center" prop="UNIT_NAME" label="单位"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="FORMULA_NAME" label="计算公式" ></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="REVISE_RULE_NAME" label="修约规则"></el-table-column>
        <el-table-column show-overflow-tooltip min-width="100" align="center" prop="isReportName" label="是否报出"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="closebatch">取消</el-button>
      </span>
    </el-dialog>
    <div is="changeJudgeComponents" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div>
  </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);
import changeJudgeComponents from './changeJudgeComponents'

export default {
  components: {changeJudgeComponents},
  data () {
    return {
      searchForm: {
        matName: '',
        batchNo: '',
        times: [],
        deptNo: '',
        sectionNo: ''
      },
      activeNames : ['1'],
      dialogTableVisible: false,
      sampleTypeNameType: [],
      saveAnalyAudit: [],
      deptNo: '', // 登录人的部门(车间)
      sectionNo: '', // 登录人的班组
      classNo: '', // 登录人的岗位
      click_main: {}, // 选中物料行（未判定）
      click_main2: {}, // 选中物料行（已判定）
      theight1: 0,
      theight2: 0,
      tableLoading11: false,
      tableLoading12: false,
      tableLoading1: false,
      tableLoading2: false,
      tableLoading21: false,
      tableLoading3: false,
      buttonLoading1: false,
      buttonLoadingAbolish: false,
      buttonLoading2: false,
      buttonLoading3: false,
      sourceData : [],
      sourceFlag:'点击查看原始记录',
      showFlag: false,
      Params: {},
      cols: [], // 未判定动态列
      tableData11: [], // 待判定物料
      tableData12: [], // 已判定物料
      tableData21: [], // 分析项目报出值数据
      pageIndex11: 1,
      pageSize11: 100,
      total_main11: 0,
      pageIndex12: 1,
      pageSize12: 100,
      total_main12: 0,
      multipleSelection1: [], // 1表多选
      multipleSelection2: [], // 2表多选
      activeName: 'first',
      activeName2: 'first2',
      icoreFilterFlag: true,
      sectionNameType: [], // 检验车间
      sectionClassType: [], // 检验班组
      companyNameType: [], // 公司
      matNameType: [], // 物料名称-查询
      matClassNameType: [], // 物料类型-查询
      activeMenu: '',
      batchShow: false, // 原始记录显示
      tableData13:[], // 原始记录1
      gradeNameJd: '' // 系统判定牌号
    }
  },
  created () {
    this.theight1 = window.innerHeight - 256;
    this.theight2 = window.innerHeight - 215;
    this.theight13 = window.innerHeight -240;
    this.activeMenu = window.top.localStorage.getItem('activeMenu')
    this.searchForm.times = [this.getYNM(new Date()), this.getYNM(new Date())]
    // 获取所有机构
    this.axios.post('pass/baseManagement/v1/sysorgs/querySysOrgCompanyAll', {}, {individualType: 'json'}).then((response) => {
      this.companyNameType = response.data;
      this.selectDepartment('F31300000')
      // 获取检测中心下的机构
      this.getCompany()
    });
  },
  mounted () {
    this.axios.post('pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode', {
      validFlag: 1,
      baseCode: 4801
    }, {individualType: 'json'}).then(res => {
      this.sampleTypeNameType = res.data
    })
    //物料类型
    this.axios.get('pass/baseManagement/v1/limsbasematerialsclasss/?validFlag=1').then((res) => {
      this.matClassNameType = res.data.list;
    });
  },
  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;
    },
    //获取个人所属哪个公司
    getCompany () {
      this.axios.get('pass/baseManagement/v1/limslrcemps/' + userId).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.searchForm.deptNo = res.data ? res.data.deptNo : ''
          this.selectClass2(this.searchForm.deptNo)
          this.searchForm.sectionNo = res.data ? res.data.sectionNo : ''
          // this.searchData()
        } else {
          this.$message.error(e.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    resetData () {
      this.searchForm.matName = ''
      this.searchForm.batchNo = ''
      this.searchForm.times = [this.getYNM(new Date()), this.getYNM(new Date())]
      // this.searchData()
    },
    // 判定
    judge () {
      if (this.multipleSelection1.length < 1) {
        this.$message.warning('请先勾选要判定的数据')
        return
      }
      let ids = []//需要提交的数据的id
      for (let i = 0; i < this.multipleSelection1.length; i++) {
        ids.push(this.multipleSelection1[i].id)
      }
      this.buttonLoading1 = true
      this.axios.post('pass/testManagement/v1/limssamplejudges/check',{jdIdList: ids, judgeData: null},{individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200){
          if (res.data){
            let h =  this.$confirm(res.message,'提醒',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              // 判定
              this.axios.post('pass/testManagement/v1/limssamplejudges/judge', {
                jdIdList: ids,
                judgeData: null
              }, {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.buttonLoading1 = false
              }).catch(e => {
                this.buttonLoading1 = false
                this.$message.error(e.message)
              })
              }
            ).catch(e => {
              this.buttonLoading1 = false
            })
          }else {
            // 判定
            this.axios.post('pass/testManagement/v1/limssamplejudges/judge', {
              jdIdList: ids,
              judgeData: null
            }, {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.buttonLoading1 = false
            }).catch(e => {
              this.buttonLoading1 = false
              this.$message.error(e.message)
            })
          }
        }
      }).catch(e => {
        this.$message.error(e.message)
        this.buttonLoading1= false
      })
    },
    //更改判定
    changeJudge () {
      if (this.multipleSelection1.length < 1) {
        this.$message.warning('请先勾选要更改判定的数据')
        return
      }
      if (this.multipleSelection1.length > 1) {
        this.$message.warning('请取消多选，只能勾选一条数据')
        return
      }
      this.showFlag = true;
      this.Params = this.multipleSelection1[0];
    },
    abolish(){
      if (this.multipleSelection1.length < 1) {
        this.$message.warning('请先勾选一条需要作废的判定数据')
        return
      }
      if (this.multipleSelection1.length > 1) {
        this.$message.warning('请取消多选，只能勾选一条数据')
        return
      }
      this.buttonLoadingAbolish = true;
      let jdId = this.multipleSelection1[0].id
      this.axios.get('pass/testManagement/v1/limssamplejudges/abolish?jdId='+jdId).then(res => {
        if (res.code == 0 || res.code ==200){
          this.$message.success('操作成功!');
          this.buttonLoadingAbolish = false;
          this.searchData();
        } else {
          this.$message.error('操作失败!');
          this.buttonLoadingAbolish = false;
        }
      }).catch(e =>{
        this.$message.error(e.message)
        this.buttonLoadingAbolish = false;
      })
    },
    abolish1(){
      if (this.multipleSelection2.length < 1) {
        this.$message.warning('请先勾选一条需要作废的判定数据')
        return
      }
      if (this.multipleSelection2.length > 1) {
        this.$message.warning('请取消多选，只能勾选一条数据')
        return
      }
      this.buttonLoadingAbolish = true;
      let jdId = this.multipleSelection2[0].id
      this.axios.get('pass/testManagement/v1/limssamplejudges/abolish?jdId='+jdId).then(res => {
        if (res.code == 0 || res.code ==200){
          this.$message.success('操作成功!');
          this.buttonLoadingAbolish = false;
          this.searchData();
        } else {
          this.$message.error('操作失败!');
          this.buttonLoadingAbolish = false;
        }
      }).catch(e =>{
        this.$message.error(e.message)
        this.buttonLoadingAbolish = false;
      })
    },
    //  撤回判定
    backDecide () {
      if (this.multipleSelection2.length < 1) {
        this.$message.warning('请先勾选已判定的数据')
        return
      }
      let ids = [] //需要提交的数据的id
      for (let i = 0; i < this.multipleSelection2.length; i++) {
        ids.push(this.multipleSelection2[i].id)
      }
      this.buttonLoading1 = true
      // 判定
      this.axios.post('pass/testManagement/v1/limssamplejudges/cancel', ids, {individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.$message.success(res.message)
          this.searchData()
        } else {
          this.$message.error(res.message)
        }
        this.buttonLoading1 = false
      }).catch(e => {
        this.buttonLoading1 = false
        this.$message.error(e.message)
      })
    },
    //查询
    searchData () {
      this.pageIndex = 1
      this.pageSize = 100
      this.pageIndex2 = 1
      this.pageSize2 = 100
      if (this.searchForm.batchNo != null){
        this.pageIndex11 = 1
        this.pageIndex12 = 1
      }
      this.dataMain11()
      this.dataMain12()
    },
    // 车间列表（检测中心下）
    selectDepartment (val) {
      this.sectionNameType = [];
      this.companyNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionNameType = item.sysOrgList;
        }
      });
    },
    // 根据选中的车间名称，查询班组名称
    selectClass (val) {
      this.sectionClassType = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClassType = item.sysOrgList;
          this.searchForm.sectionNo = ''
        }
      });
    },
    // 根据选中的车间名称，查询班组名称
    selectClass2 (val) {
      if (!val) {
        return
      }
      this.sectionClassType = [];
      this.sectionNameType.find((item) => {
        if (val === item.orgCode) {
          this.sectionClassType = item.sysOrgList;
        }
      });
    },
    clearSelect () {
      this.searchForm.sectionNo = '';
    },
    // 未判定数据
    dataMain11 () {
      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'
      }
      this.tableData21 = []
      this.gradeNameJd = ''
      let obj = {
        object: {
          validFlag: '1',
          stateFlag: '0',
          sampleTypeCode: '480103',
          batchNo: this.searchForm.batchNo,
          matName: this.searchForm.matName,
          deptNo: this.searchForm.deptNo,
          sectionNo: this.searchForm.sectionNo
        },
        startTime: startTime,
        endTime: endTime,
        pageIndex: this.pageIndex11,
        pageSize: this.pageSize11
      }
      this.tableLoading11 = true;
      this.axios.post('pass/testManagement/v1/limssamplejudges/queryLimSampleJudge', obj, {individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData11 = res.data.list
          this.total_main11 = res.data.total
        } else {
          this.$message.error(res.message)
        }
        this.tableLoading11 = false;
      }).catch(err => {
        this.tableLoading11 = false;
        this.$message.error(err.message)
      })
    },
    // 已判定数据
    dataMain12 () {
      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'
      }
      this.tableData21 = []
      this.gradeNameJd = ''
      let obj = {
        object: {
          validFlag: '1',
          stateFlag: '1,2',              // 查询已判定和已审核的
          sampleTypeCode: '480103',
          batchNo: this.searchForm.batchNo,
          matName: this.searchForm.matName,
          deptNo: this.searchForm.deptNo,
          sectionNo: this.searchForm.sectionNo
        },
        startTime: startTime,
        endTime: endTime,
        pageIndex: this.pageIndex12,
        pageSize: this.pageSize12
      }
      this.tableLoading12 = true;
      this.axios.post('pass/testManagement/v1/limssamplejudges/queryLimSampleJudge', obj, {individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.tableData12 = res.data.list
          this.total_main12 = res.data.total
        } else {
          this.$message.error(res.message)
        }
        this.tableLoading12 = false;
      }).catch(err => {
        this.tableLoading12 = false;
        this.$message.error(err.message)
      })
    },
    handleSizeChangeMain11 (pageSize) {
      this.pageIndex11 = 1;
      this.pageSize11 = pageSize;
      this.dataMain11();
    },
    handleCurrentChangeMain (pageIndex) {
      this.pageIndex11 = pageIndex;
      this.dataMain11();
    },
    handleSizeChangeMain12 (pageSize) {
      this.pageIndex12 = 1;
      this.pageSize12 = pageSize;
      this.dataMain12();
    },
    handleCurrentChangeMain12 (pageIndex) {
      this.pageIndex12 = pageIndex;
      this.dataMain12();
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    },
    changeRowColor ({row, rowIndex}) {
      if (row.warningFlag && row.warningFlag == '1') {
        return 'error-row'
      }
    },
    // 根据物料类型查询物料 - 查询
    selctMatName (val) {
      this.matNameType = [];
      this.searchForm.matNo = '';
      if (!val) {
        return;
      }
      //物料名称
      this.axios.post('pass/baseManagement/v1/limsbasematerialss/queryLimsBaseMaterialsPage/',
        {
          object: {validFlag: 1, matClassNo: val},
          pageIndex: 1,
          pageSize: 99999,
        },
        {individualType: 'json'}
      ).then((res) => {
        this.matNameType = res.data.list;
      });
    },
    //选中数据1
    searchFollow1 (val) {
      this.multipleSelection1 = val
    },
    //选中数据2
    searchFollow2 (val) {
      this.multipleSelection2 = val
    },
    //选中数据13 (原始数据)
    searchFollow13 (val) {
      this.multipleSelection13 = val
    },
    // 表格1合并单元格
    arraySpanMethod ({row, column, rowIndex, columnIndex}) {
      let tableData = this.$refs.tableMain12.tableData
      let rowsPan = 1;
      let thisColomnData = row[column['property']];
      // 相同合同列的行合并
      if (column['property'] === 'CONTRACT_NO' && thisColomnData) {
        if (rowIndex > 0 && thisColomnData === tableData[rowIndex - 1][column['property']]) {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
        while (tableData[rowIndex + rowsPan] && thisColomnData === tableData[rowIndex + rowsPan][column['property']]) {
          rowsPan += 1
        }
        return {
          rowspan: rowsPan,
          colspan: 1
        };
      }
    },
    // 表格2合并单元格
    arraySpanMethod2 ({row, column, rowIndex, columnIndex}) {
      let tableData = this.$refs.tableMain22.tableData
      let rowsPan = 1;
      let thisColomnData = row[column['property']];
      // 相同合同列的行合并
      if (column['property'] === 'CONTRACT_NO' && thisColomnData) {
        if (rowIndex > 0 && thisColomnData === tableData[rowIndex - 1][column['property']]) {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
        while (tableData[rowIndex + rowsPan] && thisColomnData === tableData[rowIndex + rowsPan][column['property']]) {
          rowsPan += 1
        }
        return {
          rowspan: rowsPan,
          colspan: 1
        };
      }
    },
    handleCurrentChange11 (val) {
      this.click_main = val
      if (this.click_main.srId) {
        this.tableLoading21 = true;
        let params = {
          srId: this.click_main.srId,
          tkId: this.click_main.tkId,
          gradeNo: this.click_main.gradeNo
        };
        this.$refs.resultTable.bodyWrapper.scrollTop = 0
        this.axios.get('pass/testManagement/v1/limssamplejudges/queryDatad', {params: params}).then(res => {
          if (res.code == 0 || res.code == 200) {
            this.tableData21 = res.data.list
            this.tableData21.forEach(item => {
              if (item.gradeNameJd && item.gradeNameJd == '不合格') {
                item.warningFlag = '1'
              } else if (item.maxVal && item.maxVal != '-' && item.anlyValue){
                let anlyVal = item.anlyValue.startsWith("<") || item.anlyValue.startsWith("≤") ? item.anlyValue.slice(1) : item.anlyValue
                if (anlyVal - item.maxVal > 0 ){
                  item.warningFlag='1'
                }
              }
            })
            this.gradeNameJd = res.data.gradeNameJd
          } else {
            this.$message.error(res.message)
          }
          this.tableLoading21 = false;
        }).catch(err => {
          this.tableLoading21 = false;
          this.$message.error(err.message)
        })
      }
      // this.dataMain21();
    },
    handleCurrentChange12 (val) {
      this.click_main = val
      console.log(this.click_main, '点击的数据...')
      if (this.click_main.srId) {
        this.tableLoading21 = true;
        let jdId = this.click_main.jdId;
        this.$refs.resultTable.bodyWrapper.scrollTop = 0
        this.axios.get(`pass/testManagement/v1/limssamplejudgeds/queryLimsSampleJudgeD?jdId=${jdId}`).then(res => {
          if (res.code == 0 || res.code == 200) {
            this.tableData21 = res.data.list
            this.gradeNameJd = res.data.gradeNameJd
          } else {
            this.$message.error(res.message)
          }
          this.tableLoading21 = false;
        }).catch(err => {
          this.tableLoading21 = false;
          this.$message.error(err.message)
        })
      }
      // this.dataMain21();
    },
    // 选中已判定物料
    handleCurrentChange21 (val) {
      this.click_main2 = val
      this.dataMain2();
    },
    refresh () {
      this.showFlag = false;
      this.searchData();
    },
    // 显示数据来源，valSource 格式 数值_stid_errstid_substid
    showDataSource (row){
      // 记录参数，用于审核后刷新本页数据
      let sr_id = row.srId;
      console.log(row.SR_ID);
      console.log(sr_id)
      this.axios.get('pass/testManagement/v1/limssampleresults/'+sr_id).then(res => {
        if (res.code == 0 || res.code == 200){
          console.log("响应数据"+res.data)
          let stId = res.data.stId
          let valSource = "1_"+stId+"__";
          console.log("参数"+valSource)
          this.tableData13 = []
          this.axios.get('pass/testManagement/v1/limssampleresults/queryDataSource?valSource='+valSource).then(res =>{
            if (res.code == 0 || res.code == 200) {
              this.tableData13 = res.data
              if(this.tableData13){
                this.tableData13.forEach(item =>{
                  item.isReportName = item.IS_REPORT == 0 ? '否' : item.IS_REPORT == 1 ? '是' : ''
                  item.isAlarmName = item.IS_ALARM == 0 ? '否' : item.IS_ALARM == 1 ? '是' : ''
                })
              }
              this.batchShow = true
            }else{
              this.$message.error(res.message)
            }
            this.batchDataLoading = false
          }).catch(e =>{
            this.batchDataLoading = false
            this.$message.error(e.message)
          })
        }else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.$message.error(e.message)
      })
    },
    // 表格13(原始数据)合并单元格
    arraySpanMethod13 ({ row, column, rowIndex, columnIndex }) {
      let tableData = this.$refs.table13.tableData
      let rowsPan = 1;
      let st = row['ST_ID'];
      if (columnIndex > 0 && columnIndex < 7 && st) {
        if (rowIndex > 0 && st === tableData[rowIndex - 1]['ST_ID']) {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
        while (tableData[rowIndex + rowsPan] && st === tableData[rowIndex + rowsPan]['ST_ID']) {
          rowsPan += 1
        }
        return {
          rowspan: rowsPan,
          colspan: 1
        };
      }
    },
    // 关闭原始记录页面
    closebatch (){
      this.batchShow = false;
      // this.dataMain();
    },
  }
}
</script>
<style scoped>
</style>
<style lang="less">
</style>

