<template>
	<view class="register">
		<view class="wrapperDEghTTorsp">
			<view class="input-contentDEghTTorsp">
				<view class="cu-form-group" style="border-bottom: 2upx solid whitesmoke;margin-bottom: 20px;">
					<view class="title">手机号</view>
					<input type="number" :disabled="true" :value="phone" placeholder="请输入手机号" maxlength="11" data-key="phone" @input="inputChangeDEghTTorsp" />
				</view>
				<view class="cu-form-group" style="border-bottom: 2upx solid whitesmoke;margin-bottom: 20px;">
					<text class="title">设置密码</text>
					<input type="password" :value="password" placeholder="请设置密码" placeholder-class="input-empty" maxlength="20"
					 minlength="6" data-key="password" @input="inputChangeDEghTTorsp" />
				</view>
				<!-- <view class="cu-form-group" style="border-bottom: 2upx solid whitesmoke;margin-bottom: 20px;" v-if="required == '是'">
					<text class="title">邀请码</text>
					<input type="number" maxlength="6" :value="invitation" placeholder="请填写邀请码(必填)" data-key="invitation" @input="inputChangeDEghTTorsp" />
				</view>
				<view class="cu-form-group" style="border-bottom: 2upx solid whitesmoke;margin-bottom: 20px;" v-if="required == '否'">
					<text class="title">邀请码</text>
					<input type="number" maxlength="6" :value="invitation" placeholder="请填写邀请码(选填)" data-key="invitation" @input="inputChangeDEghTTorsp" />
				</view> -->
			</view>
			<button class="confirm-btnDEghTTorsp" @click="startRegDEghTTorsp">绑定手机号</button>
		</view>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				userName: '',
				showAgree: false,
				code: '',
				phone: '',
				password: '',
				required: '否',
				sending: false,
				sendTime: '获取验证码',
				count: 60,
				relation: "",
				state: '',
				invitation: '',
				platform: 'app',
				sysPhone:1
			}
		},
		onLoad(d) {
			console.log(d.phone)
			if(d.phone){
				this.phone = d.phone;
			}
			this.invitationMaDEghTTorsp();
			let a = this.$queue.getData("isEnable")
			if (a) {
				this.isEnable = a;
			}
			// #ifdef APP-PLUS
			switch (uni.getSystemInfoSync().platform) {
				case 'android':
					break;
				case 'ios':
					this.sysPhone = 2;
					break;
				default:
					break;
			}
			// #endif
		},

		mounted() {
			_this = this;
		},
		methods: {
		
			// 注册邀请码必填
			invitationMaDEghTTorsp() {
				this.$Request.getT('/app/common/type/3').then(res => {
					if (res.code == 0) {
						this.required = res.data.value;
				
					}
				});
			},
			inputChangeDEghTTorsp(e) {
				const key = e.currentTarget.dataset.key;
				this[key] = e.detail.value;
			},
			
			startRegDEghTTorsp() {
				if (this.phone.length != 11) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '手机号不正确'
					});
					return false;
				}
				
				if (!this.password) {
					this.$queue.showToast('请设置密码');
					return false;
				}
				
				if (this.password.length < 6) {
					this.$queue.showToast('密码位数必须大于六位');
					return false;
				}
				
				if (!_this.invitation && this.required == '是') {
					this.$queue.showToast('请填写邀请码');
					return false;
				}
				this.$queue.showLoading('登陆中...')
				_this.isRotate = true;
				let qdCodeion = '';
				if (uni.getStorageSync('qdCodeion')) {
					qdCodeion = uni.getStorageSync('qdCodeion')
				}
				this.$Request.postT("/app/Login/bindMobile", {
					password: _this.password,
					phone: _this.phone,
					inviterCode: _this.invitation,
					qdCode: qdCodeion,
					sysPhone:_this.sysPhone
				}).then(res => {
					console.log(JSON.stringify(res))
					if (res.code === 0) {
						this.$queue.setData("mobile", _this.phone);
						this.$queue.setData("token", res.token);
						this.$queue.setData("userId", res.user.userId);
						uni.switchTab({
							url: '/pages/index/index'
						})
					} else {
						_this.isRotate = false;
						uni.hideLoading();
						uni.showModal({
							showCancel: false,
							title: '绑定失败',
							content: res.msg,
						});
					}
				});
			},
			
		}
	}
</script>

<style lang='scss'>

	page {
		background: #ffffff;
	}
	

	
	.wrapperDEghTTorsp {
		position: relative;
		z-index: 90;
		background: #ffffff;
		padding-bottom: 20px;
	}
	
	.input-contentDEghTTorsp {
		padding: 0 20px;
	}
	
	
	.confirm-btnDEghTTorsp {
		width: 300px;
		height: 42px;
		line-height: 42px;
		border-radius: 30px;
		margin-top: 40px;
		background: #5074FF;
		color: #ffffff;
		font-size: 32rpx;
	
		&:after {
			border-radius: 60px;
		}
	}
</style>
