<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               v-model="form"
               ref="crud1"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
    </avue-crud>
  </basic-container>
</template>

<script>
import {grossProfitStatistics} from "../../api/redenvelopemall/finance";

export default {
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        menu: false,
        // calcHeight: 30,
        // tip: false,
        // searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        addBtn: false,
        selection: true,
        excelBtn: true,
        column: [
          {
            searchLabelWidth:120,
            label: "供应商类型",
            prop: "source",
            props: {
              label: 'name',
              value: 'value'
            },
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/getEnumDict?enumName=GoodsSourceEnum",
          },
          {
            label: "实收金额",
            prop: "totalPaidInAmount",
          },
          {
            label: "协议金额",
            prop: "totalAgreementPrice",
          },
          {
            label: "毛利",
            prop: "grossProfit",
          },
          {
            label: "毛利率",
            prop: "rateOfGrossProfit",
          },
          {
            label: "占比",
            prop: "totalAgreementPrice",
          }
        ]
      },
      data: [],
      selectionList: [],
    }
  },
  created() {
    // this.type = this.option.column[0];
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab.name, tab.label);
      this.activeName = tab.name;
      this.onLoad(this.page);
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      if (params.createTime &&params.createTime.length>0){
        params.startTime=params.createTime[0]
        params.endTime=params.createTime[1]
      }
      console.log('time',params)
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    onLoad() {
      this.loading = true;
      grossProfitStatistics().then(res => {
        const data = res.data.data;
        this.data = data;
        this.loading = false;
        this.selectionClear();
      });
    }
  }
}
</script>
