wzj-boot/mini-app/src/components/user/dialog-registration.wpy

208 lines
5.1 KiB
Plaintext
Raw Normal View History

2021-01-12 18:04:14 +08:00
<style lang="less">
.header {
width: 100%;
height: 536rpx;
z-index: -10;
}
</style>
<template>
<div>
<van-dialog
use-slot
title="新用户注册"
:show="isShow"
show-cancel-button
bind:close="onClose"
bind:cancel="onClose"
confirm-button-open-type="getUserInfo"
bind:getuserinfo="getUserInfo"
:asyncClose="true"
>
<van-field
label="手机号:"
title-width="60px"
value="{{ user.mobile }}"
center
clearable
readonly
placeholder="请实名授权获取手机号"
border="{{ false }}"
use-button-slot
>
2021-01-21 16:14:44 +08:00
<van-button slot="button" size="small" plain type="info" color="#AC1630" open-type="getPhoneNumber"
2021-01-12 18:04:14 +08:00
bind:getphonenumber="onGetMobile">授权
</van-button>
</van-field>
<!-- <van-divider customStyle="font-size: 18px; margin: 5px 5px;" />-->
<!-- <van-field-->
<!-- label="昵称:"-->
<!-- title-width="60px"-->
<!-- value="{{ user.userInfo.nickName }}"-->
<!-- center-->
<!-- clearable-->
<!-- readonly-->
<!-- placeholder="请点击授权获取您的微信信息"-->
<!-- border="{{ false }}"-->
<!-- use-button-slot-->
<!-- >-->
<!-- <van-button slot="button" size="small" plain type="info" open-type="getUserInfo"-->
<!-- bind:getuserinfo="getUserInfo">获取昵称-->
<!-- </van-button>-->
<!-- </van-field>-->
2021-01-21 16:14:44 +08:00
<view style="margin:10px;display: flex;">
2021-01-12 18:04:14 +08:00
<van-checkbox :value="isChecked" shape="square" bind:change="onChangeCheak" checked-color="#AC1630"
2021-01-21 16:14:44 +08:00
/>
<span style="font-size: 13px;color: #AC1630;margin-left: 5px;">我同意并遵守紫色名片
<span style="color: cornflowerblue;" @tap="onTapPrivacy">《隐私政策》 </span>及
<span style="color: cornflowerblue;" @tap="onTapAgreement">《用户条款》 </span>
的全部内容</span>
2021-01-12 18:04:14 +08:00
</view>
</van-dialog>
</div>
</template>
<script>
import wepy from '@wepy/core'
import store from '@/store'
import { mapActions, mapState } from '@wepy/x'
import eventHub from '../../common/eventHub'
2021-01-15 12:00:20 +08:00
import appManager from '../../appManager'
2021-01-12 18:04:14 +08:00
import userApis from '../../apis/userApis'
2021-01-21 16:14:44 +08:00
import { newsDetailPage } from '../../store/constant/nav/pages'
2021-01-12 18:04:14 +08:00
wepy.component({
store,
props: {},
hooks: {},
data: {
that: this,
isShow: false,
model: {},
2021-01-21 16:14:44 +08:00
isChecked: false
2021-01-12 18:04:14 +08:00
},
2021-01-21 19:04:31 +08:00
// computed: mapState(['user']),
computed: {
...mapState({
'user': state => state.user,
'hotSwitch': state => state.hotSwitch
})
},
2021-01-12 18:04:14 +08:00
events: {},
methods: {
...mapActions([
'setUserAction',
'setUserInfoAction',
'setMobileAction',
'setTokenAction'
]),
getUserInfo(event) {
console.log('getUserInfo:', event.$wx.detail)
this.setUserInfoAction(event.$wx.detail.userInfo)
console.log('userInfo:', store.state.user.userInfo)
if (!this.isChecked) {
2021-01-22 10:54:01 +08:00
appManager.showToast('请同意并遵守紫色名片《隐私政策》以及《用户条款》.')
2021-01-12 18:04:14 +08:00
return false
}
if (!this.user.mobile) {
2021-01-15 12:00:20 +08:00
appManager.showToast('请授权获取手机号码.')
2021-01-12 18:04:14 +08:00
return false
}
if (!this.user.userInfo) {
2021-01-15 12:00:20 +08:00
appManager.showToast('请授权获取用户昵称.')
2021-01-12 18:04:14 +08:00
return false
}
let self = this
userApis.registrationByMini(this.user).then(r => {
if (r.code === 200) {
2021-01-15 12:00:20 +08:00
appManager.showToast('注册成功!')
2021-01-12 18:04:14 +08:00
self.isShow = false
self.setTokenAction(r.token)
} else {
2021-01-15 12:00:20 +08:00
appManager.showToast(r.msg)
2021-01-12 18:04:14 +08:00
}
}).catch(e => {
2021-01-15 12:00:20 +08:00
appManager.showToast('注册失败!')
2021-01-12 18:04:14 +08:00
})
},
async onGetMobile(e) {
console.log(e.$wx.detail)
wx.showLoading({ title: '获取中...', mask: true })
try {
let rsp = await userApis.sendMobile({
2021-01-15 12:00:20 +08:00
openid: appManager.getOpenid(),
2021-01-12 18:04:14 +08:00
detail: e.$wx.detail
})
if (rsp.code === 200) {
this.setMobileAction(rsp.data.mobile)
} else {
2021-01-15 12:00:20 +08:00
appManager.showToast('服务器连接异常.')
2021-01-12 18:04:14 +08:00
}
} catch (e) {
2021-01-15 12:00:20 +08:00
appManager.showToast('服务器连接异常.')
2021-01-12 18:04:14 +08:00
} finally {
wx.hideLoading()
}
},
onChangeCheak(e) {
this.isChecked = e.$wx.detail
},
onClose() {
this.isShow = false
2021-01-21 16:14:44 +08:00
},
onTapAgreement() {
wx.navigateTo({
url: newsDetailPage + '?id=' + 'fb4109a4020b2a2a9d1172f66d043897'
})
},
onTapPrivacy() {
wx.navigateTo({
url: newsDetailPage + '?id=' + 'a1e5ec18ae13036d14c94bf0e5d11756'
})
2021-01-12 18:04:14 +08:00
}
},
ready() {
// 获取系统信息
let self = this
wx.getSystemInfo({
success(res) {
self.model = res.model
}
})
this.page = this
2021-01-22 13:25:06 +08:00
eventHub.$on('onShowDialogRegist', (...args) => {
2021-01-12 18:04:14 +08:00
this.isShow = true
})
}
})
</script>
<config>
{
navigationBarTitleText: ''
}
</config>