feat:数量和重量商品库存分别计算

This commit is contained in:
dzc committed 2025-03-19 15:02:36 +08:00
1 parent 38d2ec2292
commit ecf4c32ca6
2 files changed
+24 -29

No files matched your search

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:common_utils/common_utils.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
@@ -36,14 +38,9 @@ class SteelyardController extends GetxController {
// 价格
RxInt price = RxInt(0);
// 在误差之内的重量
int _stableCount = 0;
// 上一下的重量
double _lastWeight = 0;
// 波动范围
static const double _weightTolerance = 0.05;
// 稳定次数
static const int _requiredStableCount = 3;
// 添加计时器
Timer? _noUpdateTimer;
static const _timeoutDuration = Duration(seconds: 3);
// 点击|开始称重|
void weightStartCallback() {
@@ -110,8 +107,6 @@ class SteelyardController extends GetxController {
widget.value = 0;
callbackWidget.value = 0;
price.value = 0;
_stableCount = 0;
_lastWeight = 0;
}
// 打开称串口
@@ -157,19 +152,16 @@ class SteelyardController extends GetxController {
final productPrice = _getProudctPrice(_product!);
final p = (callbackWidget.value * productPrice).ceil();
price.value = p;
if ((widget.value - _lastWeight).abs() <= _weightTolerance) {
_stableCount++;
if (_stableCount >= _requiredStableCount) {
weightSubmitCallback();
return;
}
} else {
_stableCount = 0;
}
_lastWeight = widget.value;
logger.i(
"|$_tag|重量|${widget.value}|单价|$productPrice|总价|${price.value}|稳定次数|$_stableCount|",
"|$_tag|重量|${widget.value}|单价|$productPrice|总价|${price.value}|",
);
// 重置超时计时器
_noUpdateTimer?.cancel();
_noUpdateTimer = Timer(_timeoutDuration, () {
if (widget.value > 0) {
weightSubmitCallback();
}
});
},
time: const Duration(milliseconds: 100),
);
+11 -8
View File
@@ -350,17 +350,20 @@ class SupermarketOrderController extends GetxController with OrderMixin {
// 校验购物车
bool _validateShopCar() {
bool flag = false;
bool flag = true;
for (final v in shopCardList) {
if (v.productNumber > 0) {
flag = true;
break;
if (v.nature == ProductNature.DEFAULT) {
if (v.productNumber <= 0) {
Toast.error(msg: "校验购物车失败,未选择商品");
return false;
}
} else if (v.nature == ProductNature.WEIGHT) {
if (v.productWidget <= 0) {
Toast.error(msg: "校验购物车失败,商品未称重");
return false;
}
}
}
if (!flag) {
Toast.error(msg: "校验购物车失败,未选择商品");
return false;
}
return flag;
}