<template>
  <div class="examination" style="display: flex">
    <div class="common-title-div-left">
        <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../../assets/img/imgScreen/logo.png' />
        单位类型
        </div>
        <div class="common-table-div-left">
       <el-table v-loading="dataLoading3"  border :height="listWidth" highlight-current-row @current-change="handleCurrentChange3" :data="table.list3" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle">
       <el-table-column width="" prop="baseName" label="度量类型" align="center"></el-table-column>
       </el-table>
        </div>
    </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-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-remove-outline" 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-right">
       <el-table v-loading="dataLoading2" ref="dataTable" border :height="tableWidth" highlight-current-row @current-change="handleCurrentChange" :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" fixed="left" 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="100px" prop="unitNo" label="单位编码  " align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="unitName" label="单位名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="unitDesc" label="中文描述" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="unitEnglish" label="英文描述" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="validFlag1" label="数据状态" align="center">
          <!-- <template slot-scope="scope">
              <span v-if="scope.row.validFlag == 1">已启用</span>
              <span v-else-if="scope.row.validFlag == 0">已停用</span>
          </template> -->
        </el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="isStdUnit" label="是否标准单位"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="createMan" 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="95px" prop="updateMan" 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>
    </div>
    <div class="common-foot-style">
        <el-pagination v-loading="dataLoading2" @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="addData2">新增</el-button>
      <el-button icon="el-icon-edit" type="goon" size="mini" @click="modifyData2">修改</el-button>
      <el-button icon="el-icon-remove-outline" type="danger" size="mini" @click="deleteData2">停用</el-button>
      <el-button icon="el-icon-check" type="goon" size="mini" @click="recoverData2">启用</el-button>
      </div>
    </div>
    <div class="common-table-div-right">
       <el-table v-loading="dataLoading" ref="dataTable2" border :height="tableWidth" highlight-current-row @current-change="handleCurrentChange2" :data="table.list2" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" :row-class-name="tableRowClassName2" :summary-method="getSummaries" show-summary>
        <el-table-column type="index" label="NO" fixed="left" 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="100px" prop="unitNoD" label="转换编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="converFactor" label="转换因子" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="unitNameD" label="转换单位" align="center"></el-table-column>>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px" prop="validFlag1" label="数据状态" align="center">
          <!-- <template slot-scope="scope">
              <span v-if="scope.row.validFlag == 1">已启用</span>
              <span v-else-if="scope.row.validFlag == 0">已停用</span>
          </template> -->
        </el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="95px" prop="createMan" 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="95px" prop="updateMan" 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>
    </div>
    <div class="common-foot-style">
        <el-pagination v-loading="dataLoading" @size-change="pageSizeChange2" @current-change="pageCurrentChange2"
          :current-page="page2.pageNum" :page-sizes="[10, 20, 50, 100, 200]" :page-size="page2.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="page2.totalPage" background>
        </el-pagination>
    </div>
    </div>
    <div is="alertComponets" :showFlag="showFlag" :Params="Params" :unitType="unitType1" @refresh='refresh2'></div>
    <div is="alertComponets2" :showFlag2="showFlag2" :Params="Params" :Params2="Params2" @refresh='refresh3'></div>
  </div>
</template>
<script>
import {
  getCookie
} from '@/utils/util.js';
import {
  cookieUserId,
  cookieUserName
} from '@/config/config.js';
import alertComponets from './alertComponents';
import alertComponets2 from './alertComponents2';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: {alertComponets, alertComponets2},
  data () {
    return {
      table: {
        list: [],
        list2: [],
        list3: []
      },
      dataLoading: false,
      dataLoading2: false,
      dataLoading3: false,
      icoreFilterFlag: true,
      unitTypeCode: '',
      unitNo: '',
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      showFlag: false,
      Params: {},
      showFlag2: false,
      unitType1: {},
      Params2: {},
      multipleSelection: [],
      multipleSelection2: [],
      tableWidth:0,
      listWidth:0
    }
    
  },
  created(){
    this.tableWidth = window.innerHeight/2 - 110 < 249 ? 249 : window.innerHeight/2 - 110
    this.listWidth = this.tableWidth * 2
  },
 mounted () {
    this.getDataList3();
    this.addScreen();
    this.addScreen2();
  },
  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;   
    },
    getSummaries2 (param) {
      const { columns, data } = param;
      const sums = [];
       columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index === 2) {
            sums[index] = this.page2.totalPage;
          }
       });
        return sums;
    },
    refresh () {
      let _this = this;
      _this.getDataList3 ();
      _this.getDataList2 (_this.unitNo);
      _this.getDataList (_this.unitTypeCode);
      // _this.getDataList2();
      // _this.multipleSelection.splice(0, 1);
      // _this.multipleSelection2 = []
      // console.log(_this.multipleSelection)
    },
    refresh2 () {
       let _this = this;
       _this.getDataList (_this.unitTypeCode);
       _this.getDataList2 (_this.unitNo);
    },
    refresh3 () {
       let _this = this;
        _this.getDataList2 (_this.unitNo);
    },
    addData () {
      let _this = this;
      if (typeof _this.unitType === 'undefined' || _this.unitType === null || _this.unitType === '') {
        this.$message.warning('请一条单位类型数据！')
      } else {
      _this.showFlag = !_this.showFlag;
      _this.Params = null;
      _this.unitType1 = _this.unitType;
      }
    },
    modifyData () {
      let _this = this;
      if (typeof _this.multipleSelection3 === 'undefined' || _this.multipleSelection3 === null || _this.multipleSelection3 === '') {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag = !_this.showFlag;
        _this.Params = Object.assign({},_this.multipleSelection3) 
      }
    },
    deleteData () {
       let _this = this;
        if (typeof _this.multipleSelection3 === 'undefined' || _this.multipleSelection3 === null || _this.multipleSelection3 === '') {
        this.$message.warning('请勾选您要停用的数据！')
       } else {
        _this.dialogTableVisible = false;
        _this.multipleSelection = []
        _this.multipleSelection.push(_this.multipleSelection3)
        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/limsbaseunits/abolish', _this.multipleSelection, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('停用操作成功');
         _this.refresh2()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recoverData () {
       let _this = this;
        if (typeof _this.multipleSelection3 === 'undefined' || _this.multipleSelection3 === null || _this.multipleSelection3 === '') {
        this.$message.warning('请勾选您要启用的数据！')
        } else {
        _this.dialogTableVisible = false;
        _this.multipleSelection = []
        _this.multipleSelection.push(_this.multipleSelection3)
        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/limsbaseunits/recover', _this.multipleSelection, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('启用成功');
         _this.refresh2()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    addData2 () {
      let _this = this;
     if (typeof _this.multipleSelection3 === 'undefined' || _this.multipleSelection3 === null || _this.multipleSelection3 === '') {
       this.$message.warning('请选择一条单位信息数据！')
     } else {
      _this.showFlag2 = !_this.showFlag2;
      _this.Params2 = null;
      _this.Params = _this.multipleSelection3
      }
      //  if (_this.multipleSelection.length !== 1) {
      //   this.$message.warning('请选择一条业务规则信息数据！')
      // } else {
      // _this.showFlag2 = !_this.showFlag2;
      // _this.Params2 = null;
      // _this.Params = _this.multipleSelection
      // }
    },
    modifyData2 () {
      let _this = this;
     if (typeof _this.multipleSelection4 === 'undefined' || _this.multipleSelection4 === null || _this.multipleSelection4 === '') {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag2 = !_this.showFlag2;
        _this.Params2 = Object.assign({},_this.multipleSelection4)
        _this.Params = null
      }
    },
    deleteData2 () {
       let _this = this;
       if (typeof _this.multipleSelection4 === 'undefined' || _this.multipleSelection4 === null || _this.multipleSelection4 === '') {
        this.$message.warning('请勾选您要停用的数据！')
      } else {
        _this.dialogTableVisible = false;
        _this.multipleSelection2 = [];
        _this.multipleSelection2.push(_this.multipleSelection4)
        for (var i = 0; i < _this.multipleSelection2.length; i++) {
        _this.multipleSelection2[i].updateMan = userName;
        _this.multipleSelection2[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsbaseunitds/abolish', _this.multipleSelection2, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('停用操作成功');
         _this.refresh3()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recoverData2 () {
       let _this = this;
        if (typeof _this.multipleSelection4 === 'undefined' || _this.multipleSelection4 === null || _this.multipleSelection4 === '') {
        this.$message.warning('请勾选您要启用的数据！')
      } else {
        _this.dialogTableVisible2 = false;
        _this.multipleSelection2 = [];
        _this.multipleSelection2.push(_this.multipleSelection4)
        for (var i = 0; i < _this.multipleSelection2.length; i++) {
        _this.multipleSelection2[i].updateMan = userName;
        _this.multipleSelection2[i].updateNo = userId
        }
        _this.axios.post('pass/baseManagement/v1/limsbaseunitds/recover', _this.multipleSelection2, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('启用成功');
         _this.refresh3()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    searchData () {
        let _this = this;
        _this.dataLoading2 = true;
        _this.page.pageNum = 1;
        _this.axios.get('pass/baseManagement/v1/limsbaseunits/' + 'like/?pageNum=' + _this.page.pageNum + '&pageSize=' + _this.page.pageSize +
          '&ruleName=' + _this.search.ruleName + '&ruleTypeName=' + _this.search.ruleTypeName)
        .then(res => {
          _this.dataLoading2 = false;
          _this.table.list = res.data.list;
          for (let i = 0; i < this.table.list.length; i++) {
          if (this.table.list[i].validFlag === '0') {
            this.table.list[i].validFlag1 = '无效'
          } else if (this.table.list[i].validFlag === '1') {
            this.table.list[i].validFlag1 = '有效'
          }
          }
          _this.page.totalPage = res.data.total;
        }).catch(e => {
          _this.dataLoading2 = false;
        });
      },
    reset () {
      let _this = this;
      _this.search.ruleName = '';
      _this.search.ruleTypeName = '';
      _this.searchData ();
      _this.getDataList3 ();
    },
    handleCurrentChange (val) {
    //   this.multipleSelection = [];
    //   this.multipleSelection.push(val);
      this.multipleSelection3 = val;
      if (val.unitNo === null) {
        this.unitNo = '';
      } else {
        this.unitNo = val.unitNo;
      }
      this.getDataList2 (this.unitNo);

    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList(this.unitTypeCode);
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList(this.unitTypeCode);
    },
    handleCurrentChange2 (val) {
    //   this.multipleSelection2 = [];
    //   this.multipleSelection2.push(val);
      this.multipleSelection4 = val;
    },
    handleCurrentChange3 (val) {
      this.unitType = val;
      if (val.unitTypeCode === null) {
        this.unitTypeCode = '';
      } else {
        this.unitTypeCode = val.baseCode;
      }
      this.getDataList (this.unitTypeCode)
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getDataList2(this.unitNo);
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getDataList2(this.unitNo);
    },
    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);
       });
    },
    addScreen2 () {
     this.$nextTick(() => {
          let ss = document.createElement('div');
          ss.innerHTML = '筛选';
          ss.style = 'text-align: center;'
          this.$refs.dataTable2.$el.getElementsByClassName('el-table__fixed')[0].getElementsByTagName('td')[0].appendChild(ss);
       });
    },
    getDataList (unitTypeCode) {
      if (unitTypeCode === null || unitTypeCode === '') {
        this.table.list = []
        return 0
      } else {
        this.dataLoading2 = true;
        this.axios.get('pass/baseManagement/v1/limsbaseunits/' + '?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize + '&unitTypeCode=' + unitTypeCode)
            .then(res => {
              this.dataLoading2 = false;
              this.table.list = res.data.list;
              for (let i = 0; i < this.table.list.length; i++) {
              if (this.table.list[i].validFlag === '0') {
                this.table.list[i].validFlag1 = '无效'
              } else if (this.table.list[i].validFlag === '1') {
                this.table.list[i].validFlag1 = '有效'
              }
              }
              this.page.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading2 = false;
            });
      }
    },
     getDataList2 (unitNo) {
      this.dataLoading = true;
       if (unitNo === null || unitNo === '') {
        this.table.list2 = [];
        this.dataLoading = false;
        return 0
      } else {
        this.axios.get('pass/baseManagement/v1/limsbaseunitds/' + '?pageNum=' + this.page2.pageNum + '&pageSize=' + this.page2.pageSize + '&unitNo=' + unitNo)
            .then(res => {
              this.dataLoading = false;
              this.table.list2 = res.data.list;
              for (let i = 0; i < this.table.list2.length; i++) {
              if (this.table.list2[i].validFlag === '0') {
                this.table.list2[i].validFlag1 = '无效'
              } else if (this.table.list2[i].validFlag === '1') {
                this.table.list2[i].validFlag1 = '有效'
              }
              }
              this.page2.totalPage = res.data.total;
            }).catch(e => {
              this.dataLoading = false;
            });
      }
    },
    getDataList3 () {
      this.dataLoading3 = true;
     this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode",{validFlag:1,baseCode:4814}, {individualType: 'json'}).then(res => {
              this.dataLoading3 = false;
              this.table.list3 = res.data
            }).catch(e => {
              this.dataLoading3 = false;
            });
   },
    tableRowClassName ({row, column, rowIndex, columnIndex}) {
      if (row.validFlag !== '1') {
        return 'error-row';
      }
      return '';
    },
    tableRowClassName2 ({ 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>
