Files
code-bang/frontend/miniapp/pages/usercenter/balance/index.js
T
2026-09-23 18:28:26 +08:00

189 lines
4.5 KiB
JavaScript

// pages/usercenter/balance/index.js
import { fetchAccountInfo, fetchAccountLogs, accountApplyWithdraw } from '../../../services/usercenter/fetchBalance';
Page({
/**
* 页面的初始数据
*/
data: {
totalAmount: 0,
accountInfo: null,
tab: 'all',
list: [],
page: 1,
pageSize: 10,
loadMoreStatus: 0,
showWithdrawDialog: false,
withdrawAmount: '',
withdrawName: '',
// 提现规则:默认折叠,仅展示核心摘要
rulesExpanded: false,
briefRules: ['单笔 0-200 元', '每日限 10 次', '单日限额 2000 元', '1-3 个工作日到账'],
ruleList: [
{ title: '单笔额度', desc: '单笔 0-200 元,以「可提现余额」为准' },
{ title: '提现次数', desc: '每个自然日最多可发起 10 次提现申请' },
{ title: '单日限额', desc: '同一自然日累计提现金额不超过 2000 元,超出请次日再试' },
{ title: '到账方式', desc: '转账至本人微信零钱,需填写与微信实名一致的姓名' },
{ title: '到账时间', desc: '审核通过后 1-3 个工作日内到账,节假日顺延' },
{ title: '审核说明', desc: '工作日统一审核处理,审核期间该笔金额将暂时冻结' },
{ title: '驳回处理', desc: '被驳回的提现金额将自动退回可提现余额,可重新发起' },
],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.loadAccountInfo();
this.loadList();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
if (this.data.loadMoreStatus === 0) {
this.setData({ loadMoreStatus: 1 });
this.loadList();
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
// Tab切换
onTabChange(e) {
const value = e.currentTarget.dataset.value;
if (value === this.data.tab) return;
this.setData({
tab: value,
list: [],
page: 1,
loadMoreStatus: 'more'
}, () => {
this.loadList();
});
},
loadAccountInfo() {
fetchAccountInfo().then((res) => {
console.log(res)
let accountInfo = res.data;
this.setData({
accountInfo,
totalAmount: (parseFloat(accountInfo.amount) + parseFloat(accountInfo.freeze)).toFixed(2)
});
});
},
// 加载明细数据(模拟)
loadList() {
let { page, pageSize, list, tab } = this.data;
let params = {
tab: tab,
page: page,
accountType: 'amount',
pageSize: pageSize,
};
fetchAccountLogs(params).then((res) => {
console.log(res)
let newList = res.data.data;
let hasMore = res.data.current_page < res.data.last_page;
this.setData({
list: list.concat(newList),
page: page + 1,
loadMoreStatus: hasMore ? 0 : 2
});
});
},
// 提现弹窗
onWithdraw() {
this.setData({ showWithdrawDialog: true });
},
// 展开/收起提现规则
onToggleRules() {
this.setData({ rulesExpanded: !this.data.rulesExpanded });
},
onWithdrawAmountInput(e) {
this.setData({ withdrawAmount: e.detail.value });
},
onWithdrawNameInput(e) {
this.setData({ withdrawName: e.detail.value });
},
onConfirmWithdraw() {
const { withdrawName, withdrawAmount } = this.data;
let params = {
'name': withdrawName,
'amount': withdrawAmount,
};
accountApplyWithdraw(params).then((res) => {
console.log(res)
if (res.code == 1) {
this.setData({
showWithdrawDialog: false,
withdrawAmount: '',
withdrawName: ''
});
wx.showModal({
title: '提示',
showCancel: false,
content: res.msg,
success: (re) => {
if (re.confirm) {
//提现之后,刷新数据
this.loadAccountInfo();
this.loadList();
console.log('用户点击确定');
}
}
});
} else {
wx.showToast({ title: res.msg, icon: 'none' });
}
});
},
onCancelWithdraw() {
this.setData({ showWithdrawDialog: false });
}
})