<template>
	<view class="default_page" :style="{'height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='PERILL团队动态评估系统' bgColor="transparent" backUrl="/pages/login"></cus-header>
		<view class="info">
			<view class="info-title">邀请你填写以下基本信息</view>
			<view class="info-form">
				<view class="info-form-item adfacjb">
					<view class="info-form-item-left">你的姓名</view>
					<view class="info-form-item-right">
						<u-input v-model="dto.realName" border="none" placeholder="请填写姓名"></u-input>
					</view>
				</view>
				<view class="info-form-item adfacjb">
					<view class="info-form-item-left">你的邮箱</view>
					<view class="info-form-item-right">
						<u-input v-model="dto.email" border="none" placeholder="请填写邮箱"></u-input>
					</view>
				</view>
			</view>
		</view>
		<view class="zt_btn" @click="handleSubmit">提交</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				info:null,
				user:null,
				dto:{
					userId:'',
					mobile:'',
					realName:'',
					email:'',
					
				}
			}
		},
		onLoad(options) {
			let params = JSON.parse(decodeURIComponent(options.params));
			this.info = params.info;
			this.user = params.user;
			this.dto.userId = this.info.userId||'';
			this.dto.mobile = this.info.mobile||'';
		},
		methods:{
			handleSubmit(){
				if(!this.dto.realName) return this.$showToast('请输入姓名')
				// if(!this.$reg.email(this.dto.email)) return this.$showToast('请输入正确的邮箱')
				
				uni.showLoading({ title:'注册提交中' });
				this.$api.post('/wx/register',this.dto,false).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					this.postRegisterRecord()
				})
			},
			postRegisterRecord(){
				if(uni.getStorageSync('shareUserId')&&!this.info.referrerId) this.info.referrerId = uni.getStorageSync('shareUserId');
				if(uni.getStorageSync('shareTQId')&&!this.info.teamQuestionnaireId) this.info.teamQuestionnaireId = uni.getStorageSync('shareTQId');
				this.$api.post('/core/register/record',{
					channelType:this.info.channelType||'common',
					referrerId:this.info.referrerId||'',
					teamQuestionnaireId:this.info.teamQuestionnaireId||'',
					userId:this.info.userId||''
				},false).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					
					uni.setStorageSync('token',this.user.token);
					uni.setStorageSync('userInfo',JSON.stringify({
						id:this.user.id,
						openId:this.user.openId||'',
						gender:this.user.gender,
						realName:this.dto.realName,
						email:this.dto.email,
						mobile:this.user.mobile,
						headUrl:this.user.headUrl,
						teamId:this.user.teamId,
						enterpriseId:this.user.enterpriseId,
						enterpriseName:this.user.enterpriseName,
						teamName:this.user.teamName,
						channelType:this.user.channelType,
						referrerId:this.user.referrerId,
						teamQuestionnaireId:this.user.teamQuestionnaireId,
						isRegister:1,
						userBrief:this.user.userBrief,
					}));
					
					uni.hideLoading();
					this.$showToast('提交成功');
					uni.reLaunch({
						url:'/pages/home'
					})
				})
			},
			checkUser(){
				this.$api.post('/wx/check',{
					channelType:this.info.channelType||'',
					isRegister:this.info.isRegister,
					referrerId:this.info.referrerId||'',
					teamQuestionnaireId:this.info.teamQuestionnaireId||'',
					userId:this.info.userId||''
				},false).then(({data:res})=>{
					if(res.code!==0) return this.$showToast(res.msg)
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	::v-deep .u-input__content__field-wrapper__field{
		font-size: 28rpx !important;
		line-height: 40rpx !important;
		text-align: right !important;
	}
	
	.default_page{
		padding: 0 30rpx;
		background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/info_bg.png') no-repeat;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		
		.info{
			width: 100%;
			margin-top: 88rpx;
			padding: 0 18rpx;
			box-sizing: border-box;
			&-title{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 42rpx;
				color: #002846;
				line-height: 42rpx;
			}
			&-tip{
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #667E90;
				line-height: 40rpx;
				margin-top: 24rpx;
			}
			&-form{
				width: 100%;
				background: #FFFFFF;
				border-radius: 24rpx;
				margin-top: 60rpx;
				padding: 0 24rpx;
				box-sizing: border-box;
				&-item{
					border-bottom: 1rpx solid #EFEFEF;
					padding: 39rpx 0;
					&:last-child{
						border: none;
					}
					&-left{
						width: 160rpx;
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 30rpx;
						color: #002846;
						line-height: 42rpx;
					}
					&-right{
						width: calc(100% - 160rpx);
					}
				}
			}
		}
		
		.zt_btn{
			margin-top: 390rpx;
		}
	}
</style>