Showing
4 changed files
with
140 additions
and
14 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2023-12-14 10:04:23 | 2 | * @Date: 2023-12-14 10:04:23 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-12-21 12:21:07 | 4 | + * @LastEditTime: 2023-12-21 13:59:23 |
| 5 | * @FilePath: /meihuaApp/src/components/calendarSelect.vue | 5 | * @FilePath: /meihuaApp/src/components/calendarSelect.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -41,7 +41,7 @@ | ... | @@ -41,7 +41,7 @@ |
| 41 | </template> | 41 | </template> |
| 42 | 42 | ||
| 43 | <script setup> | 43 | <script setup> |
| 44 | -import { ref, reactive, onMounted } from 'vue' | 44 | +import { ref, reactive, onMounted, watch } from 'vue' |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | * 获取今天和明天日期 | 47 | * 获取今天和明天日期 |
| ... | @@ -145,6 +145,17 @@ const dates = getTodayAndTomorrow(); | ... | @@ -145,6 +145,17 @@ const dates = getTodayAndTomorrow(); |
| 145 | 145 | ||
| 146 | const emit = defineEmits(['on-dates-change']); | 146 | const emit = defineEmits(['on-dates-change']); |
| 147 | 147 | ||
| 148 | +const props = defineProps({ | ||
| 149 | + startDate: { | ||
| 150 | + type: String, | ||
| 151 | + default: '', | ||
| 152 | + }, | ||
| 153 | + endDate: { | ||
| 154 | + type: String, | ||
| 155 | + default: '', | ||
| 156 | + }, | ||
| 157 | +}); | ||
| 158 | + | ||
| 148 | const state = reactive({ | 159 | const state = reactive({ |
| 149 | startDate: dates.today, | 160 | startDate: dates.today, |
| 150 | endDate: '', | 161 | endDate: '', |
| ... | @@ -160,7 +171,29 @@ const themeVars = reactive({ | ... | @@ -160,7 +171,29 @@ const themeVars = reactive({ |
| 160 | primaryColorEnd: '#6A4925' | 171 | primaryColorEnd: '#6A4925' |
| 161 | }); | 172 | }); |
| 162 | 173 | ||
| 174 | +watch( | ||
| 175 | + () => props, | ||
| 176 | + (val) => { | ||
| 177 | + // 如果传入了默认日期,则设置默认日期 | ||
| 178 | + if (val.startDate) { | ||
| 179 | + state.checkinDate = val.startDate; | ||
| 180 | + } | ||
| 181 | + if (val.endDate) { | ||
| 182 | + state.checkoutDate = val.endDate; | ||
| 183 | + } | ||
| 184 | + if (val.startDate && val.endDate) { | ||
| 185 | + state.defaultDate = [val.startDate, val.endDate]; | ||
| 186 | + state.betweenDate = getDayDifference(val.startDate, val.endDate); | ||
| 187 | + } | ||
| 188 | + }, | ||
| 189 | + { | ||
| 190 | + deep: true, | ||
| 191 | + immediate: true | ||
| 192 | + } | ||
| 193 | +); | ||
| 194 | + | ||
| 163 | onMounted(() => { | 195 | onMounted(() => { |
| 196 | + // 触发日期改变事件 | ||
| 164 | emit('on-dates-change', { startDate: state.checkinDate, endDate: state.checkoutDate, betweenDate: state.betweenDate, startDateWeek: JSON.stringify(getDayOfWeek(state.checkinDate)), endDateWeek: JSON.stringify(getDayOfWeek(state.checkoutDate)) }); | 197 | emit('on-dates-change', { startDate: state.checkinDate, endDate: state.checkoutDate, betweenDate: state.betweenDate, startDateWeek: JSON.stringify(getDayOfWeek(state.checkinDate)), endDateWeek: JSON.stringify(getDayOfWeek(state.checkoutDate)) }); |
| 165 | }) | 198 | }) |
| 166 | 199 | ... | ... |
| 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 11:09:22 | 4 | + * @LastEditTime: 2023-12-21 13:57:59 |
| 5 | * @FilePath: /meihuaApp/src/components/roomCard.vue | 5 | * @FilePath: /meihuaApp/src/components/roomCard.vue |
| 6 | * @Description: 房间详情组件 | 6 | * @Description: 房间详情组件 |
| 7 | --> | 7 | --> |
| ... | @@ -29,7 +29,7 @@ | ... | @@ -29,7 +29,7 @@ |
| 29 | </template> | 29 | </template> |
| 30 | 30 | ||
| 31 | <script setup> | 31 | <script setup> |
| 32 | -import { ref, defineProps, onMounted } 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 | const props = defineProps({ | 35 | const props = defineProps({ |
| ... | @@ -37,16 +37,39 @@ const props = defineProps({ | ... | @@ -37,16 +37,39 @@ const props = defineProps({ |
| 37 | type: Object, | 37 | type: Object, |
| 38 | default: {}, | 38 | default: {}, |
| 39 | }, | 39 | }, |
| 40 | + calenderInfo: { | ||
| 41 | + type: Object, | ||
| 42 | + default: { | ||
| 43 | + startDate: '', | ||
| 44 | + endDate: '', | ||
| 45 | + }, | ||
| 46 | + }, | ||
| 40 | }); | 47 | }); |
| 41 | 48 | ||
| 49 | +const startDate = ref(props.calenderInfo.startDate); | ||
| 50 | +const endDate = ref(props.calenderInfo.endDate); | ||
| 51 | + | ||
| 52 | +watch( | ||
| 53 | + () => props.calenderInfo, | ||
| 54 | + (val) => { | ||
| 55 | + startDate.value = val.startDate; | ||
| 56 | + endDate.value = val.endDate; | ||
| 57 | + }, | ||
| 58 | + { | ||
| 59 | + deep: true, | ||
| 60 | + immediate: true | ||
| 61 | + } | ||
| 62 | +); | ||
| 63 | + | ||
| 42 | const handleTap = () => { | 64 | const handleTap = () => { |
| 43 | Taro.navigateTo({ | 65 | Taro.navigateTo({ |
| 44 | - url: '../detail/index?id=123', | 66 | + url: `../detail/index?id=abc&start_date=${startDate.value}&end_date=${endDate.value}`, |
| 45 | }) | 67 | }) |
| 46 | } | 68 | } |
| 47 | 69 | ||
| 48 | onMounted(() => { | 70 | onMounted(() => { |
| 49 | - console.warn('房间详情的属性', props.data); | 71 | + // console.warn('选择的日期', props.calenderInfo); |
| 72 | + // console.warn('房间详情的属性', props.data); | ||
| 50 | }) | 73 | }) |
| 51 | 74 | ||
| 52 | </script> | 75 | </script> | ... | ... |
| 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-20 16:31:30 | 4 | + * @LastEditTime: 2023-12-21 13:13:32 |
| 5 | * @FilePath: /meihuaApp/src/pages/book/index.vue | 5 | * @FilePath: /meihuaApp/src/pages/book/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -19,7 +19,7 @@ | ... | @@ -19,7 +19,7 @@ |
| 19 | <view v-if="showContent" class="book-list"> | 19 | <view v-if="showContent" class="book-list"> |
| 20 | <scroll-view ref="refScrollView" :style="scrollStyle" :scroll-y="true" :scroll-with-animation="true" @scrolltolower="onScrollToLower"> | 20 | <scroll-view ref="refScrollView" :style="scrollStyle" :scroll-y="true" :scroll-with-animation="true" @scrolltolower="onScrollToLower"> |
| 21 | <view v-for="(item, index) in bookList" :key="index"> | 21 | <view v-for="(item, index) in bookList" :key="index"> |
| 22 | - <room-card :key="index" :status="item.status"></room-card> | 22 | + <room-card :key="index" :data="item" :calender-info="calenderInfo"></room-card> |
| 23 | <view v-if="index === bookList.length - 1" style="height: 2rem;"></view> | 23 | <view v-if="index === bookList.length - 1" style="height: 2rem;"></view> |
| 24 | </view> | 24 | </view> |
| 25 | </scroll-view> | 25 | </scroll-view> |
| ... | @@ -37,8 +37,13 @@ import navBar from '@/components/navBar.vue' | ... | @@ -37,8 +37,13 @@ import navBar from '@/components/navBar.vue' |
| 37 | import calendarSelect from '@/components/calendarSelect.vue' | 37 | import calendarSelect from '@/components/calendarSelect.vue' |
| 38 | import roomCard from '@/components/roomCard.vue' | 38 | import roomCard from '@/components/roomCard.vue' |
| 39 | 39 | ||
| 40 | +const calenderInfo = ref({}); | ||
| 40 | const onDatesChange = ({ startDate, endDate }) => { | 41 | const onDatesChange = ({ startDate, endDate }) => { |
| 41 | - console.warn(startDate, endDate); | 42 | + // console.warn(startDate, endDate); |
| 43 | + calenderInfo.value = { | ||
| 44 | + startDate, | ||
| 45 | + endDate | ||
| 46 | + } | ||
| 42 | } | 47 | } |
| 43 | 48 | ||
| 44 | const value = ref('0'); | 49 | const value = ref('0'); | ... | ... |
| 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 11:45:01 | 4 | + * @LastEditTime: 2023-12-21 13:44:02 |
| 5 | * @FilePath: /meihuaApp/src/pages/detail/index.vue | 5 | * @FilePath: /meihuaApp/src/pages/detail/index.vue |
| 6 | * @Description: 房间详情页面 | 6 | * @Description: 房间详情页面 |
| 7 | --> | 7 | --> |
| ... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
| 18 | </view> | 18 | </view> |
| 19 | <!-- 日历选择器 --> | 19 | <!-- 日历选择器 --> |
| 20 | <view v-if="showBook" class="book-cal"> | 20 | <view v-if="showBook" class="book-cal"> |
| 21 | - <calendar-select @on-dates-change="onDatesChange"></calendar-select> | 21 | + <calendar-select @on-dates-change="onDatesChange" :start-date="start_date" :end-date="end_date"></calendar-select> |
| 22 | </view> | 22 | </view> |
| 23 | <view v-else class="no-calendar-border"></view> | 23 | <view v-else class="no-calendar-border"></view> |
| 24 | <!-- END --> | 24 | <!-- END --> |
| ... | @@ -49,9 +49,62 @@ import { ref, computed, reactive, onMounted } from "vue"; | ... | @@ -49,9 +49,62 @@ import { ref, computed, reactive, onMounted } from "vue"; |
| 49 | import calendarSelect from '@/components/calendarSelect.vue' | 49 | import calendarSelect from '@/components/calendarSelect.vue' |
| 50 | import { getCurrentPageParam } from "@/utils/weapp"; | 50 | import { getCurrentPageParam } from "@/utils/weapp"; |
| 51 | 51 | ||
| 52 | -onMounted(() => { | 52 | +/** |
| 53 | - console.warn('id', getCurrentPageParam().id); | 53 | + * 获取日期星期几 |
| 54 | -}); | 54 | + * @param {String} dateString 日期字符串 |
| 55 | + */ | ||
| 56 | +const getDayOfWeek = (dateString) => { | ||
| 57 | + var dateParts = dateString.split('-'); | ||
| 58 | + var year = parseInt(dateParts[0]); | ||
| 59 | + var month = parseInt(dateParts[1]) - 1; // 月份从 0 开始,所以要减去 1 | ||
| 60 | + var day = parseInt(dateParts[2]); | ||
| 61 | + | ||
| 62 | + var date = new Date(year, month, day); | ||
| 63 | + var dayOfWeek = date.getDay(); | ||
| 64 | + | ||
| 65 | + // 定义星期几的名称数组 | ||
| 66 | + var days = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']; | ||
| 67 | + | ||
| 68 | + return days[dayOfWeek]; | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +/** | ||
| 72 | + * 计算日期间隔 | ||
| 73 | + * @param {*} startDate | ||
| 74 | + * @param {*} endDate | ||
| 75 | + */ | ||
| 76 | +const getDayDifference = (startDate, endDate) => { | ||
| 77 | + var startParts = startDate.split('-'); | ||
| 78 | + var startYear = parseInt(startParts[0]); | ||
| 79 | + var startMonth = parseInt(startParts[1]) - 1; // 月份从 0 开始,所以要减去 1 | ||
| 80 | + var startDay = parseInt(startParts[2]); | ||
| 81 | + | ||
| 82 | + var endParts = endDate.split('-'); | ||
| 83 | + var endYear = parseInt(endParts[0]); | ||
| 84 | + var endMonth = parseInt(endParts[1]) - 1; // 月份从 0 开始,所以要减去 1 | ||
| 85 | + var endDay = parseInt(endParts[2]); | ||
| 86 | + | ||
| 87 | + var startDateObj = new Date(startYear, startMonth, startDay); | ||
| 88 | + var endDateObj = new Date(endYear, endMonth, endDay); | ||
| 89 | + | ||
| 90 | + // 跨年处理 | ||
| 91 | + if (endYear > startYear) { | ||
| 92 | + endDateObj.setFullYear(endYear); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + // 跨月处理 | ||
| 96 | + if (endMonth > startMonth || (endMonth === startMonth && endDay > startDay)) { | ||
| 97 | + endDateObj.setMonth(endMonth); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + // 计算两个日期之间的时间差(毫秒数) | ||
| 101 | + var timeDiff = endDateObj.getTime() - startDateObj.getTime(); | ||
| 102 | + | ||
| 103 | + // 将时间差转换为天数 | ||
| 104 | + var dayDiff = Math.floor(timeDiff / (1000 * 3600 * 24)); | ||
| 105 | + | ||
| 106 | + return dayDiff; | ||
| 107 | +} | ||
| 55 | 108 | ||
| 56 | const taro_html = ref('<div>123</div>'); | 109 | const taro_html = ref('<div>123</div>'); |
| 57 | 110 | ||
| ... | @@ -77,6 +130,18 @@ const onDatesChange = ({ startDate, endDate, betweenDate, startDateWeek, endDate | ... | @@ -77,6 +130,18 @@ const onDatesChange = ({ startDate, endDate, betweenDate, startDateWeek, endDate |
| 77 | between_date.value = betweenDate; | 130 | between_date.value = betweenDate; |
| 78 | } | 131 | } |
| 79 | 132 | ||
| 133 | +onMounted(() => { | ||
| 134 | + let params = getCurrentPageParam(); | ||
| 135 | + console.warn('id', params.id); | ||
| 136 | + console.warn('start_date', params.start_date); | ||
| 137 | + console.warn('end_date', params.end_date); | ||
| 138 | + start_date.value = params.start_date; | ||
| 139 | + end_date.value = params.end_date; | ||
| 140 | + between_date.value = getDayDifference(params.start_date, params.end_date); | ||
| 141 | + start_date_week.value = JSON.stringify(getDayOfWeek(params.start_date)); | ||
| 142 | + end_date_week.value = JSON.stringify(getDayOfWeek(params.end_date)); | ||
| 143 | +}); | ||
| 144 | + | ||
| 80 | const page = ref(1); | 145 | const page = ref(1); |
| 81 | 146 | ||
| 82 | const goToConfirm = () => { | 147 | const goToConfirm = () => { | ... | ... |
-
Please register or login to post a comment