wechat_yxcl/pages/register/register.vue
2020-11-12 14:57:34 +08:00

114 lines
2.9 KiB
Vue

<template>
<view class="content">
<image src="https://eshangtech.com/ShopICO/login_logo.png" mode="aspectFit"></image>
<view class="desc" v-if="!user.WeChat_UserId ">
<!-- <view class="desc">申请获取你的公开信息(昵称头像)</view> -->
<button type="primary" class="btn" open-type="getUserInfo" @getuserinfo="bindGetUserInfo">微信授权</button>
</view>
<view class="desc" v-if="user.WeChat_UserId&& !user.Membership_Phone">
<button type="primary" class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">快速登录账号</button>
</view>
</view>
</template>
<script>
import { mapActions, mapGetters,mapMutations } from 'vuex'
export default {
data() {
return {
shouldNavback: false,
}
},
computed:{
...mapGetters({
'user':'getUser',
})
},
onLoad(option) {
if(option.source=='detail'){
this.shouldNavback = true
}
},
methods: {
...mapActions(['updateUser']),
...mapMutations(['setUser']),
getPhoneNumber (e) {
let _this = this
let _data = e.mp.detail
let user = _this.user
let arr = {
encryptedData: encodeURIComponent(_data.encryptedData),
iv: encodeURIComponent(_data.iv)
}
_this.$request.$get('WeChat_BusinessPhone',arr).then(function (rs) {
if (rs.Result_Code === 100) {
_this.updateUser(rs.Result_Data)
_this.$util.toNextRoute('switchTab', '/pages/index/index')
// uni.switchTab({url: '/pages/index/index'})
} else {
uni.showToast({title: rs.Result_Desc || '服务器错误,请联系管理员。', icon: 'none'})
}
})
},
bindGetUserInfo (e) { // 申请权限
let _this = this
let user = _this.user
if (e.mp.detail) {
uni.getUserInfo({
success (res) {
let arr = {
encryptedData: encodeURIComponent(res.encryptedData),
iv: encodeURIComponent(res.iv),
}
_this.$request.$post('WeChat_BusinessLicensed',arr).then(function (rs) {
if(rs.Result_Code==100){
let newUser = rs.Result_Data
newUser.WeChat_MiniProToken = _this.user.WeChat_MiniProToken
_this.setUser(newUser)
if(newUser.Membership_Phone) {
_this.updateUser(newUser)
_this.$util.toNextRoute('switchTab', '/pages/index/index')
// uni.reLaunch({url: '/pages/index/index'})
}else{
}
_this.$forceUpdate()
}//else{
// uni.showToast({
// title: rs.ResultDesc,
// icon: 'none',
// duration:2000
// })
// }
})
}
})
}
}
},
onUnload() {
this.$util.addUserBehavior()
},
}
</script>
<style scoped>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
padding-top: 88upx;
}
.btn {
margin-top: 64upx;
width: 580upx;
font-size: 28upx;
}
</style>