<template>
  <div>
    <el-table stripe ref="tables" :row-class-name="tableClassName" v-loading="loading" highlight-current-row :data="data" :header-cell-style="{background:'#EEEEEE',color:'#333'}" size="mini" @row-click="rowClick" height="calc(100vh - 327px)" style="width:100%;" @selection-change="handleSelectionChange"  border>
      <div slot="empty">
        <el-empty :image="require('../../../assets/empty.svg')" :image-size="250">
        </el-empty>
      </div>
      <el-table-column
        type="selection"
        width="45" 
        @handleSelectionChange="handleSelectionChange">
      </el-table-column>
      <el-table-column  v-for="col in layout" :key="col.tablecolid" :prop="col.columnname" :label="col.title" :width="col.width ? col.width : 0" :min-width="col.width ? col.width : 0" :fixed="checkFixed(col.columnname)">
        <template slot-scope="scope">
          <slot v-if="col.columnname !== 'operation'" name="customcol" :column="{data:scope.row,columnname:col.columnname}"></slot>
          <slot v-if="col.columnname === 'operation'" name="opreation" :data="scope.row"></slot>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {mapGetters} from "vuex"
export default {
  /*
    layout:表结构数据;
    data:表渲染数据;
    custom:是否启用自定义结构;
    opwidth:操作列宽度
  */
  props:['data','tableName','custom','layout','fixRightData','fixLeftData'],
  data () {
    return {
      list:[]
    }
  },
  computed:{
    ...mapGetters({
      loading:'loading'
    })
  },
  methods:{
    rowClick (row) {
      this.$emit('rowClick',row)
    },
    tableClassName ({row,rowIndex}) {
      row.index = rowIndex
    },
    handleSelectionChange(val) {
      this.$emit('checkboxCallBack',val)      
    },
    checkFixed (columnname) {
      let isRight = this.fixRightData.some(item=>item === columnname)
      let isLeft = this.fixLeftData.some(item=>item === columnname)
      if (columnname === 'operation'){
        console.log(columnname,this.fixRightData,isRight)
      }
      
      if (isRight) return 'right'
      if (isLeft) return 'left'
    }
  },
  mounted () {
  }
}

</script>
<style>
</style>