From f2bc6100200ceb0d927cc0f950a14ccb74eb13c3 Mon Sep 17 00:00:00 2001 From: fmk Date: Tue, 19 Oct 2021 19:00:17 +0800 Subject: [PATCH] safety --- lib/community/community_child_page.dart | 61 ++-- lib/retrofit/data/settlement_bean.dart | 8 +- lib/retrofit/data/shoppingCart.dart | 14 +- lib/retrofit/min_api.dart | 33 +- lib/retrofit/min_api.g.dart | 110 +++++- lib/retrofit/retrofit_api.dart | 8 +- lib/store/sku.dart | 71 ++++ lib/store/store_order.dart | 210 +++++------- lib/store/store_view/product_sku.dart | 75 +++-- lib/store/store_view/settlement.dart | 29 +- .../settlement_order_commodity.dart | 11 +- lib/store/store_view/shop_car.dart | 317 ++++++++---------- lib/store/store_view/shop_goods.dart | 36 +- lib/store/store_view/store_order_list.dart | 68 ++-- 14 files changed, 588 insertions(+), 463 deletions(-) create mode 100644 lib/store/sku.dart diff --git a/lib/community/community_child_page.dart b/lib/community/community_child_page.dart index 0f0660a5..cb1d5100 100644 --- a/lib/community/community_child_page.dart +++ b/lib/community/community_child_page.dart @@ -77,37 +77,38 @@ class _CommunityChildPage extends State { future: queryCommunity(), builder: (context, position) { return SmartRefresher( - controller: refreshController, - enablePullDown: true, - enablePullUp: true, - physics: BouncingScrollPhysics(), - header: MyHeader(), - footer: CustomFooter( - builder: (context, mode) { - return MyFooter(mode); - }, - ), - onRefresh: _onRefresh, - onLoading: () { - setState(() {}); + controller: refreshController, + enablePullDown: true, + enablePullUp: true, + physics: BouncingScrollPhysics(), + header: MyHeader(), + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); }, - child: ListView.builder( - physics: NeverScrollableScrollPhysics(), - itemBuilder: (context, position) { - return InkWell( - child: CommunityDynamic(comments[position]), - onTap: () { - Navigator.of(context).pushNamed( - '/router/community_details', - arguments: { - "comment": comments[position], - }, - ); - }, - ); - }, - itemCount: comments.length, - )); + ), + onRefresh: _onRefresh, + onLoading: () { + setState(() {}); + }, + child: ListView.builder( + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, position) { + return InkWell( + child: CommunityDynamic(comments[position]), + onTap: () { + Navigator.of(context).pushNamed( + '/router/community_details', + arguments: { + "comment": comments[position], + }, + ); + }, + ); + }, + itemCount: comments.length, + ), + ); }, ); } diff --git a/lib/retrofit/data/settlement_bean.dart b/lib/retrofit/data/settlement_bean.dart index 8315b8b5..5cee84b3 100644 --- a/lib/retrofit/data/settlement_bean.dart +++ b/lib/retrofit/data/settlement_bean.dart @@ -172,7 +172,7 @@ class OrderProductVOList { int returnStatus, int returnType, int sellPrice, - int skuId, + String skuId, String skuImg, String skuNameStr,}){ _actInfo = actInfo; @@ -227,7 +227,7 @@ class OrderProductVOList { int _returnStatus; int _returnType; int _sellPrice; - int _skuId; + String _skuId; String _skuImg; String _skuNameStr; @@ -245,7 +245,7 @@ class OrderProductVOList { int get returnStatus => _returnStatus; int get returnType => _returnType; int get sellPrice => _sellPrice; - int get skuId => _skuId; + String get skuId => _skuId; String get skuImg => _skuImg; String get skuNameStr => _skuNameStr; @@ -334,7 +334,7 @@ class OrderProductVOList { _sellPrice = value; } - set skuId(int value) { + set skuId(String value) { _skuId = value; } diff --git a/lib/retrofit/data/shoppingCart.dart b/lib/retrofit/data/shoppingCart.dart index fb69d382..78a1794a 100644 --- a/lib/retrofit/data/shoppingCart.dart +++ b/lib/retrofit/data/shoppingCart.dart @@ -7,13 +7,13 @@ /// tableId : 0 class ShoppingCart { - int cartSum; + String cartSum; int numberOfPeople; int selected; List shoppingCartSkuItemList; - int storeId; + String storeId; String storeName; - int tableId; + String tableId; static ShoppingCart fromJson(Map map) { if (map == null) return null; @@ -59,8 +59,8 @@ class ShoppingCart { class ShoppingCartSkuItemListBean { int buyNum; String createTime; - int groupId; - int id; + String groupId; + String id; List platterList; String productId; String productName; @@ -68,7 +68,7 @@ class ShoppingCartSkuItemListBean { int selected; String skuImg; String skuName; - int skuPrice; + String skuPrice; int skuStock; String storeId; int tableId; @@ -126,7 +126,7 @@ class PlatterListBean { int id; int productId; bool required; - int skuId; + String skuId; static PlatterListBean fromJson(Map map) { if (map == null) return null; diff --git a/lib/retrofit/min_api.dart b/lib/retrofit/min_api.dart index 53d6ccc9..a470375f 100644 --- a/lib/retrofit/min_api.dart +++ b/lib/retrofit/min_api.dart @@ -42,6 +42,7 @@ abstract class MinApiService { BuildContext context, String token, String tenant, + String storeId, bool showLoading = true, bool pay = false, }) { @@ -50,6 +51,9 @@ abstract class MinApiService { if (tenant != null && tenant != "") { headers["tenant"] = tenant; } + if (storeId != null && storeId != "") { + headers["store_id"] = storeId; + } if (pay) { headers["Environment"] = "app"; } @@ -83,10 +87,9 @@ abstract class MinApiService { EasyLoading.dismiss(); } debugPrint("code = ${response.statusCode}"); - // p(jsonEncode(response.data)); + p(jsonEncode(response.data)); - debugPrint(jsonEncode(response.data), - wrapWidth: response.data.toString().length); + // debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length); Map map = response.data; if (map["code"] != 0) { @@ -124,10 +127,10 @@ abstract class MinApiService { static void p(String msg) { int maxStrLength = 900; while (msg.length > maxStrLength) { - debugPrint(msg.substring(0, maxStrLength)); + debugPrint(msg.substring(0, maxStrLength), wrapWidth: maxStrLength); msg = msg.substring(maxStrLength); } - debugPrint(msg); + debugPrint(msg, wrapWidth: maxStrLength); } ///小程序查询分组及商品列表 @@ -141,8 +144,23 @@ abstract class MinApiService { ///添加购物车 @POST("shoppingcart") - Future> shoppingCart( - @Body() Map param, Map header); + Future>> addShoppingCart(@Body() Map param); + + ///获取购物车商品 + @GET("shoppingcart") ///?tableId={tableId} + Future>> getShoppingCart(@Query("tableId") int tableId); + + ///清空购物车商品 + @GET("shoppingcart/delCart") + Future> clearShoppingCart(); + + ///修改购物车 + @PUT("shoppingcart") + Future>> shoppingCart1(@Body() Map param); + + ///修改购物车商品数量 + @PUT("shoppingcart/single") + Future>> shoppingCartSingle(@Body() Map param); ///订单结算信息 @POST("order/getOrderInfo") @@ -154,7 +172,6 @@ abstract class MinApiService { @POST("order/placeOrderFirst") Future placeOrderFirst(@Body() Map param); - /// 结算 @POST("order/settlement") Future settlementApi(@Body() Map param); diff --git a/lib/retrofit/min_api.g.dart b/lib/retrofit/min_api.g.dart index dbd499fb..efe149f7 100644 --- a/lib/retrofit/min_api.g.dart +++ b/lib/retrofit/min_api.g.dart @@ -64,9 +64,8 @@ class _MinApiService implements MinApiService { } @override - Future> shoppingCart(param, header) async { + Future>> addShoppingCart(param) async { ArgumentError.checkNotNull(param, 'param'); - ArgumentError.checkNotNull(header, 'header'); const _extra = {}; final queryParameters = {}; final _data = {}; @@ -79,13 +78,108 @@ class _MinApiService implements MinApiService { extra: _extra, baseUrl: baseUrl), data: _data); - final value = BaseData.fromJson( + final value = BaseData>.fromJson( + _result.data, + (json) => (json as List) + .map( + (i) => ShoppingCart.fromJson(i as Map)) + .toList()); + return value; + } + + @override + Future>> getShoppingCart(tableId) async { + ArgumentError.checkNotNull(tableId, 'tableId'); + const _extra = {}; + final queryParameters = {r'tableId': tableId}; + final _data = {}; + final _result = await _dio.request>('shoppingcart', + queryParameters: queryParameters, + options: RequestOptions( + method: 'GET', + headers: {}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData>.fromJson( + _result.data, + (json) => (json as List) + .map( + (i) => ShoppingCart.fromJson(i as Map)) + .toList()); + return value; + } + + @override + Future> clearShoppingCart() async { + const _extra = {}; + final queryParameters = {}; + final _data = {}; + final _result = await _dio.request>( + 'shoppingcart/delCart', + queryParameters: queryParameters, + options: RequestOptions( + method: 'GET', + headers: {}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData.fromJson( _result.data, - (json) => ShoppingCart.fromJson(json), + (json) => json as bool, ); return value; } + @override + Future>> shoppingCart1(param) async { + ArgumentError.checkNotNull(param, 'param'); + const _extra = {}; + final queryParameters = {}; + final _data = {}; + _data.addAll(param ?? {}); + final _result = await _dio.request>('shoppingcart', + queryParameters: queryParameters, + options: RequestOptions( + method: 'PUT', + headers: {}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData>.fromJson( + _result.data, + (json) => (json as List) + .map( + (i) => ShoppingCart.fromJson(i as Map)) + .toList()); + return value; + } + + @override + Future>> shoppingCartSingle(param) async { + ArgumentError.checkNotNull(param, 'param'); + const _extra = {}; + final queryParameters = {}; + final _data = {}; + _data.addAll(param ?? {}); + final _result = await _dio.request>( + 'shoppingcart/single', + queryParameters: queryParameters, + options: RequestOptions( + method: 'PUT', + headers: {}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData>.fromJson( + _result.data, + (json) => (json as List) + .map( + (i) => ShoppingCart.fromJson(i as Map)) + .toList()); + return value; + } + @override Future> getOrderInfo(param) async { ArgumentError.checkNotNull(param, 'param'); @@ -127,7 +221,7 @@ class _MinApiService implements MinApiService { data: _data); final value = BaseData.fromJson( _result.data, - (json) => json as dynamic, + (json) => json as dynamic, ); return value; } @@ -139,8 +233,7 @@ class _MinApiService implements MinApiService { final queryParameters = {}; final _data = {}; _data.addAll(param ?? {}); - final _result = await _dio.request>( - 'order/settlement', + final _result = await _dio.request>('order/settlement', queryParameters: queryParameters, options: RequestOptions( method: 'POST', @@ -150,9 +243,8 @@ class _MinApiService implements MinApiService { data: _data); final value = BaseData.fromJson( _result.data, - (json) => json as dynamic, + (json) => json as dynamic, ); return value; } - } diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index d9f4f607..73e259b0 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -90,9 +90,9 @@ abstract class ApiService { EasyLoading.dismiss(); } debugPrint("code = ${response.statusCode}"); - // p(jsonEncode(response.data)); + p(jsonEncode(response.data)); - debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length); + // debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length * 10); Map map = response.data; if (map["code"] != 0) { @@ -131,11 +131,11 @@ abstract class ApiService { int maxStrLength = 900; //大于1000时 while (msg.length > maxStrLength) { - debugPrint(msg.substring(0, maxStrLength)); + debugPrint(msg.substring(0, maxStrLength), wrapWidth: maxStrLength); msg = msg.substring(maxStrLength); } //剩余部分 - print(msg); + debugPrint(msg, wrapWidth: maxStrLength); } ///文件上传 diff --git a/lib/store/sku.dart b/lib/store/sku.dart new file mode 100644 index 00000000..997b7360 --- /dev/null +++ b/lib/store/sku.dart @@ -0,0 +1,71 @@ +class Sku { + Sku( + this.id, + this.count, + this.price, + ); + + String id; + int count; + String price; + String name; + String skuId; + String skuValue; + + List attr = []; + + bool compareTo(List attr) { + bool attrY = true; + for (int i = 0; i < this.attr.length; i++) { + if (!this.attr[i].compareTo(attr[i])) { + attrY = false; + return attrY; + } + } + return attrY; + } + + Map toJson() => { + "id": id, + "count": count, + "price": price, + "skuId": skuId, + "name": name, + "value": skuValue, + "attr": attr.map((e) => e.toJson()).toList(), + }; + + Sku copy() { + return Sku( + this.id, + this.count, + this.price, + ) + ..name = this.name + ..skuValue = this.skuValue + ..attr = attr.map((e) => e.copy()).toList(); + } +} + +class Attr { + Attr(this.attrId, this.attrValue); + + String attrId; + String attrValue; + + bool compareTo(Attr attr) { + return attrId == attr.attrId && attrValue == attr.attrValue; + } + + Map toJson() => { + "attrId": attrId, + "attrValue": attrValue, + }; + + Attr copy() { + return Attr( + this.attrId, + this.attrValue, + ); + } +} diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index 6c341117..3cffa6e2 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -11,9 +11,11 @@ import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/miNiDetail.dart'; +import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; +import 'package:huixiang/store/sku.dart'; import 'package:huixiang/store/store_view/product_sku.dart'; import 'package:huixiang/store/store_view/shop_car.dart'; import 'package:huixiang/store/store_view/store_activity.dart'; @@ -48,17 +50,12 @@ class _StoreOrderPage extends State StoreInfo storeInfo; List activitys; RefreshController refreshController; - - int allCount = 0; - double allPrice = 0; StoreOrderListPage storeOrderListPage; - List> shopCarGoods = []; - List appletProducts = []; - List shopCar = []; - ScrollController controller = ScrollController(); + List shopCarGoods; + @override void initState() { super.initState(); @@ -74,16 +71,14 @@ class _StoreOrderPage extends State } _fc(int count, String productId, int allCount, double allPrice) { - if (count == 0) { - int index = - shopCarGoods.indexWhere((element) => element["id"] == productId); - shopCarGoods.removeAt(index); - } - - setState(() { - this.allCount = allCount; - this.allPrice = allPrice; - }); + // if (count == 0) { + // int index = shopCarGoods.indexWhere((element) => element.id == productId); + // shopCarGoods.removeAt(index); + // } + // setState(() { + // this.allCount = allCount; + // this.allPrice = allPrice; + // }); } /// 小程序登录 @@ -102,10 +97,12 @@ class _StoreOrderPage extends State Map minStoreInfo = baseData.data; String minToken = minStoreInfo["token"]; String tenant = widget.arguments["tenant"]; + String storeId = widget.arguments["id"]; SharedPreferences.getInstance().then( (value) => { value.setString('minToken', minToken), value.setString('tenant', tenant), + value.setString('storeId', storeId), }, ); minService = MinApiService( @@ -113,6 +110,7 @@ class _StoreOrderPage extends State context: context, token: minToken, tenant: tenant, + storeId: storeId, ); } }); @@ -400,7 +398,7 @@ class _StoreOrderPage extends State child: RoundButton( width: 17, height: 17, - text: "$allCount", + text: "${allCount}", textColor: Colors.white, fontWeight: MyFontWeight.regular, backgroup: Color(0xFF32A060), @@ -422,14 +420,12 @@ class _StoreOrderPage extends State SmartDialog.showToast("请选择要购买的商品~"); return; } - getShopCarGoods(); Navigator.of(context).pushNamed( '/router/settlement', arguments: { "storeInfo": storeInfo, "shopGoods": shopCarGoods, - "shopProduct": shopCar, }, ); } @@ -471,57 +467,35 @@ class _StoreOrderPage extends State ); } - _productListResult(List appletProducts) { - this.appletProducts = appletProducts; - } - - ///获取购物车内的商品 - getShopCarGoods() { - if (appletProducts == null || appletProducts.length == 0) return; - shopCar = []; - if (shopCarGoods != null && shopCarGoods.length > 0) { - shopCarGoods.forEach((element) { - appletProducts.forEach((element1) { - element1.productList.forEach((element2) { - if (element["id"] == element2.id) { - shopCar.add(element2); - } - }); - }); - }); - } - } - ///购物车弹窗 showShoppingCart() { - getShopCarGoods(); + queryShopCar().then((value) { + + showModalBottomSheet( + context: context, + backgroundColor: Colors.transparent, + builder: (context) { + return ShopCar( + value, + clearShopCar, + toDownOrder, + (int count, String productId, allCount, allPrice) { + // print("shopCarCount: $allCount allPrice: $allPrice "); + }, + ); + }, + ); - showModalBottomSheet( - context: context, - backgroundColor: Colors.transparent, - builder: (context) { - return ShopCar( - shopCar, - shopCarGoods, - clearShopCar, - toDownOrder, - (int count, String productId, allCount, allPrice) { - print("shopCarCount: $allCount allPrice: $allPrice "); - setState(() { - this.allCount = allCount; - this.allPrice = allPrice; - }); - }, - ); - }, - ); + }); } ///清空购物车 - clearShopCar() { - if (shopCarGoods != null) shopCarGoods.clear(); - calculatePrice(); - setState(() {}); + clearShopCar() async { + BaseData baseData = await minService.clearShoppingCart(); + if (baseData.isSuccess) { + + setState(() {}); + } } ///选规格 @@ -533,83 +507,53 @@ class _StoreOrderPage extends State } ///添加购物车 - addsShoppingCart() async { - BaseData baseDate = await apiService.creditOrder({ - "parentId": widget.arguments["parentId"], - "skuImg": null, - "skuNameStr": widget.arguments["skuNameStr"], - "skuPrice": widget.arguments["skuPrice"], - "skuStock": widget.arguments["skuStock"], - }); - if (baseDate != null && baseDate.isSuccess) {} + _addShopCar(Sku sku) async { + if (sku != null) { + BaseData> baseDate = await minService.addShoppingCart({ + "storeId": storeInfo.id, + "storeName": storeInfo.storeName ?? "", + "tableId": 0, + "shoppingCartSkuItemList": [ + { + "buyNum": sku.count, + "id": sku.skuId, + "platterList": [ + { + "skuId": sku.skuId + } + ], + "productId": sku.id, + "productName": sku.name, + "skuName": "", + "storeId": storeInfo.id, + } + ], + }); + if (baseDate != null && baseDate.isSuccess) { + queryShopCar(); + } + } + } + + ///查询购物车 + Future> queryShopCar() async { + BaseData> baseDate = await minService.getShoppingCart(0); + if (baseDate != null && baseDate.isSuccess) { + return baseDate.data; + } else { + return []; + } } ///选规格弹窗 showStoreSelector(MiNiDetail miNiDetail, String id) async { - var result = await showModalBottomSheet( + showModalBottomSheet( context: context, backgroundColor: Colors.transparent, builder: (context) { - return ProductSku(miNiDetail, id); + return ProductSku(miNiDetail, id, _addShopCar); }, ); - if (result != null) { - result["name"] = miNiDetail.productName; - miNiDetail.productSkuVOList.forEach((e0) { - String attr1 = ""; - String attr2 = ""; - e0.skuAttrList.forEach((e2) { - attr1 += e2.attrValueId; - }); - (result["attr"] as List).forEach((e1) { - attr2 += e1["attrValue"]; - }); - if(attr1 == attr2){ - result["skuId"] = e0.id; - return; - } - }); - if (shopCarGoods == null || shopCarGoods.length == 0) { - shopCarGoods = []; - shopCarGoods.add(result); - } else { - Map map; - shopCarGoods.forEach((element) { - if (element["id"] == result["id"]) { - map = element; - } - }); - if (map != null) { - int index = shopCarGoods - .indexWhere((element) => element["id"] == result["id"]); - shopCarGoods.removeAt(index); - shopCarGoods.insert(index, result); - } else { - shopCarGoods.add(result); - } - } - 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(() {}); } // @override diff --git a/lib/store/store_view/product_sku.dart b/lib/store/store_view/product_sku.dart index 92706b81..efcec472 100644 --- a/lib/store/store_view/product_sku.dart +++ b/lib/store/store_view/product_sku.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/retrofit/data/miNiDetail.dart'; +import 'package:huixiang/store/sku.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/round_button.dart'; @@ -9,8 +10,8 @@ import 'package:huixiang/view_widget/round_button.dart'; class ProductSku extends StatefulWidget { final MiNiDetail miNiDetail; final String productId; - - ProductSku(this.miNiDetail, this.productId); + final Function(Sku sku) addShopCar; + ProductSku(this.miNiDetail, this.productId, this.addShopCar); @override State createState() { @@ -22,24 +23,23 @@ class _ProductSku extends State { List selectSkus = []; int selectCount = 1; - Map tempSelected = {}; - + Sku tempSelected; @override void initState() { super.initState(); if (widget.miNiDetail != null) { - tempSelected["id"] = widget.productId; - tempSelected["count"] = 1; - tempSelected["price"] = widget.miNiDetail.price; - if (tempSelected["attr"] == null) - tempSelected["attr"] = []; + tempSelected = Sku(widget.productId, 1, widget.miNiDetail.price); + tempSelected.name = widget.miNiDetail.productName; + widget.miNiDetail.attrList.forEach((element) { selectSkus.add(element.attrValueList[0].attrValue); - (tempSelected["attr"] as List).add({ - "attrId": "${element.id}", - "attrValue": "${element.attrValueList[0].id}", - }); + tempSelected.attr.add( + Attr( + "${element.id}", + "${element.attrValueList[0].id}", + ), + ); }); } } @@ -95,7 +95,8 @@ class _ProductSku extends State { Padding( padding: EdgeInsets.only(top: 4, bottom: 7), child: Text( - "已选: " + (selectSkus.map((e) => "$e").toList().toString()), + "已选: " + + (selectSkus.map((e) => "$e").toList().toString()), style: TextStyle( color: Color(0xFF727272), fontSize: 11.sp, @@ -149,21 +150,18 @@ class _ProductSku extends State { itemBuilder: (context, position) { return attrItem( (index) { - if (tempSelected["attr"] == null) { - tempSelected["attr"] = []; + if (tempSelected.attr == null) { + tempSelected.attr = []; } - bool flag = false; - (tempSelected["attr"] as List).forEach((e0) { - if(e0["attrId"] == widget.miNiDetail.attrList[position].id){ - e0["attrValue"] = widget.miNiDetail.attrList[position].attrValueList[index].id; - flag = true; + + tempSelected.attr.forEach((e0) { + if (e0.attrId == widget.miNiDetail.attrList[position].id) { + String valueId = widget.miNiDetail.attrList[position].attrValueList[index].id; + if (e0.attrValue != valueId) { + tempSelected.attr[tempSelected.attr.indexOf(e0)].attrValue = valueId; + } } }); - if(!flag) - (tempSelected["attr"] as List).add({ - "attrId": "${widget.miNiDetail.attrList[position].id}", - "attrValue": "${widget.miNiDetail.attrList[position].attrValueList[index].id}", - }); state(() { selectSkus[position] = widget.miNiDetail @@ -197,7 +195,7 @@ class _ProductSku extends State { state(() { if (selectCount > 1) selectCount--; }); - tempSelected["count"] = selectCount; + tempSelected.count = selectCount; }, child: Image.asset( "assets/image/reduce.png", @@ -220,7 +218,7 @@ class _ProductSku extends State { onTap: () { state(() { selectCount++; - tempSelected["count"] = selectCount; + tempSelected.count = selectCount; }); }, child: Image.asset( @@ -244,7 +242,7 @@ class _ProductSku extends State { backgroup: Color(0xFF32A060), fontSize: 16.sp, callback: () { - Navigator.of(context).pop(tempSelected); + _result(); }, ), SizedBox( @@ -256,6 +254,25 @@ class _ProductSku extends State { }); } + _result() async { + ProductSkuVOListBean productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) { + bool gg = true; + selectSkus.forEach((element1) { + if (element.skuNameStr.indexOf(element1) < 0) { + gg = false; + return gg; + } + }); + return gg; + }); + // print("productSku: ${selectSkus.toString()}"); + print("productSku: ${tempSelected.toJson()}"); + if (productSku == null) return; + tempSelected.skuId = productSku.id; + tempSelected.skuValue = selectSkus.toString(); + widget.addShopCar(tempSelected); + } + Widget attrItem(Function fc, AttrListBean attrListBean, position) { return Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/store/store_view/settlement.dart b/lib/store/store_view/settlement.dart index 564a42d2..7b145c5c 100644 --- a/lib/store/store_view/settlement.dart +++ b/lib/store/store_view/settlement.dart @@ -15,6 +15,7 @@ import 'package:huixiang/retrofit/data/settlement_bean.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/min_api.dart'; +import 'package:huixiang/store/sku.dart'; import 'package:huixiang/store/store_view/settlement_order_commodity.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; @@ -45,7 +46,7 @@ class _Settlement extends State { int selectedCouponIndex = -1; List shopCar = []; - List> shopCarGoods = []; + List shopCarGoods = []; TextEditingController _vc; List addressBgs = [ @@ -115,19 +116,19 @@ class _Settlement extends State { placeOrderFirst.skuItemDTOList = []; shopCarGoods.forEach((e0) { SkuItemDTOList skuItemDTOListBean = SkuItemDTOList(); - skuItemDTOListBean.skuId = e0["skuId"]; - skuItemDTOListBean.buyNum = e0["count"]; + skuItemDTOListBean.skuId = e0.skuId; + skuItemDTOListBean.buyNum = e0.count; PlatterList platterListBean = PlatterList(); - platterListBean.skuId = e0["skuId"]; - platterListBean.productId = e0["id"]; + platterListBean.skuId = e0.skuId; + platterListBean.productId = e0.id; skuItemDTOListBean.platterList = []; skuItemDTOListBean.platterList.add(platterListBean); placeOrderFirst.skuItemDTOList.add(skuItemDTOListBean); ShoppingCartSkuItemListBean shoppingCartSkuItemListBean = ShoppingCartSkuItemListBean(); - shoppingCartSkuItemListBean.buyNum = e0["count"]; - shoppingCartSkuItemListBean.productId = e0["id"]; - shoppingCartSkuItemListBean.productName = e0["name"]; - shoppingCartSkuItemListBean.skuId = e0["skuId"]; + shoppingCartSkuItemListBean.buyNum = e0.count; + shoppingCartSkuItemListBean.productId = e0.id; + shoppingCartSkuItemListBean.productName = e0.name; + shoppingCartSkuItemListBean.skuId = e0.skuId; placeOrderFirst.shoppingCartSkuItemList.add(shoppingCartSkuItemListBean); }); placeOrderFirst.source = 1; @@ -151,8 +152,8 @@ class _Settlement extends State { settlementBean.orderProductVOList = []; shopCarGoods.forEach((e0) { OrderProductVOList orderProductVOListBean = OrderProductVOList(); - orderProductVOListBean.skuId = e0["skuId"]; - orderProductVOListBean.buyNum = e0["count"]; + orderProductVOListBean.skuId = e0.skuId; + orderProductVOListBean.buyNum = e0.count; ActInfo actInfoBean = ActInfo(); actInfoBean.couponDiscountAmount = 0; actInfoBean.couponDiscountRate = 0; @@ -209,7 +210,7 @@ class _Settlement extends State { orderProductVOListBean.returnStatus = 0; orderProductVOListBean.returnType = 0; orderProductVOListBean.sellPrice = 0; - orderProductVOListBean.skuId = 0; + orderProductVOListBean.skuId = "0"; orderProductVOListBean.skuImg = ""; orderProductVOListBean.skuNameStr = ""; settlementBean.orderProductVOList.add(orderProductVOListBean); @@ -231,7 +232,7 @@ class _Settlement extends State { if (shopCarGoods == null) return ""; double totalPrice = 0; shopCarGoods.forEach((element) { - totalPrice += double.tryParse(element["price"]) * element["count"]; + totalPrice += double.tryParse(element.price) * element.count; }); if(selectedCouponIndex != -1 && discountFlag){ double discountA = double.parse(settleOrderInfo.couponList[selectedCouponIndex].discountAmount); @@ -280,7 +281,7 @@ class _Settlement extends State { phoneWidget(), ///订单商品 - SettlementOrderCommodity(shopCar, 0,shopCarGoods,settleOrderInfo), + SettlementOrderCommodity(shopCar, 0, shopCarGoods, settleOrderInfo), // if (payStatus == 0) couponRemarks(), /*(payStatus == 0) ? paySelector() : */ diff --git a/lib/store/store_view/settlement_order_commodity.dart b/lib/store/store_view/settlement_order_commodity.dart index 9b7f9d93..4a8d66c1 100644 --- a/lib/store/store_view/settlement_order_commodity.dart +++ b/lib/store/store_view/settlement_order_commodity.dart @@ -3,6 +3,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/settleOrderInfo.dart'; +import 'package:huixiang/store/sku.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/separator.dart'; @@ -10,7 +11,7 @@ import 'package:huixiang/view_widget/separator.dart'; class SettlementOrderCommodity extends StatefulWidget { final int isTakeOut; final List orderInfo; - final List> shopCarGood; + final List shopCarGood; final SettleOrderInfo settleOrderInfo; SettlementOrderCommodity(this.orderInfo, this.isTakeOut,this.shopCarGood,this.settleOrderInfo); @@ -102,9 +103,9 @@ class _SettlementOrderCommodity extends State { } Widget commodityItem(ProductListBean productList) { - Map goodsBuyInfo; + Sku goodsBuyInfo; widget.shopCarGood.forEach((element) { - if(element["id"] == productList.id){ + if(element.id == productList.id){ goodsBuyInfo = element; return; } @@ -145,7 +146,7 @@ class _SettlementOrderCommodity extends State { ), ), Text( - "x${goodsBuyInfo["count"]}", + "x${goodsBuyInfo.count}", style: TextStyle( fontSize: 12.sp, color: Color(0xFF727272), @@ -358,7 +359,7 @@ class _SettlementOrderCommodity extends State { if (widget.shopCarGood == null) return ""; double totalPrice = 0; widget.shopCarGood.forEach((element) { - totalPrice += double.tryParse(element["price"]) * element["count"]; + totalPrice += double.tryParse(element.price) * element.count; }); return "$totalPrice"; } diff --git a/lib/store/store_view/shop_car.dart b/lib/store/store_view/shop_car.dart index 90fa6e1b..5432770c 100644 --- a/lib/store/store_view/shop_car.dart +++ b/lib/store/store_view/shop_car.dart @@ -2,23 +2,24 @@ 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/shoppingCart.dart'; +import 'package:huixiang/store/sku.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'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class ShopCar extends StatefulWidget { - final List productLists; final Function(String id) queryMiNiDetail; final Function() clearShopCar; final Function() toDownOrder; - final List> shopCarGoods; + + final List shopingCar; final Function(int count, String productId, int allCount, double allPrice) fc; ShopCar( - this.productLists, - this.shopCarGoods, + this.shopingCar, this.clearShopCar, this.toDownOrder, this.fc, { @@ -27,7 +28,7 @@ class ShopCar extends StatefulWidget { @override State createState() { - return _ShopCar(this.shopCarGoods); + return _ShopCar(); } } @@ -35,30 +36,9 @@ class _ShopCar extends State { int allCount = 0; double allPrice = 0.0; - final List> 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 @@ -103,8 +83,8 @@ class _ShopCar extends State { onTap: () { allPrice = 0; allCount = 0; - widget.productLists.clear(); - state((){}); + + state(() {}); widget.clearShopCar(); }, child: Image.asset( @@ -117,152 +97,144 @@ class _ShopCar extends State { ), ), 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 map; - print("productId: $productId"); - shopCarGoods.forEach((element) { - if (element["id"] == productId) { - map = element; - } - }); - map["count"] = count; - shopCarGoods[index] = map; - } + child: Stack( + children: [ + Positioned( + top: 0, + left: 0, + right: 0, + bottom: 54, + child: Container( + padding: EdgeInsets.only( + top: 8, + left: 16, + right: 16, + ), + child: ListView.builder( + itemCount: widget.shopingCar == null + ? 0 + : widget.shopingCar.length, + physics: BouncingScrollPhysics(), + itemBuilder: (context, position) { + return GestureDetector( + onTap: () {}, + child: ShopGoods( + widget.shopingCar[position], + (int count, List attr, String productId) { - 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"]); - } - }); - widget.fc(count, productId, allCount, allPrice); + widget.fc( + count, productId, allCount, allPrice); - state(() {}); + state(() {}); + }, + count: _shopCarGoods(position).count, + shopCarGoods: _shopCarGoods(position), + queryMiNiDetail: widget.queryMiNiDetail, + ), + ); }, - shopCarGoods: _shopCarGoods(position), - queryMiNiDetail: widget.queryMiNiDetail, ), - ); - }, - ), - ), - ), - Stack( - alignment: Alignment.bottomLeft, - children: [ - Container( - height: 54.h, - decoration: BoxDecoration( - color: Color(0xFFFAFAFA), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(8), - offset: Offset(0, -1), - blurRadius: 3, - 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(), - style: TextStyle( - fontSize: 20.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFF32A060), - ), - ), - Spacer(), - GestureDetector( - onTap: () { - widget.toDownOrder(); - }, - child: RoundButton( - width: 103.w, + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Stack( + alignment: Alignment.bottomLeft, + children: [ + Container( 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), + decoration: BoxDecoration( + color: Color(0xFFFAFAFA), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(8), + offset: Offset(0, -1), + blurRadius: 3, + 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(), + style: TextStyle( + fontSize: 20.sp, + fontWeight: MyFontWeight.medium, + color: Color(0xFF32A060), + ), + ), + Spacer(), + GestureDetector( + onTap: () { + widget.toDownOrder(); + }, + 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: () { - 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'); - }, - ), + 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'); + }, + ), + ), + ], + ), + ], ), - ], - ), - ], + ), + ], + ), + flex: 1, ), ], ), @@ -271,13 +243,14 @@ class _ShopCar extends State { ); } - Map _shopCarGoods(int position) { - Map map; - widget.shopCarGoods.forEach((element) { - if (widget.productLists[position].id == element["id"]) { - map = element; - } - }); + Sku _shopCarGoods(int position) { + Sku map = widget.shopCarGoods[position]; + // widget.shopCarGoods.forEach((element) { + // if (widget.productLists[position].id == element.id) { + // map = element; + // } + // }); + // print("shopCarGoods123123: ${map.toJson()}"); return map; } } diff --git a/lib/store/store_view/shop_goods.dart b/lib/store/store_view/shop_goods.dart index b2ce482f..728de675 100644 --- a/lib/store/store_view/shop_goods.dart +++ b/lib/store/store_view/shop_goods.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; +import 'package:huixiang/store/sku.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/view_widget/custom_image.dart'; @@ -9,12 +10,14 @@ import 'package:huixiang/view_widget/round_button.dart'; class ShopGoods extends StatefulWidget { final ProductListBean product; final Function(String id) queryMiNiDetail; - final Function(int count, String productId) fc; - final Map shopCarGoods; + final Function(int count, List attr, String productId) fc; + final Sku shopCarGoods; + final int count; ShopGoods( this.product, this.fc, { + this.count = 0, this.queryMiNiDetail, this.shopCarGoods, }); @@ -23,13 +26,13 @@ class ShopGoods extends StatefulWidget { State createState() { return _ShopGoods(); } + } class _ShopGoods extends State { @override Widget build(BuildContext context) { - int buyNum = _count(); return Container( color: Colors.white, padding: EdgeInsets.only( @@ -145,7 +148,7 @@ class _ShopGoods extends State { ], ), Spacer(), - if (buyNum == 0) + if (widget.count == 0) RoundButton( width: 49.w, text: S.of(context).xuanguige, @@ -159,11 +162,11 @@ class _ShopGoods extends State { widget.queryMiNiDetail(widget.product.id); }, ), - if (buyNum > 0) + if (widget.count > 0) InkWell( onTap: () { reduceCount(); - widget.fc(widget.shopCarGoods["count"], widget.product.id); + widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id); setState(() {}); }, child: Image.asset( @@ -172,12 +175,12 @@ class _ShopGoods extends State { height: 22, ), ), - if (buyNum > 0) + if (widget.count > 0) Container( width: 30, alignment: Alignment.center, child: Text( - "$buyNum", + "${widget.count}", style: TextStyle( color: Colors.black, fontSize: 14.sp, @@ -185,11 +188,11 @@ class _ShopGoods extends State { ), ), ), - if (buyNum > 0) + if (widget.count > 0) InkWell( onTap: () { addCount(); - widget.fc(widget.shopCarGoods["count"], widget.product.id); + widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id); setState(() {}); }, child: Image.asset( @@ -209,21 +212,12 @@ class _ShopGoods extends State { } addCount() { - widget.shopCarGoods["count"] += 1; + widget.shopCarGoods.count += 1; } reduceCount() { - widget.shopCarGoods["count"] -= 1; + widget.shopCarGoods.count -= 1; } - int _count() { - if (widget.shopCarGoods == null) return 0; - - if (widget.product.id == widget.shopCarGoods["id"]) { - return widget.shopCarGoods["count"]; - } - - return 0; - } } diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index 695b7874..b3c5464c 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -4,9 +4,11 @@ import 'package:flutter/material.dart'; import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; +import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; +import 'package:huixiang/store/sku.dart'; import 'package:huixiang/store/store_view/shop_goods.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -21,7 +23,7 @@ class StoreOrderListPage extends StatefulWidget { final Function(int count, String productId, int allCount, double allPrice) fc; final Function(String id) queryMiNiDetail; final Function(List appletProducts) productListResult; - List> shopCarGoods; + List shopCarGoods; StoreOrderListPage( this.arguments, @@ -199,8 +201,8 @@ class _StoreOrderListPage extends State { int count = 0; findMiNiGroupList.productList.forEach((element) { widget.shopCarGoods.forEach((element1) { - if (element.id == element1["id"]) { - count += element1["count"]; + if (element.id == element1.id) { + count += element1.count; } }); }); @@ -208,35 +210,47 @@ class _StoreOrderListPage extends State { } Widget goodsItem(position) { - Map map; + Sku map; + int count = 0; widget.shopCarGoods.forEach((element) { - if (productListBeans[position].id == element["id"]) { - map = element; + if (productListBeans[position].id == element.id) { + if (map == null) { + map = element; + count = map.count; + } else { + count += element.count; + } } }); - return ShopGoods( - productListBeans[position], - (int count, String productId) { - int allCount = 0; - AiDecimalAccuracy allPrice = AiDecimalAccuracy.zero; - widget.shopCarGoods.forEach((element2) { - if (element2["price"] != null && element2["price"] != "") { - double singlePrice = double.tryParse(element2["price"]); - allCount += element2["count"]; + return InkWell( + onTap: () { + widget.queryMiNiDetail(productListBeans[position].id); + }, + child: ShopGoods( + productListBeans[position], + (int count, List attr, String productId) { + int allCount = 0; + AiDecimalAccuracy allPrice = AiDecimalAccuracy.zero; + widget.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"); + AiDecimalAccuracy aiDecimalAccuracy = + AiDecimalAccuracy.fromInt(element2.count); + AiDecimalAccuracy aiPrice = + AiDecimalAccuracy.tryParse("$singlePrice"); - allPrice += (aiPrice * aiDecimalAccuracy); - } - }); - widget.fc(count, productId, allCount, allPrice.toDouble()); - setState(() {}); - }, - queryMiNiDetail: widget.queryMiNiDetail, - shopCarGoods: map, + allPrice += (aiPrice * aiDecimalAccuracy); + } + }); + widget.fc(count, productId, allCount, allPrice.toDouble()); + setState(() {}); + }, + count: count, + queryMiNiDetail: widget.queryMiNiDetail, + shopCarGoods: map, + ), ); } }