const Parser = require('../xml/xmldom/dom-parser'); //获取应用实例 var app = getApp(); Page({ data: { imgUrl:app.imgUrl, ownerType:'', ownerid:'', //业主id ownername:'', //业主名 hname:'', //房名 hcode:'', //房号 phone:'', //微信手机号 openid:'', session_key:'', nickName:'', //微信昵称 avatarRell:app.imgUrl+'timg.jpg', //微信头像 isPone:false , //是否需要显示获取手机号权限 isLogin:false, //是否需要重新登录 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.showToast({ title: '加载中', icon: 'loading', duration: 2000, sessionPhone:'', }) }, /** * 生命周期函数--监听页面显示 */ onShow: function (options) { var that = this; wx.getSetting({ success (res) { console.log('获取用户的当前设置',res) } }) try { wx.getStorage({ key: 'ownerdatas', success:function(res){ console.warn('获取缓存数据',res.data); if(res.data!=null&&res.data.length>0){ var sum = res.data.split(','); if(sum.length!=8){ //若数组没有8个,则表明缓存数据不足,删除缓存,重新获取 wx.removeStorageSync('ownerdatas'); that.setData({isLogin:true}); } else{ //若足够,则重新给data赋值 that.setData({ avatarRell:sum[0], openid:sum[1], nickName:sum[2], phone:sum[3], hcode:sum[4], hname:sum[5], ownerid:sum[6], ownername:sum[7], isLogin:false }) } } }, fail:function(res){ console.warn('获取缓存失败',res); that.setData({isLogin:true}); } }) if(that.data.phone!=undefined&&that.data.phone!=null&&that.data.phone!=''){ that.setData({isPone:false}); return; } //微信登录 wx.login({ complete: (res) => { console.warn('login',res); wx.request({ // 获取微信openid url: app.coreUrl+`GetOpenid?code=${res.code}`, method:"get", success:function(resopenid){ console.warn('coreUrl',app.coreUrl); console.warn('resopenid',resopenid); var ownerData = resopenid.data.split(','); that.setData({ openid:ownerData[0], session_key:ownerData[1] }) } }) }, })   } catch(error) { console.error('try失败',error);   } }, sp:function(){ }, getUserInfo(e){ console.warn('getUserInfo',e); var that = this; that.setData({ avatarRell:e.detail.userInfo.avatarUrl, nickName:e.detail.userInfo.nickName, isPone:true }) //获取的用户信息存入缓存 wx.setStorageSync( 'ownerdatas',e.detail.userInfo.avatarUrl+','+that.data.openid+','+that.data.nickName ) }, // 获取手机号 getPhoneNumber (e) { var that = this; wx.login({ complete: (res) => { wx.request({ url: app.coreUrl+'PostPhoneNumber', data: { encryptedData: e.detail.encryptedData, iv: e.detail.iv, code:res.code }, method: "post", success: function (resphone) { console.log('getPhoneNumber',resphone); that.setData({ phone:resphone.data.phoneNumber }); if(resphone.data.phoneNumber!=undefined&&resphone.data.phoneNumber!=''&&resphone.data.phoneNumber!=null){ wx.request({ url: app.coreUrl+'updateOwnerUrl', data:{ tel:that.data.phone, url:that.data.avatarRell, weixinid:that.data.openid }, method: "post", success:function(e){ console.warn('updateOwnerUrl',e.data); if(e.data=='微信头像更新失败,查询不到当前客户'||e.data=='参数有误'){ that.setData({ isPone:false, phone:'绑定失败,查无业主' }) } else{ //绑定成功 var arr=e.data.split(','); that.setData({ isPone:false, isLogin:false, ownerType:'', hcode:arr[0], hname:arr[1], ownerid:arr[2], ownername:arr[3] }); var value=wx.getStorageSync('ownerdatas'); console.warn('value',value); if(value!=null&&value.length>0){ let value1=value+','+that.data.phone+','+e.data; console.warn('ownerdatas',value1); wx.setStorageSync('ownerdatas', value1); //手机号存储入key为ownerdatas的缓存中 } } } }) } } }) }, }) }, jiaoFeiJiLuURL:function(){ // 跳转缴费记录 if(this.data.phone!=''){ wx.navigateTo({ url: `../jfjl/jfjl?openid=${this.data.openid}&ownerid=${this.data.ownerid}`, }) } else{ wx.showModal({ title: '提示', content: '请先点击登录', showCancel:false, success (res) { if (res.confirm) { } } }) } }, woYaoBaoXiu:function(){ // 跳转我要报修 if(this.data.phone!=''){ wx.navigateTo({ url: `../baoxiu/baoxiu?openid=${this.data.openid}&phone=${this.data.phone}&hname=${this.data.hname}&hcode=${this.data.hcode}&ownerid=${this.data.ownerid}&ownername=${this.data.ownername}`, }) } else{ wx.showModal({ title: '提示', content: '请先点击登录', showCancel:false, success (res) { if (res.confirm) { } } }) } }, woYaoTousu:function(){ // 跳转我要投诉 if(this.data.phone!=''){ wx.navigateTo({ url: `../tousu/tousu?openid=${this.data.openid}&phone=${this.data.phone}&hname=${this.data.hname}&hcode=${this.data.hcode}&ownerid=${this.data.ownerid}&ownername=${this.data.ownername}`, }) } else{ wx.showModal({ title: '提示', content: '请先点击登录', showCancel:false, success (res) { if (res.confirm) { } } }) } }, woYaoJiaoFei:function(){ // 跳转我要缴费 if(this.data.phone!=''){ wx.navigateTo({ url: `../wyjf/wyjf?openid=${this.data.openid}&phone=${this.data.phone}`, }) } else{ wx.showModal({ title: '提示', content: '请先点击登录', showCancel:false, success (res) { if (res.confirm) { } } }) } }, baoXiuJiLuURL:function(){ // 跳转报修记录 if(this.data.phone!=''){ wx.navigateTo({ url: `../bxjl/bxjl?ownerid=${this.data.ownerid}`, }) } else{ wx.showModal({ title: '提示', content: '请先点击登录', showCancel:false, success (res) { if (res.confirm) { } } }) } }, tousuJiLuURL:function(){ // 跳转报修记录 if(this.data.phone!=''){ wx.navigateTo({ url: `../tsjl/tsjl?ownerid=${this.data.ownerid}`, }) } else{ wx.showModal({ title: '提示', content: '请先点击登录', showCancel:false, success (res) { if (res.confirm) { } } }) } }, fanChanXinXiURL:function(){ //跳转房产信息 if(this.data.phone!=''){ wx.navigateTo({ url: `../fcxx/fcxx?openid=${this.data.openid}&phone=${this.data.phone}`, }) } else{ wx.showModal({ title: '提示', content: '请先点击登录', showCancel:false, success (res) { if (res.confirm) { } } }) } } })