<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true" @submit.native.prevent>
        <el-form-item label='物料名称'>
          <el-input v-model="search.matName" @keyup.enter.native="searchData()" size='mini' style="width:200px" />
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
        超差预警头
      </div>
      <div>
      <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="addData">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData">修改</el-button>
      <el-button icon="el-icon-circle-close" type="danger" :loading='deleteMainLoading' size="mini" @click="deleteData">删除</el-button>
      </div>
    </div>
    <div class="common-table-div">
       <el-table v-loading="dataLoading" ref="dataTable" border :height="tableWidth" @row-click='searchDep' highlight-current-row :data="table.list" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="alNo" label="预警编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="alarmTypeName" label="预警类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="matName" label="物料名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="stdName" label="标准号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyMethods" label="分析方法" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemName" label="分析项目" align="center"></el-table-column>
        <el-table-column  sortable :show-overflow-tooltip="true" min-width="80px" prop="memo" label="备注" align="center"></el-table-column>
        <el-table-column  sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column  sortable :show-overflow-tooltip="true" min-width="80px" prop="createMan" label="创建人" align="center"></el-table-column>
        <el-table-column  sortable :show-overflow-tooltip="true" min-width="160px" prop="updateTime" 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>
    </div>
    <div class="common-foot-style">
        <el-pagination v-loading="dataLoading" @size-change="pageSizeChange" @current-change="pageCurrentChange"
          :current-page="page.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalPage" background>
        </el-pagination>
    </div>
    <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
        超差预警项
      </div>
      <div>
      <el-button icon="el-icon-circle-plus-outline" type="goon" size="mini" @click="addDataDep">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyDataDep">修改</el-button>
      <el-button icon="el-icon-circle-close" type="danger" size="mini" :loading='depLoading' @click="deleteDep">删除</el-button>
      </div>
    </div>
    <div class="common-table-div">
       <el-table v-loading="dataLoading" border :height="tableWidth" highlight-current-row @row-click='saveDepData' :data="table.list2" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="alNoD" label="编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="alarmValue" label="超差值" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="maxSign" label="上限符号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="maxValue" label="上限值" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="minSign" label="下限符号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="minValue" label="下限值" align="center"></el-table-column>
        <el-table-column  sortable :show-overflow-tooltip="true" min-width="160px" prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column  sortable :show-overflow-tooltip="true" min-width="80px" prop="createMan" label="创建人" align="center"></el-table-column>
        <el-table-column  sortable :show-overflow-tooltip="true" min-width="160px" prop="updateTime" 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>
    </div>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div>
    <div is="warningItem" :showFlag="showFlag2" :Params="Params2" @refresh='refresh2'></div>
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
import alertComponets from './alertComponents';
import warningItem from './warningItem';
export default {
  components: {alertComponets,warningItem},
  data () {
    return {
      table: {
        list: [],
        list2:[]
      },
      dataLoading: false,
      deleteMainLoading:false,
      saveDepDatas:[],
      depLoading:false,
      saveMainRow:{},
      depData:{},
      icoreFilterFlag: true,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      testItemNameType: [],
      anlyItemNameType: [],
      testItemNameType1: [],
      anlyItemNameType1: [],
      showFlag: false,
      showFlag2:false,
      Params: {},
      Params2: {},
      multipleSelection: [],
      search: {
        matName:''
      },
      tableWidth:0,
    }
  },
  created(){
    this.tableWidth = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;
  },
  mounted () {
    this.getDataList();
    this.addScreen()
  },
  methods: {
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
        }
        if (index === 1) {
          sums[index] = data.length;
        } 
      });
      return sums;
    },
    refresh () {
      this.getDataList();
    },
    refresh2 () {
      this.searchDep(this.saveMainRow);
    },
    addData () {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    modifyData () {
      if (JSON.stringify(this.saveMainRow)==="{}") {
        this.$message.warning('请点击选中一条需要修改的超差预警头数据')
        return
      }
      this.showFlag = !this.showFlag;
      this.Params = this.saveMainRow
    },
    //删除超差预警头数据
    deleteData () {
      if (JSON.stringify(this.saveMainRow)==="{}") {
        this.$message.warning('请点击选中一条需要删除的超差预警头数据')
        return
      }
      this.deleteMainLoading = true
      this.axios.post('pass/baseManagement/v1/limsbasealarms/deletes', [this.saveMainRow.id], {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.deleteMainLoading = false
        }).catch(e => {
          this.deleteMainLoading = false
          this.$message.error(e.message)
       })
    },
    addDataDep(){
      if (JSON.stringify(this.saveMainRow)==="{}") {
        this.$message.warning('请点击选中一条超差预警头数据')
        return
      }
      this.showFlag2 = !this.showFlag2;
      this.Params2 = {alNo:this.saveMainRow.alNo};
    },
    modifyDataDep () {
      if (JSON.stringify(this.depData)==="{}") {
        this.$message.warning('请点击选中一条超差预警项数据')
        return
      }
      this.showFlag2 = !this.showFlag2;
      this.Params2 = this.depData
    },
    //删除超差预警项数据
    deleteDep () {
      if (JSON.stringify(this.depData)==="{}") {
        this.$message.warning('请点击选中一条需要删除的超差预警项数据')
        return
      }
      this.depLoading = true
      this.axios.post('pass/baseManagement/v1/limsbasealarmds/deletes', [this.depData.id], {individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
         this.$message.success(res.message);
         this.searchDep(this.saveMainRow);
        } else {
         this.$message.error(res.message)
        }
        this.depLoading = false
      }).catch(e => {
        this.depLoading = false
        this.$message.error(e.message)
      })
    },
    searchData () {
      this.page.pageNum = 1;
      this.page.pageSize = 50
      this.getDataList()
    },
    getDataList () {
      this.saveMainRow = {}
      this.table.list2 = []
      this.depData = {}
      this.dataLoading = true;
      let obj = {
        object:{
          matName:this.search.matName,
        },
        pageIndex:this.page.pageNum,
        pageSize:this.page.pageSize
      }
      this.axios.post('pass/baseManagement/v1/limsbasealarms/queryLimsBaseAlarmPage',obj, {individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.table.list = res.data.list;
          this.page.totalPage = res.data.total;
          if (this.table.list.length > 0) {
            this.$refs.dataTable.setCurrentRow(this.table.list[0])
            this.searchDep(this.table.list[0])
          }
        }else{
          this.$message.error(res.message)
        }
        this.dataLoading = false;
      }).catch(e => {
        this.dataLoading = false;
        this.$message.error(e.message)
      });
    },
    searchDep(row){
      this.saveMainRow = row
      this.depData = {}
      this.axios.post('pass/baseManagement/v1/limsbasealarmds/querylimbsealarmD',{alNo:this.saveMainRow.id}, {individualType: 'json'}).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.table.list2 = res.data
        }else{
          this.$message.error(res.message)
        }
        this.dataLoading = false;
      }).catch(e => {
        this.dataLoading = false;
        this.$message.error(e.message)
      });
    },
    saveDepData(row){
      this.depData = row
    },
    reset () {
      let _this = this;
      _this.search.matName = '';
      _this.searchData();
    },
    pageSizeChange (size) {
      this.page.pageNum = 1;
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    addScreen () {
      this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
