<template>
  <div class="main-content m20">
    <!--body-查询结果-->
    <div class="content-body">
      <div class="body">
        <div class="header">
          <span>{{ title }}</span>
        </div>
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableInfo.datas"
          tooltip-effect="dark"
          style="width: 95%;margin:0 auto"
          :fit="true"
          :height="defaultHeight"
          :row-class-name="tableRowClassName"
          :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
        >
          <el-table-column prop="index" label="序号" min-width="70" align="center">
            <template slot-scope="scope">
              {{ (pageParam.curPage - 1 ) * pageParam.pageSize + scope.$index + 1 }}
            </template>
          </el-table-column>
          <template v-for="(item,index) in tableInfo.titles">
            <el-table-column :key="item" :prop="tableInfo.fields[index]" show-overflow-tooltip :label="item" min-width="180" align="left" />
          </template>
        </el-table>
        <div v-if="showPagination" class="page-box">
          <el-row>
            <el-col :span="6" />
            <el-col :span="18" :offset="6">
              <el-pagination
                :disabled="loading"
                :page-size="pageParam.pageSize"
                :total="tableInfo.total"
                :page-sizes="[10, 20, 30, 40,50,100,200]"
                layout="slot,total, sizes, prev, pager, next, jumper"
                @size-change="pageSizeChange"
                @current-change="pageIndexChange"
              >
                <span>
                  第 {{ pageParam.curPage }} 页 /
                  共 {{ (tableInfo.total !== 0 ? parseInt((tableInfo.total + pageParam.pageSize - 1)/pageParam.pageSize) : 1) }} 页
                </span>
              </el-pagination>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tableInfo: {
      type: Object,
      default: () => {
        return {}
      }
    },
    title: {
      type: String,
      default: () => {
        return ''
      }
    },
    defaultHeight: {
      type: String,
      default: () => {
        return '300'
      }
    },
    showPagination: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  data() {
    return {
      loading: false,
      pageParam: {
        pageSize: 10,
        curPage: 1
      }
    }
  },
  watch: {},
  mounted() {},
  methods: {
    pageSizeChange(val) {
      this.pageParam.pageSize = val
      this.$emit('pageSizeChangeTable', val)
    },
    pageIndexChange(val) {
      this.pageParam.curPage = val
      this.$emit('pageIndexChangeTable', val)
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.page-box{
  margin:10PX;
  .el-pagination{
    text-align: right;
  }
}

.header{
  width: 95%;
  margin: 10px auto;
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: 600;
  color: #000;
  img{
    margin-right:10px;
  }
}
</style>
