加氢站默认选择,演示账号数据

附件默认显示,详情
This commit is contained in:
2025-12-16 11:58:00 +08:00
parent 4ace3c9f27
commit 9ce46a0c7d
9 changed files with 231 additions and 59 deletions

View File

@@ -809,6 +809,25 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
}
void getSiteList() async {
if(StorageService.to.phone == "13344444444"){
//该账号给stationOptions手动添加一个数据
final testStation = StationModel(
hydrogenId: '1142167389150920704',
name: '羚牛氢能演示加氢站',
address: '上海市嘉定区于田南路111号于田大厦',
price: '35.00', // 价格
siteStatusName: '营运中', // 状态
isSelect: 1, // 默认可选
);
// 使用 assignAll 可以确保列表只包含这个测试数据
stationOptions.assignAll([testStation]);
if (stationOptions.isNotEmpty) {
selectedStationId.value = stationOptions.first.hydrogenId;
}
return;
}
showLoading("加载中");
final originalHeaders = Map<String, dynamic>.from(HttpService.to.dio.options.headers);
try {
@@ -849,6 +868,19 @@ class C_ReservationController extends GetxController with BaseControllerMixin {
} else {
showToast('站点列表已刷新');
}
// 找到第一个可选的站点作为默认值
if (stationOptions.isNotEmpty) {
final firstSelectable = stationOptions.firstWhere(
(station) => station.isSelect == 1,
orElse: () => stationOptions.first, // 降级:如果没有可选的,就用第一个
);
selectedStationId.value = firstSelectable.hydrogenId;
} else {
// 如果列表为空,确保 selectedStationId 也为空
selectedStationId.value = null;
}
} catch (e) {
showToast('数据异常');
}

View File

@@ -437,20 +437,40 @@ class ReservationPage extends GetView<C_ReservationController> {
),
)
.toList(),
value: controller.selectedStationId.value,
value:
// 当前的站点 处理默认
controller.selectedStationId.value ??
(controller.stationOptions.isNotEmpty
? controller.stationOptions.first.hydrogenId
: null),
// 当前选中的是站点ID
onChanged: (value) {
if (value != null) {
controller.selectedStationId.value = value;
}
},
customButton: controller.selectedStationId.value == null
? null // 未选择时,显示默认的 hint
: _buildSelectedStationButton(
controller.stationOptions.firstWhere(
(s) => s.hydrogenId == controller.selectedStationId.value,
),
),
customButton: Obx(() {
// 优先从已选中的 ID 查找
var selectedStation = controller.stationOptions.firstWhereOrNull(
(s) => s.hydrogenId == controller.selectedStationId.value,
);
// 如果找不到已选中的(比如 ID 为空或列表里没有),并且列表不为空,则取第一个作为默认
final stationToShow =
selectedStation ??
(controller.stationOptions.isNotEmpty
? controller.stationOptions.first
: null);
// 如果有要显示的站点,就构建按钮
if (stationToShow != null) {
return _buildSelectedStationButton(stationToShow);
}
// 否则,返回一个空占位符,让 hint 生效
// DropdownButton2 内部会判断,如果 customButton 返回的不是一个有效Widget或根据其内部逻辑就会显示 hint
return const SizedBox.shrink();
}),
buttonStyleData: ButtonStyleData(
height: 40, // 增加高度以容纳两行文字
padding: const EdgeInsets.symmetric(horizontal: 12.0),