<template>
	<view >
		<tm-message ref="toast"></tm-message>
		<tm-sheet :shadow="24" :padding="[12,24]" :margin="[24,24]">
			<view>
				<tm-form>
					<tm-input name="title" title="手机号" v-model="reqData.mobile"></tm-input>
					<view class="flex-between" :class="$tm.vx.state().tmVuetify.black ? 'bk' : ''">
						<tm-input name="title" title="验证码" v-model="reqData.sms_code"></tm-input>
						<view>
							<tm-button @click="sendyzm" :theme="yzmvar.colorvar" size="m">{{yzmvar.text}}</tm-button>
						</view>
					</view>
					<tm-input name="title" password title="密码" v-model="reqData.password"></tm-input>
					<tm-input name="title" password title="确认密码" v-model="reqData.password1"></tm-input>
					<view class="px-24">
						<view class="py-10 text-size-s text-grey text-align-left">
							<tm-checkbox :size="32" color="bg-gradient-primary-accent" v-model="checked" round="rounded"></tm-checkbox>同意<text class="text-primary" @click="xieyi()">《用户服务协议》</text></view>
						<tm-button @click="tijiao()" theme="bg-gradient-blue-accent" block>注册</tm-button>
						<view class="py-10 text-size-s text-grey text-align-center ma-10">
							<text class="text-primary text-size-s text-align-center" @click="login()">已有账号，立即登录</text>
						</view>
					</view>
				</tm-form>
			</view>
		</tm-sheet>
	</view>
</template>	
<script>
import{myRequest} from '@/api/request.js'
export default {
	data() {
		return {
			checked:false,
			reqData:{
				mobile:'',
				sms_code:'',
				password:'',
				password1:''
			},
			yzmvar:{
				colorvar:'primary',
				text:'发送验证码'
			}
		};
	},
	onLoad() {
		
	},
	created() {
		
	},
	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.$refs.toast.show({model:'warn',label:'请输入密码'})
				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.colorvar="gray";
			that.yzmvar.text="已发送";
			setTimeout(function(){
				that.yzmvar.colorvar="primary";
				that.yzmvar.text="发送验证码";
			},5000)
		},
		login(){
			uni.navigateTo({
				url: "/pages/login/index",
			})
		},
		xieyi(){
			uni.navigateTo({
				url: "/pages/xieyi/index",
			})
		}
	}
}
</script>

<style lang="scss">

</style>
