<template>
	<view class="register">

		<view class="content">
			<!-- 头部logo -->
			<view class="header" style="margin-top: 20px;">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体 -->
			<view class="main">
				<wInput v-model="from.nickName" type="text" maxlength="8" placeholder="姓名"></wInput>
				<wInput v-model="from.phonenumber" type="text" maxlength="11" placeholder="手机号"></wInput>
				<wInput v-model="from.password" type="password" maxlength="8" placeholder="登录密码" isShowPass></wInput>
				<!-- <wInput v-model="from.orgCode" type="text" placeholder="机构注册码"></wInput> -->
			</view>

			<wButton class="wbutton" bgColor="linear-gradient(to bottom right, rgb(55,186,189), #94e2c4)" text="注 册"
				:rotate="isRotate" @click.native="startReg()"></wButton>

			<!-- 底部信息 -->
			<view class="footer">
				<text @tap="isShowAgree" class="cuIcon" :class="showAgree?'cuIcon-radiobox':'cuIcon-round'"> 同意</text>
				<!-- 协议地址 -->
				<navigator url="" open-type="navigate">《协议》</navigator>
			</view>
			<view class="uni-fixed-bottom">
				<div style="padding: 0 15px;">
					<u-row>
						<u-col span="5">
							<u-text text="技术支持：会山科技" color="#cacaca">
							</u-text>
						</u-col>
						<u-col span="3">
							<div></div>
						</u-col>
						<u-col span="5">
							<u-text style="position: absolute; right: 15px;bottom: 0;" text="hs@willalp.com"
								color="#cacaca">
							</u-text>
						</u-col>
					</u-row>
				</div>
			</view>
		</view>
		<u-modal :show="modalContent1.show" :title="modalContent1.title" confirmColor="#53a591"
			@confirm="confirmToLogin()">
			<span>请牢记登录名：</span>
			<span style="color: #53a591;">
				{{modalContent1.content}}
			</span>
		</u-modal>
	</view>
</template>

<script>
	let _this;
	import wInput from '../watch-login/watch-input.vue' //input
	import wButton from '../watch-login/watch-button.vue' //button

	export default {
		data() {
			return {
				//logo图片 base64
				//logoImage: 'data:image/png;base64,[encoded data, 23364 characters]',
				logoImage: '../../static/img/login/pns_app_icon.png',
				from: {
					"phonenumber": "", // 用户/电话
					"nickName": "", // 用户/电话
					"password": "", //密码
					"orgCode": "",
					// phonenumber: '15654542322', // 用户/电话
					// nickName: '测试', // 用户/电话
					// password: '123456', //密码
					// orgCode: 'G00000007'
				},
				verCode: "", //验证码
				showAgree: true, //协议是否选择
				isRotate: false, //是否加载旋转
				modalContent1: {
					show: false,
					title: '提示',
					content: ''
				},
			}
		},
		components: {
			wInput,
			wButton,
		},
		mounted() {
			_this = this;
		},
		methods: {
			isShowAgree() {
				//是否选择协议
				_this.showAgree = !_this.showAgree;
			},
			async submitUser() {
				const {
					data: res
				} = await this.$httpRequest({
					url: '/api/add',
					method: 'post',
					urlType: 1,
					data: this.from,
					isNotToken: true
				});
				if (res.code === 200) {
					this.confirmToLogin()
				} else {
					uni.showModal({
						title: '提示',
						content: res.msg,
						showCancel: false
					});
				}
			},
			confirmToLogin() {
				uni.reLaunch({
					url: 'login'
				})
			},
			startReg() {
				//注册
				if (this.isRotate) {
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.showAgree == false) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '请先同意《协议》'
					});
					return false;
				}
				if (this.from.nickName.length < 1) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '请填写姓名'
					});
					return false;
				}
				if (this.from.phonenumber.length != 11) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '请输入11位手机号'
					});
					return false;
				}
				if (!/^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(this.from.phonenumber)) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '请输入合法的手机号'
					});
					return false;
				}
				if (this.from.password.length < 6) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '密码至少6位数'
					});
					return false;
				}
				_this.isRotate = true
				this.submitUser()
				setTimeout(function() {
					_this.isRotate = false
				}, 1000)
			}
		}
	}
</script>

<style>
	@import url("../watch-login/css/icon.css");
	@import url("./css/main.css");
</style>
