123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- //index.js
- //获取应用实例
- const app = getApp()
- Page({
- data: {
- userInfo: {},
- waterInfo: {},
- onQuery: true,
- unAuth:false,
- items: [{
- id: 'realtimewater',
- label: '用水量',
- icon: '/static/img/icon-water.png',
- url: '?period=7',
- sonlabel:'近期用水量'
- }, {
- id: 'waterabnormal',
- label: '异常预警',
- icon: '/static/img/icon_water_abnormal.png',
- sonlabel:'用水异常提醒'
- }
- ],
- itemsrow:[
- {
- id: 'wateranalysis',
- label: '用水趋势',
- icon: '/static/img/icon_water_analysis.png',
- sonlabel:'年度用水趋势'
- }, {
- id: 'customermanage',
- label: '户号管理',
- icon: '/static/img/btn_hubiao1.png',
- sonlabel:'绑定户号'
- }
- ],
- weixinLogin: false,
- },
- getPhoneNumber(e) {
- let that = this;
- if (e.detail.encryptedData) {
- const {
- iv,
- encryptedData
- } = e.detail;
- const {
- param,
- item = {}
- } = e.currentTarget.dataset;
- wx.login({
- success: res => {
- const {
- code
- } = res;
- app.$http.postForm('/appletUser/bindingMobile', {
- code,
- encryptedData,
- iv
- }).then(({
- status,
- data = {}
- }) => {
- if (status === 0) {
- // 绑定成功
- if (this.data.userInfo.deviceId) {
- wx.navigateTo({
- url: `/pages/${item.id || param}/${item.id || param}${item.url ? item.url : ''}`
- })
- }
- wx.showToast({
- title: '授权成功',
- icon: 'none',
- duration: 2000
- })
- that.setData({
- weixinLogin:true,
- onQuery:false
- })
- console.log("weixinLogin:"+that.data.weixinLogin)
- console.log("onQuery:"+that.data.onQuery)
- return;
- }
- // 绑定成功未注册
- else {
- wx.showToast({
- title: '您尚未注册,请到平台端开通账号后重试',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- })
- }
- })
- }
- else{
- wx.showToast({
- title: '您尚未注册,请到平台端开通账号后重试',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- },
- gotopage(e) {
- const {
- param,
- item = {}
- } = e.currentTarget.dataset;
- if (!this.data.weixinLogin) {
- wx.showToast({
- title: '请您先进行授权',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- console.log("app的值",app)
- if (!this.data.userInfo.userNumber && param != 'customermanage' && item.id != 'customermanage') {
- wx.showToast({
- title: '请先绑定你的户号',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- wx.navigateTo({
- url: `/pages/${item.id || param}/${item.id || param}${item.url ? item.url : ''}`
- })
- },
- getAccountInfo() {
- let _self=this
- this.setData({
- onQuery:true,
- unAuth:false
- })
- app.$util.selfUserInfo(app.globalData, true).then((data) => {
- if (data) {
- this.setData({
- userInfo: data,
- waterInfo: data.waterStages
- })
- _self.setData({
- onQuery:false
- })
- console.log("_self.onQuery:" + _self.data.onQuery)
- } else {
- this.setData({
- userInfo: {},
- waterInfo: {}
- })
- }
-
- }).catch(() => {
- _self.setData({
- onQuery:false
- })
- })
- },
- // 获取用户注册状态 /user/getUser
- isRegister(){
- let that=this;
- that.setData({unAuth:false})
- app.$http.postForm('/appletUser/getUser').then(({ status, msg, data }) => {
- // 已授权但客户不存在
- // 未授权
- if(status===-602){
- that.setData({
- weixinLogin:false
- })
- }else if(status===0){
- that.setData({
- weixinLogin:true
- })
- }
- else if(status===-406)
- {
- that.setData({
- weixinLogin:false,
- unAuth:true
- })
- wx.showToast({
- title: '您尚未注册认证,请到平台端开通账号后重试',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- })
- },
- onShow() {
- let _self=this
- this.getAccountInfo();
- this.isRegister()
- },
- toLogin(msg) {
- this.popup && this.popup.setData({
- type: 'error',
- title: '提示',
- content: msg,
- showCancel: false
- });
- this.popup.show();
- },
- cancelEvent: function () {
- this.popup.close();
- },
- confirmEvent: function () {
- this.getAccountInfo(true);
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- //获得popup组件
- this.popup = this.selectComponent("#popup");
- },
- })
|