WxApp/page/component/myOrders/myOrder.js

62 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-08-30 15:23:27 +08:00
const app = getApp()
const baseUrl = app.globalData.baseUrl
2024-08-29 14:36:16 +08:00
// page/component/orders/orders.js
Page({
// onLoad: function (options) {
// this.setData({
// orders: [...this.data.orders, options]
// });
// },
data: {
address: {},
hasAddress: false,
total: 0,
2024-08-31 17:33:35 +08:00
orders: [],
2024-08-29 14:36:16 +08:00
},
onLoad() {
2024-08-30 15:23:27 +08:00
var self = this
2024-08-31 22:40:03 +08:00
// 获取订单status为1的待付款订单
2024-08-29 14:36:16 +08:00
wx.request({
2024-08-30 15:23:27 +08:00
url: baseUrl + "/order/loadData",
method: "POST",
2024-08-29 14:36:16 +08:00
data: {
2024-09-03 00:16:51 +08:00
openId: wx.getStorageSync('openid'),
2024-08-31 22:40:03 +08:00
status: 1
2024-08-29 14:36:16 +08:00
},
success(res) {
2024-09-01 11:15:29 +08:00
let orders = res.data.data;
// 遍历每个订单项
orders = orders.map(order => {
// 检查 specs 中是否包含 "压缩高级枕"
if (order.specs.includes("压缩高级枕")) {
// 如果包含,则将价格修改为 240
order.goodPrice = 240;
}
return order;
});
2024-08-29 14:36:16 +08:00
self.setData({
2024-08-31 17:33:35 +08:00
orders: res.data.data,
2024-08-30 15:23:27 +08:00
})
2024-09-01 11:15:29 +08:00
console.log('orders', self.data.orders)
2024-08-30 15:23:27 +08:00
},
})
2024-08-29 14:36:16 +08:00
},
onReady() {
},
onShow: function () {
2024-08-30 15:23:27 +08:00
const self = this
2024-08-29 14:36:16 +08:00
wx.getStorage({
2024-08-30 15:23:27 +08:00
key: "address",
2024-08-29 14:36:16 +08:00
success(res) {
self.setData({
address: res.data,
2024-08-30 15:23:27 +08:00
hasAddress: true,
2024-08-29 14:36:16 +08:00
})
2024-08-30 15:23:27 +08:00
},
2024-08-29 14:36:16 +08:00
})
},
2024-08-30 15:23:27 +08:00
})