初始提交:一场soul的创业实验-永平 网站与小程序
Made-with: Cursor
This commit is contained in:
137
miniprogram/pages/withdraw-records/withdraw-records.js
Normal file
137
miniprogram/pages/withdraw-records/withdraw-records.js
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* 提现记录 - 独立页面
|
||||
*/
|
||||
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}` : '' }
|
||||
}
|
||||
})
|
||||
4
miniprogram/pages/withdraw-records/withdraw-records.json
Normal file
4
miniprogram/pages/withdraw-records/withdraw-records.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
25
miniprogram/pages/withdraw-records/withdraw-records.wxml
Normal file
25
miniprogram/pages/withdraw-records/withdraw-records.wxml
Normal file
@@ -0,0 +1,25 @@
|
||||
<view class="page">
|
||||
<view class="nav-bar" style="padding-top: {{statusBarHeight}}px;">
|
||||
<view class="nav-back" bindtap="goBack">←</view>
|
||||
<text class="nav-title">提现记录</text>
|
||||
<view class="nav-placeholder"></view>
|
||||
</view>
|
||||
<view class="nav-placeholder-bar" style="height: {{statusBarHeight + 44}}px;"></view>
|
||||
|
||||
<view class="content">
|
||||
<view class="loading-tip" wx:if="{{loading}}">加载中...</view>
|
||||
<view class="empty" wx:elif="{{list.length === 0}}">暂无提现记录</view>
|
||||
<view class="list" wx:else>
|
||||
<view class="item" wx:for="{{list}}" wx:key="id">
|
||||
<view class="item-left">
|
||||
<text class="amount">¥{{item.amount}}</text>
|
||||
<text class="time">{{item.createdAt}}</text>
|
||||
</view>
|
||||
<view class="item-right">
|
||||
<text class="status status-{{item.statusRaw}}">{{item.status}}</text>
|
||||
<button wx:if="{{item.canReceive}}" class="btn-receive" data-id="{{item.id}}" bindtap="onReceiveTap">领取零钱</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
71
miniprogram/pages/withdraw-records/withdraw-records.wxss
Normal file
71
miniprogram/pages/withdraw-records/withdraw-records.wxss
Normal file
@@ -0,0 +1,71 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #000;
|
||||
}
|
||||
.nav-bar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
background: rgba(0,0,0,0.9);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 24rpx;
|
||||
height: 88rpx;
|
||||
}
|
||||
.nav-back {
|
||||
color: #00CED1;
|
||||
font-size: 36rpx;
|
||||
padding: 16rpx;
|
||||
}
|
||||
.nav-title {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
}
|
||||
.nav-placeholder { width: 80rpx; }
|
||||
.nav-placeholder-bar { width: 100%; }
|
||||
|
||||
.content {
|
||||
padding: 32rpx;
|
||||
}
|
||||
.loading-tip, .empty {
|
||||
text-align: center;
|
||||
color: rgba(255,255,255,0.6);
|
||||
font-size: 28rpx;
|
||||
padding: 80rpx 0;
|
||||
}
|
||||
.list { }
|
||||
.item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 28rpx 0;
|
||||
border-bottom: 2rpx solid rgba(255,255,255,0.06);
|
||||
}
|
||||
.item:last-child { border-bottom: none; }
|
||||
.item-left { display: flex; flex-direction: column; gap: 8rpx; }
|
||||
.item-right { display: flex; flex-direction: column; align-items: flex-end; gap: 12rpx; }
|
||||
.amount { font-size: 32rpx; font-weight: 600; color: #fff; }
|
||||
.time { font-size: 24rpx; color: rgba(255,255,255,0.5); }
|
||||
.status { font-size: 26rpx; }
|
||||
.status.status-pending { color: #FFA500; }
|
||||
.status.status-processing { color: #4CAF50; }
|
||||
.status.status-pending_confirm { color: #4CAF50; }
|
||||
.status.status-success { color: #4CAF50; }
|
||||
.status.status-failed { color: rgba(255,255,255,0.5); }
|
||||
.btn-receive {
|
||||
margin: 0;
|
||||
padding: 0 24rpx;
|
||||
height: 56rpx;
|
||||
line-height: 56rpx;
|
||||
font-size: 24rpx;
|
||||
color: #00CED1;
|
||||
background: transparent;
|
||||
border: 2rpx solid #00CED1;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
.btn-receive::after { border: none; }
|
||||
Reference in New Issue
Block a user