<template>
	<view class="container">
		<view class="wrapper">
			<!-- logo -->
			<view class="titbox">
				<view class="firtit">{{info.mobile_name}}</view>
				<view class="sectit">实现线索到回款全流程管理</view>
			</view>
			<!-- 表单 -->
			<view class="login-box">	
				<view class="input-item">
					<view class="itemtit">手机号</view>
					<view class="itembot">
						<image class="phoneimg" :src="BASE_IMG_URL+'phone1.png'" mode=""></image>
						<input 
							type="text" 
							placeholder="请输入账号" 
							placeholderStyle="color:#999;font-size:30rpx"
							class="inp"
							v-model="account"
						>	
					</view>
				</view>
				<view class="input-item">
					<view class="itemtit">密码</view>
					<view class="itembot">
						<image class="suoimg" :src="BASE_IMG_URL+'suo1.png'" mode=""></image>
						<input class="inp" v-model="password" v-if="!showPassword" type="text" password placeholder="请输入密码" placeholder-class="pl" />
						<input class="inp" v-model="password" v-if="showPassword" type="text" placeholder="请输入密码" placeholder-class="pl" />
						<image :src="BASE_IMG_URL+'nosee1.png'" v-if="!showPassword" @click="showPassword = true" class="eayimg" mode=""></image>
						<image :src="BASE_IMG_URL+'see1.png'" v-if="showPassword" @click="showPassword = false" class="eayimg" mode=""></image>
					</view>
				</view>
			</view>
			<!-- 登录按钮 -->
			<view class="btn_g" @tap="toLogin">登录</view>
			<!-- <view class="freelogin" @click="freeLogin">暂不登录，进行演示</view> -->
		</view>
		
		<!-- <view class="priva_w">
			<radio value="" color="#008EFF" @click.stop="selectAgree" :checked="readAndagree"/>请阅读并同意 <text @click.stop="showPrivacy = true">《隐私政策》</text>
		</view>

		<web-view src="https://testcrm.qingdong.vip/privacy.html" v-if="showPrivacy"></web-view> -->
		
		<!-- 需要用户阅读 并同意隐私协议 -->
		<uni-popup ref="privacyPopup" type="bottom" :safe-area="false" @touchmove.stop.prevent>
			<view class="privacy_mask">
				<view class="privacy_box">
					<view class="priva_tit">隐私政策提示</view>
					<view class="priva_tip">欢迎使用CRM客户管理软件</view>
					<view class="priva_con">
						我们将通过 <text @click="toOpenPrivacy">《隐私政策》</text> 帮助您了解我们收集、使用、存储和共享个人信息的情况。
						未经您的单独同意，我们不会主动向任何第三方共享您的个人信息。
						当您使用一些功能服务时，我们可能会在获得您的明示同意后，
						从授权第三方处获取世章或向其提供信息。
					</view>
					<button open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization" class="agreebtn">同意并继续</button>
					<view class="noagree">
						<text @click="closePop">不同意</text>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		BASE_IMG_URL,
		SIGN_NO
	} from '@/util/api.js'
	import { netNewLogin, defaultInfo, netlogin_text } from '@/api/login'
	
	export default {
		data() {
			return {
				BASE_IMG_URL:BASE_IMG_URL,
				account:'',
				showPassword:false,
				password:'',
				info:{},
				showPrivacy:false,
				readAndagree:false,
				isAgreePrivacy:false,  //弹出隐私协议
			};
		},
		onShow() {
			//获取默认头部信息
			this.getDefInfo()
			// #ifdef MP-WEIXIN
				this.handlePrivacyStatus()
			// #endif
		},
		methods: {
			///////////////////////
			//获取 隐私政策提示  判断是否已经同意隐私政策
			handlePrivacyStatus() {
				wx.getPrivacySetting({
					success:(res)=>{
						console.log(res,'000000')
						if (res.needAuthorization){
							// 需要弹出隐私协议
							this.$refs.privacyPopup.open()
							this.isAgreePrivacy = true
						}else{
							// 用户已经同意过隐私协议
							this.isAgreePrivacy = false
						}
					}
				})
			},
			toOpenPrivacy() {
				wx.openPrivacyContract({})
			},
			handleAgreePrivacyAuthorization() {
				this.isAgreePrivacy = false
				this.$refs.privacyPopup.close()
			},
			showPrivacyPop() {
				this.$refs.privacyPopup.open()
			},
			closePop() {
				this.$refs.privacyPopup.close()
			},
			////////////////////////////
			selectAgree() {
				this.readAndagree = !this.readAndagree
			},
			getDefInfo() {
				defaultInfo().then(res=>{
					this.info = res.data
					uni.setStorageSync('mapKey',res.data.map_key)
					uni.setStorageSync('appid',res.data.appid)
					uni.setStorageSync('NAME',res.data.mobile_name)
				})
			},
			jump(path, query) {
				this.$Router.push({
					path: path,
					query: query
				});
			},
			toLogin() {
				if(this.isAgreePrivacy){
					this.$refs.privacyPopup.open()
					return
				}
				if(!this.account){
					uni.showToast({
						title:'请填写账号',
						icon:'none'
					})
					return
				}
				if(!this.password){
					uni.showToast({
						title:'请填写密码',
						icon:'none'
					})
					return
				}
				// if(!this.readAndagree){
				// 	uni.showToast({
				// 		title:'请阅读并同意隐私政策',
				// 		icon:'none'
				// 	})
				// 	return
				// }
				let params = {
					account:this.account,
					password:this.password
				}	
				netNewLogin(params).then(res=>{
					this.jumpPage(res)
				})
			},
			//暂不登录
			freeLogin() {
				if(this.isAgreePrivacy){
					this.$refs.privacyPopup.open()
					return
				}
				// if(!this.readAndagree){
				// 	uni.showToast({
				// 		title:'请阅读并同意隐私政策',
				// 		icon:'none'
				// 	})
				// 	return
				// }

				netlogin_text().then(res=>{
					this.jumpPage(res)
				})
			},
			jumpPage(res){
				uni.setStorageSync('userinfo',res.data.userinfo)
				uni.setStorageSync('token',res.data.userinfo.token)
				uni.redirectTo({
					url:'/pages/index/index'
				})
			}
		}
	};
</script>

<style lang="scss">
	.priva_w{
		display: flex;
		justify-content: center;
		align-items: center;
		font-size:24rpx;
		margin-top:80rpx;
		color:#999;
		radio{
			transform: scale(0.7);
		}
		text{
			color:$uni-text-color;
		}
	}
	.freelogin{
		text-align: center;
		font-size:24rpx;
		color:red;
		margin-top:60rpx;
	}
	.wrapper {
		padding-bottom: 40upx;
		width: 100%;
		margin-top:100rpx;
		.titbox{
			padding:40rpx 0 50rpx;
			.firtit{
				font-size:48rpx;
				color:$uni-text-color;
				font-weight: bold;
				text-align: center;
			}
			.sectit{
				font-size:32rpx;
				color:#999999;
				margin-top:30rpx;
				text-align: center;
			}
		}
		// 输入
		.login-box {
			margin:0 auto 100rpx;
			.input-item {
				padding:26rpx 30rpx;
				border-bottom: 1rpx solid #c7c7c7;
				width: 630rpx;
				margin:0 auto 50rpx;
				.itemtit{
					font-size:30rpx;
					color:#666666;
					margin-bottom:50rpx;
				}
				.itembot{
					display: flex;
					justify-content: flex-start;
					align-items: center;
				}
				.phoneimg{
					width:41rpx;
					height:40rpx;
				}
				.suoimg{
					width:40rpx;
					height:44rpx;
				}	
				.inp {
					width:460rpx;
					margin-left:30rpx;
					font-size: 28rpx;
				}
				.pl {
					font-size:30rpx;
					color: #999999;
				}
				.eayimg{
					margin-left:30rpx;
					width:33rpx;
					height:33rpx;
				}
			}
		}
		.li_box{
			margin:40rpx auto 0;
			width:690rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding:0 30rpx;
			font-weight: 700;
			.register{
				font-size:26rpx;
				color:#333333;
			}
			.forgot{
				font-size:26rpx;
				color:#333333;
			}
		}
		// 登录
		
	}
</style>
