<!-- 审核弹窗 -->
<template>
    <ele-modal v-model="visible" title="提现审核" width="500">
        <el-form ref="formRef" :model="form" label-width="100px">
            <el-form-item label="审核结果" required>
                <el-radio-group v-model="form.auditResult">
                    <el-radio :label="1">通过</el-radio>
                    <el-radio :label="2">拒绝</el-radio>
                </el-radio-group>
            </el-form-item>
        </el-form>

        <template #footer>
            <el-button @click="visible = false">取消</el-button>
            <el-button type="primary" @click="handleSubmit">确定</el-button>
        </template>
    </ele-modal>
</template>

<script setup>
    import { ref, reactive } from 'vue';
    import request from '@/utils/request';
    import { ElMessage } from 'element-plus';

    const emit = defineEmits(['success']);
    const visible = defineModel({ type: Boolean });

    const form = reactive({
        auditResult: 1,
        idList: []
    });

    const formRef = ref();

    // 打开弹窗
    const handleOpen = (ids) => {
        form.idList = Array.isArray(ids) ? ids : [ids];
        form.auditResult = 1;
        visible.value = true;
    };

    // 提交审核
    const handleSubmit = async () => {
        try {
            request
                .post('/sys/finance/withdrawAudit', {
                    idList: form.idList,
                    auditResult: form.auditResult
                })
                .then((res) => {
                    if (res.data.code === 200) {
                        ElMessage.success('审核成功');
                        visible.value = false;
                        emit('success');
                    } else {
                        ElMessage.error(res.data.msg);
                    }
                });
        } catch (error) {
            console.error('审核失败:', error);
        }
    };

    defineExpose({
        handleOpen
    });
</script>
