Showing
2 changed files
with
56 additions
and
6 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2023-12-13 13:42:23 | 2 | * @Date: 2023-12-13 13:42:23 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-12-21 13:57:59 | 4 | + * @LastEditTime: 2023-12-21 14:07:08 |
| 5 | * @FilePath: /meihuaApp/src/components/roomCard.vue | 5 | * @FilePath: /meihuaApp/src/components/roomCard.vue |
| 6 | * @Description: 房间详情组件 | 6 | * @Description: 房间详情组件 |
| 7 | --> | 7 | --> |
| ... | @@ -32,6 +32,46 @@ | ... | @@ -32,6 +32,46 @@ |
| 32 | import { ref, defineProps, onMounted, watch } from 'vue' | 32 | import { ref, defineProps, onMounted, watch } from 'vue' |
| 33 | import Taro from '@tarojs/taro' | 33 | import Taro from '@tarojs/taro' |
| 34 | 34 | ||
| 35 | +/** | ||
| 36 | + * 获取今天和明天日期 | ||
| 37 | + */ | ||
| 38 | +const getTodayAndTomorrow = () => { | ||
| 39 | + var today = new Date(); // 获取当前日期 | ||
| 40 | + | ||
| 41 | + var todayYear = today.getFullYear(); | ||
| 42 | + var todayMonth = today.getMonth() + 1; // 月份从0开始,所以要加1 | ||
| 43 | + var todayDay = today.getDate(); | ||
| 44 | + | ||
| 45 | + var tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000); // 获取明天日期 | ||
| 46 | + | ||
| 47 | + var tomorrowYear = tomorrow.getFullYear(); | ||
| 48 | + var tomorrowMonth = tomorrow.getMonth() + 1; // 月份从0开始,所以要加1 | ||
| 49 | + var tomorrowDay = tomorrow.getDate(); | ||
| 50 | + | ||
| 51 | + // 跨年处理 | ||
| 52 | + if (tomorrowYear > todayYear) { | ||
| 53 | + tomorrowMonth = '01'; | ||
| 54 | + tomorrowDay = '01'; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + // 跨月处理 | ||
| 58 | + if (tomorrowMonth > 12) { | ||
| 59 | + tomorrowMonth = '01'; | ||
| 60 | + tomorrowYear = todayYear + 1; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + // 格式化为两位数 | ||
| 64 | + todayMonth = todayMonth < 10 ? '0' + todayMonth : todayMonth; | ||
| 65 | + todayDay = todayDay < 10 ? '0' + todayDay : todayDay; | ||
| 66 | + tomorrowMonth = tomorrowMonth < 10 ? '0' + tomorrowMonth : tomorrowMonth; | ||
| 67 | + tomorrowDay = tomorrowDay < 10 ? '0' + tomorrowDay : tomorrowDay; | ||
| 68 | + | ||
| 69 | + return { | ||
| 70 | + today: todayYear + '-' + todayMonth + '-' + todayDay, | ||
| 71 | + tomorrow: tomorrowYear + '-' + tomorrowMonth + '-' + tomorrowDay | ||
| 72 | + }; | ||
| 73 | +} | ||
| 74 | + | ||
| 35 | const props = defineProps({ | 75 | const props = defineProps({ |
| 36 | data: { | 76 | data: { |
| 37 | type: Object, | 77 | type: Object, |
| ... | @@ -46,8 +86,8 @@ const props = defineProps({ | ... | @@ -46,8 +86,8 @@ const props = defineProps({ |
| 46 | }, | 86 | }, |
| 47 | }); | 87 | }); |
| 48 | 88 | ||
| 49 | -const startDate = ref(props.calenderInfo.startDate); | 89 | +const startDate = ref(''); |
| 50 | -const endDate = ref(props.calenderInfo.endDate); | 90 | +const endDate = ref(''); |
| 51 | 91 | ||
| 52 | watch( | 92 | watch( |
| 53 | () => props.calenderInfo, | 93 | () => props.calenderInfo, |
| ... | @@ -61,6 +101,9 @@ watch( | ... | @@ -61,6 +101,9 @@ watch( |
| 61 | } | 101 | } |
| 62 | ); | 102 | ); |
| 63 | 103 | ||
| 104 | +// 调用方法获取今天和明天的日期 | ||
| 105 | +const dates = getTodayAndTomorrow(); | ||
| 106 | + | ||
| 64 | const handleTap = () => { | 107 | const handleTap = () => { |
| 65 | Taro.navigateTo({ | 108 | Taro.navigateTo({ |
| 66 | url: `../detail/index?id=abc&start_date=${startDate.value}&end_date=${endDate.value}`, | 109 | url: `../detail/index?id=abc&start_date=${startDate.value}&end_date=${endDate.value}`, |
| ... | @@ -68,6 +111,13 @@ const handleTap = () => { | ... | @@ -68,6 +111,13 @@ const handleTap = () => { |
| 68 | } | 111 | } |
| 69 | 112 | ||
| 70 | onMounted(() => { | 113 | onMounted(() => { |
| 114 | + if (props.calenderInfo) { | ||
| 115 | + startDate.value = props.calenderInfo.startDate; | ||
| 116 | + endDate.value = props.calenderInfo.endDate; | ||
| 117 | + } else { | ||
| 118 | + startDate.value = dates.today; | ||
| 119 | + endDate.value = dates.tomorrow; | ||
| 120 | + } | ||
| 71 | // console.warn('选择的日期', props.calenderInfo); | 121 | // console.warn('选择的日期', props.calenderInfo); |
| 72 | // console.warn('房间详情的属性', props.data); | 122 | // console.warn('房间详情的属性', props.data); |
| 73 | }) | 123 | }) | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-19 14:11:06 | 2 | * @Date: 2022-09-19 14:11:06 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-12-21 12:26:13 | 4 | + * @LastEditTime: 2023-12-21 14:02:43 |
| 5 | * @FilePath: /meihuaApp/src/pages/confirm/index.vue | 5 | * @FilePath: /meihuaApp/src/pages/confirm/index.vue |
| 6 | * @Description: 确认订单页面 | 6 | * @Description: 确认订单页面 |
| 7 | --> | 7 | --> |
| ... | @@ -204,13 +204,13 @@ onMounted(() => { | ... | @@ -204,13 +204,13 @@ onMounted(() => { |
| 204 | year: check_in[0], | 204 | year: check_in[0], |
| 205 | month: check_in[1], | 205 | month: check_in[1], |
| 206 | day: check_in[2], | 206 | day: check_in[2], |
| 207 | - day_of_week: JSON.parse(start_date_week) | 207 | + day_of_week: start_date_week ? JSON.parse(start_date_week) : '' |
| 208 | } | 208 | } |
| 209 | booking_info.value.check_out = { | 209 | booking_info.value.check_out = { |
| 210 | year: check_out[0], | 210 | year: check_out[0], |
| 211 | month: check_out[1], | 211 | month: check_out[1], |
| 212 | day: check_out[2], | 212 | day: check_out[2], |
| 213 | - day_of_week: JSON.parse(end_date_week) | 213 | + day_of_week: end_date_week ? JSON.parse(end_date_week) : '' |
| 214 | } | 214 | } |
| 215 | }); | 215 | }); |
| 216 | 216 | ... | ... |
-
Please register or login to post a comment