<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-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-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="month"
           size="small"
           :clearable='false'
           style="width:200px"
           format="yyyy-MM"
           value-format="yyyy-MM">
          </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="9">
        <div class="common-title-div">
          <div class="common-title-name">
            <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
            日期
          </div>
        </div>
        <div class="common-table-div" style="margin-bottom:0;margin-top:0">
          <el-table
            ref="table1"
            :height="theight1"
            v-loading="tableLoading1"
            :data="tableData1"
            :summary-method="getSummaries2"
            show-summary
            border
            @row-click="searchFollow"
            :header-cell-style="tableHeaderCellStyle"
            highlight-current-row
            :icorePanelShown="100"
            :icore-filter-flag="icoreFilterFlag"
            :exchangeFilterMap="{'lock_flag':{'0':'未锁定','1':'已锁定'}}"
            style="width: 100%;"
          >
            <el-table-column type="index" label="NO" align="center"></el-table-column>
            <el-table-column prop="" label="日期" :show-overflow-tooltip="true" sortable min-width="140"></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="140"></el-table-column>
            <el-table-column prop="" label="交班" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
          </el-table>
        </div>
        <div class="common-foot-style">
          <el-pagination
            @size-change="handleSizeChangeMain"
            @current-change="handleCurrentChangeMain"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 30, 40, 100 , 200]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total_main"
            background
          ></el-pagination>
        </div>
      </el-col>
      <el-col :span="15">
        <div class="common-title-div" style="min-height:50px">
          <div class="common-title-name" style="margin-right: 10px;">
            <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" v-privilege="activeMenu + 'save'" size="mini">保存</el-button>
            <el-button icon="el-icon-check" type="goon" size="mini" v-privilege="activeMenu + 'succession'">接班</el-button>
            <el-button icon="el-icon-circle-close" type="danger" size="mini" v-privilege="activeMenu + 'cancelSuccession'">取消接班</el-button>
            <el-button icon="el-icon-check" type="goon" size="mini" v-privilege="activeMenu + 'handOver'">交班</el-button>
            <el-button icon="el-icon-circle-close" type="danger" size="mini" v-privilege="activeMenu + 'cancelHandOver'">取消交班</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" 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 prop="shiftName" label="交接项目" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="shiftDesc" 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="memo" label="备注" :show-overflow-tooltip="true" sortable min-width="100"></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>
          </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" :summary-method="getSummaries2" show-summary>
            <el-table-column type="index" label="NO" align="center"></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="" label="剩余量" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
            <el-table-column prop="memo" label="备注" :show-overflow-tooltip="true" sortable min-width="100"></el-table-column>
          </el-table>
        </div>
      </el-col>  
    </el-row>
  </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:''
      },
      checked:true,
      saveValue:'',
      saveMainData:{},
      sampleLoading:false,
      saveLoading:false,
      submitLoading:false,
      sampleTypeNameType: [],
      analyzeVal:{},
      analyzeValues:{},
      theight1: 0,
      theight2: 0,
      theight3: 0,
      tableLoading1:false,
      tableLoading2:false,
      tableLoading3:false,
      tableData1:[],
      tableData2:[],
      tableData3:[],
      pageIndex: 1,
      pageSize:100,
      total_main:0,
      pageIndex_dep: 1,
      pageSize_dep:100,
      total_dep:0,
      icoreFilterFlag: true,
      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.searchForm.times = 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.searchData()
  },
  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}`;
      // 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;
    },
    resetData(){
      this.searchForm.matName = ''
      this.searchForm.sampleTypeCode = ''
      this.searchForm.eqpNo = ''
      this.searchForm.times = this.getYNM(new Date())
      this.searchData()
    },
    //点击选中样品信息数据
    searchFollow(row){
      this.saveMainData = Object.assign({},row)
    },
    //保存
    saveData(){
      if (JSON.stringify(this.analyzeVal)==="{}") {
        this.$message.warning("请先点击选中一条测试项目数据");
        return;
      }
      this.saveLoading = true
      this.axios.post('pass/testManagement/v1/limssampletests/save/'+this.analyzeVal.id,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)
      })
    },
    //提交
    subData(){
      if (JSON.stringify(this.analyzeVal)==="{}") {
        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)
      })
    },
    //点击选中分析项目的值
    selectAnalyze(val){
      this.analyzeValues = val
      this.saveValue = this.analyzeValues.reviseValue
    },
    //查询操作
    searchData (){
      this.pageIndex = 1
      this.pageSize = 100
      this.pageIndex_dep = 1
      this.pageSize_dep = 100
      this.DataMain()
      this.DataDep()
    },
    //查询样品信息表格
    DataMain () {
      // this.saveMainData = {}
      // let obj = {
      //   'object':{
      //     'matName': this.searchForm.matName,
      //     'sampleTypeCode': this.searchForm.sampleTypeCode,
      //     'isAcpt':0,
      //     'isKeep':0,
      //     'isDo':0
      //   },
      //   'list':[], //区分制样采样
      //   'list2':[484001],//区分水分测试
      //   "pageSize": this.pageSize,
      //   "pageIndex": this.pageIndex,
      //   'startTime': '',
      //   'endTime':  '' 
      // }
      // this.tableLoading1 = true;
      // this.axios.post('pass/testManagement/v1/limssampleinfos/queryLimsSampleInfoPage',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 () { 
      // let obj = {
      //   'object':{
      //     'matName': this.searchForm.matName,
      //     'sampleTypeCode': this.searchForm.sampleTypeCode,
      //   },
      //   'list':[484001],//区分测试分析类型
      //   "pageSize": this.pageSize_dep,
      //   "pageIndex": this.pageIndex_dep,
      //   'startTime': '',
      //   '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
      //     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.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)
      })
    },
    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();
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
