查看预约列表
This commit is contained in:
@@ -20,6 +20,18 @@ class ReservationModel {
|
||||
final String contactPhone;
|
||||
ReservationStatus status; // 状态是可变的
|
||||
|
||||
final String contacts;
|
||||
final String phone;
|
||||
final String stationName;
|
||||
final String startTime;
|
||||
final String endTime;
|
||||
final String date;
|
||||
final String hydAmount;
|
||||
final String state;
|
||||
final String stateName;
|
||||
final String addStatus;
|
||||
final String addStatusName;
|
||||
|
||||
ReservationModel({
|
||||
required this.id,
|
||||
required this.plateNumber,
|
||||
@@ -28,6 +40,17 @@ class ReservationModel {
|
||||
required this.contactPerson,
|
||||
required this.contactPhone,
|
||||
this.status = ReservationStatus.pending,
|
||||
required this.contacts,
|
||||
required this.phone,
|
||||
required this.stationName,
|
||||
required this.startTime,
|
||||
required this.endTime,
|
||||
required this.date,
|
||||
required this.hydAmount,
|
||||
required this.state,
|
||||
required this.stateName,
|
||||
required this.addStatus,
|
||||
required this.addStatusName,
|
||||
});
|
||||
|
||||
/// 工厂构造函数,用于从JSON创建ReservationModel实例
|
||||
@@ -50,22 +73,35 @@ class ReservationModel {
|
||||
}
|
||||
|
||||
// 格式化时间显示
|
||||
String startTime = json['startTime']?.toString() ?? '';
|
||||
String endTime = json['endTime']?.toString() ?? '';
|
||||
String timeRange = (startTime.isNotEmpty && endTime.isNotEmpty)
|
||||
? '${json['date']?.toString() ?? ''} ${startTime.substring(11, 16)}-${endTime.substring(11, 16)}' // 截取 HH:mm
|
||||
String startTimeStr = json['startTime']?.toString() ?? '';
|
||||
String endTimeStr = json['endTime']?.toString() ?? '';
|
||||
String dateStr = json['date']?.toString() ?? '';
|
||||
String timeRange = (startTimeStr.isNotEmpty && endTimeStr.isNotEmpty && dateStr.isNotEmpty)
|
||||
? '$dateStr ${startTimeStr.substring(11, 16)}-${endTimeStr.substring(11, 16)}' // 截取 HH:mm
|
||||
: '时间未定';
|
||||
|
||||
return ReservationModel(
|
||||
// id, hydAmount 需要转换为 String
|
||||
// 原始字段,用于UI兼容
|
||||
id: json['id']?.toString() ?? '',
|
||||
plateNumber: json['plateNumber']?.toString() ?? '未知车牌',
|
||||
amount: '${json['hydAmount']?.toString() ?? '0'}kg',
|
||||
// 拼接单位
|
||||
time: timeRange,
|
||||
contactPerson: json['contacts']?.toString() ?? '无联系人',
|
||||
contactPhone: json['phone']?.toString() ?? '无联系电话',
|
||||
status: currentStatus,
|
||||
|
||||
// 新增的完整字段
|
||||
contacts: json['contacts']?.toString() ?? '',
|
||||
phone: json['phone']?.toString() ?? '',
|
||||
stationName: json['stationName']?.toString() ?? '',
|
||||
startTime: startTimeStr,
|
||||
endTime: endTimeStr,
|
||||
date: dateStr,
|
||||
hydAmount: json['hydAmount']?.toString() ?? '0',
|
||||
state: json['state']?.toString() ?? '',
|
||||
addStatus: statusFromServer.toString(),
|
||||
addStatusName: json['addStatusName']?.toString() ?? '',
|
||||
stateName: json['stateName']?.toString() ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart'; // 用于日期格式化
|
||||
import 'package:getx_scaffold/common/common.dart';
|
||||
import 'package:getx_scaffold/common/services/http.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:ln_jq_app/common/model/base_model.dart';
|
||||
import 'package:ln_jq_app/common/styles/theme.dart';
|
||||
import 'package:ln_jq_app/pages/b_page/site/controller.dart';
|
||||
import 'package:ln_jq_app/storage_service.dart'; // 用于日期格式化
|
||||
|
||||
class ReservationController extends GetxController {
|
||||
/// --- 状态变量 ---
|
||||
@@ -13,7 +19,9 @@ class ReservationController extends GetxController {
|
||||
final Rx<TimeOfDay> startTime = TimeOfDay.now().obs;
|
||||
|
||||
// 结束时间,默认为开始时间后30分钟
|
||||
final Rx<TimeOfDay> endTime = TimeOfDay.fromDateTime(DateTime.now().add(const Duration(minutes: 30))).obs;
|
||||
final Rx<TimeOfDay> endTime = TimeOfDay.fromDateTime(
|
||||
DateTime.now().add(const Duration(minutes: 30)),
|
||||
).obs;
|
||||
|
||||
// 预约氢量
|
||||
final TextEditingController amountController = TextEditingController();
|
||||
@@ -22,24 +30,37 @@ class ReservationController extends GetxController {
|
||||
final TextEditingController plateNumberController = TextEditingController();
|
||||
|
||||
// 加氢站
|
||||
final List<String> stationOptions = ['诚志AP银河路加氢站', '站点B', '站点C'];
|
||||
final List<String> stationOptions = [
|
||||
'诚志AP银河路加氢站',
|
||||
'站点B',
|
||||
'站点C',
|
||||
'站点C',
|
||||
'站点C',
|
||||
'站点C',
|
||||
'站点C',
|
||||
];
|
||||
final Rx<String> selectedStation = '诚志AP银河路加氢站'.obs;
|
||||
|
||||
// --- 用于UI显示的格式化字符串 (Getters) ---
|
||||
String get formattedDate => DateFormat('yyyy-MM-dd').format(selectedDate.value);
|
||||
|
||||
// 使用 context-aware 的 format 方法
|
||||
String get formattedStartTime => startTime.value.format(Get.context!);
|
||||
|
||||
String get formattedEndTime => endTime.value.format(Get.context!);
|
||||
|
||||
/// --- 交互方法 ---
|
||||
|
||||
/// 【修改】显示 Flutter 内置的日期选择器
|
||||
void pickDate(BuildContext context) async { // 改为 async
|
||||
void pickDate(BuildContext context) async {
|
||||
// 改为 async
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: selectedDate.value,
|
||||
firstDate: DateTime.now(), // 只能从今天开始选
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)), // 假设最多预约一年内
|
||||
firstDate: DateTime.now(),
|
||||
// 只能从今天开始选
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
// 假设最多预约一年内
|
||||
helpText: '选择预约日期',
|
||||
confirmText: '确定',
|
||||
cancelText: '取消',
|
||||
@@ -51,7 +72,8 @@ class ReservationController extends GetxController {
|
||||
}
|
||||
|
||||
/// 【修改】显示 Flutter 内置的时间选择器
|
||||
void pickTime(BuildContext context, bool isStartTime) async { // 改为 async
|
||||
void pickTime(BuildContext context, bool isStartTime) async {
|
||||
// 改为 async
|
||||
TimeOfDay initialTime = isStartTime ? startTime.value : endTime.value;
|
||||
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
@@ -66,15 +88,21 @@ class ReservationController extends GetxController {
|
||||
if (isStartTime) {
|
||||
startTime.value = pickedTime;
|
||||
// 如果新的开始时间晚于或等于结束时间,自动将结束时间设置为开始时间后30分钟
|
||||
if ((pickedTime.hour * 60 + pickedTime.minute) >= (endTime.value.hour * 60 + endTime.value.minute)) {
|
||||
if ((pickedTime.hour * 60 + pickedTime.minute) >=
|
||||
(endTime.value.hour * 60 + endTime.value.minute)) {
|
||||
final newDateTime = DateTime(
|
||||
selectedDate.value.year, selectedDate.value.month, selectedDate.value.day, pickedTime.hour, pickedTime.minute)
|
||||
.add(const Duration(minutes: 30));
|
||||
selectedDate.value.year,
|
||||
selectedDate.value.month,
|
||||
selectedDate.value.day,
|
||||
pickedTime.hour,
|
||||
pickedTime.minute,
|
||||
).add(const Duration(minutes: 30));
|
||||
endTime.value = TimeOfDay.fromDateTime(newDateTime);
|
||||
}
|
||||
} else {
|
||||
// 确保结束时间不早于开始时间
|
||||
if ((pickedTime.hour * 60 + pickedTime.minute) > (startTime.value.hour * 60 + startTime.value.minute)) {
|
||||
if ((pickedTime.hour * 60 + pickedTime.minute) >
|
||||
(startTime.value.hour * 60 + startTime.value.minute)) {
|
||||
endTime.value = pickedTime;
|
||||
} else {
|
||||
// 如果选择了更早的时间,给出提示
|
||||
@@ -104,6 +132,218 @@ class ReservationController extends GetxController {
|
||||
Get.snackbar('成功', '预约已提交!', snackPosition: SnackPosition.BOTTOM);
|
||||
}
|
||||
|
||||
/// 状态变量:是否有预约数据
|
||||
bool hasReservationData = false;
|
||||
|
||||
// 新增预约数据列表
|
||||
List<ReservationModel> reservationList = [];
|
||||
|
||||
//查看预约列表
|
||||
void getReservationList() async {
|
||||
showLoading("加载中");
|
||||
|
||||
try {
|
||||
var response = await HttpService.to.post(
|
||||
"appointment/orderAddHyd/driverOrderPage",
|
||||
data: {
|
||||
'phone': StorageService.to.userId, // 使用从 renderData 中获取到的 name
|
||||
'pageNum': 1,
|
||||
'pageSize': 30, // 暂时不考虑分页,一次获取30条
|
||||
},
|
||||
);
|
||||
|
||||
// 安全校验
|
||||
if (response == null || response.data == null) {
|
||||
showToast('暂时无法获取预约数据');
|
||||
hasReservationData = false;
|
||||
reservationList = [];
|
||||
return;
|
||||
}
|
||||
|
||||
final baseModel = BaseModel<dynamic>.fromJson(response.data);
|
||||
|
||||
if (baseModel.code == 0 && baseModel.data != null) {
|
||||
// 【核心修改】处理接口返回的列表数据
|
||||
final dataMap = baseModel.data as Map<String, dynamic>;
|
||||
|
||||
final List<dynamic> listFromServer = dataMap['list'] ?? [];
|
||||
|
||||
// 使用 .map() 遍历列表,将每个 item 转换为一个 ReservationModel 对象
|
||||
reservationList = listFromServer.map((item) {
|
||||
return ReservationModel.fromJson(item as Map<String, dynamic>);
|
||||
}).toList();
|
||||
|
||||
// 根据列表是否为空来更新 hasReservationData 状态
|
||||
hasReservationData = reservationList.isNotEmpty;
|
||||
} else {
|
||||
// 接口返回业务错误
|
||||
showToast(baseModel.message);
|
||||
hasReservationData = false;
|
||||
reservationList = []; // 清空列表
|
||||
}
|
||||
} catch (e) {
|
||||
// 捕获网络或解析异常
|
||||
showToast('获取预约数据失败');
|
||||
hasReservationData = false;
|
||||
reservationList = []; // 清空列表
|
||||
} finally {
|
||||
// 无论成功失败,最后都要关闭加载动画并更新UI
|
||||
dismissLoading();
|
||||
}
|
||||
|
||||
Get.bottomSheet(
|
||||
Container(
|
||||
height: Get.height * 0.45,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 15, 20, 15),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'我的预约',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Get.back(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 0,
|
||||
backgroundColor: Colors.grey[200],
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
child: const Text('关闭', style: TextStyle(color: Colors.black54)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: reservationList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final ReservationModel reservation = reservationList[index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12.0),
|
||||
elevation: 1,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE6F7FF), // Light blue background
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(
|
||||
color: const Color(0xFF91D5FF),
|
||||
), // Blue border
|
||||
),
|
||||
child: Text(
|
||||
reservation.stateName,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF1890FF),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(
|
||||
0xFFFFF7E6,
|
||||
), // Light orange background
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
reservation.addStatusName,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFFFA8C16),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildDetailRow('车牌号:', reservation.plateNumber),
|
||||
_buildDetailRow('预约日期:', reservation.date),
|
||||
_buildDetailRow('预约氢量:', reservation.hydAmount),
|
||||
_buildDetailRow('加氢站:', reservation.stationName),
|
||||
_buildDetailRow('开始时间:', reservation.startTime),
|
||||
_buildDetailRow('结束时间:', reservation.endTime),
|
||||
_buildDetailRow('联系人:', reservation.contacts),
|
||||
_buildDetailRow('联系电话:', reservation.phone),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
isScrollControlled: true,
|
||||
backgroundColor:
|
||||
Colors.transparent, // Make background transparent to see the rounded corners
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 85,
|
||||
child: Text(label, style: TextStyle(color: Colors.grey[600], fontSize: 14)),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
amountController.dispose();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:getx_scaffold/common/index.dart';
|
||||
import 'package:getx_scaffold/common/widgets/text_x.dart';
|
||||
// import 'package:getx_scaffold/getx_scaffold.dart'; // 如果不使用其中的扩展,可以注释掉
|
||||
|
||||
import 'controller.dart';
|
||||
@@ -76,10 +79,17 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
children: [
|
||||
Icon(Icons.shield_outlined, color: Colors.blue, size: 14),
|
||||
SizedBox(width: 4),
|
||||
Text('已认证', style: TextStyle(color: Colors.blue, fontSize: 10, fontWeight: FontWeight.bold)),
|
||||
Text(
|
||||
'已认证',
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -88,10 +98,7 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildStatItem('0Kg', '累计加氢'),
|
||||
_buildStatItem('0次', '加氢次数'),
|
||||
],
|
||||
children: [_buildStatItem('0Kg', '累计加氢'), _buildStatItem('0次', '加氢次数')],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -131,7 +138,11 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Icon(Icons.propane_tank_outlined, size: 80, color: Colors.blue.withOpacity(0.5)),
|
||||
Icon(
|
||||
Icons.propane_tank_outlined,
|
||||
size: 80,
|
||||
color: Colors.blue.withOpacity(0.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -147,15 +158,20 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
const SizedBox(width: 8),
|
||||
isButton
|
||||
? ElevatedButton.icon(
|
||||
onPressed: () { /* TODO: 扫码绑定逻辑 */ },
|
||||
icon: const Icon(Icons.qr_code_scanner, size: 16),
|
||||
label: Text(value),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
),
|
||||
)
|
||||
: Text(value, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
onPressed: () {
|
||||
/* TODO: 扫码绑定逻辑 */
|
||||
},
|
||||
icon: const Icon(Icons.qr_code_scanner, size: 16),
|
||||
label: Text(value),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
value,
|
||||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -168,47 +184,97 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
// 【修改】使用 Obx 包裹以自动响应 Rx 变量的变化
|
||||
child: Obx(() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildPickerRow(
|
||||
label: '日期',
|
||||
value: controller.formattedDate,
|
||||
icon: Icons.calendar_today_outlined,
|
||||
onTap: () => controller.pickDate(context),
|
||||
),
|
||||
_buildPickerRow(
|
||||
label: '开始时间',
|
||||
value: controller.formattedStartTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, true),
|
||||
),
|
||||
_buildPickerRow(
|
||||
label: '结束时间',
|
||||
value: controller.formattedEndTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, false),
|
||||
),
|
||||
_buildTextField(label: '预约氢量(kg)', controller: controller.amountController, hint: '请输入氢量(kg)', keyboardType: TextInputType.number),
|
||||
_buildTextField(label: '车牌号', controller: controller.plateNumberController, hint: '请输入车牌号'),
|
||||
_buildStationSelector(),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: controller.submitReservation,
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
child: Obx(
|
||||
() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildPickerRow(
|
||||
label: '日期',
|
||||
value: controller.formattedDate,
|
||||
icon: Icons.calendar_today_outlined,
|
||||
onTap: () => controller.pickDate(context),
|
||||
),
|
||||
child: const Text('提交预约', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
)),
|
||||
_buildPickerRow(
|
||||
label: '开始时间',
|
||||
value: controller.formattedStartTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, true),
|
||||
),
|
||||
_buildPickerRow(
|
||||
label: '结束时间',
|
||||
value: controller.formattedEndTime,
|
||||
icon: Icons.access_time_outlined,
|
||||
onTap: () => controller.pickTime(context, false),
|
||||
),
|
||||
_buildTextField(
|
||||
label: '预约氢量(kg)',
|
||||
controller: controller.amountController,
|
||||
hint: '请输入氢量(kg)',
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
_buildTextField(
|
||||
label: '车牌号',
|
||||
controller: controller.plateNumberController,
|
||||
hint: '请输入车牌号',
|
||||
),
|
||||
_buildStationSelector(),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: controller.submitReservation,
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
backgroundColor: Colors.blue, // 明确指定背景色
|
||||
foregroundColor: Colors.white, // 明确指定前景色(文字颜色)
|
||||
),
|
||||
child: const Text(
|
||||
'提交预约',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: controller.getReservationList,
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 48), // 高度与另一个按钮保持一致
|
||||
side: const BorderSide(color: Colors.blue), // 设置边框颜色为蓝色
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'查看预约', // 假设第二个按钮是“取消”
|
||||
style: TextStyle(
|
||||
color: Colors.blue, // 设置文字颜色为蓝色
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 表单中的可点击行 (用于日期和时间选择)
|
||||
Widget _buildPickerRow({required String label, required String value, required IconData icon, required VoidCallback onTap}) {
|
||||
Widget _buildPickerRow({
|
||||
required String label,
|
||||
required String value,
|
||||
required IconData icon,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
child: Column(
|
||||
@@ -239,7 +305,12 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
}
|
||||
|
||||
// 表单中的文本输入框
|
||||
Widget _buildTextField({required String label, required TextEditingController controller, required String hint, TextInputType? keyboardType}) {
|
||||
Widget _buildTextField({
|
||||
required String label,
|
||||
required TextEditingController controller,
|
||||
required String hint,
|
||||
TextInputType? keyboardType,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
child: Column(
|
||||
@@ -261,7 +332,6 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
);
|
||||
}
|
||||
|
||||
// 构建加氢站选择器
|
||||
Widget _buildStationSelector() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
@@ -272,59 +342,109 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('加氢站', style: TextStyle(color: Colors.grey[600], fontSize: 14)),
|
||||
TextButton(onPressed: () { /* TODO: 刷新站点列表 */ }, child: const Text('刷新')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showToast("msg");
|
||||
},
|
||||
child: const Text('刷新'),
|
||||
),
|
||||
],
|
||||
),
|
||||
// 【修改】使用 Obx 包裹 DropdownButtonFormField 以响应 Rx 变量
|
||||
Obx(() => DropdownButtonFormField<String>(
|
||||
value: controller.selectedStation.value,
|
||||
isExpanded: true,
|
||||
items: controller.stationOptions.map((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(value, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(width: 8),
|
||||
if (value.contains('银河路')) // 示例:给特定站点加标签
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange[100],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text('维修中', style: TextStyle(color: Colors.orange, fontSize: 10)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Text(
|
||||
'江苏省苏州市常熟市东南街道银河路80号 | ¥45.00/kg',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 12),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
Obx(
|
||||
() => DropdownButtonHideUnderline(
|
||||
child: DropdownButton2<String>(
|
||||
isExpanded: true,
|
||||
hint: Text(
|
||||
'请选择加氢站',
|
||||
style: TextStyle(fontSize: 14, color: Theme.of(Get.context!).hintColor),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (newValue) {
|
||||
if (newValue != null) {
|
||||
controller.selectedStation.value = newValue;
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8.0)),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
||||
items: controller.stationOptions
|
||||
.map(
|
||||
(item) => DropdownMenuItem(
|
||||
value: item,
|
||||
child: _buildDropdownItem(item), // 使用自定义 Widget 构建 Item
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
value: controller.selectedStation.value,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
controller.selectedStation.value = value;
|
||||
}
|
||||
},
|
||||
buttonStyleData: ButtonStyleData(
|
||||
height: 55, // 控制按钮的高度
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0), // 控制按钮内部的内边距
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.grey[400]!),
|
||||
),
|
||||
),
|
||||
iconStyleData: const IconStyleData(
|
||||
icon: Icon(Icons.arrow_drop_down),
|
||||
iconSize: 24,
|
||||
),
|
||||
dropdownStyleData: DropdownStyleData(
|
||||
maxHeight: 200,
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(8)),
|
||||
offset: const Offset(0, -5),
|
||||
elevation: 8,
|
||||
),
|
||||
menuItemStyleData: const MenuItemStyleData(
|
||||
height: 55, // 控制每个下拉选项的高度
|
||||
padding: EdgeInsets.symmetric(horizontal: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///用于构建 DropdownMenuItem 内部的自定义 Widget
|
||||
Widget _buildDropdownItem(String value) {
|
||||
bool isSpecial = value.contains('银河路');
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
value,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (isSpecial) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange[100],
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text(
|
||||
'维修中',
|
||||
style: TextStyle(color: Colors.orange, fontSize: 10),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
const Text(
|
||||
'江苏省苏州市常熟市东南街道银河路80号 | ¥45.00/kg',
|
||||
style: TextStyle(color: Colors.grey, fontSize: 11),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建提示信息卡片
|
||||
Widget _buildTipsCard() {
|
||||
return Card(
|
||||
@@ -351,7 +471,9 @@ class ReservationPage extends GetView<ReservationController> {
|
||||
children: [
|
||||
Icon(icon, color: Colors.blue, size: 20),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: Text(text, style: const TextStyle(fontSize: 12, color: Colors.black54))),
|
||||
Expanded(
|
||||
child: Text(text, style: const TextStyle(fontSize: 12, color: Colors.black54)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
|
||||
await StorageService.to.saveLoginInfo(
|
||||
token: token,
|
||||
userId: "",
|
||||
userId: phone,
|
||||
channel: "driver",
|
||||
);
|
||||
|
||||
|
||||
@@ -177,6 +177,14 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
dropdown_button2:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dropdown_button2
|
||||
sha256: b0fe8d49a030315e9eef6c7ac84ca964250155a6224d491c1365061bc974a9e1
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.3.9"
|
||||
encrypt:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -39,6 +39,7 @@ dependencies:
|
||||
get_storage: ^2.1.1
|
||||
|
||||
flutter_native_splash: ^2.4.7
|
||||
dropdown_button2: ^2.3.8
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user