<template>
	<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">
					<view class="title text-cut-1">
						<text class="">{{item.name}}</text>
					</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 style="margin-right: 30rpx;">
							<u-icon name="map-fill" color="#FF9447"></u-icon>
							<text class="margin-left-10">{{distance(item.latitude,item.longitude)}} 米</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 v-if="false" class="flex justify-start text-cut-2"
						style="margin-top: 12rpx;width: 100%;height: 34rpx;">
						<view class="line-red sm cu-tag" v-for="(item,index) in 5" :key="index">
							首次光临减2元
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[]
			}
		},
		onLoad() {
			this.fetchList()
		},
		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: {
			fetchList(){
				this.$api.shop.list().then(res=>{
					this.list=res.data.records
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		display: flex;
		flex-direction: column;
		margin: 20rpx;
		background-color: #FFFFFF;
	
		.card {
			margin-bottom: 20rpx;
			display: flex;
			border-bottom: 1rpx solid #ececec;
			
			.left {
				width: 30%;
				
				image {
					width: 100%;
					height: 180rpx;
				}
			}
	
			.right {
				margin-left: 20rpx;
				display: flex;
				width: 70%;
				flex-direction: column;
	
				.title {
					margin-top: 10rpx;
					margin-bottom: 20rpx;
					font-size: 30rpx;
					font-weight: 800;
				}
	
				.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>
