<!-- 会员机构管理-机构管理-机构资料管理-自营会员登录账号-锁定/解锁 -->
<template>
    <app-drawer :title="t('common.alert')" v-model:show="show" :refresh="refresh" :loading="loading">
        <div class="g-text-message">
            <span v-if="isActivated">确认锁定该账户？</span>
            <span v-else>确认解锁该账户？</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, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { selfSupportLock } from '@/services/api/member'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    selectedItem: {
        type: Object as PropType<Model.SelfSupportRsp>,
        required: true
    }
})

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

const isActivated = computed(() => props.selectedItem.loginstatus === 1)

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

const onSubmit = () => {
    loading.value = true
    selfSupportLock({
        data: {
            loginid: props.selectedItem.loginid,
            status: isActivated.value ? 2 : 1
        }
    }).then(() => {
        ElMessage.success('提交成功')
        onCancel(true)
    }).catch((err) => {
        ElMessage.error('提交失败：' + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>