diff --git a/lib/community/community_page.dart b/lib/community/community_page.dart index 1d8a41f0..4c9c9b9e 100644 --- a/lib/community/community_page.dart +++ b/lib/community/community_page.dart @@ -32,7 +32,7 @@ class _CommunityPage extends State super.initState(); if (tabcontroller == null) - tabcontroller = TabController(length: lables.length, vsync: this); + tabcontroller = TabController(length: lables.length, vsync: this, initialIndex: 1); } _toRelease() async { diff --git a/lib/main_page.dart b/lib/main_page.dart index e1239a74..37fddb5b 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -229,7 +229,7 @@ class _MainPage extends State with WidgetsBindingObserver { } } - final PageController pageController = PageController(initialPage: 1); + final PageController pageController = PageController(initialPage: 0); @override Widget build(BuildContext context) { @@ -279,7 +279,7 @@ class _MainPage extends State with WidgetsBindingObserver { ); } - var clickIndex = 1; + var clickIndex = 0; Widget bottomNavigationItem(text, index) { var isSelected = index == clickIndex; diff --git a/lib/settlement/settlement.dart b/lib/settlement/settlement.dart index 30f52ecf..ba1c21e0 100644 --- a/lib/settlement/settlement.dart +++ b/lib/settlement/settlement.dart @@ -109,7 +109,8 @@ class _Settlement extends State { if (baseData != null && baseData.isSuccess) { setState(() { settleOrderInfo = baseData.data; - if (settleOrderInfo.orderProductList == null || settleOrderInfo.orderProductList.length == 0) { + if (settleOrderInfo.orderProductList == null || + settleOrderInfo.orderProductList.length == 0) { queryOrderDetails(parentId); } }); @@ -216,7 +217,8 @@ class _Settlement extends State { placeOrderFirst.subcribeTime = null; placeOrderFirst.tableId = "$tableId"; - if (tableId == 0) {///正常的商店下单 + if (tableId == 0) { + ///正常的商店下单 BaseData baseData = await minService .placeOrderFirst(placeOrderFirst.toJson()) .catchError((error) { @@ -227,7 +229,8 @@ class _Settlement extends State { this.downOrder = baseData.data; querySettlement(); } - } else { ///火锅店下单, 等待结算 + } else { + ///火锅店下单, 等待结算 BaseData baseData; if (parentId == "") { baseData = await minService @@ -368,8 +371,9 @@ class _Settlement extends State { ActivityCouponRemarks( couponCart, activityCart, - couponListBean, - promotion, + settleOrderInfo, + coupons, + promotions, couponCount(), ), @@ -398,9 +402,9 @@ class _Settlement extends State { ), ), Text( - minOrderInfo != null ? - "¥${minOrderInfo.orderSumPrice}" : - "¥${settleOrderInfo == null ? "0" : settleOrderInfo.price}", + minOrderInfo != null + ? "¥${minOrderInfo.orderSumPrice}" + : "¥${settleOrderInfo == null ? "0" : settleOrderInfo.price}", style: TextStyle( fontSize: 20.sp, fontWeight: MyFontWeight.semi_bold, @@ -462,6 +466,9 @@ class _Settlement extends State { return count; } + String coupons = ""; + String promotions = ""; + ///优惠券弹窗 couponCart() async { CouponListBean couponBean = await showModalBottomSheet( @@ -474,13 +481,15 @@ class _Settlement extends State { ); if (couponBean != null) { this.couponListBean = couponBean; - this.promotion = null; + coupons = couponListBean.promotionName; + promotions = ""; queryOrderInfo( - address != null ? address.id : null, - selectedBtn, - couponListBean != null ? couponListBean.id : null, - 0, - promotion != null ? promotion.id : null); + address != null ? address.id : null, + selectedBtn, + couponListBean != null ? couponListBean.id : null, + 0, + null, + ); } } @@ -496,11 +505,12 @@ class _Settlement extends State { ); if (pro != null) { this.promotion = pro; - this.couponListBean = null; + promotions = promotion.name; + coupons = ""; queryOrderInfo( address != null ? address.id : null, selectedBtn, - couponListBean != null ? couponListBean.id : null, + null, 0, promotion != null ? promotion.id : null, ); diff --git a/lib/settlement/settlement_view/activity_coupon_remarks.dart b/lib/settlement/settlement_view/activity_coupon_remarks.dart index cf33dcfb..52eedfaf 100644 --- a/lib/settlement/settlement_view/activity_coupon_remarks.dart +++ b/lib/settlement/settlement_view/activity_coupon_remarks.dart @@ -7,15 +7,18 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; class ActivityCouponRemarks extends StatefulWidget { final Function() couponCart; final Function() activityCart; - final CouponListBean couponListBean; - final PromotionInfoListBean promotion; + + final String coupons; + final String promotions; + final SettleOrderInfo settleOrderInfo; final int couponCount; ActivityCouponRemarks( this.couponCart, this.activityCart, - this.couponListBean, - this.promotion, + this.settleOrderInfo, + this.coupons, + this.promotions, this.couponCount, ); @@ -26,7 +29,6 @@ class ActivityCouponRemarks extends StatefulWidget { } class _ActivityCouponRemarks extends State { - @override Widget build(BuildContext context) { return Container( @@ -78,7 +80,7 @@ class _ActivityCouponRemarks extends State { ), ), Text( - widget.promotion == null ? "*优惠券与活动不可同时选择" : widget.promotion.name, + activityText(), textAlign: TextAlign.end, style: TextStyle( fontSize: 14.sp, @@ -116,9 +118,7 @@ class _ActivityCouponRemarks extends State { ), ), Text( - (widget.couponListBean == null) - ? ("未使用优惠券") - : widget.couponListBean.promotionName, + couponText(), textAlign: TextAlign.end, style: TextStyle( fontSize: 14.sp, @@ -170,4 +170,34 @@ class _ActivityCouponRemarks extends State { ), ); } + + String activityText() { + String promotion = ""; + if (widget.promotions == null || widget.promotions == "") { + promotion = "未选择任何活动"; + if (widget.settleOrderInfo == null || widget.settleOrderInfo.promotionInfoList == null) { + promotion = "暂无可选活动"; + } else if (widget.coupons != null && widget.coupons != "") { + promotion = "活动与优惠券不可同享"; + } + } else { + promotion = widget.promotions; + } + return promotion; + } + + String couponText() { + String coupon = ""; + if (widget.coupons == null || widget.coupons == "") { + coupon = "未选择任何优惠券"; + if (widget.settleOrderInfo == null || widget.settleOrderInfo.couponList == null) { + coupon = "暂无可选优惠券"; + } else if (widget.promotions != null && widget.promotions != "") { + coupon = "优惠券与活动不可同享"; + } + } else { + coupon = widget.coupons; + } + return coupon; + } } diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index 2f1987ad..835cd311 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -577,26 +577,13 @@ class _StoreOrderPage extends State ); } + /// 购物车的key,用于刷新UI GlobalKey shopCartKey = GlobalKey(); ///购物车弹窗 showShoppingCart() { queryShopCar().then((value) { this.shopCarGoods = value; - // showModalBottomSheet( - // context: context, - // backgroundColor: Colors.transparent, - // builder: (context) { - // return ShopCar( - // shopCartKey, - // this.shopCarGoods, - // clearShopCar, - // toDownOrder, - // shopCartAdd, - // shopCartReduce, - // ); - // }, - // ); dialogShowing = true; SmartDialog.show( widget: ShopCar( @@ -626,6 +613,7 @@ class _StoreOrderPage extends State ///选规格 _queryMiNiDetail(String id) async { + EasyLoading.show(status: S.current.zhengzaijiazai); BaseData baseData = await minService.miNiDetail(id); if (baseData != null && baseData.isSuccess) { showStoreSelector(baseData.data, id); @@ -634,8 +622,12 @@ class _StoreOrderPage extends State ///选规格弹窗 showStoreSelector(MiNiDetail miNiDetail, String id) async { - dialogShowing = true; - SmartDialog.show( + if (miNiDetail.attrList != null && miNiDetail.attrList.length == 1) { + _addShopCar(miNiDetail, [], 1); + } else { + EasyLoading.dismiss(); + dialogShowing = true; + SmartDialog.show( widget: ProductSku( miNiDetail, shopCarGoods, @@ -647,22 +639,28 @@ class _StoreOrderPage extends State onDismiss: () { dialogShowing = false; }, - alignmentTemp: Alignment.bottomCenter,); + alignmentTemp: Alignment.bottomCenter, + ); + } } ///添加购物车 Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async { - ProductSkuVOListBean productSku = - miNiDetail.productSkuVOList.firstWhere((element) { - bool gg = true; - selectSkus.forEach((element1) { - if (element.skuNameStr.indexOf(element1) < 0) { - gg = false; - return gg; - } + ProductSkuVOListBean productSku; + if (selectSkus!= null && selectSkus.length == 0) { + productSku = miNiDetail.productSkuVOList.first; + } else { + productSku = miNiDetail.productSkuVOList.firstWhere((element) { + bool gg = true; + selectSkus.forEach((element1) { + if (element.skuNameStr.indexOf(element1) < 0) { + gg = false; + return gg; + } + }); + return gg; }); - return gg; - }); + } if (productSku == null) return; String skuId = productSku.id; String skuValue = selectSkus @@ -693,6 +691,7 @@ class _StoreOrderPage extends State }, ], }); + EasyLoading.dismiss(); if (baseDate != null && baseDate.isSuccess) { queryShopCar().then((value) { this.shopCarGoods = value; @@ -726,8 +725,6 @@ class _StoreOrderPage extends State await minService.shoppingCartSingle(shopCarTemp); if (baseDate.isSuccess) { this.shopCarGoods = await queryShopCar(); - - print("shopingCar111111: ${this.shopCarGoods.toJson()}"); if (shopCartKey != null) { shopCartKey.currentState.setState(() {}); } @@ -746,8 +743,6 @@ class _StoreOrderPage extends State await minService.shoppingCartSingle(shopCarTemp); if (baseDate.isSuccess) { this.shopCarGoods = await queryShopCar(); - - print("shopingCar111111: ${this.shopCarGoods.toJson()}"); if (shopCartKey != null) { shopCartKey.currentState.setState(() {}); } diff --git a/lib/store/store_view/product_sku.dart b/lib/store/store_view/product_sku.dart index 829745ae..9b292e8f 100644 --- a/lib/store/store_view/product_sku.dart +++ b/lib/store/store_view/product_sku.dart @@ -177,30 +177,32 @@ class _ProductSku extends State { ), ], ), - SizedBox( - height: 23, - ), - Expanded( - child: ListView.builder( - itemCount: widget.miNiDetail.attrList.length, - scrollDirection: Axis.vertical, - physics: BouncingScrollPhysics(), - padding: EdgeInsets.zero, - itemBuilder: (context, position) { - return attrItem( - (index) { - state(() { - selectSkus[position] = widget.miNiDetail - .attrList[position].attrValueList[index].attrValue; - buildCount(); - }); - }, - widget.miNiDetail.attrList[position], - position, - ); - }, + if (widget.miNiDetail.attrList != null && widget.miNiDetail.attrList.length > 0) + SizedBox( + height: 23, + ), + if (widget.miNiDetail.attrList != null && widget.miNiDetail.attrList.length > 0) + Expanded( + child: ListView.builder( + itemCount: widget.miNiDetail.attrList.length, + scrollDirection: Axis.vertical, + physics: BouncingScrollPhysics(), + padding: EdgeInsets.zero, + itemBuilder: (context, position) { + return attrItem( + (index) { + state(() { + selectSkus[position] = widget.miNiDetail + .attrList[position].attrValueList[index].attrValue; + buildCount(); + }); + }, + widget.miNiDetail.attrList[position], + position, + ); + }, + ), ), - ), SizedBox( height: 24, ), @@ -286,23 +288,27 @@ class _ProductSku extends State { } Widget attrItem(Function fc, AttrListBean attrListBean, position) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only(top: 24, bottom: 16), - child: Text( - attrListBean.attrName, - style: TextStyle( - color: Colors.black, - fontSize: 14.sp, - fontWeight: MyFontWeight.regular, + if (attrListBean.attrValueList != null && attrListBean.attrValueList.length > 0) + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.only(top: 24, bottom: 16), + child: Text( + attrListBean.attrName, + style: TextStyle( + color: Colors.black, + fontSize: 14.sp, + fontWeight: MyFontWeight.regular, + ), ), ), - ), - sweetnessStore(fc, attrListBean.attrValueList, position), - ], - ); + sweetnessStore(fc, attrListBean.attrValueList, position), + ], + ); + else { + return Container(); + } } Widget sweetnessStore(Function fc, List arrays, position) { diff --git a/lib/store/store_view/shop_car.dart b/lib/store/store_view/shop_car.dart index d706f898..6ef893ca 100644 --- a/lib/store/store_view/shop_car.dart +++ b/lib/store/store_view/shop_car.dart @@ -121,6 +121,7 @@ class _ShopCar extends State { await widget.shopCartReduce(cart); setState(() {}); }, + isShopCart: true, count: widget.shopingCar .shoppingCartSkuItemList[position].buyNum, shoppingCartSkuItemListBean: widget.shopingCar diff --git a/lib/store/store_view/shop_goods.dart b/lib/store/store_view/shop_goods.dart index 806db92c..790c1acd 100644 --- a/lib/store/store_view/shop_goods.dart +++ b/lib/store/store_view/shop_goods.dart @@ -8,19 +8,21 @@ import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/round_button.dart'; class ShopGoods extends StatefulWidget { - final Function(String id) queryMiNiDetail; final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) add; - final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) reduce; + final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) + reduce; final ProductListBean productListBean; final ShoppingCartSkuItemListBean shoppingCartSkuItemListBean; final int count; + final bool isShopCart; ShopGoods( this.add, this.reduce, { - this.productListBean, + this.productListBean, this.count = 0, + this.isShopCart = false, this.queryMiNiDetail, this.shoppingCartSkuItemListBean, }); @@ -48,10 +50,11 @@ class _ShopGoods extends State { children: [ SizedBox(width: 12.w), MImage( - widget.productListBean != null ? widget.productListBean.imgPath : - (widget.shoppingCartSkuItemListBean != null - ? widget.shoppingCartSkuItemListBean.skuImg - : ""), + widget.productListBean != null + ? widget.productListBean.imgPath + : (widget.shoppingCartSkuItemListBean != null + ? widget.shoppingCartSkuItemListBean.skuImg + : ""), width: 70, height: 70, fit: BoxFit.cover, @@ -66,7 +69,9 @@ class _ShopGoods extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - widget.productListBean != null ? widget.productListBean.productName : widget.shoppingCartSkuItemListBean.productName, + widget.productListBean != null + ? widget.productListBean.productName + : widget.shoppingCartSkuItemListBean.productName, style: TextStyle( color: Colors.black, fontSize: 13.sp, @@ -76,13 +81,16 @@ class _ShopGoods extends State { SizedBox( height: 2, ), + ///{"id":"1442420413828169728","productId":"1432652566000304128","productName":"桂花乌龙茶","skuName":null,"buyNum":1,"skuStock":1000,"skuImg":"https://pos.upload.gznl.top/1177/2021/08/f855ffb8-d473-4f5f-93c9-5907b539b2fd.jpg", ///"skuPrice":"0.00","selected":1,"storeId":null,"groupId":"1426067376096411648","createTime":"2021-10-20 10:27:46","tableId":null,"platterList":null} Row( children: [ Expanded( child: Text( - (widget.productListBean != null ? widget.productListBean.shortName : widget.shoppingCartSkuItemListBean.skuName ?? ""), + (widget.productListBean != null + ? widget.productListBean.shortName + : widget.shoppingCartSkuItemListBean.skuName ?? ""), overflow: TextOverflow.ellipsis, maxLines: 2, style: TextStyle( @@ -154,22 +162,48 @@ class _ShopGoods extends State { ], ), Spacer(), - if (widget.count == 0) - RoundButton( - width: 49.w, - text: S.of(context).xuanguige, - textColor: Colors.white, - fontWeight: MyFontWeight.medium, - radius: 11, - backgroup: Color(0xFF32A060), - fontSize: 11.sp, - padding: EdgeInsets.symmetric(vertical: 5.h), - callback: () { - widget.queryMiNiDetail( - widget.productListBean != null ? widget.productListBean.id : widget.shoppingCartSkuItemListBean.productId); - }, + if (!widget.isShopCart) + Stack( + children: [ + Container( + margin: EdgeInsets.only(right: 8, top: 4), + child: RoundButton( + width: 49.w, + text: S.of(context).xuanguige, + textColor: Colors.white, + fontWeight: MyFontWeight.medium, + radius: 11, + backgroup: Color(0xFF32A060), + fontSize: 11.sp, + padding: EdgeInsets.symmetric(vertical: 5.h), + callback: () { + widget.queryMiNiDetail( + widget.productListBean != null + ? widget.productListBean.id + : widget.shoppingCartSkuItemListBean + .productId); + }, + ), + ), + Positioned( + right: 0, + child: Visibility( + visible: widget.count > 0, + child: RoundButton( + width: 17, + height: 17, + text: "${widget.count}", + textColor: Color(0xFF32A060), + fontWeight: MyFontWeight.regular, + backgroup: Colors.white, + fontSize: 12.sp, + radius: 100, + ), + ), + ), + ], ), - if (widget.count > 0) + if (widget.isShopCart) InkWell( onTap: () { widget.reduce(widget.shoppingCartSkuItemListBean); @@ -180,7 +214,7 @@ class _ShopGoods extends State { height: 22, ), ), - if (widget.count > 0) + if (widget.isShopCart) Container( width: 30, alignment: Alignment.center, @@ -193,7 +227,7 @@ class _ShopGoods extends State { ), ), ), - if (widget.count > 0) + if (widget.isShopCart) InkWell( onTap: () { widget.add(widget.shoppingCartSkuItemListBean); diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index dbbbb617..d3dab061 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -3,6 +3,7 @@ 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/miNiDetail.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/min_api.dart'; @@ -19,6 +20,7 @@ class StoreOrderListPage extends StatefulWidget { final StoreInfo storeInfo; final ScrollController controller; final Function(String id) queryMiNiDetail; + ShoppingCart shopCarGoods; StoreOrderListPage( @@ -44,6 +46,9 @@ class _StoreOrderListPage extends State { List appletProducts; List productListBeans = []; + ScrollController controller1 = ScrollController(); + ScrollController controller2 = ScrollController(); + @override void initState() { super.initState(); @@ -83,8 +88,6 @@ class _StoreOrderListPage extends State { } } - // RefreshController refreshController; - @override Widget build(BuildContext context) { return Container( @@ -114,8 +117,7 @@ class _StoreOrderListPage extends State { Container( width: MediaQuery.of(context).size.width - 100.w, child: ListView.builder( - itemCount: - productListBeans == null ? 0 : productListBeans.length, + itemCount: productListBeans == null ? 0 : productListBeans.length, physics: BouncingScrollPhysics(), shrinkWrap: true, padding: EdgeInsets.zero, @@ -129,9 +131,6 @@ class _StoreOrderListPage extends State { ); } - ScrollController controller1 = ScrollController(); - ScrollController controller2 = ScrollController(); - Widget orderItem(FindMiNiGroupList findMiNiGroupList, int index) { int count = calculateItemCount(findMiNiGroupList); return Container( @@ -235,13 +234,14 @@ class _StoreOrderListPage extends State { }, child: ShopGoods( (ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) { - widget.queryMiNiDetail(productListBeans[position].id); + // widget.add(productListBeans[position].id); }, (ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) { - widget.queryMiNiDetail(productListBeans[position].id); + // widget.reduce(productListBeans[position].id); }, productListBean: productListBeans[position], count: count, + isShopCart: false, queryMiNiDetail: widget.queryMiNiDetail, shoppingCartSkuItemListBean: shoppingCartSkuItemListBean, ),