This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop-wechat/pages/user/index.js

126 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2020-04-25 22:59:04 +08:00
const App = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
isLogin: false,
userInfo: {}, // 用户信息
orderCount: {}, // 订单数量
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
let _this = this;
_this.setData({
isLogin: App.checkIsLogin()
});
// 获取当前用户信息
_this.getUserDetail();
2021-07-16 16:36:54 +08:00
// 更新购物车角标
App.setCartTabBadge()
2020-04-25 22:59:04 +08:00
},
/**
* 获取当前用户信息
*/
getUserDetail() {
let _this = this;
2021-07-16 16:36:54 +08:00
App._get('user.index/detail', {}, function (result) {
2020-04-25 22:59:04 +08:00
_this.setData(result.data);
});
},
/**
* 订单导航跳转
*/
onTargetOrder(e) {
let _this = this;
if (!_this.onCheckLogin()) {
return false;
}
let urls = {
all: '/pages/order/index?type=all',
payment: '/pages/order/index?type=payment',
received: '/pages/order/index?type=received',
refund: '/pages/order/refund/index',
};
// 转跳指定的页面
wx.navigateTo({
url: urls[e.currentTarget.dataset.type]
})
},
/**
* 菜单列表导航跳转
*/
onTargetMenus(e) {
let _this = this;
if (!_this.onCheckLogin()) {
return false;
}
wx.navigateTo({
url: '/' + e.currentTarget.dataset.url
})
},
/**
* 跳转我的钱包页面
*/
onTargetWallet(e) {
let _this = this;
if (!_this.onCheckLogin()) {
return false;
}
wx.navigateTo({
url: './wallet/index'
})
},
/**
* 跳转积分明细页
*/
onTargetPoints(e) {
let _this = this;
if (!_this.onCheckLogin()) {
return false;
}
wx.navigateTo({
url: '../points/log/index'
});
},
/**
* 跳转到登录页
*/
onLogin() {
// wx.navigateTo({
// url: '../login/login',
// });
App.doLogin();
},
/**
* 验证是否已登录
*/
onCheckLogin() {
let _this = this;
if (!_this.data.isLogin) {
App.showError('很抱歉,您还没有登录');
return false;
}
return true;
},
})