<template>
	<mobile-frame :frameStyle="frameStyle" @toPath="toPath">
		<view class="main">
			<view class="one">
				<input type="text" placeholder="搜索商品" @tap="toCommon('pagesHome/market/search')"
					placeholder-class="placss">
			</view>
			<view class="two">
				<view class="two_1">
					<scroll-view scroll-y="true" class="scroll-view">
						<view class="list-scroll-view">
							<view class="list" :class="[active==index?'listActive':'']" v-for="(item,index) in typeList"
								:key="index" @tap="toChange(index,item)">
								<text>{{item.label}}</text>
							</view>
						</view>
					</scroll-view>
				</view>
				<view class="two_2">
					<scroll-view scroll-y="true" class="scroll-view">
						<view class="list-scroll-view">
							<view class="list" v-for="(item,index) in list" :key="index"
								@tap="toCommon('pagesHome/market/search',item)">
								<view class="title">
									{{item.label}}
								</view>
								<view class="market" v-if="item.children&&item.children.length>0">
									<view class="marketList" v-for="(tag,indexs) in item.children" :key="indexs"
										@tap.stop="toCommon('pagesHome/market/search',tag)">
										<image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''"
											mode=""></image>
										<view class="name">
											{{tag.label}}
										</view>
									</view>
								</view>
								<view class="market" v-else>
									<view class="marketList" @tap.stop="toCommon('pagesHome/market/search',item)">
										<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''"
											mode=""></image>
										<view class="name">
											{{item.label}}
										</view>
									</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				frameStyle: {
					useBar: true
				},
				active: '0',
				typeList: [],
				list: []
			};
		},
		onLoad: function() {
			const that = this;
			that.searchOther();
		},
		methods: {
			async searchOther() {
				const that = this;
				let res;
				res = await that.$api(`/goodsTags`, 'GET', {
					status: '0'
				})
				if (res.errcode == '0') {
					that.$set(that, `typeList`, res.data);
					if (res.total > 0) that.searchRight(res.data[0]);
				}
			},
			toChange(index, e) {
				const that = this;
				that.$set(that, `list`, []);
				that.$set(that, `active`, index);
				that.searchRight(e);
			},
			// 查询左侧信息
			async searchRight(e) {
				const that = this;
				let info = {};
				if (e.id) info.pid = e.id;
				const res = await that.$api(`/goodsTags/tree`, 'GET', {
					...info
				})
				if (res.errcode == '0' && res.data.length > 0) {
					that.$set(that, `list`, res.data[0].children)
				}
			},
			// 公共跳转
			toCommon(e, code) {
				uni.navigateTo({
					url: `/${e}?tags=${code.code}`
				})
			},
			// 菜单跳转
			toPath(e) {
				if (e && e.route && e.type == '0') {
					uni.redirectTo({
						url: `/${e.route}`
					})
				} else {
					uni.navigateTo({
						url: `/${e.route}`
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 91vh;

		.one {
			padding: 2vw;
			border: 1px solid var(--f1Color);

			input {
				background-color: var(--fFB1Color);
				border-radius: 30px;
				padding: 2vw;
				color: var(--fffColor);
				font-size: var(--font15Size);
			}

			.placss {
				color: var(--fffColor);
			}
		}

		.two {
			height: 83vh;
			display: flex;
			flex-direction: row;

			.two_1 {
				position: relative;
				width: 25vw;
				background-color: #fafafa;
				display: flex;
				flex-direction: column;

				.list {
					text-align: center;
					padding: 2.5vw 0;
					border-bottom: 1px solid var(--f1Color);

					text {
						font-size: var(--font14Size);
					}
				}

				.listActive {
					background-color: var(--fffColor);
				}
			}

			.two_2 {
				padding: 2vw;
				flex-grow: 1;
				position: relative;
				display: flex;
				flex-direction: column;

				.list {
					margin: 0 0 2vw 0;
					padding: 2vw;

					.title {
						font-size: var(--font16Size);
						margin: 0 0 2vw 0;
					}

					.market {
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;

						.marketList {
							text-align: center;
							margin: 0 2vw 2vw 0;
							width: 22vw;

							.image {
								width: 100%;
								height: 15vw;
							}

							.name {
								font-size: var(--font14Size);
							}
						}

						.marketList:nth-child(3n) {
							margin: 0 0 2vw 0;
						}
					}
				}
			}
		}
	}

	.scroll-view {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.list-scroll-view {
			display: flex;
			flex-direction: column;
		}
	}
</style>
