<!-- 会员中心-我的出入金-出金申请 -->
<template>
    <app-drawer title="出金申请" :width="800" v-model:show="show" :loading="loading" :refresh="refresh">
        <el-form ref="formRef" class="el-form--horizontal" label-width="100px" :model="formData" :rules="formRules">
            <el-form-item label="资金账号">
                <span>{{ accountInfo?.accountid }}</span>
            </el-form-item>
            <el-form-item label="账户余额">
                <span>{{ accountInfo?.balance }}</span>
            </el-form-item>
            <el-form-item label="入金金额" prop="Amount">
                <el-input type="number" placeholder="请输入" v-model.number="formData.Amount" />
            </el-form-item>
            <el-form-item label="金额大写">
                <span>壹万元</span>
            </el-form-item>
            <el-form-item class="el-form-item--row" label="备注" prop="Remark">
                <el-input type="textarea" :rows="3" v-model="formData.Remark" />
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="onCancel(false)" plain>取消</el-button>
            <el-button type="primary" @click="onSubmit">提交</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useWithdraw } from '@/business/bank'
import AppDrawer from '@pc/components/base/drawer/index.vue'

const { loading, accountInfo, formData, formSubmit } = useWithdraw()
const formRef = ref<FormInstance>()
const show = ref(true)
const refresh = ref(false)

const formRules: FormRules = {
    Amount: [{ required: true, message: '请输入金额', trigger: 'blur' }],
}

const onCancel = (isRefresh = false) => {
    show.value = false
    refresh.value = isRefresh
}

const onSubmit = () => {
    formRef.value?.validate((valid) => {
        if (valid) {
            formSubmit().then(() => {
                ElMessage.success('提交成功')
            }).catch((err) => {
                ElMessage.warning(err)
            }).finally(() => {
                onCancel(true)
            })
        }
    })
}
</script>