<template>
	<view class="category-container clearfix" :style="{paddingTop:CustomBar+'px'}">
		<cm-custom :navbar-data='nvabarData'></cm-custom>
		<!-- 头部轮播 -->
		<tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading	="true" :loadingType="5"></tui-skeleton>
		<view class="category-list tui-skeleton">
			<!--顶部搜索导航栏-->
<!-- 		<view class="'search-input-fixed">
				<bt-search :clickPath="clickPath" :toestText='hotSearchText'></bt-search>
			</view> -->
			<!-- 左侧分类导航 -->
			<scroll-view class="left-aside" scroll-y="true" scroll-with-animation :scroll-top="verticalNavTop" style="height:calc(100vh - 202rpx)" :style="{top:CustomBar+'px'}">
				<view class="row" v-if="m.smalltypeList.length > 0" v-for="(m, index) in categoryList" :key="index" :class="[index==showCategoryIndex?'on':'']" @tap="showCategory($event,index)" :data-id="index">
					<view class="text tui-skeleton-fillet">
						{{m.name}}
					</view>
					<view class="block"></view>
				</view>
			</scroll-view>
			<!--右侧子导航-->
			<scroll-view  scroll-y="true" class="right-aside" style="height:calc(100vh - 202rpx)" :style="{top:CustomBar+'px'}">
				<view class="category" v-if="n.smalltypeList.length > 0" v-for="(n,index) in categoryList" :key="index" v-show="index==showCategoryIndex" >
					<view class="category-box" v-for="(o,oIndex) in n.smalltypeList" :key="oIndex">
						<view class="title tui-skeleton-fillet">{{o.name}}</view>
						<view class="list" v-if="o.tinytypeList.length > 0">
							<view class="box" v-for="(pro,proIndex) in o.tinytypeList" :key="proIndex" @click.stop="navToListPage(pro,proIndex)">
								<image :src="pro.icon" class="tui-skeleton-fillet"></image>
								<view class="text tui-skeleton-fillet">{{pro.name}}</view>
							</view>
						</view>
						<view v-else class="no-data">
							该栏目暂无分类~
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	import btSearch from '@/components/uni-search/bt-search.vue'
	import { queryGoodscategory } from "@/api/product.js"

	export default {
		components: {
			btSearch,
		},
		data() {
			return {
				nvabarData: {		//顶部自定义导航
					title: '商品分类',  // 导航栏 中间的标题
					haveBack:false,
					textLeft:this.$store.state.isIphone,
					textColor:'#333333',
					bgColor:'#FFFFFF'
				},
				isIphoneX:this.$store.state.isIphoneX,
				CustomBar:this.CustomBar,// 顶部导航栏高度
				skeletonShow: true,
				headerShow:true,
				hotSearchText: '你想要的这里都有',
				clickPath:'/pages/search/search',
				showCategoryIndex: 0,
				categoryList: [],//分类列表
				search: '',
				cateTop: {},
				verticalNavTop: 0,
				CustomBar:this.CustomBar,// 顶部导航栏高度
			}
		},
		created() {
			this.getProductCate();
		},
		methods: {
			// 跳转至商品列表
			navToList(id){
				this.$api.navigateTo(`/pages/product/list?cate_id=${id}`)
			},
			// 获取商品分类列表
			getProductCate () {
				queryGoodscategory().then(res =>{
					this.categoryList = res.data
					// 查询第一个拥有二级菜单的子菜单
					for (let i = 0; i < this.categoryList.length; i++) {
						if (this.categoryList[i].smalltypeList.length > 0) {
							this.showCategoryIndex = i;
							break;
						}
					}
					this.skeletonShow = false;
				}).catch(res =>{
					this.$util.msg(res.msg,2000);
				})
			},
			showCategory(e,index){//分类切换显示
				this.showCategoryIndex = index;
				this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
			},
			toSearch () {// 跳转至搜索详情页
				uni.navigateTo({
					url: `/pages/search/search?search=${JSON.stringify(this.search)}`
				})
			},
			navToListPage(pro,index){//分类导航跳转
				let self = this;
				uni.setStorage({
					key: 'commodity_id',
					data: pro.tinyTypeID,
					success: function () {
						self.$api.navToListPage({type:'4',value:pro.name,id:pro.tinyTypeID});
					}
				})
			}
		}
	}
</script>
<style scoped lang="scss">
	page {
		background-color: #fff;
	}
	.search-input-fixed{
		width: 100%;
		height:auto;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1000;
		background: #FFFFFF;
		border-bottom: 1px solid #F7F7F7;
	}	
	.category-container{
		height: 100%;
	}
	/*模块分类*/
	.category-list{
		width: 100%;
		background-color: #fff;
		display: flex;
		
		.left-aside,.right-aside{
			position: absolute;
			/*  #ifdef  APP-PLUS  */
			top: calc(100rpx + var(--status-bar-height));
			/*  #endif  */
			bottom: 0rpx;
		}
		.left-aside{
			width: 200rpx;
			left: 0rpx;
			background-color: #f2f2f2;
			.row{
				width: 100%;
				height: 100rpx;
				display: flex;
				align-items: center;
				position: relative;
				.text{
					width: 100%;
					position: relative;
					font-size: $font-size-28;
					display: flex;
					justify-content: center;
					color: $text-color;
					/* transition: transform 0.3s ease;*/
					transition-property: transform;
					transition-duration: 0.2s;
					transition-timing-function: ease;
				}
				.block{
					position: absolute;
					width: 0rpx;
					left: 0;
					/* transition: transform 0.3s ease;*/
					transition-property: transform;
					transition-duration: 0.2s;
					transition-timing-function: ease;
				}
				&.on{
					height: 100rpx;
					background-color: #fff;
					.text{
						font-size: $font-size-28;
						color: $color-system;
					}
					.block{
						width: 10rpx;
						height: 60rpx;
						top: 20rpx;
						background-color: $color-system;
						border-radius: 0 15rpx 15rpx 0;
					}
				}
			}
		}
		.right-aside{
			width: 550rpx;
			left: 200rpx;
			background: #FFFFFF;
			.category{
				width: calc(100%);
				padding: 0 15rpx 20rpx 0;
				background: #F7F7F7;
				.category-box{
					background: #FFFFFF;
					margin-bottom: 20rpx;
					.title{
						padding: 0 24rpx;
						line-height: 80rpx;
						height: 80rpx;
						text-align: left;
						color: $text-color;
						font-size: $font-size-26;
						border-bottom: 1px solid #F7F7F7;
						font-weight: 600;
					}
					.list{
						margin-top: 24rpx;
						width: 100%;
						display: flex;
						flex-wrap: wrap;
						.box{
							width: calc(71.44vw / 3);
							margin-bottom: 40rpx;
							display: flex;
							justify-content: center;
							align-items: center;
							flex-wrap: wrap;
							image{
								width: 140rpx;
								height: 140rpx;
							}
							.text{
								margin-top: 8rpx;
								width: 100%;
								display: flex;
								justify-content: center;
								font-size: $font-size-24;
							}
						}
					}
					.no-data {
						text-align: center;
						margin: 30rpx 0;
						color: #999999;
						font-size: 24rpx;
						line-height: 80rpx;
					}
				}
			}
		}
	}
</style>
