<template>
	<view class="filter">
		<view class="flex justify-around">
			<view :class="{active:activeIndex==index}" class="con" :key="index"
				v-for="(item,index) in tagsList" @click="filter(index)">
				<text class="title">{{item.title}}</text>
				<view class="tag">
					<text>{{item.desc}}</text>
				</view>
			</view>
		</view>
		<view class="item">
			<view class="card" @click="goDetail(item.id)" v-for="(item,index) in list" :key="index">
				<view class="left">
					<image :src="item.cover" mode=""></image>
				</view>
				<view class="right" style="width: 100%;">
					<view class="title   flex justify-between" >
						<view class="text-cut-1" style="width: 70%;">
							<text class="">{{item.name}}</text>
						</view>
						<view @click.stop="$jump(`/pagesD/pages/menu/menu?shopId=${item.id}`)" class="text-base center" style="font-size: 28rpx;font-weight: normal;text-decoration: underline;">
							<image class="" style="width: 36rpx;height: 36rpx;margin-right: 4rpx;" src="@/static/icon/order.png" mode=""></image>
							<text>去点餐</text>
						</view>
						
					</view>
					<view class="data">
						<view class="">
							<block>
								<u-icon name="star-fill" color="#ff7001" size="30"></u-icon>
								<text
									style="margin-left: 4rpx;margin-right: 20rpx;color: #ff7001;font-size: 26rpx;">{{item.score}}</text>
							</block>
							<block>
								<text>月售</text>
								<text class="margin-left-10">{{item.sales==-1?0:item.sales}}</text>
							</block>
						</view>
						<view>
							<u-icon name="map-fill" color="#FF9447"></u-icon>
							<text class="margin-left-10">{{distance(item.latitude,item.longitude)}} km</text>
						</view>
					</view>
					<view class="text-cut-2" style="width: 100%;height: 32rpx;margin-top: 14rpx;">
						<view v-for="(item1,index1) in item.labelKey.split(',')" :key="index1" class="cu-tag sm "
							style="background-color: #fff0d9;color: #ffa353;">
							{{item1}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		props:{
			list:Array
		},
		data(){
			return {
				activeIndex: 0,
				tagsList: [{
					title: '智能筛选',
					desc: '大数据优选'
				}, 
				{
					title: '销量最好',
					desc: '销量最好'
				}, {
					title: '评分最高',
					desc: '好评如潮'
				}, 
				{
					title: '距离最近',
					desc: '由近到远'
				}]
			}
		},
		computed:{
			distance() {
				return (lat1,lng1) => {
					if (this.vuex_location!=null) {
						let distance=this.$util.calculateDistance(lat1,lng1,this.vuex_location.latitude,this.vuex_location.longitude)
						console.log(distance);
						return distance
					}else{
						return 0
					}
					
				};
			},
		},
		methods:{
			goDetail(id){
				uni.navigateTo({
					url:"/pages/consume/detail/shop-detail?id="+id,
					fail(err) {
						console.log(err);
					}
				})
			},
			filter(index){
				this.activeIndex=index
				console.log(this.activeIndex);
				this.$emit('filter',index)
			}
		}
	}
</script>

<style lang="scss">
	.filter {
		padding: 10rpx;
		display: flex;
		flex-direction: column;
	
		.con {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
	
			.title {
				font-size: 28rpx;
				font-weight: 800;
				
			}
	
			.tag {
				color: #888888;
				padding: 4rpx;
				margin-top: 10rpx;
				font-size: 22rpx;
			}
		}
	
		.active {
			color: #fd5d4a;
	
			.title {
				width: 100%;
			}
	
			.tag {
				border-radius: 20rpx 0 20rpx 0;
				background-color: #ffddd5;
				color: #fd5d4a;
			}
		}
	}
	
	.item {
		display: flex;
		flex-direction: column;
		margin-top: 50rpx;
	
		.card {
			margin-bottom: 20rpx;
			display: flex;
			border-bottom: 1rpx solid #ececec;
			padding-bottom: 20rpx;
	
			.left {
				width: 30%;
	
				image {
					width: 100%;
					border-radius: 12rpx;
					height: 180rpx;
				}
			}
	
			.right {
				margin-left: 20rpx;
				display: flex;
				width: 70%;
				flex-direction: column;
	
				.title {
					
					font-size: 30rpx;
					font-weight: 800;
					margin-bottom: 30rpx;
				}
	
				.data {
					margin-top: 20rpx;
					display: flex;
					justify-content: space-between;
					font-size: 24rpx;
					color: #666666;
				}
	
				.label {
					margin-top: 10rpx;
				}
			}
		}
	
		.card:last-child {
			border: none;
			margin-bottom: 0;
			padding-bottom: 0;
		}
	}
</style>
