<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"
        :getsearchData="searchData"
      ></tableView>
    </el-card>
  </div>
</template>
<script>
import searchView from "./searchView/index.vue";
import tableView from "./tableView/index.vue";
import { getAuerySumHospData } from "@/api/organview/index";
import moment from "moment";
const pagaData = { current: 1, size: 10 };
let newTime = moment()
  .month(moment().month() - 1)
  .startOf("month")
  .format("yyyyMM");
export default {
  name: "wrapView",
  components: {
    searchView,
    tableView,
  },
  data() {
    return {
      curetPage: 1, //表格当前在第几页
      size: 10, //表格一页有几条数据
      tabledata: {}, //接口请求到的表格数据
      viewLoding: false, //数据加载中loding
      searchData: {},
    };
  },
  created() {
    //刚进入页面请求数据
    this.getTableData(pagaData);
  },
  methods: {
    //点击搜索按钮触发
    getSearchData(data) {
      this.searchData = data;
      this.getTableData({ ...data, ...pagaData });
    },
    //获取表格数据接口
    getTableData(data) {
      let newTimeCode = !data.initCode ? newTime : data.initCode;
      this.viewLoding = true;
      getAuerySumHospData({ ...data, type: "mcs", initCode: newTimeCode })
        .then((res) => {
          this.viewLoding = false;
          if (res.success == true) {
            this.tabledata = res.data;
          }
        })
        .catch((error) => {
          this.viewLoding = false;
        });
    },
    //分页器改变触发
    changeTrunig(pageTrunig) {
      this.getTableData({
         ...this.searchData,
        current: pageTrunig.current,
        size: pageTrunig.size,
      });
    },
  },
};
</script>
<style scoped>
.wrap-box {
  padding: 5px;
}
</style>
