88 lines
2.4 KiB
JavaScript
88 lines
2.4 KiB
JavaScript
/**
|
|
* Soul创业派对 - 我发起的代付(改造后:仅我发起的,含领取记录)
|
|
*/
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
requests: [],
|
|
loading: false
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 44 })
|
|
this.loadData()
|
|
},
|
|
|
|
onShow() {
|
|
if (this.data.requests.length > 0) {
|
|
this.loadData()
|
|
}
|
|
},
|
|
|
|
async loadData() {
|
|
const userId = app.globalData.userInfo?.id || ''
|
|
if (!userId) {
|
|
wx.showToast({ title: '请先登录', icon: 'none' })
|
|
return
|
|
}
|
|
this.setData({ loading: true })
|
|
try {
|
|
const res = await app.request(`/api/miniprogram/gift-pay/my-requests?userId=${encodeURIComponent(userId)}`)
|
|
this.setData({ requests: (res && res.list) || [], loading: false })
|
|
} catch (e) {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
goToDetail(e) {
|
|
const requestSn = e.currentTarget.dataset.sn
|
|
if (requestSn) {
|
|
wx.navigateTo({ url: `/pages/gift-pay/redemption-detail?requestSn=${encodeURIComponent(requestSn)}` })
|
|
}
|
|
},
|
|
|
|
shareRequest(e) {
|
|
if (e && typeof e.stopPropagation === 'function') e.stopPropagation()
|
|
const requestSn = e?.currentTarget?.dataset?.sn
|
|
if (requestSn) {
|
|
wx.navigateTo({ url: `/pages/gift-pay/detail?requestSn=${encodeURIComponent(requestSn)}` })
|
|
}
|
|
},
|
|
|
|
async cancelRequest(e) {
|
|
if (e && typeof e.stopPropagation === 'function') e.stopPropagation()
|
|
const requestSn = e?.currentTarget?.dataset?.sn
|
|
if (!requestSn) return
|
|
const ok = await new Promise(r => {
|
|
wx.showModal({ title: '取消代付', content: '确定取消该代付请求?', success: res => r(res.confirm) })
|
|
})
|
|
if (!ok) return
|
|
try {
|
|
const res = await app.request({
|
|
url: '/api/miniprogram/gift-pay/cancel',
|
|
method: 'POST',
|
|
data: { requestSn, userId: app.globalData.userInfo?.id }
|
|
})
|
|
if (res && res.success) {
|
|
wx.showToast({ title: '已取消', icon: 'success' })
|
|
const requests = (this.data.requests || []).filter(r => r.requestSn !== requestSn)
|
|
this.setData({ requests })
|
|
} else {
|
|
wx.showToast({ title: res?.error || '取消失败', icon: 'none' })
|
|
}
|
|
} catch (e) {
|
|
wx.showToast({ title: '取消失败', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
goBack() {
|
|
app.goBackOrToHome()
|
|
},
|
|
|
|
onShareAppMessage() {
|
|
return { title: '我的代付 - Soul创业派对', path: '/pages/gift-pay/list' }
|
|
}
|
|
})
|