<template>
	<view>
		<scroll-view scroll-y class="page">
			<cu-custom bgColor="bg-cyan"><block slot="content">登录</block></cu-custom>
			<view class="photoView">
				<view class="photoImage">
					<open-data type="userAvatarUrl"></open-data>
				</view>
			</view>
			<form action="">
				<view class="cu-form-group margin-top">
					<view class="title">账号</view>
					<input placeholder="请输入登录账号" name="account" value="xjwfy" @input="getAccount"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">密码</view>
					<input placeholder="请输入登录密码" name="password" type="password" value="xjwfy1126" @input="getPassword"></input>
				</view>
			</form>
			<view class="padding flex flex-direction" style="padding-top: 40%;">
				<button class="cu-btn round bg-cyan  margin-tb-sm lg" @click="buttonClick">登录</button>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: 'xjwfy',
				password: 'xjwfy1126'
			}
		},
		mounted() {
		},
		methods: {
			getAccount: function(e){
				this.account = e.target.value
			},
			getPassword: function(e){
				this.password = e.target.value
			},
			buttonClick(e) {
				let that = this;
				uni.showLoading({
					title: '页面跳转中',
					mask: true,
					success: function(res) {
						let new_that = that;
						uni.request({
							url: 'https://mwapi.opmonitor.com/?c=app_api&a=getConfigLogin',
							data: {
								account: new_that.account,
								password: new_that.password
							},
							header: {
								'Content-type': 'application/x-www-form-urlencoded'
							},
							method: 'POST',
							success: function(res){
								
								if(res.data.data === 'false'){
									uni.navigateTo({
										url: '/pages/plugin/loginError'
									})
								}else{
									if(res.data.data === 'success'){
										// 将这些变量放置globalData中
										getApp().globalData.account = new_that.account
										getApp().globalData.password = new_that.password
										uni.navigateTo({
											url: '/pages/index/index'
										})
									}
								}
							},
							fail: () => {
								console.info('小程序域名不正确，请检查域名正确性')
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	.page {
		width: 100vw;
		height: 120Vh;
	}
	.photoView {
		padding-top: 50rpx;
		position: relative;
		color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.photoImage {
		overflow:hidden;
		display: block;
		width: 200rpx;
		height: 200rpx;
		margin: 20rpx;
		border-radius: 50%;
		border: 2px solid #fff;
		box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
	}
	.cu-form-group .title{
		min-width: calc(4em + 15px);
		font-weight: 600;
	}
	.picker {
		text-align: left;
	}
</style>
