const app = getApp()
const baseUrl = app.globalData.baseUrl
// page/component/orders/orders.js
Page({
  // onLoad: function (options) {
  //   this.setData({
  //     orders: [...this.data.orders, options]
  //   });
  // },
  data: {
    address: {},
    hasAddress: false,
    total: 0,
    orders: [],
  },
  onLoad() {
    var self = this
    // 获取订单status为1的待付款订单
    wx.request({
      url: baseUrl + "/order/loadData",
      method: "POST",
      data: {
        openId:  wx.getStorageSync('openid'),
        status: 1
      },
      success(res) {
        let orders = res.data.data;

        // 遍历每个订单项
        orders = orders.map(order => {
          // 检查 specs 中是否包含 "压缩高级枕"
          if (order.specs.includes("压缩高级枕")) {
            // 如果包含，则将价格修改为 240
            order.goodPrice = 240;
          }
          return order;
        });
        self.setData({
          orders: res.data.data,
        })
        console.log('orders', self.data.orders)
      },
    })
  },
  onReady() {
  },

  onShow: function () {
    const self = this
    wx.getStorage({
      key: "address",
      success(res) {
        self.setData({
          address: res.data,
          hasAddress: true,
        })
      },
    })
  },

})
