import {qqMapTransBMap} from '../../common/tool.js'
import uniPopup from '@/components/uni-popup/uni-popup.vue'
import agreement from '../../components/agreement/agreement.vue'
import http from '@/common/http.js';
import mixin from '@/common/mixin.js';
export default {
name: "authorization",
data() {
return {
session_key:null,
loading:false,
userinfo:null,
backurl:''
}
},
components:{
agreement,
uniPopup
},
onLoad() {
// this.togglePopup();
let page = getCurrentPages()
this.backurl=page[0].route.replace("pages","..");
},
// 混入监听方法
mixins: [mixin],
methods: {
sendlocation(){
uni.getLocation({
type: 'gcj02',
success:(res)=>{
let mapnum = qqMapTransBMap(res.longitude, res.latitude);
http.httpTokenRequest({
url: "User/setLocation",
method: 'POST'
}, {
user_id: this.userinfo.id,
latitude:mapnum.lat,
longitude:mapnum.lng,
reverse_geo:1
}).then((res) => {
})
}
});
},
// 点击获取手机号按钮
getPhoneNumber(e){
http.httpRequest({url:'User/decodePhone',method:'post'},{ encryptedData: e.detail.encryptedData, iv: e.detail.iv,session_key:this.session_key}).then((res)=>{
if(res.data.code==1){
let user=JSON.parse(res.data.data);
user.phone=user.phoneNumber;
this.userinfo=Object.assign(this.userinfo,user);
uni.setStorageSync('userinfo',this.userinfo);
getApp().globalData.userinfo=this.userinfo;
http.httpTokenRequest({url:'User/bindPhone',method:'post'},
{phone:this.userinfo.phone,type:2,user_id:this.userinfo.id}).then((res)=>{
console.log(res,'查看是否绑定成功');
})
uni.reLaunch({
url: this.backurl
});
}else{
uni.showToast({
title: '手机号码获取失败',
icon:"none",
duration: 2000
});
}
})
},
togglePopup(type, open) {
this.$refs.showpopup.open()
},
closepopup(){
this.$refs.showpopup.close()
},
gocodelogin(){
// 前往验证码登录页面
console.log('1235846')
uni.navigateTo({
url:'../codelogin/index'
})
},
wxGetUserInfo() {
this.loading=true;
let that=this;
uni.showLoading({
title: '加载中',
mask:true
});
uni.login({
provider: 'weixin',
success(res){
uni.getUserInfo({
provider: 'weixin',
success(info) {
// 用户信息 已经拿到用户信息
let nickname=info.userInfo.nickName
// console.log(res.code,'codecodecodecodecode');
// return false;
http.httpRequest({url:'User/weChat',method:'post'}, {code:res.code,type:3,nick:nickname}).then((res)=>{
var userinfo=res.data.data
userinfo.cover=info.userInfo.avatarUrl;
that.userinfo=userinfo;
that.session_key=userinfo.session_key;
that.sendlocation();
if(userinfo.phone){
uni.setStorageSync('userinfo',userinfo);
getApp().globalData.userinfo=userinfo;
uni.reLaunch({
url: that.backurl
});
}else{
console.log('弹出框要出来')
that.togglePopup()
}
})
},
complete() {
that.loading=false;
uni.hideLoading();
}
})
}
})
}
}
}