<template>
	<view class="border-box">
		<view class="content x-c">
			<!-- <image class="backImg" @tap="goBack()" src="../../static/images/icon_close.png"></image> -->
			<view class="pageTop x-c">
				<view class="loginBox">
					<view class="logo">
						<image src="/static/logo_icon2.png"></image>
					</view>
					<view class="head-title">御君方门店系统</view>
					<view class="login-item">
						<view class="input-account" :class="{'input-active': accountActive }">
							<input v-model="account" placeholder="账号" type="text" @focus="changeText('accountActive',true)"  @blur="changeText('accountActive',false)"/>
						</view>
					</view>
					<view class="login-item">
						<view class="input-pwd" :class="{'input-active': pwdActive }">
							<input v-model="password" placeholder="密码" ref="input" type="text" :password="isClose" @focus="changeText('pwdActive',true)" @blur="changeText('pwdActive',false)"/>
							<view class="close-pwd" @click="closePwd">
								<image :src="isClose?'/static/image/device/eye_close_icon36.png':'/static/image/device/eye_open_icon36.png'"></image>
							</view>
						</view>
					</view>
					<view class="login-item flexCenter">
						<view class="input-code" :class="{ 'input-active': codeActive }">
							<input v-model="code" placeholder="验证码" type="text" @focus="changeText('codeActive',true)" @blur="changeText('codeActive',false)"/>
						</view>
						<view class="input-yzcode">
							<image :src="codeImg" @click="getCode"></image>
						</view>
					</view>
					<view class="checkbox">
						<!-- 	<view class="checkbox-icon" @tap="handleAgree">
							 		<image src="../../static/image/login/radio_default.png" v-show="!agree"></image>
							 		<image src="../../static/image/login/radio_choose.png" v-show="agree"></image>
							 	</view>
							 	<view>记住密码</view> -->
						<checkbox-group @tap="handlePwd">
							<label>
								<checkbox borderColor="#E0E3EE" iconColor="#8F6726" v-model="agree" :checked="agree" />
								记住密码
							</label>
						</checkbox-group>
					</view>

					<view class="btns">
						<view class="login-btn" @click="login">登录</view>
					</view>
				</view>
			</view>
			
			<!-- <view class="pageBottom" v-if="isApp && isAgreePrivacy">
					<view class="tips y-f"> — 快捷登录 — </view> 
					<view class="menu x-ac">
						 <view v-if="wxIsInstalled" @tap="loginWeixin" ><image src="/static/image/login/weixin.png"></image></view>
						 <view v-if="isIos" @tap="quickAppleLogin" ><image src="/static/image/login/apple.png"></image></view>
					<view><image src="/static/image/login/qq.png"></image></view>
						 <view><image src="/static/image/login/weibo.png"></image></view> 
				   </view>		
			</view> -->

			<!-- <view class="checkbox">
				<view class="checkbox-icon" @tap="handleAgree">
					<image src="../../static/image/login/radio_default.png" v-show="!agree"></image>
					<image src="../../static/image/login/radio_choose.png" v-show="agree"></image>
				</view>
				<view>我已阅读并同意<text @tap="goToWeb(0)">《用户协议》</text><text @tap="goToWeb(1)">《隐私政策》</text> 并使用本机号码登录</view>
			</view> -->
		</view>
	</view>
</template>

<script>
import { login, loginByWeChat, getUserInfo, loginByApple, setPhone, getCode } from '@/api/user';
export default {
	data() {
		return {
			isClose:true,
			userName: '测试企业',
			account: '测试企业',
			password: 'admin1122..',
			registrationID: '',
			unionid: '',
			userPhone: '',
			loginType: 0,
			isApp: false,
			agree: false,
			isAgreePrivacy: false,
			isIos: false,
			from: '',
			source: '',
			appleKey: '',
			wxIsInstalled: false,
			code: '',
			codeImg: '',
			uuid: '',
			 // 激活状态变量
			accountActive: false,
			pwdActive: false,
			codeActive: false
		};
	},
	onLoad(option) {
		var token=uni.getStorageSync('AppToken');
		if(token){
			var user=JSON.parse(uni.getStorageSync('userInfo'));
			this.account=user.userName
			this.password=uni.getStorageSync('password');
		}
		
		
	},
	onShow() {
		this.getCode();
		
	},
	onUnload() {
		uni.$off('getRegistrationID');

    },
    mounted() {
       
    },
    methods: {
		getCode(){
			getCode().then(res => {
				console.log('code')
					uni.hideLoading();
					if(res.code==200){
						// console.log('code',res)
						this.codeImg='data:image/png;base64,'+res.img
						this.uuid=res.uuid
					}
					else{
						uni.showToast({title: res.msg,icon: 'none'});
					}
				},
				(rej) => {
					uni.hideLoading();
					console.log('qxj rej:' + JSON.stringify(rej));
				}
			);
		},
		initUniverify() {
			const callback = (res) => {
				// 获取一键登录弹框协议勾选状态
				univerifyManager.getCheckBoxState({
					success(res) {
						if (res.state) {
							// 关闭一键登录弹框
							univerifyManager.close();
						}
					}
				});
			};
			// 订阅自定义按钮点击事件
			univerifyManager.onButtonsClick(callback);
			// 取消订阅自定义按钮点击事件
			univerifyManager.offButtonsClick(callback);
		},
		changeText(val,value){
			this[val]=value
		},
		closePwd(){
			this.isClose=!this.isClose
		},
		handlePwd(){
			this.agree=!this.agree
		},
		login() {
			if (this.$isEmpty(this.account)) {
				uni.showToast({
					title: '请输入帐号',
					icon: 'none'
				});
				return;
			}
			if (this.$isEmpty(this.password)) {
				uni.showToast({
					title: '请输入密码',
					icon: 'none'
				});
				return;
			}
			if (this.$isEmpty(this.code)) {
				uni.showToast({
					title: '请输入验证码',
					icon: 'none'
				});
				return;
			}
			
			var data = {
				account: this.account,
				password: this.password,
				uuid: this.uuid,
				code: this.code
			};
			var that = this;
			uni.showLoading({
				title: '处理中...'
			});

			login(data).then(
				(res) => {
					uni.hideLoading();
					if (res.code == 200) {
						uni.setStorageSync('AppToken', res.data.token);
						uni.setStorageSync('userInfo', JSON.stringify(res.data.user));
						if (this.agree) {
							uni.setStorageSync('password', data.password);
						} else {
							uni.setStorageSync('password', null);
						}
						
						uni.redirectTo({
							url: '/pages/index/index'
						});
					} else {
						uni.showToast({ title: res.msg, icon: 'none' });
						this.code = '';
						this.getCode();
					}
				},
				(rej) => {
					uni.hideLoading();
					console.log('qxj rej:' + JSON.stringify(rej));
				}
			);
		},
		goToRegister() {
			this.$navTo('./register');
		},
		goToFindPass() {
			this.$navTo('./findpass');
		}
	}
};
</script>

<style scoped lang="scss">
page {
	background-color: #ffffff;
}

.border-box {
	width: 100vw;
	height: 100vh;
	background-image:url(/static/image/device/ipad_yjf_boder.png);
	background-repeat: no-repeat;
	position: relative;
	background-size: 100% 100%;
	box-sizing: border-box;
	padding: 10px;
}
.content {
	display: flex;
	width: 100%;
	height: 100%;
	background-image: url(/static/image/device/ipad_yjf_bg.png);
	background-repeat: no-repeat;
	background-size: 100% 100%;
	position: relative;
}
.backImg {
	position: absolute;
	left: 30px;
	top: 40px;
	height: 30px;
	width: 30px;
}

.pageTop {
	flex: 1;
	display: flex;
	flex-direction: column;
	width: 100%;
}

.content .head {
	text-align: center;
	width: 100%;
	height: 100px;
	// background:url(/static/image/login/top_bg.png) no-repeat 0 center;
	background-size: cover;
	box-sizing: border-box;
	font-size: 36px;
	font-weight: bold;
	color: #666;
}

.content .head image {
	width: 150px;
	height: 150px;
	border-radius: 10px;
	box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.2);
}
.title {
	color: #141414;
	margin: 50upx 0upx 30upx 0px;
	font-size: 38px;
	font-weight: 500;
}
.desc {
	color: #686866;
	padding: 0 0 30px 0px;
	font-size: 28px;
}

.logo {
	width: 110px;
	height: 110px;
	background: #8f6726;
	border-radius: 150%;
	display: flex;
	align-items: center;
	justify-content: center;
	position: absolute;
	z-index: 10;
	top: -60px;
	left: 50%;
	transform: translateX(-50%);
	image {
		width: 74px;
		height: 74px;
	}
}
.head-title {
	font-family: Source Han Serif CN, Source Han Serif CN;
	font-weight: bold;
	font-size: 36px;
	color: #222222;
	text-align: center;
	font-style: normal;
	margin-bottom: 30px;
}
.flexCenter {
	display: flex;
	align-items: center;
	justify-content: space-between;
}
.loginBox {
	padding: 67px 44px 44px;
	// width: calc(60%);
	background: #fdfdfd;
	z-index: 10;
	position: relative;
	border-radius: 24px;
	.login-item {}
	.login-item p {
		text-align: left;
	}
	.line {
		height: 0.5px;
		background-color: #efefef;
		margin-top: 10px;
	}
	
	input {
		margin-left: 80px;
		height: 52px;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 18px;
		color: #a8aaac;
		text-align: left;
		line-height: 52px;
	}
	
	.input-account {
		margin-top: 10px;
		margin-bottom: 0px;
		border-radius: 12px;
		border: 1px solid #e0e3ee;
		height: 52px;
		width: 100%;
		background: url(/static/image/device/user_icon36.png) no-repeat 0 center;
		background-size: 27px 27px;
		background-position: 27px;
		
		
	}
	.input-pwd {
		margin-top: 20px;
		// margin-bottom: 20px;
		border-radius: 12px;
		border: 1px solid #e0e3ee;
		height: 52px;
		width: 100%;
		background: url(/static/image/device/password_icon36.png) no-repeat 0 center;
		background-size: 27px 27px;
		background-position: 27px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.close-pwd{
			margin-right: 40px;
			display: flex;
			align-items: center;
			justify-content: center;
			// margin-top: 10px;
			image{
				width: 27px;
				height: 27px;
			}
			
		}
	}
	
	.input-code {
		margin-top: 20px;
		margin-right: 20px;
		margin-bottom: 20px;
		border-radius: 12px;
		border: 1px solid #e0e3ee;
		height: 52px;
		width: 100%;
		background: url(/static/image/device/code_icon36.png) no-repeat 0 center;
		background-size: 27px 27px;
		background-position: 27px;
	}

	.input-yzcode {
		margin-top: 20px;
		margin-bottom: 20px;
		width: 200px;
		height: 52px;
		image {
			width: 100%;
			height: 100%;
		}
		
	}
	
	.reg-box {
		padding-bottom: 20px;
		margin: 0 10px;
		.reg-btn {
			font-size: 16px;
			color: #ff5c03;
		}
	}
}
/* 激活状态样式（核心） */
		.input-active {
		  border:1px solid #8F6726 !important; /* 激活时边框色（示例：蓝色） */
		}
		.input-active input {
		  caret-color: #8F6726; /* 激活时光标色（与边框色一致） */
		}
.btns {
	margin-top: 30rpx;
}

.login-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 65px;
	background: #8f6726;
	border-radius: 12px;
	font-size: 24px;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(255, 255, 255, 1);
}

.pageBottom {
	height: 220px;
	width: 75%;
	display: flex;
	flex-direction: column;
	position: absolute;
	bottom: 100px;
}

.tips {
	color: #999;
	font-size: 32px;
}
.menu {
	margin-top: 30px;
	image {
		width: 96px;
		height: 96px;
	}
}

.checkbox {
	// margin: 20px;
	margin-top: 20px;
	display: flex;
	// flex-direction: row;
	align-items: center;
	// justify-content: flex-start;
	font-family: PingFang SC, PingFang SC;
	font-weight: 400;
	font-size: 18px;
	color: #999999;
	// line-height: 38px;
	text-align: left;
	.uni-label-pointer{
		display: flex;
		// flex-direction: row;
		align-items: center;
	}
	text {
		color: #8f6726;
	}
	&-icon {
		flex-shrink: 0;
		margin-right: 15px;
		image {
			height: 24px;
			width: 24px;
		}
	}
}
// 响应式适配 - 针对不同屏幕尺寸调整
// 小屏手机
@media (max-width: 412px) {
	.login-panel {
		padding: 80px 30px 40px;
		.head-title {
			font-size: 40px;
			margin-bottom: 40px;
		}
	}

	$spacing: 20px;
	$input-height: 80px;
	
	
	.loginBox {
		padding: 90px 60px 60px;
		width: calc(80%);
	}
	
}



</style>
