联调修改结构

This commit is contained in:
2026-01-14 13:18:22 +08:00
parent 16639e2384
commit f25feaa55a
8 changed files with 205 additions and 72 deletions

View File

@@ -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();

View File

@@ -109,20 +109,24 @@ class ReservationPage extends GetView<ReservationController> {
child: Column(
children: [
// Tab 切换栏
Obx(() => Container(
color: Colors.grey[50],
child: Row(
children: [
_buildTabItem(0, Icons.business_outlined, '站点信息'),
_buildTabItem(1, Icons.campaign_outlined, '站点广播'),
],
),
)),
Obx(
() => Container(
color: Colors.grey[50],
child: Row(
children: [
_buildTabItem(0, Icons.business_outlined, '站点信息'),
_buildTabItem(1, Icons.campaign_outlined, '站点广播'),
],
),
),
),
const Divider(height: 1),
// 内容区域
Obx(() => controller.selectedTabIndex.value == 0
? _buildStationInfo(context)
: _buildStationBroadcast(context)),
Obx(
() => controller.selectedTabIndex.value == 0
? _buildStationInfo(context)
: _buildStationBroadcast(context),
),
],
),
);
@@ -180,7 +184,25 @@ class ReservationPage extends GetView<ReservationController> {
_buildDisplayField(label: '官方价格 (元/kg)', value: controller.customerPrice),
const SizedBox(height: 16),
_buildSectionTitle('运营信息'),
Text('运营状态', style: TextStyle(color: Colors.grey[600], fontSize: 14)),
Row(
children: [
Text('运营状态', style: TextStyle(color: Colors.grey[600], fontSize: 14)),
//加氢站未执行的状态修改任务
if (controller.jobTipStr.isNotEmpty)
GestureDetector(
onTap: controller.showJob,
child: Row(
children: [
Text(
controller.jobTipStr,
style: TextStyle(color: Colors.yellow[800], fontSize: 14),
),
Icon(AntdIcon.question_circle, size: 14, color: Colors.yellow[800]),
],
),
),
],
),
const SizedBox(height: 8),
DropdownButtonFormField<String>(
value: controller.selectedOperationStatus,
@@ -239,7 +261,11 @@ class ReservationPage extends GetView<ReservationController> {
const SizedBox(width: 10),
const Text(
'站点广播通知',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.black87),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
],
),
@@ -249,16 +275,17 @@ class ReservationPage extends GetView<ReservationController> {
SizedBox(
height: 45.h,
child: TextField(
controller: controller.broadcastTitleController,
maxLength: 30,
decoration: InputDecoration(
hintText: '例如:临时闭站通知',
hintStyle: TextStyle(color: Colors.grey[400], fontSize: 14),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
counterText: '', // 隐藏原生计数器,我们可以按需自定义
controller: controller.broadcastTitleController,
maxLength: 30,
decoration: InputDecoration(
hintText: '例如:临时闭站通知',
hintStyle: TextStyle(color: Colors.grey[400], fontSize: 14),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
counterText: '', // 隐藏原生计数器,我们可以按需自定义
),
),
),),
),
const SizedBox(height: 20),
_buildTextFieldLabel('通知内容'),
const SizedBox(height: 8),
@@ -283,7 +310,10 @@ class ReservationPage extends GetView<ReservationController> {
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
elevation: 0,
),
child: const Text('发送', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
child: const Text(
'发送',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
const SizedBox(height: 20),
],
@@ -294,7 +324,11 @@ class ReservationPage extends GetView<ReservationController> {
Widget _buildTextFieldLabel(String label) {
return Text(
label,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Colors.black87),
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.black87,
),
);
}
@@ -340,7 +374,11 @@ class ReservationPage extends GetView<ReservationController> {
}
/// 构建一个“可点击”的选择行
Widget _buildClickField({required String label, required String value, required VoidCallback onTap}) {
Widget _buildClickField({
required String label,
required String value,
required VoidCallback onTap,
}) {
return Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: Column(