<template>
  <div class="table-box">
    <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-column
        align="center"
        label="生成对账时间"
        prop="insDt"
        min-width="100"
        #default="{ row }"
      >
        <span> {{ momentTime(row) }} </span>
      </el-table-column>

      <el-table-column
        v-if="orgType == 'SUP' || orgType == 'MSUP' || orgType == 'YBJ'"
        align="center"
        label="医院名称"
        prop="hospName"
        min-width="100"
      />
      <el-table-column
        v-if="orgType == 'HOS' || orgType == 'MHOS' || orgType == 'YBJ'"
        align="center"
        label="配送商名称"
        prop="supplierName"
        min-width="100"
      />
      <el-table-column v-if="orgType" == null align="center" label="医院名称"
      prop="hospName" min-width="100" />
    </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 moment from "moment";
export default {
  name: "tableView",
  components: {},
  data() {
    return {
      loding: false, // 表格数据加载loding
      tableData: tableData, // 表格数据
      clumnData: clumnData, // 表格头数据
      total: 0,
      pageSize: 10,
      crutPage: 1,
      orgType: "",
    };
  },
  props: {
    getTableData: {
      type: Object,
      default: {},
    },
  },
  created() {
    let { user } = this.$store.state;
    if (user && user.orgType) {
      this.orgType = user.orgType;
    }
  },
  methods: {
    momentTime(row) {
      return moment(row.insDt).format("yyyy-MM-DD HH:mm:ss");
    },
    //表格点击触发
    rowClick(row, column, event) {
      let { type } = this.$route.query;
      let pushPath = "durgdetails";
      if (this.orgType == "SUP" || this.orgType == "HOS" || type == "药品") {
        pushPath = "durgdetails";
      }
      if (this.orgType == "MSUP" || this.orgType == "MHOS" || type == "耗材") {
        pushPath = "sumdetails";
      }
      this.$router.push({
        name: pushPath,
        query: {
          ...row,
        },
      });
    },
    // 搜索区域输入的数据
    getSearchData(data) {
      console.log(data, "搜索查询到的数据");
    },
    //每页几条数据
    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;
    },
  },
};
</script>
<style scoped lang="scss">
.table-box {
  padding: 1px;
  position: relative;
  padding-bottom: 50px;
  .block {
    position: absolute;
    right: 10px;
    bottom: 10px;
  }
}
</style>
