feat(订单历史): 添加售后退货理由支持

在订单历史模块中,新增了售后退货理由的功能。具体修改包括:
1. 在 `CanteenExtraPriceSetting` 模型中添加 `afterSaleReturnReasons` 字段。
2. 新增 `refundDialog` 组件,用于显示退货理由选择对话框。
3. 在 `OrderHistoryController` 中,更新支付设置时获取并存储退货理由,并在退款时使用。

这些改动旨在为用户提供更详细的退款原因选择,提升用户体验。
This commit is contained in:
dzc committed 2025-05-16 10:36:07 +08:00
1 parent f0a6316c86
commit d03926a1a6
4 files changed
+158 -26

No files matched your search

@@ -222,6 +222,9 @@ class CanteenExtraPriceSetting extends Equatable {
/// 超过的倍数
double payAmountMealTimes;
/// 售后的退货理由
String? afterSaleReturnReasons;
// 商户支付规则列表
List<ServiceMchRule>? mchRoleList;
@@ -229,6 +232,7 @@ class CanteenExtraPriceSetting extends Equatable {
required this.payAmountEnable,
required this.payAmountMealLimit,
required this.payAmountMealTimes,
this.afterSaleReturnReasons,
this.mchRoleList,
});
@@ -237,6 +241,7 @@ class CanteenExtraPriceSetting extends Equatable {
payAmountEnable,
payAmountMealLimit,
payAmountMealTimes,
afterSaleReturnReasons,
mchRoleList,
];
@@ -501,6 +501,7 @@ mixin OrderMixin {
payAmountEnable: data.payAmountEnable!,
payAmountMealLimit: data.payAmountMealLimit!,
payAmountMealTimes: data.payAmountMealTimes!,
afterSaleReturnReasons: data.afterSaleReturnReasons,
);
if (setting == null || setting != storageData) {
await AppSettingTool.setCanteenExtraPriceConfig(storageData);
+62 -26
View File
@@ -1,4 +1,5 @@
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:forui/forui.dart';
import 'package:get/get.dart';
@@ -6,6 +7,8 @@ import 'package:get/get_connect/http/src/utils/utils.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
import 'widgets/refund_dialog.dart';
class OrderHistoryController extends GetxController {
final appC = Get.find<AppControl>();
@@ -21,6 +24,8 @@ class OrderHistoryController extends GetxController {
RxList<OrderHistoryTableItem> tabList = <OrderHistoryTableItem>[].obs;
RxList<String> saleReasons = <String>[].obs;
// 选择的时间
RxList<DateTime> selectDateTime = <DateTime>[
DateTime.now(),
@@ -51,6 +56,7 @@ class OrderHistoryController extends GetxController {
sysType.value = appSetting.sysType;
hourType.value = appSetting.hourType ?? ProductHourType.MORNING;
hourTypeC.value = {hourType.value.code};
_updateSetting();
// tabs
await getTotalList();
await getOrder();
@@ -216,34 +222,41 @@ class OrderHistoryController extends GetxController {
return;
}
final price = AppriceTool.fenToYuan(v.payPrice);
final isSure = await appMessageDialog(
refundDialog(
Get.context!,
"是否退还${v.username}用户的$price元",
title: "是否退还${v.username}用户的$price元",
saleReasons: saleReasons,
doCancel: () {
Navigator.of(Get.context!).pop();
},
doSubmit: (String value) async {
try {
EasyLoading.show(
status: '退款中...',
maskType: EasyLoadingMaskType.black,
);
final pa = {
"orderId": v.serviceUniqueCode,
"reason": value,
};
final data = await HardApi.timeLimitRefund(pa);
if (!data) throw Error();
// 修改本地订单为退款
v.status = OrderStatus.REFUND;
final orderDao = appC.dataBase.getOrderDao;
await orderDao.edit(v);
await getTotalList();
await getOrder();
TtsManage.speak("退款成功总金额$price元");
} catch (error, stack) {
TtsManage.speak("退款失败");
logger.e("退款失败error:|$error|stack:|$stack|");
} finally {
Navigator.of(Get.context!).pop();
EasyLoading.dismiss();
}
},
);
try {
if (!isSure) return;
EasyLoading.show(
status: '退款中...',
maskType: EasyLoadingMaskType.black,
);
final pa = {
"orderId": v.serviceUniqueCode,
};
final data = await HardApi.timeLimitRefund(pa);
if (!data) throw Error();
// 修改本地订单为退款
v.status = OrderStatus.REFUND;
final orderDao = appC.dataBase.getOrderDao;
await orderDao.edit(v);
await getTotalList();
await getOrder();
TtsManage.speak("退款成功总金额$price元");
} catch (error, stack) {
TtsManage.speak("退款失败");
logger.e("退款失败error:|$error|stack:|$stack|");
} finally {
EasyLoading.dismiss();
}
}
/// 跳转到订单详情
@@ -288,4 +301,27 @@ class OrderHistoryController extends GetxController {
await printManage.close();
}
}
Future<void> _updateSetting() async {
final isNetwork = AppNetworkTool.isAutoNetwork();
if (!isNetwork) return;
var setting = await AppSettingTool.getCanteenExtraPriceConfig();
try {
final data = await WalletApi.getPaySetting();
if (data == null) throw Error();
final storageData = CanteenExtraPriceSetting(
payAmountEnable: data.payAmountEnable!,
payAmountMealLimit: data.payAmountMealLimit!,
payAmountMealTimes: data.payAmountMealTimes!,
afterSaleReturnReasons: data.afterSaleReturnReasons,
);
if (setting == null || setting != storageData) {
await AppSettingTool.setCanteenExtraPriceConfig(storageData);
setting = storageData;
}
saleReasons.value = setting.afterSaleReturnReasons?.split(",") ?? [];
} catch (e, stack) {
logger.e("更新支付设置失败error:|$e|stack:|$stack|");
}
}
}
@@ -0,0 +1,90 @@
import 'package:flutter/material.dart';
import 'package:forui/forui.dart';
import 'package:get/get.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
Future<void> refundDialog(
BuildContext context, {
required String title,
required RxList<String> saleReasons,
required VoidCallback doCancel,
required Function(String) doSubmit,
}) async {
String value = saleReasons.first;
final typeC = FRadioSelectGroupController<String>(value: value);
final theme = FTheme.of(context);
final width = context.width;
final height = context.height;
showDialog(
context: context,
builder: (BuildContext _) {
return FDialog(
direction: Axis.vertical,
title: Text(title, style: theme.typography.lg),
body: <Widget>[
Obx(
() => FSelectGroup(
enabled: false,
controller: typeC,
style: theme.selectGroupStyle.copyWith(
labelLayoutStyle:
theme.selectGroupStyle.labelLayoutStyle.copyWith(
childPadding: EdgeInsets.symmetric(
vertical: 10.h,
),
),
radioStyle: theme.selectGroupStyle.radioStyle.copyWith(
padding: EdgeInsets.symmetric(
vertical: 10.h,
),
),
),
items: saleReasons
.map<FSelectGroupItem<String>>(
(v) => FSelectGroupItem.radio(
value: v,
label: Text(
v,
style: theme.typography.xl,
),
),
)
.toList(),
),
),
].toColumn().width(width * 0.5).height(height * 0.6),
actions: [
<Widget>[
FButton(
label: Text(
"确认退款",
style: theme.typography.xl.copyWith(
color: theme.colorScheme.secondary,
),
),
onPress: () {
doSubmit.call(value);
},
).flexible(flex: 1),
SizedBox(width: 20.w),
FButton(
style: FButtonStyle.destructive,
label: Text(
"取消",
style: theme.typography.xl.copyWith(
color: theme.colorScheme.secondary,
),
),
onPress: () {
doCancel.call();
},
).flexible(flex: 1),
].toRow(),
],
);
},
);
}