From 91be0a76fb97771c7208de9b92052c3bc3f34b30 Mon Sep 17 00:00:00 2001 From: w-R <953969641@qq.com> Date: Sat, 2 Apr 2022 11:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/retrofit/retrofit_api.dart | 4 +- .../shopping_cart/shopping_cart_page.dart | 539 ++++++++++-------- 2 files changed, 292 insertions(+), 251 deletions(-) diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index cb8f321b..512e5b77 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -91,8 +91,8 @@ abstract class ApiService { headers["Environment"] = "app"; } dio.options = BaseOptions( - connectTimeout: 60000, - receiveTimeout: 60000, + connectTimeout: 15000, + receiveTimeout: 15000, headers: headers, responseType: ResponseType.json, ); diff --git a/lib/store/shopping/shopping_cart/shopping_cart_page.dart b/lib/store/shopping/shopping_cart/shopping_cart_page.dart index 8108d126..a50dda53 100644 --- a/lib/store/shopping/shopping_cart/shopping_cart_page.dart +++ b/lib/store/shopping/shopping_cart/shopping_cart_page.dart @@ -16,8 +16,6 @@ import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/no_data_view.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - class ShoppingCartPage extends StatefulWidget { final String minToken; @@ -25,7 +23,8 @@ class ShoppingCartPage extends StatefulWidget { final String tenant; final StoreInfo storeInfo; - ShoppingCartPage(this.minToken,this.storeId, this.tenant,this.storeInfo); + ShoppingCartPage(this.minToken, this.storeId, this.tenant, this.storeInfo); + @override State createState() { return _ShoppingCartPage(); @@ -45,7 +44,6 @@ class _ShoppingCartPage extends State bool topIndex = false; bool isAllSelect = false; - @override void initState() { super.initState(); @@ -54,12 +52,12 @@ class _ShoppingCartPage extends State ///清空购物车 clearShopCar() async { - shopCarGoods[0].shoppingCartSkuItemList.forEach((element) { - if(element.selected == 1){ - shopCartAdd(element,-element.buyNum,element.selected); - } - }); - queryShopCar(); + shopCarGoods[0].shoppingCartSkuItemList.forEach((element) { + if (element.selected == 1) { + shopCartAdd(element, -element.buyNum, element.selected); + } + }); + queryShopCar(); } ///去下单结算页面 @@ -69,10 +67,10 @@ class _ShoppingCartPage extends State arguments: { "storeInfo": widget.storeInfo, "tableId": tableId, - "pName":pName, - "pid":pid, - "cName":cName, - "cid":cid, + "pName": pName, + "pid": pid, + "cName": cName, + "cid": cid, }, ); queryShopCar(); @@ -80,9 +78,8 @@ class _ShoppingCartPage extends State ///查询购物车商品 queryShopCar() async { - if(widget.minToken == null) - return; - if(minService == null) + if (widget.minToken == null) return; + if (minService == null) minService = MinApiService( Dio(), context: context, @@ -92,7 +89,7 @@ class _ShoppingCartPage extends State showLoading: false, ); BaseData> baseData = - await minService.getShoppingCart(tableId).catchError((error) { + await minService.getShoppingCart(tableId).catchError((error) { refreshController.refreshFailed(); }); if (baseData != null && baseData.isSuccess) { @@ -108,14 +105,13 @@ class _ShoppingCartPage extends State ///购物车数量修改 shopCartAdd( - ShoppingCartSkuItemListBean cartSkuItem,int count,int selected) async { + ShoppingCartSkuItemListBean cartSkuItem, int count, int selected) async { Map shopCarTemp = shopCarGoods[0].toJson(); cartSkuItem.buyNum += count; cartSkuItem.selected = selected; shopCarTemp["selected"] = selected; shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - BaseData baseDate = - await minService.shoppingCartSingle(shopCarTemp); + BaseData baseDate = await minService.shoppingCartSingle(shopCarTemp); if (baseDate.isSuccess) { setState(() { queryShopCar(); @@ -148,7 +144,7 @@ class _ShoppingCartPage extends State background: Colors.transparent, actions: [ GestureDetector( - onTap: (){ + onTap: () { setState(() { topIndex = !topIndex; }); @@ -156,11 +152,12 @@ class _ShoppingCartPage extends State child: Container( alignment: Alignment.center, margin: EdgeInsets.only(right: 12.w), - child: Text(!topIndex ? "管理" :S.of(context).quxiao, + child: Text( + !topIndex ? "管理" : S.of(context).quxiao, style: TextStyle( fontSize: 18.sp, fontWeight: MyFontWeight.semi_bold, - color:Colors.black, + color: Colors.black, ), ), ), @@ -200,9 +197,9 @@ class _ShoppingCartPage extends State ], ), Align( - alignment: Alignment(0.8,0.8), + alignment: Alignment(0.8, 0.8), child: Container( - height:70.h, + height: 70.h, width: double.infinity, decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), @@ -216,127 +213,133 @@ class _ShoppingCartPage extends State ], color: Color(0xFFFAFAFA), ), - padding: EdgeInsets.only(left: 16.w,right: 16.w), + padding: EdgeInsets.only(left: 16.w, right: 16.w), child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.center, children: [ GestureDetector( - onTap: (){ + onTap: () { setState(() { isAllSelect = !isAllSelect; - shopCarGoods[0].shoppingCartSkuItemList.forEach((element) { - element.selected = isAllSelect?1:0; - shopCartAdd(element,0,element.selected); + shopCarGoods[0] + .shoppingCartSkuItemList + .forEach((element) { + element.selected = isAllSelect ? 1 : 0; + shopCartAdd(element, 0, element.selected); }); }); }, - child:Image.asset( - isAllSelect ? "assets/image/icon_radio_selected.webp" : - "assets/image/icon_radio_unselected.webp", + child: Image.asset( + isAllSelect + ? "assets/image/icon_radio_selected.webp" + : "assets/image/icon_radio_unselected.webp", width: 16, height: 16, ), ), SizedBox(width: 5.w), - Expanded(child: Text( - "全选", - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFFA29E9E), + Expanded( + child: Text( + "全选", + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFFA29E9E), + ), ), - ),), - !topIndex ? - Row( - children: [ - Text.rich( - TextSpan( + ), + !topIndex + ? Row( children: [ - TextSpan( - text: "合计:", - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Colors.black, + Text.rich( + TextSpan( + children: [ + TextSpan( + text: "合计:", + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Colors.black, + ), + ), + TextSpan( + text: ((shopCarGoods?.length ?? 0) > 0) + ? (shopCarGoods[0]?.cartSum ?? "") + : "", + style: TextStyle( + fontSize: 20.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF32A060), + ), + ), + ], ), ), - TextSpan( - text:((shopCarGoods?.length??0) > 0) ? (shopCarGoods[0]?.cartSum ?? "") : "", - style: TextStyle( - fontSize: 20.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF32A060), + GestureDetector( + onTap: () { + toDownOrder(); + }, + child: Container( + alignment: Alignment.center, + width: 70.w, + height: 32.h, + margin: EdgeInsets.only(left: 6.w), + decoration: BoxDecoration( + color: Color(0xFF32A060), + borderRadius: BorderRadius.circular(16), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ), + ], + ), + child: Text( + "结算", + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, + ), + ), ), ), - ], - ), - ), - GestureDetector( - onTap:(){ - toDownOrder(); - }, - child:Container( - alignment: Alignment.center, - width: 70.w, - height: 32.h, - margin: EdgeInsets.only(left:6.w), - decoration: BoxDecoration( - color: Color(0xFF32A060), - borderRadius: BorderRadius.circular(16), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, + ) + : GestureDetector( + onTap: () { + clearShopCar(); + }, + child: Container( + alignment: Alignment.center, + width: 70.w, + height: 32.h, + margin: EdgeInsets.only(left: 6.w), + decoration: BoxDecoration( + color: Color(0xFFFB312B), + borderRadius: BorderRadius.circular(16), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ), + ], ), - ], - ), - child: Text( - "结算", - style: TextStyle( - fontSize: 16.sp, - fontWeight: MyFontWeight.regular, - color: Colors.white, - ), - ), - ),), - ], - ): - GestureDetector( - onTap: (){ - clearShopCar(); - }, - child: Container( - alignment: Alignment.center, - width: 70.w, - height: 32.h, - margin: EdgeInsets.only(left:6.w), - decoration: BoxDecoration( - color: Color(0xFFFB312B), - borderRadius: BorderRadius.circular(16), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, + child: Text( + "删除", + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.regular, + color: Colors.white, ), - ], - ), - child: Text( - "删除", - style: TextStyle( - fontSize: 16.sp, - fontWeight: MyFontWeight.regular, - color: Colors.white, ), ), ), - ), - ], ), ), @@ -345,33 +348,34 @@ class _ShoppingCartPage extends State ); } - Widget cartGoodsList(){ + Widget cartGoodsList() { return (shopCarGoods == null || shopCarGoods.length == 0) - ? NoDataView( - src: "assets/image/shopping_k.webp", - isShowBtn: false, - text:"目前暂无商品,要快去买点好吃的哦~", - fontSize: 16.sp, - margin: EdgeInsets.only(top: 150.h), - ): - Container( - margin: EdgeInsets.only(bottom: 50.h), - child: ListView.builder( - itemCount:((shopCarGoods?.length ?? 0) > 0) ? (shopCarGoods[0]?.shoppingCartSkuItemList?.length ?? 0) : 0, - shrinkWrap: true, - padding: EdgeInsets.only( - top: 8.h, - bottom: 84.h, /* + (375.h - 88.h) + 4.h*/ - ), - physics: BouncingScrollPhysics(), - itemBuilder: (context, position) { - return InkWell( - onTap: () { - }, - child: cartGoodsItem(position), - ); - }), - ); + ? NoDataView( + src: "assets/image/shopping_k.webp", + isShowBtn: false, + text: "目前暂无商品,要快去买点好吃的哦~", + fontSize: 16.sp, + margin: EdgeInsets.only(top: 150.h), + ) + : Container( + margin: EdgeInsets.only(bottom: 50.h), + child: ListView.builder( + itemCount: ((shopCarGoods?.length ?? 0) > 0) + ? (shopCarGoods[0]?.shoppingCartSkuItemList?.length ?? 0) + : 0, + shrinkWrap: true, + padding: EdgeInsets.only( + top: 8.h, + bottom: 84.h, /* + (375.h - 88.h) + 4.h*/ + ), + physics: BouncingScrollPhysics(), + itemBuilder: (context, position) { + return InkWell( + onTap: () {}, + child: cartGoodsItem(position), + ); + }), + ); } Widget cartGoodsItem(index) { @@ -395,127 +399,164 @@ class _ShoppingCartPage extends State crossAxisAlignment: CrossAxisAlignment.center, children: [ GestureDetector( - onTap: (){ + onTap: () { setState(() { - shopCarGoods[0].shoppingCartSkuItemList[index].selected = (shopCarGoods[0].shoppingCartSkuItemList[index].selected == 0) ? 1 : 0; - shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index],0,shopCarGoods[0].shoppingCartSkuItemList[index].selected); + shopCarGoods[0].shoppingCartSkuItemList[index].selected = + (shopCarGoods[0].shoppingCartSkuItemList[index].selected == + 0) + ? 1 + : 0; + shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index], 0, + shopCarGoods[0].shoppingCartSkuItemList[index].selected); }); }, - child:Image.asset( - (shopCarGoods[0].shoppingCartSkuItemList[index].selected==1) ? "assets/image/icon_radio_selected.webp" : - "assets/image/icon_radio_unselected.webp", - width:16, - height:16, + child: Image.asset( + (shopCarGoods[0].shoppingCartSkuItemList[index].selected == 1) + ? "assets/image/icon_radio_selected.webp" + : "assets/image/icon_radio_unselected.webp", + width: 16, + height: 16, ), ), SizedBox(width: 16.w), MImage( shopCarGoods[0].shoppingCartSkuItemList[index]?.skuImg ?? "", - isCircle: true, - width:81, - height:81, + isCircle: true, + width: 81, + height: 81, fit: BoxFit.cover, errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox(width: 10.w), - Expanded(child: - Container( - height:81.h,child:Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - shopCarGoods[0].shoppingCartSkuItemList[index]?.productName ?? "", - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFF353535), - ), - ), - // SizedBox(height: 5.h), - Text( - shopCarGoods[0].shoppingCartSkuItemList[index]?.skuName ?? "", - style: TextStyle( - fontSize: 10.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFF727272), - ), - ), - // SizedBox(height: 5.h), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Expanded(child:Text.rich( - TextSpan( - children: [ - TextSpan( - text: "¥", - style: TextStyle( - fontSize: 10.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF32A060), - ), - ), - TextSpan( - text:shopCarGoods[0].shoppingCartSkuItemList[index]?.skuPrice ?? "", - style: TextStyle( - fontSize: 14.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF32A060), - ), - ), - ], - ), - )), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center,children: [ - InkWell( - onTap: () { - setState(() { - if(shopCarGoods[0].shoppingCartSkuItemList[index].buyNum > 1) - shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index],-1,shopCarGoods[0].shoppingCartSkuItemList[index].selected); - }); - }, - child: Image.asset( - "assets/image/reduce.webp", - width: 22, - height: 22, + Expanded( + child: Container( + height: 81.h, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + shopCarGoods[0] + .shoppingCartSkuItemList[index] + ?.productName ?? + "", + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 14.sp, + fontWeight: MyFontWeight.medium, + color: Color(0xFF353535), ), ), - Container( - width: 30, - alignment: Alignment.center, - child: Text( - shopCarGoods[0].shoppingCartSkuItemList[index]?.buyNum.toString() ?? 0, - style: TextStyle( - color: Colors.black, - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - ), + // SizedBox(height: 5.h), + Text( + shopCarGoods[0].shoppingCartSkuItemList[index]?.skuName ?? + "", + style: TextStyle( + fontSize: 10.sp, + fontWeight: MyFontWeight.medium, + color: Color(0xFF727272), ), ), - InkWell( - onTap: () { - setState(() { - shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index],1,shopCarGoods[0].shoppingCartSkuItemList[index].selected); - }); - }, - child: Image.asset( - "assets/image/add.webp", - width: 22, - height: 22, - ), + // SizedBox(height: 5.h), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Expanded( + child: Text.rich( + TextSpan( + children: [ + TextSpan( + text: "¥", + style: TextStyle( + fontSize: 10.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF32A060), + ), + ), + TextSpan( + text: shopCarGoods[0] + .shoppingCartSkuItemList[index] + ?.skuPrice ?? + "", + style: TextStyle( + fontSize: 14.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF32A060), + ), + ), + ], + ), + )), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + InkWell( + onTap: () { + setState(() { + if (shopCarGoods[0] + .shoppingCartSkuItemList[index] + .buyNum > + 1) + shopCartAdd( + shopCarGoods[0] + .shoppingCartSkuItemList[index], + -1, + shopCarGoods[0] + .shoppingCartSkuItemList[index] + .selected); + }); + }, + child: Image.asset( + "assets/image/reduce.webp", + width: 22, + height: 22, + ), + ), + Container( + width: 30, + alignment: Alignment.center, + child: Text( + shopCarGoods[0] + .shoppingCartSkuItemList[index] + ?.buyNum + .toString() ?? + 0, + style: TextStyle( + color: Colors.black, + fontSize: 14.sp, + fontWeight: MyFontWeight.medium, + ), + ), + ), + InkWell( + onTap: () { + setState(() { + shopCartAdd( + shopCarGoods[0] + .shoppingCartSkuItemList[index], + 1, + shopCarGoods[0] + .shoppingCartSkuItemList[index] + .selected); + }); + }, + child: Image.asset( + "assets/image/add.webp", + width: 22, + height: 22, + ), + ), + ], + ) + ], ), - ],) - ], - ), - ], - )),), + ], + )), + ), ], ), );