<template>
	<view class="container">
		<uni-nav-bar dark left-icon="left" backgroundColor="#48b1f8" left-text="关闭" @clickLeft="toBack">
			<view style="width: 100%;display: flex;flex-direction: row;justify-content: center;align-items: center;">
				<text style="color: white;font-size: 1rem;">注册登录</text>
			</view>
		</uni-nav-bar>
		<view class="content">
			<view class="top">
				<!-- <image src="/static/images/logo_start.png" class="logo" mode="widthFix"></image> -->
				<!-- 				<view
					style="width: 100%;margin-bottom: 80rpx;display: flex;flex-direction: column;align-items: center;">
					
					<text style="font-size: 1.5rem;margin-top: 5rpx;">
						大恒巡检保养工单系统
					</text>
				</view> -->
				<view>
					<uni-row>
						<uni-col :span="12">
							<view class="view-flex-inline" style="padding-left: 85rpx;font-size: 1rem;">帐号登录</view>
						</uni-col>
						<uni-col :span="12">
							<view class="view-flex-inline-end"
								style="padding-right: 85rpx;font-size: 0.6rem;color: royalblue;" @click="userRegClick">
								注册</view>
						</uni-col>
					</uni-row>
				</view>
				<view class="cell">
					<view class="input-box">
						<uIcons type="auth" size="30"></uIcons>
						<input type="text" v-model="username" placeholder="请输入手机号" class="ipt" placeholder-class="hold"
							@blur="handleInputCheck" />
					</view>
				</view>
				<view class="cell">
					<view class="input-box">
						<uIcons type="locked" size="30"></uIcons>
						<input type="password" v-model="password" placeholder="请输入登录密码" class="ipt"
							placeholder-class="hold" @blur="handleInputCheck" />
					</view>
				</view>

				<!-- <view class="tip">未注册用户验证后将自动注册并登录</view> -->
				<view class="cell">
					<view
						style="margin-top: 30rpx;margin-right:24rpx;display: flex;justify-content: flex-end;flex-direction:row;">
						<checkbox-group @change="checkboxChange">
							<label style="font-size: 24rpx;">
								<checkbox value="rememberPw" :checked="rememberPw" />记住密码
							</label>
						</checkbox-group>
					</view>
				</view>
				<view class="agree">
					登录即代表同意
					<text class="a">《用户协议》</text>
					和
					<text class="a">《隐私政策》</text>
				</view>
				<view class="cell">
					<button class="submit" @click="submit" :disabled="disabled">登录</button>
				</view>
				<!-- <navigator url="/pages/login/login-phone" hover-class="none" class="change">手机登录 ></navigator> -->
			</view>

			<!-- 社交账号登录 -->
			<!-- 			<view class="bottom">
				<view class="tag">社交账号登录</view>
				<view class="chat-arr">
					<image src="/static/images/wx.png" class="icon" mode=""></image>
					<image src="/static/images/qq.png" class="icon" mode=""></image>
					<image src="/static/images/wb.png" class="icon" mode=""></image>
				</view>
			</view> -->
		</view>
		<!--  -->
	</view>
</template>

<script>
	import md5 from '@/utils/md5.js'
	import uIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue'
	import {
		tenantId
	} from '@/common/setting.js'
	import {
		devUrl,
		prodUrl,
		contentType
	} from '@/common/setting'
	export default {
		components: {
			uIcons,
		},
		data() {
			return {
				// tenantId: '000000',
				username: '',
				password: '',
				disabled: true,
				rememberPw: false,
				skipPage: 1,
				toUrl: '',
			};
		},
		onLoad(options) {

			this.skipPage = options.skipPage;
			this.toUrl = options.toUrl;
			console.log("url" + this.toUrl)
			// uni.getPushClientId({
			// 		success: (res) => {
			// 			console.log("id11111111111 "+res.cid);
			// 		},
			// 		fail(err) {
			// 			console.log(err)
			// 		}
			// 	})
			// uni.getLocation({
			// 	type: 'gcj02',
			// 	geocode: true,
			// 	success: function (res) {
			// 		console.log('当前位置：' + JSON.stringify(res));
			// 	}
			// });

			let userLoginInfo = uni.getStorageSync("userLoginInfo");
			// console.log(JSON.stringify(userLoginInfo))
			if (userLoginInfo) {
				this.rememberPw = true;
				this.disabled = false;
				this.username = userLoginInfo.username;
				this.password = userLoginInfo.pw;
			}
		},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: Number(this.skipPage)
				})
			},
			submit() {
				this.$u.api.token(tenantId, this.username, md5(this.password)).then(data => {
					console.log("token " + JSON.stringify(data))
					let dt = new Date();
					uni.setStorageSync("loginTime", dt.getTime());
					if (this.rememberPw) {
						uni.setStorageSync("userLoginInfo", {
							username: this.username,
							pw: this.password,
						});
					} else {
						uni.removeStorageSync("userLoginInfo");
					}
					this.$u.func.login(data)

					if (this.toUrl) {
						let url = decodeURIComponent(this.toUrl);
						uni.redirectTo({
							url: url
						})
					} else {
						uni.navigateBack({
							delta: 1
						})
					}
				}).catch(err => {
					console.log(err)
					this.$u.func.showToast({
						title: '用户名或密码错误' + err,
					})
				})
			},
			handleInputCheck() {
				this.disabled = false
			},
			checkboxChange: function(e) {
				let values = e.detail.value;
				if (values.length > 0) {
					this.rememberPw = true;
				} else {
					this.rememberPw = false;
				}
			},
			userRegClick() {
				var url = '/pages/login/login-register';
				uni.navigateTo({
					url: url
				})
			}
		}
	};
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		overflow: hidden;

		.set-icon {
			vertical-align: middle;
			width: 41rpx;
			height: auto;
			margin-right: 35rpx;
		}
	}

	.content {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 90vh;
		width: 100%;

		.top {
			width: 100%;
		}

		.logo {
			display: block;
			width: 160rpx;
			height: auto;
			margin: 0 auto 40rpx;
		}

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

			.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;
					}
				}

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

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

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

			.a {
				color: blue;
			}
		}

		.submit {
			margin-top: 40rpx;
			border: none;
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			box-sizing: border-box;
			border-radius: 15rpx;
			background: linear-gradient(to right, #48b1f8, #3976f7);
			color: #ffffff;

			&::after {
				content: none;
			}

			&::before {
				content: none;
			}

			&[disabled='true'] {
				background: linear-gradient(to right, #48b1f8, #3976f7);
				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;
			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>