与牧同行-小程序用户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.2 KiB

  1. import http from '../../../utils/api'
  2. Page({
  3. data: {
  4. noticeDetail: {}, // 公告详情
  5. loading: true, // 加载中
  6. },
  7. onLoad(options) {
  8. const { id } = options
  9. if (id) {
  10. this.fetchNoticeDetail(id)
  11. } else {
  12. this.setData({ loading: false })
  13. wx.showToast({
  14. title: '参数错误',
  15. icon: 'none'
  16. })
  17. }
  18. },
  19. // 获取公告详情
  20. fetchNoticeDetail(id) {
  21. http.disasterDetail({
  22. data: { id },
  23. success: res => {
  24. console.log('详情数据:', res)
  25. if (res.code === 200 && res.data) {
  26. this.setData({
  27. noticeDetail: res.data,
  28. loading: false
  29. })
  30. } else {
  31. this.setData({ loading: false })
  32. wx.showToast({
  33. title: res.msg || '数据加载失败',
  34. icon: 'none'
  35. })
  36. }
  37. },
  38. fail: err => {
  39. console.error('获取详情失败:', err)
  40. this.setData({ loading: false })
  41. wx.showToast({
  42. title: '网络错误',
  43. icon: 'none'
  44. })
  45. }
  46. })
  47. },
  48. // 返回上一页
  49. goBack() {
  50. wx.navigateBack({
  51. delta: 1
  52. })
  53. },
  54. // 格式化应对措施
  55. formatMeasures(measures) {
  56. if (!measures) return []
  57. // 按数字序号分割
  58. const items = measures.split(/[0-9]+\./).filter(item => item.trim() !== '')
  59. return items.map(item => item.trim())
  60. },
  61. // 获取分类标签背景色
  62. getTagBg(type) {
  63. const bgMap = {
  64. '天气预警': '#e0f2fe',
  65. '安全提醒': '#f3e8ff',
  66. '通知公告': '#eef2ff',
  67. '重要通知': '#fff3e0',
  68. '紧急通知': '#fee2e2'
  69. }
  70. return bgMap[type] || '#eef2ff'
  71. },
  72. // 获取级别标签背景色
  73. getLevelBg(level) {
  74. const bgMap = {
  75. '紧急': '#fee2e2',
  76. '重要': '#fff3e0',
  77. '通知': '#eef2ff',
  78. '一般': '#f1f5f9'
  79. }
  80. return bgMap[level] || '#f1f5f9'
  81. },
  82. // 获取级别文字颜色
  83. getLevelColor(level) {
  84. const colorMap = {
  85. '紧急': '#b91c1c',
  86. '重要': '#b45309',
  87. '通知': '#1e40af',
  88. '一般': '#334155'
  89. }
  90. return colorMap[level] || '#334155'
  91. }
  92. })