<!-- 交易商管理-个性化管理-交易商分组管理-分组交易商-删除 -->
<template>
    <app-drawer :title="t('common.alert')" v-model:show="show" :loading="loading" :refresh="refresh">
        <div class="g-text-message">{{ t('investor.custom.group.user.delete.tips') }}{{ selectedItem.userid }}{{ t('investor.custom.group.user.delete.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 { delInvestorForPer } 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.PersonalizedDetailRsp>,
        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
    delInvestorForPer({
        data: {
            userid: props.selectedItem.userid
        }
    }).then(() => {
        ElMessage.success(t('common.tips5'))
        onCancel(true)
    }).catch((err) => {
        ElMessage.error(t('common.tips6') + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>