hookehuyr

fix

<!--
* @Date: 2023-12-13 13:42:23
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-21 13:57:59
* @LastEditTime: 2023-12-21 14:07:08
* @FilePath: /meihuaApp/src/components/roomCard.vue
* @Description: 房间详情组件
-->
......@@ -32,6 +32,46 @@
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,
......@@ -46,8 +86,8 @@ const props = defineProps({
},
});
const startDate = ref(props.calenderInfo.startDate);
const endDate = ref(props.calenderInfo.endDate);
const startDate = ref('');
const endDate = ref('');
watch(
() => props.calenderInfo,
......@@ -61,6 +101,9 @@ watch(
}
);
// 调用方法获取今天和明天的日期
const dates = getTodayAndTomorrow();
const handleTap = () => {
Taro.navigateTo({
url: `../detail/index?id=abc&start_date=${startDate.value}&end_date=${endDate.value}`,
......@@ -68,6 +111,13 @@ const handleTap = () => {
}
onMounted(() => {
if (props.calenderInfo) {
startDate.value = props.calenderInfo.startDate;
endDate.value = props.calenderInfo.endDate;
} else {
startDate.value = dates.today;
endDate.value = dates.tomorrow;
}
// console.warn('选择的日期', props.calenderInfo);
// console.warn('房间详情的属性', props.data);
})
......
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-21 12:26:13
* @LastEditTime: 2023-12-21 14:02:43
* @FilePath: /meihuaApp/src/pages/confirm/index.vue
* @Description: 确认订单页面
-->
......@@ -204,13 +204,13 @@ onMounted(() => {
year: check_in[0],
month: check_in[1],
day: check_in[2],
day_of_week: JSON.parse(start_date_week)
day_of_week: start_date_week ? JSON.parse(start_date_week) : ''
}
booking_info.value.check_out = {
year: check_out[0],
month: check_out[1],
day: check_out[2],
day_of_week: JSON.parse(end_date_week)
day_of_week: end_date_week ? JSON.parse(end_date_week) : ''
}
});
......