<template>
  <div class="e-dynamic-table">
    <el-table v-loading="loading" :data="tableList" :row-key="rowKey" :border="border"  @selection-change="handleSelectionChange">

      <el-table-column type="selection" v-if="isSelect" width="50" align="center" />

      <el-table-column
        v-if="isIndex"
        type="index"
        label="序号"
        align="center"
        :index="
          (val) => {
            return (
              val + 1 + (queryParams.pageNum - 1) * this.queryParams.pageSize
            );
          }
        "
        width="80px"
      ></el-table-column>

      <el-table-column
        :label="tableItem.label || ''"
        :align="tableItem.align || 'left'"
        :prop="tableItem.prop || ''"
        :width="tableItem.width || ''"
        v-for="(tableItem, idx) in filterList"
        :key="idx"
      >
        <template slot-scope="scope">
          <slot v-if="tableItem.slot" :name="tableItem.slotName" :row="scope.row" ></slot>
          <span v-else class="lay-table-textarea" :title="scope.row[tableItem.prop || '']">
            {{ scope.row[tableItem.prop || ''] }}
          </span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="tableTotal > 0"
      :total="tableTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="handleQuery2"
    />
  </div>
</template>
<script>
export default {
  name: "EDynamicTable",
  props: {
    border: {
      type: Boolean,
      default: false,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    tableTotal: {
      type: Number,
      default: 0,
    },
    queryParams: {
      type: Object,
      default: () => {
        return {
          pageNum: 1,
          pageSize: 10,
        };
      },
    },
    tableList: {
      type: Array,
      default: () => {
        return [];
      },
    },
    filterList: {
      type: Array,
      default: () => {
        return [];
      },
    },
    isIndex: {
      type: Boolean,
      default: false,
    },
    isSelect: {
      type: Boolean,
      default: false
    },
    rowKey: {
      type: String,
      default: 'id'
    }
  },
  data() {
    return {
      filter: [
        {
          label: "",
          align: 'left',
          prop: '',
          width: '',
          slot: true,
          slotName: 'inst'
        },
      ],
    };
  },
  methods: {
    handleQuery2() {
      this.$emit('handleQuery', this.queryParams)
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.$emit('tableSelectionChange', selection)
    },
  }
};
</script>

