feat:bug修改

This commit is contained in:
dzc committed 2026-03-29 18:56:34 +08:00
1 parent 3729e3b896
commit 48c1ee8cb2
8 files changed
+143 -85

No files matched your search

+29 -1
View File
@@ -3,12 +3,40 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:forui/forui.dart';
import 'package:get/get.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter_subscreen_plugin/flutter_subscreen_plugin.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
class MainApp extends StatelessWidget {
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
if (state == AppLifecycleState.paused ||
state == AppLifecycleState.detached) {
try {
SubScreenPlugin.doubleScreenCancel();
} catch (_) {}
}
}
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
+10 -2
View File
@@ -1600,7 +1600,11 @@ class _$UserDao extends UserDao {
createTime:
_dateTimeEmptyConverter.decode(row['createTime'] as String),
updateTime:
_dateTimeEmptyConverter.decode(row['updateTime'] as String)),
_dateTimeEmptyConverter.decode(row['updateTime'] as String),
discountsUpdateTime: _dateTimeEmptyConverter
.decode(row['discountsUpdateTime'] as String),
discountsList:
_listDiscountsConverter.decode(row['discountsList'] as String)),
arguments: [userId]);
}
@@ -1622,7 +1626,11 @@ class _$UserDao extends UserDao {
createTime:
_dateTimeEmptyConverter.decode(row['createTime'] as String),
updateTime:
_dateTimeEmptyConverter.decode(row['updateTime'] as String)),
_dateTimeEmptyConverter.decode(row['updateTime'] as String),
discountsUpdateTime: _dateTimeEmptyConverter
.decode(row['discountsUpdateTime'] as String),
discountsList:
_listDiscountsConverter.decode(row['discountsList'] as String)),
arguments: [walletCardNumber]);
}
@@ -123,6 +123,8 @@ class UserEntity extends Equatable {
this.canteenId,
this.createTime,
this.updateTime,
this.discountsUpdateTime,
this.discountsList,
});
/// 计算优惠后的价格
@@ -44,13 +44,13 @@ UserEntity _$UserEntityFromJson(Map<String, dynamic> json) => UserEntity(
updateTime: json['updateTime'] == null
? null
: DateTime.parse(json['updateTime'] as String),
)
..discountsList = (json['discountsList'] as List<dynamic>?)
?.map((e) => DiscountsItem.fromJson(e as Map<String, dynamic>))
.toList()
..discountsUpdateTime = json['discountsUpdateTime'] == null
discountsUpdateTime: json['discountsUpdateTime'] == null
? null
: DateTime.parse(json['discountsUpdateTime'] as String);
: DateTime.parse(json['discountsUpdateTime'] as String),
discountsList: (json['discountsList'] as List<dynamic>?)
?.map((e) => DiscountsItem.fromJson(e as Map<String, dynamic>))
.toList(),
);
Map<String, dynamic> _$UserEntityToJson(UserEntity instance) =>
<String, dynamic>{
@@ -153,21 +153,24 @@ class ListDiscountsConverter
extends TypeConverter<List<DiscountsItem>?, String> {
@override
List<DiscountsItem> decode(String databaseValue) {
if (databaseValue.isEmpty) {
return [];
if (databaseValue.isEmpty) return [];
final raw = json.decode(databaseValue);
if (raw is List) {
return raw
.map<DiscountsItem>(
(e) => DiscountsItem.fromJson(
Map<String, dynamic>.from(e as Map),
),
)
.toList();
}
return json
.decode(databaseValue)
.map((e) => DiscountsItem.fromJson(e))
.toList();
return [];
}
@override
String encode(List<DiscountsItem>? value) {
if (ObjectUtil.isEmptyList(value)) {
return '';
}
return json.encode(value);
if (ObjectUtil.isEmptyList(value)) return '[]';
return json.encode(value!.map((e) => e.toJson()).toList());
}
}
+7 -17
View File
@@ -39,6 +39,9 @@ class DiscountsTool {
required List<ShopCardEntity> shopCardList,
required String hourType,
}) async {
if (ObjectUtil.isEmpty(shopCardList)) {
return 0;
}
var discountsItems = await updateUserDiscountsList(userId: userId);
discountsItems = discountsItems
?.where((element) => element.hourType?.code == hourType)
@@ -51,23 +54,10 @@ class DiscountsTool {
final extraPer = item.extraPer;
final specialDishEnable = item.specialDishEnable;
if (extraPer == null || extraPer <= 1.0) continue;
// 计算总价
int totalPrice = 0;
// 特色菜不额外收费
if (!specialDishEnable) {
totalPrice = shopCardList
.where((item) => item.isPriceIncreased)
.map((item) => item.totalPrice)
.reduce((value, element) => value + element);
extraPrice += item.computedDiscountsExtraPrice(totalPrice);
}
// 特色菜额外收费
if (specialDishEnable) {
totalPrice = shopCardList
.map((item) => item.totalPrice)
.reduce((value, element) => value + element);
extraPrice += item.computedDiscountsExtraPrice(totalPrice);
}
final iterable = specialDishEnable
? shopCardList
: shopCardList.where((e) => e.isPriceIncreased);
final totalPrice = iterable.fold<int>(0, (sum, e) => sum + e.totalPrice);
extraPrice += item.computedDiscountsExtraPrice(totalPrice);
}
return extraPrice;
@@ -307,6 +307,7 @@ mixin OrderMixin {
"productCount": v.productNumber,
"productWeight": 0,
"productNature": ProductNature.DEFAULT.name,
"isPriceIncreased": v.isPriceIncreased,
};
}).toList();
} else if (_sysType == SysType.SUPERMARKET) {
@@ -316,6 +317,7 @@ mixin OrderMixin {
"productCount": v.productNumber,
"productWeight": v.productWidget,
"productNature": v.nature.name,
"isPriceIncreased": v.isPriceIncreased,
};
}).toList();
}
@@ -332,6 +334,7 @@ mixin OrderMixin {
"orderSourceTypeId": getOrderSourceTypeId(),
"orderPayType": orderPayType.value?.name,
"list": shopList,
"extraPrice": amountMealPrice.value,
};
if (orderPayType.value != null &&
appSetting.sysType == SysType.CANTEEN &&
+73 -49
View File
@@ -131,7 +131,77 @@ class _SubProductPageState extends State<SubProductPage> {
final width = constraints.maxWidth;
final height = constraints.maxHeight;
final hdHeight = height / 11;
final hdWidth = width / 4.1;
final hdWidth = width / (_sysType == SysType.CANTEEN ? 5.1 : 4.1);
final columns = [
DataColumn2(
label: Text("名称", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
DataColumn2(
label: Text("数量", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
DataColumn2(
label: Text("单价", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
DataColumn2(
label: Text("总价", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
];
if (_sysType == SysType.CANTEEN) {
columns.insert(
1,
DataColumn2(
label: Text("是否额外收费", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
);
}
final rows = _shopList.map((v) {
final cells = [
DataCell(
Text(
v.productName,
textAlign: TextAlign.center,
).center(),
),
DataCell(
Text(
v.nature == ProductNature.DEFAULT
? v.productNumber.toString()
: "${v.productWidget}/kg",
textAlign: TextAlign.center,
).center(),
),
DataCell(
appPrice(context, v.productPrice).center(),
),
DataCell(
appPrice(context, v.totalPrice).center(),
),
];
if (_sysType == SysType.CANTEEN) {
cells.insert(
1,
DataCell(
Text(
v.isPriceIncreased ? "是" : "否",
textAlign: TextAlign.center,
).center(),
),
);
}
return DataRow(cells: cells);
});
return DataTable2(
columnSpacing: 12.w,
horizontalMargin: 12.w,
@@ -140,54 +210,8 @@ class _SubProductPageState extends State<SubProductPage> {
headingTextStyle: theme.typography.lg,
dataTextStyle: theme.typography.base,
dataRowHeight: hdHeight,
columns: [
DataColumn2(
label: Text("名称", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
DataColumn2(
label: Text("数量", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
DataColumn2(
label: Text("单价", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
DataColumn2(
label: Text("总价", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
],
rows: _shopList.map((v) {
return DataRow(
cells: [
DataCell(
Text(
v.productName,
textAlign: TextAlign.center,
).center(),
),
DataCell(
Text(
v.nature == ProductNature.DEFAULT
? v.productNumber.toString()
: "${v.productWidget}/kg",
textAlign: TextAlign.center,
).center(),
),
DataCell(
appPrice(context, v.productPrice).center(),
),
DataCell(
appPrice(context, v.totalPrice).center(),
),
],
);
}).toList(),
columns: columns,
rows: rows.toList(),
);
},
);