<template>
	<view class="wanlshophead-container" :style="{ height: `${headHeight}px`, paddingTop:`${headTop}px` }">
		
		<!-- 1.1.9 升级 其他页面进入 -->
		<view v-if="pagesNum > 1" class="text-xl text-bold" @tap="handleBack()">
			<text class="wlIcon-fanhui1"></text>
		</view>
		<!-- 直接进入 -->
		<view v-else class="text-xl text-bold" @tap="handleHome()">
			<text class="wlIcon-zhuye"></text>
		</view>
		
		<view class="content">
			<view v-if="tabbarId === 'home'" class="home">
				<view :class="{active: headTabbarId === 'page'}" @tap="handleHeadTabbarId('page')">
					<text>推荐</text>
				</view>
				<view :class="{active: headTabbarId === 'news'}" @tap="handleHeadTabbarId('news')">
					<text>新品</text>
				</view>
				<view :class="{active: headTabbarId === 'groups'}" @tap="handleHeadTabbarId('groups')">
					<text>拼团</text>
				</view>
			</view>
			<view v-else class="search round" @tap="handleSearch">
				<text class="wlIcon-sousuo1 text-bold margin-left-bj margin-right-xs"></text>
				<text>搜索店铺内宝贝</text>
			</view>
		</view>
		<view class="text-xl">
			<text @tap="handleSearch" v-if="tabbarId === 'home'" class="wlIcon-sousuo1 margin-right"></text>
			<text @tap="showModal('menu')" class="wlIcon-gengduo"></text>
		</view>
		<!-- 模态框 -->
		<view class="WANL-MODAL wanlgroups-user-container__modal">
			<view class="cu-modal top-modal" :class="modalName == 'menu' ? 'show' : ''" @tap="hideModal()">
				<view class="wanl-modal-menu cu-dialog" @tap.stop="">
					<wanl-direct @change="hideModal" />
				</view>
			</view>
			<!-- 分享 -->
			<view class="cu-modal wanl-share bottom-modal" :class="modalName == 'share' ? 'show' : ''" @tap="hideModal()">
				<view class="cu-dialog" @tap.stop="">
					<wanl-share
						ref="wanlShare"
						page="pages/shop/index"
						:scene="{id: shopId, qr:'s'}"
						:scrollAnimation="scrollAnimation" 
						:shareTitle="shopDescription"
						@change="hideModal()"
					/>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "WanlShopHead",
		props: {
			headHeight: {
				type: Number,
				default: 0
			},
			headTop: {
				type: Number,
				default: 0
			},
			shopId: {
				type: Number,
				default: 0
			},
			shopDescription: {
				type: String,
				default: "我发现了一个很好的店铺"
			},
			pagesNum: {
				type: Number,
				default: 0
			},
			tabbarId: {
				type: String,
				default: ""
			},
			headTabbarId: {
				type: String,
				default: "page"
			}
		},
		data() {
			return {
				modalName: null,
				scrollAnimation: 300
			}
		},
		methods: {
			handleBack() {
				this.$wanlshop.back(1);
			},
			handleHome() {
				this.$wanlshop.on('/pages/index');
			},
			// 弹出层
			showModal(name) {
				// 滚动下分享
				if (name == 'share' && this.modalName != 'share') {
					setTimeout(() => {
						this.scrollAnimation = 300;
					}, 300);
				}
				this.modalName = name;
			},
			hideModal(name) {
				if (name) {
					this.showModal(name);
				} else {
					// 强制关闭海报
					if(this.modalName == 'share'){
						this.$refs.wanlShare.closePoster();
					}
					this.modalName = null;
				}
			},
			handleHeadTabbarId(name){
				this.$emit('headId', name);
			},
			handleSearch() {
				this.$wanlshop.to(`/pages/shop/product/list?shop_id=${this.shopId}`, 'fade-in', 100);
			}
		}
	}
</script>

<style lang="scss">
	.wanlshophead-container {
		position: relative;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-left: 22rpx;
		padding-right: 24rpx;
		/* #ifdef MP */
		padding-right: 200rpx;
		/* #endif */

		.content {
			flex: 1;

			.home {
				display: flex;
				align-items: center;
				margin: 0 25rpx;
				font-size: 32rpx;
				color: #555;
				&>view + view{
					margin-left: 40rpx;
				}
				.active{
					color: #333;
					font-size: 38rpx;
					font-weight: 600;
				}
			}

			.search {
				display: flex;
				align-items: center;
				margin: 0 25rpx;
				background-color: #f9f9f9;
				line-height: 68rpx;
				height: 68rpx;
				color: grey;
			}

		}
	}
</style>