<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 {salesOfTheDay} 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: "time",
            type:'date',
            format:'yyyy-MM-dd',
            valueFormat:'yyyy-MM-dd HH:mm:ss',
            search:true,
          },
          {
            hide:true,
            searchLabelWidth:120,
            label: "供应商类型",
            prop: "source",
            props: {
              label: 'name',
              value: 'value'
            },
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/getEnumDict?enumName=GoodsSourceEnum",
            search: true,
            rules: [{
              required: true,
              message: "供应商类型",
              trigger: "blur"
            }]
          },{
            label: "供应商名称",
            prop: "sourceName",
            width: 120
          },
          {
            label: "订单号",
          },
          {
            label: "商品名称",
            prop: "nameStr",
          },
          {
            label: "销售单价",
            prop: "salePrice",
          },
          {
            label: "销售数量",
            prop: "totalNum",
          },
          {
            label: "应收金额",
            prop: "receivableAmount",
          },
          {
            label: "折扣金额",
            prop: "deductionAmount",
          },
          {
            label: "实收金额",
            prop: "paidInAmount",
          },
          {
            label: "折扣类型",
            prop: "zoneType",
            search: true,
            props: {
              label: 'name',
              value: 'value'
            },
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/getEnumDict?enumName=ZoneTypeEnum",
            rules: [{
              required: true,
              message: "折扣类型",
              trigger: "blur"
            }]
          }
        ]
      },
      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;
      salesOfTheDay(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>
