<!-- 会员机构管理-机构管理-机构资料管理-登录账户-全部停用/启用 -->
<template>
    <app-drawer :title="t('common.alert')" v-model:show="show" :refresh="refresh" :loading="loading">
        <div class="g-text-message">
            <span v-if="statuses === 1">{{ t('member.institution.user.login.statuses.message1') }}</span>
            <span v-else>{{ t('member.institution.user.login.statuses.message2') }}</span>
        </div>
        <template #footer>
            <el-button @click="onCancel(false)">{{ 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 { updateOrgan2User } from '@/services/api/member'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import { i18n } from '@/stores'

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

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

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

const onSubmit = () => {
    loading.value = true
    updateOrgan2User({
        data: {
            userid: props.record.userid,
            status: props.statuses
        }
    }).then(() => {
        ElMessage.success(t('common.tips1'))
        onCancel(true)
    }).catch((err) => {
        ElMessage.error(t('common.tips2') + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>