<!--交接班项目配置-->
<template>
    <div class="examination">
       <div class="common-head-search">
         <el-form :inline="true" @submit.native.prevent>
            <el-form-item label='交接项目类型'>
                 <el-select v-model="search.baseCode" clearable filterable collapse-tags size="small" style="width:200px;margin-right: 10px;" placeholder="请选择查询内容">
                   <el-option v-for="item in sampleType" :key="item.baseCode" :label="item.baseName"
                     :value="item.baseCode">
                   </el-option>
                 </el-select>
            </el-form-item>
            <el-form-item label='交接项目名称'>
              <el-input v-model="search.shiftName" @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>
       <el-row>
           <el-col :span='6'>
             <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">
               <el-table 
               v-loading="dataLoading" 
               ref="dataTable" border :height="tableHeight" 
               highlight-current-row 
               @current-change="handleCurrentChange" 
               :data="table.list" 
               :icore-filter-flag="icoreFilterFlag"
               :header-cell-style="tableHeaderCellStyle" 
               :summary-method="getSummaries2" 
               show-summary>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="180" prop="postName" label="岗位列表" align="center"></el-table-column>
                 <el-table-column sortable :show-overflow-tooltip="true" prop="sectionName" label="班组列表" align="center"></el-table-column>
                   <el-table-column sortable :show-overflow-tooltip="true" prop="deptName" label="部门列表" align="center"></el-table-column>
                     <el-table-column sortable :show-overflow-tooltip="true" prop="companyName" label="公司列表" align="center"></el-table-column>
               </el-table>
             </div>
           </el-col>
           <el-col :span='18'>
             <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="dataLoading2" 
               ref="dataTable" border :height="tableHeight" 
               highlight-current-row 
               @current-change="handleCurrentChange2" 
               :data="table.list2" 
               :icore-filter-flag="icoreFilterFlag"
               :header-cell-style="tableHeaderCellStyle" 
               :summary-method="getSummaries" 
               show-summary>
               <el-table-column prop='indexNo' type="index" label="NO" fixed="left" align="center">
                   <template slot-scope="scope">
                    {{scope.$index+1}} 
                    </template>
               </el-table-column>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="shiftNo" label="交接项目编码" align="center"></el-table-column>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="shiftName" label="交接项目名称" align="center"></el-table-column>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="shiftTypeName" label="交接项目类型" align="center"></el-table-column>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="postName" label="岗位" align="center"></el-table-column>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="defaultValue" label="默认值" align="center"></el-table-column>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" prop="validFlag" 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="100px" prop="memo" label="备注 " align="center"></el-table-column>
               <el-table-column sortable :show-overflow-tooltip="true" min-width="100px" 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>
              </div>
           
           </el-col>
       </el-row>
       
       <div is="alertComponets" :showFlag="showFlag" :Params="Params" :Params2="Params2" @refresh='refresh'></div>
    </div>
</template>
<script>
import alertComponets from './alertComponents';
const INDEX = 'indexNo';
export default {
    components: {alertComponets},
    data () {
        return {
            search: {
                baseCode:'',
                baseName:'',
                shiftName: ''
            },
            sampleType: [],
            dataLoading: false,
            dataLoading2: false,
            tableHeight: 0,
            icoreFilterFlag: true,
            table:{
                list:[],
                list2:[]
            },
            page: {
              pageSize: 50,
              pageNum: 1,
              totalPage: 0
            },
            showFlag: false,
            showFlag2: false,
            Params:{}, 
            Params2:{},  
            indexNo:''
        }
    },
    created () {
        this.tableHeight = window.innerHeight - 150
    },
    mounted () {
      let _this=this;
      _this.axios.get('pass/baseManagement/v1/limsbaseposts/')
      .then(res =>{
        _this.table.list=res.data.list;
        
      })
       _this.axios.get('pass/baseManagement/v1/limsbaseshiftitems/')
      .then(res =>{
        _this.table.list2=res.data.list;
        
      }),
        _this.axios.get('pass/baseManagement/v1/limsbaseinfos/like/'+ '?baseCode=4812')
      .then(res =>{
        _this.sampleType=res.data.list;
        
      })
    },
    methods: {
        getCode(code, arr, codeKey, nameKey) {
        if (!code) {
          return "";
        }
        let targetRow = arr.find((item) => {
          return item[codeKey] === code;
        });
        return targetRow ? targetRow[nameKey] : "";
      }, 
      getSummaries2(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;   
    },
    fetch(){
       return JSON.parse(window.localStorage.getItem(INDEX)|| '[]');
   },
   save(items){
        window.localStorage.setItem(INDEX,JSON.stringify(items))
    },
         getSummaries (param) {
          const { columns, data } = param;
          const sums = [];
           columns.forEach((column, index) => {
              if (index === 0) {
            sums[index] = '合计';
                return;
              }
              if (index === 2) {
                sums[index] = this.page.totalPage;
              }
           });
            return sums;
        },
        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);
           });
        },
        refresh () {
          if(typeof this.limspost === 'undefined' || this.limspost === null || this.limspost === ''){
           this.getDataList2(this.limsupdate.postNo)
          
          }else{
            this.getDataList(this.limspost.postNo)
          }
        
        },
        searchData () {
             this.search.baseName = this.getCode(this.search.baseCode,this.sampleType,'baseCode','baseName');
        this.axios.get('pass/baseManagement/v1/limsbaseshiftitems/like/'+ '?shiftTypeName='+ this.search.baseName +'&shiftName='+this.search.shiftName)
         .then(res =>{
        this.table.list2=res.data.list;
        
      })
        },
        setCurrent(row) {
        this.$refs.dataTable.setCurrentRow(row);
      },//修改完数据后使选中行高亮
        getDataList (postNo) {
           let _this=this;
          _this.axios.get('pass/baseManagement/v1/limsbaseshiftitems/' + '?pageNum=' + _this.page.pageNum + '&pageSize=' + _this.page.pageSize +'&postNo='+postNo)
          .then(res =>{
             _this.table.list2=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;
              this.indexNo=this.fetch();
              this.setCurrent(this.table.list2[this.indexNo]);
          })
        },
        getDataList2 (postNo) {
           let _this=this;
          _this.axios.get('pass/baseManagement/v1/limsbaseshiftitems/' + '?pageNum=' + _this.page.pageNum + '&pageSize=' + _this.page.pageSize +'&postNo='+postNo)
          .then(res =>{
             _this.table.list2=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;
              this.indexNo=this.fetch();
              this.setCurrent(this.table.list2[this.indexNo]);
          })
        },
      
        reset () {
         let _this=this;
         _this.search.baseCode='';
         _this.search.shiftName='';
        _this.axios.get('pass/baseManagement/v1/limsbaseshiftitems/')
        .then(res =>{
        _this.table.list2=res.data.list;
        
          })

        },
        handleCurrentChange (val) {
          this.limspost=val
          if(val.postNo === null){
            this.postNo=''
          }else{
            this.postNo=val.postNo
          }
          this.getDataList(this.postNo);
          
        },
        addData () {
            let _this = this;
         if (typeof _this.limspost === 'undefined' || _this.limspost === null || _this.limspost === '') {
           this.$message.warning('请选择一条岗位名称数据！')
          } else {
         _this.showFlag = !_this.showFlag;
         _this.Params2 = null;
         _this.Params = _this.limspost;
      }
        },
        modifyData (index) {
            let _this = this;
            if (typeof _this.limsupdate === 'undefined' || _this.limsupdate === null || _this.limsupdate === '') {
           this.$message.warning('请勾选一条修改数据！')
          } else {
         _this.showFlag = !_this.showFlag;
         _this.Params2 = _this.limsupdate;
         this.indexNo=index;
      }
        },
        deleteData () {
           let _this = this;
           if (typeof _this.limsupdate === 'undefined' || _this.limsupdate === null || _this.limsupdate === '') {
           this.$message.warning('请勾选一条禁用数据！')
          } else {
            _this.limsupdate.validFlag='0';
             this.axios.put('pass/baseManagement/v1/limsbaseshiftitems/'+_this.limsupdate.shiftNo,_this.limsupdate, {individualType: 'json'}).then(res => {
           if (res.succeed) {
            this.dialogTableVisible = false;
            this.$message.success('禁用成功')
            
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })
          
          }
        },
        recoverData () {
           let _this = this;
           if (typeof _this.limsupdate === 'undefined' || _this.limsupdate === null || _this.limsupdate === '') {
           this.$message.warning('请勾选一条启用数据！')
          } else if(_this.limsupdate.validFlag==='1'){
            console.log(_this.limsupdate.validFlag)
             this.$message.warning('这条数据已被启用')
          }else{

            _this.limsupdate.validFlag='1';
             this.axios.put('pass/baseManagement/v1/limsbaseshiftitems/'+_this.limsupdate.shiftNo,_this.limsupdate, {individualType: 'json'}).then(res => {
           if (res.succeed) {
            this.dialogTableVisible = false;
            this.$message.success('启用成功')
           } else {
            this.$message.error(res.message)
           }
           }).catch(e => {
            this.$message.error(e.message)
          })

          }
        },
        handleCurrentChange2 (val) {
           var i=this.table.list2.indexOf(val);
           this.limsupdate=val
           this.save(i);
        },
        pageSizeChange (size) {
          this.page.pageSize = size;
          this.getDataList2();
        },
        pageCurrentChange (index) {
          this.page.pageNum = index;
          this.getDataList2();
        },
        tableHeaderCellStyle () {
          return 'color: rgb(255,255,255);border-bottom: 1px solid #DCDFE7;'
        },
    }    
}
</script>
<style scoped>

</style>
