<template>
	<view style="touch-action: none;">
		<view class="home" style="position:fixed;" :style="{ top: top + 'px', bottom: bottom }" id="right-nav"
			@touchmove.stop.prevent="setTouchMove">
			<view class="homeCon bg-color-red dd" :class="homeActive === true ? 'on' : ''" v-if="homeActive"
				:style="{'width': showH?'100rpx':'200rpx'}">
				<image src="../../static/icon/home.png" mode="heightFix" class="logo" style="margin-right: 20rpx;"
					@click="goHome" v-if="!showH"></image>
				<button open-type="contact" bindcontact="handleContact" class="logo">
					<image src="../../static/icon/kf.png" mode="heightFix" class="logo"></image>
				</button>
				<!-- <navigator hover-class='none' url='/pages/index/index' open-type='switchTab' class='iconfont icon-shouye-xianxing'></navigator>
				<navigator hover-class='none' url='/pages/order_addcart/order_addcart' open-type='switchTab' class='iconfont icon-caigou-xianxing'></navigator>
				<navigator hover-class='none' url='/pages/user/index' open-type='switchTab' class='iconfont icon-yonghu1'></navigator> -->
			</view>
			<view @click="open" class="pictrueBox" id="home">
				<view class="pictrue">
					<image :src="
              homeActive === true
                ? 'https://xmyl.qiniu1314.com/static/images/close.gif'
                : 'https://xmyl.qiniu1314.com/static/images/open.gif'
            " class="image" />
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapGetters
	} from "vuex";
	export default {
		name: "Home",
		props: {},
		data: function() {
			return {
				top: "",
				bottom: "",
				homeActive: false,
				showH: false,
				pagesH: 580
			};
		},
		onReady() {
			let that = this
			wx.getSystemInfo({
				success: function(res) {
					const screenWidth = res.screenWidth; // 屏幕宽度
					const screenHeight = res.screenHeight; // 屏幕高度

					wx.createSelectorQuery().selectViewport().boundingClientRect(function(rect) {
						const viewportWidth = rect.width; // 视口宽度
						const viewportHeight = rect.height; // 视口高度

						const fullScreenWidth = screenWidth * viewportWidth / rect.width; // 页面全屏宽度
						const fullScreenHeight = screenHeight * viewportHeight / rect.height; // 页面全屏高度

						console.log('页面全屏宽度：', fullScreenWidth);
						console.log('页面全屏高度：', fullScreenHeight);
						that.pagesH = fullScreenHeight *1  - 100;
					}).exec();
				},
				fail: function(error) {
					console.log('获取系统信息失败', error);
				}
			});
		},
		methods: {
			handleContact(e) {
				console.log(e)
			},
			goHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			setTouchMove(e) {
				var that = this;
				console.log(e.touches[0].clientY)

				if (e.touches[0].clientY < that.pagesH  && e.touches[0].clientY > 66) {
					that.top = e.touches[0].clientY
				}
			},
			open: function() {
				this.homeActive ?
					this.closeHome() :
					this.openHome();
			},
			openHome() {
				this.homeActive = true;
				uni.setStorageSync('homeActive', true)
			},
			closeHome() {
				this.homeActive = false;
				uni.setStorageSync('homeActive', false)
			},
		},
		created() {

			// 获取当前页面的实例
			const pages = getCurrentPages();
			const currentPage = pages[pages.length - 1];

			// 获取页面路由信息
			const route = currentPage.route
			this.showH = (route == 'pages/index/index')

			console.log(this.showH, 'route')
			this.bottom = "50px";
			this.homeActive = uni.getStorageSync('homeActive')
		}
	};
</script>

<style scoped>
	.pictrueBox {
		width: 130rpx;
		height: 120rpx;
	}

	/*返回主页按钮*/
	.home {
		position: fixed;
		color: white;
		text-align: center;
		z-index: 9999;
		right: 15rpx;
		display: flex;
	}

	.home .homeCon {
		border-radius: 50rpx;
		opacity: 0;
		height: 0;
		color: #e93323;
		width: 0;
	}

	.home .homeCon.on {
		opacity: 1;
		animation: bounceInRight 0.5s cubic-bezier(0.215, 0.610, 0.355, 1.000);
		width: 200rpx;
		height: 86rpx;
		margin-bottom: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #9b0000 !important;
	}

	.home .homeCon .iconfont {
		font-size: 48rpx;
		color: #fff;
		display: inline-block;
		margin: 0 auto;
		background: #9b0000 !important;
	}

	.home .pictrue {
		width: 86rpx;
		height: 86rpx;
		border-radius: 50%;
		margin: 0 auto;
		background: #9b0000 !important;
	}

	.home .pictrue .image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
		/* transform: rotate(90deg);
		ms-transform: rotate(90deg);
		moz-transform: rotate(90deg);
		webkit-transform: rotate(90deg);
		o-transform: rotate(90deg); */
	}

	.logo {
		height: 60rpx;
		width: 60rpx;
		background: none;
		margin: 0;
		padding: 0;
	}

	.logo::after {
		border: none;
	}

	.dd {
		display: flex;
		/* justify-content: space-around; */
	}
</style>