限制条件
This commit is contained in:
@@ -290,6 +290,9 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 用于存储上一次成功预约的信息
|
||||||
|
ReservationModel? lastSuccessfulReservation;
|
||||||
|
|
||||||
/// 提交预约
|
/// 提交预约
|
||||||
void submitReservation() async {
|
void submitReservation() async {
|
||||||
if (plateNumber.isEmpty) {
|
if (plateNumber.isEmpty) {
|
||||||
@@ -301,10 +304,31 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
|||||||
showToast("请输入需要预约的氢量");
|
showToast("请输入需要预约的氢量");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
double ampuntDouble = (double.tryParse(ampuntStr) ?? 0.0);
|
||||||
|
if (ampuntDouble == 0) {
|
||||||
|
showToast("请输入需要预约的氢量");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ampuntDouble > (double.tryParse(difference) ?? 0.0)) {
|
||||||
|
showToast('当前最大可预约氢量为${difference}(KG)');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedStationId.value == null || selectedStationId.value!.isEmpty) {
|
if (selectedStationId.value == null || selectedStationId.value!.isEmpty) {
|
||||||
showToast("请先选择加氢站");
|
showToast("请先选择加氢站");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final dateStr = formattedDate;
|
||||||
|
final startTimeStr = '$dateStr ${formattedStartTime}:00';
|
||||||
|
if (lastSuccessfulReservation != null &&
|
||||||
|
lastSuccessfulReservation!.id == selectedStationId.value &&
|
||||||
|
lastSuccessfulReservation!.hydAmount == ampuntStr &&
|
||||||
|
lastSuccessfulReservation!.startTime == startTimeStr) {
|
||||||
|
showToast("请勿重复提交相同的预约");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 将选择的日期和时间组合成一个完整的 DateTime 对象
|
// 将选择的日期和时间组合成一个完整的 DateTime 对象
|
||||||
final reservationStartDateTime = DateTime(
|
final reservationStartDateTime = DateTime(
|
||||||
selectedDate.value.year,
|
selectedDate.value.year,
|
||||||
@@ -355,6 +379,27 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
|||||||
if (result.code == 0) {
|
if (result.code == 0) {
|
||||||
showSuccessToast("预约成功");
|
showSuccessToast("预约成功");
|
||||||
|
|
||||||
|
// 预约成功后,保存当前预约信息
|
||||||
|
lastSuccessfulReservation = ReservationModel(
|
||||||
|
id: selectedStationId.value!,
|
||||||
|
hydAmount: ampuntStr,
|
||||||
|
startTime: startTimeStr,
|
||||||
|
endTime: endTimeStr,
|
||||||
|
stationName: selectedStation.name,
|
||||||
|
plateNumber: '',
|
||||||
|
amount: '',
|
||||||
|
time: '',
|
||||||
|
contactPerson: '',
|
||||||
|
contactPhone: '',
|
||||||
|
contacts: '',
|
||||||
|
phone: '',
|
||||||
|
date: '',
|
||||||
|
state: '',
|
||||||
|
stateName: '',
|
||||||
|
addStatus: '',
|
||||||
|
addStatusName: '',
|
||||||
|
);
|
||||||
|
|
||||||
//打开预约列表
|
//打开预约列表
|
||||||
Future.delayed(const Duration(milliseconds: 800), () {
|
Future.delayed(const Duration(milliseconds: 800), () {
|
||||||
getReservationList();
|
getReservationList();
|
||||||
@@ -581,12 +626,14 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String leftHydrogen = "0";
|
|
||||||
String workEfficiency = "0";
|
String workEfficiency = "0";
|
||||||
String fillingWeight = "0";
|
String fillingWeight = "0";
|
||||||
String fillingTimes = "0";
|
String fillingTimes = "0";
|
||||||
String plateNumber = "";
|
String plateNumber = "";
|
||||||
String vin = "";
|
String vin = "";
|
||||||
|
String leftHydrogen = "0";
|
||||||
|
num maxHydrogen = 0;
|
||||||
|
String difference = "";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get listenLifecycleEvent => true;
|
bool get listenLifecycleEvent => true;
|
||||||
@@ -607,6 +654,7 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
|||||||
plateNumber = bean.plateNumber;
|
plateNumber = bean.plateNumber;
|
||||||
vin = bean.vin;
|
vin = bean.vin;
|
||||||
plateNumberController = TextEditingController(text: plateNumber);
|
plateNumberController = TextEditingController(text: plateNumber);
|
||||||
|
maxHydrogen = bean.maxHydrogen;
|
||||||
getCatinfo();
|
getCatinfo();
|
||||||
getJqinfo();
|
getJqinfo();
|
||||||
}
|
}
|
||||||
@@ -665,6 +713,9 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
|
|||||||
leftHydrogen = result.data["leftHydrogen"].toString();
|
leftHydrogen = result.data["leftHydrogen"].toString();
|
||||||
workEfficiency = result.data["workEfficiency"].toString();
|
workEfficiency = result.data["workEfficiency"].toString();
|
||||||
|
|
||||||
|
final leftHydrogenNum = double.tryParse(leftHydrogen) ?? 0.0;
|
||||||
|
difference = (maxHydrogen - leftHydrogenNum).toStringAsFixed(2);
|
||||||
|
|
||||||
updateUi();
|
updateUi();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -270,9 +270,9 @@ class ReservationPage extends GetView<C_ReservationController> {
|
|||||||
onTap: () => controller.pickTime(context, false),
|
onTap: () => controller.pickTime(context, false),
|
||||||
),
|
),
|
||||||
_buildTextField(
|
_buildTextField(
|
||||||
label: '预约氢量(kg)',
|
label: '预约氢量(KG)',
|
||||||
controller: controller.amountController,
|
controller: controller.amountController,
|
||||||
hint: '请输入氢量(kg)',
|
hint: '当前最大可预约氢量${controller.difference}(KG)',
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
),
|
),
|
||||||
_buildTextField(
|
_buildTextField(
|
||||||
|
|||||||
Reference in New Issue
Block a user