<template>
	<view>
		<!-- 状态栏 -->
		<view class="status" :style="{position:headerPosition}"></view>
		<view class="header" :style="{position:headerPosition}">
			<view class="addr">
				<view class="icon location"></view>{{city}}
			</view>
			<view class="input-box">
				<input placeholder="默认关键字" placeholder-style="color:#c0c0c0;" @tap="toSearch()" />
				<view class="icon search"></view>
			</view>
			<!-- <view class="icon-btn"> -->
				<!-- <view class="icon yuyin-home"></view> -->
				<!-- <button open-type="contact" class="icon"  show-message-card session-from send-message-path send-message-title> -->
				<!-- <image style="width: 30px;height: 30px;" @click="toScan"
					src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAGv0lEQVR4Xu2dgXHUSBBFWxFABuAIgAjgIsBEwBEBvRHgi2D7IsCO4EwEQARnIjgcARCBrj43WyV0s961u1vWSH+qXK6yd1rdv59Go1lNqxO2VSvQrTp6Bi8EYOUQEAACsHIFVh4+RwACsHIFVh4+RwACsHIFVh4+RwACsHIFVh4+RwACsHIFVh4+RwACsHIFVh4+RwACkKuAqj7uuu553/enIvJQRF4kHvGriPxhZucZx1DV30XknYg8zrBfbH4Ske9d1132ff/ZzBBTWksbAZD4IhZEm7qdRAtX4vln6kBEBDAD6hQQUgAoZ8r7exBrd8jfzAxnUlhTVYxcH8MM3t7Qm4yRLRwAVUXi7+OsH0q6RAAQ37mZvbk9O/t7hAIwk+R/MDPMN8Kbql6KyMtww7czGApBGABHDPvXInJVfkKH56F+0UP/ODflUnC7lB3/aVxmnpafRzd0C7schABwYIL0Q0TOzMyO14GfVFWFbiLyYI8aIRPdKAAwU31dcfSLiJxmzWCXjomqYjSAtk8qsV6YmXuu5QbghrMfZ/5TJt+HaYEAl8zaSOAeBSIAwFC1rYS54bDvS/6ud7kc1DR2zwUiAKjNjK/NLHO1LEbZhqyoKhaCxhND9x1PBAAYnp6PtHQ71lBuJnF1zy0olopdS+sRAPQVBbB0iRksW5ACqgo98T3EL83MXDl0dYYnqloDIHwlLkjHZs2oKha3/iIAz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IofYwkwI7oBCSf77yu5rWLswM7xAytUiAfj5JisReTIeCbquO9tut3+6PF1Z581m87bve5xU+94L6D77IWkYAGUUgLM42x9U8oW/Y0S46roOoKS07XaLEqtpbbPZZJW8fdj3PWoA7H5uqrDuvvbvBAoFoECAAJDgGgRpiRkYvjSzVxkHUlUsxNz37W3I0J8GwGAkqF0OMvJSsxm+ErlvKXaqgMpxQpMffgkYilHeconbl/+tXk0g2hIBCBv2h/qHXwLGycX7gkQEk5nxcnEmByETpBHQtVvdzBh2ti+gX9adVDoAuyjKiPCiXEMhJiaM4zsGr6DXRSwsTIW38v4jwJz5AixMYrGGgqVfvB849RZ6MgDCs0GDIQoQgBAZ2zVCANrNXYjnBCBExnaNEIB2cxfiOQEIkbFdIwSg3dyFeE4AQmRs1wgBaDd3IZ4TgBAZ2zVCANrNXYjnBCBExnaNEIB2cxfiOQEIkbFdIwSg3dyFeE4AQmRs18i/zMYNrphXcJEAAAAASUVORK5CYII=">
				</image> -->
				<!-- </button> -->
			<!-- </view> -->
		</view>
		<!-- 占位 -->
		<view class="place"></view>
		<view class="category-list">
			<!-- 左侧分类导航 -->
			<scroll-view scroll-y="true" class="left">
				<view class="row" v-for="(mers,index) in MerchantList" :key="mers.id"
					:class="[index==showCategoryIndex?'on':'']" @click="showCategory(index,mers.id)">
					<view class="text">
						<view class="block"></view>
						{{mers.merchantName}}
					</view>
				</view>

			</scroll-view>
			<!-- 右侧子导航 -->
			<scroll-view scroll-y="true" class="right">
				<view class="category">
				<!-- 	<view class="banner">
						<image src="/static/img/banner3.png"></image>
					</view> -->
					<view v-if="categoryList == '' " class="mart60 fotct font14 fcor666">
						<image style="width: 100px;height: 100px;"
							src="data:image/png;base64, ">
						</image>
						<view class="mart10">暂无数据</view>
					</view>
					<view class="list">
						<view class="box" v-for="(box,i) in categoryList" :key="i" @tap="toCategory(box)"
							v-show="i==showCategoryIndex">
							<image :src="imageUrl+box.ext1"></image>
							<view class="text">{{box.storeName}}</view>
						</view>
					</view>
				</view>
				<!-- <view class="loading-text" @click="getCouponList">{{ loadingText }}</view> -->
			</scroll-view>
		</view>
		
	</view>
</template>
<script>
	import {
		getCouponList,
		getStoreListByMerchant,
		getMerchantList
	} from "../../../Utils/Api.js";
	let app = getApp();
	export default {
		data() {
			return {
				showCategoryIndex: 0,
				headerPosition: "fixed",
				city: "",
				imageUrl: app.globalData.imgUrl,
				//分类列表
				categoryList: [],
				MerchantList: [],
				pageNum: 1,
				pageSize: 10,
				isNoMoreData: false
				// loadingText: '点击加载更多'
			}
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = "fixed";
			} else {
				this.headerPosition = "absolute";
			}
		},
		onLoad() {
			this.postionIng();
		},


		methods: {
			postionIng() {
				uni.showLoading({

				})
				let that = this;
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						app.globalData.latitude = res.latitude;
						app.globalData.longitude = res.longitude;
						uni.request({
							url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + res.latitude +
								',' + res.longitude + '&key=YQDBZ-T54K4-5J6U7-DO3BA-CNZJO-PTFMU',
							data: {},
							success: function(res) {
								that.city = res.data.result.address_component.city.replace(/市/g,
									'');
								app.globalData.cityId = res.data.result.ad_info.adcode;
								// app.globalData.cityId =  '500100';
								that.getMerchantList();
								uni.hideLoading()
							}
						})
					}
				})
			},
			// 商户列表
			getMerchantList() {
				uni.showLoading({
					title: '加载中...'
				})

				let params = {
					regionId: app.globalData.cityId
				}
				getMerchantList(params).then(res => {
					if (res.return_code == '000000') {
						this.MerchantList = res.return_data;
						this.getStoreListByMerchant(res.return_data[0].id);
						setTimeout(function() {
							uni.hideLoading();
						}, 2000);
					} else {
						uni.hideLoading()
					}
				})
			},
			//扫码
			toScan() {
				uni.scanCode({
					success: function(res) {
						uni.navigateTo({
							url: '../../goods/coupons-info-details/coupons-info-details?id=' + JSON
								.parse(res.result).code
						})
					},
					fail() {
						uni.showToast({
							title: '无法识别二维码',
							icon: 'none',
							duration: 2000
						})
					}
				});

			},
			//门店列表
			getStoreListByMerchant(item) {
				uni.showLoading({
					title: '加载中...'
				})

				let params = {
					merchantId: item,
					longitude: app.globalData.longitude,
					latitude: app.globalData.latitude
				}
				getStoreListByMerchant(params).then(res => {
					if (res.return_code == '000000') {
						this.categoryList = res.return_data
						setTimeout(function() {
							uni.hideLoading();
						}, 2000);
					} else {
						this.categoryList = [];
						uni.hideLoading()
					}
				})

			},
			//分类切换显示
			showCategory(index, item) {
				this.showCategoryIndex = index;
				this.getStoreListByMerchant(item);
			},
			toCategory(e) {
				uni.navigateTo({
					url: '../../goods/store-list/store-details?id=' + e.id + '&juli=' + e.distance
				})
				// uni.navigateTo({
				// 	url: '../../goods/goods?id=' + e
				// });
			},
			//搜索跳转
			toSearch() {
				uni.navigateTo({
					url: '../../goods/HM-search/HM-search'
				})
				// uni.showToast({title: "建议跳转到新页面做搜索功能"});
			}
		}
	}
</script>
<style lang="scss">
	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #fff;
		top: 0;
		/*  #ifdef  APP-PLUS  */
		height: var(--status-bar-height); //覆盖样式
		/*  #endif  */
	}

	button::after {
		border: none
	}

	.loading-text {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 60upx;
		color: #979797;
		font-size: 24upx;
	}

	.header {
		width: 92%;
		padding: 0 4%;
		height: 100upx;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #fff;
		/*  #ifdef  APP-PLUS  */
		top: var(--status-bar-height);
		/*  #endif  */

		.addr {
			width: 120upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;
			align-items: center;
			font-size: 28upx;

			.icon {
				height: 60upx;
				margin-right: 5upx;
				display: flex;
				align-items: center;
				font-size: 42upx;
				color: #ffc50a;
			}
		}

		.input-box {
			width: 100%;
			height: 60upx;
			background-color: #f5f5f5;
			border-radius: 30upx;
			position: relative;
			display: flex;
			align-items: center;

			.icon {
				display: flex;
				align-items: center;
				position: absolute;
				top: 0;
				right: 0;
				width: 60upx;
				height: 60upx;
				font-size: 34upx;
				color: #c0c0c0;
			}

			input {
				padding-left: 28upx;
				height: 28upx;
				font-size: 28upx;
				width: 100%;
			}
		}

		.icon-btn {
			width: 60upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;

			.icon {
				width: 60upx;
				height: 60upx;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 42upx;
				background-color: transparent;
			}
		}
	}

	.place {

		background-color: #ffffff;
		height: 100upx;
		/*  #ifdef  APP-PLUS  */
		margin-top: var(--status-bar-height);
		/*  #endif  */
	}

	.category-list {
		width: 100%;
		background-color: #fff;
		display: flex;

		.left,
		.right {
			position: absolute;

			top: 100upx;
			/*  #ifdef  APP-PLUS  */
			top: calc(100upx + var(--status-bar-height));
			/*  #endif  */
			bottom: 0upx;
		}

		.left {
			width: 24%;
			left: 0upx;
			background-color: #f2f2f2;

			.row {
				width: 100%;
				height: 90upx;
				display: flex;
				align-items: center;

				.text {
					width: 100%;
					position: relative;
					font-size: 28upx;
					display: flex;
					justify-content: center;
					color: #3c3c3c;

					.block {
						position: absolute;
						width: 0upx;
						left: 0;
					}
				}

				&.on {
					height: 100upx;
					background-color: #fff;

					.text {
						font-size: 30upx;
						font-weight: 600;
						color: #2d2d2d;

						.block {
							width: 10upx;
							height: 80%;
							top: 10%;
							background-color: #f06c7a;
						}
					}
				}
			}
		}

		.right {
			width: 76%;
			left: 24%;

			.category {
				width: 94%;
				padding: 20upx 3%;

				.banner {
					width: 100%;
					height: 24.262vw;
					border-radius: 10upx;
					overflow: hidden;
					box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.3);

					image {
						width: 100%;
						height: 24.262vw;
					}
				}

				.list {
					margin-top: 40upx;
					width: 100%;
					display: flex;
					flex-wrap: wrap;

					.box {
						width: calc(70vw / 2);
						margin-bottom: 30upx;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-wrap: wrap;

						image {
							width: 60%;
							height: calc(70vw / 2 * 0.6);
						}

						.text {
							margin-top: 5upx;
							width: 80%;
							display: flex;
							justify-content: center;
							font-size: 26upx;
						}
					}
				}
			}
		}
	}
</style>
