<template>
	<view class="page">
		<!-- 导航栏 -->
		<navbar title="商品列表" 
		leftClick 
		@leftClick="$utils.navigateBack" 
		bgColor="#E3441A" 
		color="#fff" />

		<!-- 搜索栏 -->
		<view class="search">
			<uv-search placeholder="搜你喜欢的产品" bgColor="#fff" 
			@search="search" 
			@change="search" 
			@custom="search"
			v-model="queryParams.title"></uv-search>
		</view>
		
		<!-- 商品列表 -->
		<view style="position: 20rpx;"
		v-if="queryParams.title">
			<productList :list="list" />
		</view>

		<!-- 分类商品列表 -->
		<view class="category"
		v-else>
			
			<view class="tabs">
				<uv-tabs 
				:list="category" 
				:activeStyle="{color : '#f00', fontWeight : 600}" 
				lineColor="#f00"
				:inactiveStyle="{color: 'rgba(0,0,0,.8)'}" 
				lineHeight="8rpx" 
				lineWidth="50rpx" 
				:current="current"
				@click="clickTabs"></uv-tabs>
			</view>
		
			<uv-vtabs 
			:list="category[current].children" 
			:current="currentChildren"
			keyName="name" 
			:chain="false"
			@change="change">
				<!-- <view class="list"> -->
					<!-- <template v-for="(item, index) in category[current].children">
							<uv-vtabs-item :index="index" :key="index">
								<view class="category-item">
									<view class="category-title">
										{{ item.name }}
									</view>
									
									<productItem :item="pro"
									v-for="(pro, i) in item.shopList" :key="i"
									@click="$utils.navigateTo(`/pages_order/product/productDetail?id=${pro.id}`)" />
								</view>
						</uv-vtabs-item>
					</template> -->
				<!-- </view> -->
				
				<uv-vtabs-item>
					<view class="category-item">
						<productItem :item="pro"
						v-for="(pro, i) in categoryList.shopList" :key="i"
						@click="$utils.navigateTo(`/pages_order/product/productDetail?id=${pro.id}`)" />
					
						<uv-empty v-if="categoryList.shopList.length == 0"  text="还没有呢"/>
					</view>
				</uv-vtabs-item>
			</uv-vtabs>
		</view>

		<!-- tabbar -->
		<tabber select="category" />
	</view>
</template>

<script>
	import productItem from '@/components/product/productItem.vue';
	import mixinsList from '@/mixins/list.js'
	import {
		mapState
	} from 'vuex'
	import tabber from '@/components/base/tabbar.vue'
	import productList from '@/components/user/productList.vue'
	export default {
		mixins: [mixinsList],
		components: {
			productItem,
			tabber,
			productList,
		},
		data() {
			return {
				mixinsListApi: 'getClassShopPageList',
				current : 0,
				currentChildren : 0,
			}
		},
		computed: {
			...mapState(['category']),
			categoryList(){
				return this.category[this.current].children[this.currentChildren]
			},
		},
		onLoad({
			search,
			cid
		}) {
			if (search) {
				this.queryParams.title = search
			}
			// this.$store.commit('getCategoryList')
			if(this.category.length > 0 && cid){
				this.category.forEach((n, i) => {
					if(n.id == cid){
						this.current = i
					}
				})
				// this.queryParams.classId = cid
			}else if (this.category.length > 0) {
				// this.queryParams.classId = this.category[0].id
			}
		},
		methods: {
			change(e) {
				// this.queryParams.classId = this.category[e].id
				this.currentChildren = e
			},
			clickTabs({index}){
				this.current = index
				this.currentChildren = 0
			},
			search(){
				for(let i = 0;i < 10;i++){
					delete this.queryParams[i]
				}
				this.queryParams.pageSize = 10
				this.getData()
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		/deep/ .uv-vtabs {
			height: calc(100vh - 600rpx) !important;
		}

		/deep/ .uv-vtabs__bar {
			height: calc(100vh - 600rpx) !important;
		}

		/deep/ .uv-vtabs__content {
			height: calc(100vh - 600rpx) !important;
		}

		.search {
			position: relative;
			background: #FFFFFF;
			margin: 20rpx;
			border-radius: 41rpx;
			padding: 10rpx 20rpx;
			display: flex;
			align-items: center;

			/deep/ .uv-search__action {
				background-color: $uni-color;
				color: #FFFFFF;
				padding: 10rpx 20rpx;
				border-radius: 30rpx;
			}
		}

		&::v-deep .uv-vtabs__content {
			background: transparent !important;
			overflow: hidden;
		}
	}

	.category {
		font-size: 30rpx;
		color: #333;
		.category-title{
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 120rpx;
			
			&::before,
			&::after {
				position: absolute;
				top: 50%;
				content: '';
				width: 10%;
				border-top: 2rpx solid black;
			}
			
			&::before {
				left: 25%;
			}
			
			&::after {
				right: 25%;
			}
		}
		
		&::v-deep .uv-vtabs {
			width: 750rpx;
			overflow: hidden;
		}
		
		.list {
			width: 100%;
			padding: 0rpx 20rpx;
			box-sizing: border-box;
		}

	}
</style>