239 lines
4.5 KiB
Vue
239 lines
4.5 KiB
Vue
<template>
|
|
<view class="room-card" :class="{ 'is-full': !isAvailable }">
|
|
<image
|
|
class="room-cover"
|
|
:src="room.coverImage || '/static/default-room.png'"
|
|
mode="aspectFill"
|
|
@tap="handleTap"
|
|
/>
|
|
<!-- 满房遮罩 -->
|
|
<view v-if="!isAvailable" class="full-overlay" @tap="handleTap">
|
|
<text class="full-text">所选日期已满房</text>
|
|
</view>
|
|
<view class="room-info" @tap="handleTap">
|
|
<text class="room-name text-ellipsis">{{ room.name }}</text>
|
|
<view class="room-meta">
|
|
<text class="room-address text-ellipsis" v-if="room.address">{{ room.address }}</text>
|
|
</view>
|
|
<view class="room-tags" v-if="room.type || room.bedType">
|
|
<text class="tag" v-if="room.type">{{ typeLabels[room.type] || room.type }}</text>
|
|
<text class="tag" v-if="room.bedType">{{ room.bedType }}</text>
|
|
</view>
|
|
<view class="room-bottom">
|
|
<view class="room-rating" v-if="room.rating">
|
|
<text class="rating-icon">★</text>
|
|
<text class="rating-score">{{ room.rating }}</text>
|
|
<text class="rating-count" v-if="room.reviewCount">({{ room.reviewCount }}条评价)</text>
|
|
</view>
|
|
<view class="room-price-row">
|
|
<view class="room-price">
|
|
<text class="price-symbol">¥</text>
|
|
<text class="price-value">{{ room.price }}</text>
|
|
<text class="price-unit">/晚</text>
|
|
</view>
|
|
<view class="book-btn" :class="{ 'disabled': !isAvailable }" @tap.stop="handleBook">
|
|
<text class="book-text">订</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed } from 'vue';
|
|
|
|
const props = defineProps<{
|
|
room: {
|
|
id: number;
|
|
name: string;
|
|
coverImage?: string;
|
|
type?: string;
|
|
bedType?: string;
|
|
price: number;
|
|
rating?: number;
|
|
reviewCount?: number;
|
|
address?: string;
|
|
isAvailable?: boolean;
|
|
};
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'tap'): void;
|
|
(e: 'book'): void;
|
|
}>();
|
|
|
|
const isAvailable = computed(() => props.room.isAvailable !== false);
|
|
|
|
const typeLabels: Record<string, string> = {
|
|
hotel: '酒店',
|
|
homestay: '民宿',
|
|
apartment: '公寓',
|
|
hostel: '青旅',
|
|
};
|
|
|
|
function handleTap() {
|
|
emit('tap');
|
|
}
|
|
|
|
function handleBook() {
|
|
if (!isAvailable.value) return;
|
|
emit('book');
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.room-card {
|
|
display: flex;
|
|
position: relative;
|
|
background: #fff;
|
|
border-radius: 16rpx;
|
|
margin-bottom: 20rpx;
|
|
overflow: hidden;
|
|
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
|
}
|
|
|
|
.room-card.is-full {
|
|
opacity: 0.85;
|
|
}
|
|
|
|
.room-cover {
|
|
width: 240rpx;
|
|
height: 220rpx;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.full-overlay {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 240rpx;
|
|
height: 220rpx;
|
|
background: rgba(0, 0, 0, 0.5);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.full-text {
|
|
font-size: 24rpx;
|
|
color: #fff;
|
|
background: rgba(255, 68, 68, 0.9);
|
|
padding: 8rpx 16rpx;
|
|
border-radius: 8rpx;
|
|
}
|
|
|
|
.room-info {
|
|
flex: 1;
|
|
padding: 16rpx 20rpx;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
min-width: 0;
|
|
}
|
|
|
|
.room-name {
|
|
font-size: 30rpx;
|
|
font-weight: 600;
|
|
color: #333;
|
|
line-height: 1.3;
|
|
}
|
|
|
|
.room-meta {
|
|
margin-top: 6rpx;
|
|
}
|
|
|
|
.room-address {
|
|
font-size: 22rpx;
|
|
color: #999;
|
|
}
|
|
|
|
.room-tags {
|
|
display: flex;
|
|
gap: 10rpx;
|
|
margin-top: 8rpx;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.tag {
|
|
font-size: 20rpx;
|
|
color: #FF6B35;
|
|
background: #fff1eb;
|
|
padding: 2rpx 10rpx;
|
|
border-radius: 6rpx;
|
|
}
|
|
|
|
.room-bottom {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-end;
|
|
margin-top: 8rpx;
|
|
}
|
|
|
|
.room-rating {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.rating-icon {
|
|
color: #FF6B35;
|
|
font-size: 24rpx;
|
|
}
|
|
|
|
.rating-score {
|
|
font-size: 28rpx;
|
|
font-weight: 700;
|
|
color: #FF6B35;
|
|
margin-left: 4rpx;
|
|
}
|
|
|
|
.rating-count {
|
|
font-size: 20rpx;
|
|
color: #999;
|
|
margin-left: 4rpx;
|
|
}
|
|
|
|
.price-symbol {
|
|
font-size: 22rpx;
|
|
color: #FF6B35;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.price-value {
|
|
font-size: 36rpx;
|
|
color: #FF6B35;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.price-unit {
|
|
font-size: 20rpx;
|
|
color: #999;
|
|
}
|
|
|
|
.room-price-row {
|
|
display: flex;
|
|
align-items: flex-end;
|
|
gap: 16rpx;
|
|
}
|
|
|
|
.book-btn {
|
|
background: linear-gradient(135deg, #FF6B35, #ff8a5c);
|
|
width: 56rpx;
|
|
height: 56rpx;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.book-btn.disabled {
|
|
background: #ccc;
|
|
}
|
|
|
|
.book-text {
|
|
font-size: 28rpx;
|
|
font-weight: 700;
|
|
color: #fff;
|
|
}
|
|
</style>
|