<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" :close-on-click-modal="false"
        @closed="closeDialog">
        <el-form ref="form" :model="form" :rules="rules" label-width="90px">
            <el-form-item label="网络名称" prop="networkName">
                {{ form.networkName }}
            </el-form-item>
            <el-form-item label="用户" prop="userName">
                {{ form.userName }}
            </el-form-item>
            <el-form-item label="提现金额(U)" prop="amount">
                {{ form.amount }}
            </el-form-item>
            <el-form-item label="提现状态" prop="statusName">
                {{ form.statusName }}
            </el-form-item>
            <!-- <el-form-item label="确认时间" prop="confirmTime">
                <el-date-picker v-model="form.confirmTime" type="datetime" placeholder="选择日期">
                </el-date-picker>
            </el-form-item> -->
            <el-form-item label="手续费" prop="fee">
                {{ form.fee }}
            </el-form-item>
            <el-form-item v-if="form.status === 'pending' || form.status === 'approved'" label="审核状态"
                prop="approveStatus">
                <el-radio-group v-model="form.approveStatus">
                    <template v-if="form.status === 'pending'">
                        <el-radio v-for="(item, index) in options" :key="'option_' + index" :label="item.value">{{
                            item.label }}</el-radio>
                    </template>
                    <template v-else-if="form.status === 'approved'">
                        <el-radio v-for="(item, index) in confirmOptions" :key="'confirm_option_' + index"
                            :label="item.value">{{
                                item.label }}</el-radio>
                    </template>
                </el-radio-group>
            </el-form-item>
            <el-form-item v-if="form.status==='approved'" label="交易Hash" prop="hash">
                <el-input v-model="form.hash" placeholder="交易Hash" />
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" maxlength="200" show-word-limit placeholder="备注" />
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" :loading="loading" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { approve, confirm } from '@/api/admin/member-withdrawal-log'

export default {
    name: 'approve',
    props: {
        open: {
            type: Boolean,
            default: false
        },
        title: {
            type: String,
            default: "提现审核"
        },
        data: {
            type: Object,
            default: () => { }
        }
    },
    watch: {
        open(val) {
            this.dialogVisible = val
        },
        data(val) {
            this.form = { approveStatus: 1, ...val }
        }
    },
    data() {
        return {
            dialogVisible: this.open,
            form: {

            },
            loading: false,
            // approveStatus:1,
            rules: {
                approveStatus: [{ required: true, message: '请选择审核状态', trigger: 'trigger' }]
            },
            options: [{
                label: '通过',
                value: 1
            }, {
                label: '拒绝',
                value: 2
            }],
            confirmOptions: [
                {
                    label: "已转账",
                    value: 1
                },
                {
                    label: "转账失败",
                    value: 2
                }
            ]
        }
    },
    methods: {
        submitForm() {
            this.loading = true
            //审核
            if (this.form.status === 'pending') {
                approve({ id: this.form.id, approval: this.form.approveStatus, remark: this.form.remark }).then(res => {
                    if (res.code === 200) {
                        this.msgSuccess(res.msg)
                        this.cancel()
                    }
                })
                    .finally(f => {
                        this.loading = false
                    })
            } else if (this.form.status === 'approved') { //确认提现
                confirm({ id: this.form.id, confirmVal: this.form.approveStatus, remark: this.form.remark ,hash:this.form.hash}).then(res => {
                    console.log("res", res)
                    if (res.code === 200) {
                        this.msgSuccess(res.msg)
                        this.cancel()
                    }
                })
                    .finally(f => {
                        this.loading = false
                    })
            } else {
                this.loading = false
            }
        },
        closeDialog() {
            this.form = {}
            this.loading = false
            this.$emit('update:open', false)
        },
        cancel() {
            this.dialogVisible = false
        }
    }
}
</script>