This commit is contained in:
@jyuhsin
2025-05-27 11:56:08 +08:00
parent 42c957bc85
commit 1ab84aadc4
3 changed files with 82 additions and 21 deletions
@@ -3,6 +3,7 @@ package io.v.nutz.activity.controller.site;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wizzer.framework.base.Result;
@@ -389,7 +390,7 @@ public class SiteReserveController {
return record;
}
@At
/*@At
@ViReturn
public Object getAllowTime(String siteId, Integer year, Integer month) {
if(StrUtil.isBlank(siteId)) {
@@ -413,6 +414,34 @@ public class SiteReserveController {
List<NutMap> openHours = siteInfo.getOpen_hours();
List<Integer> weekNumList = openHours.stream().map(o -> o.getInt("weekNum")).distinct().collect(Collectors.toList());
List<String> result = new ArrayList<>();
//循环时间段
for (DateTime day : fullDateList) {
//先判断星期
int week = day.dayOfWeek() - 1;
if(weekNumList.contains(week)) {
result.add(DateUtil.format(day, "yyyy-MM-dd"));
}
}
return result;
}*/
@At
@ViReturn
public Object getAllowTime(String siteId) {
//根据今天的日期往后加一个星期
if(StrUtil.isBlank(siteId)) {
return new ArrayList<>();
}
DateTime todayDate = DateUtil.date();//今天
Date nextWeekDate = DateUtil.offsetDay(todayDate, 7); // 往后 7 天
List<DateTime> fullDateList = DateUtil.rangeToList(todayDate, nextWeekDate, DateField.DAY_OF_MONTH);
//查询场地
ActivitySiteInfo siteInfo = siteInfoService.fetch(siteId);
List<NutMap> openHours = siteInfo.getOpen_hours();
List<Integer> weekNumList = openHours.stream().map(o -> o.getInt("weekNum")).distinct().collect(Collectors.toList());
List<String> result = new ArrayList<>();
//循环时间段
for (DateTime day : fullDateList) {
@@ -440,6 +469,7 @@ public class SiteReserveController {
List<NutMap> result = new ArrayList<>();
//这个是满足星期的所有时间
List<NutMap> mapList = openHours.stream().filter(o -> o.getInt("weekNum") == week).collect(Collectors.toList());
for (NutMap nutMap : mapList) {
String startTime = nutMap.getString("start_time");
String endTime = nutMap.getString("end_time");
@@ -467,8 +497,23 @@ public class SiteReserveController {
ActivityType type = siteInfoService.dao().fetch(ActivityType.class, siteInfo.getTypeId());
List<AuditState> stateList = siteInfoService.dao().query(AuditState.class, Cnd.where("module", "=", type.getModuleName()).and("stateAuditType", "!=", AuditTypeEnum.REJECT.getValue()));
// 获取当前时间的时分
String nowTimeStr = DateUtil.format(DateUtil.date(), "HH:mm");
DateTime nowTime = DateUtil.parseTimeToday(nowTimeStr);
//找预约记录
for (NutMap nutMap : result) {
if(day.equals(DateUtil.today())) {
DateTime startTime = DateUtil.parseTimeToday(nutMap.getString("start_time"));
// 计算时间差(单位:分钟)
long diffMinutes = Math.abs(DateUtil.between(nowTime, startTime, DateUnit.MINUTE));
// 相差不足4小时
if(nowTime.getTime() > startTime.getTime() || diffMinutes <= 240) {
nutMap.addv("disabled", true);
nutMap.addv("tooltip", "不可预约");
continue;
}
}
List<ActivitySiteReserve> reserveList = siteInfoService.dao().query(
ActivitySiteReserve.class,
Cnd.where("site_id", "=", siteId)
@@ -478,8 +523,15 @@ public class SiteReserveController {
.and("reserve_state", "in", stateList.stream().map(AuditState::getStateId).collect(Collectors.toList()))
);
int count = Lang.isNotEmpty(reserveList) ? reserveList.stream().mapToInt(ActivitySiteReserve::getJoinCount).sum() : 0;
nutMap.addv("allowCount", maxNum);
nutMap.addv("hasCount", count);
if(count >= maxNum) {
nutMap.addv("disabled", true);
nutMap.addv("tooltip", "已约满");
}
long hasReserve = reserveList.stream().filter(o -> o.getReserve_person_id().equals(ShiroUtil.getUserId())).count();
if(hasReserve > 0) {
nutMap.addv("disabled", true);
nutMap.addv("tooltip", "已预约");
}
}
return result;
}
@@ -65,7 +65,7 @@ layout("/mobile/platform.html"){
background-color: #0e78c5;
}
.calendar-left {
width: calc(100% - 20px);
/*width: calc(100% - 20px);*/
overflow-x: auto;
display: flex;
height: 90%;
@@ -139,13 +139,13 @@ layout("/mobile/platform.html"){
</div>
</div>
</div>
<div class="calendar-right">
<!--<div class="calendar-right">
<van-icon size="16" color="white" name="arrow-down" @click="calendarVisible=true"></van-icon>
<van-calendar class="top_pop" v-model="calendarVisible" color="#246fb4" position="top" @confirm="onConfirm"
:default-date="selectDate?.toDate()"
:formatter="calendarFormatter"
title="选择开始日期"></van-calendar>
</div>
</div>-->
</div>
<div class="container">
@@ -153,6 +153,15 @@ layout("/mobile/platform.html"){
<tr v-for="item in timeData">
<td class="time">{{item.start_time + '-' + item.end_time}}</td>
<td>
<div v-if="item.disabled === true" class="state">{{ item.tooltip }}</div>
<div @click="chooseTime(item)" v-else class="state" style="background-color: #e8ffef; color: #52986a">
<span v-if="!times.map(o => o.fullDay).includes(selectDate.format('YYYY-MM-DD') + ' ' + item.start_time + '-' + item.end_time)">可预约</span>
<span v-else>
<van-icon name="passed" size="26" style="line-height: 36px;position: unset"></van-icon>
</span>
</div>
</td>
<!--<td>
<div v-if="isCanRe(item)===3" class="state" style="background-color: #0e78c5;color: #fff3f3">
已预约
</div>
@@ -167,7 +176,7 @@ layout("/mobile/platform.html"){
</div>
<div v-if="isCanRe(item) === 0" class="state">已过期</div>
<div v-if="isCanRe(item) === 4" class="state">不可预约</div>
</td>
</td>-->
</tr>
</table>
<van-empty v-else image="error" :description="moment(selectDate).format('YYYY-MM-DD') + '不能预约'"></van-empty>
@@ -300,7 +309,7 @@ layout("/mobile/platform.html"){
setWeekList(startDate) {
const wk = []
let count = 0
while (wk.length < 7) {
while (wk.length < 8) {
const addDate = moment(startDate).add(count, 'd')
let dis = false
if(this.allowDayList.length > 0 && !this.allowDayList.includes(moment(addDate).format('YYYY-MM-DD'))) {
@@ -377,8 +386,6 @@ layout("/mobile/platform.html"){
}
},
isCanRe(item) {
const now = new Date()
const end = moment().format('YYYY-MM-DD') + ' ' + item.end_time + ':00'
const itemFullTime = this.selectDate.format('YYYY-MM-DD') + " " + item.start_time + "-" + item.end_time
if(this.site.notApplyTimeList && this.site.notApplyTimeList.length > 0) {
@@ -394,18 +401,14 @@ layout("/mobile/platform.html"){
const c = moment(sTime).isBefore(moment(notApplyStartTime)) && moment(eTime).isAfter(moment(notApplyEndTime))
if(a || b || c) {
return 4
this.$set(item, 'disabled', true)
this.$set(item, 'tooltip', '不可预约')
}
}
}
if (this.alreadyReserveRecord.includes(itemFullTime)) {
return 3
}
if (now.getTime() >= new Date(end).getTime() && this.selectDate.format('YYYY-MM-DD') === moment().format('YYYY-MM-DD')) {
return 0
} else {
return item.hasCount >= item.allowCount ? 2 : 1
this.$set(item, 'disabled', true)
this.$set(item, 'tooltip', '已预约')
}
},
async onLoad() {
@@ -333,9 +333,15 @@ layout("/layouts/platform.html"){
<el-select v-model="formData.time" style="width: 100%" filterable @change="timeChange"
placeholder="请选择预约时间">
<el-option v-for="item in allowTimeList"
:label="item.hasCount >= item.allowCount ? item.start_time + ' - ' + item.end_time + '(已约满)' : item.start_time + ' - ' + item.end_time"
:disabled="item.hasCount >= item.allowCount"
:value="item.start_time + '-' + item.end_time"></el-option>
:disabled="item.disabled === true"
:value="item.start_time + '-' + item.end_time">
<template #default>
<span v-if="item.disabled === true">
{{ item.start_time + ' - ' + item.end_time + '(' + item.tooltip + ')' }}
</span>
<span v-else>{{ item.start_time + ' - ' + item.end_time }}</span>
</template>
</el-option>
</el-select>
</el-form-item>