<template>
	<view class="content">
		<view class="title-img">
			<image src="../../static/img/logo.png" mode=""></image>
		</view>
		<view class="title-LOGO">
			艺绘
		</view>
		<view class="bg">
			<image src="../../static/img/pbbg.png" mode=""></image>
		</view>

		<view class="register-content">
			<view class="res-box">
				<image src="../../static/img/pb03.png" mode=""></image>
				<input class="input" type="number" v-model="phone" placeholder="请输入手机号">
			</view>
			<view class="res-box">
				<image src="../../static/img/pb02.png" mode=""></image>
				<input class="input" type="password" v-model="loginPass" placeholder="请输入密码">
			</view>
			<!-- <view class="res-box">
				<image src="../../static/public/pb01.png" mode=""></image>
				<input class="input" type="number" v-model="code" placeholder="请输入验证码">
			</view> -->
		</view>
		<view class="button" @click="registerTo">
			登录
		</view>
		<view class="tishi">
			<view class="for-pass" @click="getNavto('/pages/set/changePass')">
				忘记密码
			</view>
			<view class="ss">

			</view>
			<view class="for-phone" @click="getNavto('/pages/public/register')">
				账号注册
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapMutations
	} from 'vuex';
	import {
		getUserInfo
	} from '@/api/user.js';
	import {
		register,
		verify,
		login
	} from '@/api/login.js';
	export default {
		data() {
			return {
				phone: '', //用户
				loginPass: '', //密码
				payPass: '',
				invitation: '', //邀请码
				code: '', //验证码
				time: '', //保存倒计时对象
				countDown: 0 //倒计时
			};
		},
		onLoad() {
			// 获取扫码邀请人id
			this.invitation = uni.getStorageSync('spread') || '';
		},
		// computed: {
		// 	...mapMutations('user', ['setUserInfo', 'login']),
		// },
		methods: {
			...mapMutations('user', ['setUserInfo', 'login']),
			//跳转详情
			getNavto(url) {
				uni.navigateTo({
					url: url
				})
			},
			//登录
			registerTo() {
				let obj = this
				let jiaoyan = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
				if (!jiaoyan.test(obj.phone)) {
					this.$api.msg('请输入正确的手机号!')
					return
				} else if (obj.phone == '') {
					this.$api.msg('请输入手机号')
					return
				} else if (obj.loginPass == '') {
					this.$api.msg('请输入密码')
					return
				} else {
					login({
						account: obj.phone,
						password: obj.loginPass

					}).then(res => {
						console.log(res, 'res');
						//传入账号密码之后,登录接口会返回给我一个登陆时间以及token,我把存到本地缓存里
						//然后获取用户信息接口,缓存接口给我的data,然后跳转至首页即可
						uni.setStorageSync('token', res.data.token)
						getUserInfo({}).then(res => {
							
							// console.log(res, 'res');
							obj.login(); //确认登录状态
							console.log(obj.login);
							console.log('18252757278','w');
							//用户数据获取到的用户信息存储到本地里
							obj.setUserInfo(res.data);
							let ur = uni.getStorageSync('present') || '/pages/index/index';
							uni.switchTab({
								url: '/pages/index/index',
								fail(e) {
									uni.navigateTo({
										url: ur,
										fail(e) {
											uni.navigateTo({
												url: '/pages/index/index',
											});
										}
									});
								}
							})
						})

					}).catch(function(e) {
						console.log(e);
					});
				}
			},


		}
	};
</script>

<style lang="scss">
	page,
	.content {
		min-height: 100%;
		background-color: #181818;

		.bg {
			width: 750rpx;
			height: 200rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.title-img {
			margin: 70rpx auto 0;
			width: 161px;
			height: 161px;
			border-radius: 50%;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.title-LOGO {
			text-align: center;
			margin: 30rpx;
			font-size: 36px;
			font-family: PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
		}

		.register-content {
			.res-box {
				height: 110rpx;
				align-items: center;
				display: flex;
				margin: 0 75rpx;
				border-bottom: #f3f3f3 solid 2rpx;

				image {
					width: 31rpx;
					height: 40rpx;
				}

				.input {
					flex-grow: 1;
					color: #9F570E;
					margin-left: 40rpx;
				}
			}
		}

		.button {
			margin: 40rpx auto;
			text-align: center;
			width: 452rpx;
			height: 90rpx;
			background: $bgBaseBg;
			border-radius: 45rpx;
			font-size: 34rpx;
			font-weight: 500;
			color: #9F570E;
			line-height: 90rpx;
		}

		.tishi {
			display: flex;
			align-items: center;
			justify-content: center;


			.for-pass {
				font-size: 28rpx;
				font-weight: 500;
				color: #FFFFFF;
			}

			.ss {
				height: 26rpx;
				width: 3rpx;
				background-color: #f3f3f3;
				margin: 0 10rpx;
			}

			.for-phone {
				font-size: 28rpx;
				font-weight: 500;
				color: #FFFFFF;
			}

		}
	}
</style>
