Files
soul-yongping/miniprogram/pages/gift-pay/redemption-detail.js

81 lines
2.1 KiB
JavaScript

/**
* 卡若创业派对 - 代付领取详情(发起人查看:文章信息、领取人明细、剩余份数)
*/
const app = getApp()
Page({
data: {
statusBarHeight: 44,
requestSn: '',
detail: null,
loading: true,
remaining: 0
},
onLoad(options) {
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 44 })
const requestSn = (options.requestSn || '').trim()
if (!requestSn) {
wx.showToast({ title: '链接无效', icon: 'none' })
setTimeout(() => wx.navigateBack(), 1500)
return
}
this.setData({ requestSn })
this.loadDetail()
},
async loadDetail() {
const { requestSn } = this.data
const userId = app.globalData.userInfo?.id || ''
if (!userId) {
this.setData({ loading: false })
wx.showToast({ title: '请先登录', icon: 'none' })
return
}
this.setData({ loading: true })
try {
const res = await app.request(
`/api/miniprogram/gift-pay/detail?requestSn=${encodeURIComponent(requestSn)}&userId=${encodeURIComponent(userId)}`
)
if (res && res.success) {
const q = res.quantity || 0
const redeemed = res.redeemedCount || 0
const remaining = Math.max(0, q - redeemed)
this.setData({
detail: res,
remaining,
loading: false
})
} else {
this.setData({ loading: false })
wx.showToast({ title: res?.error || '加载失败', icon: 'none' })
}
} catch (e) {
this.setData({ loading: false })
wx.showToast({ title: '加载失败', icon: 'none' })
}
},
goToDetail() {
const { requestSn } = this.data
if (requestSn) {
wx.navigateTo({ url: `/pages/gift-pay/detail?requestSn=${encodeURIComponent(requestSn)}` })
}
},
goToArticle() {
const { detail } = this.data
if (!detail) return
const mid = detail.productMid || 0
const id = detail.productId || ''
if (detail.productType === 'section' && (mid || id)) {
const q = mid ? `mid=${mid}` : `id=${id}`
wx.navigateTo({ url: `/pages/read/read?${q}` })
}
},
goBack() {
app.goBackOrToHome()
}
})