187 lines
3.7 KiB
JavaScript
187 lines
3.7 KiB
JavaScript
const App = getApp();
|
||
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
userInfo: {},
|
||
isLogin: false,
|
||
showModal: false,
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
|
||
this.getUserDetail();
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
let _this = this;
|
||
_this.setData({
|
||
isLogin: App.checkIsLogin()
|
||
});
|
||
this.getUserDetail();
|
||
},
|
||
|
||
/**
|
||
* 获取当前用户信息
|
||
*/
|
||
getUserDetail() {
|
||
let _this = this;
|
||
App._post_form('user.index/detail', {
|
||
user_id: wx.getStorageSync('user_id')
|
||
}, result => {
|
||
_this.setData(result.data);
|
||
});
|
||
},
|
||
/**
|
||
* 菜单列表导航跳转
|
||
*/
|
||
onTargetMenus(e) {
|
||
let _this = this;
|
||
if (!_this.onCheckLogin()) {
|
||
return false;
|
||
}
|
||
wx.navigateTo({
|
||
url: '/' + e.currentTarget.dataset.url
|
||
})
|
||
},
|
||
/**
|
||
* 验证是否已登录
|
||
*/
|
||
onCheckLogin() {
|
||
let _this = this;
|
||
if (!_this.data.isLogin) {
|
||
App.showError('很抱歉,您还没有登录');
|
||
return false;
|
||
}
|
||
return true;
|
||
},
|
||
|
||
/**
|
||
* 退出登录
|
||
*/
|
||
toClear() {
|
||
console.log('退出登录');
|
||
// wx.clearStorageSync()
|
||
wx.clearStorageSync('openId');
|
||
wx.clearStorageSync('token');
|
||
wx.clearStorageSync('userInfo');
|
||
// getApp().globalData.userInfo = null;
|
||
console.log('退出登录22')
|
||
|
||
wx.switchTab({
|
||
url: '/pages/index/index'
|
||
});
|
||
|
||
wx.showToast({
|
||
title: '已退出',
|
||
icon: 'none'
|
||
});
|
||
|
||
},
|
||
|
||
//登陆按钮
|
||
loginUser: function () {
|
||
let _this = this;
|
||
_this.setData({
|
||
showModal: true
|
||
});
|
||
},
|
||
//取消登录
|
||
loginClose: function () {
|
||
let _this = this;
|
||
_this.setData({
|
||
showModal: false,
|
||
modalInput:""
|
||
});
|
||
},
|
||
bindIdCard: function (e) {
|
||
this.setData({
|
||
idcard: e.detail.value
|
||
})
|
||
},
|
||
//登录接口
|
||
checkIdCard: function () {
|
||
let _this = this;
|
||
let idCard = _this.data.idcard;
|
||
if (idCard == undefined) {
|
||
wx.showModal({
|
||
title: "提示",
|
||
content: "身份证号不能为空",
|
||
success: function (a) {
|
||
|
||
}
|
||
});
|
||
return false;
|
||
}
|
||
let user_id = wx.getStorageSync('user_id');
|
||
|
||
App.getUserInfoByIdCard(idCard, (user_id) => {
|
||
_this.getUserProfile(user_id);
|
||
this.getUserDetail();
|
||
this.getUserProfile();
|
||
_this.setData({
|
||
showModal: false,
|
||
isLogin: App.checkIsLogin()
|
||
})
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 获取用户微信信息
|
||
*/
|
||
getUserProfile(user_id) {
|
||
if (!user_id) {
|
||
let user_id = wx.getStorageSync('user_id');
|
||
}
|
||
|
||
const app = this
|
||
try {
|
||
wx.getUserProfile({
|
||
lang: 'zh_CN',
|
||
desc: '获取用户相关信息',
|
||
success({
|
||
userInfo
|
||
}) {
|
||
console.log('用户同意了授权')
|
||
console.log('userInfo:', userInfo)
|
||
App.getUserInfo(userInfo, user_id, () => {
|
||
app.Updatestep();
|
||
});
|
||
},
|
||
fail() {
|
||
console.log('用户拒绝了授权--微信授权')
|
||
}
|
||
})
|
||
} catch (e) {
|
||
console.log('error:', e.message)
|
||
if (e.message === 'wx.getUserProfile is not a function') {
|
||
App.showError('wx.getUserProfile 接口无法使用,请升级到最新版微信')
|
||
} else {
|
||
App.showError(error.message)
|
||
}
|
||
}
|
||
|
||
},
|
||
|
||
/**
|
||
* 编辑
|
||
*/
|
||
jumpEdit: function () {
|
||
let _this = this;
|
||
if (!_this.onCheckLogin()) {
|
||
return false;
|
||
}
|
||
wx.navigateTo({
|
||
url: "/packageA/user/editProfile"
|
||
})
|
||
}
|
||
}) |