hookehuyr

细节完善

1 <!-- 1 <!--
2 * @Date: 2023-06-21 10:23:09 2 * @Date: 2023-06-21 10:23:09
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-08-24 15:11:10 4 + * @LastEditTime: 2023-08-25 10:36:50
5 - * @FilePath: /front/src/views/index.vue 5 + * @FilePath: /bieyuan/src/views/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
50 <van-icon size="1.5rem" name="https://cdn.ipadbiz.cn/bieyuan/hua01@2x.png" /> 50 <van-icon size="1.5rem" name="https://cdn.ipadbiz.cn/bieyuan/hua01@2x.png" />
51 </div> 51 </div>
52 </div> 52 </div>
53 - <div :class="['more', 'item', index === -1 ? 'selected' : '']"> 53 + <div @click="showMore" :class="['more', 'item', index === -1 ? 'selected' : '']">
54 <div style="margin-top: 1rem;"> 54 <div style="margin-top: 1rem;">
55 <van-icon size="1.25rem" name="https://cdn.ipadbiz.cn/bieyuan/rili@2x.png" /> 55 <van-icon size="1.25rem" name="https://cdn.ipadbiz.cn/bieyuan/rili@2x.png" />
56 </div> 56 </div>
57 - <div style="color: #93663D;" @click="showMore">更多</div> 57 + <div style="color: #93663D;">更多</div>
58 <div style="position: absolute; bottom: -0.7rem; left: calc(50% - 0.6rem)"> 58 <div style="position: absolute; bottom: -0.7rem; left: calc(50% - 0.6rem)">
59 <van-icon size="1.2rem" name="https://cdn.ipadbiz.cn/bieyuan/hua01@2x.png" /> 59 <van-icon size="1.2rem" name="https://cdn.ipadbiz.cn/bieyuan/hua01@2x.png" />
60 </div> 60 </div>
...@@ -92,7 +92,15 @@ ...@@ -92,7 +92,15 @@
92 <div @click="clickNext" class="next-btn">下一步</div> 92 <div @click="clickNext" class="next-btn">下一步</div>
93 </div> 93 </div>
94 94
95 - <van-calendar v-model:show="show" type="multiple" :max-range="7" @confirm="onConfirm" color="#93663D" /> 95 + <van-calendar
96 + v-model:show="show"
97 + type="multiple"
98 + :max-range="7"
99 + :formatter="formatter"
100 + :max-date="maxDate"
101 + color="#93663D"
102 + @confirm="onConfirm"
103 + />
96 </div> 104 </div>
97 </template> 105 </template>
98 106
...@@ -110,6 +118,10 @@ const $route = useRoute(); ...@@ -110,6 +118,10 @@ const $route = useRoute();
110 const $router = useRouter(); 118 const $router = useRouter();
111 useTitle($route.meta.title); 119 useTitle($route.meta.title);
112 120
121 +function getDaysInMonth(year, month) {
122 + return new Date(year, month, 0).getDate();
123 +}
124 +
113 onMounted(async () => { 125 onMounted(async () => {
114 const { data } = await orderRestCountAPI(); 126 const { data } = await orderRestCountAPI();
115 // 获取三天数据 127 // 获取三天数据
...@@ -138,10 +150,36 @@ const selectedDates = ref([]); ...@@ -138,10 +150,36 @@ const selectedDates = ref([]);
138 const index = ref(0); 150 const index = ref(0);
139 const shortcut = ref([]); 151 const shortcut = ref([]);
140 152
141 -const showMore = () => { 153 +const asyncData = ref();
154 +const showMore = async () => {
142 show.value = true; 155 show.value = true;
156 + const { data } = await orderRestCountAPI({ start_date: dayjs().format('YYYY-MM-DD'), end_date: dayjs(maxDate.value).format('YYYY-MM-DD') });
157 + asyncData.value = data;
158 + asyncData.value.forEach(item => {
159 + item.format = item.date.split('-')
160 + });
143 } 161 }
144 162
163 +const formatter = computed(() => {
164 + if (!asyncData.value) {
165 + return (day) => day;
166 + }
167 + return (day) => {
168 + const year = day.date.getFullYear();
169 + const month = day.date.getMonth() + 1;
170 + const date = day.date.getDate();
171 +
172 + asyncData.value.forEach(item => {
173 + const arr = item.format;
174 + if (year === +arr[0] && month === +arr[1] && date === +arr[2]) {
175 + // day.topInfo = '剩余';
176 + day.bottomInfo = item.rest_count;
177 + }
178 + });
179 + return day;
180 + };
181 +});
182 +
145 const onConfirm = (dates) => { // 选择日历确定回调 183 const onConfirm = (dates) => { // 选择日历确定回调
146 show.value = false; 184 show.value = false;
147 index.value = -1; 185 index.value = -1;
...@@ -198,6 +236,14 @@ const clickNext = () => { // 点击下一步按钮 ...@@ -198,6 +236,14 @@ const clickNext = () => { // 点击下一步按钮
198 } 236 }
199 } 237 }
200 238
239 +// 最大日期默认为6个月
240 +const getFutureDate = () => {
241 + const currentDate = new Date();
242 + const futureDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 6, currentDate.getDate());
243 + return futureDate;
244 +}
245 +const maxDate = ref(getFutureDate());
246 +
201 const isPositiveInteger = (value) => { 247 const isPositiveInteger = (value) => {
202 // 判断是否为数字 248 // 判断是否为数字
203 if (typeof value !== 'number') { 249 if (typeof value !== 'number') {
......
1 <!-- 1 <!--
2 * @Date: 2023-08-22 14:13:07 2 * @Date: 2023-08-22 14:13:07
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-08-24 15:19:19 4 + * @LastEditTime: 2023-08-24 17:02:52
5 - * @FilePath: /front/src/views/next.vue 5 + * @FilePath: /bieyuan/src/views/next.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
...@@ -124,10 +124,6 @@ const validatorId = (val) => { ...@@ -124,10 +124,6 @@ const validatorId = (val) => {
124 }; 124 };
125 125
126 const onSubmit = async () => { 126 const onSubmit = async () => {
127 - // const { data, msg } = await orderAddAPI({ dates: $route.query.dates, details: userInfo.value });
128 - // if (data) {
129 -
130 - // }
131 // 提交预约信息 127 // 提交预约信息
132 axios.post('/srv/?a=order_add', { 128 axios.post('/srv/?a=order_add', {
133 dates: JSON.parse($route.query.dates), 129 dates: JSON.parse($route.query.dates),
......
...@@ -51,8 +51,16 @@ ...@@ -51,8 +51,16 @@
51 <div @click="clickNext" class="next-btn">下一步</div> 51 <div @click="clickNext" class="next-btn">下一步</div>
52 </div> 52 </div>
53 53
54 - <van-calendar :default-date="defaultDate" v-model:show="show" type="multiple" :max-range="7" @confirm="onConfirm" 54 + <van-calendar
55 - color="#93663D" /> 55 + v-model:show="show"
56 + :default-date="defaultDate"
57 + type="multiple"
58 + :max-range="7"
59 + :formatter="formatter"
60 + :max-date="maxDate"
61 + color="#93663D"
62 + @confirm="onConfirm"
63 + />
56 </div> 64 </div>
57 </template> 65 </template>
58 66
...@@ -70,6 +78,10 @@ const $route = useRoute(); ...@@ -70,6 +78,10 @@ const $route = useRoute();
70 const $router = useRouter(); 78 const $router = useRouter();
71 useTitle($route.meta.title); 79 useTitle($route.meta.title);
72 80
81 +function getDaysInMonth(year, month) {
82 + return new Date(year, month, 0).getDate();
83 +}
84 +
73 onMounted(async () => { 85 onMounted(async () => {
74 const dates = $route.query.dates && JSON.parse($route.query.dates); 86 const dates = $route.query.dates && JSON.parse($route.query.dates);
75 const { data } = await orderRestCountAPI({ dates }); 87 const { data } = await orderRestCountAPI({ dates });
...@@ -82,6 +94,12 @@ onMounted(async () => { ...@@ -82,6 +94,12 @@ onMounted(async () => {
82 }); 94 });
83 // 获取默认日期集合 95 // 获取默认日期集合
84 selectedDates.value = shortcut.value.map(item => item.date); 96 selectedDates.value = shortcut.value.map(item => item.date);
97 + // 默认勾选日历信息
98 + let default_date = JSON.parse($route.query.dates);
99 + defaultDate.value = [];
100 + default_date.forEach((date) => {
101 + defaultDate.value.push(dayjs(date).toDate())
102 + });
85 }); 103 });
86 104
87 const defaultDate = ref(null); 105 const defaultDate = ref(null);
...@@ -95,27 +113,49 @@ const num = ref(1); ...@@ -95,27 +113,49 @@ const num = ref(1);
95 const show = ref(false); 113 const show = ref(false);
96 const selectedDates = ref([]); 114 const selectedDates = ref([]);
97 115
98 -const showMore = () => { 116 +const asyncData = ref();
117 +const showMore = async () => {
99 show.value = true; 118 show.value = true;
100 - // 默认勾选日历信息 119 + const { data } = await orderRestCountAPI({ start_date: dayjs().format('YYYY-MM-DD'), end_date: dayjs(maxDate.value).format('YYYY-MM-DD') });
101 - let default_date = JSON.parse($route.query.dates); 120 + asyncData.value = data;
102 - defaultDate.value = []; 121 + asyncData.value.forEach(item => {
103 - default_date.forEach((date) => { 122 + item.format = item.date.split('-')
104 - defaultDate.value.push(dayjs(date).toDate())
105 }); 123 });
106 } 124 }
125 +
126 +const formatter = computed(() => {
127 + if (!asyncData.value) {
128 + return (day) => day;
129 + }
130 + return (day) => {
131 + const year = day.date.getFullYear();
132 + const month = day.date.getMonth() + 1;
133 + const date = day.date.getDate();
134 +
135 + asyncData.value.forEach(item => {
136 + const arr = item.format;
137 + if (year === +arr[0] && month === +arr[1] && date === +arr[2]) {
138 + // day.topInfo = '剩余';
139 + day.bottomInfo = item.rest_count;
140 + }
141 + });
142 + return day;
143 + };
144 +});
145 +
107 const onConfirm = async (dates) => { 146 const onConfirm = async (dates) => {
108 show.value = false; 147 show.value = false;
109 selectedDates.value = []; 148 selectedDates.value = [];
110 dates.forEach((date) => { 149 dates.forEach((date) => {
111 selectedDates.value.push(dayjs(date).format('YYYY-MM-DD')) 150 selectedDates.value.push(dayjs(date).format('YYYY-MM-DD'))
151 + defaultDate.value.push(dayjs(date).toDate())
112 }); 152 });
113 // 后台请求数据 153 // 后台请求数据
114 const { data } = await orderRestCountAPI({ dates : selectedDates.value }); 154 const { data } = await orderRestCountAPI({ dates : selectedDates.value });
115 shortcut.value = data; 155 shortcut.value = data;
116 shortcut.value.forEach(item => { 156 shortcut.value.forEach(item => {
117 item.checked = true; 157 item.checked = true;
118 - }) 158 + });
119 }; 159 };
120 160
121 const selectIndex = (idx) => { 161 const selectIndex = (idx) => {
...@@ -129,6 +169,14 @@ const clickPlus = () => { ...@@ -129,6 +169,14 @@ const clickPlus = () => {
129 num.value = num.value + 1; 169 num.value = num.value + 1;
130 } 170 }
131 171
172 +// 最大日期默认为6个月
173 +const getFutureDate = () => {
174 + const currentDate = new Date();
175 + const futureDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 6, currentDate.getDate());
176 + return futureDate;
177 +}
178 +const maxDate = ref(getFutureDate());
179 +
132 const isPositiveInteger = (value) => { 180 const isPositiveInteger = (value) => {
133 // 判断是否为数字 181 // 判断是否为数字
134 if (typeof value !== 'number') { 182 if (typeof value !== 'number') {
......