Browse Source

safety

master
fmk 3 years ago
parent
commit
8f897411c7
  1. 52
      lib/store/store_order.dart
  2. 76
      lib/store/store_view/shop_car.dart
  3. 23
      lib/store/store_view/shop_goods.dart
  4. 14
      lib/store/store_view/store_order_list.dart

52
lib/store/store_order.dart

@ -53,7 +53,6 @@ class _StoreOrderPage extends State<StoreOrderPage>
double allPrice = 0;
StoreOrderListPage storeOrderListPage;
List<ProductListBean> productLists = [];
List<Map<String, dynamic>> shopCarGoods = [];
ScrollController controller = ScrollController();
@ -310,6 +309,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
shopCarGoods,
controller,
_queryMiNiDetail,
_productListResult,
_fc,
),
@ -450,20 +450,26 @@ class _StoreOrderPage extends State<StoreOrderPage>
);
}
List<FindMiNiGroupList> appletProducts = [];
_productListResult(List<FindMiNiGroupList> appletProducts) {
this.appletProducts = appletProducts;
}
///
showShoppingCart() {
if (appletProducts == null || appletProducts.length == 0) return;
List<ProductListBean> shopCar = [];
if (shopCarGoods != null && shopCarGoods.length > 0) {
shopCarGoods.forEach((element) {
ProductListBean productListBean = productLists.firstWhere((element1) {
return element["id"] == element1.id;
});
if (productListBean != null) {
shopCar.add(productListBean);
appletProducts.forEach((element1) {
element1.productList.forEach((element2) {
if (element["id"] == element2.id) {
shopCar.add(element2);
}
});
});
});
}
showModalBottomSheet(
@ -473,11 +479,8 @@ class _StoreOrderPage extends State<StoreOrderPage>
return ShopCar(
shopCar,
shopCarGoods,
clearShopCar,
(int count, String productId, allCount, allPrice) {
if (count == 0) {
int index = shopCarGoods.indexWhere((element) => element["id"] == productId);
shopCarGoods.removeAt(index);
}
print("shopCarCount: $allCount allPrice: $allPrice ");
setState(() {
this.allCount = allCount;
@ -489,6 +492,14 @@ class _StoreOrderPage extends State<StoreOrderPage>
);
}
///
clearShopCar() {
if (shopCarGoods != null)
shopCarGoods.clear();
calculatePrice();
setState(() {});
}
///
_queryMiNiDetail(String id) async {
BaseData<MiNiDetail> baseData = await minService.miNiDetail(id);
@ -529,7 +540,6 @@ class _StoreOrderPage extends State<StoreOrderPage>
map = element;
}
});
print("result000: $map");
if (map != null) {
int index = shopCarGoods.indexWhere((element) => element["id"] == result["id"]);
shopCarGoods.removeAt(index);
@ -540,11 +550,25 @@ class _StoreOrderPage extends State<StoreOrderPage>
}
calculatePrice();
}
print("result111: $shopCarGoods");
}
calculatePrice() {
AiDecimalAccuracy allPriceDecimal = AiDecimalAccuracy.zero;
int allCount = 0;
shopCarGoods.forEach((element2) {
if (element2["price"] != null && element2["price"] != "") {
double singlePrice = double.tryParse(element2["price"]);
allCount += element2["count"];
AiDecimalAccuracy aiDecimalAccuracy = AiDecimalAccuracy.fromInt(element2["count"]);
AiDecimalAccuracy aiPrice = AiDecimalAccuracy.tryParse("$singlePrice");
allPriceDecimal += (aiPrice * aiDecimalAccuracy);
}
});
this.allCount = allCount;
this.allPrice = allPriceDecimal.toDouble();
setState(() {});
}

76
lib/store/store_view/shop_car.dart

@ -1,7 +1,7 @@
import 'package:ai_decimal_accuracy/ai_decimal_accuracy.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/retrofit/data/order_info.dart';
import 'package:huixiang/store/store_view/shop_goods.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/round_button.dart';
@ -10,6 +10,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
class ShopCar extends StatefulWidget {
final List<ProductListBean> productLists;
final Function(String id) queryMiNiDetail;
final Function() clearShopCar;
final List<Map<String, dynamic>> shopCarGoods;
final Function(int count, String productId, int allCount, double allPrice) fc;
@ -17,11 +18,10 @@ class ShopCar extends StatefulWidget {
ShopCar(
this.productLists,
this.shopCarGoods,
this.fc,
{
this.clearShopCar,
this.fc, {
this.queryMiNiDetail,
}
);
});
@override
State<StatefulWidget> createState() {
@ -30,17 +30,39 @@ class ShopCar extends StatefulWidget {
}
class _ShopCar extends State<ShopCar> {
int allCount;
double allPrice;
int allCount = 0;
double allPrice = 0.0;
final List<Map<String, dynamic>> shopCarGoods;
_ShopCar(this.shopCarGoods);
@override
void initState() {
super.initState();
if (shopCarGoods != null) {
AiDecimalAccuracy allPriceDecimal = AiDecimalAccuracy.zero;
shopCarGoods.forEach((element) {
if (element["price"] != null && element["price"] != "") {
double singlePrice = double.tryParse(element["price"]);
allCount += element["count"];
AiDecimalAccuracy aiDecimalAccuracy = AiDecimalAccuracy.fromInt(element["count"]);
AiDecimalAccuracy aiPrice = AiDecimalAccuracy.tryParse("$singlePrice");
allPriceDecimal += (aiPrice * aiDecimalAccuracy);
}
});
allPrice = allPriceDecimal.toDouble();
}
}
@override
Widget build(BuildContext context) {
return StatefulBuilder(builder: (context1, state) {
return StatefulBuilder(
builder: (context1, state) {
return Container(
alignment: Alignment.topCenter,
width: double.infinity,
@ -77,7 +99,7 @@ class _ShopCar extends State<ShopCar> {
),
InkWell(
onTap: () {
state(() {});
widget.clearShopCar();
},
child: Image.asset(
"assets/image/delete.png",
@ -97,7 +119,8 @@ class _ShopCar extends State<ShopCar> {
),
child: ListView.builder(
itemCount: widget.productLists == null
? 0 : widget.productLists.length,
? 0
: widget.productLists.length,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
@ -108,14 +131,27 @@ class _ShopCar extends State<ShopCar> {
int index = shopCarGoods.indexWhere((element) => element["id"] == productId);
if (count == 0) {
shopCarGoods.removeAt(index);
int index1 = widget.productLists.indexWhere((element) => element.id == productId);
widget.productLists.removeAt(index1);
} else {
Map<String, dynamic> map;
print("productId: $productId");
shopCarGoods.forEach((element) {
if (element["id"] == productId) {
map = element;
}
Map<String, dynamic> map = shopCarGoods.firstWhere((element) => element["id"] == productId);
});
map["count"] = count;
shopCarGoods[index] = map;
}
allCount = 0;
allPrice = 0;
shopCarGoods.forEach((element) {
if (element["price"] != null && element["price"] != "") {
double singlePrice = double.tryParse(element["price"]);
if (element["price"] != null &&
element["price"] != "") {
double singlePrice =
double.tryParse(element["price"]);
allCount += element["count"];
allPrice += (singlePrice * element["count"]);
}
@ -216,7 +252,8 @@ class _ShopCar extends State<ShopCar> {
fontSize: 12.sp,
radius: 100,
callback: () {
Navigator.of(context).pushNamed('/router/test_page');
Navigator.of(context)
.pushNamed('/router/test_page');
},
),
),
@ -227,16 +264,17 @@ class _ShopCar extends State<ShopCar> {
],
),
);
});
},
);
}
Map<String, dynamic> _shopCarGoods(int position) {
Map<String, dynamic> map;
widget.shopCarGoods.forEach((element) {
if (widget.productLists[position].id == element["id"]) {
return element;
map = element;
}
});
return null;
return map;
}
}

23
lib/store/store_view/shop_goods.dart

@ -7,13 +7,13 @@ import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/round_button.dart';
class ShopGoods extends StatefulWidget {
final ProductListBean productList;
final ProductListBean product;
final Function(String id) queryMiNiDetail;
final Function(int count, String productId) fc;
final Map<String, dynamic> shopCarGoods;
ShopGoods(
this.productList,
this.product,
this.fc, {
this.queryMiNiDetail,
this.shopCarGoods,
@ -30,7 +30,6 @@ class _ShopGoods extends State<ShopGoods> {
@override
Widget build(BuildContext context) {
int buyNum = _count();
print("result:11 $buyNum");
return Container(
color: Colors.white,
padding: EdgeInsets.only(
@ -44,7 +43,7 @@ class _ShopGoods extends State<ShopGoods> {
children: [
SizedBox(width: 12.w),
MImage(
widget.productList != null ? widget.productList.imgPath : "",
widget.product != null ? widget.product.imgPath : "",
width: 70,
height: 70,
fit: BoxFit.cover,
@ -59,7 +58,7 @@ class _ShopGoods extends State<ShopGoods> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.productList.productName,
widget.product.productName,
style: TextStyle(
color: Colors.black,
fontSize: 13.sp,
@ -73,7 +72,7 @@ class _ShopGoods extends State<ShopGoods> {
children: [
Expanded(
child: Text(
widget.productList.shortName,
widget.product.shortName,
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(
@ -110,7 +109,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4,
),
Text(
"¥${widget.productList.price}",
"¥${widget.product.price}",
style: TextStyle(
color: Color(0xFFFF7A1A),
fontSize: 11.sp,
@ -133,7 +132,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4,
),
Text(
"¥${widget.productList.applyPrice}",
"¥${widget.product.applyPrice}",
style: TextStyle(
color: Color(0xFFA29E9E),
fontSize: 10.sp,
@ -156,14 +155,14 @@ class _ShopGoods extends State<ShopGoods> {
fontSize: 11.sp,
padding: EdgeInsets.symmetric(vertical: 5.h),
callback: () {
widget.queryMiNiDetail(widget.productList.id);
widget.queryMiNiDetail(widget.product.id);
},
),
if (buyNum > 0)
InkWell(
onTap: () {
reduceCount();
widget.fc(widget.shopCarGoods["count"], widget.productList.id);
widget.fc(widget.shopCarGoods["count"], widget.product.id);
setState(() {});
},
child: Image.asset(
@ -189,7 +188,7 @@ class _ShopGoods extends State<ShopGoods> {
InkWell(
onTap: () {
addCount();
widget.fc(widget.shopCarGoods["count"], widget.productList.id);
widget.fc(widget.shopCarGoods["count"], widget.product.id);
setState(() {});
},
child: Image.asset(
@ -219,7 +218,7 @@ class _ShopGoods extends State<ShopGoods> {
int _count() {
if (widget.shopCarGoods == null) return 0;
if (widget.productList.id == widget.shopCarGoods["id"]) {
if (widget.product.id == widget.shopCarGoods["id"]) {
return widget.shopCarGoods["count"];
}

14
lib/store/store_view/store_order_list.dart

@ -19,6 +19,7 @@ class StoreOrderListPage extends StatefulWidget {
final ScrollController controller;
final Function(int count, String productId, int allCount, double allPrice) fc;
final Function(String id) queryMiNiDetail;
final Function(List<FindMiNiGroupList> appletProducts) productListResult;
List<Map<String, dynamic>> shopCarGoods;
StoreOrderListPage(
@ -28,6 +29,7 @@ class StoreOrderListPage extends StatefulWidget {
this.shopCarGoods,
this.controller,
this.queryMiNiDetail,
this.productListResult,
this.fc
);
@ -47,17 +49,6 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
List<FindMiNiGroupList> appletProducts;
List<ProductListBean> productListBeans = [];
void notifyList(List<ProductListBean> product){
setState(() {
product.forEach((e0) {
productListBeans.forEach((e1) {
if(e0.id == e1.id)
e1.buyNum = e0.buyNum;
});
});
});
}
@override
void initState() {
super.initState();
@ -87,6 +78,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
if (baseData != null && baseData.isSuccess) {
setState(() {
appletProducts = baseData.data;
widget.productListResult(appletProducts);
productListBeans.clear();
if (appletProducts.length > 0)
productListBeans.addAll(appletProducts[0].productList);

Loading…
Cancel
Save