<template>
	<view style="position: relative;">
		<view class="bg"></view>
		<view class="bg1"></view>
		<view class="content">
			<view class="top">
				<view class="logo">
					<image src="@/static/icon/logo.png" mode=""></image>
				</view>
			</view>
			
			<view  style="width: 76%;margin-top: 30rpx;">
				<u-form :model="form" :error-type="['message']"  ref="uForm">
					<u-form-item  label-position="top" label="账号" prop="phone" label-width="150">
						<u-input :border="false" placeholder="请输入账号" v-model="form.phone" type="number"></u-input>
					</u-form-item>
					<u-form-item   label-position="top" label="密码" prop="password" label-width="150">
						<u-input :border="false" placeholder="请输入登录密码" type="password" v-model="form.password"></u-input>
					</u-form-item>
				</u-form>
				<view  class="text-right margin-top-10 text-sm">
					<text @click="$jump('/pages/login/forget')" style="text-decoration: underline;">忘记密码</text>
					<text @click="$jump('/pages/login/login')" style="margin-left: 20rpx;text-decoration: underline;">手机号快捷登录</text>
				</view>
			</view>
			
			<view  style="width: 86%;margin-top: 120rpx;">
				<view @click="login" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 36rpx;">
					立即登录
				</view>
			
			</view>
		</view>
	</view>
</template>

<script>
	import md5Libs from "uview-ui/libs/function/md5";
	export default {
		data() {
			return {
				customStyle:{
					'backgroundColor':'#d18c42',
					'color':'#ffffff'
				},
				form:{
					phone:'',
					password:''
				},
				rules: {
					phone: [
						{ 
							required: true, 
							message: '请输入账号', 
							trigger: ['change','blur'],
						}
					],
					password: [
						{ 
							required: true, 
							message: '请输入密码', 
							trigger: ['change','blur'],
						}
					],
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad() {
			 if (this.$cache.get('phone')) {
			 	uni.reLaunch({
			 		url:"/pages/index/index"
			 	})
			 }
		},
		methods: {
			login() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$dialog.showLoading('登录中..')
						setTimeout(()=>{
							this.doLogin()
						},500)
					}
				});
			},
			async doLogin(){
				let params={
					type: "MALL",
					phone:this.form.phone,
					secret: md5Libs.md5(this.form.password)
				}
				try{
					let res=await this.$api.appaccount.login(params)
					this.$cache.put('phone',this.form.phone)
					uni.reLaunch({
						url:"/pages/index/index"
					})
				}catch(e){
					this.$u.toast('账号或者密码错误!')
				}finally{
					uni.hideLoading()
				}
			}
		}
	}
</script>

<style>
	page{
		background-color: #FFFFFF;
	}
</style>

<style lang="scss" scoped>
	$color:#d18c42;
	
	page{
		background-color: #FFFFFF;
	}
	
	.btn{
		background-color: $color;
		color:#FFFFFF;
	}
	
	.bg{
		z-index: 99;
		height: 440rpx;
		width: 440rpx;
		position: absolute;
		right: -240rpx;
		top: -240rpx;
		background-color: #d18c42;
		border-radius: 50%;
		box-shadow: 0rpx 0rpx 50rpx #c5803b;
	}
	
	.bg1{
		height: 500rpx;
		width: 500rpx;
		position: absolute;
		right: -240rpx;
		top: -240rpx;
		background-color: #d18c42;
		border-radius: 50%;
		box-shadow: #c6813b;
	}
	
	.content{
		height: 84vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		
		.top{
			display: flex;
			.logo{
				background-color: $color;
				width: 160rpx;
				height: 160rpx;
				border-radius: 40rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				
				image{
					width: 100rpx;
					height: 100rpx;
				}
			}
			
			.title{
				margin-right: 20rpx;
				display: flex;
				flex-direction: column;
				text-align: left;
				
				text:first-child{
					font-size: 46rpx;
					color: #000;
					margin-bottom: 20rpx;
				}
				
				text:last-child{
					font-size: 28rpx;
					color: #7f7f7f;
				}
			}
			
			
		}
	}
</style>
