调整司机预约时间
站点工单状态
This commit is contained in:
@@ -76,8 +76,6 @@ void initHttpSet() {
|
||||
await StorageService.to.clearLoginInfo();
|
||||
Get.offAll(() => LoginPage());
|
||||
return baseModel.message;
|
||||
} else {
|
||||
return baseModel.message;
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
e.printInfo();
|
||||
|
||||
@@ -7,16 +7,17 @@ import 'package:ln_jq_app/common/styles/theme.dart';
|
||||
import 'package:ln_jq_app/storage_service.dart';
|
||||
|
||||
enum ReservationStatus {
|
||||
pending, // 待处理 ( addStatus: 1)
|
||||
completed, // 已完成 ( addStatus: 2)
|
||||
rejected, // 已拒绝 ( 3)
|
||||
pending, // 待处理 ( addStatus: 0)
|
||||
completed, // 完成 ( addStatus: 1)
|
||||
rejected, // 拒绝 ( -1)
|
||||
unadded, // 未加 ( 2)
|
||||
unknown, // 未知状态
|
||||
}
|
||||
|
||||
class ReservationModel {
|
||||
final String id;
|
||||
final String plateNumber;
|
||||
String amount;
|
||||
String amount;
|
||||
final String time;
|
||||
final String contactPerson;
|
||||
final String contactPhone;
|
||||
@@ -33,6 +34,7 @@ class ReservationModel {
|
||||
final String stateName;
|
||||
final String addStatus;
|
||||
final String addStatusName;
|
||||
bool hasEdit;
|
||||
|
||||
ReservationModel({
|
||||
required this.id,
|
||||
@@ -41,6 +43,7 @@ class ReservationModel {
|
||||
required this.time,
|
||||
required this.contactPerson,
|
||||
required this.contactPhone,
|
||||
required this.hasEdit,
|
||||
this.status = ReservationStatus.pending,
|
||||
required this.contacts,
|
||||
required this.phone,
|
||||
@@ -57,21 +60,26 @@ class ReservationModel {
|
||||
|
||||
/// 工厂构造函数,用于从JSON创建ReservationModel实例
|
||||
factory ReservationModel.fromJson(Map<String, dynamic> json) {
|
||||
//1完成 0待处理 2已拒绝
|
||||
// 1完成 2未加 -1拒绝 0是待加氢
|
||||
ReservationStatus currentStatus;
|
||||
int statusFromServer = json['addStatus'] as int? ?? 0;
|
||||
switch (statusFromServer) {
|
||||
case 0:
|
||||
currentStatus = ReservationStatus.pending;
|
||||
break;
|
||||
case 1:
|
||||
currentStatus = ReservationStatus.completed;
|
||||
break;
|
||||
case 2:
|
||||
currentStatus = ReservationStatus.rejected;
|
||||
break;
|
||||
default:
|
||||
currentStatus = ReservationStatus.unknown;
|
||||
int state = json['state'] as int? ?? 0;
|
||||
if (state == -1) {
|
||||
currentStatus = ReservationStatus.rejected;
|
||||
} else {
|
||||
switch (statusFromServer) {
|
||||
case 0:
|
||||
currentStatus = ReservationStatus.pending;
|
||||
break;
|
||||
case 1:
|
||||
currentStatus = ReservationStatus.completed;
|
||||
break;
|
||||
case 2:
|
||||
currentStatus = ReservationStatus.unadded;
|
||||
break;
|
||||
default:
|
||||
currentStatus = ReservationStatus.unknown;
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化时间显示
|
||||
@@ -105,6 +113,7 @@ class ReservationModel {
|
||||
addStatus: statusFromServer.toString(),
|
||||
addStatusName: json['addStatusName']?.toString() ?? '',
|
||||
stateName: json['stateName']?.toString() ?? '',
|
||||
hasEdit: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -189,7 +198,7 @@ class SiteController extends GetxController with BaseControllerMixin {
|
||||
// 【核心修改】处理接口返回的列表数据
|
||||
final dataMap = baseModel.data as Map<String, dynamic>;
|
||||
|
||||
final List<dynamic> listFromServer = dataMap['list'] ?? [];
|
||||
final List<dynamic> listFromServer = dataMap['records'] ?? [];
|
||||
|
||||
// 使用 .map() 遍历列表,将每个 item 转换为一个 ReservationModel 对象
|
||||
reservationList = listFromServer.map((item) {
|
||||
@@ -553,8 +562,8 @@ class SiteController extends GetxController with BaseControllerMixin {
|
||||
orderAmount = result.data["orderAmount"].toString();
|
||||
completedAmount = result.data["completedAmount"].toString();
|
||||
name = result.data["name"].toString();
|
||||
orderTotalAmount = result.data["orderTotalAmount"] ?? "";
|
||||
orderUnfinishedAmount = result.data["orderUnfinishedAmount"] ?? "";
|
||||
orderTotalAmount = result.data["orderTotalAmount"].toString() ?? "";
|
||||
orderUnfinishedAmount = result.data["orderUnfinishedAmount"].toString() ?? "";
|
||||
|
||||
leftHydrogen = leftHydrogen.isEmpty ? "统计中" : leftHydrogen.toString();
|
||||
orderTotalAmount = orderTotalAmount.isEmpty ? "统计中" : orderTotalAmount.toString();
|
||||
|
||||
@@ -433,15 +433,19 @@ class SitePage extends GetView<SiteController> {
|
||||
Color color;
|
||||
switch (status) {
|
||||
case ReservationStatus.pending:
|
||||
text = '待处理';
|
||||
text = '待加氢';
|
||||
color = Colors.orange;
|
||||
break;
|
||||
case ReservationStatus.completed:
|
||||
text = '已完成';
|
||||
text = '已加氢';
|
||||
color = Colors.greenAccent;
|
||||
break;
|
||||
case ReservationStatus.rejected:
|
||||
text = '已拒绝';
|
||||
text = '拒绝加氢';
|
||||
color = Colors.red;
|
||||
break;
|
||||
case ReservationStatus.unadded:
|
||||
text = '未加氢';
|
||||
color = Colors.red;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -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