<template>
	<view :style="{ minHeight: sys.windowHeight + 'px' }"
		:class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
		<tm-menubars title="" :shadow="0" :showback="false"></tm-menubars>
		<view class="tou C1b1b1b">新用户注册</view>
		<view class="zhuti">
			<tm-form>
				<view class="tel text-size-m mt-50">请输入注册手机号码</view>
				<tm-input name="title" v-model="reqData.mobile"></tm-input>
				<view class="mima">
					<tm-input placeholder="请输入短信验证码" name="title" v-model="reqData.sms_code"></tm-input>
					<tm-button class="wangji" @click="sendyzm" size="m">{{yzmvar.text}}</tm-button>
				</view>
				<tm-input name="title" placeholder="请设置6-20位登录密码" password v-model="reqData.password"></tm-input>
				<tm-input name="title" placeholder="请再次确认登录密码" password v-model="reqData.password1"></tm-input>
				<view class="px-24">
					<view class="py-10 text-size-s mt-30">
						<tm-checkbox :size="32" color="bg-gradient-primary-accent" v-model="checked" round="rounded"></tm-checkbox>
						<text class="text-white" @click="xieyi()" style="vertical-align: middle;">阅读并同意《用户协议》</text>
					</view>
					<tm-button @click="tijiao()" theme="primary" :round="24" class="mt-50" block>注册</tm-button>
					<view class="py-10 text-size-s text-grey text-align-center mt-30">
						<text class="text-white text-size-s text-align-center" @click="login()">已有账户，立即登录</text>
					</view>
				</view>
			</tm-form>
		</view>
		<!-- 弹出层消息 -->
		<tm-message ref="toast"></tm-message>
	</view>
</template>	
<script>
import{myRequest} from '@/api/request.js'
export default {
	data() {
		return {
			checked:false,
			reqData:{
				mobile:'',
				sms_code:'',
				password:'',
				password1:''
			},
			yzmvar:{
				text:'发送验证码'
			}
		};
	},
	onLoad() {
		
	},
	created() {
		this.sys = uni.getSystemInfoSync();
	},
	methods: {
		tijiao(){
			var that=this;
			if(that.reqData.mobile==""){
				that.$refs.toast.show({model:'warn',label:'请输入手机号'})
				return
			}else if(that.reqData.sms_code==""){
				that.$refs.toast.show({model:'warn',label:'请输入验证码'})
				return
			}else if(that.reqData.password=="" || that.reqData.password.length<6 ||that.reqData.password.length>20){
				that.$refs.toast.show({model:'warn',label:'请设置6-20位登录密码'})
				return
			}else if(that.reqData.password1==""){
				that.$refs.toast.show({model:'warn',label:'请再次确认登录密码'})
				return
			}else if(that.reqData.password != that.reqData.password1){
				that.$refs.toast.show({model:'warn',label:'密码不一致'})
				return
			}else if(! that.checked){
				that.$refs.toast.show({model:'warn',label:'请勾选用户协议'})
				return
			}
			myRequest({
				url: "/api/login/register",
				method:'post',
				data:that.reqData
			}).then(res => {
				console.log(res)
				if (res.data.code == 200) {
					that.$refs.toast.show({model:'success',label:res.data.msg})
					setTimeout(function(){
						uni.navigateTo({
							url: "/pages/login/index",
						})
					},2000)
				}else{
					that.$refs.toast.show({model:'error',label:res.data.msg})
				}
			})
			
		},
		sendyzm(){
			var that=this;
			if(that.reqData.mobile==""){
				that.$refs.toast.show({model:'warn',label:'请输入手机号'})
				return
			}
			that.yzmvar.text="已发送";
			setTimeout(function(){
				that.yzmvar.text="发送验证码";
			},15000)
		},
		login(){
			uni.navigateTo({
				url: "/pages/login/index",
			})
		},
		xieyi(){
			uni.navigateTo({
				url: "/pages/xieyi/index",
			})
		}
	}
}
</script>

<style lang="scss">
	/deep/ .tm-menubars .body{
		background-color: #1b1b1b !important;
	}
	/deep/ .grey-darken-5{
		background-color: #0d0d0d!important;
		padding: 0px !important;
	}
	.tou{
		font-size: 28px;
		padding: 15px 30px 40px 30px;
	}
	.tel{
		margin-left: 5px;
	}
	.zhuti{
		padding: 15px 30px 40px 30px;
	}
	.mima{
		position: relative;
	}
	.wangji{
		position: absolute;
		right: 0px;
		top: 3px;
	}
	/deep/ .wangji .primary{
		background-color: #303440 !important;
	}
	
</style>
