Quellcode durchsuchen

修改预约日历的显示

wangfumin vor 1 Monat
Ursprung
Commit
b69858a47c

+ 51 - 33
components/active-time-select/index.js

@@ -330,10 +330,12 @@ Component({
       console.log('今天状态检查:', {
         isInOpenRange,
         todayStatus,
+        openStart,
+        openEnd,
         activityData: this.data.activityData
       });
       
-      // 只有今天可以选择时才默认选中(今天状态为'今天'表示可约)
+      // 如果今天在开放的时间段内,则默认选中今天
       if (isInOpenRange && (todayStatus === '今天' || todayStatus === '已开放')) {
         this.setData({
           selectedDate: today
@@ -350,39 +352,35 @@ Component({
         
         console.log('默认选中今天:', today, '状态:', todayStatus);
       } else {
-        // 今天不可选择时,如果有活动数据且活动开始时间在未来,选择活动开始时间
-        if (this.data.activityData && this.data.activityData.startTime) {
-          const activityStartDate = new Date(this.data.activityData.startTime);
-          activityStartDate.setHours(0, 0, 0, 0);
+        // 如果开放的时间段在未来,则选择时间段的第一天
+        if (openStart > today) {
+          const firstAvailableDate = new Date(openStart);
+          const firstDateStatus = this.getDateStatus(firstAvailableDate, false, false, true);
           
-          // 检查活动开始时间是否在未来且在活动时间范围内
-          if (activityStartDate >= today && this.isDateInOpenRange(activityStartDate, openStart, openEnd)) {
-            const startDateStatus = this.getDateStatus(activityStartDate, false, false, true);
-            if (startDateStatus === '已开放') {
-              this.setData({
-                selectedDate: activityStartDate
-              });
-              
-              // 更新日历显示以反映选中状态
-              this.updateDayClasses();
-              
-              // 触发自定义事件,向父组件传递默认选择的日期
-              this.triggerEvent('datechange', {
-                date: activityStartDate,
-                dateString: this.formatDate(activityStartDate)
-              });
-              
-              console.log('默认选中活动开始时间:', activityStartDate);
-              return;
-            }
+          if (firstDateStatus === '已开放' || firstDateStatus === '今天') {
+            this.setData({
+              selectedDate: firstAvailableDate
+            });
+            
+            // 更新日历显示以反映选中状态
+            this.updateDayClasses();
+            
+            // 触发自定义事件,向父组件传递默认选择的日期
+            this.triggerEvent('datechange', {
+              date: firstAvailableDate,
+              dateString: this.formatDate(firstAvailableDate)
+            });
+            
+            console.log('默认选中开放时间段的第一天:', firstAvailableDate, '状态:', firstDateStatus);
+            return;
           }
         }
         
-        // 今天不可选择且没有合适的活动开始时间时,确保selectedDate为null
+        // 如果都不满足条件,确保selectedDate为null
         this.setData({
           selectedDate: null
         });
-        console.log('今天不可选择,不默认选中。状态:', todayStatus);
+        console.log('无合适的默认日期可选择');
       }
     },
 
@@ -403,19 +401,39 @@ Component({
       const { startTime, endTime } = this.data.activityData;
       if (!startTime || !endTime) return;
       
+      const today = new Date();
+      today.setHours(0, 0, 0, 0);
+      
       const startDate = new Date(startTime);
       const endDate = new Date(endTime);
+      startDate.setHours(0, 0, 0, 0);
+      endDate.setHours(23, 59, 59, 999);
+      
+      let targetYear, targetMonth;
+      
+      // 判断今天是否在时间段内
+      const isTodayInRange = this.isDateInOpenRange(today, startDate, endDate);
+      
+      if (isTodayInRange) {
+        // 如果今天在时间段内,跳转到今天所在的月份
+        targetYear = today.getFullYear();
+        targetMonth = today.getMonth() + 1;
+        console.log('今天在活动时间段内,跳转到今天所在月份:', targetYear, targetMonth);
+      } else {
+        // 如果今天不在时间段内,跳转到开放时间段第一天所在的月份
+        targetYear = startDate.getFullYear();
+        targetMonth = startDate.getMonth() + 1;
+        console.log('今天不在活动时间段内,跳转到开放时间段第一天所在月份:', targetYear, targetMonth);
+      }
       
-      // 如果开始时间不在当前月份,跳转到开始时间所在月份
       const currentYear = this.data.currentYear;
       const currentMonth = this.data.currentMonth;
-      const startYear = startDate.getFullYear();
-      const startMonth = startDate.getMonth() + 1;
       
-      if (startYear !== currentYear || startMonth !== currentMonth) {
+      // 如果目标月份不是当前月份,则跳转
+      if (targetYear !== currentYear || targetMonth !== currentMonth) {
         this.setData({
-          currentYear: startYear,
-          currentMonth: startMonth
+          currentYear: targetYear,
+          currentMonth: targetMonth
         }, () => {
           this.initCalendar();
           this.initDefaultDate();

+ 15 - 7
components/time-select/time-select.js

@@ -223,6 +223,11 @@ Component({
       const weekdayKey = weekdayMap[dayOfWeek];
       const availableSlots = this.data.apiData && this.data.apiData.time ? this.data.apiData.time[weekdayKey] : 0;
       
+      // 如果值是-1,则显示闭馆
+      if (availableSlots === -1 || (!availableSlots && availableSlots !== 0)) {
+        return '闭馆';
+      }
+      
       if (isToday) {
         return availableSlots > 0 ? '今天' : '已约满';
       } else {
@@ -251,12 +256,12 @@ Component({
       if (day.isPast) classes.push('past');
       
       // 可选择状态
-      if (day.isInOpenRange && !day.isPast && day.status !== '已约满' && day.status !== '未开放') {
+      if (day.isInOpenRange && !day.isPast && day.status !== '已约满' && day.status !== '未开放' && day.status !== '闭馆') {
         classes.push('selectable');
       }
       
-      // 选中状态 - 优先级最高
-      if (isSelected && day.status !== '未开放') {
+      // 选中状态 - 优先级最高,排除未开放和闭馆状态
+      if (isSelected && day.status !== '未开放' && day.status !== '闭馆') {
         classes.push('selected');
       }
       
@@ -270,6 +275,9 @@ Component({
       if (day.status === '已约满') {
         classes.push('full');
       }
+      if (day.status === '闭馆') {
+        classes.push('closed');
+      }
       
       return classes.join(' ');
     },
@@ -298,8 +306,8 @@ Component({
         return;
       }
       
-      // 只有开放日期范围内且未过期且未约满且不是未开放的日期才可选择
-      if (day.isInOpenRange && !day.isPast && day.status !== '已约满' && day.status !== '未开放') {
+      // 只有开放日期范围内且未过期且未约满且不是未开放且不是闭馆的日期才可选择
+      if (day.isInOpenRange && !day.isPast && day.status !== '已约满' && day.status !== '未开放' && day.status !== '闭馆') {
         this.setData({
           selectedDate: day.fullDate
         });
@@ -370,8 +378,8 @@ Component({
         apiData: this.data.apiData
       });
       
-      // 只有今天可以选择时才默认选中(今天状态为'今天'表示可约)
-      if (isInOpenRange && (todayStatus === '今天' || todayStatus === '已开放')) {
+      // 只有今天可以选择时才默认选中(今天状态为'今天'或'已开放'表示可约,排除闭馆状态
+      if (isInOpenRange && (todayStatus === '今天' || todayStatus === '已开放') && todayStatus !== '闭馆') {
         this.setData({
           selectedDate: today
         });

+ 5 - 0
components/time-select/time-select.wxss

@@ -136,6 +136,11 @@
   color: rgba(88, 71, 53, 0.5);
 }
 
+/* 闭馆 */
+.day-cell.closed .day-status {
+  color: rgba(88, 71, 53, 0.5);
+}
+
 /* 已约满日期样式 */
 .day-cell.full .day-status {
   color: #B1967B;

+ 69 - 9
pages/index/active-preview/active-preview.js

@@ -20,6 +20,26 @@ Page({
     // 页面显示时的逻辑
   },
 
+  // 检查活动是否已过期(按日期比较)
+  isActivityExpired(activity) {
+    if (!activity.endTime) return false;
+    
+    const today = new Date();
+    const activityEndDate = new Date(activity.endTime);
+    
+    // 只比较日期,忽略具体时间
+    const todayDateString = today.getFullYear() + '-' + 
+      String(today.getMonth() + 1).padStart(2, '0') + '-' + 
+      String(today.getDate()).padStart(2, '0');
+    
+    const endDateString = activityEndDate.getFullYear() + '-' + 
+      String(activityEndDate.getMonth() + 1).padStart(2, '0') + '-' + 
+      String(activityEndDate.getDate()).padStart(2, '0');
+    
+    // 如果活动结束日期小于今天,则认为已过期
+    return endDateString < todayDateString;
+  },
+
   // 加载活动列表
   loadActivityList() {
     museumApi.getSocialActivityList({
@@ -30,10 +50,21 @@ Page({
     .then(response => {
       console.log('获取活动列表成功:', response);
       if (response && response.records) {
+        // 过滤掉已过期的活动(结束日期小于今天)
+        const validActivities = response.records.filter(activity => {
+          const isExpired = this.isActivityExpired(activity);
+          if (isExpired) {
+            console.log('活动已过期,将被过滤:', activity.title || activity.name, activity.endTime);
+          }
+          return !isExpired;
+        });
+        
+        console.log(`活动过滤结果: 总数${response.records.length},有效${validActivities.length},过期${response.records.length - validActivities.length}`);
+        
         this.setData({
-          activityList: response.records
+          activityList: validActivities
         });
-        this.updateTimeInfoFromActivity(response.records);
+        this.updateTimeInfoFromActivity(validActivities);
       }
     })
     .catch(error => {
@@ -82,6 +113,14 @@ Page({
       });
   },
 
+  // 判断时间段是否为下午(大于等于14:00)
+  isAfternoonTime(timeStr) {
+    // 时间格式如:"10:00-14:00" 或 "14:00-18:00"
+    const startTime = timeStr.split('-')[0].trim();
+    const hour = parseInt(startTime.split(':')[0]);
+    return hour >= 14;
+  },
+
   // 更新时间信息
   updateTimeInfo(data) {
     let openTime = '10:00';
@@ -97,16 +136,37 @@ Page({
         closeTime = times[1];
       }
     } else if (data.length >= 2) {
-      // 有两项或更多数据
-      const firstTime = data[0].time;
-      const lastTime = data[data.length - 1].time;
+      // 有两项或更多数据,根据时间段判断上午下午
+      let morningData = null;
+      let afternoonData = null;
+      
+      // 遍历数据,根据时间判断是上午还是下午
+      data.forEach(item => {
+        if (this.isAfternoonTime(item.time)) {
+          afternoonData = item;
+        } else {
+          morningData = item;
+        }
+      });
+      
+      // 取上午时段的开始时间作为开馆时间
+      if (morningData && morningData.time.includes('-')) {
+        openTime = morningData.time.split('-')[0];
+      }
+      
+      // 取下午时段的结束时间作为闭馆时间
+      if (afternoonData && afternoonData.time.includes('-')) {
+        closeTime = afternoonData.time.split('-')[1];
+      }
       
-      if (firstTime && firstTime.includes('-')) {
-        openTime = firstTime.split('-')[0];
+      // 如果没有上午时段,用下午时段的开始时间作为开馆时间
+      if (!morningData && afternoonData && afternoonData.time.includes('-')) {
+        openTime = afternoonData.time.split('-')[0];
       }
       
-      if (lastTime && lastTime.includes('-')) {
-        closeTime = lastTime.split('-')[1];
+      // 如果没有下午时段,用上午时段的结束时间作为闭馆时间
+      if (!afternoonData && morningData && morningData.time.includes('-')) {
+        closeTime = morningData.time.split('-')[1];
       }
     }
 

+ 81 - 24
pages/index/start-preview/start-preview.js

@@ -127,27 +127,66 @@ Page({
     
     if (data && Array.isArray(data) && data.length > 0) {
       if (data.length >= 2) {
-        // 有两项数据,按现有逻辑显示
-        const morningData = data[0];
-        const afternoonData = data[1];
+        // 有两项数据,根据时间段判断上午下午
+        let morningData = null;
+        let afternoonData = null;
         
-        morningText = morningData.pcs > 0 ? `余票${morningData.pcs}张` : '已约满';
-        morningTime = morningData.time;
-        morningId = morningData.id;
+        // 遍历数据,根据时间判断是上午还是下午
+        data.forEach(item => {
+          if (this.isAfternoonTime(item.time)) {
+            afternoonData = item;
+          } else {
+            morningData = item;
+          }
+        });
         
-        afternoonText = afternoonData.pcs > 0 ? `余票${afternoonData.pcs}张` : '已约满';
-        afternoonTime = afternoonData.time;
-        afternoonId = afternoonData.id;
+        // 处理上午数据
+        if (morningData) {
+          if (morningData.pcs <= -1) {
+            morningText = '闭馆';
+            morningDisabled = true;
+          } else if (morningData.pcs > 0) {
+            morningText = `余票${morningData.pcs}张`;
+          } else {
+            morningText = '已约满';
+          }
+          morningTime = morningData.time;
+          morningId = morningData.id;
+        } else {
+          showMorning = false;
+          morningDisabled = true;
+        }
         
-        // 检查时间段是否已过期
-        morningDisabled = this.isTimeSlotExpired(morningTime, this.data.selectedDate);
-        if (morningDisabled) {
-          morningText = '已过期';
+        // 处理下午数据
+        if (afternoonData) {
+          if (afternoonData.pcs <= -1) {
+            afternoonText = '闭馆';
+            afternoonDisabled = true;
+          } else if (afternoonData.pcs > 0) {
+            afternoonText = `余票${afternoonData.pcs}张`;
+          } else {
+            afternoonText = '已约满';
+          }
+          afternoonTime = afternoonData.time;
+          afternoonId = afternoonData.id;
+        } else {
+          showAfternoon = false;
+          afternoonDisabled = true;
         }
         
-        afternoonDisabled = this.isTimeSlotExpired(afternoonTime, this.data.selectedDate);
-        if (afternoonDisabled) {
-          afternoonText = '已过期';
+        // 检查时间段是否已过期(只有未被禁用且不是闭馆状态的时间段才检查过期)
+        if (morningData && !morningDisabled && morningText !== '闭馆') {
+          morningDisabled = this.isTimeSlotExpired(morningTime, this.data.selectedDate);
+          if (morningDisabled) {
+            morningText = '已过期';
+          }
+        }
+        
+        if (afternoonData && !afternoonDisabled && afternoonText !== '闭馆') {
+          afternoonDisabled = this.isTimeSlotExpired(afternoonTime, this.data.selectedDate);
+          if (afternoonDisabled) {
+            afternoonText = '已过期';
+          }
         }
       } else {
         // 只有一项数据,根据时间段判断显示上午还是下午
@@ -159,26 +198,44 @@ Page({
         
         if (isAfternoon) {
           // 显示下午,隐藏上午
-          afternoonText = singleData.pcs > 0 ? `余票${singleData.pcs}张` : '已约满';
+          if (singleData.pcs <= -1) {
+            afternoonText = '闭馆';
+            afternoonDisabled = true;
+          } else if (singleData.pcs > 0) {
+            afternoonText = `余票${singleData.pcs}张`;
+          } else {
+            afternoonText = '已约满';
+          }
           afternoonTime = singleData.time;
           afternoonId = singleData.id;
           
-          afternoonDisabled = this.isTimeSlotExpired(afternoonTime, this.data.selectedDate);
-          if (afternoonDisabled) {
-            afternoonText = '已过期';
+          if (!afternoonDisabled) {
+            afternoonDisabled = this.isTimeSlotExpired(afternoonTime, this.data.selectedDate);
+            if (afternoonDisabled) {
+              afternoonText = '已过期';
+            }
           }
           
           showMorning = false;
           morningDisabled = true;
         } else {
           // 显示上午,隐藏下午
-          morningText = singleData.pcs > 0 ? `余票${singleData.pcs}张` : '已约满';
+          if (singleData.pcs <= -1) {
+            morningText = '闭馆';
+            morningDisabled = true;
+          } else if (singleData.pcs > 0) {
+            morningText = `余票${singleData.pcs}张`;
+          } else {
+            morningText = '已约满';
+          }
           morningTime = singleData.time;
           morningId = singleData.id;
           
-          morningDisabled = this.isTimeSlotExpired(morningTime, this.data.selectedDate);
-          if (morningDisabled) {
-            morningText = '已过期';
+          if (!morningDisabled) {
+            morningDisabled = this.isTimeSlotExpired(morningTime, this.data.selectedDate);
+            if (morningDisabled) {
+              morningText = '已过期';
+            }
           }
           
           showAfternoon = false;

+ 37 - 7
pages/index/visit-preview/visit-preview.js

@@ -76,6 +76,14 @@ Page({
       });
   },
 
+  // 判断时间段是否为下午(大于等于14:00)
+  isAfternoonTime(timeStr) {
+    // 时间格式如:"10:00-14:00" 或 "14:00-18:00"
+    const startTime = timeStr.split('-')[0].trim();
+    const hour = parseInt(startTime.split(':')[0]);
+    return hour >= 14;
+  },
+
   // 更新时间信息
   updateTimeInfo(data) {
     let openTime = '10:00';
@@ -91,15 +99,37 @@ Page({
         closeTime = times[1];
       }
     } else if (data.length >= 2) {
-      // 有两项或更多数据
-      const firstTime = data[0].time;
-      const lastTime = data[data.length - 1].time;
+      // 有两项或更多数据,根据时间段判断上午下午
+      let morningData = null;
+      let afternoonData = null;
+      
+      // 遍历数据,根据时间判断是上午还是下午
+      data.forEach(item => {
+        if (this.isAfternoonTime(item.time)) {
+          afternoonData = item;
+        } else {
+          morningData = item;
+        }
+      });
       
-      if (firstTime && firstTime.includes('-')) {
-        openTime = firstTime.split('-')[0];
+      // 取上午时段的开始时间作为开馆时间
+      if (morningData && morningData.time.includes('-')) {
+        openTime = morningData.time.split('-')[0];
       }
-      if (lastTime && lastTime.includes('-')) {
-        closeTime = lastTime.split('-')[1];
+      
+      // 取下午时段的结束时间作为闭馆时间
+      if (afternoonData && afternoonData.time.includes('-')) {
+        closeTime = afternoonData.time.split('-')[1];
+      }
+      
+      // 如果没有上午时段,用下午时段的开始时间作为开馆时间
+      if (!morningData && afternoonData && afternoonData.time.includes('-')) {
+        openTime = afternoonData.time.split('-')[0];
+      }
+      
+      // 如果没有下午时段,用上午时段的结束时间作为闭馆时间
+      if (!afternoonData && morningData && morningData.time.includes('-')) {
+        closeTime = morningData.time.split('-')[1];
       }
     }
 

+ 4 - 4
pages/index/visit-preview/visit-preview.wxss

@@ -69,7 +69,7 @@
 }
 
 .time-value {
-  font-size: 80rpx;
+  font-size: 60rpx;
   font-weight: bold;
   color: #94765A;
 }
@@ -139,8 +139,8 @@
 }
 
 .btn-reserve {
-  background: url('https://sit-kelamayi.4dage.com/mini/wxImg/preview-btn.png');
-  width: 660rpx;
+  background: url('https://sit-kelamayi.4dage.com/mini/wxImg/preview-btn.png') no-repeat;
+  width: 99%;
   height: 186rpx;
   border-radius: 10rpx;
   display: flex;
@@ -156,7 +156,7 @@
   display: flex;
   justify-content: center;
   align-items: center;
-  width: 660rpx;
+  width: 99%;
   height: 128rpx;
   background: rgba(255, 255, 255, 0.5);
   border-radius: 10rpx;