<template>
	<view class="foods-list">
		<view class="foods-item" v-for="f in foodsList" :key="f.id" @click="showDetail(f)">
			<view class="foods-cover">
				<image class="cover" :src="f.cover" mode="scaleToFill"></image>
			</view>
			<view class="foods-info">
				<view class="foods-name">{{ f.title }}</view>
				<view class="foods-month">月销 {{ f.saleCount }} 单</view>
				<view class="foods-coupon">
					<text class="iconfont icon-coupon_fill icon-coupon"></text>
					<text>{{f.couponDesc}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { defineComponent } from "vue";
	import { FoodsModel } from "../../service/models";
	defineComponent({
		name: 'FoodsList'
	})

	defineProps<{
		foodsList : FoodsModel[]
	}>()
	function showDetail(f : FoodsModel) {
		uni.navigateTo({
			url: `/pages/index/detail?id=${f.id}`
		})
	}
</script>

<style lang="scss">
	.foods-list {
		background-color: #fafafa;
		padding: 10px 0;

		.foods-item {
			background-color: #fff;
			display: flex;
			padding: 10px;
			border-bottom: 1px solid #efefef;

			&:last-child {
				border-bottom: none;
			}
		}

		.foods-cover {
			width: 80px;
			margin-right: 10px;

			.cover {
				display: block;
				width: 100%;
				height: 60px;
			}
		}

		.foods-info {
			flex: 1;
		}

		.foods-name {}

		.foods-month {
			font-size: 13px;
			color: #999999;
			margin-bottom: 5px;
		}

		.foods-coupon {
			border-top: 1px dashed #eee;
			padding-top: 5px;
			font-size: 13px;
			color: #999999;

			.icon-coupon {
				color: $uni-color-primary;
				position: relative;
				top: 1px;
				margin-right: 2px;
			}
		}
	}
</style>