<template>
	<view>
		<view class="w100 h-348 relative">
			<image class="w100 h100" src="/static/images/de.png" mode=""></image>
			<view class="w100 absolute" style="top: 0;">
				<uni-nav-bar left-icon="back" title="登录" :border="false" backgroundColor="transparent" class="fw-b" @clickLeft="$tools.goBack()"></uni-nav-bar>
			</view>
		</view>
		<view class="w100 rows rowsc">
			<image class="w-188 h-188 br-100" :src="$tools.oss(logo)" mode="aspectFill"></image>
		</view>
		<view class="w100 rows rowsl rowsm mt-300">
			<button class="w-546 h-90 bg br-100 colfff fs-30 rows rowsm rowsc" open-type="getPhoneNumber" 
			@getphonenumber="getIphone">授权登录</button>
			<view class="w100 rows rowsc rowsm mt-50">
				<image class="w-24 h-24 mr-15" :src="onSel?'/static/images/xaunzhong.png':'/static/images/dfg.png'" mode="" @click="onSel = !onSel"></image>
				<view class="rows">
					<text class="col666 fs-24">我已阅读并同意</text>
					<view class="fs-24 col" @click="$tools.goNext(`/pageOne/mes/agreement?name=用户协议&type=2`)">《用户协议》</view>
					<view class="fs-24 col" @click="$tools.goNext(`/pageOne/mes/agreement?name=隐私政策&type=1`)">《隐私政策》</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				onSel:false,
				invitation:'',
				logo:''
			}
		},
		onLoad(e) {
			this.invitation = e.pid
			this.richText()
		},
		methods: {
			getIphone(e){
				if(this.onSel==false) return this.$tools.showtt('请先阅读并同意协议')
				uni.login({
					success:(res) => {
						this.insertUserByPhoneNew(e.detail,res.code)
					} 
				})
			},
			insertUserByPhoneNew(e,code){
				this.$tools.axios("POST","user/wxRegister",{
					code,
					iv:e.iv,
					encryptedData:e.encryptedData,
					invitation:this.invitation||''
				}).then(res => {
					this.$tools.showtt(res.msg)
					if(res.code!=1) return
					uni.setStorageSync('token',res.data.userinfo.token)
					uni.setStorageSync('uid',res.data.userinfo.id)
					setTimeout(() => {
						this.$tools.goSwitchTab('/pages/tabbar/index')
					},1000)
				})
			},
			richText(){
				this.$tools.axios("POST","index/richText").then(res => {
					this.logo = res.data.logo
				})
			}
		}
	}
</script>

<style>
	
</style>
