<template>
	<view class="content">
		<view class="topbg">
			<view class="ts">
				<view class="mb-5">欢迎登录</view>
				<view>沪抖团线上展厅</view>
			</view>
		</view>

		<view class="edit">
			<view class="logo">
				<image src="../../static/logo.png"></image>
				沪抖团
			</view>

			<view class="editem">
				<view class="input">
					<icon class="iconfont icon-gerenzhongxin1 mr-10"></icon>
					<input class="uni-input input100" v-model="account" placeholder="请输入账号" />
				</view>
				<view class="input">
					<icon class="iconfont icon-icon-test5 mr-10"></icon>
					<input type="password" class="uni-input" v-model="password" placeholder="请输入密码" />
				</view>
				<view class="tips size12" @click="$store.commit('changeSecratary', true)">
					忘记密码联系管理员
				</view>
			</view>
			<view class="btnlogin" @click="handleTelLogin">登录</view>
			<view class="wxbtn" @click="handleAdd">
				<text>注册</text>
			</view>
			<view class="xieyi">
				<checkbox-group @change="checkboxChange">
					<checkbox :value="1" style="transform:scale(0.8)" />勾选同意沪抖团<text @click="handlexieyi "
						class="bluecolor">《个人信息保护政策》</text>
				</checkbox-group>
			</view>
		</view>
		<!-- 联系人弹框 -->
		<secratary></secratary>

	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	export default {
		data() {
			return {
				value: 0,
				account: "",
				password: "",
				sessionid: ""
			}
		},
		computed: {
			...mapState(["HomeContent"]),
		},
		async onLoad() {
			let that = this
			that.login()
		},
		methods: {
			login() {
				let that = this
				uni.login({
					success(res2) {
						if (res2.code) {
							if (res2.errMsg = "login:ok") {
								that.$model.onlogin({
									code: res2.code,
								}).then(res => {
									console.log("11111", res)
									if (res.code == 2) {
										that.token = null
										that.sessionid = res.data.sessionid
										uni.setStorageSync('sessionid', res.data.sessionid)
										return
									}
								}).catch(e => {})
							}
						}
					}
				})
			},
			// 登录、
			handleTelLogin() {
				let that = this
				if (!that.account) {
					that.$tools.msg("请输入账号")
					return
				}
				if (!that.password) {
					that.$tools.msg("请输入密码")
					return
				}
				if (that.password.length < 6) {
					that.$tools.msg("密码长度不能小于6位数")
					return
				}
				if (this.value == 0) {
					this.$tools.msg("请先勾选同意沪抖团《个人信息保护政策》")
					return
				}
				this.$model.getlogin({
					account: that.account,
					password: that.password,
					sessionid: that.sessionid,
				}).then(res => {
					if (res.code != 0) {
						that.$tools.msg(res.message)
						return
					}
					uni.setStorageSync('token', res.data.token)
					uni.setStorageSync('refreshtoken', res.data.refreshtoken)
					uni.setStorageSync('sessionid', res.data.sessionid)
					uni.reLaunch({
						url: "/pages/index/index"
					})
				}).catch(err => {})
			},
			// 
			handleAdd() {
				uni.navigateTo({
					url: "/pageTwo/login/add"
				})
			},
			checkboxChange(e) {
				this.value = e.detail.value.length ? e.detail.value[0] : "0"
				console.log(e.detail, e.detail.value)
			},
			handlexieyi() {
				uni.navigateTo({
					url: "/pageTwo/index/detail?content=1"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		// display: flex;
		overflow: hidden;
		flex-wrap: wrap;
		padding: 0 !important;
		justify-content: space-between;
	}

	.topbg {
		width: 126%;
		position: relative;
		height: 140px;
		left: -13%;
		background: $navColor;
		border-radius: 0 0 60% 60%;

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

		.ts {
			font-size: 20px;
			font-weight: bold;
			text-align: left;
			color: #fff;
			z-index: 9;
			position: absolute;
			bottom: 50px;
			left: 15%;
		}
	}



	.edit {
		margin: 40rpx auto 0;
		width: calc(82% - 30px);
		position: relative;
		background: #fff;
		border-radius: 10px;
		padding: 15px;
		text-align: center;
		background-color: #fff;
		max-height: 780rpx;

		.logo {
			width: 100%;
			height: 55px;
			margin-top: 15px;
			color: #000;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 22px;
			font-weight: bold;

			image {
				width: 53px;
				height: 53px;
				margin-right: 10px;
			}
		}

		.tips {
			width: 100%;
			text-align: right;
		}

		.editem {
			margin-top: 28px;
			display: flex;
			align-items: center;
			font-size: 28upx;
			justify-content: space-between;
			flex-wrap: wrap;
		}

		.input {
			width: 100%;
			padding: 0 10px;
			height: 40px;
			line-height: 40px;
			margin-bottom: 15px;
			display: flex;
			position: relative;
			text-align: left;
			background-color: #f7f7f7;
			border-radius: 5px;

			icon {
				color: #666;
				font-size: 22px;
			}

			input {
				height: 40px;
				line-height: 40px;
				position: absolute;
				left: 35px;
				right: 0px;
				z-index: 88;
			}
		}

		.btnlogin {
			width: 100%;
			margin: 40rpx 0 20px;
			height: 38px;
			line-height: 38px;
			background: $blue;
			font-weight: 700;
			border-radius: 10px;
			text-align: center;
			color: #fff !important;
		}

		.code {
			width: 110px;
			background: #dfdfdf;
			font-size: 12px;
			margin: 0;
			border-radius: 10px;
			text-align: center;
			position: absolute;
			right: 2.5px;
			top: 2.5px;
			z-index: 99;
		}
	}

	.wxbtn {
		width: 100%;
		text-align: center;
		color: $blue;
		display: flex;
		align-items: flex-end;
		justify-content: center;

		text {
			border-bottom: 1px solid $blue;
		}
	}

	.xieyi {
		font-size: 12px;
		color: #333;
		width: 100%;
		text-align: center;
		display: flex;
		align-items: flex-end;
		margin-top: 40rpx;

		checkbox-group {
			text-align: left;
		}

		text {
			border-bottom: 1px solid #333;
		}
	}
</style>