<template>
  <div class="wrap-box" v-loading="viewLoding">
    <!-- 头部搜索组件 -->
    <el-card class="box-card">
      <searchView @searchSuses="getSearchData"></searchView>
    </el-card>
    <br />
    <el-card class="box-card">
      <!-- 表格组件 -->
      <tableView
        :getTableData="tabledata"
        @pageTruning="changeTrunig"
        :searchData="searchData"
      ></tableView>
    </el-card>
  </div>
</template>
<script>
import searchView from "./searchView/index.vue";
import tableView from "./tableView/index.vue";
import { getAccountDetlDrug } from "@/api/details/index";
import moment from "moment";
const pagaData = { current: 1, size: 10 };
export default {
  name: "wrapView",
  components: {
    searchView,
    tableView,
  },
  data() {
    return {
      curetPage: 1, //表格当前在第几页
      size: 10, //表格一页有几条数据
      tabledata: {}, //接口请求到的表格数据
      viewLoding: false, //数据加载中loding
      searchData: {},
    };
  },
  created() {
    //刚进入页面请求数据
    this.getTableData(pagaData);
  },
  methods: {
    momentTime(row) {
      return moment(row).format("yyyy-MM-DD HH:mm:ss");
    },
    //点击搜索按钮触发
    getSearchData(data) {
      this.searchData = data;
      this.getTableData({ ...data, ...pagaData });
    },
    //获取表格数据接口
    getTableData(data) {
      this.viewLoding = true;
      let pamData = this.$route.query;
      let parmObj = {};
      let { orgType, userID } = this.$store.state.user;
      if (orgType == "SUP") {
        parmObj["splerId"] = userID;
        parmObj["hospId"] = pamData.hospId;
      } else if (orgType == "HOS") {
        parmObj["hospId"] = userID;
        parmObj["splerId"] = pamData.supplierId;
      } else {
        parmObj["hospId"] = pamData.hospId;
        parmObj["splerId"] = pamData.supplierId;
      }
      let newDate = this.momentTime(pamData.insDt);
      // 接口请求
      getAccountDetlDrug({ ...data, ...parmObj, insDt: newDate })
        .then((res) => {
          this.viewLoding = false;
          if (res.success == true) {
            this.tabledata = res.data;
          }
        })
        .catch((error) => {
          this.viewLoding = false;
        });
    },
    //分页器改变触发
    changeTrunig(pageTrunig) {
      this.getTableData({
        current: pageTrunig.current,
        size: pageTrunig.size,
      });
    },
  },
};
</script>
<style scoped>
.wrap-box {
  padding: 5px;
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

::-webkit-scrollbar {
  display: none;
  /* Chrome Safari */
}
</style>
