You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
5.8 KiB
JavaScript

2 years ago
// pages/money/index.js
const app = getApp();
const commonUtil = require("../../utils/commonUtil.js");
Page({
/**
* 页面的初始数据
*/
data: {
showMoney:true,
wallet: {commissionsSettle: '0.00', commissions: '0.00'},
balance: '0.00',
auth: 0,
openId: '',
isLogin: false,
hasUserInfo: {},
agencyStatus: 0,
user: {},
wxCode: '',
},
login:function(){
if(!this.data.isLogin) {
wx.navigateTo({
url: '/pages/login/index',
})
}
},
openEyes:function(){
this.setData({
showMoney:false
})
},
closeEyes:function(){
this.setData({
showMoney:true
})
},
wxLogin() {
var that = this;
wx.login({
success(res) {
if (res.code) {
that.setData({
wxCode: res.code
});
} else {
console.log('获取code失败' + res.errMsg)
}
}
})
},
getWalletInfo: function() {
var that = this;
wx.request({
url: app.globalData.ip + "/wallet/info",
data: {
},
header: app.globalData.header,
method: "GET",
success: function(res) {
console.log(res)
if(res.data.status == 200) {
console.log(res);
//绑定成功
// console.log(new Number(res.data.data.balance / 100).toFixed(2));
// console.log( commonUtil.moneyToFixed(res.data.data.balance) + '');
that.setData({
balance: new Number(res.data.data.balance / 100).toFixed(2),
auth: res.data.data.auth,
// openId: res.data.data.openId,
});
} else {
wx.showToast({
icon: "none",
title: res.data.msg,
})
}
},
fail: function(res) {
console.log("操作失败");
}
})
},
getAgencyWallet() {
var that = this;
wx.request({
url: app.globalData.ip + "/agency/promition/getAgencyWallet",
method: "POST",
header: app.globalData.header,
data: {},
success: function(res) {
console.log(res);
res.data.data.commissionsSettle = new Number(res.data.data.commissionsSettle / 100).toFixed(2);
res.data.data.commissions = new Number(res.data.data.commissions / 100).toFixed(2);
that.setData({
wallet: res.data.data
});
}
});
},
getUserInfoBtn: function(e) {
console.log(e)
let that = this;
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
let encryptedData = res.encryptedData;
let iv = res.iv;
//发起网络请求
wx.request({
url: app.globalData.ip + '/decodeUserInfo',
data: {
encryptedData: encryptedData,
iv: iv,
code: that.data.wxCode,
type: 'dtdl',
},
method: "POST",
header: app.globalData.header,
success: function(res) {
console.log(res);
if(res.data.status == 200) {//设置头像昵称成功,进去提现页面
wx.navigateTo({
url: '/pages/withdraw/index',
})
} else {
wx.showToast({
icon: "none",
title: res.data.msg,
})
}
},
fail: function(res) {
}
})
},
fail: (res) => {
console.log(res);
wx.showToast({
icon: "none",
title: '获取授权失败,将影响您的提现。',
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
// if(app.globalData.isLogin) {
// this.getWalletInfo();
// this.getAgencyWallet();
// }
this.wxLogin();
if (app.globalData.isLogin) {
this.setData({
isLogin: app.globalData.isLogin,
hasUserInfo: app.globalData.hasUserInfo,
agencyStatus: app.globalData.agencyStatus,
user: app.globalData.user,
});
this.getWalletInfo();
this.getAgencyWallet();
} else {
// 由于 userLogin 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userLoginCallback = res => {
this.setData({
isLogin: app.globalData.isLogin,
hasUserInfo: app.globalData.hasUserInfo,
agencyStatus: app.globalData.agencyStatus,
user: app.globalData.user,
});
this.getWalletInfo();
this.getAgencyWallet();
}
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
onShareTimeline(){}
})