<template>
  <div>
    <basic-container>
      <avue-crud
        :option="option"
        :data="dataList"
        ref="crud"
        v-model="form"
        :page.sync="page"
        :search.sync="search"
        @search-change="searchChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        @on-load="onLoad"
        :table-loading="loading"
        @saveColumn="saveColumn"
      >
        <template slot="corpIdSearch">
          <crop-select
            v-model="search.corpId"
            corpType="KH"
          ></crop-select>
        </template>
        <template slot-scope="scope" slot="corpId">
          {{ scope.row.corpName }}
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import option from './config/mainList.json';
import {getList} from '@/api/maintenance/overpayment';

export default {
  name: "index",
  data() {
    return {
      option: {},
      dataList: [],
      form: {},
      page: {
        pageSize: 10,
        pagerCount: 5,
        total: 0,
      },
      search: {},
      loading: false,
    }
  },
  created() {
    this.option = option
    let i = 0;
    this.option.column.forEach(item => {
      if (item.search) i++
    })
    if (i % 3 !== 0){
      const num = 3 - Number(i % 3)
      this.option.searchMenuSpan = num * 8;
      this.option.searchMenuPosition = "right";
    }
  },
  methods: {
    searchChange(params, done) {
      this.onLoad(this.page, params);
      done();
    },
    currentChange(val) {
      this.page.currentPage = val;
    },
    sizeChange(val) {
      this.page.currentPage = 1;
      this.page.pageSize = val;
    },
    refreshChange() {
      this.onLoad(this.page, this.search);
    },
    onLoad(page, params) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, params)
        .then(res => {
          this.dataList = res.data.data.records ? res.data.data.records : [];
          this.page.total = res.data.data.total;
          if (this.page.total) {
            this.option.height = window.innerHeight - 260;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    async saveColumn() {},
  },
}
</script>

<style scoped>

</style>
