202 lines
7.1 KiB
Dart
202 lines
7.1 KiB
Dart
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/widgets.dart';
|
||
|
||
import '../../apis/app.dart';
|
||
import '../../components/appbar.dart';
|
||
import '../../components/gradientButton.dart';
|
||
|
||
class OrderDetailPage extends StatefulWidget {
|
||
final String orderId;
|
||
const OrderDetailPage({super.key, required this.orderId});
|
||
|
||
@override
|
||
State<OrderDetailPage> createState() => _OrderDetailPageState();
|
||
}
|
||
|
||
class _OrderDetailPageState extends State<OrderDetailPage> {
|
||
Map<String, dynamic>? orderDetail;
|
||
bool isLoading = true;
|
||
String? errorMessage;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_getOrderDetail();
|
||
}
|
||
|
||
// 添加时间格式化方法
|
||
String formatDateTime(String? dateTimeStr) {
|
||
if (dateTimeStr == null || dateTimeStr.isEmpty) {
|
||
return "暂无";
|
||
}
|
||
try {
|
||
final dateTime = DateTime.parse(dateTimeStr);
|
||
return "${dateTime.year}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} "
|
||
"${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}";
|
||
} catch (e) {
|
||
print("时间格式化错误: $e");
|
||
return dateTimeStr;
|
||
}
|
||
}
|
||
// 获取订单详情
|
||
Future<void> _getOrderDetail() async {
|
||
try {
|
||
print("获取订单详情参数: orderId=${widget.orderId}");
|
||
|
||
// 准备API请求参数,直接传递数值
|
||
final response = await userApi.getOrderDetail(int.parse(widget.orderId));
|
||
print("订单详情返回数据: $response");
|
||
|
||
if (response['code'] == 200) {
|
||
setState(() {
|
||
orderDetail = response['data'];
|
||
isLoading = false;
|
||
});
|
||
} else {
|
||
setState(() {
|
||
errorMessage = response['msg'] ?? "获取订单详情失败";
|
||
isLoading = false;
|
||
});
|
||
print("获取订单详情失败: ${response['msg']}");
|
||
}
|
||
} catch (e) {
|
||
setState(() {
|
||
errorMessage = "获取订单详情异常";
|
||
isLoading = false;
|
||
});
|
||
print("获取订单详情异常: $e");
|
||
}
|
||
}
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: const CustomAppBar(title: '订单详情'),
|
||
body: Container(
|
||
decoration: const BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage('images/pwd_bg.png'),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: isLoading
|
||
? Center(child: CircularProgressIndicator())
|
||
: errorMessage != null
|
||
? Center(
|
||
child: Text(
|
||
errorMessage!,
|
||
style: TextStyle(color: Colors.red, fontSize: 16),
|
||
),
|
||
)
|
||
: Column(
|
||
children: [
|
||
const SizedBox(height: 50),
|
||
Image.asset(
|
||
'images/check.png',
|
||
width: 60,
|
||
height: 60,
|
||
),
|
||
const SizedBox(height: 10),
|
||
const Text(
|
||
'作品已提交,后台审核中',
|
||
style: TextStyle(fontSize: 18, color: Colors.white),
|
||
),
|
||
Container(
|
||
padding: const EdgeInsets.all(10.0),
|
||
margin: EdgeInsets.only(top: 30),
|
||
child: Container(
|
||
color: Color(0xFF1F212E),
|
||
width: double.infinity,
|
||
height: 200,
|
||
padding: EdgeInsets.all(10),
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text('订单详情',
|
||
style: TextStyle(fontSize: 16, color: Colors.white)),
|
||
_buildDetailRow('订单价格', orderDetail?['money'] != null
|
||
? '${(orderDetail!['money'] / 1000).toStringAsFixed(2)}元'
|
||
: '0.00元'),
|
||
_buildDetailRow('订单编号', orderDetail?['orderInfoId'] ?? ""),
|
||
_buildDetailRow('创建时间', formatDateTime(orderDetail?['createTime'])),
|
||
_buildDetailRow('付款时间', formatDateTime(orderDetail?['payTime'])),
|
||
_buildDetailRow('MR位置', orderDetail?['arLocation'] ?? ""),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
const Spacer(),
|
||
Padding(
|
||
padding: const EdgeInsets.all(20.0),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: TextButton(
|
||
style: TextButton.styleFrom(
|
||
backgroundColor: Color(0xFF96FBE9).withOpacity(0.2),
|
||
side: BorderSide(
|
||
color: Color(0xFF96FBE9).withOpacity(0.8),
|
||
width: 1),
|
||
shape: RoundedRectangleBorder(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
minimumSize: Size(150,41),
|
||
),
|
||
onPressed: () {
|
||
Navigator.pushNamedAndRemoveUntil(
|
||
context,
|
||
'/tabs',
|
||
(route) => false,
|
||
arguments: {'initialIndex': 1},
|
||
);
|
||
},
|
||
child: Text(
|
||
'继续发布',
|
||
style: TextStyle(color: Colors.white, fontSize: 16),
|
||
),
|
||
),
|
||
),
|
||
SizedBox(width: 10),
|
||
Expanded(
|
||
child: GradientButton(
|
||
width: 150,
|
||
height: 41,
|
||
text: '完成',
|
||
onPressed: () {
|
||
print("点击了完成按钮");
|
||
Navigator.pushNamedAndRemoveUntil(
|
||
context,
|
||
'/tabs',
|
||
(route) => false,
|
||
arguments: {'initialIndex': 0},
|
||
);
|
||
},
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildDetailRow(String label, String value) {
|
||
return Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
label,
|
||
style: TextStyle(fontSize: 14, color: Colors.white.withOpacity(0.5)),
|
||
),
|
||
Text(
|
||
value,
|
||
style: TextStyle(fontSize: 12, color: Colors.white),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
}
|