<template>
    <view 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="info-column">
                    <view style="text-align: left">
                        <view class="info-column-title">
                            <view class="goods-scribing-title" v-if="item1.scribingPrice > 0">
                                活动
                            </view>
                            <view class="goods-title overflow-ellipsis-line ellipsis-line1 flex-1">
                                {{ item1.name }}
                            </view>
                        </view>
                        <view class="goods-desc overflow-ellipsis-line ellipsis-line1">
                            {{ item1.remarks || ' ' }}
                        </view>
                    </view>
                </view>

                <view class="image-column">
                    <u-image
                        :src="item1.image"
                        class="good-img"
                        width="100%"
                        height="350"
                        border-radius="20"
                    ></u-image>
                </view>

                <view class="price-column" v-if="item1.scribingPrice > 0">
                    <view>
                        <view class="price-wrap">
                            ¥
                            <span class="price">{{ numFilter(item1.price) }}</span>
                            元
                            <view class="subprice line-through">
                                原价:¥{{ numFilter(item1.scribingPrice) }}
                            </view>
                        </view>
                        <view class="text-base normal mt-1" style="color: #b0aeae">
                            <text class="font-bold">{{ item1.orderNum }}</text>
                            人预约过
                        </view>
                    </view>
                    <view class="btn_con">
                        <view class="btn_scribing bg-primary">立即抢购</view>
                    </view>
                </view>
                <view class="price-column" v-else>
                    <view>
                        <view class="price-wrap">
                            ¥
                            <span class="price">{{ numFilter(item1.price) }}</span>
                            元
                        </view>
                        <view class="text-base normal mt-1" style="color: #b0aeae">
                            <text class="font-bold">{{ item1.orderNum }}</text>
                            人预约过
                        </view>
                    </view>
                    <view class="btn_con">
                        <view class="btn bg-primary">立即抢购</view>
                    </view>
                </view>
            </view>
        </block>
    </view>
</template>

<script lang="ts" setup>
defineProps({
    lists: {
        type: Array,
        default: []
    }
})

const goPage = (url: string) => {
    uni.navigateTo({ url: url })
}
//截取当前数据到小数点后两位
const numFilter = value => {
    const realVal = parseFloat(value).toFixed(2)
    return realVal
}
</script>

<style lang="scss" scoped>
// 商品列表
.goods-item {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    // padding: 20rpx;
    border-radius: 17rpx;
    background-color: #fff;
    //box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin: 20rpx;

    .image-column {
        margin-left: 20rpx;
        margin-right: 20rpx;
        width: 94%;

        .good-img {
            width: 100%;
            //border-radius: 20rpx; //u-image故从属性中传入
            border-radius: 25px;
            border-radius: 50%;
        }
    }

    .info-column {
        display: flex;
        flex-direction: column;
        border-radius: 10rpx;
        justify-content: space-between;

        text-align: left;
        padding-left: 26rpx;
        margin-top: 20rpx;
        margin-bottom: 20rpx;

        .info-column-title {
            display: flex;
            align-items: center;
            margin-bottom: 10rpx;

            .goods-title {
                font-size: 1.1rem;
            }

            .goods-scribing-title {
                font-size: 0.79rem;
                // box-sizing: border-box;
                margin-right: 15rpx;
                color: white;
                padding: 3rpx; //让字体与背景上下有一定的间隔
                background-color: #ff5856;
                border-radius: 20rpx;
                width: 80rpx;
                display: flex;
                justify-content: center;
                align-items: center;
            }
        }

        .goods-desc {
            font-size: 0.775rem;
            color: #808695;
        }
    }

    .price-column {
        display: flex;
        flex-direction: row;
        align-items: center;
        border-radius: 10rpx;
        justify-content: space-between;
        margin: 20rpx;

        .price-wrap {
            display: flex;
            flex-direction: row;
            align-items: baseline;
            color: #ff5856;

            .price {
                font-size: 1.5rem; //¥
                display: flexbox;
            }

            .subprice {
                color: #aeaeae;
                margin-left: 20rpx;
            }
        }

        .btn,
        .btn_scribing {
            margin-top: auto;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #fff;
            width: 180rpx;
            height: 66rpx;
            border-radius: 50rpx;
            margin-right: 10rpx;

            font-size: 0.79rem;
            font-weight: bold;
        }

        .btn {
            // background-color: #34afff;
        }
        .btn_scribing {
            // background-color: $u-type-primary;
        }
    }
}
</style>
