<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="#" type="index" width="50"></el-table-column>
        <el-table-column align="center" prop="shopId" label="商家ID" width="70" />
        <el-table-column align="center" prop="vouchersNumber" label="代金券提现数量" width="120" />
        <el-table-column align="center" prop="amount" label="实际提现金额" width="120" />
        <el-table-column align="center" prop="type" label="代金券提现类型" width="120">
          <template slot-scope="{ row }">
            <el-tag v-if="row.type === 1">充值</el-tag>
            <el-tag v-if="row.type === 2">兑换</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="ratio" label="代金券提现比例" width="120">
          <template slot-scope="{ row }">
            <el-tag type="success">{{ parseInt(row.ratio * 100) + '%' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="handleSn" label="对应提现单号" width="200" />
        <el-table-column align="center" prop="entryAccountSn" label="入账单号集合">
          <template slot-scope="{ row }">
            <el-popover placement="right" width="400" trigger="click">
              <ul class="popover-list">
                <li class="popover-list-li" v-for="(item, index) in row.entryAccountSn.split(',')" :key="item + index">{{ item }}</li>
              </ul>
              <el-button slot="reference" type="primary" size="mini">查看</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="outgoingAccountSn" label="出账单号集合">
          <template slot-scope="{ row }">
            <el-popover placement="right" width="400" trigger="click">
              <ul class="popover-list">
                <li class="popover-list-li" v-for="(item, index) in row.outgoingAccountSn.split(',')" :key="item + index">{{ item }}</li>
              </ul>
              <el-button slot="reference" type="primary" size="mini">查看</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="createTime" label="创建时间"></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>
  </div>
</template>

<script>
import { getWithdrawalRecortAllApi } from '@/api/business'

export default {
  name: 'withdrawalRecord',
  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 getWithdrawalRecortAllApi(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>
.popover-list {
  height: 300px;
  overflow-y: auto;

  &::-webkit-scrollbar {
    background-color: transparent;
    width: 10px;
  }

  &::-webkit-scrollbar-thumb {
    background-color: #e9e9e9;
    border-radius: 5px;
    width: 10px;
  }

  .popover-list-li {
    height: 30px;
    line-height: 30px;
    padding-left: 20px;
    position: relative;

    &::after {
      content: '';
      position: absolute;
      display: block;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background-color: #409eff;
      top: 50%;
      left: 0;
      transform: translateY(-50%);
    }
  }
}
</style>
