<template>
  <div class="SalesReportRejectedNew">
    <date-picker-title :title="title" @refresh="handleRefresh" />
    <el-table :data="tableData" size="mini" border v-loading="loading">
      <el-table-column type="index" width="40px" />
      <el-table-column label="产品编码" prop="good_code" width="160px" show-overflow-tooltip />
      <el-table-column label="产品名称" prop="good_name" min-width="160px" show-overflow-tooltip />
      <el-table-column label="当日库存销售" prop="good_num" width="120px" show-overflow-tooltip />
      <el-table-column label="当日库存发货" prop="send_num" width="100px" show-overflow-tooltip/>
      <el-table-column label="当前剩余可用库存" prop="stock_num" width="120px" show-overflow-tooltip/>
      <el-table-column label="业务公司名称" prop="supplierName" min-width="190px" show-overflow-tooltip/>
      <el-table-column label="库存采购单" prop="good_price" width="90px" show-overflow-tooltip/>
      <el-table-column label="当前库存消耗金额" prop="total_fee" width="130px" show-overflow-tooltip />
    </el-table>
  </div>
</template>

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

      const res = await asyncRequest.salestock({
        start_day: this.date[0] || "",
        end_day: this.date[1] || "",
        page:1,
        size: 10000
      });

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

        const totalItem = Number(res.data.list.reduce((prev,{total_fee}) => {
          return addition(prev, total_fee,)
        },0)).toFixed(2)

        this.tableData.push({
          good_code: '合计',
          total_fee:totalItem
        })
      } else {
        this.tableData = [];
      }

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