<template>
  <div class="SalesReportRejectedNew" v-loading="loading">
    <el-table :data="tableData" size="mini" border>
      <el-table-column label="备库部门" prop="name" />
      <el-table-column label="备库单数" prop="num" />
    </el-table>
  </div>
</template>

<script>
import asyncRequest from "@/api/newReport";
import setHeight from "@/mixins/index";
import { addition } from "./_utils";
export default {
  name: "Consult",
  mixins: [setHeight],
  props: ['date'],
  watch: {
    date: function(val) {
      this.dataTime = val;
      if (val && val.length === 2) {
        this.searchList();
      }
    }
  },
  data() {
    return {
      loading: false,
      tableData:[]
    };
  },
  async created() {
    window.onresize = () => {
      this.getHeight();
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.getHeight();
    });
    this.searchList();
  },
  methods: {
    async searchList() {
      this.loading = true;
      this.tableData = [];

      const res = await asyncRequest.bkOrder({
        start: this.date[0] || "",
        end: this.date[1] || ""
      });

      if (res.code === 0 && res.data && res.data.length > 0) {
        this.tableData = res.data

        this.tableData.push({
          name: '总计',
          num:this.tableData.reduce((prev, {num}) => {
            return addition(prev, num)
          }, 0)
        })
      } else {
        this.tableData = [];
      }

      this.getHeight();
      this.loading = false;
    }
  }
};
</script>
