<!-- 交易商管理-交易商管理-交易商管理-登录账户-锁定 -->
<template>
    <app-drawer :title="t('common.alert')" v-model:show="show" :loading="loading" :refresh="refresh">
        <div class="g-text-message" v-if="selectedItem.loginstatus === 1">{{ t('investor.manage.user.login.lock.tips2') }}</div>
        <div class="g-text-message" v-else>{{ t('investor.manage.user.login.lock.tips1') }}</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 { lockAccount } from '@/services/api/investor'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    selectedItem: {
        type: Object as PropType<Investor.InvestorLoginListRsp>,
        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 = () => {
    const { loginid, loginstatus } = props.selectedItem
    loading.value = true
    lockAccount({
        data: {
            loginid,
            status: loginstatus === 1 ? 2 : 1
        }
    }).then(() => {
        ElMessage.success(loginstatus === 1 ? t('investor.manage.user.login.lock.tips3') : t('investor.manage.user.login.lock.tips4'))
        onCancel(true)
    }).catch((err) => {
        ElMessage.error((loginstatus === 1 ? t('investor.manage.user.login.lock.tips5') : t('investor.manage.user.login.lock.tips6')) + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>