210 lines
4.7 KiB
JavaScript
210 lines
4.7 KiB
JavaScript
|
|
/*
|
|
* 本时生活
|
|
*/
|
|
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
isUser : false, //用户登录状态
|
|
currentId : '', //轮播下标
|
|
infos : '', //用户信息
|
|
order : '', //订单信息
|
|
account : '',
|
|
// 卡轮播
|
|
swiper: {
|
|
imgUrls: [
|
|
{
|
|
id : 0,
|
|
src : '/static/img/user_card_00.png',
|
|
color : '#676869',
|
|
type : 'silver'
|
|
},
|
|
{
|
|
id : 1,
|
|
src : '/static/img/user_card_02.png',
|
|
color : '#192b4c',
|
|
type : 'drill'
|
|
},
|
|
{
|
|
id : 2,
|
|
src : '/static/img/user_card_01.png',
|
|
color : '#ff8f00',
|
|
type : 'balance'
|
|
}
|
|
],
|
|
autoplay: false,
|
|
interval: 5000,
|
|
duration: 1000,
|
|
current : 0
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad (options) {
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow () {
|
|
// 检查用户是否已登录
|
|
const current = wx.getStorageSync("current")
|
|
this.setData({
|
|
currentId: current
|
|
})
|
|
|
|
if(wx.getStorageSync("token") == ""){
|
|
this.setData({
|
|
infos : '',
|
|
order : '',
|
|
account : '',
|
|
isUser : false
|
|
})
|
|
return
|
|
}
|
|
|
|
this.setData({
|
|
isUser : getApp().globalData.isUser
|
|
})
|
|
|
|
// 获取用户信息
|
|
this.userInfo();
|
|
},
|
|
|
|
/**
|
|
* 用户信息
|
|
*/
|
|
userInfo() {
|
|
wx.$api.user.index().then(res=>{
|
|
// 是否设置过密码缓存
|
|
wx.setStorage({
|
|
key : 'hasPaypass',
|
|
data : res.data.info.has_paypass
|
|
})
|
|
|
|
this.setData({
|
|
infos : res.data.info,
|
|
order : res.data.order,
|
|
account : res.data.info.account
|
|
})
|
|
}).catch(err=>{
|
|
if(!err.login){
|
|
this.setData({
|
|
infos : '',
|
|
order : '',
|
|
account : '',
|
|
isUser : false
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 处理账户积分跳转
|
|
*/
|
|
swiperNav(e) {
|
|
let newType = e.currentTarget.dataset.type
|
|
if(this.data.isUser){
|
|
if(newType == "balance"){
|
|
wx.navigateTo({
|
|
url: '/pages/myBalance/myBalance'
|
|
})
|
|
return
|
|
}
|
|
|
|
wx.navigateTo({
|
|
url: "/pages/account/account?type=" + newType
|
|
})
|
|
}else{
|
|
// 去登录
|
|
wx.navigateTo({
|
|
url: "/pages/login/login"
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 处理未登录时的转跳
|
|
*/
|
|
userNav(e){
|
|
let pageUrl = e.currentTarget.dataset.url
|
|
if(this.data.isUser){
|
|
wx.navigateTo({
|
|
url: pageUrl
|
|
})
|
|
}else{
|
|
// 去登录
|
|
wx.navigateTo({
|
|
url: "/pages/login/login"
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 判断是否新用户
|
|
*/
|
|
userLogin(){
|
|
if(app.globalData.token != '') {
|
|
wx.navigateTo({
|
|
url: '/pages/chooseTel/chooseTel'
|
|
})
|
|
}else {
|
|
wx.navigateTo({
|
|
url: '/pages/login/login',
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 切换用户
|
|
*/
|
|
switchParty() {
|
|
wx.navigateTo({
|
|
url: '/pages/chooseTel/chooseTel?type=mobiles'
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 左箭头
|
|
*/
|
|
prevImg () {
|
|
var swiper = this.data.swiper;
|
|
var current = swiper.current;
|
|
|
|
swiper.current = current > 0 ? current - 1 : swiper.imgUrls.length - 1;
|
|
this.setData({
|
|
swiper: swiper,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 右箭头
|
|
*/
|
|
nextImg () {
|
|
var swiper = this.data.swiper;
|
|
var current = swiper.current;
|
|
swiper.current = current < (swiper.imgUrls.length - 1) ? current + 1 : 0;
|
|
this.setData({
|
|
swiper: swiper,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 敬请期待
|
|
*/
|
|
await() {
|
|
wx.showToast({
|
|
title : '努力开发中~',
|
|
icon : 'none',
|
|
duration: 1000
|
|
})
|
|
}
|
|
|
|
}) |