diff --git a/lib/common/routers/pages.dart b/lib/common/routers/pages.dart index c51e1bd..09aacec 100644 --- a/lib/common/routers/pages.dart +++ b/lib/common/routers/pages.dart @@ -36,6 +36,7 @@ class RoutePages { binding: BindingsBuilder(() { Get.lazyPut(() => SelectPayTypeDialogController()); Get.lazyPut(() => PanelController()); + Get.lazyPut(() => SteelyardController()); Get.lazyPut(() => SupermarketOrderController()); }), ), diff --git a/lib/common/widgets/order/order_common.dart b/lib/common/widgets/order/order_common.dart index 3402419..337bf29 100644 --- a/lib/common/widgets/order/order_common.dart +++ b/lib/common/widgets/order/order_common.dart @@ -59,9 +59,11 @@ Widget orderAllPrice( /// 商品选择面板 Widget orderSelectPanel( BuildContext context, { - void Function(int, int)? onChange, + void Function(int, int)? onPlusChange, + void Function(double, int)? onWidgetChange, String label = "", int total = 1, + double widget = 0, num price = 0, int index = 0, double height = 50, @@ -79,48 +81,80 @@ Widget orderSelectPanel( overflow: TextOverflow.ellipsis, style: theme.typography.lg, ).width(maxWidth * 0.4), - [ - appPrice(context, price), - SizedBox(width: 10.w), - FIcon( - FAssets.icons.plus, - color: theme.colorScheme.secondary, - ) - .width(height.w) - .height(double.infinity) - .decorated(color: theme.colorScheme.primary) - .onTap(() { - if (total < 100) { - if (onChange != null) { - onChange(total + 1, index); - } - } - }), - Text( - total.toString(), - style: theme.typography.lg, - ).center().width(60.w).height(double.infinity).decorated( - color: theme.colorScheme.secondary, - borderRadius: theme.style.borderRadius / 2, - ), - FIcon( - FAssets.icons.minus, - color: theme.colorScheme.secondary, - ) - .width(height.w) - .height(double.infinity) - .decorated(color: theme.colorScheme.error) - .onTap(() { - if (total > 0) { - if (onChange != null) { - onChange(total - 1, index); - } - } - }), - ] - .toRow(mainAxisAlignment: MainAxisAlignment.end) - .expanded() - .offstage(offstage: !showPlus), + showPlus + ? [ + appPrice(context, price), + SizedBox(width: 10.w), + FIcon( + FAssets.icons.plus, + color: theme.colorScheme.secondary, + ) + .width(height.w) + .height(double.infinity) + .decorated(color: theme.colorScheme.primary) + .onTap( + () { + if (total < 100) { + if (onPlusChange != null) { + onPlusChange(total + 1, index); + } + } + }, + ), + Text( + total.toString(), + style: theme.typography.lg, + ).center().width(60.w).height(double.infinity).decorated( + color: theme.colorScheme.secondary, + borderRadius: theme.style.borderRadius / 2, + ), + FIcon( + FAssets.icons.minus, + color: theme.colorScheme.secondary, + ) + .width(height.w) + .height(double.infinity) + .decorated(color: theme.colorScheme.error) + .onTap( + () { + if (total > 0) { + if (onPlusChange != null) { + onPlusChange(total - 1, index); + } + } + }, + ), + ].toRow(mainAxisAlignment: MainAxisAlignment.end).expanded() + : const SizedBox.shrink(), + showWidget + ? [ + Text( + "称重", + style: theme.typography.base.copyWith( + height: 1, + color: theme.colorScheme.secondary, + ), + ) + .center() + .width(height.w * 1.5) + .height(double.infinity) + .decorated(color: theme.colorScheme.primary) + .onTap( + () { + if (onWidgetChange != null) { + onWidgetChange(widget, index); + } + }, + ), + Text( + "${widget.toString()} / kg", + style: theme.typography.lg, + ).center().width(120.w).height(double.infinity).decorated( + color: theme.colorScheme.secondary, + borderRadius: theme.style.borderRadius / 2, + ), + ].toRow(mainAxisAlignment: MainAxisAlignment.end).expanded() + : const SizedBox.shrink(), ] .toRow(mainAxisAlignment: MainAxisAlignment.center) .height(height.h) diff --git a/lib/common/widgets/order/steelyard_container.dart b/lib/common/widgets/order/steelyard_container.dart index 1351aa4..f2d404d 100644 --- a/lib/common/widgets/order/steelyard_container.dart +++ b/lib/common/widgets/order/steelyard_container.dart @@ -1,4 +1,6 @@ import 'package:common_utils/common_utils.dart'; +import 'package:ducafe_ui_core/ducafe_ui_core.dart'; +import 'package:forui/forui.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:pj_supermarket_cloud/common/index.dart'; @@ -22,7 +24,7 @@ class SteelyardController extends GetxController { final app = Get.find(); // 称重商品 - Rxn _widgetProduct = Rxn(null); + SupermarketSpuEntity? _widgetProduct = null; // 重量 RxDouble widget = RxDouble(0); @@ -65,7 +67,7 @@ class SteelyardController extends GetxController { } // 打开称重 - bool open(CanteenSpuEntity current) { + bool open(SupermarketSpuEntity current) { final isOpen = _openSerial(); if (!isOpen) { _closeStatus(); @@ -73,7 +75,7 @@ class SteelyardController extends GetxController { } _closeStatus(); logger.i("|$_tag|称重,商品uniqueCode:|${current.serviceUniqueCode}|"); - _widgetProduct.value = current; + _widgetProduct = current; return true; } @@ -84,7 +86,7 @@ class SteelyardController extends GetxController { // 清除状态 _closeStatus() { - _widgetProduct.value = null; + _widgetProduct = null; widget.value = 0; callbackWidget.value = 0; price.value = 0; @@ -127,16 +129,77 @@ class SteelyardController extends GetxController { interval( callbackWidget, (callback) { - if (_widgetProduct.value != null) { + if (_widgetProduct != null) { widget.value = callbackWidget.value; final p = - callbackWidget.value * _widgetProduct.value!.price / 100 * 100; + callbackWidget.value * _widgetProduct!.retailPrice / 100 * 100; price.value = int.parse(p.toStringAsFixed(2)); logger.i( - "|$_tag|称重,重量:|${widget.value}|;价格:|${_widgetProduct.value!.price}|"); + "|$_tag|称重,重量:|${widget.value}|;价格:|${_widgetProduct!.retailPrice}|"); } }, time: const Duration(seconds: 1), ); } } + +Widget steelyardEmpty(BuildContext context) { + final theme = FTheme.of(context); + return [ + [ + FIcon( + FAssets.icons.layers, + size: theme.typography.xl2.fontSize, + ), + SizedBox(width: 10.w), + Text( + "请将商品放置到电子称中,点击开始称重", + style: theme.typography.xl, + ), + ].toRow(mainAxisAlignment: MainAxisAlignment.center), + SizedBox(height: 10.w), + Text( + "注意:请将电子称上的物品全部清空再点击开始称重", + style: theme.typography.base, + ), + ].toColumn(mainAxisAlignment: MainAxisAlignment.center); +} + +Widget steelyardContainer(BuildContext context) { + final theme = FTheme.of(context); + final textStyle = theme.typography.xl.copyWith( + color: theme.colorScheme.secondary, + ); + const textWidth = 180; + return GetBuilder(builder: (controller) { + return [ + Visibility( + visible: controller.isWidget.value, + replacement: steelyardEmpty(context), + child: steelyardEmpty(context), + ).expanded(), + SizedBox(height: 100.h), + [ + FButton( + label: Text("开始称重", style: textStyle), + onPress: () => controller.weightStartCallback(), + ).width(textWidth.w), + FButton( + label: Text("确定重量", style: textStyle), + onPress: () => controller.weightSubmitCallback(), + ).width(textWidth.w), + FButton( + style: FButtonStyle.destructive, + label: Text("取消", style: textStyle), + onPress: () => controller.weightCancelCallback(), + ).width(textWidth.w), + ] + .toRowSpace( + space: 30.w, + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.center, + ) + .marginOnly(top: 20.h), + ].toColumn(mainAxisAlignment: MainAxisAlignment.center); + }); +} diff --git a/lib/pages/canteen_product/view.dart b/lib/pages/canteen_product/view.dart index 084cbe7..abc3dc6 100644 --- a/lib/pages/canteen_product/view.dart +++ b/lib/pages/canteen_product/view.dart @@ -175,7 +175,7 @@ class CanteenProductPage extends GetView { total: current.productNumber, index: index, showPlus: true, - onChange: (number, i) => + onPlusChange: (number, i) => controller.doComputedInputChange(number, i), ).marginOnly(bottom: 10.h); }, diff --git a/lib/pages/supermarket_order/controller.dart b/lib/pages/supermarket_order/controller.dart index 92c93a6..fd67a64 100644 --- a/lib/pages/supermarket_order/controller.dart +++ b/lib/pages/supermarket_order/controller.dart @@ -17,6 +17,9 @@ class SupermarketOrderController extends GetxController with OrderMixin { late SysSetting appSetting; + // 称重商品 + Rxn widgetProduct = Rxn(null); + _initData() { update(["supermarket_order"]); } @@ -132,6 +135,29 @@ class SupermarketOrderController extends GetxController with OrderMixin { sendSubScreen(); } + // |购买商品|点击称重 + void computedPanelWidget(double widget, int i) { + final current = shopCardList[i]; + final targetProduct = supermarketSpuList.firstWhereOrNull((e) { + return e.serviceUniqueCode == current.productServiceUniqueCode; + }); + if (targetProduct == null) return; + if (widgetProduct.value != null) { + if (widgetProduct.value!.serviceUniqueCode == + current.productServiceUniqueCode) { + Toast.error(msg: "该商品已在称重"); + return; + } + } + final supermarketC = Get.find(); + final isOpen = supermarketC.open(targetProduct); + if (!isOpen) { + Toast.error(msg: "连接电子称错误"); + return; + } + widgetProduct.value = targetProduct; + } + void _listenPayTypeSelectCallback() { final payTypeSelect = Get.find(); // |支付方式|点击|开始识别| diff --git a/lib/pages/supermarket_order/view.dart b/lib/pages/supermarket_order/view.dart index bb98123..61f945e 100644 --- a/lib/pages/supermarket_order/view.dart +++ b/lib/pages/supermarket_order/view.dart @@ -228,8 +228,10 @@ class SupermarketOrderPage extends GetView { index: index, showPlus: current.nature == ProductNature.DEFAULT, showWidget: current.nature == ProductNature.WEIGHT, - onChange: (number, i) => + onPlusChange: (number, i) => controller.doComputedInputChange(number, i), + onWidgetChange: (widget, i) => + controller.computedPanelWidget(widget, i), ).marginOnly(bottom: 10.h); }, ), @@ -280,9 +282,13 @@ class SupermarketOrderPage extends GetView { final width = context.width; final theme = FTheme.of(context); return [ - SizedBox(width: 15.w), - _buildProductArea(context).expanded(), - SizedBox(width: 15.w), + Obx( + () => Visibility( + visible: controller.widgetProduct.value != null, + replacement: steelyardContainer(context), + child: _buildProductArea(context), + ), + ).marginSymmetric(horizontal: 15.w).expanded(), _buildUser().width(width * 0.25).decorated( border: Border.all( color: theme.colorScheme.primary,