<template>
	<view :style="privacyPolicyModel?'overflow: hidden':'overflow: unset'">
		<view class="fixed_top_status_bar"></view>
		<!-- #ifdef APP-PLUS -->
		<view class="privacy_policy_model" v-if="privacyPolicyModel" @touchmove.stop.prevent="moveHandle">
			<view class="privacy_model" @touchmove.stop.prevent="moveHandle" @touchstart.stop="()=>{}" >
				<view class="privacy_model_title">{{$L('用户隐私政策')}}</view>
				<scroll-view class="privacy_policy" scroll-y @touchmove.stop.prevent="moveHandle">
					<rich-text :nodes="privacyPolicyHtml"></rich-text>
				</scroll-view>
				<view class="privacy_model_confirm" @click="confirmPrivacy">{{$L('同意，继续使用')}}</view>
				<view class="privacy_model_cancel" @click="cancelPrivacy">{{$L('不同意，退出APP')}}>></view>
			</view>
		</view>
		<!-- #endif -->
		<home-deco :deco_info="deco_data" :width='width' :height='height' :home_page_img='home_page_img' :is_show_top="true" :home_is_show_top_cat="home_is_show_top_cat" :is_from_found="false" type="home" :overflow="privacyPolicyModel"></home-deco>
	</view>
</template>


<script>
	import HomeDeco from '@/components/home_deco.vue'
	import privacyPolicy from "@/static/app-plus/privacyPolicy.js";
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				deco_data:[] ,//首页装修数据
				home_is_show_top_cat:true ,//是否显示顶部分类，默认显示
				home_page_img:[],
				width:'',
				height:'',
				shareData:{},
				privacyPolicyHtml:'', //隐私政策协议的富文本
				privacyPolicyModel:true,
			};
		},
		components: {
			HomeDeco
		},
		computed:{
			...mapState(['hasLogin', 'userInfo', 'userCenterData'])
		},
		onLoad() {
			this.loadData();
			this.privacyPolicyHtml=privacyPolicy.user_privacy_policy_content;
			let privacyPolicyHtml = uni.getStorageSync('privacyPolicy');
			if(privacyPolicyHtml){
				this.privacyPolicyModel = false;
			}
		},
		onShow(){
			let privacyPolicyHtml = uni.getStorageSync('privacyPolicy');
			if(privacyPolicyHtml){
				this.privacyPolicyModel = false;
			}
			if(this.userInfo.access_token){
				this.$request({
					url: 'v3/member/front/member/getInfo',
				}).then(res => {
					if (res.state == 200) {
						this.setUserCenterData(res.data);
					}
				}).catch((e) => {})
			}
		},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function () {
		  const {
		    shareData
		  } = this;
		  return shareData;
		},
		methods: {
			...mapMutations(['login', 'setUserCenterData']),
			async loadData() {
				uni.showLoading({
					title:'加载中...'
				})
				// #ifdef H5
				this.client = 'h5'
				// #endif
				
				// #ifdef APP-PLUS
				switch(uni.getSystemInfoSync().platform){
					case 'android':
					   this.client = 'android'
					   break;
					case 'ios':
					   this.client = 'ios'
					   break;
					default:
					   break;
				}
				// #endif
				
				// #ifdef MP
				this.client = 'weixinXcx'
				// #endif
				let param = {}
				param.url = 'v3/system/front/deco/index?os='+this.client
				param.method = 'GET'
				this.$request(param).then(res => {
					if (res.state == 200) {
						if(JSON.stringify(res.data) == "{}"){
							this.deco_data = null;
							uni.hideLoading();
							return
						}
						if(res.data.data != ''){
							this.deco_data = JSON.parse(res.data.data)
						}else{
							this.deco_data = null
						}
						
						
						// #ifdef MP
						  this.shareData={
						    title: res.data.siteName,
						    path: '/pages/index/index',
						    imageUrl: res.data.xcxImage
						  }
						  // #endif
						if(res.data.showTip != null){
							this.home_page_img = JSON.parse(res.data.showTip)
							const {windowWidth,windowHeight} = uni.getSystemInfoSync();
							this.width = this.home_page_img[0].width || windowWidth*0.75 * 1.8;
							this.height = this.home_page_img[0].height || windowHeight*0.56 * 1.8;
						}else{
							this.home_page_img = []
						}
						
						if(this.deco_data && this.deco_data.length != undefined && this.deco_data.length>0){
							this.home_is_show_top_cat = this.deco_data[0].type == 'top_cat_nav'?true:false;
						}
						uni.hideLoading()
					}
				})
			},
			//阻止模态框下页面滚动
			moveHandle(){},
			//同意，继续使用
			confirmPrivacy(){
				this.privacyPolicyModel = false;
				uni.setStorageSync('privacyPolicy',this.privacyPolicyHtml);
			},
			//不同意，退出app
			cancelPrivacy(){
				this.privacyPolicyModel = false;
				uni.clearStorageSync('privacyPolicy');
				//退出app
				// #ifdef APP-PLUS
				 if (plus.os.name.toLowerCase() === 'android') {
					 plus.runtime.quit();
				 }
				 else{ 
					 const threadClass = plus.ios.importClass("NSThread");
					 const mainThread = plus.ios.invoke(threadClass, "mainThread");
					 plus.ios.invoke(mainThread, "exit");
					 plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
				 }
				// #endif
			}
		},
	}
</script>

<style lang="scss">
.fixed_top_status_bar {
		position: fixed;
		/* #ifdef APP-PLUS */
		height: var(--status-bar-height);
		/* #endif */
		/* #ifndef APP-PLUS */
		height: 0;
		/* #endif */
		top: 0;
		left: 0;
		right: 0;
		z-index: 99;
		background: #fff;
	}
page{
	background: #F5F5F5;
}
.privacy_policy_model{
	width: 750rpx;
	height:100vh;
	background: rgba(0,0,0,0.7);
	position: fixed;
	top: 0;
	left: 0;
	z-index: 9999999;
	overflow: hidden;
	.privacy_model{
		width: 625rpx;
		height:70vh;
		background: #FFFFFF;
		border-radius: 15rpx;
		margin: 0 auto;
		margin-top: 17vh;
		padding-bottom: 24rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.privacy_model_title{
			height: 104rpx;
			font-size: 34rpx;
			font-family: Source Han Sans CN;
			font-weight: bold;
			color: #000000;
			line-height: 104rpx;
			text-align: center;
			border-bottom: 1rpx solid #F2F2F2;
		}
		.privacy_policy{
			width: 625rpx;
			height: 50vh;
			padding:0 43rpx;
			box-sizing: border-box;
		}
		.privacy_model_confirm{
			width: 542rpx;
			height: 72rpx;
			background: linear-gradient(90deg, #FC1C1C 0%, #FF7918 100%);
			border-radius: 36rpx;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 72rpx;
			text-align: center;
			margin: 20rpx auto;
		}
		.privacy_model_cancel{
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #FF991E;
			text-align: center;
			line-height: 28rpx;
		}
	}
}
</style>
