<!-- 通知公告-资讯管理-审核 -->
<template>
    <DetailsView ref="detailsRef" v-bind="{ record }" :loading="loading">
        <el-button type="primary" @click="onSubmit(1)">{{ t('notice.news.audit.tips1') }}</el-button>
        <el-button type="primary" @click="onSubmit(0)">{{ t('notice.news.audit.tips2') }}</el-button>
    </DetailsView>
</template>

<script lang="ts" setup>
import { reactive, shallowRef, PropType } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { auditinform } from '@/services/api/notice'
import DetailsView from '../details/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    record: {
        type: Object as PropType<Notice.InformManqueryRsp>,
        required: true
    }
})

const { global: { t } } = i18n
const detailsRef = shallowRef()
const loading = shallowRef(false)

const formData = reactive<Notice.AuditInformReq>({
    id: props.record.id,
    flag: 0,
})

const onSubmit = (flag: number) => {
    ElMessageBox.confirm(
        flag === 1 ? t('notice.news.audit.tips3') : t('notice.news.audit.tips4'),
        t('notice.news.audit.title')
    ).then(() => {
        formData.flag = flag
        loading.value = true

        auditinform({
            data: formData
        }).then(() => {
            ElMessage.success(t('common.tips1'))
            detailsRef.value?.close(true)
        }).catch((err) => {
            ElMessage.error(t('common.tips2') + err)
            detailsRef.value?.close()
        }).finally(() => {
            loading.value = false
        })
    })
}
</script>