<!-- 会员机构管理-机构管理-机构资料管理-资金账户-重置密码 -->
<template>
    <app-drawer :title="t('common.alert')" v-model:show="show" :loading="loading">
        <div class="g-text-message">{{ t('member.institution.user.account.password.message') }}</div>
        <template #footer>
            <el-button @click="onCancel">{{ t('operation.cancel') }}</el-button>
            <el-button type="primary" @click="onSubmit">{{ t('operation.confirm') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { taaccountResetPwd } 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.OrganTaaccountRsp>,
        required: true
    }
})

const { global: { t } } = i18n
const show = shallowRef(true)
const loading = shallowRef(false)

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

const onSubmit = () => {
    loading.value = true
    taaccountResetPwd({
        data: {
            accountid: props.record.accountId
        }
    }).then(() => {
        ElMessage.success(t('member.institution.user.account.password.tips1'))
    }).catch((err) => {
        ElMessage.error(t('member.institution.user.account.password.tips2') + err)
    }).finally(() => {
        loading.value = false
        onCancel()
    })
}
</script>