<template>
  <div class="p-2">
    <div>
      <el-card shadow="hover" class="mb-[10px]">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px" size="default" class="ry_form">
          <el-form-item label="充值码" prop="code">
            <el-input v-model.trim="queryParams.code" placeholder="请输入充值码" clearable />
          </el-form-item>
          <el-form-item label="昵称" prop="nickname">
            <el-input v-model.trim="queryParams.nickname" placeholder="请输入昵称" clearable />
          </el-form-item>
          <el-form-item label="充值人手机号" prop="phone">
            <el-input v-model.trim="queryParams.phone" placeholder="请输入手机号码" clearable />
          </el-form-item>
          <el-form-item label="充值方式" prop="method">
            <el-select v-model="queryParams.method">
              <el-option v-for="item in userWithdrawMethodMap" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="充值类型" prop="type">
            <el-select v-model="queryParams.type">
              <el-option v-for="item in userWithdrawTypeMap" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <!--        <el-form-item label="审核状态" prop="auditStatus">
          <el-select v-model="queryParams.auditStatus">
            <el-option v-for="item in userWithdrawAuditMap" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>-->
          <el-form-item label="充值状态" prop="status">
            <el-select v-model="queryParams.status">
              <el-option v-for="item in userWithdrawStatusMap" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item class="flex_one tr">
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            <!--        <el-button :icon="showMoreCondition ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"  @click="showMoreCondition = !showMoreCondition">{{showMoreCondition ? '收起条件' : '展开条件'}}</el-button>-->
          </el-form-item>
        </el-form>
      </el-card>
      <el-card shadow="hover">
        <el-table v-loading="userChargeInfoTableLoading" :data="userChargedrawInfo.data" border empty-text="暂无数据">
          <el-table-column label="充值人" prop="createBy" align="center" />
          <el-table-column label="充值时间" prop="createTime" align="center" />
          <!--        <el-table-column label="提现码" prop="code" />-->
          <el-table-column label="充值方式" prop="method" align="center">
            <template v-slot="scope">
              {{ getEmulistLabelById(scope.row.method, userWithdrawMethodMap) }}
            </template>
          </el-table-column>
          <el-table-column label="充值类型" prop="type" align="center">
            <template v-slot="scope">
              {{ getEmulistLabelById(scope.row.type, userWithdrawTypeMap) }}
            </template>
          </el-table-column>
          <el-table-column label="充值状态" prop="status" align="center">
            <template v-slot="scope">
              {{ getEmulistLabelById(scope.row.status, userWithdrawStatusMap) }}
            </template>
          </el-table-column>
          <el-table-column label="充值金额" prop="money" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.money || '0.00' }} </template>
          </el-table-column>
          <el-table-column label="手续费" prop="fee" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.fee || '0.00' }} </template>
          </el-table-column>

          <el-table-column label="实际充值金额" prop="actualMoney" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.actualMoney || '0.00' }} </template>
          </el-table-column>
        </el-table>
        <pagination
          v-if="userChargedrawInfo.total"
          :total="userChargedrawInfo.total"
          v-model:page="chargeDataParams.current"
          v-model:limit="chargeDataParams.size"
          @pagination="
            () => {
              getList(userChargedrawInfo.record);
            }
          "
        />
      </el-card>
    </div>
  </div>
</template>
<script>
import { getUserChargeList } from '@/api/trade/index.js';

export default {
  name: 'UmsChargeManage',
  data() {
    return {
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        nickname: null,
        phone: null,
        code: '',
        method: undefined,
        type: undefined,
        auditStatus: undefined,
        status: undefined
      },
      userWithdrawMethodMap: [],
      userWithdrawTypeMap: [],
      userWithdrawStatusMap: [],
      userWithdrawAuditMap: [],

      userChargedrawInfo: {
        total: 0,
        data: [],
        record: {}
      },
      userChargeInfoModalVisible: false,
      userChargeInfoTableLoading: false,
      chargeDataParams: {
        current: 1,
        size: 10
      }
    };
  },
  created() {
    this.getList();
    this.getWithdrawEmu();
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nickName: null,
        phone: null,
        code: '',
        method: undefined,
        type: undefined,
        auditStatus: undefined,
        status: undefined
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },

    showAuditModal(record) {
      this.currentRecord = record;
      this.auditFormOpen = true;
    },
    resetAuditForm() {
      this.currentRecord = {};
      this.auditFormOpen = false;
      this.auditStatus = null;
      this.auditReason = null;
    },

    /** 查询会员信息列表 */
    getList() {
      this.userChargeInfoTableLoading = true;
      const { current: pageNum, size: pageSize } = this.queryParams;
      const query = { ...this.queryParams, pageNum: undefined, pageSize: undefined };
      const pageReq = { current: pageNum - 1, size: pageSize };
      getUserChargeList(query, pageReq)
        .then((response) => {
          const { records = [], total = 0 } = response.data || {};
          this.userChargedrawInfo = {
            total: total,
            data: records || []
          };
          this.userChargeInfoTableLoading = false;
        })
        .catch(() => {
          this.userChargeInfoTableLoading = false;
        });
    },

    async getWithdrawEmu() {
      const userWithdrawMethodMap = await this.getDictionaryByKey('ums_withdraw_method');
      const userWithdrawTypeMap = await this.getDictionaryByKey('ums_withdraw_type');
      const userWithdrawStatusMap = await this.getDictionaryByKey('ums_withdraw_status');
      const userWithdrawAuditMap = await this.getDictionaryByKey('sys_common_audit');

      this.userWithdrawMethodMap = userWithdrawMethodMap;
      this.userWithdrawTypeMap = userWithdrawTypeMap;
      this.userWithdrawStatusMap = userWithdrawStatusMap;
      this.userWithdrawAuditMap = userWithdrawAuditMap;
    }
  }
};
</script>
