<template>
	<view class="container">
		
		<view class="content">
			<view class="topTitle">警地融合</view>
			<view class="top">
				<u--form labelWidth="120"
						labelPosition="top"
						:model="loginInfo"
						:rules="rules"
						ref="uForm">
				<view class="cell">
					<u-form-item
						label="用户名"
						prop="name"
						ref="item1">
						<u--input
								v-model="loginInfo.name"
								border="surround"
						></u--input>
					</u-form-item>
				</view>
				
				<!--<view class="cell">
					<u-form-item
						label="密码"
						prop="password"
						ref="item1">
						<u--input
								v-model="loginInfo.password"
								border="surround"
						></u--input>
					</u-form-item>
				</view>-->
				</u--form>
				
				
				<view class="agree">
					登录即代表同意
					<text class="a">《用户协议》</text>
					和
					<text class="a">《隐私政策》</text>
				</view> 
				<button class="submit" @click="submit" :disabled="disabled">登录</button>
				<view class="tip">未注册用户验证后将自动注册并登录</view>
			</view>

		
		</view>
		<!--  -->
	</view>
</template>

<script>
import sm2 from '@/utils/sm2.js'
import {publicKey} from '@/common/setting'
import {wxlogin} from "@/api/user.js"
export default {
	onLoad(option) {
		const { redirect } = option
		if (redirect) this.redirect = redirect
	},
	data() {
		return {
			tenantId: '000000',
			username: 'admin',
			password: 'admin',
			disabled: false,
			redirect: '',
			loginInfo:{
				name:'',
				password:'',
			},
			rules:{
				'name':{
					type: 'string',
					required: true,
					message: '请填写用户名',
					trigger: ['blur', 'change']
				},
			
			},
		}
	},
	onLoad(option) {
		const { redirect } = option
		if (redirect) this.redirect = redirect
		var _this = this;	
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
	    	this.$refs.uForm.setRules(this.rules)
	},
	
	methods: {
		submit() {
			this.$refs.uForm.validate().then(res => {
				uni.showLoading({
					title: '加载中'
				});
				uni.login({
				  provider: 'weixin',
				  success: (loginRes) => {
					  // 登录成功，获取用户code
					  const { code } = loginRes;
					  this.$u.api.wxlogin({account:this.loginInfo.name,code:code})
						.then(data => {
							this.$u.func.login(data.data, this.redirect)
							uni.hideLoading()
						})
						.catch(err => {
							console.log(err)
							this.$u.func.showToast({ title: '用户名或密码错误' })
							uni.hideLoading()
						})
				  },
				})
			}).catch(errors => {
				
			})
			
		
			
		},
		handleInputCheck() {
			this.disabled = false
		}
	}
}
</script>

<style lang="scss">
.container {
	min-height: 100vh;
	overflow: hidden;
	.topTitle{
		text-align: center;
		font-size: 1.2rem;
		font-weight: bold;
		padding:60rpx 0;
		color: #0d0d0d;
		position: relative;
		z-index: 9;
		}
		.bg{
			position: absolute;
			background: url('data:image/png;base64,[encoded data, 61464 characters]') 0 0 no-repeat;
			width: 100%;
			background-size: 100%;
			height: calc((100vw / 375) * 480);
			left:0;
			top: 0;
			z-index: 0;
		}
	.set-icon {
		vertical-align: middle;
		width: 41rpx;
		height: auto;
		margin-right: 35rpx;
	}
}

.content {
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	align-items: center;
	position: relative;
	z-index: 1;
	width: 100%;
    padding-top: 150rpx;
	box-sizing: border-box;
	.top {
		width: 100%;
	}

	.logo {
		display: block;
		width: 281rpx;
		height: auto;
		margin: 0 auto 60rpx;
	}

	.cell {
		width: 100%;
		padding: 0 85rpx;
		box-sizing: border-box;
		margin-top: 36rpx;

		.name {
			font-size: 22rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #3e4a59;
			line-height: 30rpx;
			opacity: 0.72;
		}

		.input-box {
			padding: 30rpx 0;
			//border-bottom: 2rpx solid #f6f6f6;
			display: flex;
			align-items: center;

			.code {
				font-size: 22rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #0d0d0d;
				line-height: 30rpx;

				text {
					// color: #14b9c8;
					color: #5f88ff;
				}
			}

			.ipt {
				flex: 1;
				// height: 24rpx;
				font-size: 24rpx;
			}

			.hold {
				font-size: 26rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #3e4a59;
				line-height: 30px;
				opacity: 0.45;
			}
		}
	}

	.agree {
		margin: 27rpx 95rpx 0;
		font-size: 22rpx;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		color: #cacaca;
		line-height: 34rpx;

		.a {
			color: #000000;
		}
	}

	.submit {
		margin: 60rpx 90rpx 0;
		border: none;
		width: 572rpx;
		height: 86rpx;
		line-height: 86rpx;
		box-sizing: border-box;
		border-radius: 15rpx;
		background-color: #5f88ff;
		color: #ffffff;

		&::after {
			content: none;
		}

		&::before {
			content: none;
		}

		&[disabled='true'] {
			background: #e4e4e4;
			font-size: 36rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #ffffff;
		}
	}

	.tip {
		margin-top: 30rpx;
		text-align: center;
		font-size: 22rpx;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		color: #cacaca;
		line-height: 34rpx;
	}

	.change {
		margin-top: 20rpx;
		text-align: center;
		font-size: 22rpx;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		// color: #14b9c8;
		color: #5f88ff;
		line-height: 34rpx;
	}

	.tag {
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 22rpx;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		color: #9f9f9f;
		line-height: 34rpx;

		&::before {
			content: '';
			display: block;
			width: 160rpx;
			height: 1px;
			background: #d8d8d8;
			opacity: 0.86;
		}

		&::after {
			content: '';
			display: block;
			width: 160rpx;
			height: 1px;
			background: #d8d8d8;
			opacity: 0.86;
		}
	}

	.chat-arr {
		margin-top: 50rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.icon {
			width: 73rpx;
			height: 73rpx;
		}
	}
}
</style>
