<template>
  <div class="examination">
    <div class="common-head-search">
      <el-form :inline="true">
        <el-form-item label='分析项目编号'>
          <el-input v-model="search.anlyItemNo" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容" style="width: 200px;"></el-input>
        </el-form-item>
        <el-form-item label='分析项目'>
          <el-input v-model="search.anlyItemName" size="small" @keyup.enter.native="searchData()" placeholder="请输入查询内容" style="width: 200px;"></el-input>
        </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" size="mini" @click="deleteData">停用</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData">启用</el-button>
      </div>
    </div>
    <div class="common-table-div">
       <el-table v-loading="dataLoading" ref="dataTable" border :height="height_top" highlight-current-row @selection-change="handleSelectionChange" :data="table.list" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :row-class-name="tableRowClassName" :summary-method="getSummaries" 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 sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemNo" 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="90px" prop="itemTypeName" label="项目类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="dataTypeName" label="数据类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px"  prop="validFlag1" label="数据状态" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="dspOrder" label="显示顺序" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="unitName" label="度量单位" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="formulaName" label="计算公式" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="reviseRuleName" label="修约规则" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="outputTypeName" label="输出类型" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="defaultValue" 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="90px" prop="anlyCnt" label="分析次数" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="memo" label="备注" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isCompute1" label="是否计算" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="isMid1" label="是否中间项" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isReport1" label="是否报出" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isLogin1" label="是否必检" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isAlarm1" label="是否报警" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="80px" prop="isRare1" label="是否贵重" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemAlias" label="分析项目别名" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemDesc" label="分析项目描述" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="anlyItemEng" 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="[50, 100, 200, 500 ,1000]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page.totalPage" background>
        </el-pagination>
    </div>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div>
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
import alertComponets from './alertComponents';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: {alertComponets},
  data () {
    return {
      table: {
        list: []
      },
      dataLoading: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 100,
        pageNum: 1,
        totalPage: 0
      },
      showFlag: false,
      Params: {},
      multipleSelection: [],
      search: {
        anlyItemNo: '',
        anlyItemName: ''
      },
      height_top:0
    }
  },
  created() {
    this.height_top = window.innerHeight - 190;
  },
 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();
    },
    open(mag, typ, time) {
        this.$message({
          showClose: true,
          message: mag,
          type: typ,
          duration: time
        });
    },
    addData () {
      let _this = this;
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
    },
    modifyData () {
      let _this = this;
      if (_this.multipleSelection.length !== 1) {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag = !_this.showFlag;
        _this.Params = _this.multipleSelection
      }
    },
     recoverData () {
       let _this = this;
        if (_this.multipleSelection.length < 1) {
        this.$message.warning('请勾选您要启用的数据！')
      } else {
        for (var j= 0; j < _this.multipleSelection.length; j++) {
          if (_this.multipleSelection[j].validFlag === '1') {
          this.$message.warning('请勾选状态为已停用的数据！')  
          return 
          }
        }
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection.length; i++) {
        _this.multipleSelection[i].updateMan = userName;
        _this.multipleSelection[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsstdanlyitems/recover', _this.multipleSelection, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.open('启用成功', 'success', 1200)
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    deleteData () {
       let _this = this;
        if (_this.multipleSelection.length < 1) {
        this.$message.warning('请勾选您要删除的数据！')
      } else {
        for (var j= 0; j < _this.multipleSelection.length; j++) {
          if (_this.multipleSelection[j].validFlag === '0') {
          this.$message.warning('请勾选状态为已启用的数据！')  
          return 
          }
        }
        _this.dialogTableVisible = false;
        for (var i = 0; i < _this.multipleSelection.length; i++) {
        _this.multipleSelection[i].updateMan = userName;
        _this.multipleSelection[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsstdanlyitems/abolish', _this.multipleSelection, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.open('删除成功', 'success', 1200)
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    searchData () {
      this.page.pageNum = 1;
      this.getDataList()
    },
    reset () {
      let _this = this;
      _this.search.anlyItemNo = '';
      _this.search.anlyItemName = '';
      _this.searchData();
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    pageSizeChange (size) {
      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);
       });
    },
    getDataList () {
      this.dataLoading = true;
      let obj = {
        object:{
          anlyItemNo:this.search.anlyItemNo,
          anlyItemName:this.search.anlyItemName
        },
        pageIndex:this.page.pageNum,
        pageSize:this.page.pageSize
      }
      this.axios.post('pass/baseManagement/v1/limsstdanlyitems/queryLimsStdAnlyItemPage',obj, {individualType: 'json'}).then(res => {
        this.dataLoading = false;
        this.table.list = res.data.list;
        this.table.list.forEach(item =>{
          item.validFlag1 = item.validFlag === '0' ? '无效' : item.validFlag === '1' ? '有效' : ''
          item.isCompute1 = item.isCompute === '0' ? '否' : item.isCompute === '1' ? '是' : ''
          item.isMid1 = item.isMid === '0' ? '否' : item.isMid === '1' ? '是' : ''
          item.isReport1 = item.isReport === '0' ? '否' : item.isReport === '1' ? '是' : ''
          item.isLogin1 = item.isLogin === '0' ? '否' : item.isLogin === '1' ? '是' : ''
          item.isAlarm1 = item.isAlarm === '0' ? '否' : item.isAlarm === '1' ? '是' : ''
           item.isRare1 = item.isRare === '0' ? '否' : item.isRare === '1' ? '是' : ''
        })
      this.page.totalPage = res.data.total;
      }).catch(e => {
        this.dataLoading = false;
      });
    },
    tableRowClassName ({row, column, rowIndex, columnIndex}) {
      if (row.validFlag !== '1') {
        return 'error-row';
      }
      return '';
    },
    tableHeaderCellStyle () {
      return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
    }
  }
}
</script>
<style  scoped>
</style>
