<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <!-- <div class="filter-container">
      <el-input v-model="listQuery.shopName" clearable size="mini" class="filter-item" style="width: 200px; margin-left: 10px" placeholder="请输入商家名称" />
      <el-button size="mini" class="filter-item" type="primary" icon="el-icon-search" style="margin-left: 10px" @click="handleSearch">查找</el-button>
      <br />
      <el-button size="mini" type="primary" icon="el-icon-plus" @click="$refs.EditModal && $refs.EditModal.handleOpen({ shopId: '' })">添加</el-button>
    </div> -->

    <!-- 查询结果 -->
    <div v-tableHeight>
      <el-table v-loading="listLoading" height="100%" element-loading-text="正在查询中。。。" :data="list" v-bind="{ stripe: true, size: 'small', border: true, fit: true, highlightCurrentRow: true }">
        <el-table-column align="center" label="商家ID" prop="shopId" fixed="left" />
        <el-table-column align="center" label="商家名称 " prop="shopName"></el-table-column>

        <el-table-column align="center" label="审核状态" prop="auditStatus">
          <template slot-scope="{ row }">
            <el-tag v-if="row.auditStatus === 2" :style="{ marginRight: '6px' }" type="success">已通过</el-tag>
            <el-tag v-if="row.auditStatus === 1" :style="{ marginRight: '6px' }" type="warning">已申请</el-tag>
            <el-tag v-if="row.auditStatus === 3" :style="{ marginRight: '6px' }" type="danger">不通过</el-tag>
          </template>
        </el-table-column>

        <el-table-column align="center" label="提现比例" prop="ratio">
          <template slot-scope="{ row }">
            <el-tag v-if="row.ratio" :style="{ marginRight: '6px' }" type="success">{{ row.ratio * 100 + '%' }}</el-tag>
            <span v-else>--</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作" width="220" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="{ row }">
            <el-button :disabled="[2, 3].includes(row.auditStatus)" type="warning" size="mini" @click="handleDetail(row)">资格审核</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div style="padding-top: 10px;">
      <el-pagination
        :current-page="listQuery.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="(val) => (listQuery.pageSize = val) && getList()"
        @current-change="(val) => (listQuery.page = val) && getList()"
      />
    </div>

    <Examine @refresh="refresh" ref="examineRef"></Examine>
  </div>
</template>

<script>
import { getWithdrawalApplicationList } from '@/api/business'
import Examine from './Examine.vue'

export default {
  name: 'voucherApply',
  components: { Examine },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        pageSize: 20
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      this.listLoading = true
      try {
        const res = await getWithdrawalApplicationList(this.listQuery)
        this.list = res.data.list
        this.total = res.data.total
      } finally {
        this.listLoading = false
      }
    },
    handleSearch() {
      this.listQuery.page = 1
      this.getList()
    },
    handleDetail(row) {
      this.$refs.examineRef && this.$refs.examineRef.open(row)
    },
    refresh() {
      this.listQuery.page = 1
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  display: flex;
  flex-direction: column;

  .filter-container {
    .filter-item {
      display: inline-block;
      vertical-align: middle;
      margin-bottom: 10px;
    }
  }

  .small-padding {
    .cell {
      padding-left: 5px;
      padding-right: 5px;
    }
  }

  .fixed-width {
    .el-button--mini {
      padding: 7px 10px;
    }
  }
}
</style>
