Browse Source

safety

master
fmk 3 years ago
parent
commit
8f897411c7
  1. 52
      lib/store/store_order.dart
  2. 394
      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; double allPrice = 0;
StoreOrderListPage storeOrderListPage; StoreOrderListPage storeOrderListPage;
List<ProductListBean> productLists = [];
List<Map<String, dynamic>> shopCarGoods = []; List<Map<String, dynamic>> shopCarGoods = [];
ScrollController controller = ScrollController(); ScrollController controller = ScrollController();
@ -310,6 +309,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
shopCarGoods, shopCarGoods,
controller, controller,
_queryMiNiDetail, _queryMiNiDetail,
_productListResult,
_fc, _fc,
), ),
@ -450,19 +450,25 @@ class _StoreOrderPage extends State<StoreOrderPage>
); );
} }
List<FindMiNiGroupList> appletProducts = [];
_productListResult(List<FindMiNiGroupList> appletProducts) {
this.appletProducts = appletProducts;
}
/// ///
showShoppingCart() { showShoppingCart() {
if (appletProducts == null || appletProducts.length == 0) return;
List<ProductListBean> shopCar = []; List<ProductListBean> shopCar = [];
if (shopCarGoods != null && shopCarGoods.length > 0) { if (shopCarGoods != null && shopCarGoods.length > 0) {
shopCarGoods.forEach((element) { shopCarGoods.forEach((element) {
ProductListBean productListBean = productLists.firstWhere((element1) { appletProducts.forEach((element1) {
return element["id"] == element1.id; element1.productList.forEach((element2) {
if (element["id"] == element2.id) {
shopCar.add(element2);
}
});
}); });
if (productListBean != null) {
shopCar.add(productListBean);
}
}); });
} }
@ -473,11 +479,8 @@ class _StoreOrderPage extends State<StoreOrderPage>
return ShopCar( return ShopCar(
shopCar, shopCar,
shopCarGoods, shopCarGoods,
clearShopCar,
(int count, String productId, allCount, allPrice) { (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 "); print("shopCarCount: $allCount allPrice: $allPrice ");
setState(() { setState(() {
this.allCount = allCount; this.allCount = allCount;
@ -489,6 +492,14 @@ class _StoreOrderPage extends State<StoreOrderPage>
); );
} }
///
clearShopCar() {
if (shopCarGoods != null)
shopCarGoods.clear();
calculatePrice();
setState(() {});
}
/// ///
_queryMiNiDetail(String id) async { _queryMiNiDetail(String id) async {
BaseData<MiNiDetail> baseData = await minService.miNiDetail(id); BaseData<MiNiDetail> baseData = await minService.miNiDetail(id);
@ -529,7 +540,6 @@ class _StoreOrderPage extends State<StoreOrderPage>
map = element; map = element;
} }
}); });
print("result000: $map");
if (map != null) { if (map != null) {
int index = shopCarGoods.indexWhere((element) => element["id"] == result["id"]); int index = shopCarGoods.indexWhere((element) => element["id"] == result["id"]);
shopCarGoods.removeAt(index); shopCarGoods.removeAt(index);
@ -540,11 +550,25 @@ class _StoreOrderPage extends State<StoreOrderPage>
} }
calculatePrice(); calculatePrice();
} }
print("result111: $shopCarGoods");
} }
calculatePrice() { 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(() {}); setState(() {});
} }

394
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:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.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/store/store_view/shop_goods.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
@ -10,6 +10,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
class ShopCar extends StatefulWidget { class ShopCar extends StatefulWidget {
final List<ProductListBean> productLists; final List<ProductListBean> productLists;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function() clearShopCar;
final List<Map<String, dynamic>> shopCarGoods; final List<Map<String, dynamic>> shopCarGoods;
final Function(int count, String productId, int allCount, double allPrice) fc; final Function(int count, String productId, int allCount, double allPrice) fc;
@ -17,11 +18,10 @@ class ShopCar extends StatefulWidget {
ShopCar( ShopCar(
this.productLists, this.productLists,
this.shopCarGoods, this.shopCarGoods,
this.fc, this.clearShopCar,
{ this.fc, {
this.queryMiNiDetail, this.queryMiNiDetail,
} });
);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -30,213 +30,251 @@ class ShopCar extends StatefulWidget {
} }
class _ShopCar extends State<ShopCar> { class _ShopCar extends State<ShopCar> {
int allCount = 0;
int allCount; double allPrice = 0.0;
double allPrice;
final List<Map<String, dynamic>> shopCarGoods; final List<Map<String, dynamic>> shopCarGoods;
_ShopCar(this.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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return StatefulBuilder(builder: (context1, state) { return StatefulBuilder(
return Container( builder: (context1, state) {
alignment: Alignment.topCenter, return Container(
width: double.infinity, alignment: Alignment.topCenter,
height: MediaQuery.of(context).size.height / 2, width: double.infinity,
decoration: BoxDecoration( height: MediaQuery.of(context).size.height / 2,
color: Colors.white, decoration: BoxDecoration(
borderRadius: BorderRadius.only( color: Colors.white,
topLeft: Radius.circular(8), borderRadius: BorderRadius.only(
topRight: Radius.circular(8), topLeft: Radius.circular(8),
), topRight: Radius.circular(8),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(
top: 16,
left: 16,
right: 16,
bottom: 8,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"已选商品",
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
),
),
InkWell(
onTap: () {
state(() {});
},
child: Image.asset(
"assets/image/delete.png",
width: 22,
height: 22,
),
),
],
),
), ),
Expanded( ),
child: Container( child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
top: 8, top: 16,
left: 16, left: 16,
right: 16, right: 16,
bottom: 8,
), ),
child: ListView.builder( child: Row(
itemCount: widget.productLists == null mainAxisAlignment: MainAxisAlignment.spaceBetween,
? 0 : widget.productLists.length, crossAxisAlignment: CrossAxisAlignment.start,
physics: BouncingScrollPhysics(), children: [
itemBuilder: (context, position) { Text(
return GestureDetector( "已选商品",
onTap: () {}, style: TextStyle(
child: ShopGoods( color: Colors.black,
widget.productLists[position], fontSize: 14.sp,
(int count, String productId) { fontWeight: MyFontWeight.medium,
int index = shopCarGoods.indexWhere((element) => element["id"] == productId); ),
if (count == 0) { ),
shopCarGoods.removeAt(index); InkWell(
} onTap: () {
Map<String, dynamic> map = shopCarGoods.firstWhere((element) => element["id"] == productId); widget.clearShopCar();
map["count"] = count; },
shopCarGoods[index] = map; child: Image.asset(
"assets/image/delete.png",
shopCarGoods.forEach((element) { width: 22,
if (element["price"] != null && element["price"] != "") { height: 22,
double singlePrice = double.tryParse(element["price"]); ),
allCount += element["count"]; ),
allPrice += (singlePrice * element["count"]); ],
),
),
Expanded(
child: Container(
padding: EdgeInsets.only(
top: 8,
left: 16,
right: 16,
),
child: ListView.builder(
itemCount: widget.productLists == null
? 0
: widget.productLists.length,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {},
child: ShopGoods(
widget.productLists[position],
(int count, String productId) {
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["count"] = count;
shopCarGoods[index] = map;
} }
});
widget.fc(count, productId, allCount, allPrice); allCount = 0;
allPrice = 0;
shopCarGoods.forEach((element) {
if (element["price"] != null &&
element["price"] != "") {
double singlePrice =
double.tryParse(element["price"]);
allCount += element["count"];
allPrice += (singlePrice * element["count"]);
}
});
state((){}); widget.fc(count, productId, allCount, allPrice);
},
shopCarGoods: _shopCarGoods(position), state(() {});
queryMiNiDetail: widget.queryMiNiDetail, },
), shopCarGoods: _shopCarGoods(position),
); queryMiNiDetail: widget.queryMiNiDetail,
}, ),
);
},
),
), ),
), ),
), Stack(
Stack( alignment: Alignment.bottomLeft,
alignment: Alignment.bottomLeft, children: [
children: [ Container(
Container( height: 54.h,
height: 54.h, decoration: BoxDecoration(
decoration: BoxDecoration( color: Color(0xFFFAFAFA),
color: Color(0xFFFAFAFA), boxShadow: [
boxShadow: [ BoxShadow(
BoxShadow( color: Colors.black.withAlpha(8),
color: Colors.black.withAlpha(8), offset: Offset(0, -1),
offset: Offset(0, -1), blurRadius: 3,
blurRadius: 3, spreadRadius: 0,
spreadRadius: 0,
),
],
),
child: Row(
children: [
Spacer(),
Text(
S.of(context).heji,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Colors.black,
), ),
), ],
Text( ),
"" + allPrice.toString(), child: Row(
style: TextStyle( children: [
fontSize: 20.sp, Spacer(),
fontWeight: MyFontWeight.medium, Text(
color: Color(0xFF32A060), S.of(context).heji,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Colors.black,
),
), ),
), Text(
Spacer(), "" + allPrice.toString(),
GestureDetector( style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF32A060),
),
),
Spacer(),
GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
'/router/settlement',
arguments: {},
);
},
child: RoundButton(
width: 103.w,
height: 54.h,
text: S.current.jiesuan,
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060),
radius: 0,
fontSize: 16.sp,
padding: EdgeInsets.symmetric(vertical: 5.h),
),
),
],
),
),
Stack(
children: [
InkWell(
onTap: () { onTap: () {
Navigator.of(context).pushNamed( Navigator.of(context).pop();
'/router/settlement',
arguments: {},
);
}, },
child: Image.asset(
"assets/image/shopp.png",
width: 88,
height: 88,
),
),
Positioned(
right: 15,
top: 14,
child: RoundButton( child: RoundButton(
width: 103.w, width: 17,
height: 54.h, height: 17,
text: S.current.jiesuan, text: allCount.toString(),
textColor: Colors.white, textColor: Colors.white,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060), backgroup: Color(0xFF32A060),
radius: 0, fontSize: 12.sp,
fontSize: 16.sp, radius: 100,
padding: EdgeInsets.symmetric(vertical: 5.h), callback: () {
Navigator.of(context)
.pushNamed('/router/test_page');
},
), ),
), ),
], ],
), ),
), ],
Stack( ),
children: [ ],
InkWell( ),
onTap: () { );
Navigator.of(context).pop(); },
}, );
child: Image.asset(
"assets/image/shopp.png",
width: 88,
height: 88,
),
),
Positioned(
right: 15,
top: 14,
child: RoundButton(
width: 17,
height: 17,
text: allCount.toString(),
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060),
fontSize: 12.sp,
radius: 100,
callback: () {
Navigator.of(context).pushNamed('/router/test_page');
},
),
),
],
),
],
),
],
),
);
});
} }
Map<String, dynamic> _shopCarGoods(int position) { Map<String, dynamic> _shopCarGoods(int position) {
Map<String, dynamic> map;
widget.shopCarGoods.forEach((element) { widget.shopCarGoods.forEach((element) {
if (widget.productLists[position].id == element["id"]) { 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'; import 'package:huixiang/view_widget/round_button.dart';
class ShopGoods extends StatefulWidget { class ShopGoods extends StatefulWidget {
final ProductListBean productList; final ProductListBean product;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(int count, String productId) fc; final Function(int count, String productId) fc;
final Map<String, dynamic> shopCarGoods; final Map<String, dynamic> shopCarGoods;
ShopGoods( ShopGoods(
this.productList, this.product,
this.fc, { this.fc, {
this.queryMiNiDetail, this.queryMiNiDetail,
this.shopCarGoods, this.shopCarGoods,
@ -30,7 +30,6 @@ class _ShopGoods extends State<ShopGoods> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
int buyNum = _count(); int buyNum = _count();
print("result:11 $buyNum");
return Container( return Container(
color: Colors.white, color: Colors.white,
padding: EdgeInsets.only( padding: EdgeInsets.only(
@ -44,7 +43,7 @@ class _ShopGoods extends State<ShopGoods> {
children: [ children: [
SizedBox(width: 12.w), SizedBox(width: 12.w),
MImage( MImage(
widget.productList != null ? widget.productList.imgPath : "", widget.product != null ? widget.product.imgPath : "",
width: 70, width: 70,
height: 70, height: 70,
fit: BoxFit.cover, fit: BoxFit.cover,
@ -59,7 +58,7 @@ class _ShopGoods extends State<ShopGoods> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
widget.productList.productName, widget.product.productName,
style: TextStyle( style: TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 13.sp, fontSize: 13.sp,
@ -73,7 +72,7 @@ class _ShopGoods extends State<ShopGoods> {
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
widget.productList.shortName, widget.product.shortName,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 2, maxLines: 2,
style: TextStyle( style: TextStyle(
@ -110,7 +109,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4, width: 4,
), ),
Text( Text(
"¥${widget.productList.price}", "¥${widget.product.price}",
style: TextStyle( style: TextStyle(
color: Color(0xFFFF7A1A), color: Color(0xFFFF7A1A),
fontSize: 11.sp, fontSize: 11.sp,
@ -133,7 +132,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4, width: 4,
), ),
Text( Text(
"¥${widget.productList.applyPrice}", "¥${widget.product.applyPrice}",
style: TextStyle( style: TextStyle(
color: Color(0xFFA29E9E), color: Color(0xFFA29E9E),
fontSize: 10.sp, fontSize: 10.sp,
@ -156,14 +155,14 @@ class _ShopGoods extends State<ShopGoods> {
fontSize: 11.sp, fontSize: 11.sp,
padding: EdgeInsets.symmetric(vertical: 5.h), padding: EdgeInsets.symmetric(vertical: 5.h),
callback: () { callback: () {
widget.queryMiNiDetail(widget.productList.id); widget.queryMiNiDetail(widget.product.id);
}, },
), ),
if (buyNum > 0) if (buyNum > 0)
InkWell( InkWell(
onTap: () { onTap: () {
reduceCount(); reduceCount();
widget.fc(widget.shopCarGoods["count"], widget.productList.id); widget.fc(widget.shopCarGoods["count"], widget.product.id);
setState(() {}); setState(() {});
}, },
child: Image.asset( child: Image.asset(
@ -189,7 +188,7 @@ class _ShopGoods extends State<ShopGoods> {
InkWell( InkWell(
onTap: () { onTap: () {
addCount(); addCount();
widget.fc(widget.shopCarGoods["count"], widget.productList.id); widget.fc(widget.shopCarGoods["count"], widget.product.id);
setState(() {}); setState(() {});
}, },
child: Image.asset( child: Image.asset(
@ -219,7 +218,7 @@ class _ShopGoods extends State<ShopGoods> {
int _count() { int _count() {
if (widget.shopCarGoods == null) return 0; if (widget.shopCarGoods == null) return 0;
if (widget.productList.id == widget.shopCarGoods["id"]) { if (widget.product.id == widget.shopCarGoods["id"]) {
return widget.shopCarGoods["count"]; 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 ScrollController controller;
final Function(int count, String productId, int allCount, double allPrice) fc; final Function(int count, String productId, int allCount, double allPrice) fc;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(List<FindMiNiGroupList> appletProducts) productListResult;
List<Map<String, dynamic>> shopCarGoods; List<Map<String, dynamic>> shopCarGoods;
StoreOrderListPage( StoreOrderListPage(
@ -28,6 +29,7 @@ class StoreOrderListPage extends StatefulWidget {
this.shopCarGoods, this.shopCarGoods,
this.controller, this.controller,
this.queryMiNiDetail, this.queryMiNiDetail,
this.productListResult,
this.fc this.fc
); );
@ -47,17 +49,6 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
List<FindMiNiGroupList> appletProducts; List<FindMiNiGroupList> appletProducts;
List<ProductListBean> productListBeans = []; 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 @override
void initState() { void initState() {
super.initState(); super.initState();
@ -87,6 +78,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
setState(() { setState(() {
appletProducts = baseData.data; appletProducts = baseData.data;
widget.productListResult(appletProducts);
productListBeans.clear(); productListBeans.clear();
if (appletProducts.length > 0) if (appletProducts.length > 0)
productListBeans.addAll(appletProducts[0].productList); productListBeans.addAll(appletProducts[0].productList);

Loading…
Cancel
Save