/**
 * 消息通知
 * 对齐后端 /api/user/notifications + /api/user/notifications/read
 */
const api = require('../../utils/api');

Page({
  data: {
    loading: true,
    list: []
  },

  onShow() {
    this.loadList();
  },

  async loadList() {
    this.setData({ loading: true });
    const list = await api.getNotifications().catch(() => []);
    this.setData({ list: Array.isArray(list) ? list : [], loading: false });
    // 自动标记已读
    if (list.length > 0) {
      api.readNotifications().catch(() => {});
    }
  },

  goOrder(e) {
    const orderNo = e.currentTarget.dataset.orderno;
    if (orderNo) {
      wx.navigateTo({ url: '/pages/order-detail/order-detail?orderNo=' + orderNo });
    }
  }
});
