feat:挂单

This commit is contained in:
dzc committed 2026-02-06 17:12:02 +08:00
1 parent 988247f3cd
commit 2b956342f4
12 files changed
+545 -36

No files matched your search

@@ -12,4 +12,29 @@ abstract class OrderHoldBillDao {
@delete
Future<void> del(OrderHoldBillEntity entity);
@Query("""
SELECT * FROM order_hold_bill
WHERE
createTime >= :startTime
AND createTime <= :endTime
ORDER BY createTime DESC
LIMIT :pageSize OFFSET :offset
""")
Future<List<OrderHoldBillEntity>> list(
String startTime,
String endTime,
int pageSize,
int offset,
);
@Query("""
SELECT COUNT(*) FROM order_hold_bill WHERE createTime >= :startTime AND createTime <= :endTime
""")
Future<int?> count(String startTime, String endTime);
@Query("""
DELETE FROM order_hold_bill WHERE createTime < datetime('now', '-7 days')
""")
Future<int?> deleteOlderThan7Days();
}
+33 -9
View File
@@ -85,9 +85,11 @@ abstract class AppDatabase extends FloorDatabase {
CREATE TABLE IF NOT EXISTS order_hold_bill (
id INTEGER PRIMARY KEY AUTOINCREMENT,
sysType TEXT NOT NULL,
orderListJson TEXT,
carListJson TEXT,
userJson TEXT,
orderJson TEXT,
price INTEGER DEFAULT 0 NOT NULL,
extraPrice INTEGER DEFAULT 0 NOT NULL,
payPrice INTEGER DEFAULT 0 NOT NULL,
createTime TEXT NOT NULL
)
''');
@@ -101,16 +103,22 @@ abstract class AppDatabase extends FloorDatabase {
final columns =
await database.rawQuery("PRAGMA table_info(order_hold_bill)");
bool hasSysType = false;
bool hasCarListJson = false;
bool hasOrderListJson = false;
bool hasUserJson = false;
bool hasOrderJson = false;
bool hasPrice = false;
bool hasExtraPrice = false;
bool hasPayPrice = false;
bool hasCreateTime = false;
for (final c in columns) {
final name = c['name'];
if (name == 'sysType') hasSysType = true;
if (name == 'carListJson') hasCarListJson = true;
if (name == 'orderListJson') hasOrderListJson = true;
if (name == 'userJson') hasUserJson = true;
if (name == 'orderJson') hasOrderJson = true;
if (name == 'price') hasPrice = true;
if (name == 'extraPrice') hasExtraPrice = true;
if (name == 'payPrice') hasPayPrice = true;
if (name == 'createTime') hasCreateTime = true;
}
if (!hasSysType) {
@@ -118,24 +126,40 @@ abstract class AppDatabase extends FloorDatabase {
'ALTER TABLE order_hold_bill ADD COLUMN sysType TEXT',
);
}
if (!hasOrderListJson) {
if (!hasCarListJson) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN orderListJson TEXT',
'ALTER TABLE order_hold_bill ADD COLUMN carListJson TEXT',
);
if (hasOrderListJson) {
// 旧列迁移到新列
await database.execute(
"UPDATE order_hold_bill SET carListJson = orderListJson WHERE carListJson IS NULL",
);
}
}
if (!hasUserJson) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN userJson TEXT',
);
}
if (!hasOrderJson) {
if (!hasPrice) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN orderJson TEXT',
'ALTER TABLE order_hold_bill ADD COLUMN price INTEGER DEFAULT 0 NOT NULL',
);
}
if (!hasExtraPrice) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN extraPrice INTEGER DEFAULT 0 NOT NULL',
);
}
if (!hasPayPrice) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN payPrice INTEGER DEFAULT 0 NOT NULL',
);
}
if (!hasCreateTime) {
await database.execute(
'ALTER TABLE order_hold_bill ADD COLUMN createTime TEXT',
'ALTER TABLE order_hold_bill ADD COLUMN createTime TEXT DEFAULT "" NOT NULL',
);
}
await database.execute(
+48 -8
View File
@@ -124,7 +124,7 @@ class _$AppDatabase extends AppDatabase {
await database.execute(
'CREATE TABLE IF NOT EXISTS `order_record` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `uniqueCode` TEXT NOT NULL, `serviceUniqueCode` TEXT NOT NULL, `sysType` TEXT NOT NULL, `userCode` TEXT NOT NULL, `username` TEXT, `hourType` TEXT, `price` INTEGER NOT NULL, `extraPrice` INTEGER NOT NULL, `payPrice` INTEGER NOT NULL, `walletId` TEXT, `orderSourceTypeId` TEXT, `type` TEXT NOT NULL, `status` TEXT NOT NULL, `payType` TEXT NOT NULL, `productDesc` TEXT, `count` INTEGER NOT NULL, `weight` REAL NOT NULL, `payTime` TEXT, `createTime` TEXT NOT NULL)');
await database.execute(
'CREATE TABLE IF NOT EXISTS `order_hold_bill` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `sysType` TEXT NOT NULL, `orderListJson` TEXT, `userJson` TEXT, `orderJson` TEXT, `createTime` TEXT NOT NULL)');
'CREATE TABLE IF NOT EXISTS `order_hold_bill` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `sysType` TEXT NOT NULL, `carListJson` TEXT, `userJson` TEXT, `price` INTEGER NOT NULL, `extraPrice` INTEGER NOT NULL, `payPrice` INTEGER NOT NULL, `createTime` TEXT NOT NULL)');
await database.execute(
'CREATE TABLE IF NOT EXISTS `canteen_spu` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `serviceUniqueCode` TEXT NOT NULL, `classifyServiceUniqueCode` TEXT NOT NULL, `hourType` INTEGER, `saleDate` TEXT NOT NULL, `name` TEXT NOT NULL, `price` INTEGER NOT NULL, `image` TEXT, `isDefault` INTEGER NOT NULL, `status` INTEGER NOT NULL, `sort` INTEGER NOT NULL, `createTime` TEXT NOT NULL, `updateTime` TEXT NOT NULL)');
await database.execute(
@@ -608,15 +608,18 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
_$OrderHoldBillDao(
this.database,
this.changeListener,
) : _orderHoldBillEntityInsertionAdapter = InsertionAdapter(
) : _queryAdapter = QueryAdapter(database),
_orderHoldBillEntityInsertionAdapter = InsertionAdapter(
database,
'order_hold_bill',
(OrderHoldBillEntity item) => <String, Object?>{
'id': item.id,
'sysType': _sysTypeConverter.encode(item.sysType),
'orderListJson': item.orderListJson,
'carListJson': item.carListJson,
'userJson': item.userJson,
'orderJson': item.orderJson,
'price': item.price,
'extraPrice': item.extraPrice,
'payPrice': item.payPrice,
'createTime': _dateTimeConverter.encode(item.createTime)
}),
_orderHoldBillEntityUpdateAdapter = UpdateAdapter(
@@ -626,9 +629,11 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
(OrderHoldBillEntity item) => <String, Object?>{
'id': item.id,
'sysType': _sysTypeConverter.encode(item.sysType),
'orderListJson': item.orderListJson,
'carListJson': item.carListJson,
'userJson': item.userJson,
'orderJson': item.orderJson,
'price': item.price,
'extraPrice': item.extraPrice,
'payPrice': item.payPrice,
'createTime': _dateTimeConverter.encode(item.createTime)
}),
_orderHoldBillEntityDeletionAdapter = DeletionAdapter(
@@ -638,9 +643,11 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
(OrderHoldBillEntity item) => <String, Object?>{
'id': item.id,
'sysType': _sysTypeConverter.encode(item.sysType),
'orderListJson': item.orderListJson,
'carListJson': item.carListJson,
'userJson': item.userJson,
'orderJson': item.orderJson,
'price': item.price,
'extraPrice': item.extraPrice,
'payPrice': item.payPrice,
'createTime': _dateTimeConverter.encode(item.createTime)
});
@@ -648,6 +655,8 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
final StreamController<String> changeListener;
final QueryAdapter _queryAdapter;
final InsertionAdapter<OrderHoldBillEntity>
_orderHoldBillEntityInsertionAdapter;
@@ -656,6 +665,37 @@ class _$OrderHoldBillDao extends OrderHoldBillDao {
final DeletionAdapter<OrderHoldBillEntity>
_orderHoldBillEntityDeletionAdapter;
@override
Future<List<OrderHoldBillEntity>> list(
String startTime,
String endTime,
int pageSize,
int offset,
) async {
return _queryAdapter.queryList(
'SELECT * FROM order_hold_bill WHERE createTime >= ?1 AND createTime <= ?2 ORDER BY createTime DESC LIMIT ?3 OFFSET ?4',
mapper: (Map<String, Object?> row) => OrderHoldBillEntity(id: row['id'] as int?, sysType: _sysTypeConverter.decode(row['sysType'] as String), carListJson: row['carListJson'] as String?, userJson: row['userJson'] as String?, price: row['price'] as int, extraPrice: row['extraPrice'] as int, payPrice: row['payPrice'] as int, createTime: _dateTimeConverter.decode(row['createTime'] as String)),
arguments: [startTime, endTime, pageSize, offset]);
}
@override
Future<int?> count(
String startTime,
String endTime,
) async {
return _queryAdapter.query(
'SELECT COUNT(*) FROM order_hold_bill WHERE createTime >= ?1 AND createTime <= ?2',
mapper: (Map<String, Object?> row) => row.values.first as int,
arguments: [startTime, endTime]);
}
@override
Future<int?> deleteOlderThan7Days() async {
return _queryAdapter.query(
'DELETE FROM order_hold_bill WHERE createTime < datetime(\'now\', \'-7 days\')',
mapper: (Map<String, Object?> row) => row.values.first as int);
}
@override
Future<int> save(OrderHoldBillEntity entity) {
return _orderHoldBillEntityInsertionAdapter.insertAndReturnId(
@@ -16,22 +16,31 @@ class OrderHoldBillEntity {
SysType sysType;
/// 订单列表json
String? orderListJson;
String? carListJson;
/// 支付订单json
String? userJson;
String? orderJson;
/// 购物车的总金额
int price;
/// 购物车额外金额
int extraPrice;
/// 结算总金额
int payPrice;
/// 创建时间
DateTime createTime;
OrderHoldBillEntity({
this.id,
this.orderListJson,
this.userJson,
this.orderJson,
required this.sysType,
this.carListJson,
this.userJson,
required this.price,
required this.extraPrice,
required this.payPrice,
required this.createTime,
});
@@ -9,10 +9,12 @@ part of 'order_hold_bill_entity.dart';
OrderHoldBillEntity _$OrderHoldBillEntityFromJson(Map<String, dynamic> json) =>
OrderHoldBillEntity(
id: (json['id'] as num?)?.toInt(),
orderListJson: json['orderListJson'] as String?,
userJson: json['userJson'] as String?,
orderJson: json['orderJson'] as String?,
sysType: $enumDecode(_$SysTypeEnumMap, json['sysType']),
carListJson: json['carListJson'] as String?,
userJson: json['userJson'] as String?,
price: (json['price'] as num).toInt(),
extraPrice: (json['extraPrice'] as num).toInt(),
payPrice: (json['payPrice'] as num).toInt(),
createTime: DateTime.parse(json['createTime'] as String),
);
@@ -21,9 +23,11 @@ Map<String, dynamic> _$OrderHoldBillEntityToJson(
<String, dynamic>{
'id': instance.id,
'sysType': _$SysTypeEnumMap[instance.sysType]!,
'orderListJson': instance.orderListJson,
'carListJson': instance.carListJson,
'userJson': instance.userJson,
'orderJson': instance.orderJson,
'price': instance.price,
'extraPrice': instance.extraPrice,
'payPrice': instance.payPrice,
'createTime': instance.createTime.toIso8601String(),
};
+1 -1
View File
@@ -1,4 +1,4 @@
class AppriceTool {
class AppPriceTool {
static const int _fractionDigits = 2;
static String fenToYuan(num? price) {
+2 -1
View File
@@ -27,7 +27,8 @@ export './order/steelyard_container.dart';
export './order/order_caneen_common.dart';
export './order/order_common.dart';
export './order/order_supermarket_common.dart';
export 'order/order_more_dialog.dart';
export './order/select_hold_bill_dialog.dart';
export './order/order_more_dialog.dart';
export './setting/setting_password_dialog.dart';
@@ -374,7 +374,7 @@ mixin OrderMixin {
await orderDao.edit(sqlOrderDetail);
if (orderPayType.value != OrderPayType.WALLET_QR_CODE_SCAN) {
if (sqlOrderDetail.payPrice != 0) {
final price = AppriceTool.fenToYuan(sqlOrderDetail.payPrice);
final price = AppPriceTool.fenToYuan(sqlOrderDetail.payPrice);
TtsManage.speak("购买成功总金额$price元");
}
Toast.success(msg: "购买成功");
@@ -24,7 +24,7 @@ Future<OrderMoreTypeEnum?> selectOrderMoreDialog() async {
final width = Get.context!.width;
final height = Get.context!.height;
final dialogWidth = width * 0.3;
final dialogHeight = height * 0.5;
final dialogHeight = height * 0.25;
return showDialog<OrderMoreTypeEnum?>(
context: context,
barrierDismissible: true,
@@ -55,7 +55,10 @@ Future<OrderMoreTypeEnum?> selectOrderMoreDialog() async {
).marginOnly(bottom: 20.h),
)
.toList(),
].toColumn().width(double.infinity).height(dialogHeight),
]
.toColumn(mainAxisAlignment: MainAxisAlignment.center)
.width(double.infinity)
.height(dialogHeight),
actions: [],
);
});
@@ -0,0 +1,366 @@
import 'dart:convert';
import 'package:common_utils/common_utils.dart';
import 'package:data_table_2/data_table_2.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:forui/forui.dart';
import 'package:get/get.dart';
import 'package:pj_supermarket_cloud/common/index.dart';
class SelectHoldBillController extends GetxController {
static const String _tag = "挂单管理 Controller";
final appC = Get.find<AppControl>();
// 选择的时间
RxList<DateTime> selectDateTime = <DateTime>[
DateTime.now(),
DateTime.now().add(const Duration(days: 1)),
].obs;
RxInt currentPage = RxInt(1);
RxInt totalPage = RxInt(0);
RxInt pageSize = RxInt(5);
RxList<OrderHoldBillEntity> holdBillList = RxList();
Rxn<int> selectedId = Rxn<int>(null);
@override
void onInit() async {
super.onInit();
await getHoldBillList();
}
@override
void onClose() {}
Future<void> doDateRangeDate(List<DateTime>? dateTime) async {
if (ObjectUtil.isEmptyList(dateTime)) {
return;
}
selectDateTime.value = dateTime!;
currentPage.value = 1;
await doPage();
}
/// 搜索
Future<void> doPage({int? page}) async {
if (page != null) currentPage.value = page;
await getHoldBillList(isLoading: true);
}
/// 获取挂单列表
Future<void> getHoldBillList({bool isLoading = false}) async {
if (isLoading) {
EasyLoading.show(
status: '查询中...',
maskType: EasyLoadingMaskType.black,
);
}
final orderHoldBillDao = appC.dataBase.getOrderHoldBillDao;
try {
final startTime = DateUtil.formatDate(
DateTime(selectDateTime[0].year, selectDateTime[0].month,
selectDateTime[0].day, 0, 0, 0),
);
final endTime = DateUtil.formatDate(
DateTime(selectDateTime[1].year, selectDateTime[1].month,
selectDateTime[1].day, 23, 59, 59),
);
final total = await orderHoldBillDao.count(
startTime,
endTime,
);
totalPage.value = total ?? 0;
final list = await orderHoldBillDao.list(
startTime,
endTime,
pageSize.value,
(currentPage.value - 1) * pageSize.value,
);
if (ObjectUtil.isEmptyList(list)) {
holdBillList.value = [];
return;
}
holdBillList.value = list;
} catch (error, stack) {
LogUtil.e("|$_tag|,获取挂单列表意外的错误error:|$error|,stack:|$stack|");
} finally {
if (isLoading) {
Future.delayed(const Duration(seconds: 1), () {
EasyLoading.dismiss();
});
}
// 只保留7天内的挂单数据
orderHoldBillDao.deleteOlderThan7Days();
}
}
}
Future<OrderHoldBillEntity?> selectHoldBillDialog() async {
final context = Get.context!;
final theme = FTheme.of(context);
final holdBillC = Get.put<SelectHoldBillController>(
SelectHoldBillController(),
);
await holdBillC.getHoldBillList(isLoading: true);
final width = Get.context!.width;
final height = Get.context!.height;
final dialogWidth = width * 0.9;
final dialogHeight = height * 0.7;
return showDialog<OrderHoldBillEntity?>(
context: context,
barrierDismissible: true,
builder: (BuildContext _) {
return FDialog(
title: Text(
"挂单列表",
style: theme.typography.lg,
).marginOnly(bottom: 20.h),
style: theme.dialogStyle.copyWith(
insetPadding: EdgeInsets.zero,
maxWidth: dialogWidth,
minWidth: dialogWidth,
horizontalStyle: theme.dialogStyle.horizontalStyle.copyWith(
padding: EdgeInsets.all(20.w),
),
),
body: <Widget>[
_buildHoldBillSearch(context),
_buildHoldBillList(context).expanded(),
Obx(
() => appPage(
context,
pageNo: holdBillC.currentPage.value,
pageSize: holdBillC.pageSize.value,
total: holdBillC.totalPage.value,
onPageChanged: (pageNo) => holdBillC.doPage(page: pageNo),
),
)
].toColumn().width(double.infinity).height(dialogHeight),
actions: [
<Widget>[
FButton(
label: Text(
'确定',
style: theme.typography.base.copyWith(
color: theme.colorScheme.secondary,
),
),
onPress: () {
final holdBillC = Get.find<SelectHoldBillController>();
final selected = holdBillC.holdBillList.firstWhereOrNull(
(v) => v.id == holdBillC.selectedId.value,
);
if (selected == null) {
EasyLoading.showInfo("请先选择一条挂单");
return;
}
Get.back(result: selected);
},
).flexible(flex: 1),
SizedBox(width: 10.w),
FButton(
style: FButtonStyle.outline,
label: Text('取消', style: theme.typography.base),
onPress: () => Get.back(result: null),
).flexible(flex: 1),
].toRow()
],
);
},
);
}
Widget _buildHoldBillSearch(BuildContext context) {
final holdBillC = Get.find<SelectHoldBillController>();
return <Widget>[
const Spacer(),
Obx(
() => appDatePicker(
context,
datetimeRange: holdBillC.selectDateTime,
onChnage: (dateList) => holdBillC.doDateRangeDate(dateList),
).width(400.w).marginOnly(right: 15.w),
),
].toRow();
}
Widget _buildHoldBillList(BuildContext context) {
final theme = FTheme.of(context);
final holdBillC = Get.find<SelectHoldBillController>();
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final width = constraints.maxWidth;
// 计算列可用总宽度 = 父容器宽度 - 左右边距 - 每列之间的间距
const int colCount = 4;
final double spacing = 12.w; // columnSpacing
final double marginH = 12.w; // horizontalMargin
final double totalColAvailableWidth =
width - 2 * marginH - spacing * (colCount - 1);
final hdWidth = totalColAvailableWidth / colCount;
final height = constraints.maxHeight;
final hdHeight = (height - 60.h) / 5;
return Obx(
() => DataTable2(
columnSpacing: 12.w,
horizontalMargin: 12.w,
minWidth: 600.w,
showBottomBorder: true,
headingTextStyle: theme.typography.lg,
dataTextStyle: theme.typography.base,
dataRowHeight: hdHeight,
columns: [
DataColumn2(
label: Text("购物车", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth * 1.7,
),
DataColumn2(
label: Text("价格", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth * 0.8,
),
DataColumn2(
label: Text("挂单时间", textAlign: TextAlign.center),
headingRowAlignment: MainAxisAlignment.center,
fixedWidth: hdWidth,
),
],
rows: holdBillC.holdBillList.map((e) {
final carList = (jsonDecode(e.carListJson ?? '[]') as List)
.map((v) => ShopCardEntity.fromJson(v as Map<String, dynamic>))
.toList();
return DataRow(
selected: holdBillC.selectedId.value == e.id,
onSelectChanged: (selected) {
if (selected == true) {
holdBillC.selectedId.value = e.id;
}
},
color: WidgetStateProperty.resolveWith<Color?>((states) {
if (states.contains(WidgetState.selected)) {
return theme.colorScheme.secondary.withAlpha(24);
}
if (states.contains(WidgetState.hovered)) {
return theme.colorScheme.secondary.withAlpha(12);
}
return null;
}),
cells: [
DataCell(
GridView.builder(
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing: 5,
crossAxisSpacing: 5,
childAspectRatio: 30,
),
itemCount: carList.length,
itemBuilder: (context, i) {
final currentCar = carList[i];
return <Widget>[
Text(
"${currentCar.productName}(单价¥${AppPriceTool.fenToYuan(currentCar.productPrice)}) x ${currentCar.productNumber}",
textAlign: TextAlign.left,
style: theme.typography.sm,
),
Text("共", style: theme.typography.sm),
appPrice(
context,
currentCar.totalPrice,
textStyle: theme.typography.sm,
),
].toRow().marginOnly(left: 50.w);
},
),
),
DataCell(
GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing: 5,
crossAxisSpacing: 5,
childAspectRatio: 10,
),
itemCount: 3,
itemBuilder: (context, i) {
// 购物车总价
if (i == 0) {
return <Widget>[
Text(
"购物车总价:",
textAlign: TextAlign.left,
style: theme.typography.sm,
).flexible(flex: 1),
appPrice(
context,
e.price,
textStyle: theme.typography.sm,
).flexible(flex: 1),
].toRow();
}
// 额外价格
if (i == 1) {
return <Widget>[
Text(
"额外价格:",
textAlign: TextAlign.left,
style: theme.typography.sm,
).flexible(flex: 1),
appPrice(
context,
e.extraPrice,
textStyle: theme.typography.sm,
).flexible(flex: 1),
].toRow();
}
// 支付价格
if (i == 2) {
return <Widget>[
Text(
"支付价格:",
textAlign: TextAlign.left,
style: theme.typography.sm,
).flexible(flex: 1),
appPrice(
context,
e.payPrice,
textStyle: theme.typography.sm,
).flexible(flex: 1),
].toRow();
}
return SizedBox.shrink();
},
),
),
DataCell(
Text(
DateUtil.formatDate(
e.createTime,
format: DateFormats.full,
),
textAlign: TextAlign.center,
style: theme.typography.base,
).center(),
),
],
);
}).toList(),
),
);
},
);
}
+1 -1
View File
@@ -221,7 +221,7 @@ class OrderHistoryController extends GetxController {
Toast.error(msg: "超过4个小时不能退款");
return;
}
final price = AppriceTool.fenToYuan(v.payPrice);
final price = AppPriceTool.fenToYuan(v.payPrice);
refundDialog(
Get.context!,
title: "是否退还${v.username}用户的$price元",
+40 -3
View File
@@ -1,4 +1,5 @@
import 'package:common_utils/common_utils.dart';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_subscreen_plugin/flutter_subscreen_plugin.dart';
@@ -121,10 +122,46 @@ class SupermarketOrderController extends GetxController with OrderMixin {
// 更多 start
// **************************************************************************
// 加入挂单
Future<void> addHoldBill() async {}
Future<void> addHoldBill() async {
final validShopCar = _validateShopCar();
if (!validShopCar) return;
// 加入挂单数据库
final holdBillDao = appC.dataBase.getOrderHoldBillDao;
final holdBill = OrderHoldBillEntity(
sysType: SysType.SUPERMARKET,
carListJson: jsonEncode(
shopCardList.map((e) => e.toJson()).toList(),
),
userJson:
payUser.value != null ? jsonEncode(payUser.value!.toJson()) : null,
price: totalPrice.value,
extraPrice: amountMealPrice.value,
payPrice: totalPrice.value,
createTime: DateTime.now(),
);
await holdBillDao.save(holdBill);
Toast.success(msg: "已加入挂单列表");
TtsManage.speak("已加入挂单列表");
}
// 挂单列表
Future<void> holdBillList() async {}
Future<void> holdBillList() async {
final holdBill = await selectHoldBillDialog();
if (ObjectUtil.isEmpty(holdBill)) return;
// 清空状态
_clearShopCard();
// 使用挂单数据
final carList = (jsonDecode(holdBill?.carListJson ?? '[]') as List)
.map((v) => ShopCardEntity.fromJson(v as Map<String, dynamic>))
.toList();
if (!ObjectUtil.isEmptyList(carList)) {
shopCardList.addAll(carList);
}
totalPrice.value = holdBill?.price ?? 0;
amountMealPrice.value = holdBill?.extraPrice ?? 0;
computedTotalPrice(isSendSubScreen: false);
sendSubScreen();
}
// **************************************************************************
// 更多 end
// **************************************************************************
@@ -317,7 +354,7 @@ class SupermarketOrderController extends GetxController with OrderMixin {
final validShopCar = _validateShopCar();
if (!validShopCar) return;
// 总金额
final price = AppriceTool.fenToYuan(totalPrice.value);
final price = AppPriceTool.fenToYuan(totalPrice.value);
await createSqlOrder();
await updateSqlOrder();
_clearShopCard();