<template>
    <basic-container class="base">
      <avue-crud
      :data="tableData"
      :option="tabOption"
      :page.sync="page"
      :table-loading="tableLoading"
      @on-load="getList"
      @size-change="sizeChange"
      @current-change="currentChange"
      @search-change="searchVal"
      >
        <template  slot-scope="scope" slot="menu">
          <el-button v-if='scope.row.approvalStatus =="PENDING"' type="text" @click="auditClick(scope.row)">审核</el-button>
          <el-button v-else type="text" @click="auditClick(scope.row)">详情</el-button>        </template>
      </avue-crud>
    </basic-container>
</template>

<script>
import { tabOption } from '@/const/crud/account/invioce/index.js'
import { getInvoiceAdmin } from '@/api/account/invoice/index.js'

export default {
  data() {
    return {
      tableData: [],
      tabOption,
      page: {
        total: 0, // 总页数
        pageSize: 10,
        pagerCount:0,
      },
      tableLoading: false
    }
  },
  activated() {
    this.getList(this.page)
  },
  methods: {
    async  getList(page, params) {
      this.tableLoading = true
      let data = Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm
        )
      let res = await getInvoiceAdmin(data)
      if(res.data.code === 0) {
        this.tableData = res.data.data.records
        this.page.total = res.data.data.total
      }
      this.tableLoading = false
    },
    // 分页查询
    sizeChange(pageSize){
      this.page.pageSize = pageSize;
    },
    currentChange(current){
      this.page.currentPage = current;
    },
    searchReset() {
      this.searchForm = {};
    },
    searchVal(form, done) {
      this.searchForm = form;
      this.page.currentPage = 1;
      this.getList(this.page, form);
      done();
    },
    auditClick(row) {
      this.$router.push({
        path: "/admin/account/recharge/audit?id=" + row.id,
      });
    },
  }
}
</script>

<style lang="scss" scoped>

</style>
