<template>
	<view :style="{ minHeight: sys.windowHeight + 'px' }"
		:class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
		<tm-menubars title="" :shadow="0" :showback="false"></tm-menubars>
		<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" :password="! on" title="登录密码" v-model="reqData.password"></tm-input>
						<view>
							<tm-switch v-model="on" :text="['','...']"></tm-switch>
						</view>
					</view>
					<view class="px-24">
						<tm-button @click="tijiao()" theme="bg-gradient-blue-accent" block>登陆</tm-button>
						<tm-row class="mt-40 mb-20">
							<tm-col color="text-size-xs" :grid="6">
								<view class="py-10"><text class="text-primary text-size-s text-align-center" @click="zhuce()">注册新用户</text></view>
							</tm-col>
							<tm-col color="text-size-xs" :grid="6">
								<view class="py-10"><text class="text-primary text-size-s text-align-center" @click="zhaohui()">找回密码</text></view>
							</tm-col>
						</tm-row>
					</view>
				</tm-form>
			</view>
		</tm-sheet>
	</view>
</template>	
<script>
import{myRequest} from '@/api/request.js'
export default {
	data() {
		return {
			on:false,
			reqData:{
				mobile:'',
				password:'',
			}
		};
	},
	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.password==""){
				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)
					that.$refs.toast.show({model:'success',label:res.data.msg})
					setTimeout(function(){
						uni.navigateTo({
							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",
			})
		},
		login(){
			uni.navigateTo({
				url: "/pages/login/index",
			})
		}
	}
}
</script>

<style lang="scss">
	/deep/ .tm-menubars .body{
		background-color: #1b1b1b !important;
	}
</style>
