<!--
 * @Author: your name
 * @Date: 2022-01-08 14:47:24
 * @LastEditTime: 2022-01-19 16:18:10
 * @LastEditors: Please set LastEditors
 * @Description: 表格
 * @FilePath: \goldenPig\src\components\table-cpn\TableContent.vue
-->
<template>
  <div class="table-content">
    <div class="header">
      <div class="left">
        <slot name="leftTitle"> </slot>
      </div>
      <div class="right">
        <slot name="rightHandler"> </slot>
      </div>
    </div>

    <div class="content">
      <el-table
        empty-text="暂无数据"
        :data="dataList"
        :size="tableSize"
        :height="height"
        row-key="id"
        default-expand-all
        border
      >
        <el-table-column
          v-if="shows.select"
          type="selection"
          width="55"
          align="center"
        >
        </el-table-column>
        <el-table-column
          v-if="shows.index"
          type="index"
          label="序号"
          width="60"
          align="center"
        >
        </el-table-column>
        <template v-for="item in propList">
          <el-table-column
            :key="item.label"
            :align="item.align || 'center'"
            v-bind="item"
          >
            <template #default="scope">
              <slot :name="item.slotName" :row="scope.row"> </slot>
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>

    <div class="footer" v-if="footer">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentChange"
        :current-page="currentPage"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    /** 表格 */
    height: {
      type: Number,
      default: 458,
    },
    propList: {
      type: Array,
      required: true,
    },
    shows: {
      type: Object,
      default: () => ({
        select: false,
        index: false,
      }),
    },
    dataList: {
      type: Array,
      required: true,
    },
    tableSize: {
      type: String,
      default: "small",
    },
    treeProps: {
      type: Object,
      default: () => ({}),
    },
    /** 分页 */
    footer: {
      type: Boolean,
      default: true,
    },
    pageSizes: {
      type: Array,
      default: () => [10, 20, 40, 100],
    },
    total: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      /** 分页 */
      pageSize: 10,
      currentPage: 1,
    };
  },
  methods: {
    /** 分页相关 */
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.$emit("handleSizeChange", this.pageSize);
    },
    currentChange(val) {
      this.currentPage = val;
      this.$emit("handleCurrentChange", this.currentPage);
    },
  },
};
</script>
<style scoped>
.table-content {
  margin: 15px;
  background-color: #fff;
  border-radius: 5px;
  padding: 20px 25px 20px 25px;
}

.header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 5px;
}

.right {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.footer {
  margin-top: 15px;
  text-align: right;
}
</style>
