138 lines
4.1 KiB
JavaScript
138 lines
4.1 KiB
JavaScript
/**
|
|
* 提现记录 - 独立页面
|
|
*/
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
list: [],
|
|
loading: true
|
|
},
|
|
|
|
onLoad() {
|
|
wx.showShareMenu({ withShareTimeline: true })
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 44 })
|
|
this.loadRecords()
|
|
},
|
|
|
|
onShow() {
|
|
this.loadRecords()
|
|
},
|
|
|
|
async loadRecords() {
|
|
const userInfo = app.globalData.userInfo
|
|
if (!app.globalData.isLoggedIn || !userInfo || !userInfo.id) {
|
|
this.setData({ list: [], loading: false })
|
|
return
|
|
}
|
|
this.setData({ loading: true })
|
|
try {
|
|
const res = await app.request('/api/miniprogram/withdraw/records?userId=' + userInfo.id)
|
|
if (res && res.success && res.data && Array.isArray(res.data.list)) {
|
|
const list = (res.data.list || []).map(item => ({
|
|
id: item.id,
|
|
amount: (item.amount != null ? item.amount : 0).toFixed(2),
|
|
status: this.statusText(item.status),
|
|
statusRaw: item.status,
|
|
createdAt: (item.createdAt ?? item.created_at) ? this.formatDate(item.createdAt ?? item.created_at) : '--',
|
|
canReceive: !!item.canReceive
|
|
}))
|
|
this.setData({ list, loading: false })
|
|
} else {
|
|
this.setData({ list: [], loading: false })
|
|
}
|
|
} catch (e) {
|
|
console.log('[WithdrawRecords] 加载失败:', e)
|
|
this.setData({ list: [], loading: false })
|
|
}
|
|
},
|
|
|
|
statusText(status) {
|
|
const map = {
|
|
pending: '待审核',
|
|
pending_confirm: '待确认收款',
|
|
processing: '处理中',
|
|
success: '已到账',
|
|
failed: '已拒绝'
|
|
}
|
|
return map[status] || status || '--'
|
|
},
|
|
|
|
formatDate(dateStr) {
|
|
if (!dateStr) return '--'
|
|
const d = new Date(dateStr)
|
|
const y = d.getFullYear()
|
|
const m = (d.getMonth() + 1).toString().padStart(2, '0')
|
|
const day = d.getDate().toString().padStart(2, '0')
|
|
return `${y}-${m}-${day}`
|
|
},
|
|
|
|
goBack() {
|
|
getApp().goBackOrToHome()
|
|
},
|
|
|
|
async onReceiveTap(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
if (!id) return
|
|
wx.showLoading({ title: '加载中...' })
|
|
try {
|
|
const res = await app.request('/api/miniprogram/withdraw/confirm-info?id=' + encodeURIComponent(id))
|
|
wx.hideLoading()
|
|
if (!res || !res.success || !res.data) {
|
|
wx.showToast({ title: res?.message || '获取领取信息失败', icon: 'none' })
|
|
return
|
|
}
|
|
const { mchId, appId, package: pkg } = res.data
|
|
if (!pkg || pkg === '') {
|
|
wx.showToast({
|
|
title: '打款已发起,请到微信零钱中查看',
|
|
icon: 'none',
|
|
duration: 2500
|
|
})
|
|
return
|
|
}
|
|
if (!wx.canIUse('requestMerchantTransfer')) {
|
|
wx.showToast({ title: '当前微信版本过低,请更新后重试', icon: 'none' })
|
|
return
|
|
}
|
|
wx.requestMerchantTransfer({
|
|
mchId: mchId || '',
|
|
appId: appId || wx.getAccountInfoSync().miniProgram.appId,
|
|
package: pkg,
|
|
success: (res) => {
|
|
if (res.errMsg === 'requestMerchantTransfer:ok') {
|
|
wx.showToast({ title: '已调起收款页', icon: 'success' })
|
|
this.loadRecords()
|
|
} else {
|
|
wx.showToast({ title: res.errMsg || '操作完成', icon: 'none' })
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
if (err.errMsg && err.errMsg.indexOf('cancel') !== -1) {
|
|
wx.showToast({ title: '已取消', icon: 'none' })
|
|
} else {
|
|
wx.showToast({ title: err.errMsg || '调起失败', icon: 'none' })
|
|
}
|
|
}
|
|
})
|
|
} catch (e) {
|
|
wx.hideLoading()
|
|
wx.showToast({ title: '网络异常,请重试', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
onShareAppMessage() {
|
|
const ref = app.getMyReferralCode()
|
|
return {
|
|
title: 'Soul创业派对 - 提现记录',
|
|
path: ref ? `/pages/withdraw-records/withdraw-records?ref=${ref}` : '/pages/withdraw-records/withdraw-records'
|
|
}
|
|
},
|
|
|
|
onShareTimeline() {
|
|
const ref = app.getMyReferralCode()
|
|
return { title: 'Soul创业派对 - 提现记录', query: ref ? `ref=${ref}` : '' }
|
|
}
|
|
})
|