import http from '../../../utils/api' Page({ data: { noticeDetail: {}, // 公告详情 loading: true, // 加载中 }, onLoad(options) { const { id } = options if (id) { this.fetchNoticeDetail(id) } else { this.setData({ loading: false }) wx.showToast({ title: '参数错误', icon: 'none' }) } }, // 获取公告详情 fetchNoticeDetail(id) { http.disasterDetail({ data: { id }, success: res => { console.log('详情数据:', res) if (res.code === 200 && res.data) { this.setData({ noticeDetail: res.data, loading: false }) } else { this.setData({ loading: false }) wx.showToast({ title: res.msg || '数据加载失败', icon: 'none' }) } }, fail: err => { console.error('获取详情失败:', err) this.setData({ loading: false }) wx.showToast({ title: '网络错误', icon: 'none' }) } }) }, // 返回上一页 goBack() { wx.navigateBack({ delta: 1 }) }, // 格式化应对措施 formatMeasures(measures) { if (!measures) return [] // 按数字序号分割 const items = measures.split(/[0-9]+\./).filter(item => item.trim() !== '') return items.map(item => item.trim()) }, // 获取分类标签背景色 getTagBg(type) { const bgMap = { '天气预警': '#e0f2fe', '安全提醒': '#f3e8ff', '通知公告': '#eef2ff', '重要通知': '#fff3e0', '紧急通知': '#fee2e2' } return bgMap[type] || '#eef2ff' }, // 获取级别标签背景色 getLevelBg(level) { const bgMap = { '紧急': '#fee2e2', '重要': '#fff3e0', '通知': '#eef2ff', '一般': '#f1f5f9' } return bgMap[level] || '#f1f5f9' }, // 获取级别文字颜色 getLevelColor(level) { const colorMap = { '紧急': '#b91c1c', '重要': '#b45309', '通知': '#1e40af', '一般': '#334155' } return colorMap[level] || '#334155' } })