<template>
    <basic-container>
  <el-tabs v-model="activeName" @tab-click="handleClick">
    <el-tab-pane label="绿色积分" name="1">
        <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>
    </el-tab-pane>
    <el-tab-pane label="红色积分" name="2">
      <avue-crud :option="option"
                 :table-loading="loading"
                 :data="data"
                 :page.sync="page"
                 v-model="form"
                 ref="crud"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 @selection-change="selectionChange"
                 @current-change="currentChange"
                 @size-change="sizeChange"
                 @refresh-change="refreshChange"
                 @on-load="onLoad">
      </avue-crud>
    </el-tab-pane>
    <el-tab-pane label="抢红包" name="3">
      <avue-crud :option="option"
                 :table-loading="loading"
                 :data="data"
                 :page.sync="page"
                 v-model="form"
                 ref="crud3"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 @selection-change="selectionChange"
                 @current-change="currentChange"
                 @size-change="sizeChange"
                 @refresh-change="refreshChange"
                 @on-load="onLoad">
      </avue-crud>
    </el-tab-pane>
    <el-tab-pane label="分红型红包" name="4">
      <avue-crud :option="option"
                 :table-loading="loading"
                 :data="data"
                 :page.sync="page"
                 v-model="form"
                 ref="crud3"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 @selection-change="selectionChange"
                 @current-change="currentChange"
                 @size-change="sizeChange"
                 @refresh-change="refreshChange"
                 @on-load="onLoad">
      </avue-crud>
    </el-tab-pane>
  </el-tabs>
  </basic-container>
</template>

<script>
import {info} from "@/api/platform/userticket";
export default {
  data(){
    return {
      activeName: '2',
      optionTab:{
        column: [{
          label: '绿色积分',
          prop: '1',
        }, {
          label: '红色积分',
          prop: '2',
        }, {
          label: '抢红包',
          prop: '3',
        }]
      },
      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: "userName",
            search: true
          },
          {
            label: "用户账号",
            prop: "account",
            width: 120
          },
          {
            label: "类型",
            prop: "typeDesc",
          },
          {
            label: "上月余额",
            prop: "lastMonthBalance",
          },
          {
            label: "本月增加额",
            prop: "currMonthIncrease",
          },
          {
            label: "本月减少额",
            prop: "currMonthReduced",
          },
          {
            label: "本月余额",
            prop: "currMonthBalance",
          },
          {
            label: "本月提现总额",
            prop: "currMonthWithdrawn",
          }
        ]
      },
      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;
      info(page.currentPage, page.pageSize, this.activeName, 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>
