<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" input-type="number" v-model="reqData.mobile"></tm-input>
				<view class="mima">
					<tm-input name="title"  password v-model="reqData.password" placeholder="登录密码"></tm-input>
					<view class="wangji text-size-s" @click="zhaohui()">忘记密码？</view>
				</view>
				<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>
				<view class="px-24">
					<tm-button @click="tijiao()" theme="primary" :round="24" block class="mt-50 logincla">登录</tm-button>
					<tm-button @click="zhuce()" theme="primary" :round="24" block class="mt-30">注册新用户</tm-button>
				</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:'',
				password:'',
			}
		};
	},
	onLoad() {
		
	},
	created() {
		this.sys = uni.getSystemInfoSync();
	},
	methods: {
		xieyi(){
			uni.navigateTo({
				url: "/pages/xieyi/index",
			})
		},
		tijiao(){
			var that=this;
			if(that.reqData.mobile==""){
				that.$refs.toast.show({model:'warn',label:'请输入手机号'})
				return
			}else if(that.reqData.password==""){
				that.$refs.toast.show({model:'warn',label:'请输入密码'})
				return
			}else if(! that.checked){
				that.$refs.toast.show({model:'warn',label:'请勾选用户协议'})
				return
			}
			myRequest({
				url: "/api/login/login",
				method:'post',
				data:that.reqData
			}).then(res => {
				console.log(res.data)
				if (res.data.code == 200) {
					uni.setStorageSync("token",res.data.data.token)
					uni.setStorageSync("family_id",res.data.data.family_id)
					that.$refs.toast.show({model:'success',label:res.data.msg})
					setTimeout(function(){
						uni.switchTab({
							url: "/pages/index/index",
						})
					},2000)
				}else{
					that.$refs.toast.show({model:'error',label:res.data.msg})
				}
			})
			
		},
		zhuce(){
			uni.navigateTo({
				url: "/pages/registered/index",
			})
		},
		zhaohui(){
			uni.navigateTo({
				url: "/pages/zhaohui/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;
	}
	.zhuti{
		padding: 15px 30px 40px 30px;
	}
	.tel{
		margin-left: 5px;
	}
	.mima{
		position: relative;
	}
	.wangji{
		position: absolute;
		right: 0px;
		top: 0px;
		line-height: 50px;
		text-decoration:underline;
	}
	/deep/ .logincla .primary{
		background-color: #303440 !important;
	}
</style>
