<!--
 * @Author: Fly
 * @Date: 2025-12-20 09:41:16
 * @LastEditTime: 2025-12-23 14:18:46
 * @Description: 
-->
<template>
    <Drawer :title="DrawerTitle" :visible.sync="DrawerVisible" :showFooter="true" :skeleton="skeletonLoading"
        :wrapperClosable="true" :size="$drawerWidth(800)">
        <el-form ref="form" label-width="120px" :size="ELsize">
            <div class="form-headline">提现信息</div>
            <el-row class="form-content">
                <el-col :span="24">
                    <el-form-item label="提现单号：">{{ FormData.withdrawalNo | AgentLevelOptionFilter | TableItemEmpty
                    }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="提现人：">{{ FormData.withdrawalName | TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="用户手机号：">{{ FormData.withdrawalPhone | TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="申请时间：">{{ FormData.createTime | TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="提现金额：">{{ FormData.amount | TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="提现手续费：">{{ FormData.fee | TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="资金来源：">{{ FormData.withdrawalSource | WithdrawalSourceOptionFilter |
                        TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="提现方式：">{{ FormData.withdrawalMethod | WithdrawalMethodOptionFilter |
                        TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="提现账号：">{{ FormData.accountInfo | TableItemEmpty }}</el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="提现状态：">{{ FormData.status | WithdrawalStatusOptionFilter | TableItemEmpty
                    }}
                    </el-form-item>
                </el-col>


            </el-row>
        </el-form>
        <el-form ref="auditFormRef" label-width="120px" :model="EditForm" :rules="EditFormRules" :size="ELsize">
            <div class="form-headline">审核信息</div>
            <el-row class="form-content" v-if="formType == 'detail'">
                <!-- 查看 -->
                <el-form-item label="审核状态：">{{ FormData.auditStatus | AuditStatusOptionFilter | TableItemEmpty }}
                </el-form-item>
                <el-form-item label="审核结果：">{{ FormData.auditResult | TableItemEmpty }}</el-form-item>
            </el-row>
            <!-- 审核 -->
            <template v-if="isAuditStatus(FormData.auditStatus)">
                <el-form-item label="审核状态：" prop="auditStatus">
                    <el-radio-group v-model="EditForm.auditStatus">
                        <el-radio :label="AuditStatusEnum.AUDIT_APPROVED">通过</el-radio>
                        <el-radio :label="AuditStatusEnum.AUDIT_REJECTED">拒绝</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="审核结果："
                    :prop="EditForm.auditStatus === AuditStatusEnum.AUDIT_REJECTED ? 'auditResult' : ''">
                    <el-input v-model="EditForm.auditResult" type="textarea" :autosize="{ minRows: 3 }"></el-input>
                </el-form-item>
            </template>
        </el-form>
        <template v-slot:footer>
            <template v-if="isAuditStatus(FormData.auditStatus)">
                <el-button type="primary" :size="ELsize" :loading="submitAuditLoading"
                    @click.stop="submitAuditForm">提交审核</el-button>
            </template>
            <el-button :size="ELsize" @click.stop="DrawerVisible = false">取消</el-button>
        </template>

    </Drawer>
</template>

<script>
import { getWithdrawalDetail, setWithdrawalAudit } from "@/api/financeManage";
import { AuditStatusEnum } from "@/utils/statusEnum.js";
export default {
    name: '',
    data() {
        return {
            AuditStatusEnum,
            DrawerTitle: '',
            DrawerVisible: false,
            skeletonLoading: false,
            FormData: {},
            formType: 'detail', // detail | audit
            EditForm: {
                auditStatus: '',
                auditResult: ''
            },
            EditFormRules: {
                auditStatus: [
                    { required: true, message: '请选择审核状态', trigger: 'blur' }
                ],
                auditResult: [
                    { required: true, message: '请输入审核结果', trigger: 'blur' }
                ]
            },
            submitAuditLoading: false,
        };
    },
    created() {
        // setTimeout(() => {
        //     this.openHandle({ id: 45 })
        // }, 100);
    },

    methods: {
        isAuditStatus(auditStatus) {
            try {
                // console.log("this.formType === 'audit' = ", this.formType === 'audit');
                // console.log("auditStatus == AuditStatusEnum.AUDIT_APPROVED", auditStatus, AuditStatusEnum.AUDIT_PENDING);
                return this.formType === 'audit' && auditStatus == this.AuditStatusEnum.AUDIT_PENDING;
            } catch (error) {
                // console.log("isAuditStatus error", error);
                return false;
            }
        },
        async openHandle(row, type = 'audit') {
            this.EditForm = {
                auditStatus: '',
                auditResult: ''
            };
            const { id } = row || {};
            this.skeletonLoading = true;
            this.formType = type || 'detail';
            this.DrawerTitle = this.formType === 'detail' ? '查看' : '审核';
            this.DrawerVisible = true;
            let V_ = null;
            try {
                if (id) {
                    const { data } = await getWithdrawalDetail(id);
                    V_ = data;
                }
            } catch { }
            this.FormData = V_ || row || {};
            this.skeletonLoading = false;
        },
        async submitAuditForm() {
            this.$refs.auditFormRef.validate(async (valid) => {
                if (valid) {
                    try {
                        this.submitAuditLoading = true;
                        const Parmas = {
                            ...this.EditForm,
                            id: this.FormData.id
                        }
                        await setWithdrawalAudit(Parmas);
                        const s = setTimeout(() => {
                            this.DrawerVisible = false;
                            this.$emit('success');
                        }, 500);
                    } catch { } finally {
                        this.submitAuditLoading = false;
                    }
                }
            });
        },
    },
};
</script>