<template>
	<view>
		<view class="head">
			<text>智能高效客户管理平台</text>
		</view>
		<view class="input">
			<view class="cwjs-cells item-flex">
				<view class="cwjs-item center">
					<image src="https://qufang.oss-cn-beijing.aliyuncs.com/channelHelper/user.png" class="logo_input">
					</image>
					<input class="cwjs-item cwjs-input" v-model="username"  placeholder="请输入账号名"  type="number" maxlength="11" placeholder-style="color:#AAAAAA"></input>
				</view>
			</view>
			<view class="cwjs-cells item-flex" style="margin-top:13rpx;">
				<view class="cwjs-item center">
					<image src="https://qufang.oss-cn-beijing.aliyuncs.com/channelHelper/lock.png" class="logo_input">
					</image>
					<input class="cwjs-item cwjs-input" placeholder="请输入密码" placeholder-style="color:#AAAAAA" type="password" v-model="password" maxlength="16" v-if="passwordType"></input>
					<input class="cwjs-item cwjs-input" placeholder="请输入密码" placeholder-style="color:#AAAAAA" maxlength="16" v-model="password" v-else></input>
				</view>
				<view class="imagesBox" @tap="changeBindPassword">
					<image
						:src="'https://qufang.oss-cn-beijing.aliyuncs.com/upload/icon/xcx/jjycrm/login/' + (passwordType==true?'close_eyes.png':'open_eyes.png')"
						class="images" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="textbox">
				<view class="textbox-1" @tap="bindVerification">验证码登录</view>
				<view class="textbox-2"></view>
				<view class="textbox-11" @tap="bindpassword">忘记密码</view>
			</view>
		</view>
		<view class="button" @tap="bindWxBLogin">登录</view>
		<image src="https://qufang.oss-cn-beijing.aliyuncs.com/upload/icon/xcx/jjycrm/login/footer.png" class="footer">
		</image>
	</view>
</template>

<script>
	var util = require("../../utils/util.js");
	var config = require("../../config");
	var app = getApp();
	var WXB_SESSION_LOGIN_DATA = 'weapp_session_login_data';
	export default {
		data() {
			return {
				username: '',
				//获取到的用户名的值
				password: '',
				//获取到的密码栏中的值
				passwordType: true,
				agreeChecked: true
			};
		},
		onLoad: function(options) {
			uni.hideToast();
		},
		methods: {
			//验证码登录
			bindVerification() {
				uni.navigateTo({
					url: '/pages/login/Verification?role=1',
				})
			},
			//忘记密码
			bindpassword() {
				uni.navigateTo({
					url: '/pages/login/Verification?role=2',
				})
			},
			//密码选择
			changeBindPassword: function(e) {
				this.passwordType=!this.passwordType;
			},
			//登录
			bindWxBLogin: function(e) {
				util.showBusy('正在登录...');
				var that = this;
				if (this.username == '') {
					util.showNone("请输入账号名");
					return false;
				}
				if (this.password == '') {
					util.showNone("请输入密码");
					return false;
				}
				var loginParams = {
					loginName: this.username,
					password: this.password
				}; 
				// 请求服务器登录地址，获得会话信息
				uni.request({
					url: config.service.login,
					header: {
						'content-type': 'application/json'
					},
					method: "POST",
					data: loginParams,
					success: function(result) {
						var data = result.data; //console.log("登陆信息", data);
						if (data && data.code == 10000) {
							var res = data.data;
							if (res) {
								var data = {
									'token': res
								};
								uni.setStorageSync(WXB_SESSION_LOGIN_DATA, data); //写入缓存
								that.getMenu()
								that.getUser();
								util.showSuccess('登录成功');
							} else {
								util.showNone("账号名或密码错误，请重试");
								return false;
							} 
							// 没有正确响应会话信息
						} else {
							util.showNone(data.message);
							return false;
						}
					},
					// 响应错误
					fail: function(loginResponseError) {
						util.showNone("网络异常，请重试");
						return false;
					}
				});
			},
			getUser(){
				util.getRequestPromise(config.service.getUser, {}, false, "GET").then(data => {
					if (data.zkProperties) {
				
					} else {
						data.zkProperties = [{
							id: "",
							propertyName: ''
						}]
					}
					let lopan = {
						id: data.zkProperties[0].id,
						name: data.zkProperties[0].propertyName
					}
					uni.setStorageSync("fendianindex", 0); //写入缓存
					uni.setStorageSync("weapp_session_userInfo_data", data); //写入缓存
					uni.setStorageSync("buildingID", lopan); //楼盘id写入缓存
					uni.switchTab({
						url: '/pages/index/index'
					});
				});
			},
			getMenu(){
				this.$u.get("/user/getMenu").then(data => {
					uni.setStorageSync("weapp_session_Menu_data", data)
				})	
			}
			
			
		}
	};
</script>
<style lang="scss">
	.cwjs-logo {
		display: block;
		width: 219rpx;
		height: 158rpx;
		margin: 54rpx auto 66rpx;
	}

	.cwjs-tips {
		font-size: 24rpx;
		padding: 80rpx 0;
		color: #8a8a8a;
	}

	.cwjs-form {
		position: relative;
		margin: 0;
		background-color: #fff;
		border-radius: 10px;
		padding: 20rpx 40rpx 113rpx;
	}

	.cwjs-cells {
		width: 569rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		margin: 0 auto;
		height: 88rpx;
		overflow: hidden;
		border-bottom: 1rpx solid #BFC7D3;
		position: relative;
	}

	.center {
		flex: 1;
	}

	.cwjs-input {
		height: 48rpx;
		line-height: 48rpx;
		padding: 23rpx 23rpx 23rpx 78rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		color: #000;
	}

	.images {
		display: block;
		width: 40rpx;
		height: 21rpx;
		margin-right: 30rpx;
		margin-top: 33.5rpx;
	}

	.mod-btn {
		position: absolute;
		bottom: -80rpx;
		left: 50%;
		margin-left: -80rpx;
	}

	.mod-btn .button {
		width: 160rpx;
		height: 160rpx;
		background: linear-gradient(180deg, rgba(116, 197, 230, 1) 0%, rgba(64, 147, 201, 1) 100%);
		border: 10rpx solid rgba(255, 255, 255, 1);
		border-radius: 100%;
		font-size: 36rpx;
		color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.mod-btn .button::after {
		content: ""
	}

	.retPassword {
		display: inline;
		width: auto;
		font-size: 28rpx;
		color: rgba(64, 147, 201, 1);
		line-height: 40rpx;
		float: right;
	}

	.retPassword:active {
		background-color: #fff;
	}

	.appliyAdmin {
		position: absolute;
		left: 50%;
		margin-left: -57rpx;
		bottom: 100rpx;
		width: 114rpx;
		font-size: 28rpx;
		color: rgba(255, 255, 255, 1);
		line-height: 40rpx;
	}

	/* 头部 */

	.head {
		width: 750rpx;
		height: 410rpx;
		background-image: url(https://qufang.oss-cn-beijing.aliyuncs.com/channelHelper/background.png);
		background-size: 100vw auto;
		background-repeat: no-repeat;
	}

	.background {
		width: 750rpx;
		height: 400rpx;
		position: absolute;
		top: -3rpx;
		left: 0;
	}

	.logo {
		width: 248upx;
		height: 248upx;
		display: block;
		position: absolute;
		top: 134rpx;
		left: 240.5rpx;
	}

	.head text {
		font-size: 34rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #008EF2;
		position: absolute;
		top: 353rpx;
		width: 100%;
		text-align: center;

	}

	/* 输入框 */
	.input {
		width: 100%;
		height: auto;
		padding: 0 105rpx;
		box-sizing: border-box;
	}

	.logo_input {
		width: 34rpx;
		height: 38rpx;
		position: absolute;
		top: 25rpx;
		left: 0;
	}

	/* 登录 */
	.button {
		width: 603rpx;
		height: 89rpx;
		background: rgba(72, 149, 255, 1);
		box-shadow: 0rpx 2rpx 14rpx 0rpx rgba(151, 192, 255, 1);
		border-radius: 45rpx;
		text-align: center;
		line-height: 89rpx;
		color: #fff;
		margin: 0 auto;
		margin-top: 239rpx;
		font-size: 34rpx;
	}

	.footer {
		width: 100%;
		height: 157rpx;
		position: absolute;
		bottom: 0;
		left: 0;
	}

	.agreeBox {
		/* text-align: center; */
		/* width: 450rpx; */
		/* padding-left: 145rpx; */
		font-size: 28rpx;
		color: #88909E;
		margin: 0 auto;
		margin-top: 30rpx;
		position: relative;
		display: flex;
		margin-left: 83upx;
	}

	checkbox {
		transform: scale(0.5);
	}

	checkbox-group {
		display: inline;
	}

	navigator {
		display: inline
	}

	.agreeBox image {
		width: 26rpx;
		height: 26rpx;
		display: block;
		position: absolute;
		top: 9rpx;
		left: 18rpx;
		margin-right: 19rpx;
	}

	.imagesBox {
		width: 80rpx;
		height: 88rpx;
	}

	.chooseBox {
		width: 60rpx;
		height: 60rpx;
	}

	.login {
		text-decoration: underline;
		text-align: center;
		margin-top: 40px;
		color: #88909E;
		font-size: 28rpx;
	}

	.textbox {
		width: 569rpx;
		display: flex;
		margin-top: 40rpx;
	}

	.textbox-1 {
		width: 30%;
		font-size: 30rpx;
		color: #999999;
	}

	.textbox-11 {
		width: 30%;
		text-align: right;
		font-size: 30rpx;
		color: #999999;
	}

	.textbox-2 {
		width: 40%;
	}
</style>
