1、订单页查询定点杆状态
This commit is contained in:
parent
fd71158f9d
commit
1903385ff3
@ -21,4 +21,7 @@ class ShopApi {
|
|||||||
// 订单详情接口
|
// 订单详情接口
|
||||||
static const String goodsOrderDetail = '/app/order';
|
static const String goodsOrderDetail = '/app/order';
|
||||||
|
|
||||||
|
// 查询订单状态
|
||||||
|
static const String goodsOrderStatus= '/trans/easypay/paymentQuery';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import 'package:loopin/utils/wxsdk.dart';
|
|||||||
import 'package:loopin/utils/index.dart';
|
import 'package:loopin/utils/index.dart';
|
||||||
|
|
||||||
import '../../behavior/custom_scroll_behavior.dart';
|
import '../../behavior/custom_scroll_behavior.dart';
|
||||||
|
import '../../utils/lifecycle_handler.dart';
|
||||||
|
|
||||||
class OrderDetail extends StatefulWidget {
|
class OrderDetail extends StatefulWidget {
|
||||||
const OrderDetail({super.key});
|
const OrderDetail({super.key});
|
||||||
@ -28,6 +29,37 @@ class _OrderDetailState extends State<OrderDetail> with SingleTickerProviderStat
|
|||||||
super.initState();
|
super.initState();
|
||||||
_orderId = Get.arguments;
|
_orderId = Get.arguments;
|
||||||
getOrderDetail(orderId: _orderId);
|
getOrderDetail(orderId: _orderId);
|
||||||
|
LifecycleHandler.onAppResumed = _onAppResumed;
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
// 清理回调,避免内存泄漏
|
||||||
|
LifecycleHandler.onAppResumed = null;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
void _onAppResumed() {
|
||||||
|
print('App回到前台,刷新订单状态,订单Id${_orderId}');
|
||||||
|
getOrderDetail(orderId: _orderId); // 刷新订单详情数据
|
||||||
|
getOrderRealStatus(orderId: _orderId); // 同时主动拉取订单状态
|
||||||
|
_showPaymentResultDialog(); // 展示支付结果弹框
|
||||||
|
}
|
||||||
|
// 获取订单状态
|
||||||
|
void getOrderRealStatus({required String orderId}) async {
|
||||||
|
try {
|
||||||
|
final res = await Http.get('${ShopApi.goodsOrderStatus}/$orderId');
|
||||||
|
// transState
|
||||||
|
var orderStatus = res['data']['transState'];
|
||||||
|
print('状态-------------->${orderStatus}');
|
||||||
|
if (orderStatus == 2) { // 已支付
|
||||||
|
MyDialog.toast('支付成功');
|
||||||
|
} else {
|
||||||
|
MyDialog.toast('支付尚未完成,请稍后查看');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
print('报错-------------->${e}');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取订单详情信息,包含商品参数
|
// 获取订单详情信息,包含商品参数
|
||||||
@ -107,7 +139,7 @@ class _OrderDetailState extends State<OrderDetail> with SingleTickerProviderStat
|
|||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
_checkOrderStatus();
|
getOrderRealStatus(orderId: _orderId); // 主动再次拉取订单状态
|
||||||
},
|
},
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
@ -128,7 +160,7 @@ class _OrderDetailState extends State<OrderDetail> with SingleTickerProviderStat
|
|||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
_checkOrderStatus();
|
getOrderRealStatus(orderId: _orderId); // 同时主动拉取订单状态
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Color(0xFFFF5000),
|
backgroundColor: Color(0xFFFF5000),
|
||||||
@ -153,30 +185,6 @@ class _OrderDetailState extends State<OrderDetail> with SingleTickerProviderStat
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查订单状态
|
|
||||||
void _checkOrderStatus() async {
|
|
||||||
try {
|
|
||||||
// 调用接口查询订单状态
|
|
||||||
final res = await Http.get('${ShopApi.goodsOrderDetail}/$_orderId');
|
|
||||||
if (res['data'] != null) {
|
|
||||||
setState(() {
|
|
||||||
orderGoodsInfo = res['data'];
|
|
||||||
});
|
|
||||||
|
|
||||||
// todo 根据状态进行不同的操作
|
|
||||||
int status = orderGoodsInfo?['orderStatus'] ?? 0;
|
|
||||||
if (status == 2) { // 已支付
|
|
||||||
MyDialog.toast('支付成功');
|
|
||||||
} else {
|
|
||||||
MyDialog.toast('支付尚未完成,请稍后查看');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print('查询订单状态失败: $e');
|
|
||||||
MyDialog.toast('查询订单状态失败,请稍后重试');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取订单状态文本
|
// 获取订单状态文本
|
||||||
String getOrderStatusText(int status) {
|
String getOrderStatusText(int status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
@ -242,10 +250,6 @@ class _OrderDetailState extends State<OrderDetail> with SingleTickerProviderStat
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
// 打开微信小程序的某个页面地址,如pages/index/index
|
// 打开微信小程序的某个页面地址,如pages/index/index
|
||||||
Wxsdk.openMiniApp(orderId: _orderId);
|
Wxsdk.openMiniApp(orderId: _orderId);
|
||||||
// 拉起支付后显示支付结果弹框
|
|
||||||
Future.delayed(Duration(milliseconds: 1500), () {
|
|
||||||
_showPaymentResultDialog();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor: WidgetStateProperty.all(Color(0xff07c160)),
|
backgroundColor: WidgetStateProperty.all(Color(0xff07c160)),
|
||||||
|
@ -4,6 +4,7 @@ import 'package:loopin/IM/im_service.dart';
|
|||||||
class LifecycleHandler with WidgetsBindingObserver {
|
class LifecycleHandler with WidgetsBindingObserver {
|
||||||
static bool isInForeground = true;
|
static bool isInForeground = true;
|
||||||
static DateTime appBecameActiveTime = DateTime.now();
|
static DateTime appBecameActiveTime = DateTime.now();
|
||||||
|
static VoidCallback? onAppResumed; // 添加回调函数
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
@ -11,6 +12,9 @@ class LifecycleHandler with WidgetsBindingObserver {
|
|||||||
case AppLifecycleState.resumed:
|
case AppLifecycleState.resumed:
|
||||||
isInForeground = true;
|
isInForeground = true;
|
||||||
appBecameActiveTime = DateTime.now();
|
appBecameActiveTime = DateTime.now();
|
||||||
|
if (onAppResumed != null) {
|
||||||
|
onAppResumed!();
|
||||||
|
}
|
||||||
logger.i("App 回到前台:$appBecameActiveTime");
|
logger.i("App 回到前台:$appBecameActiveTime");
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user