<!-- 会员机构管理-机构管理-机构开户申请-审核拒绝 -->
<template>
    <app-drawer :title="t('member.institution.open.details.title1')" width="480" v-model:show="show" :loading="loading" :refresh="refresh">
        <el-form ref="formRef" label-width="100px" :model="formData" :rules="formRules" :show-message="false">
            <el-form-item :label="t('member.institution.open.details.reason')" prop="remark">
                <el-input type="textarea" v-model="formData.remark" maxlength="200" :rows="5" :placeholder="t('common.pleaseenter')" />
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="onCancel(false)">{{ t('operation.close') }}</el-button>
            <el-button type="primary" @click="onSubmit">{{ t('operation.submit') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { ref, PropType, toRaw } from 'vue'
import { ElMessage, FormInstance, FormRules } from 'element-plus'
import { wskhUserinfoApproved } from '@/services/api/member'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    record: {
        type: Object as PropType<Member.MemberDetail>,
        required: true
    }
})

const { global: { t } } = i18n
const formRef = ref<FormInstance>()
const show = ref(true)
const refresh = ref(false)
const loading = ref(false)

const formData = ref<Partial<Member.MemberDetail>>({
    userid: props.record.userid,
    auditflag: 2
})

// 表单验证规则
const formRules: FormRules = {
    remark: [{ required: true }],
}

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

const onSubmit = () => {
    formRef.value?.validate((valid) => {
        if (valid) {
            loading.value = true
            wskhUserinfoApproved({
                data: toRaw(formData.value)
            }).then(() => {
                ElMessage.success(t('common.tips7'))
                onCancel(true)
            }).catch((err) => {
                ElMessage.error(t('common.tips8') + err)
                onCancel()
            }).finally(() => {
                loading.value = false
            })
        }
    })
}
</script>