<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="ID" prop="id">
        <el-input
            v-model="queryParams.id"
            :placeholder="'请输入ID'"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="systemName+'号'" prop="usercode">
        <el-input
          v-model="queryParams.usercode"
          :placeholder="'请输入'+systemName+'号'"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户名称" prop="cardName">
        <el-input
          v-model="queryParams.cardName"
          placeholder="请输入账户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户" prop="cardAccount">
        <el-input
          v-model="queryParams.cardAccount"
          placeholder="请输入账户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="审核状态" clearable size="small">
          <el-option
              v-for="dict in cashStatusList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
              @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-check"
          size="mini"
          :disabled="multiple"
          v-hasPermi="['cai:accountCash:edit']"
          @click="handleBatchSuccess"
        >批量通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cai:accountCash:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-upload"
            size="mini"
            @click="handleImport"
            v-hasPermi="['cai:accountCash:edit']"
        >导入(批量通过)</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="accountCashList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" width="60" />
      <el-table-column label="订单号" align="center" prop="orderNo" show-overflow-tooltip/>
      <el-table-column :label="systemName+'号'" align="center" prop="usercode" />
      <el-table-column label="不通过退紫贝" align="center" prop="coinCallbackCoin" />
      <el-table-column label="提现紫贝" align="center" prop="withdrawCoin" />
      <el-table-column label="提现金额" align="center" prop="cashMoney" />
      <el-table-column label="银行名称" align="center" prop="bank" />
      <el-table-column label="账户名称" align="center" prop="cardName" />
      <el-table-column label="账户" align="center" prop="cardAccount" />
      <el-table-column label="状态" align="center" prop="status" >
        <template v-slot="scope">
          <cai-dict-tag :options="cashStatusList" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createTime" width="140"/>
      <el-table-column label="审核人IP" align="center" prop="operateIp" />
      <el-table-column label="审核时间" align="center" prop="verifyTime" show-overflow-tooltip />
      <el-table-column label="审核备注" align="center" prop="verifyRemark" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        <template v-slot="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleSuccess(scope.row)"
            v-if="scope.row.status === 1"
            v-hasPermi="['cai:accountCash:edit']"
          >通过</el-button>
          <el-button
              size="mini"
              type="text"
              @click="handleFail(scope.row)"
              v-if="scope.row.status === 1"
              v-hasPermi="['cai:accountCash:edit']"
          >不通过</el-button>
          <el-button
              size="mini"
              type="text"
              @click="handleClose(scope.row)"
              v-if="scope.row.status === 1"
              v-hasPermi="['cai:accountCash:edit']"
          >取消</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <import-audit-account-cash-dialog v-if="importAuditAccountCashVisible" ref="importAuditAccountCash" @refreshDataList="getList" />
  </div>
</template>

<script>
import {
  accountCashBatchSuccess,
  accountCashClose,
  accountCashFail,
  accountCashSuccess,
  listAccountCash
} from '@/api/cai/accountCash'
import {cashStatusList} from '@/constant/statusMap'
import ImportAuditAccountCashDialog from '@/views/cai/accountCash/import-audit-account-cash-dialog.vue'

export default {
  name: "AccountCash",
  components:{
    ImportAuditAccountCashDialog
  },
  data() {
    return {
      systemName: process.env.VUE_APP_SYSTEM_HOME,
      cashStatusList,
      importAuditAccountCashVisible:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户提现记录表格数据
      accountCashList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        usercode: undefined,
        orderNo: undefined,
        cardName: undefined,
        cardAccount: undefined,
        status: 1,
        id: undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户提现记录列表 */
    getList() {
      this.loading = true;
      listAccountCash(this.queryParams).then(response => {
        this.accountCashList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleImport(){
      this.importAuditAccountCashVisible = true
      this.$nextTick(() => {
        this.$refs.importAuditAccountCash.init()
      })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleSuccess(row) {
      const id = row.id
      this.$modal.confirm('是否确认通过该提现？').then(() => {
        this.loading = true;
        return accountCashSuccess(id);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    handleFail(row) {
      const id = row.id
      this.$prompt('请输入拒绝理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputType: 'textarea',
        inputPattern: /^.{1,100}$/,
        inputErrorMessage: '理由必填，不超过100个字符'
      }).then(({value}) => {
        this.loading = true;
        return accountCashFail(id,value);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    handleClose(row) {
      const id = row.id
      this.$modal.confirm('是否取消该提现？').then(() => {
        this.loading = true;
        return accountCashClose(id);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    handleBatchSuccess() {
      const ids = this.ids;
      this.$modal.confirm('是否批量确认通过该提现？').then(() => {
        this.loading = true;
        return accountCashBatchSuccess(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cai/accountCash/export', {
        ...this.queryParams
      }, `提现记录_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
