<template>
	<view class="searchResult">
		<zs-choose-tab :tabList="tabList" @choose="chooseTab"></zs-choose-tab>
		<zs-list mt="0" @load="loadMore" :status="status">
			<view class="item" v-for="(item,index) in list" :key="index">
					<zs-img class="icon" :src="item.logoPath" radius="full" width="120rpx" height="120rpx" @click="goShopDetail(item)"></zs-img>
				<view class="shop-box">
					<view class="shop-info">
						<view class="shop-name" @click="goShopDetail(item)">
							{{item.shopVo.shopName}}
						</view>
						<view class="address-box">
							<view class="address">
								{{item.district}} 
							</view>
							<view class="distance">
								{{(item.shopVo.distance/1000).toFixed(2)}}km
							</view>
						</view>
					</view>
	
					<!-- <view class="goods-list"> -->
						<scroll-view class="goods-list" enable-flex scroll-x="true">
						<view class="goods-item" v-for="(i,d) in item.goodsVos" :key="d"  @click="goGoodsDetail(item,i)">
							<zs-img :src="i.goodsImg" width="160rpx" height="160rpx"></zs-img>
							<view class="goods-name">
							{{i.goodsName}}
							</view>
							<view class="price-box">
									<view class="price">
									￥{{i.realPrice}}
									</view>
									<view class="old-price">
										 ￥{{i.marketPrice}}
									</view>
							</view>
						</view>
	
						</scroll-view>
					<!-- </view> -->
				</view>
			</view>
		</zs-list>
	</view>
</template>

<script>
	import {
		search
	} from '@/api/shop.js';
	import {
		getMenu,
	} from '@/api/common.js'
	export default {
		data() {
			return {
				location:'',
				query: {
					district:'',
					pageCurrent: 1,
					pageSize: 10,
					'location.lat': 0,
					'location.lon': 0,
					range:'',
					queryName: ''
				},
				status: 'more',
				list: [],
				tabList: [{
						id: 1,
						label: '区域',
						list: [
				
							{
								id: 1,
								label: '观山湖'
							},
							{
								id: 2,
								label: '白云区'
							},
							{
								id: 3,
								label: '花果山区'
							}
						]
					},
					{
						id: 1,
						label: '全部分类',
						list: []
					},
					
					{
						id: 1,
						label: '附近',
						list: [
							{
								id:5,
								label: '5KM'
							},
							{
								id:10,
								label: '10KM'
							},
							{
								id:20,
								label: '20KM'
							},
							{
								id:50,
								label: '50KM'
							}
						]
					},
				]
			}
		},
		methods: {
			goShopDetail(item) {
				uni.setStorageSync('shopInfo', JSON.stringify(item))
				uni.navigateTo({
					url: '/detail/shopDetail/shopDetail'
				})
			},
			goGoodsDetail(item,i) {
				uni.setStorageSync('shopInfo', JSON.stringify(item))
				uni.reLaunch({
					url: `/detail/goodsDetail/index?id=${i.goodsId}`
				})
			},
			chooseTab(val) {
				console.log(val);
				this.query.range = val[2].id
				if(val[0]){
					this.query['location.lat'] = val[0].location.lat
					this.query['location.lon'] = val[0].location.lng
					this.query.range = 50
					this.query.district = val[0].label
				}else if(!val[0]){
					this.query['location.lat'] = this.location.latitude
					this.query['location.lon'] = this.location.longitude
					this.query.district = ''
				}
				if(val[1]){
					this.query.menuId = val[1].id
				}else if(!val[1]){
					this.query.menuId = ''
				}
				this.query.pageCurrent = 1
				this.status = 'more'
				this.list = []
				this.search()
			},
			search() {
				// if(this.status == 'noMore') return
				this.status = 'loading'
				let obj = JSON.parse(JSON.stringify(this.query))
				if(!obj.range){
					delete obj.range
				}
				search(obj).then(res => {
					if (res.state == 'Success') {
						this.list = this.list.concat(res.content.records)
						console.log(res.content.total>=this.list.length);
						if(res.content.total>this.list.length){
							this.status = 'more'
						}else{
							this.status = 'noMore'
							this.query.pageCurrent++
						}
					}
				})
			},
			loadMore() {
				this.search()
			},
			// 金刚区
			getMenu(){
					getMenu({currentPage:1,pageSize:10,status:2}).then(res=>{
						if(res.state == 'Success'){
							let list = []
							res.content.records.map(item => {
								list.push({
									id: item.id,
									label: item.menuName
								})
							})
							this.tabList[1].list = list
						}
					})
			},
		},
		onLoad(options) {
			this.tabList[0].list = JSON.parse(uni.getStorageSync('districtList'))
			this.location = JSON.parse(uni.getStorageSync('location'))
			this.query['location.lat'] = this.location.latitude
			this.query['location.lon'] = this.location.longitude
			this.query.queryName = options.search
			this.search()
			this.getMenu()
		}
	}
</script>

<style lang="scss" scoped>
.searchResult{
	padding: 100rpx 24rpx 20rpx;
	background: #F9F9F9;
	.item{
		padding: 24rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		display: flex;
		align-items: flex-start;
		margin-bottom: 20rpx;
		
		.icon{
			width: 120rpx;
		}
		.shop-box{
			flex: 1;
				margin-left: 20rpx;
			.shop-info{
				.shop-name{
					font-weight: 600;
					font-size: 36rpx;
					color: #222222;
					width: 100%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.address-box{
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-weight: 300;
					font-size: 24rpx;
					color: #AAAAAA;
					margin-top: 25rpx;
					.address{
						width: 400rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
			}
			.goods-list{
				display: flex;
				align-items: flex-start;
				margin-top: 20rpx;
				overflow: auto;
				width: calc(750rpx - 94rpx - 120rpx - 20rpx);
				.goods-item{
					display: inline-block;
					width: 160rpx;
					margin-right: 20rpx;
					.goods-name{
						margin-top: 20rpx;
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						/* 弹性伸缩盒子模型显示 */
						display: -webkit-box;
						/* 限制在一个块元素显示的文本的行数 */
						-webkit-line-clamp: 2;
						/* 设置或检索伸缩盒对象的子元素的排列方式 */
						-webkit-box-orient: vertical;
					}
				}
				.price-box{
					display: flex;
					align-items: center;
					margin-top: 20rpx;
					.price{
						font-weight: 600;
						font-size: 28rpx;
						color: #FF4D3A;
					}
					.old-price{
						font-weight: 300;
						font-size: 20rpx;
						color: #AAAAAA;
						text-decoration: line-through;
					}
				}
			}
		}
	}
}
</style>