flutter/lib/pages/order/detail.dart

363 lines
13 KiB
Dart
Raw Normal View History

2025-07-21 15:46:30 +08:00
library;
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2025-09-01 18:18:26 +08:00
import 'package:loopin/service/http.dart';
import 'package:loopin/api/shop_api.dart';
2025-07-21 15:46:30 +08:00
import 'package:shirne_dialog/shirne_dialog.dart';
import 'package:timer_count_down/timer_count_down.dart';
2025-09-01 18:18:26 +08:00
import 'package:loopin/utils/wxsdk.dart';
2025-09-03 10:39:38 +08:00
import 'package:loopin/utils/index.dart';
2025-07-21 15:46:30 +08:00
import '../../behavior/custom_scroll_behavior.dart';
class OrderDetail extends StatefulWidget {
const OrderDetail({super.key});
@override
State<OrderDetail> createState() => _OrderDetailState();
}
class _OrderDetailState extends State<OrderDetail> with SingleTickerProviderStateMixin {
late String _orderId;
2025-09-01 18:18:26 +08:00
dynamic orderGoodsInfo;
@override
void initState() {
super.initState();
_orderId = Get.arguments;
getOrderDetail(orderId: _orderId);
}
// 获取订单详情信息,包含商品参数
void getOrderDetail({required String orderId}) async {
2025-09-01 18:18:26 +08:00
try {
final res = await Http.get('${ShopApi.goodsOrderDetail}/$orderId');
print('订单详情-------------->${res['data']}');
setState(() {
orderGoodsInfo = res['data']; // 注意取 data 部分
});
} catch (e) {
Get.back();
}
}
// 计算时间
int handleTime() {
String dbTime = '2025-08-21 15:07:31.293';
DateTime orderTime = DateTime.parse(dbTime);
// 计算过期时间 = 下单时间 + 15分钟
DateTime expireTime = orderTime.add(const Duration(minutes: 15));
// 剩余秒数
int remainSeconds = expireTime.difference(DateTime.now()).inSeconds;
if (remainSeconds < 0) remainSeconds = 0;
return remainSeconds;
}
2025-07-21 15:46:30 +08:00
Widget emptyTip() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 5.0,
children: [
Image.asset(
'assets/images/empty.png',
width: 100.0,
),
Text(
'还没有订单信息~',
style: TextStyle(color: Colors.grey, fontSize: 12.0),
)
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[50],
appBar: AppBar(
backgroundColor: Color(0xFFFF5000),
foregroundColor: Colors.white,
title: Text('订单详情'),
titleSpacing: 1.0,
// actions: [
// IconButton(
// icon: Icon(Icons.help, size: 18.0),
// onPressed: () {},
// ),
// ],
2025-07-21 15:46:30 +08:00
),
body: ScrollConfiguration(
behavior: CustomScrollBehavior().copyWith(scrollbars: false),
child: ListView(
physics: BouncingScrollPhysics(),
padding: EdgeInsets.all(10.0),
children: [
Column(
spacing: 5.0,
children: [
Text.rich(
TextSpan(style: TextStyle(fontFamily: 'Arial'), children: [
WidgetSpan(
child: Icon(
Icons.info,
size: 16.0,
)),
TextSpan(text: ' 待支付, '),
TextSpan(text: ' 剩余 '),
// TextSpan(
// text: '00 : 29 : 55',
// style: TextStyle(color: Colors.red),
// ),
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Countdown(
// createtime
// seconds: 15 * 60, // 15分钟
seconds: handleTime(),
build: (_, double time) {
int m = ((time % 3600) ~/ 60).toInt();
int s = (time % 60).toInt();
String formatted = "${m.toString().padLeft(2, '0')} : ${s.toString().padLeft(2, '0')}";
return Text(
formatted,
style: const TextStyle(color: Colors.red),
);
},
interval: const Duration(seconds: 1),
onFinished: () {
print("倒计时结束");
},
),
2025-07-21 15:46:30 +08:00
),
]),
),
Text(
'超过30分钟未支付订单将自动取消',
style: TextStyle(color: Colors.grey, fontSize: 12.0),
),
SizedBox(
height: 10.0,
),
],
),
// 商品信息
Container(
margin: EdgeInsets.only(bottom: 10.0),
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15.0), boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(10),
offset: Offset(0.0, 1.0),
blurRadius: 1.0,
spreadRadius: 0.0,
),
]),
child: Column(
spacing: 10.0,
children: [
Row(
children: [
2025-09-03 10:39:38 +08:00
/* Wrap(
2025-07-21 15:46:30 +08:00
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 5.0,
children: [
ClipOval(
child: Image.asset(
'assets/images/avatar/img11.jpg',
width: 25.0,
),
),
2025-09-03 10:39:38 +08:00
Text('${orderGoodsInfo['contactUserName']}'),
//contactUserName
2025-07-21 15:46:30 +08:00
Icon(
Icons.arrow_forward_ios_rounded,
color: Colors.grey,
size: 12.0,
),
],
2025-09-03 10:39:38 +08:00
),*/
2025-07-21 15:46:30 +08:00
Spacer(),
Text(
'待付款',
style: TextStyle(color: Colors.red),
)
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 10.0,
children: [
2025-09-03 10:39:38 +08:00
/* SvgPicture.asset(
'assets/images/svg/kefu.svg',
height: 36.0,
width: 36.0,
)*/
2025-07-21 15:46:30 +08:00
Image.network(
2025-09-03 10:39:38 +08:00
'${orderGoodsInfo['productInfo'][0]['pic']}',
2025-07-21 15:46:30 +08:00
width: 80.0,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 5.0,
children: [
2025-09-03 10:39:38 +08:00
// Text('${orderGoodsInfo['contactUserName']}'),
2025-07-21 15:46:30 +08:00
Text(
2025-09-03 10:39:38 +08:00
'${orderGoodsInfo['productInfo'][0]['productName']}',
2025-07-21 15:46:30 +08:00
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
Row(
children: [
Text(
2025-09-03 10:39:38 +08:00
'¥${orderGoodsInfo['productInfo'][0]['salePrice']}',
2025-07-21 15:46:30 +08:00
style: TextStyle(color: Colors.red),
),
Spacer(),
Text(
2025-09-03 10:39:38 +08:00
'x1',
2025-07-21 15:46:30 +08:00
style: TextStyle(color: Colors.grey),
),
],
),
],
),
)
],
),
],
),
),
// 订单信息
Container(
margin: EdgeInsets.only(bottom: 10.0),
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15.0), boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(10),
offset: Offset(0.0, 1.0),
blurRadius: 1.0,
spreadRadius: 0.0,
),
]),
child: Column(
spacing: 10.0,
children: [
Row(
children: [
Text(
'订单信息',
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
),
Spacer(),
InkWell(
child: Icon(
Icons.copy,
color: Colors.grey,
size: 14.0,
),
onTap: () {
MyDialog.toast('复制订单信息', icon: Icon(Icons.check_circle));
},
)
],
),
Column(
spacing: 5.0,
children: [
Row(
children: [
Text(
'订单号',
style: TextStyle(color: Colors.grey),
),
Spacer(),
2025-09-03 10:39:38 +08:00
Text(orderGoodsInfo['orderId'], style: TextStyle(fontSize: 12.0)),
2025-07-21 15:46:30 +08:00
],
),
Row(
children: [
Text(
'下单时间',
style: TextStyle(color: Colors.grey),
),
Spacer(),
2025-09-03 10:39:38 +08:00
Text(orderGoodsInfo['createTime'], style: TextStyle(fontSize: 12.0)),
2025-07-21 15:46:30 +08:00
],
),
Row(
children: [
Text(
'购买数量',
style: TextStyle(color: Colors.grey),
),
Spacer(),
2025-09-03 10:39:38 +08:00
// 添加空值安全检查
Text((orderGoodsInfo['productInfo'][0]['buyNum'] ?? 0).toString(),
style: TextStyle(fontSize: 12.0)),
2025-07-21 15:46:30 +08:00
],
),
Row(
children: [
Text(
'订单金额',
style: TextStyle(color: Colors.grey),
),
Spacer(),
2025-09-03 10:39:38 +08:00
Text('¥${orderGoodsInfo['totalAmount']??'0.00'}', style: TextStyle(fontSize: 12.0)),
2025-07-21 15:46:30 +08:00
],
),
Row(
children: [
Text(
'实付金额',
style: TextStyle(color: Colors.grey),
),
Spacer(),
2025-09-03 10:39:38 +08:00
Text('¥${orderGoodsInfo['payAmount']??'0.00'}', style: TextStyle(fontSize: 12.0)),
2025-07-21 15:46:30 +08:00
],
),
],
)
],
),
),
],
),
),
// 底部固定按钮
bottomNavigationBar: SafeArea(
minimum: const EdgeInsets.all(10),
child: Container(
height: 50.0,
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
onPressed: () {},
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(Colors.white),
foregroundColor: WidgetStateProperty.all(Colors.black87),
),
child: const Text('取消订单'),
),
const SizedBox(width: 10.0),
ElevatedButton(
2025-09-01 18:18:26 +08:00
onPressed: () {
//打开微信小程序的某个页面地址如pages/index/index
Wxsdk.openMiniApp(orderId:_orderId);
},
2025-07-21 15:46:30 +08:00
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(Color(0xff07c160)),
foregroundColor: WidgetStateProperty.all(Colors.white),
),
child: const Text('去支付'),
),
],
),
),
),
);
}
}