<!-- 通知公告-资讯管理-详情 -->
<template>
    <app-drawer :title="t('notice.news.details.title1')" width="900" v-model:show="show" :refresh="refresh">
        <app-table-details :data="data" :label-width="120" :cell-props="detailProps" :column="2">
            <!-- 缩略图 -->
            <template #coverimage="{ value }">
                <el-image :src="getFirstPathFullUrl(value)" fit="cover" lazy style="width: 128px; height: 72px" />
            </template>
            <!-- 内容 -->
            <template #context="{ value }">
                <div v-html="value"></div>
            </template>
        </app-table-details>
        <template #footer>
            <el-button @click="close(false)">{{ t('operation.close') }}</el-button>
            <slot></slot>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate, getFirstPathFullUrl } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { informDetail } from '@/services/api/notice'
import { CellProp } from '@pc/components/base/table-details/types'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTableDetails from '@pc/components/base/table-details/index.vue'
import { i18n } from '@/stores'

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

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

const flagEnum = useEnum('flag')

const { data } = useRequest(informDetail, {
    params: {
        id: props.record.id,
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const detailProps = computed<CellProp[]>(() => [
    { prop: 'columnname', label: 'notice.news.details.columnname' },
    { prop: 'author', label: 'notice.news.details.author' },
    { prop: 'srcname: string;', label: 'notice.news.details.srcname' },
    { prop: 'hits', label: 'notice.news.details.hits' },
    { prop: 'istop', label: 'notice.news.details.istop', formatValue: (val) => flagEnum.getEnumTypeName(val) },
    { prop: 'isshow', label: 'notice.news.details.isshow', formatValue: (val) => flagEnum.getEnumTypeName(val) },
    { prop: 'publishdate', label: 'notice.news.details.publishdate', formatValue: (val) => formatDate(val, 'YYYY-MM-DD') },
    { prop: 'coverimage', label: 'notice.news.details.coverimage', entireRow: true },
    { prop: 'title', label: 'notice.news.details.title', entireRow: true },
    { prop: 'brief', label: 'notice.news.details.brief', entireRow: true },
    { prop: 'context', label: 'notice.news.details.context', entireRow: true }
])

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

defineExpose({
    close
})
</script>