Showing
4 changed files
with
154 additions
and
19 deletions
| ... | @@ -14,6 +14,7 @@ declare module '@vue/runtime-core' { | ... | @@ -14,6 +14,7 @@ declare module '@vue/runtime-core' { |
| 14 | NavBar: typeof import('./src/components/navBar.vue')['default'] | 14 | NavBar: typeof import('./src/components/navBar.vue')['default'] |
| 15 | NutCalendar: typeof import('@nutui/nutui-taro')['Calendar'] | 15 | NutCalendar: typeof import('@nutui/nutui-taro')['Calendar'] |
| 16 | NutCol: typeof import('@nutui/nutui-taro')['Col'] | 16 | NutCol: typeof import('@nutui/nutui-taro')['Col'] |
| 17 | + NutConfigProvider: typeof import('@nutui/nutui-taro')['ConfigProvider'] | ||
| 17 | NutRow: typeof import('@nutui/nutui-taro')['Row'] | 18 | NutRow: typeof import('@nutui/nutui-taro')['Row'] |
| 18 | Picker: typeof import('./src/components/time-picker-data/picker.vue')['default'] | 19 | Picker: typeof import('./src/components/time-picker-data/picker.vue')['default'] |
| 19 | PosterBuilder: typeof import('./src/components/PosterBuilder/index.vue')['default'] | 20 | PosterBuilder: typeof import('./src/components/PosterBuilder/index.vue')['default'] | ... | ... |
| 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-14 18:25:51 | 4 | + * @LastEditTime: 2023-12-15 10:48:55 |
| 5 | * @FilePath: /meihuaApp/src/components/calendarSelect.vue | 5 | * @FilePath: /meihuaApp/src/components/calendarSelect.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| 9 | <view class="calendar-select-page" @tap="openCalendar"> | 9 | <view class="calendar-select-page" @tap="openCalendar"> |
| 10 | <nut-row gutter="10"> | 10 | <nut-row gutter="10"> |
| 11 | - <nut-col span="10"> | 11 | + <nut-col span="9"> |
| 12 | <view style="color: #7D7C7C; font-size: 0.8rem;">入住日期</view> | 12 | <view style="color: #7D7C7C; font-size: 0.8rem;">入住日期</view> |
| 13 | - <view style="color: #6A4925; font-size: 0.95rem; font-weight: bold;">2023.12.07 星期四</view> | 13 | + <view style="color: #6A4925; font-size: 0.85rem; font-weight: bold;">{{ state.checkinDate}} {{ getDayOfWeek(state.checkinDate) }}</view> |
| 14 | </nut-col> | 14 | </nut-col> |
| 15 | - <nut-col span="4"> | 15 | + <nut-col span="5"> |
| 16 | <view style="color: #6A4925; margin-top: 15%; font-size: 0.8rem; text-align: center; background-color: #fff; padding: 0.25rem 0; border-radius: 0.5rem;"> | 16 | <view style="color: #6A4925; margin-top: 15%; font-size: 0.8rem; text-align: center; background-color: #fff; padding: 0.25rem 0; border-radius: 0.5rem;"> |
| 17 | - 共1晚 | 17 | + 共{{ state.betweenDate }}晚 |
| 18 | </view> | 18 | </view> |
| 19 | </nut-col> | 19 | </nut-col> |
| 20 | - <nut-col span="10"> | 20 | + <nut-col span="9"> |
| 21 | <view style="color: #7D7C7C; font-size: 0.8rem;">退房日期</view> | 21 | <view style="color: #7D7C7C; font-size: 0.8rem;">退房日期</view> |
| 22 | - <view style="color: #6A4925; font-size: 0.95rem; font-weight: bold;">2023.12.08 星期五</view> | 22 | + <view style="color: #6A4925; font-size: 0.85rem; font-weight: bold;">{{ state.checkoutDate }} {{ getDayOfWeek(state.checkoutDate) }}</view> |
| 23 | </nut-col> | 23 | </nut-col> |
| 24 | </nut-row> | 24 | </nut-row> |
| 25 | </view> | 25 | </view> |
| 26 | + <nut-config-provider :theme-vars="themeVars"> | ||
| 26 | <nut-calendar | 27 | <nut-calendar |
| 27 | v-model:visible="state.isVisible" | 28 | v-model:visible="state.isVisible" |
| 28 | - :default-value="state.date" | 29 | + :default-value="state.defaultDate" |
| 29 | type="range" | 30 | type="range" |
| 30 | - :start-date="`2019-12-22`" | 31 | + :start-date="state.startDate" |
| 31 | - :end-date="`2021-01-08`" | 32 | + :end-date="state.endDate" |
| 33 | + start-text="入住" | ||
| 34 | + end-text="退房" | ||
| 32 | @close="closeSwitch('isVisible')" | 35 | @close="closeSwitch('isVisible')" |
| 33 | @choose="setChooseValue" | 36 | @choose="setChooseValue" |
| 34 | @select="select" | 37 | @select="select" |
| 35 | > | 38 | > |
| 36 | </nut-calendar> | 39 | </nut-calendar> |
| 40 | + </nut-config-provider> | ||
| 37 | </template> | 41 | </template> |
| 38 | 42 | ||
| 39 | <script setup> | 43 | <script setup> |
| 40 | -import { ref, reactive } from 'vue' | 44 | +import { ref, reactive, onMounted } from 'vue' |
| 45 | + | ||
| 46 | +/** | ||
| 47 | + * 获取今天和明天日期 | ||
| 48 | + */ | ||
| 49 | +const getTodayAndTomorrow = () => { | ||
| 50 | + var today = new Date(); // 获取当前日期 | ||
| 51 | + | ||
| 52 | + var todayYear = today.getFullYear(); | ||
| 53 | + var todayMonth = today.getMonth() + 1; // 月份从0开始,所以要加1 | ||
| 54 | + var todayDay = today.getDate(); | ||
| 55 | + | ||
| 56 | + var tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000); // 获取明天日期 | ||
| 57 | + | ||
| 58 | + var tomorrowYear = tomorrow.getFullYear(); | ||
| 59 | + var tomorrowMonth = tomorrow.getMonth() + 1; // 月份从0开始,所以要加1 | ||
| 60 | + var tomorrowDay = tomorrow.getDate(); | ||
| 61 | + | ||
| 62 | + // 跨年处理 | ||
| 63 | + if (tomorrowYear > todayYear) { | ||
| 64 | + tomorrowMonth = '01'; | ||
| 65 | + tomorrowDay = '01'; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + // 跨月处理 | ||
| 69 | + if (tomorrowMonth > 12) { | ||
| 70 | + tomorrowMonth = '01'; | ||
| 71 | + tomorrowYear = todayYear + 1; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + // 格式化为两位数 | ||
| 75 | + todayMonth = todayMonth < 10 ? '0' + todayMonth : todayMonth; | ||
| 76 | + todayDay = todayDay < 10 ? '0' + todayDay : todayDay; | ||
| 77 | + tomorrowMonth = tomorrowMonth < 10 ? '0' + tomorrowMonth : tomorrowMonth; | ||
| 78 | + tomorrowDay = tomorrowDay < 10 ? '0' + tomorrowDay : tomorrowDay; | ||
| 79 | + | ||
| 80 | + return { | ||
| 81 | + today: todayYear + '-' + todayMonth + '-' + todayDay, | ||
| 82 | + tomorrow: tomorrowYear + '-' + tomorrowMonth + '-' + tomorrowDay | ||
| 83 | + }; | ||
| 84 | +} | ||
| 85 | + | ||
| 86 | +/** | ||
| 87 | + * 获取日期星期几 | ||
| 88 | + * @param {String} dateString 日期字符串 | ||
| 89 | + */ | ||
| 90 | +const getDayOfWeek = (dateString) => { | ||
| 91 | + var dateParts = dateString.split('-'); | ||
| 92 | + var year = parseInt(dateParts[0]); | ||
| 93 | + var month = parseInt(dateParts[1]) - 1; // 月份从 0 开始,所以要减去 1 | ||
| 94 | + var day = parseInt(dateParts[2]); | ||
| 95 | + | ||
| 96 | + var date = new Date(year, month, day); | ||
| 97 | + var dayOfWeek = date.getDay(); | ||
| 98 | + | ||
| 99 | + // 定义星期几的名称数组 | ||
| 100 | + var days = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']; | ||
| 101 | + | ||
| 102 | + return days[dayOfWeek]; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +/** | ||
| 106 | + * 计算日期间隔 | ||
| 107 | + * @param {*} startDate | ||
| 108 | + * @param {*} endDate | ||
| 109 | + */ | ||
| 110 | +const getDayDifference = (startDate, endDate) => { | ||
| 111 | + var startParts = startDate.split('-'); | ||
| 112 | + var startYear = parseInt(startParts[0]); | ||
| 113 | + var startMonth = parseInt(startParts[1]) - 1; // 月份从 0 开始,所以要减去 1 | ||
| 114 | + var startDay = parseInt(startParts[2]); | ||
| 115 | + | ||
| 116 | + var endParts = endDate.split('-'); | ||
| 117 | + var endYear = parseInt(endParts[0]); | ||
| 118 | + var endMonth = parseInt(endParts[1]) - 1; // 月份从 0 开始,所以要减去 1 | ||
| 119 | + var endDay = parseInt(endParts[2]); | ||
| 120 | + | ||
| 121 | + var startDateObj = new Date(startYear, startMonth, startDay); | ||
| 122 | + var endDateObj = new Date(endYear, endMonth, endDay); | ||
| 123 | + | ||
| 124 | + // 跨年处理 | ||
| 125 | + if (endYear > startYear) { | ||
| 126 | + endDateObj.setFullYear(endYear); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + // 跨月处理 | ||
| 130 | + if (endMonth > startMonth || (endMonth === startMonth && endDay > startDay)) { | ||
| 131 | + endDateObj.setMonth(endMonth); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + // 计算两个日期之间的时间差(毫秒数) | ||
| 135 | + var timeDiff = endDateObj.getTime() - startDateObj.getTime(); | ||
| 136 | + | ||
| 137 | + // 将时间差转换为天数 | ||
| 138 | + var dayDiff = Math.floor(timeDiff / (1000 * 3600 * 24)); | ||
| 139 | + | ||
| 140 | + return dayDiff; | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +// 调用方法获取今天和明天的日期 | ||
| 144 | +const dates = getTodayAndTomorrow(); | ||
| 145 | + | ||
| 146 | +const emit = defineEmits(['on-dates-change']); | ||
| 41 | 147 | ||
| 42 | const state = reactive({ | 148 | const state = reactive({ |
| 43 | - date: ['2019-12-23', '2019-12-26'], | 149 | + startDate: dates.today, |
| 150 | + endDate: '', | ||
| 151 | + checkinDate: dates.today, | ||
| 152 | + checkoutDate: dates.tomorrow, | ||
| 153 | + defaultDate: [dates.today, dates.tomorrow], | ||
| 154 | + betweenDate: getDayDifference(dates.today, dates.tomorrow), | ||
| 44 | isVisible: false | 155 | isVisible: false |
| 45 | }); | 156 | }); |
| 46 | 157 | ||
| 158 | +const themeVars = reactive({ | ||
| 159 | + primaryColor: '#6A4925', | ||
| 160 | + primaryColorEnd: '#6A4925' | ||
| 161 | +}); | ||
| 162 | + | ||
| 163 | +onMounted(() => { | ||
| 164 | +}) | ||
| 165 | + | ||
| 47 | const openSwitch = (param) => { | 166 | const openSwitch = (param) => { |
| 48 | state[`${param}`] = true; | 167 | state[`${param}`] = true; |
| 49 | }; | 168 | }; |
| 50 | const closeSwitch = (param) => { | 169 | const closeSwitch = (param) => { |
| 51 | state[`${param}`] = false; | 170 | state[`${param}`] = false; |
| 52 | }; | 171 | }; |
| 172 | + | ||
| 173 | +/** | ||
| 174 | + * 日历控件选择日期确认回调 | ||
| 175 | + * @param {*} param | ||
| 176 | + */ | ||
| 177 | + | ||
| 53 | const setChooseValue = (param) => { | 178 | const setChooseValue = (param) => { |
| 54 | - // state.date = [...[param[0][3], param[1][3]]]; | 179 | + state.checkinDate = param[0][3]; |
| 55 | - console.warn(param); | 180 | + state.checkoutDate = param[1][3]; |
| 181 | + state.defaultDate = [state.checkinDate, state.checkoutDate]; | ||
| 182 | + state.betweenDate = getDayDifference(state.checkinDate, state.checkoutDate); | ||
| 183 | + emit('on-dates-change', { startDate: state.checkinDate, endDate: state.checkoutDate }); | ||
| 56 | }; | 184 | }; |
| 185 | + | ||
| 186 | + | ||
| 57 | const select = (param) => { | 187 | const select = (param) => { |
| 58 | - console.warn(param); | ||
| 59 | }; | 188 | }; |
| 60 | 189 | ||
| 61 | const show = ref(false); | 190 | const show = ref(false); |
| ... | @@ -78,6 +207,7 @@ const onConfirm = (event) => { | ... | @@ -78,6 +207,7 @@ const onConfirm = (event) => { |
| 78 | .calendar-select-page { | 207 | .calendar-select-page { |
| 79 | background-color: #F6ECE1; | 208 | background-color: #F6ECE1; |
| 80 | border-radius: 0.5rem; | 209 | border-radius: 0.5rem; |
| 81 | - padding: 1rem; | 210 | + padding: 1rem 0; |
| 211 | + padding-left: 0.5rem; | ||
| 82 | } | 212 | } |
| 83 | </style> | 213 | </style> | ... | ... |
| 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-14 18:23:40 | 4 | + * @LastEditTime: 2023-12-15 10:43:48 |
| 5 | * @FilePath: /meihuaApp/src/pages/book/index.vue | 5 | * @FilePath: /meihuaApp/src/pages/book/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
| 10 | <view class="cover-header"></view> | 10 | <view class="cover-header"></view> |
| 11 | <view class="book-content"> | 11 | <view class="book-content"> |
| 12 | <view class="book-calc"> | 12 | <view class="book-calc"> |
| 13 | - <calendar-select></calendar-select> | 13 | + <calendar-select @on-dates-change="onDatesChange"></calendar-select> |
| 14 | </view> | 14 | </view> |
| 15 | <view class="book-type">类型选择</view> | 15 | <view class="book-type">类型选择</view> |
| 16 | <view class="book-list">scroll-view</view> | 16 | <view class="book-list">scroll-view</view> |
| ... | @@ -24,6 +24,10 @@ import Taro from '@tarojs/taro' | ... | @@ -24,6 +24,10 @@ import Taro from '@tarojs/taro' |
| 24 | import { ref } from "vue"; | 24 | import { ref } from "vue"; |
| 25 | import calendarSelect from '@/components/calendarSelect.vue' | 25 | import calendarSelect from '@/components/calendarSelect.vue' |
| 26 | import navBar from '@/components/navBar.vue' | 26 | import navBar from '@/components/navBar.vue' |
| 27 | + | ||
| 28 | +const onDatesChange = ({ startDate, endDate }) => { | ||
| 29 | + console.warn(startDate, endDate); | ||
| 30 | +} | ||
| 27 | </script> | 31 | </script> |
| 28 | 32 | ||
| 29 | <script> | 33 | <script> | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2023-12-13 11:13:13 | 2 | * @Date: 2023-12-13 11:13:13 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-12-14 18:24:03 | 4 | + * @LastEditTime: 2023-12-15 10:42:58 |
| 5 | * @FilePath: /meihuaApp/src/pages/my/index.vue | 5 | * @FilePath: /meihuaApp/src/pages/my/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> | ... | ... |
-
Please register or login to post a comment