<!-- 通知公告提醒列表页 --> <script name="WorkList" setup lang="ts"> import type { Ref } from 'vue' import type { DateModelType } from 'element-plus' import dayjs from 'dayjs' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import type { dictType } from '@/global' import { getNoticeeApi, readNotice } from '@/api/system/notice' import noticeDetail from '@/views/system/notice/noticeDetail.vue' import useUserStore from '@/store/modules/user' const $router = useRouter() const messageSourceModuleList = ref<dictType[]>([]) // 来源模块 const statusList = [ { id: '1', name: '已读', }, { id: '0', name: '未读', }, ] const user = useUserStore() // 用户信息 const timeRange = ref<[DateModelType, DateModelType]>(['', '']) const detailDialogRef = ref() // 查询条件 const listQuery = ref({ alreadyRead: 0, // 0未读 noticeStartTime: '', noticeEndTime: '', noticeNo: '', noticePublisher: '', noticeTitle: '', systemType: 1, // 1业务系统、2受检系统 noticeSketch: '', // 内容简述 limit: 20, offset: 1, }) const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading const list = ref([]) // 表格数据 // 筛选时间段数据 const dateRange = ref<[DateModelType, DateModelType]>(['', '']) // 表头 const columns = ref<TableColumn[]>([ { text: '标题', value: 'noticeTitle', align: 'center', width: '180' }, { text: '内容简述', value: 'noticeSketch', align: 'center' }, { text: '发布人', value: 'noticePublisher', align: 'center' }, { text: '发布时间', value: 'noticeTime', align: 'center' }, { text: '读取状态', value: 'readName', align: 'center', width: '100' }, ]) // -------------------------------------标签-------------------------------------------------- const radioMenus = ref([ // 标签内容 { name: '未读', value: 0 }, { name: '已读', value: 1 }, ]) const current = ref(0) // 选择的tab 默认基本信息 // --------------------------------------------------------------------------------------- // 获取审批提醒列表页 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } getNoticeeApi(listQuery.value).then((res) => { list.value = res.data.rows.map((item: { noticeTime: string; read: string }) => { return { ...item, noticeTime: dayjs(item.noticeTime).format('YYYY-MM-DD HH:mm'), readName: `${item.read}` === '1' ? '已读' : '未读', } }) total.value = res.data.total loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 搜索 const searchList = () => { fetchData(false) } // 重置 const reset = () => { listQuery.value = { alreadyRead: 0, // 0未读 noticeStartTime: '', noticeEndTime: '', noticeNo: '', noticePublisher: '', noticeTitle: '', systemType: 1, // 1业务系统、2受检系统 noticeSketch: '', // 内容简述 limit: 20, offset: 1, } timeRange.value = ['', ''] fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { listQuery.value.limit = val.size } if (val && val.page) { listQuery.value.offset = val.page } fetchData(true) } // 获取字典值 const getDict = async () => { // 来源模块 getDictByCode('messageSourceModule').then((response) => { messageSourceModuleList.value = response.data }) } // 跳转详情页 const detail = (row: any) => { detailDialogRef.value.initDialog(row) } const confirm = (id: string, read: string) => { if (read === '0') { // 通知公告标记已读 readNotice({ userId: user.id, ids: [id], }).then(() => { fetchData() // 刷新通知公告 }) } } // 时间变更 watch(timeRange, (val) => { if (val) { listQuery.value.noticeStartTime = `${val[0]}` listQuery.value.noticeEndTime = `${val[1]}` } else { listQuery.value.noticeStartTime = '' listQuery.value.noticeEndTime = '' } }) watch(() => current.value, (newValue) => { listQuery.value.alreadyRead = newValue fetchData() }) onMounted(async () => { await getDict() // 获取字典 fetchData(true) // 获取数据 }) </script> <template> <div class="workBench-radio-menu"> <h4 style="padding: 0;margin: 0;"> 通知公告 </h4> <el-radio-group v-model="current"> <el-radio-button v-for="item in radioMenus" :key="item.value" :label="item.value"> {{ item.name }} </el-radio-button> </el-radio-group> </div> <!-- 布局 --> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.noticeTitle" placeholder="标题" clearable class="w-50 m-2" /> </search-item> <search-item> <el-input v-model.trim="listQuery.noticeSketch" placeholder="内容简述" clearable class="w-50 m-2" /> </search-item> <search-item> <el-input v-model.trim="listQuery.noticePublisher" placeholder="发布人" clearable class="w-50 m-2" /> </search-item> <search-item> <el-date-picker v-model="timeRange" type="datetimerange" format="YYYY-MM-DD HH:mm" value-format="YYYY-MM-DD HH:mm" range-separator="至" start-placeholder="发布时间(开始)" end-placeholder="发布时间(结束)" clearable /> <!-- <el-date-picker v-model="searchQuery.noticeTime" type="datetime" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" placeholder="发布时间" /> --> </search-item> <!-- <template #btns> <el-button class="filter-item" type="info" :icon="Delete" :style="{ marginTop: '-10px' }" @click="reset"> 重置 </el-button> </template> --> </search-area> <table-container> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" @change="changePage" > <template #preColumns> <el-table-column label="#" width="55" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" align="center" fixed="right" width="90"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="detail(row)"> 详情 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> <notice-detail ref="detailDialogRef" @confirm="confirm" /> </template> <style lang="scss" scoped> .workBench-radio-menu { width: 100%; display: flex; justify-content: space-between; background-color: #fff; padding: 10px; } </style>