<template>
  <div class="table-box">
    <el-button type="primary" icon="el-icon-download" @click="DownloadData()"
      >导出</el-button
    >
    <br />
    <br />
    <el-table
      ref="multipleTable"
      v-loading="loding"
      :data="tableData"
      element-loading-text="加载中..."
      border
      fit
      highlight-current-row
      max-height="400"
      @row-dblclick="rowClick"
    >
      <template slot="empty">
        <img src="" alt />
        <p>暂无数据</p>
      </template>
      <el-table-column fixed="left" align="center" type="index" label="序号" />
      <el-table-column
        v-for="item in clumnData"
        align="center"
        :label="item.label"
        :key="item.prop"
        :prop="item.prop"
        :min-width="item.width"
      />
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="crutPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { clumnData, tableData } from "./clumnData";
import { exportAllProdHospExcel } from "@/api/settimview/index";
import { exportData } from "./const";
import moment from "moment";
let newTime = moment()
  .month(moment().month() - 1)
  .startOf("month")
  .format("yyyyMM");
export default {
  name: "tableView",
  components: {},
  data() {
    return {
      loding: false, // 表格数据加载loding
      tableData: [], // 表格数据
      clumnData: clumnData, // 表格头数据
      total: 0,
      pageSize: 10,
      crutPage: 1,
      pamData: {},
      orgType: "",
      searchData: {},
    };
  },
  props: {
    getTableData: {
      type: Object,
      default: {},
    },
    getsearchData: {
      type: Object,
      default: {},
    },
  },
  created() {},
  mounted() {},
  methods: {
    // 搜索区域输入的数据
    getSearchData(data) {
      console.log(data, "搜索查询到的数据");
    },
    //数据导出
    DownloadData() {
      let { user } = this.$store.state;
      let newTimeCode = !this.searchData.initCode
        ? newTime
        : this.searchData.initCode;
      exportAllProdHospExcel({
        ...this.searchData,
        type: "drug",
        initCode: newTimeCode,
        userId: user.userID,
      }).then((res) => {
        const _res = res.data;
        exportData(_res);
      });
    },
    //每页几条数据
    handleSizeChange(val) {
      this.pageSize = val;
      this.crutPage = 1;
      let tablePam = { size: val, current: 1 };
      this.$emit("pageTruning", tablePam);
    },
    // 当前在第几页
    handleCurrentChange(val) {
      this.crutPage = val;
      let tablePam = { size: this.pageSize, current: val };
      this.$emit("pageTruning", tablePam);
    },
  },
  watch: {
    //表格数据发生改变时重新渲染
    getTableData(newData, oldData) {
      let data = newData.records ? newData.records : [];
      this.tableData = data;
      this.total = newData.total ? newData.total : 0;
      this.pageSize = newData.size ? newData.size : 10;
    },
    getsearchData(newData, oldData) {
      this.searchData = newData;
    },
  },
};
</script>
<style scoped lang="scss">
.table-box {
  padding: 1px;
  position: relative;
  padding-bottom: 50px;
  .block {
    position: absolute;
    right: 10px;
    bottom: 10px;
  }
}
</style>
