roomCard.vue
5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!--
* @Date: 2023-12-13 13:42:23
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-27 18:49:51
* @FilePath: /meihuaApp/src/components/roomCard.vue
* @Description: 房间详情组件
-->
<template>
<view class="room-card-component" @tap="handleTap">
<image class="room-cover" mode="aspectFill" :src="cover" />
<view class="room-info">
<nut-row>
<nut-col span="18" class="room-info-left">
<view class="room-info-title">{{ title }}</view>
<view class="room-info-desc">{{ room_num }}室 宜住{{ capacity }}人</view>
</nut-col>
<nut-col span="6" class="room-info-right">
<nut-price :price="discount_price" size="normal" style="font-weight: bold;" />
<nut-price :price="original_price" size="small" strike-through style="color: #7D7C7C;" />
</nut-col>
</nut-row>
</view>
<!-- <view v-if="!num && props.type !== 'index'" class="room-status">
<view class="room-status-wrapper">
<image mode="aspectFill" src="https://cdn.ipadbiz.cn/meihua/icon_checked@2x.png" />
</view>
</view> -->
</view>
</template>
<script setup>
import { ref, defineProps, onMounted, watch } from 'vue'
import Taro from '@tarojs/taro'
/**
* 获取今天和明天日期
*/
const getTodayAndTomorrow = () => {
var today = new Date(); // 获取当前日期
var todayYear = today.getFullYear();
var todayMonth = today.getMonth() + 1; // 月份从0开始,所以要加1
var todayDay = today.getDate();
var tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000); // 获取明天日期
var tomorrowYear = tomorrow.getFullYear();
var tomorrowMonth = tomorrow.getMonth() + 1; // 月份从0开始,所以要加1
var tomorrowDay = tomorrow.getDate();
// 跨年处理
if (tomorrowYear > todayYear) {
tomorrowMonth = '01';
tomorrowDay = '01';
}
// 跨月处理
if (tomorrowMonth > 12) {
tomorrowMonth = '01';
tomorrowYear = todayYear + 1;
}
// 格式化为两位数
todayMonth = todayMonth < 10 ? '0' + todayMonth : todayMonth;
todayDay = todayDay < 10 ? '0' + todayDay : todayDay;
tomorrowMonth = tomorrowMonth < 10 ? '0' + tomorrowMonth : tomorrowMonth;
tomorrowDay = tomorrowDay < 10 ? '0' + tomorrowDay : tomorrowDay;
return {
today: todayYear + '-' + todayMonth + '-' + todayDay,
tomorrow: tomorrowYear + '-' + tomorrowMonth + '-' + tomorrowDay
};
}
const props = defineProps({
data: { // 房间详情
type: Object,
default: {},
},
calenderInfo: { // 日历信息
type: Object,
default: {
startDate: '',
endDate: '',
},
},
type: {
type: String,
default: '',
}
});
const startDate = ref('');
const endDate = ref('');
watch(
() => props.calenderInfo,
(val) => {
startDate.value = val.startDate;
endDate.value = val.endDate;
},
{
deep: true,
immediate: true
}
);
// 调用方法获取今天和明天的日期
const dates = getTodayAndTomorrow();
const handleTap = () => {
if (!startDate.value) {
startDate.value = dates.today;
}
if (!endDate.value) {
endDate.value = dates.tomorrow;
}
if (props.type === 'index') { // 首页进入的
Taro.navigateTo({
url: `../detail/index?id=${id.value}&room_type=${room_type.value}&start_date=&end_date=`,
});
} else {
Taro.navigateTo({
url: `../detail/index?id=${id.value}&room_type=${room_type.value}&start_date=${startDate.value}&end_date=${endDate.value}`,
});
}
}
const id = ref(''); // 房间id
const cover = ref(''); // 封面图
const title = ref(''); // 标题
const original_price = ref(''); // 原价
const discount_price = ref(''); // 优惠价
const capacity = ref(''); // 能住几个人
const num = ref(''); // 可售数量
const room_num = ref(''); // 房间描述 两室
const room_type = ref(''); //
onMounted(() => {
id.value = props.data.id;
cover.value = props.data.cover ? props.data.cover : 'https://cdn.ipadbiz.cn/meihua/img1@2x.png';
title.value = props.data.title;
room_num.value = props.data.room_num;
capacity.value = props.data.capacity;
num.value = props.data.num;
original_price.value = props.data.original_price;
discount_price.value = props.data.discount_price;
room_type.value = props.data.room_type;
});
watch(
() => props.data,
(val) => {
if (val) {
id.value = val.id;
cover.value = val.cover ? val.cover : 'https://cdn.ipadbiz.cn/meihua/img1@2x.png';
title.value = val.title;
room_num.value = val.room_num;
capacity.value = val.capacity;
num.value = val.num;
original_price.value = val.original_price;
discount_price.value = val.discount_price;
room_type.value = val.room_type;
}
},
{
deep: true,
immediate: true
}
);
</script>
<style lang="less">
:root,
page {
--nut-price-medium-size: 35rpx;
}
.room-card-component {
position: relative;
margin: 1rem;
background-color: white;
box-shadow: 0px 0px 8px 0px rgba(0,0,0,0.1);
border: 1px solid #f9f9f9;
border-radius: 0.5rem;
overflow: hidden;
.room-cover {
width: 100%;
height: 10rem;
}
.room-info {
padding: 0.5rem;
.room-info-left {
.room-info-title {
color: #0B0B0B;
font-weight: bold;
margin-top: 5rpx;
}
.room-info-desc {
color: #7D7C7C;
font-size: 0.8rem;
margin-top: 0.2rem;
}
}
.room-info-right {
display: flex;
flex-direction: column;
align-items: flex-end;
.room-info-discount {
color: #EB2E2E;
font-weight: bold;
}
.room-info-price {
}
}
}
.room-status {
width: 100%;
height: 10rem;
position: absolute;
left: 0;
top: 0;
background-color: rgba(0, 0, 0, 0.5);
.room-status-wrapper {
position: absolute; left: calc(50% - 200rpx / 2); right: 0; top: 50rpx;
image {
width: 200rpx;
height: 200rpx;
}
}
}
}
</style>