hookehuyr

新增预约页面逻辑

...@@ -16,6 +16,7 @@ declare module '@vue/runtime-core' { ...@@ -16,6 +16,7 @@ declare module '@vue/runtime-core' {
16 VanCheckbox: typeof import('vant/es')['Checkbox'] 16 VanCheckbox: typeof import('vant/es')['Checkbox']
17 VanCheckboxGroup: typeof import('vant/es')['CheckboxGroup'] 17 VanCheckboxGroup: typeof import('vant/es')['CheckboxGroup']
18 VanCol: typeof import('vant/es')['Col'] 18 VanCol: typeof import('vant/es')['Col']
19 + VanDatePicker: typeof import('vant/es')['DatePicker']
19 VanDialog: typeof import('vant/es')['Dialog'] 20 VanDialog: typeof import('vant/es')['Dialog']
20 VanEmpty: typeof import('vant/es')['Empty'] 21 VanEmpty: typeof import('vant/es')['Empty']
21 VanField: typeof import('vant/es')['Field'] 22 VanField: typeof import('vant/es')['Field']
...@@ -28,5 +29,6 @@ declare module '@vue/runtime-core' { ...@@ -28,5 +29,6 @@ declare module '@vue/runtime-core' {
28 VanRow: typeof import('vant/es')['Row'] 29 VanRow: typeof import('vant/es')['Row']
29 VanSwipe: typeof import('vant/es')['Swipe'] 30 VanSwipe: typeof import('vant/es')['Swipe']
30 VanSwipeItem: typeof import('vant/es')['SwipeItem'] 31 VanSwipeItem: typeof import('vant/es')['SwipeItem']
32 + VanToast: typeof import('vant/es')['Toast']
31 } 33 }
32 } 34 }
......
1 <!-- 1 <!--
2 * @Date: 2024-01-15 13:35:51 2 * @Date: 2024-01-15 13:35:51
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-01-15 16:22:20 4 + * @LastEditTime: 2024-01-16 15:15:07
5 * @FilePath: /xysBooking/src/views/booking.vue 5 * @FilePath: /xysBooking/src/views/booking.vue
6 * @Description: 预约页面 6 * @Description: 预约页面
7 * @Version: 1.0.0 7 * @Version: 1.0.0
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
12 <div class="choose-date"> 12 <div class="choose-date">
13 <div class="title"> 13 <div class="title">
14 <div class="text">选择参访日期</div> 14 <div class="text">选择参访日期</div>
15 - <div class="day">01月</div> 15 + <div @click="chooseDate" class="day">{{ currentDateText }} 月</div>
16 </div> 16 </div>
17 <div class="days-of-week"> 17 <div class="days-of-week">
18 <div v-for="day in daysOfWeek" :key="day" class="item">{{ day }}</div> 18 <div v-for="day in daysOfWeek" :key="day" class="item">{{ day }}</div>
...@@ -28,52 +28,70 @@ ...@@ -28,52 +28,70 @@
28 </div> 28 </div>
29 </div> 29 </div>
30 </div> 30 </div>
31 - <div class="choose-time"> 31 + <div v-if="checked_day" class="choose-time">
32 <div class="title"> 32 <div class="title">
33 <div class="text">选择参访时间段</div> 33 <div class="text">选择参访时间段</div>
34 </div> 34 </div>
35 <div class="time-list"> 35 <div class="time-list">
36 - <div @click="chooseTime(item, index)" v-for="(item, index) in timePeriod" :key="index" class="time"> 36 + <div
37 + @click="chooseTime(item, index)"
38 + v-for="(item, index) in timePeriod"
39 + :key="index"
40 + :class="['time', !item.num ? 'disabled' : '']"
41 + >
37 <div class="left"> 42 <div class="left">
38 <van-icon v-if="checked_time !== index" name="https://cdn.ipadbiz.cn/xys/booking/%E5%8D%95%E9%80%8901@2x.png" />&nbsp; 43 <van-icon v-if="checked_time !== index" name="https://cdn.ipadbiz.cn/xys/booking/%E5%8D%95%E9%80%8901@2x.png" />&nbsp;
39 <van-icon v-else name="https://cdn.ipadbiz.cn/xys/booking/%E5%8D%95%E9%80%8902@2x.png" />&nbsp; 44 <van-icon v-else name="https://cdn.ipadbiz.cn/xys/booking/%E5%8D%95%E9%80%8902@2x.png" />&nbsp;
40 {{ item.left }} 45 {{ item.left }}
41 </div> 46 </div>
42 - <div class="right">余量:{{ item.right }}</div> 47 + <div class="right">
48 + <span v-if="item.num">余量:{{ item.right }}</span>
49 + <span v-else>已约满</span>
50 + </div>
43 </div> 51 </div>
44 </div> 52 </div>
45 </div> 53 </div>
46 </div> 54 </div>
47 <div style="height: 5rem;"></div> 55 <div style="height: 5rem;"></div>
48 <div class="next"> 56 <div class="next">
49 - <div class="button" style="background-color: #A67939;">下一步</div> 57 + <div @click="nextBtn" class="button" style="background-color: #A67939;">下一步</div>
50 </div> 58 </div>
59 +
60 + <van-popup v-model:show="showPicker" position="bottom">
61 + <van-date-picker
62 + v-model="currentDate"
63 + title="选择年月"
64 + :min-date="minDate"
65 + :max-date="maxDate"
66 + :columns-type="columnsType"
67 + @confirm="onConfirm"
68 + @cancel="onCancel"
69 + />
70 + </van-popup>
71 +
72 + <van-toast v-model:show="show_error" style="">
73 + <template #message>
74 + {{ error_message }}
75 + </template>
76 + </van-toast>
51 </div> 77 </div>
52 </template> 78 </template>
53 79
54 <script setup> 80 <script setup>
55 import { ref } from 'vue' 81 import { ref } from 'vue'
56 import { useRoute, useRouter } from 'vue-router' 82 import { useRoute, useRouter } from 'vue-router'
57 - 83 +import { showSuccessToast, showFailToast, showToast } from 'vant';
58 import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js' 84 import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
59 //import { } from '@/utils/generateModules.js' 85 //import { } from '@/utils/generateModules.js'
60 //import { } from '@/utils/generateIcons.js' 86 //import { } from '@/utils/generateIcons.js'
61 //import { } from '@/composables' 87 //import { } from '@/composables'
88 +import { useGo } from '@/hooks/useGo'
89 +
62 const $route = useRoute(); 90 const $route = useRoute();
63 const $router = useRouter(); 91 const $router = useRouter();
64 useTitle($route.meta.title); 92 useTitle($route.meta.title);
65 93
66 -const dates = ref([ 94 +const go = useGo();
67 - "2024-01-01",
68 - "2024-01-02",
69 - "2024-01-03",
70 - "2024-01-04",
71 - "2024-01-05",
72 - "2024-01-06",
73 - "2024-01-07",
74 - "2024-01-08",
75 - "2024-01-09",
76 -]);
77 95
78 const dates_list = ref([{ 96 const dates_list = ref([{
79 date: "2024-01-01", 97 date: "2024-01-01",
...@@ -112,6 +130,7 @@ const dates_list = ref([{ ...@@ -112,6 +130,7 @@ const dates_list = ref([{
112 price: 5, 130 price: 5,
113 num: 1, 131 num: 1,
114 }]); 132 }]);
133 +const dates = ref(dates_list.value.map(item => item.date));
115 134
116 const findDatesInfo = (date) => { 135 const findDatesInfo = (date) => {
117 const result = dates_list.value.find((item) => item.date === date); 136 const result = dates_list.value.find((item) => item.date === date);
...@@ -168,35 +187,62 @@ const checked_time = ref(-1); ...@@ -168,35 +187,62 @@ const checked_time = ref(-1);
168 const timePeriod = ref([{ 187 const timePeriod = ref([{
169 left: '05:00-08:00', 188 left: '05:00-08:00',
170 right: 1098, 189 right: 1098,
190 + num: 1,
171 }, { 191 }, {
172 - left: '05:00-08:00', 192 + left: '08:00-10:00',
173 - right: 1098, 193 + right: 98,
174 -}, { 194 + num: 0,
175 - left: '05:00-08:00', 195 +}]);
176 - right: 1098,
177 -},{
178 - left: '05:00-08:00',
179 - right: 1098,
180 -}, {
181 - left: '05:00-08:00',
182 - right: 1098,
183 -}, {
184 - left: '05:00-08:00',
185 - right: 1098,
186 -}, {
187 - left: '05:00-08:00',
188 - right: 1098,
189 -},]);
190 196
191 -const chooseTime = (item, index) => { 197 +const chooseTime = (item, index) => { // 选择时间段回调
192 - checked_time.value = index; 198 + if (item.num) {
199 + checked_time.value = index;
200 + }
193 console.log(item, index); 201 console.log(item, index);
194 }; 202 };
195 203
196 -const chooseDay = (date) => { 204 +const checked_day_price = ref(0);
197 - checked_day.value = date; 205 +
198 - console.log(date); 206 +const chooseDay = (date) => { // 点击日期回调
207 + if (findDatesInfo(date).num) { // 有余数可约
208 + checked_day.value = date;
209 + checked_day_price.value = findDatesInfo(date).price;
210 + }
199 }; 211 };
212 +
213 +const showPicker = ref(false);
214 +const chooseDate = () => {
215 + showPicker.value = true;
216 +}
217 +
218 +const raw_date = new Date();
219 +const currentDate = ref([raw_date.getFullYear(), raw_date.getMonth()]);
220 +const columnsType = ['year', 'month'];
221 +const minDate = new Date(2024, 0, 1);
222 +const maxDate = new Date(2030, 11, 1);
223 +const currentDateText = ref((raw_date.getMonth() + 1).toString().padStart(2, '0'));
224 +
225 +const onConfirm = ({ selectedValues, selectedOptions }) => { // 选择日期回调
226 + showPicker.value = false;
227 + currentDateText.value = selectedValues[1].toString();
228 + // 清空选择
229 + checked_day.value = '';
230 + checked_time.value = -1;
231 +}
232 +const onCancel = () => {
233 + showPicker.value = false;
234 +}
235 +
236 +const show_error = ref(false);
237 +const error_message = ref('');
238 +const nextBtn = () => {
239 + if (!checked_day.value || checked_time.value === -1) {
240 + show_error.value = true;
241 + error_message.value = '请选择日期和时间段';
242 + } else {
243 + go('/submit', { date: checked_day.value, time: timePeriod.value[checked_time.value]['left'], price: checked_day_price.value });
244 + }
245 +}
200 </script> 246 </script>
201 247
202 <style lang="less" scoped> 248 <style lang="less" scoped>
...@@ -241,7 +287,7 @@ const chooseDay = (date) => { ...@@ -241,7 +287,7 @@ const chooseDay = (date) => {
241 display: flex; 287 display: flex;
242 padding: 0.5em 1%; 288 padding: 0.5em 1%;
243 .item { 289 .item {
244 - width: 11%; 290 + width: 11.5%;
245 text-align: center; 291 text-align: center;
246 margin: 0 0.3rem; 292 margin: 0 0.3rem;
247 padding: 0.5rem 0; 293 padding: 0.5rem 0;
...@@ -306,6 +352,15 @@ const chooseDay = (date) => { ...@@ -306,6 +352,15 @@ const chooseDay = (date) => {
306 .right { 352 .right {
307 color: #A67939; 353 color: #A67939;
308 } 354 }
355 + &.disabled {
356 + background-color: #E0E0E0;
357 + .left {
358 + color: #C7C7C7;
359 + }
360 + .right {
361 + color: #C7C7C7;
362 + }
363 + }
309 } 364 }
310 } 365 }
311 } 366 }
......