174 lines
3.5 KiB
JavaScript
174 lines
3.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: '',
|
|
cancelBtnStyle: 'color: #ff0000; border-color: #ff0000; background-color: #fff;',
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
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 });
|
|
},
|
|
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 });
|
|
}
|
|
}) |