<template>
	<!-- <page-meta :page-font-size="`${this.scaleFontSize}px`"  :root-font-size="`${this.scaleFontSize}px`"></page-meta> -->
	<view class="border-box">
	<view class="content y-ac">
		<view class="logo">
			<image class="logo-1" src='/static/image/new/logo.svg'></image>
			<image class="logo-2" src='/static/image/new/img_welcom.svg'></image>
		</view>
		<view class="checkbox">
			<view class="btn" @click="goTest()">开始检测</view>
			<view class="checkbox-icon x-c" @tap="handleAgree">
				<image src="/static/image/new/icon_check_default.svg" v-show="!agree"></image>
				<image src="/static/image/new/icon_check.svg" v-show="agree"></image>
				<view class="checkbox-text">我已阅读并同意<text @tap="goToWeb(0)">《用户协议》</text><text @tap="goToWeb(1)">《隐私政策》</text></view>
			</view>
			
		</view>
		<!-- <view class="center-box" :class="{ 'flex-box': width < height }">
			<view class="bg-item y-start" @click="goTest()">
				<view class="title">体质辨识</view>
				<view class="more">
					<text>点击了解</text>
				</view>
			</view>
			<view class="bg-item y-start" @click="goUser()">
				<view class="title">客户管理</view>
				<view class="more">
					<text>点击了解</text>
				</view>
			</view>
		</view> -->
		<!-- <view class="footer">
			<view>登录账号：{{info.userName||'-'}}</view>
			<view>姓名：{{info.nickName||'-'}}</view>
		</view> -->
	</view>
	</view>
</template>

<script>
	import store from '@/store';
	import {selectUserInfo} from '@/api/user.js';
	export default {
		components: {
			
		},
		data() {
			return {
				height: uni.getSystemInfoSync().screenHeight,
				width: uni.getSystemInfoSync().screenWidth,
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
				option: '',
				top: 0,
				statusBarBG: 'none',
				headerHeight: 44,
				// locCity: '国健通',
				scaleFontSize: uni.getStorageSync('fontSize'),
				info:{},
				user:{},
				agree: false,
			
			};
		},
		onPageScroll(e) {
			if (this.template == 'homeIndex') {
				this.top = e.scrollTop;
			}
		},
		computed: {
			// 计算属性的 getter
			headerBG() {
				if (this.template == 'homeIndex') {
					var top = this.top / 88;
					return 'rgba(255,92,3, ' + top + ')';
				}
			}
		},
		onLoad(option) {
			
			const systemInfo = uni.getSystemInfoSync();
			console.log("qxj screenWidth:"+systemInfo.screenWidth);
			console.log("qxj screenHeight:"+systemInfo.screenHeight);  //定制设备平板 800x1232   平板设备1280x785
              
			let that = this;
			uni.setNavigationBarTitle({
				title: that.$qconfig.appName
			});
			uni.setStorageSync('indexTemplate', 0);
			this.option = option;
			// this.user=JSON.parse(uni.getStorageSync('userInfo'));
			// this.selectUserInfo();
			//this.scaleFontSize = store.state.timStore.fontSize;
			// this.$nextTick(()=>{
			// 	  this.$refs[this.template].initLoad(this.option)
			// })
		},
		onReady() {
			// this.$refs.indexSubsection.selectorQuery();
			// this.$refs[this.template].initReady();
		},
		onShow() {
			// if (!this.$isLogin()) {
			// 	uni.navigateTo({
			// 		url: '/pages/auth/loginIndex'
			// 	});
			// } else {
			// 	// this.$updateMsgDot();
			// }
		},
		methods: {
			// 同意
			handleAgree() {
				this.agree = !this.agree
			},
			goToWeb(index) {
				// uni.setStorageSync('url', index == 0 ? "https://userapp.his.cdwjyyh.com/web/userAgreement" :
				// 	"https://userapp.his.cdwjyyh.com/web/privacyPolicy");
				uni.navigateTo({
					url: "/pages/index/agreement"
				})
			},
			selectUserInfo(){
				selectUserInfo().then(res => {
						if(res.code==200){
							console.log('res',res)
							  this.info=res.user
						}
						else{
							uni.showToast({title: res.msg,icon: 'none'});
						}
					},
					rej => {}
				);
			},
			logout(){
			 	uni.showModal({
			 		title:"提示",
			 		content:"确认退出登录吗?",
			 		showCancel:true,
			 		cancelText:'取消',
			 		confirmText:'确定',
			 		success:res=>{
			 			if(res.confirm){
							// this.$logout();
			 				uni.removeStorageSync('AppToken');
							uni.removeStorageSync('selectUser');
							uni.$emit('loginOut');
								 uni.reLaunch({
									url: '/pages/auth/loginIndex'
								});				
			 			}else{
							
			 			}
			 		}
			 	})
			 },
			 goUser(){
				 // uni.redirectTo({
				 // 	url: '/pages/user/myUserList?userId='+this.user.userId
				 // });
				 uni.navigateTo({
				  url: '/pages/user/myUserList?userId='+this.user.userId
				 })
			 },
			 goTest(){
				 if (!this.agree) {
				 	uni.showToast({
				 		title: "请同意相关协议",
				 		icon: 'none'
				 	});
				 	return
				 }
			 	// 	uni.navigateTo({
			 	// 	//url:"/pages/device/tongue/indexOld"
					// url:"/pages/device/tongue/facePhoto"
			 	// 	});
						uni.navigateTo({
						 url:'/pages/user/userInfo'
						})
			 },
			changeTemplate(e) {
				const tem = e == 1 ? 'watchIndex' : 'homeIndex';
				if (this.template == tem) return;
				this.template = tem;
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 100
				});
				this.$nextTick(() => {
					//this.$refs[this.template].initLoad(this.option)
					this.$refs[this.template].initReady();
					// this.$refs[this.template].initShow();
				});
			},
			registerIdCode() {
				//注册，先注册再获取，注意APP合规性，若最终用户未同意隐私政策则不要调用
				idCode.register((res) => {
					console.log(res);
				});
			},
			async getLocation() {
				let status;
				// #ifdef APP-PLUS
				status = await this.checkPermission();
				if (status !== 1) {
					return;
				}
				// #endif
				// #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
				status = await this.getSetting();
				if (status === 2) {
					this.showConfirm();
					return;
				}
				// #endif
				this.doGetLocation();
			},
			doGetLocation() {
				getLocation().then((res) => {
					this.locCity = res.city.replace(/市|区/g, '');
				});
			},
			getSetting: function() {
				return new Promise((resolve, reject) => {
					uni.getSetting({
						success: (res) => {
							if (res.authSetting['scope.userLocation'] === undefined) {
								resolve(0);
								return;
							}
							if (res.authSetting['scope.userLocation']) {
								resolve(1);
							} else {
								resolve(2);
							}
						}
					});
				});
			},
			openSetting: function() {
				this.hideConfirm();
				uni.openSetting({
					success: (res) => {
						if (res.authSetting && res.authSetting['scope.userLocation']) {
							this.doGetLocation();
						}
					},
					fail: (err) => {}
				});
			},
			async checkPermission() {
				let status = permision1.isIOS ? await permision1.requestIOS('location') : await permision1
					.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
				if (status === null || status === 1) {
					status = 1;
				} else if (status === 2) {
					uni.showModal({
						content: '系统定位已关闭',
						confirmText: '确定',
						showCancel: false,
						success: function(res) {}
					});
				} else if (status.code) {
					uni.showModal({
						content: status.message
					});
				} else {
					uni.showModal({
						content: '需要定位权限',
						confirmText: '设置',
						success: function(res) {
							if (res.confirm) {
								permision1.gotoAppSetting();
							}
						}
					});
				}
				return status;
			},

			showQidai() {
				uni.showToast({
					title: '功能完善中,敬请期待...',
					icon: 'none'
				});
			},
			goToMsg() {
				uni.switchTab({
					url: '/pages_im/pages/conversation/conversationList/index'
				});
			},
			async goToWXMsg() {
				const url = getApp().globalData.kfurl; //企业微信客服链接
				const corpId = getApp().globalData.corpId; //企业id
				// #ifdef H5
				window.location.href = url;
				// #endif
				// #ifdef MP-WEIXIN
				wx.openCustomerServiceChat({
					extInfo: {
						url
					},
					corpId,
					success(res) {
						console.log('成功');
					},
					fail(err) {
						console.log(err, '报错');
					}
				});
				// #endif

				// #ifdef APP-PLUS
				let shares = await this.getAppShare().catch((err) => {
					throw Error(err);
				});
				shares['weixin'].openCustomerServiceChat({
						corpid: corpId,
						url
					},
					(suc) => {
						console.log('客服打开成功', JSON.stringify(res));
					},
					(err) => {
						console.log('error', JSON.stringify(err));
					}
				);
				// #endif
			},
			getAppShare() {
				// #ifdef APP-PLUS
				return new Promise((re, rj) => {
					let shares = null;
					var pusher = plus.share.getServices(
						function(s) {
							shares = {};
							s.forEach((e) => (shares[e.id] = e));
							re(shares);
						},
						function(e) {
							rj(e);
						}
					);
				});
				// #endif
			},
		
			getIdCodes() {
				//获取设备的各种标识码
				idCode.getIdCodes((res) => {
					if (res.data) {
						//this.msgList.unshift(JSON.stringify(res.data));
						let ua = plus.navigator.getUserAgent();
						console.log('qxj ua:' + ua);
						console.log('qxj getIdCodes:' + JSON.stringify(res.data));
					}
				});
			},
			
			scanQRCode() {
				const that = this;
				uni.scanCode({
					success(res) {
						if (res.result) {
							// 扫描成功，处理二维码内容
							console.log('扫描结果：', res.result);
							const scanInfo = res.result;
							if (scanInfo && scanInfo.indexOf('https://userapp.his.cdwjyyh.com/bindcompanyuser') > -
								1) {
								const companyUserId = this.getUrlParam(scanInfo).companyUserId;
								console.log('扫描结果公司码：', companyUserId);
								this.$handleBindCompanyFsUser(companyUserId);
							}
						} else {
							// 扫描失败
							uni.showToast({
								title: '扫描失败',
								icon: 'none'
							});
						}
					},
					fail() {}
				});
			},
			getUrlParam(url) {
				const queryStr = url.split('?')[1];
				if (!queryStr) {
					return {};
				}
				const params = queryStr.split('&');
				const queryParams = {};
				params.forEach((param) => {
					const [key, value] = param.split('=');
					queryParams[key] = value;
				});
				return queryParams;
			}
		}
	};
</script>

<style lang="scss" scoped>
	// @mixin u-flex($flexD, $alignI, $justifyC) {
	// 	display: flex;
	// 	flex-direction: $flexD;
	// 	align-items: $alignI;
	// 	justify-content: $justifyC;
	// }
 .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/new/bg_home.png);
	 background-repeat: no-repeat;
	 background-size: 100% 100%;
	 position: relative;
	 // padding-top: 20px;
	 .logo{
		 margin-top: 30px;
		 width: 100%;
		 display: flex;
		align-items: center;
		 flex-direction: column;
		 .logo-1{
			 width: 536px;
			 height: 263px;
		 }
		 .logo-2{
			 margin-top: 55px;
			 width: 490px;
			 height: 104px;
		 }
	 }
	 .btn-box{
		 width: 100%;
		 text-align: right;
		 justify-content: right;
		 margin-top: 50px;
		 padding-right: 37px;
		 .item-box{
			width: 167px;
			height: 47px;
			background: #8F6726;
			border-radius: 9px 9px 9px 9px;
			 margin-left: 16px;
			 font-family: Microsoft YaHei, Microsoft YaHei;
			 font-weight: 400;
			 font-size: 18px;
			 color: #FFFFFF;
			 text-align: center;
			 image{
				 width: 24px;
				 height: 24px;
				 margin-right:10px ;
			 }
		 }
	 }
	 .center-box{
		 width: 100%;
		 display: flex;
		 align-items: center;
		 justify-content: center;
		 &.flex-box{
			flex-direction: column;
			.bg-item:last-child{
				 margin-left: 0px;
				 margin-top: 40px;
			 }
		 }
		 .bg-item{
			width: 504px;
			height: 267px;
			 padding: 41px;
			 border-radius: 16px;
			 background-image:url(/static/image/device/tzbs_bg.png);
			 background-repeat: no-repeat;
			 background-size: 100% 100%;
			 &:last-child{
				 margin-left: 40px;
				  background-image:url(/static/image/device/khgl_bg.png);
			 }
			 .title{
				 font-family: Source Han Serif CN, Source Han Serif CN;
				 font-weight: bold;
				 font-size: 39px;
				 color: #FFFFFF;
				 text-align: left;
			 }
			 .more{
				 margin-top: 15px;
				width: 89px;
				height: 30px;
				background: #FFFFFF;
				border-radius: 6px 6px 6px 6px;
				 display: flex;
				 align-items: center;
				 justify-content: center;
				 background: #FFFFFF;
				 text-align: center;
				 text{
					 font-family: PingFang SC, PingFang SC;
					 font-weight: 400;
					 font-size: 16px;
					 color: #A14212;
				 }
			 }
		 }
		 
	 }
	 .footer{
		 width: 100%;
		 display: flex;
		 align-items: center;
		 justify-content: center;
		 // position: absolute;
		 padding-bottom:50px;
		 view{
			 font-family: PingFang SC, PingFang SC;
			 font-weight: 400;
			 font-size: 20px;
			 color: #8F6726;
			 text-align: center;
			 &:last-child{
				 margin-left: 40px;
			 }
		 }
	 }
 }
 .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;
	flex-direction: column;
 	.uni-label-pointer{
 		display: flex;
 		// flex-direction: row;
 		align-items: center;
 	}
 	text {
 		color: #3BABAF;
 	}
 	&-icon {
 		flex-shrink: 0;
 		
 		image {
 			height: 24px;
 			width: 24px;
			margin-right: 10px;
 		}
 	}
	&-text{
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 22px;
		color: #333333;
	}
	.btn{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 535px;
		height: 95px;
		background: #37C3A0;
		border-radius: 158px 158px 158px 158px;
		font-family: PingFang SC, PingFang SC;
		font-weight: 600;
		font-size: 40px;
		color: #FFFFFF;
		margin-bottom: 40px;
	}
 }
// @media screen and (max-width: 1149px) and (min-aspect-ratio: 1/1) {
//   .bg-item{
// 	  margin-left: 0 !important;
// 	  transform: scale(0.85);
//   }
//   .content .logo{
// 	  transform: scale(0.9);
//   }
// }
</style>