<!-- 通知公告-公告通知管理-详情 -->
<template>
    <app-drawer title="详情" width="900" v-model:show="show"
        :refresh="refresh">
        <app-table-details title="信息" :data="data" :label-width="120" :cell-props="detailProps1" :column="2">
            <template #content="{ value }">
                <div v-html="value"></div>
            </template>
        </app-table-details>
        <app-table-details title="审核" :data="data" :label-width="120" :cell-props="detailProps2" :column="2" />
        <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 } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { noticeMsgDetail } 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.QueryRsp>,
        required: true
    }
})

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

const msgtypeEnum = useEnum('msgtype') // 消息类型
const sendtypeEnum = useEnum('sendtype') // 发布类型

const { data } = useRequest(noticeMsgDetail, {
    params: {
        auditid: props.record.autoid,
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const detailProps1 = computed<CellProp[]>(() => [
    { prop: 'msgtype', label: '消息类型', formatValue: (val) => msgtypeEnum.getEnumTypeName(val) },
    { prop: 'sendtype', label: '推送方式', formatValue: (val) => sendtypeEnum.getEnumTypeName(val) },
    { prop: 'membername', label: '接收交易商', show: props.record.sendtype === 3 },
    { prop: 'membername', label: '接收会员', show: props.record.sendtype === 2 || props.record.sendtype === 4 },
    { prop: 'scheduletime', label: '生效时间', formatValue: (val) => formatDate(val) },
    { prop: 'endtime', label: '结束时间', formatValue: (val) => formatDate(val) },
    { prop: 'creatorName', label: '录入人' },
    { prop: 'createtime', label: '录入时间', formatValue: (val) => formatDate(val) },
    { prop: 'title', label: '标题', entireRow: true },
    { prop: 'content', label: '内容', entireRow: true }
])

const detailProps2 = computed<CellProp[]>(() => [
    { prop: 'auditName', label: '审核人' },
    { prop: 'audittime', label: '审核时间', formatValue: (val) => formatDate(val) },
    { prop: 'auditremark', label: '备注' },
])

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

defineExpose({
    close
})
</script>