<template>
	<view>
		<!-- 顶部操作条 -->
		<cu-custom :bgColor="'bg-main-color'" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">产品分类</block>
		</cu-custom>
		<vertical-nav :containerHeight="containerHeight" :list="categoryList" :isClick2ShowProducts="true"></vertical-nav>
	</view>
</template>

<script>
	import verticalNav from '@/components/multi-level-nav/vertical-nav.vue';
	
	export default {
		components: {
			verticalNav
		},
		data() {
			return {
				containerHeight: '100vh - ' + this.CustomBar + 'px',
				categoryList: []
			}
		},
		onLoad() {
			this.loadData();
			this.bindEvent();
		},
		onUnload() {
			this.offBindEvent();
		},
		methods: {
			async loadData() {
				// this.categoryList = await this.$api.data('categoryList');
				this.categoryList = await uni.request({
					url: '/goods/category/list',
					method: 'POST'
				})
			},
			bindEvent() {
				uni.$on(this.$globalFun.VERTICAL_NAV_GET_ITEM, this.chooseSubType);
				uni.$on(this.$globalFun.VERTICAL_NAV_SEARCH, this.searchType);
			},
			offBindEvent() {
				uni.$off(this.$globalFun.VERTICAL_NAV_GET_ITEM);
				uni.$off(this.$globalFun.VERTICAL_NAV_SEARCH);
			},
			chooseSubType(item) {
				let params = {
					type: 1
				}
				uni.navigateTo({
					url: '/pages/product/filtered-products?params=' + encodeURIComponent(JSON.stringify(params))
				})
			},
			searchType(keyWords) {
				console.log("搜索" + keyWords)
			}
		}
	}
</script>

<style>
</style>
