<template>
    <card title="热门服务">
        <block v-for="item1 in lists" :key="item1.id">
            <view class="goods-item mr-[20rpx]" @click="goPage(`/pages/goods/index?id=${item1.id}`)">
                <view class="flex justify-center">
                    <u-image :src="item1.image" width="200" height="200"></u-image>
                </view>
                <view class="goods-item--text text-center">
                    <view class="goods-title truncate mt-[20rpx] mb-[16rpx]">{{ item1.name }}</view>
                    <view>
                        <price :price="item1.price" :desc="item1.unit" :scribingPrice="item1.scribingPrice"></price>
                    </view>
                    <view class="truncate goods-desc">
                        <text space="emsp" decode="true" class="goods-desc-text">{{
                            item1.remarks || ' '
                            }}</text>
                    </view>
                </view>
            </view>
        </block>
    </card>
</template>

<script lang="ts" setup>
import Card from './card.vue'
import Price from '@/components/price/index.vue'

defineProps({
    lists: {
        type: Array,
        default: []
    }
})

const goPage = (url: string) => {
    uni.navigateTo({ url: url })
}
</script>

<style lang="scss" scoped>
// 商品列表
.goods-item {
    width: 200rpx;
    display: inline-block;
    vertical-align: top; // 确保顶部对齐
    height: 400rpx; // 设置固定高度

    &--text {
        display: flex;
        flex-direction: column;
        height: 180rpx; // 文本区域固定高度

        .goods-title {
            font-weight: 500;
            color: #222;
            font-size: 30rpx;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            margin-top: 20rpx;
            margin-bottom: 16rpx;
        }

        .goods-desc {
            color: #888;
            font-size: 24rpx;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            width: 100%;
            margin-top: auto; // 推到底部
            min-height: 24rpx; // 确保即使没有内容也占位
        }
    }
}

.goods-desc-text {
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 100%;
}
</style>
