司机预约时间调整
This commit is contained in:
@@ -457,8 +457,27 @@ class ReservationPage extends GetView<C_ReservationController> {
|
||||
/// 时间 Slider 选择器
|
||||
Widget _buildTimeSlider(BuildContext context) {
|
||||
return Obx(() {
|
||||
// 这里的逻辑对应 Controller 中的 24 小时可用 Slot
|
||||
int currentIdx = controller.startTime.value.hour;
|
||||
// 获取当前小时作为滑块值 (0-23)
|
||||
int currentHour = controller.startTime.value.hour;
|
||||
|
||||
// 动态获取站点的营业范围限制
|
||||
final station = controller.stationOptions.firstWhereOrNull(
|
||||
(s) => s.hydrogenId == controller.selectedStationId.value,
|
||||
);
|
||||
// 解析营业时间
|
||||
// 处理格式如 "09:00" 或 "09:00:00"
|
||||
final startParts = (station?.startBusiness ?? "00:00").split(':');
|
||||
final endParts = (station?.endBusiness ?? "23:59").split(':');
|
||||
|
||||
int bizStartHour = int.tryParse(startParts[0]) ?? 0;
|
||||
int bizEndHour = int.tryParse(endParts[0]) ?? 23;
|
||||
int bizEndMinute = (endParts.length > 1) ? (int.tryParse(endParts[1]) ?? 0) : 0;
|
||||
|
||||
// 优化结束小时逻辑
|
||||
// 如果分钟为 0 (例如 18:00),说明该小时整点已关门,最大可选小时应减 1
|
||||
if (bizEndMinute == 0 && bizEndHour > 0) {
|
||||
bizEndHour--;
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@@ -507,23 +526,23 @@ class ReservationPage extends GetView<C_ReservationController> {
|
||||
overlayColor: const Color(0xFF006633).withOpacity(0.1),
|
||||
),
|
||||
child: Slider(
|
||||
value: currentIdx.toDouble(),
|
||||
min: 0,
|
||||
max: 23,
|
||||
divisions: 23,
|
||||
value: currentHour.toDouble().clamp(
|
||||
bizStartHour.toDouble(),
|
||||
bizEndHour.toDouble(),
|
||||
),
|
||||
min: bizStartHour.toDouble(),
|
||||
max: bizEndHour.toDouble(),
|
||||
// divisions: bizEndHour - bizStartHour > 0 ? bizEndHour - bizStartHour : 1,
|
||||
onChanged: (val) {
|
||||
int hour = val.toInt();
|
||||
// 模拟 Controller 中的 pickTime 逻辑校验
|
||||
final now = DateTime.now();
|
||||
final isToday =
|
||||
controller.selectedDate.value.year == now.year &&
|
||||
controller.selectedDate.value.month == now.month &&
|
||||
controller.selectedDate.value.day == now.day;
|
||||
|
||||
if (isToday && hour < now.hour) {
|
||||
// 如果是今天且小时数小于当前,则忽略
|
||||
return;
|
||||
}
|
||||
// 如果是今天,判断不可选过去的时间点
|
||||
if (isToday && hour < now.hour) return;
|
||||
|
||||
controller.startTime.value = TimeOfDay(hour: hour, minute: 0);
|
||||
controller.endTime.value = TimeOfDay(hour: (hour + 1) % 24, minute: 0);
|
||||
@@ -650,6 +669,7 @@ class ReservationPage extends GetView<C_ReservationController> {
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
controller.selectedStationId.value = value;
|
||||
controller.resetTimeForSelectedDate();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user