// pages/redGrider/redGrider.js var api = require('../../utils/api.js') var config = require('../../utils/config.js') const partyApi = require('../../utils/partApi') const app = getApp() Page({ /** * 页面的初始数据 */ data: { statusHeight: app.globalData.deviceInfo.statusHeight, // 自定义头部状态栏高度 navigationHeight: app.globalData.deviceInfo.navigationHeight, userName: {}, faceImg: '', pass: 0, userId: '', userInfo: {}, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getUserInfo() this.getUserProfile() }, getUserProfile(e) { let obj = JSON.parse(wx.getStorageSync('userInfo')) if (null != obj.id) { this.setData({ userId: obj.id, faceImg: obj.faceImg }) } this.getCentralhousehold(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { let savedUserInfoString = wx.getStorageSync("userInfo"); if (savedUserInfoString) { let savedUserInfo = JSON.parse(savedUserInfoString); this.setData({ userName: savedUserInfo.realName, faceImg: savedUserInfo.faceImg }) } else { this.setData({ userName: '请先注册', faceImg: '../../images/head.png' }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, back() { //返回上一级,关闭当前页面 wx.navigateBack({ delta: 1 }) }, logout() { let than = this wx.showModal({ title: '提示', content: '确定退出登录', success(res) { if (res.confirm) { wx.showLoading({ title: "退出中,请稍后...", mask: true, success() { setTimeout(() => { wx.removeStorage({ key: 'token', }) wx.removeStorage({ key: 'userInfo', }) wx.reLaunch({ url: '/pages/login/login' }) app.globalData.selected = 0; }, 1000) } }) } } }) }, tapchangeImg() { const _this = this; wx.chooseMedia({ count: 1, mediaType: ['image'], sourceType: ['album', 'camera'], camera: 'back', success(res) { const url = res.tempFiles[0].tempFilePath; if (url) { wx.uploadFile({ filePath: url, name: 'file', url: config.BASEURL() + 'commonsUtils/upload', formData: {}, success: function (res) { let imgUrl = JSON.parse(res.data).data.url; if (imgUrl) { _this.setData({ faceImg: imgUrl }) wx.login({ success: (res) => { let para = {} let obj = JSON.parse(wx.getStorageSync('userInfo') || {}) para.identityNo = obj.identityNo; para.mobile = obj.mobile; para.partyFlag = obj.partyFlag; para.realName = obj.realName; para.shibei = obj.shibei; para.villageName = obj.villageName; para.workIndustry = obj.workIndustry; para.workType = obj.workType; para.workUnit = obj.workUnit; para.hobbies = obj.hobbies; para.allDeptIds = obj.allDeptIds.split(","); para.couplingCommunity = obj.couplingCommunity.split(","); para.userId = wx.getStorageSync('userId') para.wxCode = res.code para.faceImg = _this.data.faceImg if (res.code) { api.userInfoUpdate(para).then(res => { if (res.code == 0) { wx.setStorageSync(para, 'userInfo') _this.getUserInfo() } }).catch(err => { console.log(err); }) } }, }) } } }) } } }) }, getUserInfo() { api.getUserInfo().then(res => { let userInfoString = JSON.stringify(res.data); wx.setStorageSync('userInfo', userInfoString); this.getUserProfile() }).catch(err => { console.log(err) }) }, getCentralhousehold() { let para = this.data.userId partyApi.getCentralhousehold(para).then(res => { if (null == res.data) { this.setData({ pass: 0 // 审核状态 }) } else { this.setData({ pass: res.data.pass // 审核状态 }) } }) }, })