<template>
	<mobile-frame>
		<view class="main">
			<view class="one">
				<view class="one_1" v-if="barActive=='0'">
					<view class="first">
						<image class="image" :src="info.logo&&info.logo.length>0?info.logo[0].url:''" mode=""></image>
					</view>
					<view class="second">
						<scroll-view scroll-y="true" class="scroll-view">
							<view class="list-scroll-view">
								<view class="list" v-for="(item,index) in shoplist" :key="index" @tap="toBuy(item)">
									<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
									<view class="name">
										{{item.name}}
									</view>
									<view class="other">
										<view class="money">
											<text>¥</text>
											<text>{{item.sell_money}}</text>
										</view>
										<view class="btn">
											<button type="default" size="mini">购买</button>
										</view>
									</view>
								</view>
							</view>
						</scroll-view>
					</view>
				</view>
				<view class="one_3" v-else-if="barActive=='1'">
					<view class="first">
						<input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索商品">
					</view>
					<view class="second">
						<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
							<view class="list-scroll-view">
								<view class="second_1">
									<view :class="['list',condActive==index?'activeList':'']" v-for="(item,index) in condList" :key="index" @tap="toCond(index,item)">
										<view class="name">
											{{item.name}}
										</view>
										<view class="icon">
											<view class="icon_1">
												<text :class="['iconfont',item.shangActive]" v-if="condActive==index&&shang==true"></text>
												<text :class="['iconfont',item.shang]" v-else></text>
											</view>
											<view class="icon_1">
												<text :class="['iconfont', item.xiaActive]" v-if="condActive==index&&xia==true"></text>
												<text :class="['iconfont', item.xia]" v-else></text>
											</view>
										</view>
									</view>
								</view>
								<view class="second_2">
									<view class="list" v-for="(item,index) in allList" :key="index">
										<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
										<view class="sale" v-if="item.is_sale==true">
											<text>已售尽</text>
										</view>
										<view class="name">
											{{item.name}}
										</view>
										<view class="other">
											<view class="money">
												<text>¥</text>
												<text>{{item.sell_money}}</text>
											</view>
											<view class="other_1">{{item.evaluate||0}}人评价</view>
											<view class="btn" v-if="item.is_sale==false">
												<text class="iconfont icon-gouwuche"></text>
											</view>
										</view>
									</view>
								</view>
							</view>
						</scroll-view>
					</view>
				</view>
				<view class="one_4" v-else-if="barActive=='2'">
					<view class="first">
						<image class="image" :src="info.logo&&info.logo.length>0?info.logo[0].url:''" mode=""></image>
						<view class="name">{{info.name}}</view>
					</view>
					<view class="second">
						<view class="second_1">
							<view class="grade">
								<view>{{info.goods_score||0}}</view>
								商品
							</view>
							<view class="grade">
								<view>{{info.send_score||0}}</view>
								发货
							</view>
							<view class="grade">
								<view>{{info.service_score||0}}</view>
								服务
							</view>
						</view>
						<view class="second_2">
							<view class="second_2_bor">
								<image class="image" :src="info.logo&&info.logo.length>0?info.logo[0].url:''" mode=""></image>
							</view>
							<view class="txt">
								店铺二维码
							</view>
						</view>
					</view>
					<view class="collect">
						<text v-if="!collection" @click="toCollect" class="iconfont icon-yduishoucangkongxin"></text>
						<text v-else @click="toCollect" class="iconfont icon-yduishoucangshixin"></text>
					</view>
				</view>
			</view>
			<view class="two">
				<view class="list" v-for="(item,index) in barList" :key="index" @tap="barChange(index,item)">
					<view class="icon">
						<text :class="['iconfont',barActive==index?item.acticon:item.icon]"></text>
					</view>
					<view :class="['name',barActive==index?'activename':'']">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				barActive: '0',
				barList: [ //底部菜单
					{
						icon: 'icon-shangdian',
						acticon: "icon-shangdian-copy",
						name: '微店首页'
					},
					{
						icon: 'icon-shangpinfenlei',
						acticon: "icon-shangpinfenlei-copy",
						name: '全部商品'
					}, 
					{
						icon: 'icon-qiyejianjie',
						acticon: "icon-qiyejianjie-copy",
						name: '店铺简介'
					}
				],
				// 店铺信息
				info: {},
				// 店铺部分商品
				shoplist: [],
				active: '0',
				typeList: [ //
					{
						label: '进口食品'
					}
				],
				list: [ //
					{
						label: '进口食品'
					}
				],
				// 收藏
				collection: false,
				searchInfo: {},
				allList: [ //
					{
						"_id": "63353758101f3c01048c4f61",
						"file": [{
							"id": "20220929141236",
							"name": "f0e22552dddcf494f9720c655a8420a.png",
							"uri": "/files/point/goods/20220929141236.png",
							"url": "https://broadcast.waityou24.cn/files/point/goods/20220929141236.png",
							"uid": 1664431956868,
							"status": "success"
						}],
						"name": "test",
						"sell_money": 0.1
					}
				],
				condActive: 0,
				shang: false,
				xia: false,
				condList: [ // 筛选
					{
						name: '默认',
					},
					{
						name: '销量',
						shang: 'icon-shangjiantou',
						shangActive: 'icon-shangjiantou-copy',
						xia: 'icon-xiajiantou',
						xiaActive: 'icon-xiajiantou-copy'
					},
					{
						name: '价格',
						shang: 'icon-shangjiantou',
						shangActive: 'icon-shangjiantou-copy',
						xia: 'icon-xiajiantou',
						xiaActive: 'icon-xiajiantou-copy'
					},
					{
						name: '浏览量',
						shang: 'icon-shangjiantou',
						shangActive: 'icon-shangjiantou-copy',
						xia: 'icon-xiajiantou',
						xiaActive: 'icon-xiajiantou-copy'
					}
				]
			};
		},
		onLoad: function(e) {
			const that = this;
			that.$set(that, `id`, e.id || '6333d71d32c5f69745f9bd32');
			that.search()
		},
		onShow: function() {},
		methods: {
			// 查询信息
			async search() {
				const that = this;
				if (that.id) {
					// 查询店铺信息
					const res = await that.$api(`/shop/${that.id}`, 'GET');
					if (res.errcode == '0') that.$set(that, `info`, res.data);
					// 查询店铺商品
					that.searchShopMarket();
				}
			},
			// 查询店铺商品
			async searchShopMarket() {
				const that = this;
				const res = await that.$api(`/viewGoods/indexGoodsList`, 'GET', {
					shop: that.id,
					skip: 0,
					limit: 20
				})
				if (res.errcode == '0') that.$set(that, `shoplist`, res.data);
			},
			// 购买
			toBuy(item) {
				if (item && item._id) {
					uni.navigateTo({
						url: `/pagesHome/order/detail?id=${item._id}`
					})
				}
			},
			// 选择底部菜单
			barChange(index, item) {
				const that = this;
				that.$set(that, `barActive`, index);
				uni.setNavigationBarTitle({
					title: item.name
				});
			},
			// 公共跳转
			toCommon(e) {
				uni.navigateTo({
					url: `/${e}`
				})
			},
			// 输入框
			toInput(e) {
				const that = this;
				that.$set(that.searchInfo, `name`, e.detail.value)
			},
			toChange(index, e) {
				const that = this;
				that.$set(that, `active`, index);
				// that.searchRight(e);
			},
			// 筛选
			toCond(index, e) {
				const that = this;
				that.$set(that, `condActive`, index);
				if (that.xia == false) {
					that.$set(that, `shang`, false);
					that.$set(that, `xia`, true);
				} else if (that.xia == true) {
					that.$set(that, `shang`, true);
					that.$set(that, `xia`, false);
				}
			},
			// 收藏
			toCollect() {
				const that = this;
				that.collection = !that.collection;
				if (that.collection == true) {
					uni.showToast({
						title: `收藏成功`,
						icon: 'none'
					})
				} else {
					uni.showToast({
						title: `取消成功`,
						icon: 'none'
					})
				}
			},
			// 分页
			toPage() {}
		}
	}
</script>

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

		.one {
			position: relative;
			flex-grow: 1;

			.one_1 {
				display: flex;
				flex-direction: column;
				width: 96vw;
				height: 90vh;
				padding: 2vw;
				background-color: var(--fFB1Color);

				.first {
					margin: 0 0 2vw 0;

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

				.second {
					position: relative;
					flex-grow: 1;

					.list {
						margin: 0 2vw 2vw 0;
						background-color: var(--fffColor);
						padding: 2vw;
						width: 43vw;
						border-radius: 5px;

						.image {
							width: 100%;
							height: 49vw;
							margin: 0 0 1vw 0;
						}

						.name {
							font-size: var(--font15Size);
							margin: 0 0 2vw 0;
						}

						.other {
							display: flex;
							flex-direction: row;
							justify-content: space-between;

							.money {
								color: var(--ff0Color);

								text:nth-child(1) {
									font-size: var(--font12Size);
								}
							}

							.btn {
								button {
									border-radius: 25px;
									color: var(--fffColor);
									background-color: var(--ff0Color);
									font-size: var(--font12Size);
								}
							}
						}
					}

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

			.one_2 {
				height: 91vh;
				display: flex;
				flex-direction: row;
				padding: 2vw;

				.first_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);
					}
				}

				.first_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;
							}
						}
					}
				}
			}

			.one_3 {
				display: flex;
				flex-direction: column;
				width: 100vw;
				height: 90vh;

				.first {
					border-bottom: 1px solid var(--f85Color);
					padding: 2vw;

					input {
						padding: 2vw;
						background-color: var(--f1Color);
						font-size: var(--font14Size);
						border-radius: 5px;
					}
				}

				.second {
					position: relative;
					flex-grow: 1;

					.second_1 {
						width: 96vw;
						background-color: var(--fffColor);
						padding: 2vw;
						display: flex;
						flex-direction: row;
						justify-content: space-around;

						.list {
							display: flex;
							flex-direction: row;

							.icon {
								position: relative;
								top: -5px;
								left: 2px;

								.icon_1 {
									height: 10px;

									.iconfont {
										font-size: 12px;
									}
								}
							}
						}

						.activeList {
							.name {
								color: #ff0000;
							}

						}
					}

					.second_2 {
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						padding: 2vw 2vw 0 2vw;
						background-color: var(--f1Color);

						.list {
							position: relative;
							width: 43vw;
							margin: 0 2vw 2vw 0;
							padding: 2vw;
							border-radius: 9px;
							background-color: var(--fffColor);

							.image {

								width: 100%;
								height: 40vw;
							}

							.sale {
								position: absolute;
								top: 18vw;
								text-align: center;
								width: 43vw;

								text {
									background-color: #0000005f;
									border-radius: 90px;
									display: inline-block;
									width: 15vw;
									height: 15vw;
									color: var(--fffColor);
									text-align: center;
									line-height: 15vw;
								}
							}

							.name {
								font-size: var(--font16Size);
								margin: 0 0 1vw 0;
							}

							.other {
								display: flex;
								flex-direction: row;
								justify-content: space-between;

								.money {
									font-size: var(--font14Size);
									color: var(--ff0Color);

									text:nth-child(1) {
										font-size: var(--font12Size);
									}
								}

								.other_1 {
									flex-grow: 1;
									margin: 0 0 0 2vw;
									font-size: var(--font12Size);
									color: var(--f85Color);
								}

								.btn {
									button {
										font-size: var(--font20Size);
									}
								}
							}
						}

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


					}
				}
			}

			.one_4 {
				.first {
					display: flex;
					flex-direction: column;
					align-items: center;
					background-color: var(--fFB1Color);
					border-bottom-right-radius: 10vw;
					border-bottom-left-radius: 10vw;

					.image {
						width: 20vw;
						height: 20vw;
						border-radius: 20vw;
					}

					.name {
						margin: 2vw 0;
						font-size: var(--font16Szie);
						font-weight: bold;
						color: var(--mainColor);
					}
				}

				.second {
					margin: 2vw 0;

					.second_1 {
						display: flex;
						justify-content: space-evenly;

						.grade {
							display: flex;
							flex-direction: column;
							align-items: center;
							color: var(--f85Color);
							font-size: var(--font13Size);

							view {
								margin: 1vw 0 0 0;
								color: var(--ff0Color);
							}
						}
					}

					.second_2 {
						display: flex;
						justify-content: center;
						flex-direction: column;
						margin: 15vw 25vw 0 25vw;
						text-align: center;
						background: #b2b2b2;
						padding: 2vw;
						border-radius: 5px;

						.second_2_bor {
							.image {
								width: 100%;
								height: 40vw;
							}
						}

						.txt {
							color: #fff;
							font-size: 14px;
							margin: 2vw 0;
						}
					}
				}
			}

			.collect {
				position: fixed;
				top: 0;
				right: 2vw;

				.iconfont {
					font-size: 25px;
				}
			}
		}

		.two {
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			border-top: 1px solid #f1f1f1;

			.list {
				padding: 1vw 0;
				text-align: center;

				.icon {}

				.name {
					font-size: 12px;
				}

				.activename {
					color: var(--fFB1Color);
				}
			}
		}
	}

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

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