<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.plineNo" @keyup.enter.native="searchData()" size="small" placeholder="请输入查询内容" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label='产线描述'>
          <el-input v-model="search.plineName" @keyup.enter.native="searchData()" size="small" 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-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" style="margin-bottom:0">
       <el-table v-loading="dataLoading" ref="dataTable" border :height="theight1" highlight-current-row @selection-change="handleSelectionChange" :data="table.list" :icore-filter-flag="icoreFilterFlag"
       :header-cell-style="tableHeaderCellStyle" @current-change="handleCurrentChange" :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" fixed="left"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="plineNo" label="产线编号" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="plineName" label="产线描述" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="plineAbbr" label="产线简写" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="companyName" label="公司名称"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="deptName" label="部门名称"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="120px" prop="sectionName" label="班组名称"  align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="validFlag1" 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="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="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">
       <el-table v-loading="dataLoading2" ref="dataTable2" border :height="theight2" highlight-current-row @selection-change="handleSelectionChange2" :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" fixed="left"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="processNo" label="工序编号 " align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" prop="processName" label="工序描述" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="160px" prop="plineName" label="产线名称" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="processAbbr" label="工序简写" align="center"></el-table-column>
        <el-table-column sortable :show-overflow-tooltip="true" min-width="90px"  prop="validFlag1" 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="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="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 is="alertComponets" :showFlag="showFlag" :Params="Params" @refresh='refresh'></div>
    <div is="alertComponets2" :showFlag2="showFlag2" :Params="Params" :Params2="Params2" @refresh='refresh2'></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: []
      },
      dataLoading: false,
      dataLoading2: false,
      icoreFilterFlag: true,
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      page2: {
        pageSize: 999,
        pageNum: 1,
        totalPage: 0
      },
      plineNo: '',
      showFlag: false,
      Params: {},
      showFlag2: false,
      Params2: {},
      multipleSelection: [],
      // multipleSelection3: {},
      // multipleSelection4: {},
      multipleSelection2: [],
      search: {
        plineName: '',
        plineNo: ''
      },
      theight1:0,
      theight2:0
    }
  },
  created(){
    this.theight1 = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;
    this.theight2 = window.innerHeight / 2 - 130 < 249 ? 249 : window.innerHeight / 2 - 130;;
  },
 mounted () {
    this.getDataList();
    // this.getDataList2();
    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;
    },
    refresh () {
      let _this = this;
      _this.getDataList();
      _this.getDataList2(_this.plineNo);
      // _this.multipleSelection.splice(0, 1);
      // _this.multipleSelection2 = []
      // console.log(_this.multipleSelection)
    },
    refresh2 () {
      let _this = this;
      _this.getDataList2(_this.plineNo);
    },
    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 = Object.assign({},_this.multipleSelection) 
      }
    },
    deleteData () {
       let _this = this;
        if (_this.multipleSelection.length < 1) {
        this.$message.warning('请勾选您要停用的数据！')
       } else {
        _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/limsbaseplines/abolish', _this.multipleSelection, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('停用操作成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recoverData () {
       let _this = this;
        if (_this.multipleSelection.length < 1) {
        this.$message.warning('请勾选您要启用的数据！')
        } else {
        _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/limsbaseplines/recover', _this.multipleSelection, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('启用成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    addData2 () {
      let _this = this;
     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 (_this.multipleSelection2.length !== 1) {
        this.$message.warning('请勾选您要修改的一条数据！')
      } else {
        _this.showFlag2 = !_this.showFlag2;
        _this.Params2 = Object.assign({},_this.multipleSelection2) ;
        _this.Params = null
      }
    },
    deleteData2 () {
       let _this = this;
       if (_this.multipleSelection2.length < 1) {
        this.$message.warning('请勾选您要停用的数据！')
      } else {
        _this.dialogTableVisible = false;
        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/limsbaseprocesss/abolish', _this.multipleSelection2, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('停用操作成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    recoverData2 () {
       let _this = this;
        if (_this.multipleSelection2.length < 1) {
        this.$message.warning('请勾选您要启用的数据！')
      } else {
        _this.dialogTableVisible2 = false;
        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/limsbaseprocesss/recover', _this.multipleSelection2, {individualType: 'json'}).then(res => {
        if (res.succeed) {
         this.$message.success('启用成功');
         _this.refresh()
        } else {
         this.$message.error(res.message)
        }
        }).catch(e => {
         this.$message.error(e.message)
       })
      }
    },
    searchData () {
      this.page.pageNum = 1;
      this.page.pageSize = 50
      this.getDataList()
    },
    reset () {
      let _this = this;
      _this.search.plineName = '';
      _this.search.plineNo = '';
      _this.searchData();
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
      if(val.length > 0) {
        this.plineNo = val[val.length-1].plineNo
        this.getDataList2(this.plineNo)
      }
    },
    handleSelectionChange2 (val) {
      this.multipleSelection2 = val
    },
    pageSizeChange (size) {
      this.page.pageSize = size;
      this.getDataList();
    },
    pageCurrentChange (index) {
      this.page.pageNum = index;
      this.getDataList();
    },
    pageSizeChange2 (size) {
      this.page2.pageSize = size;
      this.getDataList2(this.plineNo);
    },
    pageCurrentChange2 (index) {
      this.page2.pageNum = index;
      this.getDataList2(this.plineNo);
    },
    handleCurrentChange (val) {
      if (val.plineNo === null) {
        this.plineNo = '';
      } else {
        this.plineNo = val.plineNo;
      }
      this.getDataList2 (this.plineNo);
    },
    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 () {
      this.dataLoading = true;
      this.axios.get('pass/baseManagement/v1/limsbaseplines/' + 'like/?pageNum=' + this.page.pageNum + '&pageSize=' + this.page.pageSize +
          '&plineName=' + this.search.plineName + '&plineNo=' + this.search.plineNo)
        .then(res => {
          this.dataLoading = 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.dataLoading = false;
        });
    },
    getDataList2 (plineNo) {
      this.dataLoading2 = true;
      if (plineNo === null || plineNo === '') {
        this.table.list2 = [];
        this.dataLoading2 = false;
        return 0
      } else {
        this.axios.get('pass/baseManagement/v1/limsbaseprocesss/' + '?pageNum=' + this.page2.pageNum + '&pageSize=' + this.page2.pageSize + '&plineNo=' + plineNo)
            .then(res => {
              this.dataLoading2 = 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.dataLoading2 = 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>
