73 lines
1.9 KiB
JavaScript
73 lines
1.9 KiB
JavaScript
/**
|
|
* Soul创业实验 - 订单页
|
|
*/
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
orders: [],
|
|
loading: true
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
|
|
this.loadOrders()
|
|
},
|
|
|
|
onShow() {
|
|
this.loadOrders()
|
|
},
|
|
|
|
async loadOrders() {
|
|
this.setData({ loading: true })
|
|
try {
|
|
let purchasedSections = app.globalData.purchasedSections || []
|
|
let sectionMidMap = app.globalData.sectionMidMap || {}
|
|
const userId = app.globalData.userInfo?.id
|
|
if (userId) {
|
|
try {
|
|
const res = await app.request(`/api/miniprogram/user/purchase-status?userId=${encodeURIComponent(userId)}`)
|
|
if (res?.success && res.data) {
|
|
purchasedSections = res.data.purchasedSections || []
|
|
sectionMidMap = res.data.sectionMidMap || {}
|
|
app.globalData.purchasedSections = purchasedSections
|
|
app.globalData.sectionMidMap = sectionMidMap
|
|
}
|
|
} catch (_) { /* 使用缓存 */ }
|
|
}
|
|
const orders = purchasedSections.map((id, index) => ({
|
|
id: `order_${index}`,
|
|
sectionId: id,
|
|
mid: sectionMidMap[id] || 0,
|
|
title: `章节 ${id}`,
|
|
amount: 1,
|
|
status: 'completed',
|
|
createTime: new Date(Date.now() - index * 86400000).toLocaleDateString()
|
|
}))
|
|
this.setData({ orders })
|
|
} catch (e) {
|
|
console.error('加载订单失败:', e)
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
goToRead(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
const mid = e.currentTarget.dataset.mid
|
|
const q = mid ? `mid=${mid}` : `id=${id}`
|
|
wx.navigateTo({ url: `/pages/read/read?${q}` })
|
|
},
|
|
|
|
goBack() { wx.navigateBack() },
|
|
|
|
onShareAppMessage() {
|
|
const ref = app.getMyReferralCode()
|
|
return {
|
|
title: 'Soul创业派对 - 我的订单',
|
|
path: ref ? `/pages/purchases/purchases?ref=${ref}` : '/pages/purchases/purchases'
|
|
}
|
|
}
|
|
})
|