const App = getApp(); Page({ /** * 页面的初始数据 */ data: { userInfo: {}, UserCategory:[], category_id:0, category_name:'未选择队伍', isLogin: false, show:0 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getUserDetail(); this.getUserCategory(); }, /** * 生命周期函数--监听页面显示 */ onShow() { let _this = this; _this.setData({ isLogin: App.checkIsLogin() }); }, /** * 获取当前用户信息 */ getUserDetail() { let _this = this; App._post_form('user.index/detail', { user_id: wx.getStorageSync('user_id') }, result => { _this.setData(result.data); _this.setData({ category_id:result.data.userInfo.category_id }); }); }, getUserCategory(){ let _this = this; App._post_form('user.index/getUserCategory', {}, result => { _this.setData(result.data); let UserCategoryArr = result.data.UserCategory; for(let i=0; i { _this.setData({ show:!_this.data.show }); let status = result.data.status, msg; switch(status) { case 0: msg = '修改失败'; break; case 1: msg = '修改成功'; break; default: msg = '修改失败'; } wx.showToast({ title: msg, icon: 'none', duration: 2000 }) _this.setData({ category_name:result.data.category_name }); }); }, /** * 菜单列表导航跳转 */ 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; }, })