var api = require('../../utils/api.js') var global = require('../../utils/config.js') import regeneratorRuntime from '../../utils/runtime.js' const app = getApp() Page({ data: { gridId: '', gridName: '', gridNameArr: [], formid: '', resToken: '', resGridName: '', inviteUserId: '', GridNameId:"" }, onLoad(options) { if (options.gid) { this.setData({ gridId:'1221751857028825090', inviteUserId: options.inviteUserId }) } this.getToken(options.gid) // this.getInvitation() }, // getInvitation(){ // let that = this // api.getInvitation(this.data.gridId).then(function (res) { // that.setData({ // GridNameId:res.data // }) // that.getGridName() // }) // }, getToken: function (gid) { let that = this wx.login({ success(res) { if (res.code) { console.log('微信CODE: ' + res.code) let wxCode = res.code const para = { inviteUserId: that.data.inviteUserId, //写死四机社区第一网格 gridId: '1224104693058306049', wxCode: res.code } api.getTokenV3(para).then(function (res) { global.Token = res.data.token wx.removeStorageSync('token') wx.setStorageSync('token', res.data.token) that.setData({ resToken: res.data.token, resGridName: res.data.grid }) }) } } }) }, getGridName() { let that = this api.getCompleteName(this.data.GridNameId).then(function (res) { wx.setStorage({ key: "gridName", data: res.data }) that.setData({ gridName: res.data, gridNameArr: res.data.split('/') }) }) }, bindGetUserInfo: function (e) { if (e.detail.userInfo) { // let wxHeadImg = e.detail.userInfo.avatarUrl // let wxNickName = e.detail.userInfo.nickName console.log(e) let that = this wx.login({ success: function (response) { let code = response.code; wx.getUserInfo({ success: function (res) { console.log(res.encryptedData) console.log(res.iv) let encryptedData = res.encryptedData let iv = res.iv api.updateWxInfo(code, encryptedData, iv).then(function (res) { // 跳转到首页 console.log('跳转到首页') wx.setStorageSync('isFirst', 'noFirst') wx.reLaunch({ url: '/pages/index/index' }) }) } }) } }) } else { console.log('拒绝授权') wx.redirectTo({ url: '/pages/index/index' }) // wx.showModal({ // title: '提示', // content: '您点击了拒绝授权,将无法进入小程序,请授权之后再进入!', // showCancel: false, // confirmText: '返回授权', // success: function (res) { // if (res.confirm) { // console.log('用户点击了“返回授权”') // } // } // }) } }, navigateToIndex () { wx.reLaunch({ url: '/pages/home/home' }) } })