<!-- 通知公告-公告通知管理-弹出 -->
<template>
    <app-drawer :title="t('common.alert')" v-model:show="show" :loading="loading" :refresh="refresh">
        <div class="g-text-message">
            <span v-if="record.isforcedisplay">是否取消强制弹出此公告消息？</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 } from 'vue'
import { ElMessage } from 'element-plus'
import { updateforcedisplay } from '@/services/api/notice'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    record: {
        type: Object as PropType<Notice.QueryRsp>,
        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
    updateforcedisplay({
        data: {
            auditid: props.record.autoid,
            isforcedisplay: props.record.isforcedisplay ? 0 : 1,
        }
    }).then(() => {
        ElMessage.success('操作成功')
        onCancel(true)
    }).catch((err) => {
        ElMessage.error('操作失败：' + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>