<template>
  <div>
    <!--    <el-button @click="this.export">导出</el-button>-->
    <el-table
      id="table"
      :data="dataSet"
      :show-header="true"
      :default-sort="defaultSort"
      v-loading="listLoading"
      element-loading-text="Loading"
      highlight-current-row
      :height="height"
      border
    >
      <el-table-column
        v-for="(_col, index) in header"
        :key="index"
        :prop="_col.prop"
        :fixed="_col.fixed"
        :label="_col.label"
        :width="_col.width"
        :formatter="_col.formatter"
        :sortable="_col.sortable"
        :render-header="_col.renderHeader"
        :column-key="index.toString()"
        :show-overflow-tooltip="true"
        min-width="50px"
        align="center"
      />
    </el-table>
  </div>
</template>

<script>
import { v2tableMapping } from "@/api/report";
export default {
  name: "ZxCommonTable",
  props: {
    sqlId: {
      type: String,
      required: true,
    },
    height: {
      type: String,
      required: false,
      default: '80vh'
    },
    condition: {
      type: Object,
      required: false,
    },
    header: {
      type: Array,
      required: true,
    },
    defaultSort: {
      type: Array,
      required: false,
    },
  },

  data() {
    return {
      queryDate: [],
      listLoading: false,
      dataSet: [],
    };
  },
  created() {},
  mounted() {
    // this.fetchData()
  },

  methods: {
    fetchData() {
      this.listLoading = true;
      this.condition["sqlId"] = this.sqlId;
      v2tableMapping(this.condition).then((response) => {
        this.dataSet = response.result.data;
        this.listLoading = false;
      });
    },
    export() {
      // import('@/vendor/Export2Excel').then(excel => {
      //   const tHeader = ['Id', 'Title', 'Author', 'Readings', 'Date']
      //   excel.export_json_to_excel({
      //     header: tHeader, //表头 必填
      //     data: [['a', 'b', 'c', 'd']],
      //     filename: 'excel-list', //非必填
      //     autoWidth: true, //非必填
      //     bookType: 'xlsx' //非必填
      //   })
      // })
    },
  },
};
</script>
