<template>
	<div class="content">
		<img class="loginimg" src="../assets/images/login.png" alt="">
		<div class="login">
			<div class="item">
				<van-cell-group>
					<van-field v-model="name" placeholder="请输入登录名" />
				</van-cell-group>
			</div>
			<div class="item">
				<van-cell-group>
					<van-field v-model="password" type="password" placeholder="请输入密码" />
				</van-cell-group>
			</div>
			<!-- <div class="item">
				<van-cell-group>
			       <van-field v-model="yzm" type="number"  placeholder="请输入验证码" />
			    </van-cell-group>
			</div> -->
			<div class="btn">
				<van-button type="primary" color="#00c4b8" @click="login">登录</van-button>
			</div>
			<!-- <div class="register">
				<router-link to="">新用户注册</router-link>
				<router-link to="">忘记密码</router-link>
			</div> -->
			<div style="font-size: 10px;text-align: center;padding-top: 1.625rem;">
				<a style="color: black" href="https://beian.miit.gov.cn">沪ICP备2021029008号-1</a>
			</div>
		</div>
	</div>
</template>


<script>
import { Toast, Dialog, Loading } from 'vant'
import { solicLogin } from '../api/index'
export default {
	data() {
		return {
			name: "",
			password: "",
			yzm: ""
		}
	},
	created: function () {

	},
	methods: {
		//登录
		async login() {
			if (this.name == '' || this.name == undefined) {
				Toast('请输入登录名');
				return;
			}
			if (this.password == '' || this.password == undefined) {
				Toast('请输入登录名');
				return;
			}
			// this.$http.post(this.$store.state.host+"/appSysUser/solic_login",{USERNAME:this.name,PASSWORD:this.password},{emulateJSON:true})
			const res = await solicLogin({ USERNAME: this.name, PASSWORD: this.password }, { emulateJSON: true, loading: true, message: '登录中...' })
			console.log(res, 'res')

			if (res.result == 'success') {
				//localStorage
				localStorage.setItem("courierUserId", res.userId);
				localStorage.setItem("roomId", res.roomId);
				localStorage.setItem("courierId", res.userId);
				this.$router.push({ path: '/' });
				window.location.reload()
			} else {
				Toast(res.message);
			}

			//发送失败
			// Toast("登录失败!")

		}
	}
}
</script>
<style scoped lang="less">
.content {
	height: 100vh;

	.loginimg {
		width: 3.48rem;
		margin: 0 auto;
		display: block;
		padding: 2.15rem .8rem;
	}

	.login {
		width: 5.8rem;
		margin: 0 auto;

		.item {
			border: .01rem solid #bfbfbf;
			border-radius: .1rem;
			margin-bottom: .5rem;
			background: white;
			overflow: hidden;
			color: #999999;
		}

		.item:nth-of-type(3) {
			margin-bottom: .2rem;
		}

		.btn {
			button {
				width: 100%;
			}
		}

		.register {
			font-size: .24rem;
			display: flex;
			justify-content: space-between;
			margin-top: .2rem;

			a {
				color: #999999;
			}

			a:nth-of-type(1) {
				color: #02bfb3;
			}
		}
	}
}
</style>
