联调修改结构
This commit is contained in:
@@ -53,9 +53,71 @@ class ReservationController extends GetxController with BaseControllerMixin {
|
||||
String operatingEnterprise = "";
|
||||
String hydrogenId = "";
|
||||
|
||||
String jobTipStr = "";
|
||||
String jobDetailsStr = "";
|
||||
String jobId = "";
|
||||
|
||||
Future<void> renderData() async {
|
||||
showLoading("加载中");
|
||||
try {
|
||||
//获取加氢站未执行的状态修改任务信息
|
||||
var jobData = await HttpService.to.get('appointment/job/hyd/un-executed');
|
||||
if (jobData != null) {
|
||||
final jobDataResult = BaseModel.fromJson(jobData.data);
|
||||
if (jobDataResult.code == 0) {
|
||||
try{
|
||||
jobId = jobDataResult.data["id"] ?? "";
|
||||
String endTime = jobDataResult.data["endTime"] ?? "";
|
||||
String beginTime = jobDataResult.data["beginTime"] ?? "";
|
||||
String hydStatus = jobDataResult.data["hydStatus"] ?? "";
|
||||
String hydStatusStr = "";
|
||||
if (hydStatus == "0") {
|
||||
hydStatusStr = "营运中";
|
||||
} else if (hydStatus == "1") {
|
||||
hydStatusStr = "维修中";
|
||||
} else if (hydStatus == "2") {
|
||||
hydStatusStr = "站点关闭";
|
||||
} else if (hydStatus == "3") {
|
||||
hydStatusStr = "暂停营业";
|
||||
}
|
||||
|
||||
jobDetailsStr = "当前站点已设置$beginTime-$endTime为$hydStatusStr状态";
|
||||
|
||||
if (endTime.isNotEmpty) {
|
||||
try {
|
||||
// 解析时间字符串
|
||||
DateTime endDateTime = DateTime.parse(endTime);
|
||||
DateTime beginDateTime = DateTime.parse(beginTime);
|
||||
DateTime now = DateTime.now(); // 2. 计算时间差 (endTime - now)
|
||||
Duration diff = endDateTime.difference(now);
|
||||
|
||||
// 计算小时数 (允许小数,例如 0.5)
|
||||
// inMinutes / 60 可以得到更精确的小数小时
|
||||
double hoursLeft = diff.inMinutes / 60.0;
|
||||
|
||||
if (hoursLeft > 0) {
|
||||
// 如果是正数,表示还有多久结束
|
||||
String timeTip = "${hoursLeft.toStringAsFixed(1)}小时后";
|
||||
jobTipStr = "$timeTip$hydStatusStr";
|
||||
} else {
|
||||
jobTipStr = "";
|
||||
}
|
||||
|
||||
// 如果是处于非营运状态,自动回填开始和结束时间
|
||||
// 假设 customStartTime 是现在,customEndTime 是接口返回的结束时间
|
||||
customStartTime = beginDateTime;
|
||||
customEndTime = endDateTime;
|
||||
} catch (e) {
|
||||
print("时间解析失败: $e");
|
||||
}
|
||||
}
|
||||
}catch (e){
|
||||
Logger.d("解析失败: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取站点信息
|
||||
var responseData = await HttpService.to.get(
|
||||
'appointment/station/getStationInfoById?hydrogenId=${StorageService.to.userId}',
|
||||
);
|
||||
@@ -102,7 +164,7 @@ class ReservationController extends GetxController with BaseControllerMixin {
|
||||
}
|
||||
|
||||
operatingEnterprise = operatingEnterprise.isEmpty ? "暂未设置" : operatingEnterprise;
|
||||
updateUi();
|
||||
|
||||
dismissLoading();
|
||||
} catch (e) {
|
||||
dismissLoading();
|
||||
@@ -110,6 +172,8 @@ class ReservationController extends GetxController with BaseControllerMixin {
|
||||
}
|
||||
} catch (e) {
|
||||
dismissLoading();
|
||||
} finally {
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,14 +301,14 @@ class ReservationController extends GetxController with BaseControllerMixin {
|
||||
},
|
||||
);
|
||||
|
||||
if (responseData == null || responseData!.data == null) {
|
||||
if (responseData == null || responseData.data == null) {
|
||||
dismissLoading();
|
||||
showToast('服务暂不可用,请稍后');
|
||||
return;
|
||||
}
|
||||
var result = BaseModel.fromJson(responseData.data);
|
||||
if (result.code == 0) {
|
||||
showSuccessToast("保存成功");
|
||||
showSuccessToast("保存成功,已同步通知对应司机");
|
||||
}
|
||||
dismissLoading();
|
||||
} catch (e) {
|
||||
@@ -252,6 +316,54 @@ class ReservationController extends GetxController with BaseControllerMixin {
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示当前未执行任务的详情弹窗
|
||||
void showJob() {
|
||||
if (jobDetailsStr.isEmpty) {
|
||||
showToast("当前没有正在生效的任务设置");
|
||||
return;
|
||||
}
|
||||
|
||||
DialogX.to.showConfirmDialog(
|
||||
title: '当前设置详情',
|
||||
content: Text(
|
||||
jobDetailsStr,
|
||||
style: const TextStyle(fontSize: 15, height: 1.5),
|
||||
),
|
||||
confirmText: '好的',
|
||||
cancelText: '取消设置',
|
||||
onCancel: () {
|
||||
// 点击“取消设置”调用删除接口
|
||||
_cancelJob();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 内部私有方法:调用取消/删除任务接口
|
||||
void _cancelJob() async {
|
||||
showLoading("正在取消...");
|
||||
try {
|
||||
var response = await HttpService.to.delete(
|
||||
'appointment/job/hyd/$jobId',
|
||||
);
|
||||
|
||||
dismissLoading();
|
||||
if (response != null) {
|
||||
var result = BaseModel.fromJson(response.data);
|
||||
if (result.code == 0) {
|
||||
showSuccessToast("已成功取消该设置");
|
||||
// 成功后重新刷新页面数据,重置状态
|
||||
renderData();
|
||||
} else {
|
||||
showErrorToast(result.error);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
dismissLoading();
|
||||
showErrorToast("取消失败,请稍后重试");
|
||||
Logger.d("取消任务失败: $e");
|
||||
}
|
||||
}
|
||||
|
||||
/// 发送站点广播
|
||||
void sendBroadcast() async {
|
||||
String title = broadcastTitleController.text.trim();
|
||||
@@ -270,10 +382,7 @@ class ReservationController extends GetxController with BaseControllerMixin {
|
||||
try {
|
||||
var responseData = await HttpService.to.post(
|
||||
'appointment/notice/push/station/broadcast',
|
||||
data: {
|
||||
'title': title,
|
||||
'content': content,
|
||||
},
|
||||
data: {'title': title, 'content': content},
|
||||
);
|
||||
|
||||
dismissLoading();
|
||||
|
||||
Reference in New Issue
Block a user