<template>
	<view class="discountsDetail">
		<zs-img width="100%" height="310rpx" :src="banner"></zs-img>
		
		<!-- titleArr: 选择项数组 dropArr: 下拉项数组 二维数组 @finishDropClick: 下拉筛选完成事件-->
		<cc-dropDownMenu :titleArr="titleArr" :dropArr="dropArr" @finishDropClick="finishClick"></cc-dropDownMenu>

		<!-- 内容 -->
			<zs-list  class="store-box" mt="0" @load="loadMore" :status="status">
			<view class="item" v-for="(item,index) in list" :key="index">
				<!-- <image :src="item.src" mode="" class="icon" @click="goDetail(item)"></image> -->
				<zs-img :src="item.logoPath" width="164rpx" height="164rpx" radius="full" @click.native="goDetail(item)"></zs-img>
				<view class="info">
					<view class="title">
						{{item.shopVo.shopName}}
					</view>
					<view  class="activity" :class="!item.activityContent?'white':''">
						<image class="card" src="../../static/card-icon.png" mode=""></image>
						{{item.activityContent || '-'}}
					</view>
					<view class="address" >
						<image class="position" src="../../static/address-icon.png" mode=""></image>
						距离你{{(item.shopVo.distance/1000).toFixed(2)}}km ·{{item.district}}
					</view>
					
				</view>
			</view>
			</zs-list>
		

		
	</view>
</template>

<script>
	import { search } from '@/api/shop.js';
	export default {
		options: { styleIsolation: 'shared' },
		data() {
			return {
				longitude: '',
				latitude: '',
				destination: '',
				_mapContext: null,
				status:'more',
				list: [],
				btnText:'去使用',
				titleArr: ['全城', '距离最近'],
				dropArr: [
					// 距离
					[
						{
							text: '全城',
							value: "440103"
						}
					],
					
					// 类型
					[
						{
							text: '距离最近',
							value: "40-60"
						}
					],
				],
				banner:'',
				filterResultData: [],
				query:{
					menuId:'',
					queryName:'',
					'location.lat':0,
					'location.lon':0,
					pageCurrent:1,
					pageSize:10
				}
			}
		},
		methods: {
			finishClick(resultData) {
				this.filterResultData = resultData;
			},
	
			goDetail(item){
				uni.setStorageSync('shopInfo',JSON.stringify(item))
				uni.navigateTo({
					url:'../shopDetail/shopDetail'
				})
			},
			loadMore(){
				this.search()
			},
			search() {
				return new Promise((resolve,reject)=>{
					if(this.status == 'noMore') return
					this.status = 'loading'
					search(this.query).then(res=>{
						if(res.state == 'Success'){
							this.list = this.list.concat(res.content.records)
							if(this.list.length >= res.content.total){
								this.status = 'noMore'
							}else{
								this.status = 'more'
								this.query.pageCurrent++
							}
							resolve()
						}
					})
				})
			},
		},
		onPullDownRefresh() {
			this.query.pageCurrent = 1
			this.list = []
			this.status = 'more'
			this.search().then(()=>{
				uni.stopPullDownRefresh()
			})
		},
		onLoad(option) {
			let that = this
			const eventChannel = this.getOpenerEventChannel();
			if(JSON.stringify(eventChannel) !=='{}'){
				eventChannel.on('banner', function(data) {
					that.banner = data
				})
			}
			uni.setNavigationBarTitle({
				title: option.title
			});
			this.query.menuId = option.id
			let location = JSON.parse(uni.getStorageSync('location'))
			this.query['location.lat'] = location.latitude
			this.query['location.lon'] = location.longitude
			this.search()

		},
		
	}
</script>

<style lang="scss">

	.bar-item-text {
		max-width: 250rpx !important;
	}

	.screen-bar::after {
		display: none;
	}
	.discountsDetail  cc-drop-down-menu .screen-bar{
		// position: fixed;
		top: 0%;
		left: 0;
		width: 100%;
	}
	.discountsDetail {
		.banner{
			width: 100%;
			height: 310rpx;
			position: relative;
			z-index: 99;
		}
		.recommend{
			display: flex;
			justify-content: space-between;
			margin: 20rpx 30rpx;
			.recommend-item.color{
				background: linear-gradient(0deg, #FFDA84 0%, #FFF6E1 100%);
				
			}
			.recommend-item{
				padding: 18rpx;
				border-radius: 16rpx;
				width: 335rpx;
				box-sizing: border-box;
				background: linear-gradient(0deg, #FF9898 0%, rgba(255,101,101,0.09) 100%);;
				box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255,255,255,0.16);
				.top{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.title{
						color: #0F0F0F;
						font-size: 26rpx;
					}
					.type-box{
						display: flex;
						align-items: center;
						padding: 0 16rpx;
						height: 40rpx;
						line-height: 40rpx;
						border-radius: 20rpx;
						border: 1rpx solid #FF4343;
						.hot{
							width: 16.7rpx;
							height: 21.7rpx;
						}
						.type{
							font-size: 20rpx;
							font-weight: 400;
							color: #FF4343;
							margin-left: 6rpx;
						}
					}
				}
				.image-box{
					position: relative;
					margin-top: 20rpx;
					background: #fff;
					border-radius: 16rpx;
					display: flex;
					.icon{
						width: 116rpx;
						height: 116rpx;
						margin-left: 15rpx;
					}
					.info{
						padding: 16rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						.title{
							font-size: 20rpx;
							font-weight: bold;
						}
						.btn-box{
							display: flex;
							align-items: center;
							width: 100%;
							font-size: 18rpx;
							height: 36rpx;
							line-height: 36rpx;
							margin-top: 10rpx;
							.btn{
								height: 36rpx;
								line-height: 36rpx;
								padding: 0 14rpx;
								background: #FE5B47;
								color: #FFFFFF;
							}
							.desc{
								height: 36rpx;
								line-height: 36rpx;
								font-weight: 400;
								color: #FF4343;
								padding: 0 18rpx 0 10rpx;
								background: rgba(254, 91, 71, .17);
								border-radius: 0 8rpx 8rpx 0;
							}
						}
					}
				}
			}
		}

		.zs-list {
			// padding-top: 20rpx;
			.item {
				display: flex;
				padding: 20rpx 30rpx;
				background: #fff;
				border-radius: 16rpx;
				margin: 20rpx 30rpx 0;
				border-bottom: 1rpx solid #F0F0F0;
				.icon{
					border-radius: 8px;
				}	
				.info{
					flex: 1;
					padding-left: 20rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					position: relative;
					.title{
						font-size: 28rpx;
						font-weight: bold;
						width: 340rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						margin-top: 10rpx;
					}
					.address{
						color: #bebebe;
						display: flex;
						align-items: center;
						font-size: 24rpx;
						.u-icon{
							align-self: flex-start;
						}
						.position {
								width: 30rpx;
								height: 30rpx;
								margin-right: 8rpx;
							}
					}
					.activity.white{
						color: #fff;
						background: #fff;
						.card{
							display: none;
						}
					}
					.activity{
						font-size: 24rpx;
						color: #FF4D3A;
						line-height: 42rpx;
						display: flex;
						align-items: center;
						background: linear-gradient(90deg, #FAF4EB 0%, rgba(255,235,207,0) 100%);
						.card{
							width: 30.4rpx;
							height: 30rpx;
							vertical-align: bottom;
							margin: 0 8rpx 0 14rpx;
						}
						// text-align: center;
						// background: linear-gradient(90deg, rgba(253,149,108,0) 0%, #FD8B64 50%, rgba(253,140,101,0) 100%);
					}

				}
			}
		}

		#map {
			position: relative;
			top: -100000px;
			left: -1000000px;
		}
	}
</style>