<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 {costBreakdownStatistics} 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: [
          {
            label: "时间",
            prop: "createTime",
          },
          {
            hide:true,
            searchLabelWidth:120,
            label: "供应商类型",
            prop: "source",
            props: {
              label: 'label',
              value: 'value'
            },
            type: "select",
            dicData:[{
              label:'中宏',
              value:0,
            },{
              label:'胜天半子',
              value:1,
            },{
              label:'唯品尚',
              value:2,
            }],
            search: true,
            rules: [{
              required: true,
              message: "供应商类型",
              trigger: "blur"
            }]
          },{
            label: "供应商名称",
            prop: "sourceName",
            width: 120
          },
          {
            label: "合同号",

          },
          {
            label: "商品名称",
            prop: "goodsName",
            hide:true,
          },
          {
            label: "商品名称",
            prop: "nameStr",
          },
          {
            label: "协议单价",
            prop: "",
          },
          {
            label: "数量",
            prop: "sale",
          },
          {
            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) {
      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(page, params = {}) {
      this.loading = true;
      costBreakdownStatistics(page.currentPage, page.pageSize,Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    }
  }
}
</script>
