const { baseUrl } = require('../../../request');

Page({
  data: {
    title: '',
    createTime: '',
    content: '',
    id: null
  },

  onLoad(options) {
    // 1. 获取跳转传来的 id
    const id = options.id;
    this.setData({ id });

    // 2. 拉取通知详情
    this.fetchNotificationDetail(id);
  },

  fetchNotificationDetail(id) {
    const token = wx.getStorageSync('token');
    wx.request({
      url: baseUrl + '/projectNotification/mini/query/id', // 用你的实际接口
      method: 'POST',
      header: {
        Authorization: token
      },
      data: { id },
      success: (res) => {
        if (res.data.code === 1) {
          const detail = res.data.data || {};
          this.setData({
            title: detail.notificationTitle || '',
            createTime: detail.createTime || '',
            content: detail.notificationContent || ''
          });
        } else {
          wx.showToast({
            title: res.data.message || '获取通知失败',
            icon: 'none'
          });
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        });
      }
    });
  }
});
