Files
ln-ios/ln_jq_app/lib/pages/b_page/reservation/controller.dart
2025-11-24 14:49:07 +08:00

153 lines
4.6 KiB
Dart

import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:ln_jq_app/common/model/base_model.dart';
import 'package:ln_jq_app/pages/login/view.dart';
import '../../../storage_service.dart';
class ReservationController extends GetxController with BaseControllerMixin {
@override
String get builderId => 'b_reservation'; // 确保ID与View中一致
// --- 运营状态下拉菜单所需的状态 ---
// 下拉菜单的选项列表
final List<String> operationStatusOptions = ["营运中", "维修中", "暂停营业", "站点关闭"];
// 当前选中的值,默认为'运营中'
String selectedOperationStatus = "营运中";
@override
void onInit() {
super.onInit();
renderData();
}
String name = "";
String address = "";
String phone = "";
String costPrice = ""; //氢气价格
String customerPrice = ""; //官方价格
String startBusiness = "";
String endBusiness = "";
String timeStr = "";
String operatingEnterprise = "";
String hydrogenId = "";
Future<void> renderData() async {
showLoading("加载中");
try {
var responseData = await HttpService.to.get(
'appointment/station/getStationInfoById?hydrogenId=${StorageService.to.userId}',
);
if (responseData == null && responseData!.data == null) {
dismissLoading();
showToast('暂时无法获取站点信息');
return;
}
try {
var result = BaseModel.fromJson(responseData.data);
name = result.data["name"];
hydrogenId = result.data["hydrogenId"].toString();
address = result.data["address"];
var rawCostPrice = result.data["costPrice"];
if (rawCostPrice != null && rawCostPrice.toString().isNotEmpty) {
costPrice = "¥$rawCostPrice";
} else {
costPrice = "暂无价格";
}
var customerPriceTemp = result.data["customerPrice"];
if (customerPriceTemp != null && customerPriceTemp.toString().isNotEmpty) {
customerPrice = "$customerPriceTemp";
} else {
customerPrice = "暂无价格";
}
phone = result.data["phone"];
startBusiness = result.data["startBusiness"];
endBusiness = result.data["endBusiness"];
operatingEnterprise = result.data["operatingEnterprise"].toString();
String temp = result.data["siteStatusName"].toString();
selectedOperationStatus = (temp.isEmpty || temp == "null") ? "营运中" : temp;
if (startBusiness.isNotEmpty && endBusiness.isNotEmpty) {
// 营业时间为24小时的特殊处理
if (startBusiness == "00:00:00" && endBusiness == "23:59:59") {
timeStr = "24小时营业";
} else {
timeStr = '${startBusiness.substring(0, 5)} - ${endBusiness.substring(0, 5)}';
}
} else {
timeStr = "时间未设置";
}
operatingEnterprise = operatingEnterprise.isEmpty ? "暂未设置" : operatingEnterprise;
updateUi();
dismissLoading();
} catch (e) {
// 如果解析 JSON 失败
dismissLoading();
showToast('数据异常');
}
} catch (e) {
dismissLoading();
}
}
/// 更新运营状态的方法
void onOperationStatusChanged(String? newValue) {
if (newValue != null) {
selectedOperationStatus = newValue;
updateUi();
}
}
void saveInfo() async {
showLoading("保存中");
try {
var responseData = await HttpService.to.post(
'appointment/station/updateStationStatus',
data: {
'hydrogenId': hydrogenId,
'siteStatus': selectedOperationStatus == "营运中"
? "0"
: selectedOperationStatus == "维修中"
? "1"
: selectedOperationStatus == "站点关闭"
? "2"
: selectedOperationStatus == "暂停营业"
? "3"
: 0,
'updateTime': getNowDateTimeString(),
},
);
if (responseData == null && responseData!.data == null) {
dismissLoading();
showToast('服务暂不可用,请稍后');
return;
}
var result = BaseModel.fromJson(responseData.data);
if (result.code == 0) {
showSuccessToast("保存成功");
}
dismissLoading();
} catch (e) {
dismissLoading();
}
}
void logout() async {
// TODO: 在这里执行退出登录的逻辑
//清理本地缓存的用户信息 导航到登录页面
await StorageService.to.clearLoginInfo();
Get.offAll(() => LoginPage());
}
}