From 4a7a13067527182da923e82cdba91e5240b49437 Mon Sep 17 00:00:00 2001 From: w-R <953969641@qq.com> Date: Wed, 5 Jan 2022 15:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E5=8B=BE=E9=80=89;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mine/mine_page.dart | 35 +- lib/mine/mine_view/mine_item.dart | 5 +- lib/retrofit/data/shoppingCart.dart | 1 - .../settlement_view/distribution.dart | 2 +- .../shopping/activity_prefecture_details.dart | 15 +- .../shopping_cart/cart_goods_list.dart | 203 -------- .../shopping_cart/shopping_cart_page.dart | 465 +++++++++++++----- .../shopping/shopping_goods_details.dart | 423 ++++++++-------- .../shopping/shopping_home/search_page.dart | 41 +- lib/store/shopping/shopping_mall_home.dart | 243 +-------- lib/union/union_page.dart | 2 +- 11 files changed, 637 insertions(+), 798 deletions(-) delete mode 100644 lib/store/shopping/shopping_cart/cart_goods_list.dart diff --git a/lib/mine/mine_page.dart b/lib/mine/mine_page.dart index c6397f88..15ba7165 100644 --- a/lib/mine/mine_page.dart +++ b/lib/mine/mine_page.dart @@ -187,9 +187,6 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { }, ), - ///关注度/粉丝/发布 - attention(), - ///我的 VIP等级信息 MineVipView( tag: "vip", @@ -199,10 +196,15 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { rankMax: userInfo?.memberRankVo?.nextOrigin??0, createTime: userInfo?.createTime??"", ), + ], ), ), + + ///关注度/粉丝/发布 + attention(), + /// 钱包或领券中心 WalletCoupon(), @@ -300,7 +302,20 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { ///关注度/粉丝/成就数量 Widget attention(){ return Container( - margin: EdgeInsets.only(left: 16,top: 10), + padding: EdgeInsets.only(bottom: 16,top: 16), + margin: EdgeInsets.only(left: 16,top:16,right: 16), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ), + ], + ), child:GestureDetector( onTap:(){ Navigator.of(context).pushNamed( @@ -320,7 +335,7 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { ); }, child: - Row( + Column( children: [ Text( S.of(context).guanzhu, @@ -330,7 +345,7 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { fontWeight: MyFontWeight.regular, ), ), - SizedBox(width: 5,), + SizedBox(height: 5,), Text( infoNumber != null ?infoNumber.follow.toString() :"0", style: TextStyle( @@ -350,7 +365,7 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { ); }, child: - Row( + Column( children: [ Text( S.of(context).fensi, @@ -360,7 +375,7 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { fontWeight: MyFontWeight.regular, ), ), - SizedBox(width: 5,), + SizedBox(height: 5,), Text( infoNumber != null ?infoNumber.fans.toString() :"0", style: TextStyle( @@ -380,7 +395,7 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { ); }, child: - Row( + Column( children: [ Text( "成就", @@ -390,7 +405,7 @@ class _MinePage extends State with AutomaticKeepAliveClientMixin { fontWeight: MyFontWeight.regular, ), ), - SizedBox(width: 5,), + SizedBox(height: 5,), Text( infoNumber != null ?infoNumber.achievementNumber.toString() :"0", style: TextStyle( diff --git a/lib/mine/mine_view/mine_item.dart b/lib/mine/mine_view/mine_item.dart index 2193cadf..31d1962f 100644 --- a/lib/mine/mine_view/mine_item.dart +++ b/lib/mine/mine_view/mine_item.dart @@ -16,7 +16,7 @@ class _MineItem extends State { @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.fromLTRB(16.w, 10.h, 16.w, 28.h), + margin: EdgeInsets.fromLTRB(16.w, 10.h, 16.w, 6.h), padding: EdgeInsets.fromLTRB(20.w, 12.h, 20.w, 12.h), decoration: BoxDecoration( color: Colors.white, @@ -134,7 +134,8 @@ class _MineItem extends State { SizedBox(height: 10.h,), Row( children: [ - Expanded(child: InkWell( + Expanded(child: + InkWell( onTap: () { SharedPreferences.getInstance().then((value) { if (value.getString("token") == null || diff --git a/lib/retrofit/data/shoppingCart.dart b/lib/retrofit/data/shoppingCart.dart index eb18422b..2126eb88 100644 --- a/lib/retrofit/data/shoppingCart.dart +++ b/lib/retrofit/data/shoppingCart.dart @@ -18,7 +18,6 @@ class ShoppingCart { int selectDiscount; String storeName; String tableId; - bool isSelect; List promotionInfoList; List couponList; diff --git a/lib/settlement/settlement_view/distribution.dart b/lib/settlement/settlement_view/distribution.dart index 474906e9..90883fd2 100644 --- a/lib/settlement/settlement_view/distribution.dart +++ b/lib/settlement/settlement_view/distribution.dart @@ -86,7 +86,7 @@ class _DistributionMode extends State { @override Widget build(BuildContext context) { return Container( - height: 143.h, + height: 147.h, margin: EdgeInsets.only( left: 16, right: 16, diff --git a/lib/store/shopping/activity_prefecture_details.dart b/lib/store/shopping/activity_prefecture_details.dart index 9f67cbca..4b3b5482 100644 --- a/lib/store/shopping/activity_prefecture_details.dart +++ b/lib/store/shopping/activity_prefecture_details.dart @@ -77,8 +77,6 @@ class _ActivityPrefectureDetails extends State { }); }); - // testTime = "${DateTime.now().year}-${DateTime.now().month}-${DateTime.now().day} 08:00:20"; - pageType = widget.arguments["type"]; storeId = widget.arguments["storeId"]; tenant = widget.arguments["tenant"]; @@ -99,11 +97,10 @@ class _ActivityPrefectureDetails extends State { showLoading: false, ); apiService.minLogin(storeId).catchError((onError) { - debugPrint(onError); + debugPrint(onError.toString()); }).then((baseData) { if (baseData != null && baseData.isSuccess) { - Map minStoreInfo = baseData.data; - minToken = minStoreInfo["token"]; + minToken = baseData.data["token"]; queryStoreInfo(); SharedPreferences.getInstance().then( (value) => { @@ -120,7 +117,8 @@ class _ActivityPrefectureDetails extends State { storeId: storeId, showLoading: false, ); - queryFindActListByType(pageType == "2" ?false:true); + + queryStoreInfo(); EasyLoading.dismiss(); } @@ -562,7 +560,6 @@ class _ActivityPrefectureDetails extends State { ///秒杀列表 Widget seckilList() { - // var tStatus = timeFlag(actTimeList[actTimeListIndex].actTime.startHour); return Container( height: MediaQuery.of(context).size.height - 62.h - @@ -790,7 +787,7 @@ class _ActivityPrefectureDetails extends State { color: Color(0xFFF5F5F5), ), Container( - width: 100.w, + width:productList.sellCount == 0 ? 0 :(((productList?.sellCount ?? 0)/(productList?.productStock ?? 0)) * 180.w).toDouble(), height: 8.h, decoration: BoxDecoration( gradient: LinearGradient( @@ -807,7 +804,7 @@ class _ActivityPrefectureDetails extends State { width: 5, ), Text( - "已售${productList.sellCount}", + "已售${productList.sellCount}件", style: TextStyle( fontSize: 10.sp, fontWeight: MyFontWeight.regular, diff --git a/lib/store/shopping/shopping_cart/cart_goods_list.dart b/lib/store/shopping/shopping_cart/cart_goods_list.dart deleted file mode 100644 index fccc1bec..00000000 --- a/lib/store/shopping/shopping_cart/cart_goods_list.dart +++ /dev/null @@ -1,203 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:huixiang/retrofit/retrofit_api.dart'; -import 'package:huixiang/utils/font_weight.dart'; -import 'package:huixiang/view_widget/classic_header.dart'; -import 'package:huixiang/view_widget/my_footer.dart'; -import 'package:pull_to_refresh/pull_to_refresh.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; -class CartGoodsList extends StatefulWidget { - - @override - State createState() { - return _CartGoodsList(); - } -} - -class _CartGoodsList extends State { - RefreshController refreshController = RefreshController(); - ApiService apiService; - int pageNum = 0; - - @override - void initState() { - super.initState(); - _onRefresh(); - } - - _onRefresh() async { - pageNum = 0; - setState(() {}); - } - - @override - Widget build(BuildContext context) { - return Container( - height: MediaQuery.of(context).size.height - - 103.h - - MediaQuery.of(context).padding.top, - child: SmartRefresher( - controller: refreshController, - enablePullUp: false, - enablePullDown: true, - physics: BouncingScrollPhysics(), - header: MyHeader(), - onRefresh: () { - }, - child: ListView.builder( - itemCount:6, - padding: EdgeInsets.only( - top: 8.h, - bottom: 84.h, /* + (375.h - 88.h) + 4.h*/ - ), - physics: NeverScrollableScrollPhysics(), - itemBuilder: (context, position) { - return InkWell( - onTap: () { - }, - child: cartGoodsItem(), - ); - }), - ), - ); - } - - Widget cartGoodsItem() { - return Container( - margin: EdgeInsets.all(16), - padding: EdgeInsets.all(16), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ), - ], - color: Colors.white, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Image.asset( - // ? "assets/image/icon_radio_selected.png" : - "assets/image/icon_radio_unselected.png", - width:16, - height:16, - ), - SizedBox(width: 16.w), - // MImage( - // "assets/image/icon_story_td.png", - // isCircle: true, - // width:81, - // height:81, - // fit: BoxFit.cover, - // errorSrc: "assets/image/default_1.png", - // fadeSrc: "assets/image/default_1.png", - // ), - Image.asset( - "assets/image/icon_story_td.png", - width: 81, - height: 81, - fit: BoxFit.cover, - ), - SizedBox(width: 10.w), - Expanded(child: - Container( - height:81.h,child:Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "[生态小农]山林放养鸡蛋30枚/盒", - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFF353535), - ), - ), - // SizedBox(height: 5.h), - Text( - "套盒装", - 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: "58.2", - style: TextStyle( - fontSize: 14.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF32A060), - ), - ), - ], - ), - )), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center,children: [ - InkWell( - onTap: () { - setState(() { - }); - }, - child: Image.asset( - "assets/image/reduce.png", - width: 22, - height: 22, - ), - ), - Container( - width: 30, - alignment: Alignment.center, - child: Text( - "1", - style: TextStyle( - color: Colors.black, - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - ), - ), - ), - InkWell( - onTap: () { - }, - child: Image.asset( - "assets/image/add.png", - width: 22, - height: 22, - ), - ), - ],) - ], - ), - ], - )),), - ], - ), - ); - } -} diff --git a/lib/store/shopping/shopping_cart/shopping_cart_page.dart b/lib/store/shopping/shopping_cart/shopping_cart_page.dart index 5610cb72..94795f97 100644 --- a/lib/store/shopping/shopping_cart/shopping_cart_page.dart +++ b/lib/store/shopping/shopping_cart/shopping_cart_page.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; @@ -9,23 +9,22 @@ 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/shopping/shopping_home/recommend_goods_list_view.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/classic_header.dart'; +import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; -import 'package:huixiang/view_widget/round_button.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'cart_goods_list.dart'; class ShoppingCartPage extends StatefulWidget { final String minToken; final String storeId; final String tenant; + final StoreInfo storeInfo; - ShoppingCartPage(this.minToken,this.storeId, this.tenant); + ShoppingCartPage(this.minToken,this.storeId, this.tenant,this.storeInfo); @override State createState() { return _ShoppingCartPage(); @@ -36,7 +35,6 @@ class _ShoppingCartPage extends State with AutomaticKeepAliveClientMixin { ApiService apiService; MinApiService minService; - // ShoppingCart shopCarGoods; List shopCarGoods = []; String pName; String pid; @@ -44,35 +42,62 @@ class _ShoppingCartPage extends State String cid; int tableId = 0; bool topIndex = false; + bool isAllSelect = false; @override void initState() { super.initState(); - SharedPreferences.getInstance().then((value) { - minService = MinApiService( - Dio(), - context: context, - token: widget.minToken, - tenant: widget.tenant, - storeId: widget.storeId, - showLoading: false, - ); - queryShopCar(); - }); + queryShopCar(); } ///清空购物车 clearShopCar() async { BaseData baseData = await minService.clearShoppingCart(); if (baseData.isSuccess) { - shopCarGoods = null; - setState(() {}); + queryShopCar(); } } - ///查询购物商品 + ///去下单结算页面 + toDownOrder() async { + // int num = count(); + + // if (num == 0) { + // SmartDialog.showToast("请先选择您要购买的商品!~"); + // return; + // } + await Navigator.of(context).pushNamed( + '/router/settlement', + arguments: { + "storeInfo": widget.storeInfo, + "tableId": tableId, + // "parentCode": parentCode, + // "parentId": parentId, + "pName":pName, + "pid":pid, + "cName":cName, + "cid":cid, + "shoppingCart": shopCarGoods, + // "numberOfPeople": numberOfPeople, + }, + ); + queryShopCar(); + } + + ///查询购物车商品 queryShopCar() async { + if(widget.minToken == null) + return; + if(minService == null) + minService = MinApiService( + Dio(), + context: context, + token: widget.minToken, + tenant: widget.tenant, + storeId: widget.storeId, + showLoading: false, + ); BaseData> baseData = await minService.getShoppingCart(tableId).catchError((error) { refreshController.refreshFailed(); @@ -121,44 +146,22 @@ class _ShoppingCartPage extends State // } // } - /// 购物车的key,用于刷新UI - GlobalKey shopCartKey = GlobalKey(); - - ///购物车➕1 - // Future shopCartAdd( - // ShoppingCartSkuItemListBean cartSkuItem) async { - // Map shopCarTemp = shopCarGoods.toJson(); - // cartSkuItem.buyNum += 1; - // shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - // BaseData> baseDate = - // await minService.shoppingCartSingle(shopCarTemp); - // if (baseDate.isSuccess) { - // this.shopCarGoods = await queryShopCar(); - // if (shopCartKey != null) { - // shopCartKey.currentState.setState(() {}); - // } - // setState(() {}); - // } - // return this.shopCarGoods; - // } - // - // ///购物车➖1 - // Future shopCartReduce( - // ShoppingCartSkuItemListBean cartSkuItem) async { - // Map shopCarTemp = shopCarGoods.toJson(); - // cartSkuItem.buyNum -= 1; - // shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - // BaseData> baseDate = - // await minService.shoppingCartSingle(shopCarTemp); - // if (baseDate.isSuccess) { - // this.shopCarGoods = await queryShopCar(); - // if (shopCartKey != null) { - // shopCartKey.currentState.setState(() {}); - // } - // setState(() {}); - // } - // return this.shopCarGoods; - // } + ///购物车数量修改 + shopCartAdd( + ShoppingCartSkuItemListBean cartSkuItem,int count,int selected) async { + Map shopCarTemp = shopCarGoods[0].toJson(); + cartSkuItem.buyNum += count; + cartSkuItem.selected = 0; + shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; + BaseData> baseDate = + await minService.shoppingCartSingle(shopCarTemp); + if (baseDate.isSuccess) { + setState(() { + queryShopCar(); + }); + } + refreshController.refreshFailed(); + } final SwiperController controller = SwiperController(); @@ -192,7 +195,7 @@ 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, @@ -212,17 +215,19 @@ class _ShoppingCartPage extends State header: MyHeader(), physics: BouncingScrollPhysics(), onRefresh: () { - setState(() {}); + setState(() { + queryShopCar(); + }); }, child: SingleChildScrollView( physics: NeverScrollableScrollPhysics(), child: FutureBuilder( - // future: queryHome(), + // future: queryShopCar(), builder: (context, snapshot) { return Column( children: [ ///购物车商品列表 - CartGoodsList(), + cartGoodsList(), ], ); }, @@ -255,10 +260,21 @@ class _ShoppingCartPage extends State mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.center, children: [ - Image.asset( - "assets/image/icon_radio_unselected.png", - width: 16, - height: 16, + GestureDetector( + onTap: (){ + setState(() { + isAllSelect = !isAllSelect; + shopCarGoods[0].shoppingCartSkuItemList.forEach((element) { + element.selected = isAllSelect?1:0; + }); + }); + }, + child:Image.asset( + isAllSelect ? "assets/image/icon_radio_selected.png" : + "assets/image/icon_radio_unselected.png", + width: 16, + height: 16, + ), ), SizedBox(width: 5.w), Expanded(child: Text( @@ -269,81 +285,96 @@ class _ShoppingCartPage extends State color: Color(0xFFA29E9E), ), ),), - Text.rich( - TextSpan( - children: [ + !topIndex ? + Row( + children: [ + Text.rich( TextSpan( - text: "合计:", + 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), + ), + ), + + ], + ), + ), + 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: 12.sp, + fontSize: 16.sp, fontWeight: MyFontWeight.regular, - color: Colors.black, + color: Colors.white, ), ), - TextSpan( - text: "¥20.4", - style: TextStyle( - fontSize: 20.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF32A060), + ),), + ], + ): + 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, + ), ), ), - - ], - ), - ), - 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, ), - ), - ), - // 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, - // ), - // ), - // ), + ], ), ), @@ -352,6 +383,174 @@ class _ShoppingCartPage extends State ); } + Widget cartGoodsList(){ + return 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) { + return Container( + margin: EdgeInsets.all(16), + padding: EdgeInsets.all(16), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ), + ], + color: Colors.white, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + GestureDetector( + onTap: (){ + setState(() { + shopCarGoods[0].shoppingCartSkuItemList[index].selected = (shopCarGoods[0].shoppingCartSkuItemList[index].selected == 1) ? 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.png" : + "assets/image/icon_radio_unselected.png", + width:16, + height:16, + ), + ), + SizedBox(width: 16.w), + MImage( + shopCarGoods[0].shoppingCartSkuItemList[index]?.skuImg ?? "", + isCircle: true, + width:81, + height:81, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.png", + fadeSrc: "assets/image/default_1.png", + ), + 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.png", + 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.png", + width: 22, + height: 22, + ), + ), + ],) + ], + ), + ], + )),), + ], + ), + ); + } @override bool get wantKeepAlive => true; diff --git a/lib/store/shopping/shopping_goods_details.dart b/lib/store/shopping/shopping_goods_details.dart index c7564a29..77f86c7d 100644 --- a/lib/store/shopping/shopping_goods_details.dart +++ b/lib/store/shopping/shopping_goods_details.dart @@ -22,7 +22,10 @@ import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/store/store_view/product_sku.dart'; import 'package:huixiang/store/store_view/store_order_list.dart'; import 'package:huixiang/utils/font_weight.dart'; +import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; +import 'package:huixiang/view_widget/my_footer.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -31,6 +34,7 @@ class ShoppingGoodsDetails extends StatefulWidget { final Map arguments; ShoppingGoodsDetails({this.arguments}); + @override State createState() { return _ShoppingGoodsDetails(); @@ -38,6 +42,8 @@ class ShoppingGoodsDetails extends StatefulWidget { } class _ShoppingGoodsDetails extends State { + final RefreshController refreshController = RefreshController(); + final ScrollController scrollController = ScrollController(); ApiService apiService; MinApiService minService; String tenant; @@ -64,15 +70,9 @@ class _ShoppingGoodsDetails extends State { tenant = widget.arguments["tenant"]; id = widget.arguments["id"]; + debugPrint("store_param tenant:$tenant storeId:$storeId"); + SharedPreferences.getInstance().then((value) { - minService = MinApiService( - Dio(), - context: context, - token: minToken, - tenant: tenant, - storeId: storeId, - showLoading: false, - ); minLogin(value); queryStoreInfo(); queryMiNiDetail(id); @@ -89,14 +89,13 @@ class _ShoppingGoodsDetails extends State { showLoading: false, ); apiService.minLogin(storeId).catchError((onError) { - debugPrint(onError); + debugPrint(onError.toString()); }).then((baseData) { if (baseData != null && baseData.isSuccess) { - Map minStoreInfo = baseData.data; - minToken = minStoreInfo["token"]; + minToken = baseData.data["token"]; queryStoreInfo(); SharedPreferences.getInstance().then( - (value) => { + (value) => { value.setString('minToken', minToken), value.setString('tenant', tenant), value.setString('storeId', storeId), @@ -110,6 +109,9 @@ class _ShoppingGoodsDetails extends State { storeId: storeId, showLoading: false, ); + + queryStoreInfo(); + EasyLoading.dismiss(); } }); @@ -117,8 +119,9 @@ class _ShoppingGoodsDetails extends State { /// 查询店铺信息 queryStoreInfo() async { - BaseData baseData = await apiService.queryStoreInfo(storeId).catchError((error) { - debugPrint(error); + BaseData baseData = + await apiService.queryStoreInfo(storeId).catchError((error) { + debugPrint(error.toString()); }); if (baseData != null && baseData.isSuccess) { storeInfo = StoreInfo.fromJson(baseData.data); @@ -134,19 +137,32 @@ class _ShoppingGoodsDetails extends State { ///商品详情 queryMiNiDetail(id) async { - EasyLoading.show(status: S.current.zhengzaijiazai); - BaseData baseData = await minService.miNiDetail(id); + if (minService == null) + minService = MinApiService( + Dio(), + context: context, + token: minToken, + tenant: tenant, + storeId: storeId, + showLoading: false, + ); + BaseData baseData = + await minService.miNiDetail(id).catchError((error) { + refreshController.refreshFailed(); + }); if (baseData != null && baseData.isSuccess) { miNiDetail = baseData.data; - + refreshController.refreshCompleted(); + } else { + refreshController.refreshFailed(); } - EasyLoading.dismiss(); } ///选规格弹窗 - showStoreSelector(MiNiDetail miNiDetail, String id,int count) async { - if (miNiDetail.attrList != null && miNiDetail.attrList.length == 1 - && miNiDetail.attrList[0].attrValueList.length == 1) { + showStoreSelector(MiNiDetail miNiDetail, String id, int count) async { + if (miNiDetail.attrList != null && + miNiDetail.attrList.length == 1 && + miNiDetail.attrList[0].attrValueList.length == 1) { _addShopCar(miNiDetail, [], count); } else { EasyLoading.dismiss(); @@ -171,7 +187,7 @@ class _ShoppingGoodsDetails extends State { ///选规格添加购物车 Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async { - if (selectSkus!= null && selectSkus.length == 0) { + if (selectSkus != null && selectSkus.length == 0) { productSku = miNiDetail.productSkuVOList.first; } else { productSku = miNiDetail.productSkuVOList.firstWhere((element) { @@ -200,44 +216,40 @@ class _ShoppingGoodsDetails extends State { } ///商品➕1 - add(MiNiDetail miNiDetail, selectSkus) async { + add(MiNiDetail miNiDetail, selectSkus) async {} - } ///商品➖1 - reduce(MiNiDetail miNiDetail, selectSkus) async { - - } + reduce(MiNiDetail miNiDetail, selectSkus) async {} ///添加购物车按钮 addShoppingCar() async { - BaseData> baseDate = await minService.addShoppingCart({ - "storeId":storeId, - "storeName": storeInfo?.storeName ?? "", - "numberOfPeople": numberOfPeople, - "tableId": tableId, - "parentId": parentId, - "parentCode": parentCode, - "shoppingCartSkuItemList": [ - { - "buyNum": count1, - "id":skuId1, - "productId": miNiDetail.id, - "productName": miNiDetail.productName, - "skuName": skuValue1, - "storeId":storeId, - "skuPrice": productSku.skuPrice, - "skuStock": productSku.skuStock, - "tableId": tableId, - }, - ], - }); - EasyLoading.dismiss(); - if (baseDate != null && baseDate.isSuccess) { - SmartDialog.showToast("添加购物车成功", alignment: Alignment.center); - } + BaseData> baseDate = await minService.addShoppingCart({ + "storeId": storeId, + "storeName": storeInfo?.storeName ?? "", + "numberOfPeople": numberOfPeople, + "tableId": tableId, + "parentId": parentId, + "parentCode": parentCode, + "shoppingCartSkuItemList": [ + { + "buyNum": count1, + "id": skuId1, + "productId": miNiDetail.id, + "productName": miNiDetail.productName, + "skuName": skuValue1, + "storeId": storeId, + "skuPrice": productSku.skuPrice, + "skuStock": productSku.skuStock, + "tableId": tableId, + }, + ], + }); + EasyLoading.dismiss(); + if (baseDate != null && baseDate.isSuccess) { + SmartDialog.showToast("添加购物车成功", alignment: Alignment.center); + } } - @override Widget build(BuildContext context) { return Stack( @@ -247,62 +259,82 @@ class _ShoppingGoodsDetails extends State { child: Column( children: [ Expanded( - child: SingleChildScrollView( - physics: BouncingScrollPhysics(), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - buildColumn(), + child: Container( + child: SmartRefresher( + controller: refreshController, + enablePullDown: true, + enablePullUp: true, + header: MyHeader(), + physics: BouncingScrollPhysics(), + scrollController: scrollController, + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); + }, + ), + onRefresh: () { + setState(() { + queryMiNiDetail(id); + }); + }, + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + buildColumn(), - ///拼团 - groupOption(), + ///拼团 + groupOption(), - ///拼团规则 - groupRule(), - goodsOption(), - Padding( - padding: EdgeInsets.only(top: 16.h, bottom: 12.h), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - width: 21, - height: 1.h, - color: Color(0xFF979797), + ///拼团规则 + groupRule(), + goodsOption(), + Padding( + padding: EdgeInsets.only(top: 16.h, bottom: 12.h), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + width: 21, + height: 1.h, + color: Color(0xFF979797), + ), + Text( + "商品详情", + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFF585858), + ), + ), + Container( + width: 21, + height: 1.h, + color: Color(0xFF979797), + ), + ], ), - Text( - "商品详情", - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF585858), - ), - ), - Container( - width: 21, - height: 1.h, - color: Color(0xFF979797), - ), - ], - ), - ), - Container( - color: Colors.white, - margin: EdgeInsets.only(bottom:72.h), - child: Html( - data:miNiDetail?.detail ?? "", - customImageRenders: { - networkSourceMatcher(): networkImageRender( - loadingWidget: () { - return Container(); + ), + Container( + color: Colors.white, + margin: EdgeInsets.only(bottom: 72.h), + child: Html( + data: miNiDetail?.detail ?? "", + customImageRenders: { + networkSourceMatcher(): networkImageRender( + loadingWidget: () { + return Container(); + }, + ), }, ), - }, - ), + ), + ], ), - ], + ), ), ), flex: 1, @@ -313,7 +345,7 @@ class _ShoppingGoodsDetails extends State { Align( alignment: Alignment.bottomCenter, child: Container( - height:80.h, + height: 80.h, width: double.infinity, decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), @@ -334,11 +366,11 @@ class _ShoppingGoodsDetails extends State { children: [ GestureDetector( onTap: () { - setState(() { - Navigator.of(context) - .pushNamed('/router/shopping_mall_home', arguments: { - "type": 1, - }); + Navigator.of(context) + .pushNamed('/router/shopping_mall_home', arguments: { + "type": 1, + "id": storeId, + "tenant": tenant }); }, child: Column( @@ -402,16 +434,16 @@ class _ShoppingGoodsDetails extends State { child: Row( children: [ GestureDetector( - onTap: (){ - setState(() { - addShoppingCar(); - }); + onTap: () { + if (productSku == null) + SmartDialog.showToast("请选择規格!", alignment: Alignment.center); + addShoppingCar(); }, - child:Container( + child: Container( alignment: Alignment.center, width: 120.w, - height:37.h, - margin: EdgeInsets.only(left:6.w), + height: 37.h, + margin: EdgeInsets.only(left: 6.w), decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), border: Border.all( @@ -431,36 +463,36 @@ class _ShoppingGoodsDetails extends State { ), ), GestureDetector( - onTap: (){ - // toDownOrder(); - }, - child: Container( - alignment: Alignment.center, - width: 120.w, - height:37.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, + onTap: () { + // toDownOrder(); + }, + child: Container( + alignment: Alignment.center, + width: 120.w, + height: 37.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, ), - ], - ), - child: Text( - "立即购买", - style: TextStyle( - fontSize: 16.sp, - fontWeight: MyFontWeight.regular, - color: Colors.white, ), - ), - ) - ), + )), + ///秒杀按钮 // GestureDetector( // onTap: (){ @@ -794,7 +826,7 @@ class _ShoppingGoodsDetails extends State { ), ), TextSpan( - text:miNiDetail?.price ?? "", + text: miNiDetail?.price ?? "", style: TextStyle( fontSize: 28.sp, fontWeight: MyFontWeight.semi_bold, @@ -862,7 +894,7 @@ class _ShoppingGoodsDetails extends State { color: Color(0xFF5A5A5A), ), child: Text( - miNiDetail?.supplierName ?? "", + miNiDetail?.supplierName ?? "", style: TextStyle( fontSize: 10.sp, fontWeight: MyFontWeight.regular, @@ -876,7 +908,7 @@ class _ShoppingGoodsDetails extends State { height: 8.h, ), Text( - miNiDetail?.shortName ?? "", + miNiDetail?.shortName ?? "", maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle( @@ -911,17 +943,14 @@ class _ShoppingGoodsDetails extends State { ), ), itemBuilder: (context, position) { - return - miNiDetail == null - ? - Container() + return miNiDetail == null + ? Container() : Image.network( miNiDetail.imgs.elementAt(position), fit: BoxFit.cover, - ) - ; + ); }, - itemCount:miNiDetail?.imgs?.length ?? 0, + itemCount: miNiDetail?.imgs?.length ?? 0, ), GestureDetector( onTap: () { @@ -1019,7 +1048,7 @@ class _ShoppingGoodsDetails extends State { ), Expanded( child: Text( - ( skuValue1 ?? "请选择規格") + (count1 > 0 ? "x${count1}" : ""), + (skuValue1 ?? "请选择規格") + (count1 > 0 ? "x${count1}" : ""), overflow: TextOverflow.ellipsis, maxLines: 2, style: TextStyle( @@ -1032,7 +1061,7 @@ class _ShoppingGoodsDetails extends State { GestureDetector( onTap: () { setState(() { - showStoreSelector(miNiDetail, id,1); + showStoreSelector(miNiDetail, id, 1); }); }, child: Icon( @@ -1121,12 +1150,13 @@ class _ShoppingGoodsDetails extends State { ), ), GestureDetector( - onTap: (){ + onTap: () { setState(() { - Navigator.of(context).popAndPushNamed('/router/group_page_details'); + Navigator.of(context) + .popAndPushNamed('/router/group_page_details'); }); }, - child: Text( + child: Text( "更多", style: TextStyle( fontSize: 11.sp, @@ -1577,44 +1607,43 @@ class _ShoppingGoodsDetails extends State { } ///联系电话 -showCallMobile() { - showCupertinoModalPopup( - context: context, - builder: (context) { - return CupertinoActionSheet( - title: Text(S.of(context).bodadianhua), - actions: [ - if (storeInfo != null && - storeInfo.tel != null && - storeInfo.tel != "") - CupertinoActionSheetAction( - child: Text(storeInfo.tel), - onPressed: () { - callMobile(storeInfo.tel); - Navigator.of(context).pop(); - }, - isDefaultAction: true, - isDestructiveAction: false, - ), - ], - cancelButton: CupertinoActionSheetAction( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text(S.of(context).quxiao), - isDestructiveAction: true, - ), - ); - }); -} - -callMobile(mobile) async { - String url = "tel:$mobile"; - if (await canLaunch(url)) { - await launch(url); - } else { - throw 'Could not launch $url'; + showCallMobile() { + showCupertinoModalPopup( + context: context, + builder: (context) { + return CupertinoActionSheet( + title: Text(S.of(context).bodadianhua), + actions: [ + if (storeInfo != null && + storeInfo.tel != null && + storeInfo.tel != "") + CupertinoActionSheetAction( + child: Text(storeInfo.tel), + onPressed: () { + callMobile(storeInfo.tel); + Navigator.of(context).pop(); + }, + isDefaultAction: true, + isDestructiveAction: false, + ), + ], + cancelButton: CupertinoActionSheetAction( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text(S.of(context).quxiao), + isDestructiveAction: true, + ), + ); + }); } -} + callMobile(mobile) async { + String url = "tel:$mobile"; + if (await canLaunch(url)) { + await launch(url); + } else { + throw 'Could not launch $url'; + } + } } diff --git a/lib/store/shopping/shopping_home/search_page.dart b/lib/store/shopping/shopping_home/search_page.dart index 7ac7e71d..a4484aeb 100644 --- a/lib/store/shopping/shopping_home/search_page.dart +++ b/lib/store/shopping/shopping_home/search_page.dart @@ -11,6 +11,7 @@ import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/classic_header.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/view_widget/custom_image.dart'; +import 'package:huixiang/view_widget/my_footer.dart'; import 'package:huixiang/view_widget/round_button.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -81,8 +82,8 @@ class _SearchPage extends State with AutomaticKeepAliveClientMixin, editingController.text =widget.arguments["searchKey"]; }); appletGoods(widget.arguments["searchKey"]); - } + getHistorySearch(); } ///获取保存列表 @@ -101,6 +102,8 @@ class _SearchPage extends State with AutomaticKeepAliveClientMixin, ///保存列表 setHistorySearch(String text)async{ + if(text == null || text.trim() == "") + return; SharedPreferences value = await SharedPreferences.getInstance(); var str = value.getString("historySearch"); if(str == null ) @@ -125,6 +128,9 @@ class _SearchPage extends State with AutomaticKeepAliveClientMixin, ///小程序查询分组及商品列表 appletGoods(String text) async { + if(editingController.text.trim() == ""){ + return; + } if(minService == null) minService = MinApiService( Dio(), @@ -160,6 +166,11 @@ class _SearchPage extends State with AutomaticKeepAliveClientMixin, }); } + _onRefresh(){ + appletGoods(editingController.text); + refreshController.refreshCompleted(); + } + @override Widget build(BuildContext context) { return Stack( @@ -341,16 +352,21 @@ class _SearchPage extends State with AutomaticKeepAliveClientMixin, child: SmartRefresher( controller: refreshController, enablePullDown: true, - enablePullUp: false, + enablePullUp: true, header: MyHeader(), physics: BouncingScrollPhysics(), - onRefresh: () { - setState(() {}); + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); }, + ),onRefresh: () { + setState(() { + _onRefresh(); + }); + }, child: SingleChildScrollView( physics: NeverScrollableScrollPhysics(), child: FutureBuilder( - // future: queryHome(), builder: (context, snapshot) { return Column( children: [ @@ -411,6 +427,12 @@ class _SearchPage extends State with AutomaticKeepAliveClientMixin, itemBuilder: (context, index) { return GestureDetector( onTap: () { + setState(() { + if(hotSearch[index] != null){ + editingController.text =hotSearch[index]; + appletGoods(hotSearch[index]); + } + }); }, child: hotSearchItem(hotSearch[index]), ); @@ -501,7 +523,14 @@ class _SearchPage extends State with AutomaticKeepAliveClientMixin, ), itemBuilder: (context, index) { return GestureDetector( - onTap: () {}, + onTap: () { + setState(() { + if(historySearch[index] != null){ + editingController.text =historySearch[index]; + appletGoods(historySearch[index]); + } + }); + }, child: historySearchItem(historySearch[index]), ); }, diff --git a/lib/store/shopping/shopping_mall_home.dart b/lib/store/shopping/shopping_mall_home.dart index 14608397..1b20da39 100644 --- a/lib/store/shopping/shopping_mall_home.dart +++ b/lib/store/shopping/shopping_mall_home.dart @@ -32,7 +32,6 @@ class _ShoppingMallHome extends State int choiceIndex = 0; String storeId = ""; String tenant = ""; - ///小程序token String minToken; StoreInfo storeInfo; @@ -64,11 +63,12 @@ class _ShoppingMallHome extends State showLoading: false, ); apiService.minLogin(storeId).catchError((onError) { - debugPrint(onError); + debugPrint(onError.toString()); }).then((baseData) { if (baseData != null && baseData.isSuccess) { - Map minStoreInfo = baseData.data; - minToken = minStoreInfo["token"]; + setState(() { + minToken = baseData.data["token"]; + }); queryStoreInfo(); SharedPreferences.getInstance().then( (value) => { @@ -86,14 +86,6 @@ class _ShoppingMallHome extends State showLoading: false, ); - - // queryShopCar().then((value) { - // this.shopCarGoods = value; - // setState(() {}); - // }); - // if (tableId > 0) { - // getParentInfo(); - // } EasyLoading.dismiss(); } }); @@ -103,7 +95,7 @@ class _ShoppingMallHome extends State queryStoreInfo() async { BaseData baseData = await apiService.queryStoreInfo(storeId).catchError((error) { - debugPrint(error); + debugPrint(error.toString()); }); if (baseData != null && baseData.isSuccess) { storeInfo = StoreInfo.fromJson(baseData.data); @@ -117,226 +109,6 @@ class _ShoppingMallHome extends State EasyLoading.dismiss(); } - // ///选规格 - // _queryMiNiDetail(String id,int count) async { - // EasyLoading.show(status: S.current.zhengzaijiazai); - // BaseData baseData = await minService.miNiDetail(id); - // if (baseData != null && baseData.isSuccess) { - // showStoreSelector(baseData.data, id,count); - // } - // } - // - // ///选规格弹窗 - // showStoreSelector(MiNiDetail miNiDetail, String id,int count) async { - // if (miNiDetail.attrList != null && miNiDetail.attrList.length == 1 - // && miNiDetail.attrList[0].attrValueList.length == 1) { - // _addShopCar(miNiDetail, [], count); - // } else { - // EasyLoading.dismiss(); - // dialogShowing = true; - // SmartDialog.show( - // widget: ProductSku( - // miNiDetail, - // shopCarGoods, - // id, - // _addShopCar, - // add, - // reduce, - // ), - // onDismiss: () { - // dialogShowing = false; - // }, - // alignmentTemp: Alignment.bottomCenter, - // ); - // } - // } - // - // ///添加购物车 - // Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async { - // 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; - // }); - // } - // if (productSku == null) return; - // String skuId = productSku.id; - // String skuValue = selectSkus - // .toString() - // .replaceAll("[", "") - // .replaceAll("]", "") - // .replaceAll(",", ""); - // - // if (miNiDetail != null) { - // BaseData> baseDate = await minService.addShoppingCart({ - // "storeId": storeInfo.id, - // "storeName": storeInfo.storeName ?? "", - // "numberOfPeople": numberOfPeople, - // "tableId": tableId, - // "parentId": parentId, - // "parentCode": parentCode, - // "shoppingCartSkuItemList": [ - // { - // "buyNum": count, - // "id": skuId, - // "productId": miNiDetail.id, - // "productName": miNiDetail.productName, - // "skuName": skuValue, - // "storeId": storeInfo.id, - // "skuPrice": productSku.skuPrice, - // "skuStock": productSku.skuStock, - // "tableId": tableId, - // }, - // ], - // }); - // EasyLoading.dismiss(); - // if (baseDate != null && baseDate.isSuccess) { - // queryShopCar().then((value) { - // this.shopCarGoods = value; - // setState(() {}); - // }); - // } - // } - // } - // - // ///商品➕1 - // add(MiNiDetail miNiDetail, selectSkus) async { - // ProductSkuVOListBean productSku = - // miNiDetail.productSkuVOList.firstWhere((element) { - // return skuY(element, selectSkus); - // }); - // - // if (productSku == null) return; - // String skuId = productSku.id; - // if (shopCarGoods == null) { - // await _addShopCar(miNiDetail, selectSkus, 2); - // return; - // } - // int shopSkuIndex = shopCarGoods.shoppingCartSkuItemList - // .indexWhere((element) => skuId == element.id); - // Map shopCarTemp = shopCarGoods.toJson(); - // shopCarGoods.tableId = "$tableId"; - // - // if (shopSkuIndex >= 0) { - // shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum += 1; - // ShoppingCartSkuItemListBean cartSkuItem = shopCarGoods - // .shoppingCartSkuItemList - // .firstWhere((element) => skuId == element.id); - // shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - // } else { - // await _addShopCar(miNiDetail, selectSkus, 2); - // return; - // } - // - // BaseData> baseDate = - // await minService.shoppingCartSingle(shopCarTemp); - // if (baseDate.isSuccess) { - // queryShopCar().then((value) { - // this.shopCarGoods = value; - // setState(() {}); - // }); - // } - // } - // - // ///商品➖1 - // reduce(MiNiDetail miNiDetail, selectSkus) async { - // ProductSkuVOListBean productSku = - // miNiDetail.productSkuVOList.firstWhere((element) { - // return skuY(element, selectSkus); - // }); - // - // if (productSku == null) return; - // String skuId = productSku.id; - // if (shopCarGoods == null) { - // await _addShopCar(miNiDetail, selectSkus, 2); - // return; - // } - // ShoppingCartSkuItemListBean shopSkuItem = shopCarGoods - // .shoppingCartSkuItemList - // .firstWhere((element) => skuId == element.skuId); - // int shopSkuIndex = shopCarGoods.shoppingCartSkuItemList - // .indexWhere((element) => skuId == element.skuId); - // - // if (shopSkuItem != null) { - // if (shopSkuItem.buyNum > 1) { - // shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum -= 1; - // } - // } else { - // await _addShopCar(miNiDetail, selectSkus, 2); - // return; - // } - // shopCarGoods.tableId = "$tableId"; - // - // Map shopCarTemp = shopCarGoods.toJson(); - // ShoppingCartSkuItemListBean cartSkuItem = shopCarGoods - // .shoppingCartSkuItemList - // .firstWhere((element) => skuId == element.id); - // shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - // - // BaseData> baseDate = - // await minService.shoppingCartSingle(shopCarTemp); - // if (baseDate.isSuccess) { - // queryShopCar().then((value) { - // this.shopCarGoods = value; - // setState(() {}); - // }); - // } - // } - // - // bool skuY(ProductSkuVOListBean productSku, selectSkus) { - // bool gg = true; - // selectSkus.forEach((element1) { - // if (productSku.skuNameStr.indexOf(element1) < 0) { - // gg = false; - // return gg; - // } - // }); - // return gg; - // } - - // ///查询购物车 - // Future queryShopCar() async { - // pName="";//活动 - // pid="";//活动 - // cName="";//优惠券 - // cid="";//优惠券 - // BaseData> baseDate = - // await minService.getShoppingCart(tableId); - // if (baseDate != null && - // baseDate.isSuccess && - // baseDate.data != null && - // baseDate.data.length > 0) { - // if( baseDate.data[0].selectDiscount ==1){ - // baseDate.data[0].couponList.forEach((element) { - // if(element.isMaxCoupon){ - // cName = element.promotionName; - // cid = element.id; - // } - // }); - // }else if(baseDate.data[0].selectDiscount==2){ - // baseDate.data[0].promotionInfoList.forEach((element) { - // if(element.isMaxPromotion){ - // pName=element.name; - // pid=element.id; - // } - // }); - // } - // return baseDate.data[0]; - // } else { - // return null; - // } - // } - - @override Widget build(BuildContext context) { super.build(context); @@ -360,17 +132,18 @@ class _ShoppingMallHome extends State ]), ), ), - if (choiceIndex == 0) + if (minToken != null && choiceIndex == 0) ShoppingHomePage( minToken, storeInfo, storeId, tenant, ), - if (choiceIndex == 1) ShoppingCartPage( + if (minToken != null && choiceIndex == 1) ShoppingCartPage( minToken, storeId, tenant, + storeInfo, ), Align( alignment: Alignment.bottomCenter, diff --git a/lib/union/union_page.dart b/lib/union/union_page.dart index 7c9e9d89..ea8b01ab 100644 --- a/lib/union/union_page.dart +++ b/lib/union/union_page.dart @@ -257,7 +257,7 @@ class _UnionPage extends State '/router/shopping_mall_home', arguments: { "type":0, - "id": storeName.id, + "id":storeName.id, "tenant": storeName.tenantCode, "storeName":storeName.storeName },