调整司机预约时间
站点工单状态
This commit is contained in:
@@ -79,6 +79,16 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
void pickDate(BuildContext context) {
|
||||
DateTime tempDate = selectedDate.value;
|
||||
|
||||
// 获取今天的日期 (不含时间)
|
||||
final DateTime today = DateTime(
|
||||
DateTime.now().year,
|
||||
DateTime.now().month,
|
||||
DateTime.now().day,
|
||||
);
|
||||
|
||||
//计算明天的日期
|
||||
final DateTime tomorrow = today.add(const Duration(days: 1));
|
||||
|
||||
Get.bottomSheet(
|
||||
Container(
|
||||
height: 300,
|
||||
@@ -106,8 +116,17 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
),
|
||||
CupertinoButton(
|
||||
onPressed: () {
|
||||
final bool isChangingToToday = tempDate.isAtSameMomentAs(today) && !selectedDate.value.isAtSameMomentAs(today);
|
||||
final bool isDateChanged = !tempDate.isAtSameMomentAs(selectedDate.value);
|
||||
|
||||
// 更新选中的日期
|
||||
selectedDate.value = tempDate;
|
||||
Get.back();
|
||||
Get.back(); // 先关闭弹窗
|
||||
|
||||
// 如果日期发生了变化,则重置时间
|
||||
if (isDateChanged) {
|
||||
resetTimeForSelectedDate();
|
||||
}
|
||||
},
|
||||
child: const Text(
|
||||
'确认',
|
||||
@@ -125,12 +144,9 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
child: CupertinoDatePicker(
|
||||
mode: CupertinoDatePickerMode.date,
|
||||
initialDateTime: selectedDate.value,
|
||||
minimumDate: DateTime(
|
||||
DateTime.now().year,
|
||||
DateTime.now().month,
|
||||
DateTime.now().day,
|
||||
),
|
||||
maximumDate: DateTime.now().add(const Duration(days: 365)),
|
||||
minimumDate: today, // 最小可选日期为今天
|
||||
maximumDate: tomorrow, // 最大可选日期为明天
|
||||
// ---------------------
|
||||
onDateTimeChanged: (DateTime newDate) {
|
||||
tempDate = newDate;
|
||||
},
|
||||
@@ -143,6 +159,24 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
);
|
||||
}
|
||||
|
||||
void resetTimeForSelectedDate() {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
|
||||
// 判断新选择的日期是不是今天
|
||||
if (selectedDate.value.isAtSameMomentAs(today)) {
|
||||
// 如果是今天,就将时间重置为当前时间所在的半小时区间
|
||||
startTime.value = _calculateInitialStartTime(now);
|
||||
endTime.value = TimeOfDay.fromDateTime(
|
||||
_getDateTimeFromTimeOfDay(startTime.value).add(const Duration(minutes: 30)),
|
||||
);
|
||||
} else {
|
||||
// 如果是明天(或其他未来日期),则可以将时间重置为一天的最早可用时间,例如 00:00
|
||||
startTime.value = const TimeOfDay(hour: 0, minute: 0);
|
||||
endTime.value = const TimeOfDay(hour: 0, minute: 30);
|
||||
}
|
||||
}
|
||||
|
||||
///30 分钟为间隔 时间选择器
|
||||
void pickTime(BuildContext context) {
|
||||
final now = DateTime.now();
|
||||
@@ -386,6 +420,7 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
stateName: '',
|
||||
addStatus: '',
|
||||
addStatusName: '',
|
||||
hasEdit: true,
|
||||
);
|
||||
|
||||
//打开预约列表
|
||||
@@ -393,7 +428,7 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
getReservationList();
|
||||
});
|
||||
} else {
|
||||
showErrorToast(result.message);
|
||||
showToast(result.error);
|
||||
}
|
||||
} catch (e) {
|
||||
dismissLoading();
|
||||
@@ -432,13 +467,30 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
|
||||
if (baseModel.code == 0 && baseModel.data != null) {
|
||||
final dataMap = baseModel.data as Map<String, dynamic>;
|
||||
final List<dynamic> listFromServer = dataMap['list'] ?? [];
|
||||
final List<dynamic> listFromServer = dataMap['records'] ?? [];
|
||||
reservationList = listFromServer.map((item) {
|
||||
return ReservationModel.fromJson(item as Map<String, dynamic>);
|
||||
}).toList();
|
||||
|
||||
// 根据列表是否为空来更新 hasReservationData 状态
|
||||
hasReservationData = reservationList.isNotEmpty;
|
||||
|
||||
for (var reservation in reservationList) {
|
||||
try {
|
||||
// 获取当前时间和预约的结束时间
|
||||
final now = DateTime.now();
|
||||
final endDateTime = DateTime.parse(reservation.endTime);
|
||||
|
||||
// 如果当前时间在结束时间之后,则不能编辑
|
||||
if (now.isAfter(endDateTime)) {
|
||||
reservation.hasEdit = false;
|
||||
} else {
|
||||
reservation.hasEdit = true;
|
||||
}
|
||||
} catch (e) {
|
||||
reservation.hasEdit = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
showToast(baseModel.message);
|
||||
hasReservationData = false;
|
||||
@@ -544,7 +596,7 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
||||
),
|
||||
),
|
||||
),
|
||||
plateNumber.isEmpty
|
||||
!reservation.hasEdit
|
||||
? SizedBox()
|
||||
: GestureDetector(
|
||||
onTap: () async {
|
||||
|
||||
Reference in New Issue
Block a user