diff --git a/lib/home/home_page.dart b/lib/home/home_page.dart index f4b816fc..c6bf0ad8 100644 --- a/lib/home/home_page.dart +++ b/lib/home/home_page.dart @@ -40,6 +40,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import '../retrofit/data/user_info.dart'; +import '../utils/flutter_utils.dart'; import '../view_widget/channel_dialog.dart'; import '../view_widget/custom_image.dart'; import 'home_view/happy_help_farmers.dart'; @@ -76,6 +77,7 @@ class HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin { List<Goods> goods = []; List<GoodsCategory> gooodsCategorys = []; List<BannerData> bannerData = []; + List<BannerData> activityBannerData = []; List<Brand> brandData = []; List<Article> articles = []; Founder founder; @@ -87,6 +89,7 @@ class HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin { UserInfo userInfo; dynamic mRaiseMoney = 0; //众筹金余额 int _loadCount = 0; + DioErrorType dioErrorType; @override void initState() { @@ -160,7 +163,9 @@ class HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin { try { BaseData<PageInfo<BannerData>> baseData = await apiService.queryBanner({ "model": {"type": "HOME_PAGE"}, - }).catchError((onError) {}); + }).catchError((onError) { + dioErrorType = onError.type; + }); if (baseData != null && baseData.isSuccess) { bannerData = baseData.data.records; // if (bannerData.length > 0) swiperController.move(0, animation: false); @@ -170,12 +175,32 @@ class HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin { } } + ///宣传banner + queryActivityBanner() async { + try { + BaseData<PageInfo<BannerData>> baseData = await apiService.queryBanner({ + "model": {"type": "HOME_STORE_PAGE"}, + }).catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + activityBannerData = baseData.data.records; + } + } finally { + addLoadCount(); + } + } + addLoadCount() { _loadCount += 1; - if (_loadCount == 6) { + if (_loadCount == 7) { _loadCount = 0; EasyLoading.dismiss(); - if (refreshController.isRefresh) refreshController.refreshCompleted(); + if (dioErrorType == null) + refreshController.refreshCompleted(); + else { + SmartDialog.showToast(AppUtils.dioErrorTypeToString(dioErrorType), + alignment: Alignment.center); + refreshController.refreshFailed(); + } if (mounted) setState(() {}); } } @@ -240,11 +265,11 @@ class HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin { goods = pageGoods.data.list; } } finally { - if(isRefresh) - addLoadCount(); + if (isRefresh) + addLoadCount(); else { EasyLoading.dismiss(); - setState((){}); + setState(() {}); } } } @@ -334,8 +359,10 @@ class HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin { token: value.getString("token"), ); } + dioErrorType = null; if (isFirstIn) queryActivity(); queryBanner(); + queryActivityBanner(); queryRecommendRank(); queryGoodsCategory(); queryPointsProductList(true); @@ -627,50 +654,118 @@ class HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin { Widget spread() { return Container( width: double.infinity, + // margin: EdgeInsets.symmetric(horizontal:14.w), height: 85.h, - child: Swiper( - pagination: SwiperPagination( - alignment: Alignment.bottomCenter, - margin: EdgeInsets.only(top: 5.h), - builder: DotSwiperPaginationBuilder( - size: 8.w, - activeSize: 8.w, - space: 5.w, - activeColor: Colors.white, - color: Colors.white.withAlpha(76), - ), - ), - autoplay: true, - duration: 1000, - autoplayDelay: 2000, - itemBuilder: (context, position) { - return GestureDetector( - onTap: () { - if (position == 0) { - Navigator.of(context).pushNamed('/router/invite_friends'); - } else if (position == 1) { - Navigator.of(context).pushNamed('/router/trading_card_page'); - } - }, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 14.w), - child: ClipRRect( - child: Image.asset( - spreadItem[position], - width: double.infinity, - fit: BoxFit.fill, - height: double.infinity, + child: bannerData != null && bannerData.isNotEmpty + ? Swiper( + pagination: SwiperPagination( + alignment: Alignment.bottomCenter, + margin: EdgeInsets.only(top: 5.h), + builder: DotSwiperPaginationBuilder( + size: 8.w, + activeSize: 8.w, + space: 5.w, + activeColor: Colors.white, + color: Colors.white.withAlpha(76), ), - borderRadius: BorderRadius.circular(6.w), ), + autoplay: true, + duration: 1000, + autoplayDelay: 2000, + itemBuilder: (context, position) { + return InkWell( + onTap: () { + spreadBannerClick(activityBannerData[position]); + }, + child: Container( + margin: EdgeInsets.symmetric(horizontal: 14.w), + child: MImage( + activityBannerData[position].imgUrl, + fit: BoxFit.cover, + radius: BorderRadius.circular(6), + errorSrc: "assets/image/default_2_1.webp", + fadeSrc: "assets/image/default_2_1.webp", + ), + ), + ); + // GestureDetector( + // onTap: () { + // if (position == 0) { + // Navigator.of(context).pushNamed('/router/invite_friends'); + // } else if (position == 1) { + // Navigator.of(context).pushNamed('/router/trading_card_page'); + // } + // }, + // child: Container( + // margin: EdgeInsets.symmetric(horizontal: 14.w), + // child: ClipRRect( + // child: Image.asset( + // spreadItem[position], + // width: double.infinity, + // fit: BoxFit.fill, + // height: double.infinity, + // ), + // borderRadius: BorderRadius.circular(6.w), + // ), + // ), + // ); + }, + itemCount: activityBannerData.length, + ) + : Image.asset( + "assets/image/default_2_1.webp", + fit: BoxFit.cover, ), - ); - }, - itemCount: 2, - ), ); } + /// contentType 跳转类型(0:不跳转,1:积分商品,2:活动,3:文章,4:页面跳转,5:课程,7:门店跳转) + spreadBannerClick(BannerData activityBannerData) async { + switch (activityBannerData.contentType) { + case 1: + Navigator.of(context).pushNamed('/router/integral_store_page', + arguments: {"goodsId": activityBannerData.content}); + break; + case 2: + Navigator.of(context).pushNamed('/router/web_page', arguments: { + "activityId": activityBannerData.content, + }); + break; + case 3: + Navigator.of(context).pushNamed('/router/web_page', arguments: { + "articleId": activityBannerData.content, + }); + break; + case 4: + String router = activityBannerData.content; + // String router = "/router/store_order?{\"id\":\"1512378184161558528\",\"tenant\":\"1188\",\"storeName\":\"农场煮意\"}"; + if (router.contains("?")) { + String params = router.substring(router.indexOf("?") + 1); + Map map = jsonDecode(params); + Navigator.of(context).pushNamed( + router.substring(0, router.indexOf("?")), + arguments: map); + } else { + Navigator.of(context).pushNamed(router); + } + break; + case 5: + Navigator.of(context).pushNamed('/router/class_details', arguments: { + "id": activityBannerData.content, + }); + break; + case 7: + String params = activityBannerData.content + .substring(activityBannerData.content.indexOf("?") + 1); + Map map = jsonDecode(params); + Navigator.of(context).pushNamed( + activityBannerData.content + .substring(0, activityBannerData.content.indexOf("?")), + arguments: map); + break; + } + } + final List<String> spreadItem = [ "assets/image/welfare_spread.webp", "assets/image/welfare_yz.webp", diff --git a/lib/home/welfare_page.dart b/lib/home/welfare_page.dart index 902a9511..a6cb8fdf 100644 --- a/lib/home/welfare_page.dart +++ b/lib/home/welfare_page.dart @@ -39,69 +39,48 @@ class _WelfarePage extends State<WelfarePage> { List<Goods> goods = []; Goods goodsPrice; List<Coupon> coupons = []; - List<List<Coupon>> coupon=[]; + List<List<Coupon>> coupon = []; String categoryId; bool orderDesc = true; int orderType = 1; int type = 1; int couponIndex = 0; int swiperIndex = 0; + int _loadCount = 0; @override void initState() { super.initState(); - SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), context: context, token: value.getString("token")), - _onRefresh(), - - }); + _onRefresh(); } queryGoods() async { - if (apiService == null) { - SharedPreferences value = await SharedPreferences.getInstance(); - apiService = ApiService( - Dio(), - context: context, - token: value.getString("token"), - ); - } - var param = { - "categoryId": categoryId ?? "", - "orderDesc": orderDesc, - "orderType": orderType, - "pageNum": 1, - "pageSize": 100, - "state": 1 - }; - BaseData<PageInfo<Goods>> pageGoods = - await apiService.creditGoods(param).catchError((onError) { - refreshController.loadFailed(); - refreshController.refreshFailed(); - }); - EasyLoading.dismiss(); - if (pageGoods != null && pageGoods.isSuccess) { - setState(() { + try { + var param = { + "categoryId": categoryId ?? "", + "orderDesc": orderDesc, + "orderType": orderType, + "pageNum": 1, + "pageSize": 100, + "state": 1 + }; + BaseData<PageInfo<Goods>> pageGoods = + await apiService.creditGoods(param).catchError((onError) { + refreshController.loadFailed(); + refreshController.refreshFailed(); + }); + EasyLoading.dismiss(); + if (pageGoods != null && pageGoods.isSuccess) { goods.clear(); goods.addAll(pageGoods.data.list); - }); - refreshController.refreshCompleted(); - refreshController.loadComplete(); - } else { - refreshController.loadFailed(); - refreshController.refreshFailed(); + } + } finally { + addLoadCount(); } } queryCoupon() async { - if (apiService == null) { - SharedPreferences value = await SharedPreferences.getInstance(); - apiService = ApiService( - Dio(), - context: context, - token: value.getString("token"), - ); - } + try{ BaseData<PageInfo<Coupon>> baseData = await apiService.queryCoupon({ "centre": true, "pageNum": 1, @@ -110,36 +89,48 @@ class _WelfarePage extends State<WelfarePage> { "state": 0 }).catchError((onError) { SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type), - alignment: Alignment.center); - refreshController.refreshFailed(); - refreshController.loadFailed(); + alignment: Alignment.center); }); coupons.clear(); coupon.clear(); if (baseData != null && baseData.isSuccess) { coupons.addAll(baseData.data.list); - for(var i = 0;i < coupons.length~/3+1;i++){ + for (var i = 0; i < coupons.length ~/ 3 + 1; i++) { List<Coupon> con = []; - con = coupons.skip(i*3).take((i*3<coupons.length)?3:(coupons.length - (i*3))).toList(); + con = coupons + .skip(i * 3) + .take((i * 3 < coupons.length) ? 3 : (coupons.length - (i * 3))) + .toList(); coupon.add(con); } - if(coupon.length > 0 && coupon[coupon.length - 1].isEmpty) - coupon.removeAt(coupon.length-1); - refreshController.refreshCompleted(); - refreshController.loadComplete(); + if (coupon.length > 0 && coupon[coupon.length - 1].isEmpty) + coupon.removeAt(coupon.length - 1); setState(() {}); - } else { - refreshController.refreshFailed(); - refreshController.loadFailed(); + }}finally{ + addLoadCount(); } } - - _onRefresh(){ + _onRefresh() async{ + EasyLoading.show(status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); + if (apiService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + apiService = + ApiService(Dio(), context: context, token: value.getString("token")); + } queryGoods(); queryCoupon(); } + addLoadCount() { + _loadCount += 1; + if (_loadCount == 2) { + _loadCount = 0; + EasyLoading.dismiss(); + if (refreshController.isRefresh) refreshController.refreshCompleted(); + if (mounted) setState(() {}); + } + } @override Widget build(BuildContext context) { @@ -157,7 +148,10 @@ class _WelfarePage extends State<WelfarePage> { width: double.infinity, height: 236.h, ), - Expanded(child: Container(color: Colors.white,)) + Expanded( + child: Container( + color: Colors.white, + )) ], ), Scaffold( @@ -170,7 +164,7 @@ class _WelfarePage extends State<WelfarePage> { titleSize: 18.sp, brightness: Brightness.dark, ), - body:SmartRefresher( + body: SmartRefresher( controller: refreshController, enablePullDown: true, enablePullUp: false, @@ -180,18 +174,15 @@ class _WelfarePage extends State<WelfarePage> { return MyFooter(mode); }, ), - onRefresh:(){ - setState(() { - _onRefresh(); - }); - }, + onRefresh:_onRefresh, physics: BouncingScrollPhysics(), scrollController: ScrollController(), child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.circular(6), - topRight: Radius.circular(6),), + topRight: Radius.circular(6), + ), color: Colors.white, boxShadow: [ BoxShadow( @@ -213,12 +204,10 @@ class _WelfarePage extends State<WelfarePage> { Container( color: Colors.white, - padding: EdgeInsets.only(left: 14,right: 14), - child:Column( + padding: EdgeInsets.only(left: 14, right: 14), + child: Column( children: [ - inviteFriends(), - benefitExchange(), ], ), @@ -242,7 +231,8 @@ class _WelfarePage extends State<WelfarePage> { decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.circular(6), - topRight: Radius.circular(6),), + topRight: Radius.circular(6), + ), color: Colors.white, boxShadow: [ BoxShadow( @@ -253,14 +243,13 @@ class _WelfarePage extends State<WelfarePage> { ), ], ), - child: Column( + child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: EdgeInsets.symmetric(horizontal: 17.w,vertical: 16.h), - child: - Row( + padding: EdgeInsets.symmetric(horizontal: 17.w, vertical: 16.h), + child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -282,81 +271,82 @@ class _WelfarePage extends State<WelfarePage> { ), ], )), - coupon.length == 0? - NoDataView( + coupon.length == 0 + ? NoDataView( + src: "assets/image/ka.webp", + isShowBtn: false, + text: S.of(context).haimeiyouyouhuiquankeyilingqu, + fontSize: 16.sp, + ) + : AspectRatio( + aspectRatio: 1.10, + child: Swiper( + onIndexChanged: (it) { + swiperIndex = it; + }, + index: couponIndex, + viewportFraction: 0.9, + scale: 0.7, + key: UniqueKey(), + pagination: SwiperPagination( + alignment: Alignment.bottomCenter, + builder: DotSwiperPaginationBuilder( + size: 8, + activeSize: 8, + space: 5, + activeColor: Colors.black, + color: Colors.black.withAlpha(76), + ), + ), + physics: BouncingScrollPhysics(), + itemBuilder: (context, position) { + return Column( + children: [ + Container( + child: weekList(coupon[position]), + ), + ], + ); + }, + itemCount: coupon.length ?? 0, + ), + ) + ], + )); + } + + Widget weekList(List<Coupon> cops) { + return Expanded( + child: (cops == null && cops.length == 0) + ? NoDataView( src: "assets/image/ka.webp", isShowBtn: false, text: S.of(context).haimeiyouyouhuiquankeyilingqu, fontSize: 16.sp, - ): AspectRatio( - aspectRatio: 1.10, - child: Swiper( - onIndexChanged: (it){ - swiperIndex = it; - }, - index: couponIndex, - viewportFraction: 0.9, - scale: 0.7, - key: UniqueKey(), - pagination: SwiperPagination( - alignment: Alignment.bottomCenter, - builder: DotSwiperPaginationBuilder( - size: 8, - activeSize: 8, - space: 5, - activeColor: Colors.black, - color: Colors.black.withAlpha(76), - ), - ), - physics: BouncingScrollPhysics(), - itemBuilder: (context, position) { - return Column( - children: [ - Container( - child: weekList(coupon[position]), - ), - ], - ); - }, - itemCount:coupon.length ?? 0, - ), ) - ], - ) + : ListView.builder( + padding: EdgeInsets.zero, + itemCount: cops.length, + scrollDirection: Axis.vertical, + shrinkWrap: true, + physics: BouncingScrollPhysics(), + itemBuilder: (context, position) { + return GestureDetector( + onTap: () {}, + child: weekCoupon(cops[position]), + ); + }, + ), ); } - Widget weekList(List<Coupon> cops){ - return Expanded( - child:(cops == null && cops.length == 0)? - NoDataView( - src: "assets/image/ka.webp", - isShowBtn: false, - text: S.of(context).haimeiyouyouhuiquankeyilingqu, - fontSize: 16.sp, - ):ListView.builder( - padding: EdgeInsets.zero, - itemCount: cops.length, - scrollDirection: Axis.vertical, - shrinkWrap: true, - physics: BouncingScrollPhysics(), - itemBuilder: (context, position) { - return GestureDetector( - onTap: () { - }, - child: weekCoupon(cops[position]), - ); - }, - ),); - } - ///优惠券列表 Widget weekCoupon(Coupon cop) { return Container( height: 95.h, width: double.infinity, - margin: EdgeInsets.only(bottom:10), - padding:EdgeInsets.symmetric(horizontal: 12), + margin: EdgeInsets.only(bottom: 10), + padding: EdgeInsets.symmetric(horizontal: 12), decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.fill, @@ -367,8 +357,9 @@ class _WelfarePage extends State<WelfarePage> { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded(child: Container( - margin: EdgeInsets.only(top: 12,bottom: 12), + Expanded( + child: Container( + margin: EdgeInsets.only(top: 12, bottom: 12), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, @@ -383,31 +374,37 @@ class _WelfarePage extends State<WelfarePage> { color: Color(0xFF0D0D0D), ), ), - SizedBox(height: 12,), - (cop.status == 0)? - Text( - "发放时间: ${cop?.publishStartTime ?? ""}", - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: cop.status == 3 ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D), - ), - ):Text( - "有效期至 ${cop?.useEndTime ?? ""}", - maxLines:1, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: cop.status == 3 ? Color(0xFFB3B3B3) :Color(0xFF4D4D4D), - ), - ) + SizedBox( + height: 12, + ), + (cop.status == 0) + ? Text( + "发放时间: ${cop?.publishStartTime ?? ""}", + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: cop.status == 3 + ? Color(0xFFB3B3B3) + : Color(0xFF4D4D4D), + ), + ) + : Text( + "有效期至 ${cop?.useEndTime ?? ""}", + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: cop.status == 3 + ? Color(0xFFB3B3B3) + : Color(0xFF4D4D4D), + ), + ) ], ), )), - Column( // mainAxisAlignment: MainAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.end, @@ -441,7 +438,8 @@ class _WelfarePage extends State<WelfarePage> { style: TextStyle( fontSize: 16.sp, fontWeight: MyFontWeight.medium, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), SizedBox( @@ -450,26 +448,25 @@ class _WelfarePage extends State<WelfarePage> { Text( coupon != null ? double.tryParse("${cop.discountAmount}" ?? "0") - .toInt() - .toString() + .toInt() + .toString() : "", style: TextStyle( fontSize: 24.sp, fontWeight: MyFontWeight.semi_bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], ), Text( - S.of(context).manyuankeyong(coupon != null - ? ("${cop.fullAmount}" ?? "0") - .toString() - : ""), + S.of(context).manyuankeyong( + coupon != null ? ("${cop.fullAmount}" ?? "0").toString() : ""), style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.semi_bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], @@ -489,7 +486,8 @@ class _WelfarePage extends State<WelfarePage> { style: TextStyle( fontSize: 22.sp, fontWeight: MyFontWeight.semi_bold, - color:cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], @@ -500,7 +498,7 @@ class _WelfarePage extends State<WelfarePage> { style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.semi_bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], @@ -511,7 +509,7 @@ class _WelfarePage extends State<WelfarePage> { crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( - padding: EdgeInsets.only(bottom:10,top: 7), + padding: EdgeInsets.only(bottom: 10, top: 7), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -520,7 +518,8 @@ class _WelfarePage extends State<WelfarePage> { style: TextStyle( fontSize: 26.sp, fontWeight: MyFontWeight.semi_bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], @@ -531,7 +530,7 @@ class _WelfarePage extends State<WelfarePage> { style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.semi_bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], @@ -547,31 +546,35 @@ class _WelfarePage extends State<WelfarePage> { textBaseline: TextBaseline.alphabetic, children: [ Text( - cop.limitAmount != "0.00"?"¥":"", + cop.limitAmount != "0.00" ? "¥" : "", style: TextStyle( fontSize: 16.sp, fontWeight: MyFontWeight.medium, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), SizedBox( height: 4.h, ), Text( - cop.limitAmount != "0.00"?(coupon != null - ? "${AppUtils.calculateDouble(double.tryParse(cop.limitAmount) ?? 0)}" - : "") :"", + cop.limitAmount != "0.00" + ? (coupon != null + ? "${AppUtils.calculateDouble(double.tryParse(cop.limitAmount) ?? 0)}" + : "") + : "", style: TextStyle( fontSize: 24.sp, fontWeight: FontWeight.bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], ), ], ); - }else{ + } else { return Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, @@ -582,25 +585,29 @@ class _WelfarePage extends State<WelfarePage> { textBaseline: TextBaseline.alphabetic, children: [ Text( - cop.discountPercent != 0 ? (coupon != null - ? "${(cop.discountPercent / 10.0 >= 10) ? 10 : cop.discountPercent / 10.0}" ?? - "0" - : ""):"", + cop.discountPercent != 0 + ? (coupon != null + ? "${(cop.discountPercent / 10.0 >= 10) ? 10 : cop.discountPercent / 10.0}" ?? + "0" + : "") + : "", style: TextStyle( fontSize: 30.sp, fontWeight: MyFontWeight.semi_bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), SizedBox( height: 4.h, ), Text( - cop.discountPercent != 0 ? "折" :"", + cop.discountPercent != 0 ? "折" : "", style: TextStyle( fontSize: 16.sp, fontWeight: MyFontWeight.semi_bold, - color: cop.status == 3 ? Color(0xFFB3B3B3):Color(0xff32A060), + color: + cop.status == 3 ? Color(0xFFB3B3B3) : Color(0xff32A060), ), ), ], @@ -612,67 +619,66 @@ class _WelfarePage extends State<WelfarePage> { ///优惠券领取状态 Widget weekBtn(Coupon cop) { - if(cop.status == 0) - return Align( - alignment: Alignment.centerRight, - child: InkWell( - onTap: () { - receiveCoupon(cop.id); - }, - child: Container( - padding: EdgeInsets.symmetric(horizontal: 12.w,vertical: 2.h), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(3), - color: Color(0xFF32A060), - ), - child: Text( - S.of(context).lingqu, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.medium, - color: Colors.white, - ), - ), - ), + if (cop.status == 0) + return Align( + alignment: Alignment.centerRight, + child: InkWell( + onTap: () { + receiveCoupon(cop.id); + }, + child: Container( + padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 2.h), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(3), + color: Color(0xFF32A060), + ), + child: Text( + S.of(context).lingqu, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.medium, + color: Colors.white, ), - ); - if(cop.status == 1 || cop.status == 2) + ), + ), + ), + ); + if (cop.status == 1 || cop.status == 2) return Align( - alignment: Alignment.centerRight, - child: InkWell( - onTap: () { - if (cop.bizType == 5 || cop.bizType == 3) { - Navigator.of(context).pushNamed( - '/router/write_off_page', - arguments: { - "couponId": cop.id, - "coupon": jsonEncode(cop.toJson()), - }); - } else { - showStoreSelector(cop.storeList); - } - }, - child: Container( - // height: 19.h, - padding: EdgeInsets.symmetric(horizontal:8.w,vertical: 1.h), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(3), - border: Border.all( - width: 1, color: Color(0xFF32A060), style: BorderStyle.solid), - color: Colors.transparent, - ), - alignment: Alignment.center, - child:Text( - S.of(context).qushiyong, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF32A060), - ), - ), - ), + alignment: Alignment.centerRight, + child: InkWell( + onTap: () { + if (cop.bizType == 5 || cop.bizType == 3) { + Navigator.of(context) + .pushNamed('/router/write_off_page', arguments: { + "couponId": cop.id, + "coupon": jsonEncode(cop.toJson()), + }); + } else { + showStoreSelector(cop.storeList); + } + }, + child: Container( + // height: 19.h, + padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 1.h), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(3), + border: Border.all( + width: 1, color: Color(0xFF32A060), style: BorderStyle.solid), + color: Colors.transparent, + ), + alignment: Alignment.center, + child: Text( + S.of(context).qushiyong, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFF32A060), ), - ); + ), + ), + ), + ); } ///领取优惠券 @@ -682,8 +688,8 @@ class _WelfarePage extends State<WelfarePage> { if (baseData != null && baseData.isSuccess) { queryCoupon(); showAlertDialog(); - }else{ - SmartDialog.showToast(baseData?.msg,alignment: Alignment.center); + } else { + SmartDialog.showToast(baseData?.msg, alignment: Alignment.center); } } @@ -710,8 +716,8 @@ class _WelfarePage extends State<WelfarePage> { ///邀请好友 Widget inviteFriends() { return Container( - margin: EdgeInsets.only(top:24.h,bottom:20.h), - child:Column( + margin: EdgeInsets.only(top: 24.h, bottom: 20.h), + child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -723,17 +729,19 @@ class _WelfarePage extends State<WelfarePage> { color: Color(0xFF0D0D0D), ), ), - SizedBox(height: 12,), + SizedBox( + height: 12, + ), GestureDetector( - onTap: (){ + onTap: () { Navigator.of(context).pushNamed('/router/invite_friends'); }, - child:ClipRRect( - child:Image.asset( + child: ClipRRect( + child: Image.asset( "assets/image/welfare_spread.webp", - width:double.infinity, + width: double.infinity, fit: BoxFit.fill, - height:80.h, + height: 80.h, ), borderRadius: BorderRadius.circular(6.w), ), @@ -747,28 +755,29 @@ class _WelfarePage extends State<WelfarePage> { Widget benefitExchange() { return Container( width: double.infinity, - margin: EdgeInsets.only(top:24.h,bottom:20.h), - child:Column( + margin: EdgeInsets.only(top: 24.h, bottom: 20.h), + child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( - onTap: (){ + onTap: () { Navigator.of(context).pushNamed('/router/welfare_exchange'); }, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ - Expanded(child: - Text( - S.of(context).fuliduihuan, - style: TextStyle( - fontSize: 15.sp, - fontWeight: MyFontWeight.bold, - color: Color(0xFF0D0D0D), + Expanded( + child: Text( + S.of(context).fuliduihuan, + style: TextStyle( + fontSize: 15.sp, + fontWeight: MyFontWeight.bold, + color: Color(0xFF0D0D0D), + ), ), - ),), + ), Text( S.of(context).gengduo, style: TextStyle( @@ -785,47 +794,50 @@ class _WelfarePage extends State<WelfarePage> { ], ), ), - SizedBox(height: 12,), - (goods == null || goods.length == 0)? NoDataView( - src: "assets/image/xiao_fei.webp", - isShowBtn: false, - text: "暂无商品可兑换", - fontSize: 16.sp, - margin: EdgeInsets.all(60.h), - ) - :GridView.builder( - itemCount:goods.length>6?6:goods.length, - padding: EdgeInsets.only( - // left: 16.w, - // right: 16.w, - top: 18.h, - bottom: 16.h, - ), - shrinkWrap: true, - physics: BouncingScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - //一行的Widget数量 - crossAxisCount: 2, - //水平子Widget之间间距 - crossAxisSpacing: 11.w, - //垂直子Widget之间间距 - mainAxisSpacing: 16.w, - //子Widget宽高比例 0.59 - childAspectRatio: - 200 / (285 / 2 + (285 / 2) * AppUtils.textScale(context)), - ), - itemBuilder: (context, index) { - return GestureDetector( - onTap: () { - Navigator.of(context).pushNamed( - '/router/integral_store_page', - arguments: {"goodsId": goods[index].id}, - ); - }, - child: exchangeItem(goods[index]), - ); - }, - ) + SizedBox( + height: 12, + ), + (goods == null || goods.length == 0) + ? NoDataView( + src: "assets/image/xiao_fei.webp", + isShowBtn: false, + text: "暂无商品可兑换", + fontSize: 16.sp, + margin: EdgeInsets.all(60.h), + ) + : GridView.builder( + itemCount: goods.length > 6 ? 6 : goods.length, + padding: EdgeInsets.only( + // left: 16.w, + // right: 16.w, + top: 18.h, + bottom: 16.h, + ), + shrinkWrap: true, + physics: BouncingScrollPhysics(), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + //一行的Widget数量 + crossAxisCount: 2, + //水平子Widget之间间距 + crossAxisSpacing: 11.w, + //垂直子Widget之间间距 + mainAxisSpacing: 16.w, + //子Widget宽高比例 0.59 + childAspectRatio: 200 / + (285 / 2 + (285 / 2) * AppUtils.textScale(context)), + ), + itemBuilder: (context, index) { + return GestureDetector( + onTap: () { + Navigator.of(context).pushNamed( + '/router/integral_store_page', + arguments: {"goodsId": goods[index].id}, + ); + }, + child: exchangeItem(goods[index]), + ); + }, + ) ], ), ); @@ -871,10 +883,8 @@ class _WelfarePage extends State<WelfarePage> { margin: EdgeInsets.only( right: 12.w, top: 10.h, - ),padding: EdgeInsets.only( - bottom: 8, - left: 8 - ), + ), + padding: EdgeInsets.only(bottom: 8, left: 8), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, @@ -894,12 +904,12 @@ class _WelfarePage extends State<WelfarePage> { Text( pointPrice(goods), style: TextStyle( - color: Color(0xFFE5600D), - fontSize: 16.sp, + color: Color(0xFFE5600D), + fontSize: 16.sp, fontFamily: 'JDZhengHT', - fontWeight: MyFontWeight.semi_bold, - ), - ), + fontWeight: MyFontWeight.semi_bold, + ), + ), ], ), ), @@ -912,16 +922,22 @@ class _WelfarePage extends State<WelfarePage> { ); } - String pointPrice(Goods goodsPrice){ - if(goodsPrice == null) - return ""; - if(goodsPrice?.oneBean!=null && goodsPrice?.oneBean!="0"){ + String pointPrice(Goods goodsPrice) { + if (goodsPrice == null) return ""; + if (goodsPrice?.oneBean != null && goodsPrice?.oneBean != "0") { return "${goodsPrice?.oneBean}印章"; - } else if(goodsPrice?.onePrice!=null && goodsPrice?.onePrice!="0"){ + } else if (goodsPrice?.onePrice != null && goodsPrice?.onePrice != "0") { return S.of(context).jifen_(goodsPrice?.onePrice); - }else if((goodsPrice?.onePrice == null || goodsPrice?.onePrice == "0") && ((goodsPrice?.price != null && goodsPrice?.price != "0") || (goodsPrice?.money != null && goodsPrice?.money != "0.00"))){ - return (goodsPrice?.price== "0"|| goodsPrice?.price == null ? "" : S.of(context).jifen_(goodsPrice?.price)) + (goodsPrice?.money== "0"|| goodsPrice?.money == null ? "" : " + ${AppUtils.calculateDouble(double.tryParse(goodsPrice?.money) ?? 0)}元"); - }else if(goodsPrice.oneMoney != null && goodsPrice.oneMoney != "0.00"){ + } else if ((goodsPrice?.onePrice == null || goodsPrice?.onePrice == "0") && + ((goodsPrice?.price != null && goodsPrice?.price != "0") || + (goodsPrice?.money != null && goodsPrice?.money != "0.00"))) { + return (goodsPrice?.price == "0" || goodsPrice?.price == null + ? "" + : S.of(context).jifen_(goodsPrice?.price)) + + (goodsPrice?.money == "0" || goodsPrice?.money == null + ? "" + : " + ${AppUtils.calculateDouble(double.tryParse(goodsPrice?.money) ?? 0)}元"); + } else if (goodsPrice.oneMoney != null && goodsPrice.oneMoney != "0.00") { return "${AppUtils.calculateDouble(double.tryParse(goodsPrice.oneMoney) ?? 0)}元"; } } @@ -929,8 +945,10 @@ class _WelfarePage extends State<WelfarePage> { ///活动任务 Widget activityTask() { return Container( - margin: EdgeInsets.only(bottom:20.h,), - child:Column( + margin: EdgeInsets.only( + bottom: 20.h, + ), + child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -956,17 +974,18 @@ class _WelfarePage extends State<WelfarePage> { ), ], ), - SizedBox(height: 12.h,), + SizedBox( + height: 12.h, + ), ListView.builder( padding: EdgeInsets.zero, - itemCount:6, + itemCount: 6, scrollDirection: Axis.vertical, shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemBuilder: (context, position) { return GestureDetector( - onTap: () { - }, + onTap: () {}, child: taskItem(), ); }, @@ -978,72 +997,76 @@ class _WelfarePage extends State<WelfarePage> { Widget taskItem() { return Container( - width:double.infinity, - height:95.h, + width: double.infinity, + height: 95.h, decoration: BoxDecoration( borderRadius: BorderRadius.circular(6), color: Colors.white, boxShadow: [ - BoxShadow( - color: Color(0x08213303).withAlpha(12), - offset: Offset(0, 2), - blurRadius: 3, - spreadRadius: 0, - ), - ], + BoxShadow( + color: Color(0x08213303).withAlpha(12), + offset: Offset(0, 2), + blurRadius: 3, + spreadRadius: 0, + ), + ], ), - padding: EdgeInsets.symmetric(horizontal: 12.w,vertical: 12.h), + padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 12.h), margin: EdgeInsets.only(bottom: 10.h), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.end, children: [ - Expanded(child:Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "海峡姐妹茶新品尝鲜(0/3)", - style: TextStyle( - fontSize: 14.sp, - fontWeight: MyFontWeight.bold, - color: Color(0xFF353535), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "海峡姐妹茶新品尝鲜(0/3)", + style: TextStyle( + fontSize: 14.sp, + fontWeight: MyFontWeight.bold, + color: Color(0xFF353535), + ), ), - ), - Text( - "可获得¥10代金券", - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF4D4D4D), + Text( + "可获得¥10代金券", + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFF4D4D4D), + ), ), - ), Text( - "购买任意3杯新品", - style: TextStyle( - fontSize: 10.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFFB3B3B3), + Text( + "购买任意3杯新品", + style: TextStyle( + fontSize: 10.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFFB3B3B3), + ), ), - ), - ], - ),), + ], + ), + ), Container( width: 55.w, height: 21.h, decoration: BoxDecoration( gradient: new LinearGradient( - begin: Alignment.centerLeft, - end: Alignment.centerRight, - colors: [ - Color(0xFFFF2700), - Color(0xFFFF4F00), - ],), + begin: Alignment.centerLeft, + end: Alignment.centerRight, + colors: [ + Color(0xFFFF2700), + Color(0xFFFF4F00), + ], + ), // border: Border.all(color: Colors.white,width: 0.5), shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(3), ), alignment: Alignment.center, - child:Text( + child: Text( "领取", style: TextStyle( fontSize: 12.sp, @@ -1056,5 +1079,4 @@ class _WelfarePage extends State<WelfarePage> { ), ); } - } diff --git a/lib/integral/integral_page.dart b/lib/integral/integral_page.dart index 04f8b83f..771ec56e 100644 --- a/lib/integral/integral_page.dart +++ b/lib/integral/integral_page.dart @@ -19,10 +19,10 @@ import 'package:huixiang/view_widget/sign_in_widget.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 '../utils/flutter_utils.dart'; import 'intergra_view/integral_task.dart'; class IntegralPage extends StatefulWidget { - @override State<StatefulWidget> createState() { return _IntegralPage(); @@ -51,13 +51,17 @@ class _IntegralPage extends State<IntegralPage> { ); userInfo = UserInfo.fromJson(jsonDecode(value.getString("user"))); - BaseData<List<Rank>> rankData = await apiService.rankList() - .catchError((onError) {}); + BaseData<List<Rank>> rankData = + await apiService.rankList().catchError((onError) { + SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type), + alignment: Alignment.center); + refreshController.refreshFailed(); + }); if (rankData != null && rankData.isSuccess) { ranks.clear(); ranks.addAll(rankData.data); refreshController.refreshCompleted(); - }else { + } else { refreshController.refreshFailed(); } @@ -112,7 +116,9 @@ class _IntegralPage extends State<IntegralPage> { Scaffold( backgroundColor: Colors.transparent, appBar: MyAppBar( - exit: (){Navigator.of(context).pop(signInfo.todayHasSignin ?? false);}, + exit: () { + Navigator.of(context).pop(signInfo?.todayHasSignin ?? false); + }, background: Colors.transparent, leadingColor: Colors.white, title: "", @@ -124,7 +130,9 @@ class _IntegralPage extends State<IntegralPage> { margin: EdgeInsets.only(right: 16.w), child: GestureDetector( onTap: () { - Navigator.of(context).pushNamed('/router/integral_detailed_page',arguments:{"titleType":2}); + Navigator.of(context).pushNamed( + '/router/integral_detailed_page', + arguments: {"titleType": 2}); }, child: Text( S.of(context).mingxi, @@ -137,17 +145,17 @@ class _IntegralPage extends State<IntegralPage> { ), ), ), - body:SmartRefresher( + body: SmartRefresher( controller: refreshController, enablePullDown: true, enablePullUp: false, - header: MyHeader(), + header: MyHeader(color: Colors.white,), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), - onRefresh:(){ + onRefresh: () { setState(() { querySignInfo(); }); @@ -163,9 +171,19 @@ class _IntegralPage extends State<IntegralPage> { return Column( children: [ /// 上面的积分和VIP等级显示 - IntegralVip(rankLevel, signInfo, userInfo,"${ (signInfo?.signInList?.length ) ?? "0"}", - ((signInfo?.rewardList != null && signInfo.rewardList.length > (signInfo?.signInList?.length ?? 0)) ? - signInfo.rewardList[signInfo?.signInList?.length ?? 0]:0).toString()), + IntegralVip( + rankLevel, + signInfo, + userInfo, + "${(signInfo?.signInList?.length) ?? "0"}", + ((signInfo?.rewardList != null && + signInfo.rewardList.length > + (signInfo?.signInList?.length ?? + 0)) + ? signInfo.rewardList[ + signInfo?.signInList?.length ?? 0] + : 0) + .toString()), ///立即签到 InForPoints(signInfo, _signIn), @@ -191,7 +209,9 @@ class _IntegralPage extends State<IntegralPage> { SmartDialog.showToast("今日已签到了", alignment: Alignment.center); return; } - EasyLoading.show(status: S.of(context).zhengzaijiazai,maskType: EasyLoadingMaskType.black); + EasyLoading.show( + status: S.of(context).zhengzaijiazai, + maskType: EasyLoadingMaskType.black); BaseData baseData = await apiService.signIn().catchError((onError) {}); if (baseData != null && baseData.isSuccess) { setState(() {}); diff --git a/lib/integral/intergra_view/integral_task.dart b/lib/integral/intergra_view/integral_task.dart index 408d8694..e9bb165a 100644 --- a/lib/integral/intergra_view/integral_task.dart +++ b/lib/integral/intergra_view/integral_task.dart @@ -6,6 +6,8 @@ import 'package:huixiang/utils/font_weight.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/view_widget/round_button.dart'; +import '../../view_widget/no_data_view.dart'; + class IntegralTask extends StatefulWidget { final SignInfo signInfo; @@ -57,28 +59,38 @@ class _IntegralTask extends State<IntegralTask> { ), Expanded( child: Container( - child: ListView.builder( - padding: EdgeInsets.only(left: 10.w, top: 20.h), - physics: BouncingScrollPhysics(), - // loop: false, - // pagination: SwiperPagination( - // alignment: Alignment.bottomCenter, - // builder: DotSwiperPaginationBuilder( - // size: 8, - // activeSize: 8, - // space: 5, - // activeColor: Colors.black, - // color: Colors.black.withAlpha(76), - // ), - // ), - itemBuilder: (context, position) { - return taskItem(widget.signInfo.taskList[position]); - }, - itemCount: (widget.signInfo != null && - widget.signInfo.taskList != null && - widget.signInfo.taskList.length > 0) - ? widget.signInfo.taskList.length - : 0), + child: (widget.signInfo != null && + widget.signInfo.taskList != null && + widget.signInfo.taskList.length > 0) + ? ListView.builder( + padding: EdgeInsets.only(left: 10.w, top: 20.h), + physics: BouncingScrollPhysics(), + // loop: false, + // pagination: SwiperPagination( + // alignment: Alignment.bottomCenter, + // builder: DotSwiperPaginationBuilder( + // size: 8, + // activeSize: 8, + // space: 5, + // activeColor: Colors.black, + // color: Colors.black.withAlpha(76), + // ), + // ), + itemBuilder: (context, position) { + return taskItem(widget.signInfo.taskList[position]); + }, + itemCount: (widget.signInfo != null && + widget.signInfo.taskList != null && + widget.signInfo.taskList.length > 0) + ? widget.signInfo.taskList.length + : 0) + : NoDataView( + src: "assets/image/xiao_fei.webp", + isShowBtn: false, + text: "暂无任务可做~", + fontSize: 16.sp, + margin: EdgeInsets.only(left: 60.w, right: 60.w), + ), ), flex: 1, ) diff --git a/lib/mine/mine_shop_page.dart b/lib/mine/mine_shop_page.dart index 8b1ae39b..9fc90c7d 100644 --- a/lib/mine/mine_shop_page.dart +++ b/lib/mine/mine_shop_page.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/page.dart'; @@ -85,19 +86,25 @@ class _MineShopPage extends State<MineShopPage> with WidgetsBindingObserver{ super.dispose(); } - queryVipCard() async { - BaseData<List<VipCard>> baseData = - await apiService.vipList({}).catchError((error) { - refreshController.refreshFailed(); - }); - if (baseData != null && baseData.isSuccess) { - coupons.clear(); - coupons.addAll(baseData.data); - setState(() { - refreshController.refreshCompleted(); + queryVipCard({bool showLoading = true}) async { + try{ + if(showLoading)EasyLoading.show(status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); + BaseData<List<VipCard>> baseData = + await apiService.vipList({ + "keywords":editingController.text, + }).catchError((error) { + refreshController.refreshFailed(); }); - } else { - refreshController.refreshFailed(); + if (baseData != null && baseData.isSuccess) { + coupons.clear(); + coupons.addAll(baseData.data); + refreshController.refreshCompleted(); + } else { + refreshController.refreshFailed(); + } + }finally{ + EasyLoading.dismiss(); + setState(() {}); } } @@ -109,6 +116,7 @@ class _MineShopPage extends State<MineShopPage> with WidgetsBindingObserver{ FocusScope.of(context).requestFocus(FocusNode()); }, child: Scaffold( + resizeToAvoidBottomInset: false, appBar: MyAppBar( title: "店铺充值", titleColor: Colors.black, @@ -142,7 +150,13 @@ class _MineShopPage extends State<MineShopPage> with WidgetsBindingObserver{ onTap: () { Navigator.of(context).pushNamed( '/router/mine_shop_recharge', - arguments: {"id": coupons[position].id}); + arguments: { + "id": coupons[position].id, + "tenantCode":coupons[position].tenantCode, + "storeId":coupons[position].storeList[0].id + }).then((value) { + queryVipCard(showLoading: false); + }); }, child: shopItem(coupons[position]), ); @@ -184,6 +198,7 @@ class _MineShopPage extends State<MineShopPage> with WidgetsBindingObserver{ textInputAction: TextInputAction.search, onEditingComplete: () { FocusScope.of(context).requestFocus(FocusNode()); + queryVipCard(); }, controller: editingController, cursorHeight: 25.h, diff --git a/lib/mine/mine_shop_recharge.dart b/lib/mine/mine_shop_recharge.dart index f2d93a53..cdf8e95e 100644 --- a/lib/mine/mine_shop_recharge.dart +++ b/lib/mine/mine_shop_recharge.dart @@ -1,31 +1,34 @@ -import 'package:barcode_widget/barcode_widget.dart'; +import 'dart:io'; + import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bmflocation/flutter_bmflocation.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:flutter_html/flutter_html.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:fluwx/fluwx.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; -import 'package:huixiang/retrofit/data/page.dart'; -import 'package:huixiang/retrofit/data/product.dart'; -import 'package:huixiang/retrofit/data/user_bill.dart'; import 'package:huixiang/retrofit/data/vip_card.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/store/scan.dart'; import 'package:huixiang/utils/font_weight.dart'; -import 'package:huixiang/utils/location.dart'; -import 'package:huixiang/utils/painter_bg.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/my_footer.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../retrofit/data/member_recharge_list.dart'; import '../retrofit/data/rechargeActLists.dart'; +import '../retrofit/data/wx_pay.dart'; +import '../retrofit/min_api.dart'; import '../utils/flutter_utils.dart'; +import '../utils/min.dart'; +import '../view_widget/classic_header.dart'; +import '../view_widget/my_footer.dart'; import '../view_widget/no_data_view.dart'; import '../view_widget/recharge_details_dialog.dart'; +import 'package:tobias/tobias.dart' as tobias; class MineShopRecharge extends StatefulWidget { final Map<String, dynamic> arguments; @@ -40,203 +43,358 @@ class MineShopRecharge extends StatefulWidget { class _MineShopRecharge extends State<MineShopRecharge> { ApiService apiService; + MinApiService minService; VipCard vipCard; - RechargeActLists rechargeActLists; + List<MemberRechargeList> memberRechargeList = []; int selectIndex = 0; double discount = 100; var checkIndex = 2; + dynamic payListen; + int _loadCount = 0; + String tenant; + String storeId; + String minToken; final RefreshController refreshController = RefreshController(); @override void dispose() { super.dispose(); refreshController.dispose(); + if (payListen != null) payListen.cancel(); } @override void initState() { super.initState(); - vipDetail("", ""); + storeId = widget.arguments["storeId"]; + tenant = widget.arguments["tenantCode"]; + _onRefresh(); + payListen = weChatResponseEventHandler.listen((event) async { + print("payCallback: ${event.errCode}"); + if (event.errCode == 0) { + SmartDialog.showToast("充值成功", alignment: Alignment.center); + } else { + SmartDialog.showToast("充值失败", alignment: Alignment.center); + } + vipDetail(); + }); } ///会员卡详情 - vipDetail(latitude, longitude) async { - SharedPreferences value = await SharedPreferences.getInstance(); - if (apiService == null) - apiService = - ApiService(Dio(), context: context, token: value.getString("token")); - BaseData<VipCard> baseData = await apiService.vipDetail({ - "id": widget.arguments["id"], - "latitude": "$latitude", - "longitude": "$longitude", - }).catchError((onError) {}); + vipDetail({bool isSingle = true}) async { + try { + BaseData<VipCard> baseData = await apiService.vipDetail({ + "id": widget.arguments["id"], + "latitude": "", + "longitude": "", + }).catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + vipCard = baseData.data; + } + } finally { + if(isSingle) + setState((){}); + else + addLoadCount(); + } + } + + ///小程序登录 + minLogin() async { + try { + var baseData = await apiService.minLogin(storeId).catchError((onError) { + debugPrint(onError.toString()); + }); + if (baseData != null && baseData.isSuccess) { + minToken = baseData.data["token"]; + SharedPreferences.getInstance().then( + (value) => { + value.setString('minToken', minToken), + value.setString('tenant', tenant), + value.setString('storeId', storeId), + }, + ); + minService = MinApiService( + Dio(), + context: context, + token: minToken, + tenant: tenant, + storeId: storeId, + ); + } + } finally {} + } + + ///充值列表 + queryRechargeActList() async { + try { + BaseData<List<MemberRechargeList>> baseData = + await minService.memberRechargeList().catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + memberRechargeList = baseData.data; + } + } finally { + addLoadCount(); + } + } + + ///门店充值 + shopRecharge() async { + if (minService == null) await minLogin(); + BaseData<dynamic> baseData = await minService.memberRecharge({ + "money": 0, + "rechargeId": memberRechargeList[selectIndex].id, + "type": checkIndex == 2 ? "wechat" : "alipay", + }).catchError((error) {}); if (baseData != null && baseData.isSuccess) { - vipCard = baseData.data; - refreshController.loadComplete(); + if (checkIndex == 2) { + if (Platform.isAndroid) { + if (!(await Min.isInitialize())) { + // 小程序的微信支付和app的充值支付使用同一个WXPayEntryActivity回调, + // 然而充值时小程序未初始化会导致回调内部代码调用getPackage空指针, + // 故而在此初始化一下 + await Min.initialize(); + } + } + WxPay wxPay = WxPay.fromJson(baseData.data); + await registerWxApi( + appId: wxPay.appId, + doOnAndroid: true, + universalLink: "https://hx.lotus-wallet.com/app/", + ); + payWithWeChat( + appId: wxPay.appId, + partnerId: wxPay.partnerId, + prepayId: wxPay.prepayId, + packageValue: wxPay.packageValue, + nonceStr: wxPay.nonceStr, + timeStamp: int.tryParse(wxPay.timeStamp), + sign: wxPay.sign, + ); + } else { + tobias.isAliPayInstalled().then((value) => { + // 判断是否安装了支付宝 + if (!value) + {SmartDialog.showToast("请安装支付宝", alignment: Alignment.center)} + else + { + tobias.aliPay(baseData.data["body"]).then((payRes) { + if (payRes['resultStatus'] == 9000 || + payRes['resultStatus'] == '9000') { + SmartDialog.showToast("充值成功", + alignment: Alignment.center); + } else { + SmartDialog.showToast(payRes['memo'], + alignment: Alignment.center); + } + vipDetail(); + }) + } + }); + } } else { - refreshController.loadFailed(); + SmartDialog.showToast(baseData.msg, alignment: Alignment.center); + } + } + + _onRefresh() async { + EasyLoading.show( + status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); + if (apiService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + apiService = + ApiService(Dio(), context: context, token: value.getString("token")); + } + if (minService == null) await minLogin(); + vipDetail(isSingle: false); + queryRechargeActList(); + } + + addLoadCount() { + _loadCount += 1; + if (_loadCount == 2) { + _loadCount = 0; + EasyLoading.dismiss(); + if (refreshController.isRefresh) refreshController.refreshCompleted(); + if (mounted) setState(() {}); } - print("object:object"); - setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( - appBar: MyAppBar( - title: "店铺充值", - titleColor: Colors.black, - background: Colors.white, - brightness: Brightness.dark, - leadingColor: Colors.black, - ), - body: - Column( - children: [ - shopRechargeCard(), - // NoDataView( - // src: "assets/image/xiao_fei.webp", - // isShowBtn: false, - // text: "当前店铺暂无充值套餐~", - // fontSize: 16.sp, - // margin: EdgeInsets.only(top: 120.h, left: 60.w, right: 60.w), - // ), - Expanded(child:ListView.builder( - padding: EdgeInsets.zero, - itemCount: 6, - scrollDirection: Axis.vertical, - shrinkWrap: true, - physics: BouncingScrollPhysics(), - itemBuilder: (context, position) { - return GestureDetector( - onTap: () { - setState(() { - selectIndex = position; - }); - }, - child: rechargeItem(position)); - }, - )), - Container( - width: double.infinity, - margin: EdgeInsets.only(left: 16, right: 16), - padding: EdgeInsets.only( - top: 20.h, - bottom: 24.h, - ), - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only(bottom: 16.h), - child: Text( - S.of(context).zhifufangshi, - style: TextStyle( - fontSize: 16.sp, - color: Colors.black, - fontWeight: FontWeight.bold, - ), + appBar: MyAppBar( + title: "店铺充值", + titleColor: Colors.black, + background: Colors.white, + brightness: Brightness.dark, + leadingColor: Colors.black, + ), + body: SmartRefresher( + enablePullDown: true, + enablePullUp: false, + header: MyHeader(), + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); + }, + ), + controller: refreshController, + onRefresh: _onRefresh, + physics: BouncingScrollPhysics(), + child: Column( + children: [ + shopRechargeCard(), + (memberRechargeList != null && + (memberRechargeList?.length ?? 0) > 0) + ? Expanded( + child: ListView.builder( + padding: EdgeInsets.zero, + itemCount: (memberRechargeList != null && + (memberRechargeList?.length ?? 0) > 0) + ? memberRechargeList.length + : 0, + scrollDirection: Axis.vertical, + shrinkWrap: true, + physics: BouncingScrollPhysics(), + itemBuilder: (context, position) { + return GestureDetector( + onTap: () { + setState(() { + selectIndex = position; + }); + }, + child: rechargeItem( + memberRechargeList[position], position)); + }, + )) + : NoDataView( + src: "assets/image/xiao_fei.webp", + isShowBtn: false, + text: "当前店铺暂无充值套餐~", + fontSize: 16.sp, + margin: + EdgeInsets.only(top: 90.h, left: 60.w, right: 60.w), ), + if (memberRechargeList != null && + (memberRechargeList?.length ?? 0) > 0) + Container( + width: double.infinity, + margin: EdgeInsets.only(left: 16, right: 16), + padding: EdgeInsets.only( + top: 20.h, + bottom: 24.h, ), - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - setState(() { - checkIndex = 2; - }); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Image.asset( - "assets/image/icon_we_chat.webp"), - Expanded( - flex: 1, - child: Padding( - padding: EdgeInsets.only(left: 8.w), - child: Text( - S.of(context).weixinzhifu, - style: TextStyle( - fontSize: 14.sp, - color: Color(0xff353535), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.only(bottom: 16.h), + child: Text( + S.of(context).zhifufangshi, + style: TextStyle( + fontSize: 16.sp, + color: Colors.black, + fontWeight: FontWeight.bold, + ), + ), + ), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + setState(() { + checkIndex = 2; + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset("assets/image/icon_we_chat.webp"), + Expanded( + flex: 1, + child: Padding( + padding: EdgeInsets.only(left: 8.w), + child: Text( + S.of(context).weixinzhifu, + style: TextStyle( + fontSize: 14.sp, + color: Color(0xff353535), + ), + ), ), ), - ), + checkView(2), + ], ), - checkView(2), - ], - ), + ), + SizedBox(height: 10.h), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + setState(() { + checkIndex = 3; + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset("assets/image/icon_alipay.webp"), + Expanded( + flex: 1, + child: Padding( + padding: EdgeInsets.only(left: 8.w), + child: Text( + S.of(context).zhifubao, + style: TextStyle( + fontSize: 14.sp, + color: Color(0xff353535), + ), + ), + ), + ), + checkView(3), + ], + ), + ), + ], ), - SizedBox(height: 10.h), - GestureDetector( + ), + if (memberRechargeList != null && + (memberRechargeList?.length ?? 0) > 0) + Align( + alignment: Alignment.bottomCenter, + child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - setState(() { - checkIndex = 3; - }); + shopRecharge(); }, - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Image.asset( - "assets/image/icon_alipay.webp"), - Expanded( - flex: 1, - child: Padding( - padding: EdgeInsets.only(left: 8.w), - child: Text( - S.of(context).zhifubao, - style: TextStyle( - fontSize: 14.sp, - color: Color(0xff353535), - ), - ), - ), + child: Container( + height: 56.h, + width: double.infinity, + alignment: Alignment.center, + decoration: BoxDecoration( + color: Color(0xFF32A060), + borderRadius: BorderRadius.circular(27), + ), + margin: EdgeInsets.only( + top: 12.h, left: 16.w, right: 16.w, bottom: 21.h), + child: Text( + S.of(context).querenchongzhi, + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.medium, + color: Colors.white, ), - checkView(3), - ], - ), - ), - ], - ), - ), - Align( - alignment: Alignment.bottomCenter, - child: GestureDetector( - onTap: () { - }, - child: Container( - height: 56.h, - width: double.infinity, - alignment: Alignment.center, - decoration: BoxDecoration( - color: Color(0xFF32A060), - borderRadius: BorderRadius.circular(27), - ), - margin: EdgeInsets.only( - top: 12.h, left: 16.w, right: 16.w, bottom: 21.h), - child: Text( - S.of(context).querenchongzhi, - style: TextStyle( - fontSize: 16.sp, - fontWeight: MyFontWeight.medium, - color: Colors.white, + ), ), ), - ), - ), - ) - ], - ), - ); + ) + ], + ), + )); } ///卡片背景底色 @@ -256,15 +414,15 @@ class _MineShopRecharge extends State<MineShopRecharge> { Widget shopRechargeCard() { return GestureDetector( behavior: HitTestBehavior.opaque, - onTap: (){ - Navigator.of(context).pushNamed( - '/router/mine_shop_details', + onTap: () { + Navigator.of(context).pushNamed('/router/mine_shop_details', arguments: {"id": widget.arguments["id"]}); }, child: Container( width: double.infinity, // height:140.h, - margin: EdgeInsets.only(bottom: 24.h, top: 14.h, left: 14.w, right: 14.w), + margin: + EdgeInsets.only(bottom: 24.h, top: 14.h, left: 14.w, right: 14.w), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, @@ -350,14 +508,15 @@ class _MineShopRecharge extends State<MineShopRecharge> { children: [ Expanded( child: Text( - "¥ ${vipCard != null ? vipCard.balance : ""}", - style: TextStyle( - color: Color(0xFF262626), - fontSize: 24.sp, - fontFamily: 'JDZhengHT', - fontWeight: MyFontWeight.medium, + "¥ ${vipCard != null ? vipCard.balance : ""}", + style: TextStyle( + color: Color(0xFF262626), + fontSize: 24.sp, + fontFamily: 'JDZhengHT', + fontWeight: MyFontWeight.medium, + ), ), - ),), + ), Text( "适用门店", style: TextStyle( @@ -366,7 +525,9 @@ class _MineShopRecharge extends State<MineShopRecharge> { fontWeight: MyFontWeight.regular, ), ), - SizedBox(width: 2,), + SizedBox( + width: 2, + ), Image.asset( "assets/image/icon_right_z.webp", width: 16, @@ -385,7 +546,7 @@ class _MineShopRecharge extends State<MineShopRecharge> { } ///充值item - Widget rechargeItem(index) { + Widget rechargeItem(MemberRechargeList memberRechargeList, index) { return Container( width: double.infinity, height: 69.h, @@ -393,12 +554,11 @@ class _MineShopRecharge extends State<MineShopRecharge> { borderRadius: BorderRadius.circular(4), border: Border.all( color: - selectIndex == index ? Color(0xFF32A060) : Color(0xFFFAFAFA), + selectIndex == index ? Color(0xFF32A060) : Color(0xFFFAFAFA), width: selectIndex == index ? 1 : 0, ), - color: - selectIndex == index ? Color(0XFFF0FAF4) : Colors.white), - margin: EdgeInsets.only(bottom: 14.h,left: 14.w,right: 14.w), + color: selectIndex == index ? Color(0XFFF0FAF4) : Colors.white), + margin: EdgeInsets.only(bottom: 14.h, left: 14.w, right: 14.w), padding: EdgeInsets.only(left: 16), child: Flex( direction: Axis.horizontal, @@ -419,7 +579,7 @@ class _MineShopRecharge extends State<MineShopRecharge> { ), TextSpan( text: - "555元", + "${AppUtils.calculateDouble(double.tryParse(memberRechargeList.rechargeMoney) ?? 0)}元", style: TextStyle( fontSize: 18.sp, fontFamily: 'JDZhengHT', @@ -435,7 +595,7 @@ class _MineShopRecharge extends State<MineShopRecharge> { width: 1.w, height: 37.h, color: - selectIndex == index ? Color(0xFF32A060) : Color(0xFF979797), + selectIndex == index ? Color(0xFF32A060) : Color(0xFF979797), margin: EdgeInsets.only(right: 16.w, left: 12), ), Expanded( @@ -457,7 +617,7 @@ class _MineShopRecharge extends State<MineShopRecharge> { ), TextSpan( text: - "526元", + "${AppUtils.calculateDouble((double.tryParse(memberRechargeList.rechargeMoney) ?? 0) + (double.tryParse(memberRechargeList.giftdMoney) ?? 0) + ((double.tryParse(memberRechargeList.rechargeMoney) ?? 0) - ((double.tryParse(memberRechargeList.rechargeMoney) ?? 0) * (discount / 100))))}元", style: TextStyle( fontSize: 18.sp, fontFamily: 'JDZhengHT', @@ -474,7 +634,8 @@ class _MineShopRecharge extends State<MineShopRecharge> { GestureDetector( onTap: () { setState(() { - if (selectIndex == index) showRecharge(index); + if (selectIndex == index) + showRecharge(memberRechargeList, index); }); }, child: Row( @@ -521,12 +682,93 @@ class _MineShopRecharge extends State<MineShopRecharge> { } ///充值说明底部弹窗 - showRecharge(index) { + showRecharge(MemberRechargeList memberRechargeList, index) { showModalBottomSheet( context: context, backgroundColor: Colors.transparent, builder: (context) { - return RechargeWidget(rechargeActLists.preferentialList[index]); + return Container( + padding: EdgeInsets.only(top: 12), + decoration: new BoxDecoration( + color: Colors.white, + borderRadius: new BorderRadius.only( + topLeft: const Radius.circular(25.0), + topRight: const Radius.circular(25.0))), + child: Container( + height: 355, + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: Container( + margin: EdgeInsets.symmetric(vertical: 12.h), + alignment: Alignment.center, + child: Text( + "充值说明", + style: TextStyle( + fontWeight: MyFontWeight.bold, + fontSize: 15.sp, + color: Color(0xFF353535), + ), + ), + )), + GestureDetector( + onTap: () { + setState(() { + Navigator.of(context).pop(); + }); + }, + child: Icon( + Icons.clear, + color: Colors.black, + size: 18, + ), + ), + SizedBox(width: 14), + ], + ), + SizedBox( + height: 12.h, + ), + Container( + width: double.infinity, + height: 1.h, + color: Color(0xFFF2F2F2), + margin: EdgeInsets.only(bottom: 13.h), + ), + Padding( + padding: EdgeInsets.only(left: 14), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Expanded( + child: Container( + color: Colors.white, + child: Html( + data: memberRechargeList?.remark ?? "", + customImageRenders: { + networkSourceMatcher(): + networkImageRender( + loadingWidget: () { + return Container(); + }, + ), + }, + ), + ), + ) + ], + ), + ) + ], + ), + ))); }); } diff --git a/lib/mine/mine_view/mine_item.dart b/lib/mine/mine_view/mine_item.dart index cd64533f..e2ecbdf2 100644 --- a/lib/mine/mine_view/mine_item.dart +++ b/lib/mine/mine_view/mine_item.dart @@ -224,7 +224,7 @@ class _MineItem extends State<MineItem> { ], ), SizedBox(height: 12.h,), - if(isShowMore) + // if(isShowMore) Row( children: [ ///我的砍价 @@ -314,9 +314,9 @@ class _MineItem extends State<MineItem> { // ),), ], ), - if(isShowMore) + // if(isShowMore) SizedBox(height: 12.h,), - if(isShowMore) + // if(isShowMore) Row( children: [ ////发票管理 @@ -345,38 +345,39 @@ class _MineItem extends State<MineItem> { Expanded(child:Container(),), ], ), - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - setState(() { - isShowMore = !isShowMore; - }); - }, - child: Container( - margin: EdgeInsets.symmetric(vertical: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - Text( - (isShowMore != null && !isShowMore)?S.of(context).zhankai: S.of(context).shouqi, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF32A060), - ), - ), - Icon( - (isShowMore != null && !isShowMore) - ? Icons.keyboard_arrow_down - : Icons.keyboard_arrow_up, - color: Color(0xFF32A060), - size: 18, - ), - ], - ),), - ) + ///收起展开 + // GestureDetector( + // behavior: HitTestBehavior.opaque, + // onTap: () { + // setState(() { + // isShowMore = !isShowMore; + // }); + // }, + // child: Container( + // margin: EdgeInsets.symmetric(vertical: 10), + // child: Row( + // mainAxisAlignment: MainAxisAlignment.center, + // crossAxisAlignment: CrossAxisAlignment.center, + // mainAxisSize: MainAxisSize.max, + // children: [ + // Text( + // (isShowMore != null && !isShowMore)?S.of(context).zhankai: S.of(context).shouqi, + // style: TextStyle( + // fontSize: 12.sp, + // fontWeight: MyFontWeight.regular, + // color: Color(0xFF32A060), + // ), + // ), + // Icon( + // (isShowMore != null && !isShowMore) + // ? Icons.keyboard_arrow_down + // : Icons.keyboard_arrow_up, + // color: Color(0xFF32A060), + // size: 18, + // ), + // ], + // ),), + // ) ], ), ); diff --git a/lib/mine/mine_vip/mine_attainment_page.dart b/lib/mine/mine_vip/mine_attainment_page.dart index 71665f2f..c7e1895c 100644 --- a/lib/mine/mine_vip/mine_attainment_page.dart +++ b/lib/mine/mine_vip/mine_attainment_page.dart @@ -20,6 +20,8 @@ import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../../view_widget/no_data_view.dart'; + class MineAttainmentPage extends StatefulWidget { final Map<String, dynamic> arguments; @@ -41,7 +43,6 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { SocialInfo infoNumber; final RefreshController refreshController = RefreshController(); - @override void dispose() { super.dispose(); @@ -115,7 +116,7 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { ); BaseData<SocialInfo> baseData = - await apiService.socialInfo().catchError((onError) {}); + await apiService.socialInfo().catchError((onError) {}); if (baseData != null && baseData.isSuccess) { setState(() { infoNumber = baseData.data; @@ -125,7 +126,7 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { EasyLoading.dismiss(); } - _onRefresh(){ + _onRefresh() { queryAttainmentBadges(); querySocialInfo(); } @@ -140,151 +141,162 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { ), ), child: Scaffold( - backgroundColor: Colors.transparent, - appBar: MyAppBar( - title:S.of(context).wodechengjiu, - titleColor: Colors.black, - titleSize: 18.sp, - background: Colors.transparent, - leadingColor: Colors.black, - ), - body: SmartRefresher( - controller: refreshController, - enablePullDown: true, - enablePullUp: false, - header: MyHeader(), - footer: CustomFooter( - builder: (context, mode) { - return MyFooter(mode); - }, - ), - onRefresh:(){ - setState(() { - _onRefresh(); - }); + backgroundColor: Colors.transparent, + appBar: MyAppBar( + title: S.of(context).wodechengjiu, + titleColor: Colors.black, + titleSize: 18.sp, + background: Colors.transparent, + leadingColor: Colors.black, + ), + body: SmartRefresher( + controller: refreshController, + enablePullDown: true, + enablePullUp: false, + header: MyHeader(), + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); }, - physics: BouncingScrollPhysics(), - child: Container( - child: - SingleChildScrollView( - physics: BouncingScrollPhysics(), - child: Column( - children: [ - SizedBox(height: 24), - MImage( - userInfo?.headimg ?? "", - isCircle: true, - width: 58, - height: 58, - fit: BoxFit.cover, - errorSrc: "assets/image/default_user.webp", - fadeSrc: "assets/image/default_user.webp", + ), + onRefresh: () { + setState(() { + _onRefresh(); + }); + }, + physics: BouncingScrollPhysics(), + child: Container( + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + child: Column( + children: [ + SizedBox(height: 24), + MImage( + userInfo?.headimg ?? "", + isCircle: true, + width: 58, + height: 58, + fit: BoxFit.cover, + errorSrc: "assets/image/default_user.webp", + fadeSrc: "assets/image/default_user.webp", + ), + SizedBox(height: 8), + Text( + userInfo?.nickname ?? S.of(context).denglu, + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.bold, + color: Color(0xFF353535), ), - SizedBox(height: 8), - Text( - userInfo?.nickname ?? S.of(context).denglu, - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.bold, - color: Color(0xFF353535), - ), + ), + SizedBox(height: 28), + Container( + margin: EdgeInsets.only( + left: 16, right: 16, top: 26, bottom: 8), + padding: EdgeInsets.all(20), + decoration: BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 3), + blurRadius: 14, + spreadRadius: 0, + ) + ], + borderRadius: BorderRadius.all(Radius.circular(8)), ), - SizedBox(height: 28), - Container( - margin: - EdgeInsets.only(left: 16, right: 16, top: 26, bottom: 8), - padding: EdgeInsets.all(20), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 3), - blurRadius: 14, - spreadRadius: 0, - ) - ], - borderRadius: BorderRadius.all(Radius.circular(8)), - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Text( - S.of(context).chengjiuhuizhang, - style: TextStyle( - fontWeight: MyFontWeight.medium, - fontSize: 14.sp, - color: Color(0xFF353535)), - ), - SizedBox(width: 4), - Text( - "(", - style: TextStyle( - fontWeight: MyFontWeight.medium, - fontSize: 14, - color: Color(0xFF353535)), - ), - Text( - infoNumber != null ? infoNumber.achievementNumber.toString() :"0", - style: TextStyle( - fontWeight: MyFontWeight.medium, - fontSize: 14, - color: Color(0xFF32A060)), - ), - Text( - "/${vipBadgesList.length})", - style: TextStyle( - fontWeight: MyFontWeight.medium, - fontSize: 14, - color: Color(0xFF353535)), - ), - ], - ), - SizedBox(height: 12), - attainmentBadge(), - ], - ), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Text( + S.of(context).chengjiuhuizhang, + style: TextStyle( + fontWeight: MyFontWeight.medium, + fontSize: 14.sp, + color: Color(0xFF353535)), + ), + SizedBox(width: 4), + Text( + "(", + style: TextStyle( + fontWeight: MyFontWeight.medium, + fontSize: 14, + color: Color(0xFF353535)), + ), + Text( + infoNumber != null + ? infoNumber.achievementNumber.toString() + : "0", + style: TextStyle( + fontWeight: MyFontWeight.medium, + fontSize: 14, + color: Color(0xFF32A060)), + ), + Text( + "/${vipBadgesList.length})", + style: TextStyle( + fontWeight: MyFontWeight.medium, + fontSize: 14, + color: Color(0xFF353535)), + ), + ], + ), + SizedBox(height: 12), + attainmentBadge(), + ], ), - ], - ), + ), + ], ), ), - ),), + ), + ), + ), ); } ///成就徽章列表 Widget attainmentBadge() { - return GridView.builder( - itemCount: vipBadgesList == null ? 0 : vipBadgesList.length, - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - //一行的Widget数量 - crossAxisCount: 3, - //水平子Widget之间间距 - crossAxisSpacing: 13, - //垂直子Widget之间间距 - mainAxisSpacing: 12, - //子Widget宽高比例 - childAspectRatio: AppUtils.textScale(context) > 1 - ? (1 - ((AppUtils.textScale(context) - 1))) - : 0.85, - ), - itemBuilder: (context, index) { - return GestureDetector( - onTap: () { - setState(() { - queryAchievementDetail(index); - }); - }, - child: badgeItem(vipBadgesList[index]), - ); - }, - ); + return (vipBadgesList != null && (vipBadgesList?.length ?? 0) > 0) + ? GridView.builder( + itemCount: vipBadgesList == null ? 0 : vipBadgesList.length, + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + //一行的Widget数量 + crossAxisCount: 3, + //水平子Widget之间间距 + crossAxisSpacing: 13, + //垂直子Widget之间间距 + mainAxisSpacing: 12, + //子Widget宽高比例 + childAspectRatio: AppUtils.textScale(context) > 1 + ? (1 - ((AppUtils.textScale(context) - 1))) + : 0.85, + ), + itemBuilder: (context, index) { + return GestureDetector( + onTap: () { + setState(() { + queryAchievementDetail(index); + }); + }, + child: badgeItem(vipBadgesList[index]), + ); + }, + ) + : NoDataView( + src: "assets/image/xiao_fei.webp", + isShowBtn: false, + text: "当前暂无成就徽章~", + fontSize: 16.sp, + margin: EdgeInsets.only(left: 60.w, right: 60.w), + ); + ; } Widget badgeItem(VipBadgesList vipBadgesList) { @@ -358,7 +370,7 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { ), SizedBox(height: 10), Text( - "${vipBadgesList.length >index ?vipBadgesList[index].name :""}${achievementDetail.length > checkPosition ?achievementDetail[checkPosition].name:""}徽章", + "${vipBadgesList.length > index ? vipBadgesList[index].name : ""}${achievementDetail.length > checkPosition ? achievementDetail[checkPosition].name : ""}徽章", style: TextStyle( fontSize: 16.sp, fontWeight: MyFontWeight.semi_bold, @@ -369,7 +381,7 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { height: 6.h, ), Text( - "再${vipBadgesList.length >index ? vipBadgesList[index].name :""} ${AppUtils.calculateDouble(double.tryParse(achievementDetail.length > checkPosition ?achievementDetail[checkPosition].lessScore :"") ?? 0)} 即可升级", + "再${vipBadgesList.length > index ? vipBadgesList[index].name : ""} ${AppUtils.calculateDouble(double.tryParse(achievementDetail.length > checkPosition ? achievementDetail[checkPosition].lessScore : "") ?? 0)} 即可升级", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, @@ -392,27 +404,29 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { ), SizedBox(width: 8), Column( - crossAxisAlignment:CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: - achievementDetail[checkPosition].rewardList != null - ? achievementDetail[checkPosition].rewardList.map((e) { - return Text( - rewardStr(e), - style: TextStyle( - fontWeight: MyFontWeight.regular, - fontSize: 12.sp, - color: Color(0xFF515151)), - ); - }).toList() - : [], + achievementDetail[checkPosition].rewardList != null + ? achievementDetail[checkPosition] + .rewardList + .map((e) { + return Text( + rewardStr(e), + style: TextStyle( + fontWeight: MyFontWeight.regular, + fontSize: 12.sp, + color: Color(0xFF515151)), + ); + }).toList() + : [], ), ], ), Expanded( child: Container( height: double.maxFinite, - margin: EdgeInsets.only(top:14), + margin: EdgeInsets.only(top: 14), child: ListView.builder( shrinkWrap: true, scrollDirection: Axis.horizontal, @@ -443,12 +457,12 @@ class _MineAttainmentPage extends State<MineAttainmentPage> { ); } - String rewardStr(RewardList rewardList){ - if(rewardList.rewardType == 1) + String rewardStr(RewardList rewardList) { + if (rewardList.rewardType == 1) return "积分:${rewardList.refId}"; - else if(rewardList.rewardType == 2) + else if (rewardList.rewardType == 2) return "平台余额:${rewardList.refId}"; - else if(rewardList.rewardType == 3) + else if (rewardList.rewardType == 3) return "平台兑换券:${rewardList.couponName}"; return ""; } diff --git a/lib/mine/recharge_page.dart b/lib/mine/recharge_page.dart index abd7ef2f..5f946c78 100644 --- a/lib/mine/recharge_page.dart +++ b/lib/mine/recharge_page.dart @@ -19,9 +19,14 @@ import 'package:huixiang/utils/min.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/recharge_details_dialog.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:tobias/tobias.dart' as tobias; +import '../view_widget/classic_header.dart'; +import '../view_widget/my_footer.dart'; +import '../view_widget/no_data_view.dart'; + class RechargePage extends StatefulWidget { @override State<StatefulWidget> createState() { @@ -43,19 +48,13 @@ class _RechargePage extends State<RechargePage> { RechargeActLists rechargeActLists; int selectStoreIndex = 0; String recommendName; + final RefreshController refreshController = RefreshController(); + int _loadCount = 0; @override void initState() { super.initState(); - - SharedPreferences.getInstance().then((value) { - apiService = ApiService(Dio(), - context: context, token: value.getString("token"), pay: true); - queryBenefitList(); - queryRuleDetails(); - queryRechargeActList(); - queryUserBalance(); - }); + _onRefresh(); payListen = weChatResponseEventHandler.listen((event) async { print("payCallback: ${event.errCode}"); if (event.errCode == 0) { @@ -77,10 +76,10 @@ class _RechargePage extends State<RechargePage> { ///会员权益列表 queryBenefitList() async { - BaseData<List<VipBenefitList>> baseData = - await apiService.benefitList().catchError((onError) {}); - if (baseData != null && baseData.isSuccess) { - setState(() { + try { + BaseData<List<VipBenefitList>> baseData = + await apiService.benefitList().catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { vipBenefitList.clear(); vipBenefitList.addAll(baseData.data); vipBenefitList.forEach((element) { @@ -90,51 +89,77 @@ class _RechargePage extends State<RechargePage> { discount = double.parse(element.config); } }); - }); + } + } finally { + addLoadCount(); } - EasyLoading.dismiss(); } queryUserBalance() async { - BaseData<UserInfo> baseData = - await apiService.queryInfo().catchError((onError) {}); - if (baseData != null && baseData.isSuccess) { - userInfo = baseData.data; - mBalance = userInfo?.money ?? "0"; - if (mounted) setState(() {}); + try { + BaseData<UserInfo> baseData = + await apiService.queryInfo().catchError((onError) { + SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type), + alignment: Alignment.center); + refreshController.refreshFailed(); + refreshController.loadFailed(); + }); + if (baseData != null && baseData.isSuccess) { + userInfo = baseData.data; + mBalance = userInfo?.money ?? "0"; + } + } finally { + addLoadCount(); } } ///会员权益介绍/规则/说明/储值说明 queryRuleDetails() async { - BaseData<VipRuleDetails> baseData = - await apiService.vipBenefit().catchError((onError) {}); - if (baseData != null && baseData.isSuccess) { - setState(() { + try { + BaseData<VipRuleDetails> baseData = + await apiService.vipBenefit().catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { vipRuleDetails = baseData.data; - }); + } + } finally { + addLoadCount(); } - EasyLoading.dismiss(); } ///充值列表 queryRechargeActList() async { - if (apiService == null) { - SharedPreferences value = await SharedPreferences.getInstance(); - apiService = ApiService( - Dio(), - context: context, - token: value.getString("token"), - ); - } - BaseData<RechargeActLists> baseData = - await apiService.rechargeActList().catchError((onError) {}); - if (baseData != null && baseData.isSuccess) { - setState(() { + try { + BaseData<RechargeActLists> baseData = + await apiService.rechargeActList("admin").catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { rechargeActLists = baseData.data; - }); + } + } finally { + addLoadCount(); + } + } + + _onRefresh() async { + EasyLoading.show( + status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); + SharedPreferences value = await SharedPreferences.getInstance(); + if (apiService == null) + apiService = ApiService(Dio(), + context: context, token: value.getString("token"), pay: true); + queryBenefitList(); + queryRuleDetails(); + queryRechargeActList(); + queryUserBalance(); + } + + addLoadCount() { + _loadCount += 1; + if (_loadCount == 4) { + _loadCount = 0; + EasyLoading.dismiss(); + if (refreshController.isRefresh) refreshController.refreshCompleted(); + if (mounted) setState(() {}); } - EasyLoading.dismiss(); } @override @@ -148,403 +173,423 @@ class _RechargePage extends State<RechargePage> { leadingColor: Colors.black, ), body: Container( - color: Color(0xFFFFFFFF), - child: SingleChildScrollView( - physics: BouncingScrollPhysics(), - child: Container( - child: Column( - children: [ - Container( - margin: EdgeInsets.only(left: 16, right: 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - // ItemInputWidget( - // S.of(context).qingshuruchongzhijine, - // hintText: "", - // controller: controller, - // padding: EdgeInsets.all(20), - // errorText: S.of(context).chongzhizuixiaojine(100), - // titleColor: Color(0xFF727272), - // errorTextColor: Color(0xFF32A060), - // radius: 8, - // discount: discount / 10, - // style: TextStyle( - // fontWeight: FontWeight.bold, - // fontSize: 27.sp, - // color: color, - // ), - // inputLimit: 6, - // textInputType: TextInputType.number, - // textInputFormatter: - // FilteringTextInputFormatter.digitsOnly, - // onChanged: (value) { - // if (value != null && - // value != "" && - // double.tryParse(value) < 100) { - // color = Colors.red; - // } else { - // color = Colors.black; - // } - // setState(() {}); - // }, - // ), - SizedBox( - height: 20, - ), - Row( + color: Color(0xFFFFFFFF), + child: SmartRefresher( + enablePullDown: true, + enablePullUp: false, + header: MyHeader(), + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); + }, + ), + controller: refreshController, + onRefresh: _onRefresh, + physics: BouncingScrollPhysics(), + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + child: Container( + child: Column( + children: [ + Container( + margin: EdgeInsets.only(left: 16, right: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, children: [ - Expanded( - child: Text( + // ItemInputWidget( + // S.of(context).qingshuruchongzhijine, + // hintText: "", + // controller: controller, + // padding: EdgeInsets.all(20), + // errorText: S.of(context).chongzhizuixiaojine(100), + // titleColor: Color(0xFF727272), + // errorTextColor: Color(0xFF32A060), + // radius: 8, + // discount: discount / 10, + // style: TextStyle( + // fontWeight: FontWeight.bold, + // fontSize: 27.sp, + // color: color, + // ), + // inputLimit: 6, + // textInputType: TextInputType.number, + // textInputFormatter: + // FilteringTextInputFormatter.digitsOnly, + // onChanged: (value) { + // if (value != null && + // value != "" && + // double.tryParse(value) < 100) { + // color = Colors.red; + // } else { + // color = Colors.black; + // } + // setState(() {}); + // }, + // ), + SizedBox( + height: 20, + ), + Row( + children: [ + Expanded( + child: Text( S.of(context).zhanghuyue, style: TextStyle( fontSize: 15.sp, color: Color(0xFF181818), fontFamily: 'JDZhengHT', - fontWeight: - MyFontWeight.semi_bold), + fontWeight: MyFontWeight.semi_bold), )), - Text.rich( - TextSpan(children: [ - TextSpan( - text: "$mBalance", - style: TextStyle( - fontSize: 26.sp, - fontFamily: 'JDZhengHT', - color: Color(0xFF181818), - fontWeight: - MyFontWeight.semi_bold), - ), - TextSpan( - text: "元", - style: TextStyle( - fontSize: 15.sp, - color: Color(0xFF181818), - fontWeight: - MyFontWeight.semi_bold), + Text.rich( + TextSpan(children: [ + TextSpan( + text: "$mBalance", + style: TextStyle( + fontSize: 26.sp, + fontFamily: 'JDZhengHT', + color: Color(0xFF181818), + fontWeight: MyFontWeight.semi_bold), + ), + TextSpan( + text: "元", + style: TextStyle( + fontSize: 15.sp, + color: Color(0xFF181818), + fontWeight: MyFontWeight.semi_bold), + ), + ]), ), - ]), + ], ), + SizedBox(height: 28), + rechargeList(), + // Row( + // crossAxisAlignment: CrossAxisAlignment.start, + // mainAxisAlignment: MainAxisAlignment.spaceAround, + // children: [ + // if (vipRuleDetails?.recharge != null && + // vipRuleDetails.recharge != "") + // Expanded( + // child: Container( + // color: Colors.white, + // child: Html( + // data: "注意:${vipRuleDetails?.recharge ?? ""}", + // customImageRenders: { + // networkSourceMatcher(): networkImageRender( + // loadingWidget: () { + // return Container(); + // }, + // ), + // }, + // ), + // ), + // ) + // ], + // ), ], + )), + if (rechargeActLists != null && + (rechargeActLists?.preferentialList?.length ?? 0) > 0) + Container( + width: double.infinity, + margin: EdgeInsets.only(left: 16, right: 16), + padding: EdgeInsets.only( + top: 20.h, + bottom: 24.h, ), - SizedBox(height: 28), - rechargeList(), - // Row( - // crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisAlignment: MainAxisAlignment.spaceAround, - // children: [ - // if (vipRuleDetails?.recharge != null && - // vipRuleDetails.recharge != "") - // Expanded( - // child: Container( - // color: Colors.white, - // child: Html( - // data: "注意:${vipRuleDetails?.recharge ?? ""}", - // customImageRenders: { - // networkSourceMatcher(): networkImageRender( - // loadingWidget: () { - // return Container(); - // }, - // ), - // }, - // ), - // ), - // ) - // ], + // decoration: BoxDecoration( + // color: Colors.white, + // borderRadius: BorderRadius.circular(4), // ), - ], - )), - Container( - width: double.infinity, - margin: EdgeInsets.only(left: 16, right: 16), - padding: EdgeInsets.only( - top: 20.h, - bottom: 24.h, - ), - // decoration: BoxDecoration( - // color: Colors.white, - // borderRadius: BorderRadius.circular(4), - // ), - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only(bottom: 16.h), - child: Text( - S.of(context).zhifufangshi, - style: TextStyle( - fontSize: 16.sp, - color: Colors.black, - fontWeight: FontWeight.bold, - ), - ), - ), - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - setState(() { - checkIndex = 2; - }); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Image.asset( - "assets/image/icon_we_chat.webp"), - Expanded( - flex: 1, - child: Padding( - padding: EdgeInsets.only(left: 8.w), - child: Text( - S.of(context).weixinzhifu, - style: TextStyle( - fontSize: 14.sp, - color: Color(0xff353535), - ), + Padding( + padding: EdgeInsets.only(bottom: 16.h), + child: Text( + S.of(context).zhifufangshi, + style: TextStyle( + fontSize: 16.sp, + color: Colors.black, + fontWeight: FontWeight.bold, ), ), ), - checkView(2), - ], - ), - ), - SizedBox(height: 10.h), - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - setState(() { - checkIndex = 3; - }); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Image.asset( - "assets/image/icon_alipay.webp"), - Expanded( - flex: 1, - child: Padding( - padding: EdgeInsets.only(left: 8.w), - child: Text( - S.of(context).zhifubao, - style: TextStyle( - fontSize: 14.sp, - color: Color(0xff353535), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + setState(() { + checkIndex = 2; + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset("assets/image/icon_we_chat.webp"), + Expanded( + flex: 1, + child: Padding( + padding: EdgeInsets.only(left: 8.w), + child: Text( + S.of(context).weixinzhifu, + style: TextStyle( + fontSize: 14.sp, + color: Color(0xff353535), + ), + ), + ), ), - ), + checkView(2), + ], + ), + ), + SizedBox(height: 10.h), + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + setState(() { + checkIndex = 3; + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset("assets/image/icon_alipay.webp"), + Expanded( + flex: 1, + child: Padding( + padding: EdgeInsets.only(left: 8.w), + child: Text( + S.of(context).zhifubao, + style: TextStyle( + fontSize: 14.sp, + color: Color(0xff353535), + ), + ), + ), + ), + checkView(3), + ], ), ), - checkView(3), ], ), ), - ], - ), - ), - if((rechargeActLists?.isOpen ?? false) == true) - GestureDetector( - onTap: () { - showRecommendStore(); - }, - child: Container( - padding: EdgeInsets.only( - left: 14.w, - right: 16.w, - top: 14.h, - bottom: 14.h), - margin: EdgeInsets.only( - bottom: 22.h, left: 14.w, right: 14.w), - decoration: BoxDecoration( - color: Color(0xFFFAFAFA), - borderRadius: BorderRadius.circular(4), - ), - child: Row( - children: [ - Image.asset( - "assets/image/recharge_z.webp", - width: 16.w, - height: 17.h, - fit: BoxFit.fill, + if ((rechargeActLists?.isOpen ?? false) == true) + GestureDetector( + onTap: () { + showRecommendStore(); + }, + child: Container( + padding: EdgeInsets.only( + left: 14.w, + right: 16.w, + top: 14.h, + bottom: 14.h), + margin: EdgeInsets.only( + bottom: 22.h, left: 14.w, right: 14.w), + decoration: BoxDecoration( + color: Color(0xFFFAFAFA), + borderRadius: BorderRadius.circular(4), ), - SizedBox(width: 8.w), - Expanded( - child: Text( - recommendName ??"为喜爱门店打call!(可选)", + child: Row( + children: [ + Image.asset( + "assets/image/recharge_z.webp", + width: 16.w, + height: 17.h, + fit: BoxFit.fill, + ), + SizedBox(width: 8.w), + Expanded( + child: Text( + recommendName ?? "为喜爱门店打call!(可选)", style: TextStyle( fontWeight: MyFontWeight.regular, fontSize: 12.sp, - color: (recommendName != null) ?Color(0xFF32A060):Color(0xFF868686), + color: (recommendName != null) + ? Color(0xFF32A060) + : Color(0xFF868686), ), )), - Icon( - Icons.arrow_forward_ios, - size: 16, - ), - ], - )), - ), - Align( - alignment: Alignment.bottomCenter, - child: GestureDetector( - onTap: () { - recharge(); - }, - child: Container( - height: 56.h, - width: double.infinity, - alignment: Alignment.center, - decoration: BoxDecoration( - color: Color(0xFF32A060), - borderRadius: BorderRadius.circular(27), + Icon( + Icons.arrow_forward_ios, + size: 16, + ), + ], + )), ), - margin: EdgeInsets.only( - left: 16, right: 16, bottom: 21), - child: Text( - S.of(context).querenchongzhi, - style: TextStyle( - fontSize: 16.sp, - fontWeight: MyFontWeight.medium, - color: Colors.white, + if (rechargeActLists != null && + (rechargeActLists?.preferentialList?.length ?? 0) > 0) + Align( + alignment: Alignment.bottomCenter, + child: GestureDetector( + onTap: () { + recharge(); + }, + child: Container( + height: 56.h, + width: double.infinity, + alignment: Alignment.center, + decoration: BoxDecoration( + color: Color(0xFF32A060), + borderRadius: BorderRadius.circular(27), + ), + margin: EdgeInsets.only( + left: 16, right: 16, bottom: 21), + child: Text( + S.of(context).querenchongzhi, + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.medium, + color: Colors.white, + ), + ), + ), ), - ), - ), - ), - - // Container( - // height: 56.h, - // color: Colors.white, - // child: Row( - // children: [ - // Expanded(child:Container( - // padding:EdgeInsets.only(top: 7.h,left:16), - // child:Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Row( - // children: [ - // Text( - // S.of(context).heji, - // style: TextStyle( - // fontSize: 14.sp, - // fontWeight: MyFontWeight.regular, - // color: Colors.black, - // ), - // ), - // Text( - // controller.text, - // style: TextStyle( - // fontSize: 16.sp, - // fontWeight: MyFontWeight.medium, - // color: Color(0xFF32A060), - // ), - // ), - // ], - // ), - // if(controller.text != "") - // Text.rich( - // TextSpan( - // children: [ - // TextSpan( - // text: "充值", - // style: TextStyle( - // fontSize:12.sp, - // fontWeight: MyFontWeight.regular, - // color: Color(0xFFADADAD), - // ), - // ), - // TextSpan( - // text:"¥${controller.text}", - // style: TextStyle( - // fontSize: 12.sp, - // fontWeight: MyFontWeight.regular, - // color:Color(0xff3541C9), - // ), - // ), - // TextSpan( - // text: "赠送", - // style: TextStyle( - // fontSize:12.sp, - // fontWeight: MyFontWeight.regular, - // color: Color(0xFFADADAD), - // ), - // ), - // TextSpan( - // text:"¥${((double.tryParse(controller.text)??0) - ((double.tryParse(controller.text)??0) * (discount/100))).toStringAsFixed(2)}", - // style: TextStyle( - // fontSize: 12.sp, - // fontWeight: MyFontWeight.regular, - // color: Color(0xff3541C9), - // ), - // ),TextSpan( - // text: "元", - // style: TextStyle( - // fontSize:12.sp, - // fontWeight: MyFontWeight.regular, - // color: Color(0xFFADADAD), - // ), - // ), - // ], - // ), - // ), - // ], - // )) - // ), - // GestureDetector( - // onTap: () { - // recharge(); - // }, - // child: RoundButton( - // width: 103.w, - // height: 54.h, - // text: S.of(context).chongzhi, - // textColor: Colors.white, - // fontWeight: MyFontWeight.regular, - // backgroup: Color(0xFF32A060), - // radius: 0, - // fontSize: 16.sp, - // padding: EdgeInsets.symmetric(vertical: 5.h), - // ), - // ), - // ], - // ), - // ) - ) - ], + // Container( + // height: 56.h, + // color: Colors.white, + // child: Row( + // children: [ + // Expanded(child:Container( + // padding:EdgeInsets.only(top: 7.h,left:16), + // child:Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Row( + // children: [ + // Text( + // S.of(context).heji, + // style: TextStyle( + // fontSize: 14.sp, + // fontWeight: MyFontWeight.regular, + // color: Colors.black, + // ), + // ), + // Text( + // controller.text, + // style: TextStyle( + // fontSize: 16.sp, + // fontWeight: MyFontWeight.medium, + // color: Color(0xFF32A060), + // ), + // ), + // ], + // ), + // if(controller.text != "") + // Text.rich( + // TextSpan( + // children: [ + // TextSpan( + // text: "充值", + // style: TextStyle( + // fontSize:12.sp, + // fontWeight: MyFontWeight.regular, + // color: Color(0xFFADADAD), + // ), + // ), + // TextSpan( + // text:"¥${controller.text}", + // style: TextStyle( + // fontSize: 12.sp, + // fontWeight: MyFontWeight.regular, + // color:Color(0xff3541C9), + // ), + // ), + // TextSpan( + // text: "赠送", + // style: TextStyle( + // fontSize:12.sp, + // fontWeight: MyFontWeight.regular, + // color: Color(0xFFADADAD), + // ), + // ), + // TextSpan( + // text:"¥${((double.tryParse(controller.text)??0) - ((double.tryParse(controller.text)??0) * (discount/100))).toStringAsFixed(2)}", + // style: TextStyle( + // fontSize: 12.sp, + // fontWeight: MyFontWeight.regular, + // color: Color(0xff3541C9), + // ), + // ),TextSpan( + // text: "元", + // style: TextStyle( + // fontSize:12.sp, + // fontWeight: MyFontWeight.regular, + // color: Color(0xFFADADAD), + // ), + // ), + // ], + // ), + // ), + // ], + // )) + // ), + // GestureDetector( + // onTap: () { + // recharge(); + // }, + // child: RoundButton( + // width: 103.w, + // height: 54.h, + // text: S.of(context).chongzhi, + // textColor: Colors.white, + // fontWeight: MyFontWeight.regular, + // backgroup: Color(0xFF32A060), + // radius: 0, + // fontSize: 16.sp, + // padding: EdgeInsets.symmetric(vertical: 5.h), + // ), + // ), + // ], + // ), + // ) + ) + ], + ), + ), ), - ), - ), - ), + )), ); } var checkIndex = 2; Widget rechargeList() { - return ListView.builder( - padding: EdgeInsets.zero, - itemCount: (rechargeActLists != null && (rechargeActLists?.preferentialList?.length ?? 0) > 0) ? rechargeActLists.preferentialList.length : 0, - scrollDirection: Axis.vertical, - shrinkWrap: true, - physics: BouncingScrollPhysics(), - itemBuilder: (context, position) { - return GestureDetector( - onTap: () { - setState(() { - selectIndex = position; - }); + return (rechargeActLists != null && + (rechargeActLists?.preferentialList?.length ?? 0) > 0) + ? ListView.builder( + padding: EdgeInsets.zero, + itemCount: (rechargeActLists != null && + (rechargeActLists?.preferentialList?.length ?? 0) > 0) + ? rechargeActLists.preferentialList.length + : 0, + scrollDirection: Axis.vertical, + shrinkWrap: true, + physics: BouncingScrollPhysics(), + itemBuilder: (context, position) { + return GestureDetector( + onTap: () { + setState(() { + selectIndex = position; + }); + }, + child: rechargeItem( + rechargeActLists.preferentialList[position], position)); }, - child: rechargeItem(rechargeActLists.preferentialList[position], position)); - }, - ); + ) + : NoDataView( + src: "assets/image/xiao_fei.webp", + isShowBtn: false, + text: "暂无充值套餐~", + fontSize: 16.sp, + margin: EdgeInsets.only(top: 90.h, left: 60.w, right: 60.w), + ); } Widget rechargeItem(PreferentialList preferentialList, index) { @@ -695,13 +740,13 @@ class _RechargePage extends State<RechargePage> { ///选择推荐门店 showRecommendStore() { showModalBottomSheet( - context: context, - backgroundColor: Colors.transparent, + context: context, + backgroundColor: Colors.transparent, builder: (BuildContext context) { return StatefulBuilder(builder: ( - context, - state, - ) { + context, + state, + ) { return Container( height: 355.h, decoration: BoxDecoration( @@ -719,17 +764,17 @@ class _RechargePage extends State<RechargePage> { children: [ Expanded( child: Container( - alignment: Alignment.center, - margin: EdgeInsets.symmetric(vertical: 12), - child: Text( - S.of(context).xuanzetuijianmendian, - style: TextStyle( - fontWeight: MyFontWeight.bold, - fontSize: 15.sp, - color: Color(0xFF353535), - ), - ), - )), + alignment: Alignment.center, + margin: EdgeInsets.symmetric(vertical: 12), + child: Text( + S.of(context).xuanzetuijianmendian, + style: TextStyle( + fontWeight: MyFontWeight.bold, + fontSize: 15.sp, + color: Color(0xFF353535), + ), + ), + )), GestureDetector( onTap: () { setState(() { @@ -752,24 +797,24 @@ class _RechargePage extends State<RechargePage> { ), Expanded( child: ListView.builder( - physics: BouncingScrollPhysics(), - itemBuilder: (context, position) { - return GestureDetector( - onTap: () { - state(() { - selectStoreIndex = position; - }); - }, - child: recommendStoreItem(position), - ); + physics: BouncingScrollPhysics(), + itemBuilder: (context, position) { + return GestureDetector( + onTap: () { + state(() { + selectStoreIndex = position; + }); }, - itemCount: rechargeActLists.channels.length ?? 0, - )), + child: recommendStoreItem(position), + ); + }, + itemCount: rechargeActLists.channels.length ?? 0, + )), GestureDetector( onTap: () { setState(() { recommendName = - rechargeActLists.channels[selectStoreIndex]; + rechargeActLists.channels[selectStoreIndex]; Navigator.of(context).pop(); }); }, @@ -797,7 +842,8 @@ class _RechargePage extends State<RechargePage> { ), ); }); - },); + }, + ); } Widget recommendStoreItem(index) { diff --git a/lib/order/order_history_page.dart b/lib/order/order_history_page.dart index 8e37518e..f6011da1 100644 --- a/lib/order/order_history_page.dart +++ b/lib/order/order_history_page.dart @@ -1,5 +1,6 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/order/order_utils.dart'; @@ -133,57 +134,29 @@ class OrderHistoryList extends StatefulWidget { class _OrderHistoryList extends State<OrderHistoryList> with AutomaticKeepAliveClientMixin { final RefreshController refreshController = RefreshController(); - - @override - Widget build(BuildContext context) { - super.build(context); - return SmartRefresher( - controller: refreshController, - enablePullDown: true, - enablePullUp: true, - physics: BouncingScrollPhysics(), - header: MyHeader(), - footer: CustomFooter( - builder: (context, mode) { - return MyFooter(mode); - }, - ), - onRefresh: _onRefresh, - onLoading: queryOrder, - child: (orderInfos != null && orderInfos.length > 0) - ? ListView.builder( - itemCount: orderInfos != null ? orderInfos.length : 0, - itemBuilder: (context, position) { - return InkWell( - onTap: () { - Navigator.of(context).pushNamed('/router/order_details', - arguments: {"id": orderInfos[position].id,"jumpState":2}); - }, - child: orderItem(orderInfos[position]), - ); - }) - : NoDataView( - src: "assets/image/ding_dan.webp", - isShowBtn: false, - text: "目前暂无订单,快去下一单吧~", - fontSize: 16.sp, - margin: EdgeInsets.only(top: 120), - ), - ); - } - bool isRemake = true; - ApiService apiService; int current = 1; + List<OrderInfo> orderInfos = []; + UserInfo userInfo; + @override + void initState() { + super.initState(); + SharedPreferences.getInstance().then((value) => { + apiService = ApiService(Dio(), + showLoading: true, + context: context, + token: value.getString("token")), + queryOrder(), + queryUserBalance(), + }); + } _onRefresh() { current = 1; queryOrder(); } - List<OrderInfo> orderInfos = []; - queryOrder() async { BaseData<PageInfo<OrderInfo>> baseData = await apiService.orderList({ "current": current, @@ -214,24 +187,173 @@ class _OrderHistoryList extends State<OrderHistoryList> } setState(() {}); } else { - SmartDialog.showToast(baseData?.msg ?? "",alignment: Alignment.center); + if((baseData?.msg ?? "") != "") + SmartDialog.showToast(baseData.msg,alignment: Alignment.center); refreshController.refreshFailed(); refreshController.loadFailed(); } } - @override - void initState() { - super.initState(); - - SharedPreferences.getInstance().then((value) => { - apiService = ApiService(Dio(), - showLoading: true, + minLogin(OrderInfo orderInfo) { + apiService.minLogin(orderInfo.storeId).catchError((onError) { + debugPrint(onError); + }).then((baseData) { + if (baseData != null && baseData.isSuccess) { + Map<String, dynamic> minStoreInfo = baseData.data; + String minToken = minStoreInfo["token"]; + String tenant = orderInfo.tenantCode; + String storeId = orderInfo.storeId; + SharedPreferences.getInstance().then( + (value) => { + value.setString('minToken', minToken), + value.setString('tenant', tenant), + value.setString('storeId', storeId), + }, + ); + paySelected( + orderInfo, + MinApiService( + Dio(), context: context, - token: value.getString("token")), - queryOrder(), - queryUserBalance(), - }); + token: minToken, + tenant: tenant, + storeId: storeId, + )); + } + }); + } + + queryDetails(id) async { + if (apiService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService(Dio(), + context: context, token: value.getString("token"), showLoading: true); + } + BaseData<OrderInfo> baseData = + await apiService.orderDetail(id).catchError((error) {}); + if (baseData != null && baseData.isSuccess) { + return baseData.data; + } + } + + queryUserBalance() async { + BaseData<UserInfo> baseData = + await apiService.queryInfo().catchError((onError) { + + }); + if (baseData != null && baseData.isSuccess) { + userInfo = baseData.data; + if (mounted) setState(() {}); + }else { + SmartDialog.showToast(baseData.msg, alignment: Alignment.center); + } + } + + paySelected(OrderInfo orderInfo, MinApiService minService) async { + var payChannel = await showModalBottomSheet( + context: context, + backgroundColor: Colors.transparent, + builder: (context) { + return OrderPaySelected(userInfo); + }, + ); + if (payChannel != null && payChannel > 0) { + orderInfo = await queryDetails(orderInfo.id); + OrderUtils.carryOnPay( + payChannel, + minService, + orderInfo, + (BaseData baseData) { + SmartDialog.showToast( + baseData?.msg == "ok" ? "订单支付成功" : baseData?.msg, + alignment: Alignment.center); + Future.delayed(Duration(seconds: 3), () { + _onRefresh(); + }); + }, + ); + } + } + + payResult(BaseData baseData) {} + + orderCancel(String orderId) async { + BaseData baseData = + await apiService.orderCancel(orderId).catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + SmartDialog.showToast("订单取消成功"); + _onRefresh(); + }else{ + if(baseData.msg != null) + SmartDialog.showToast(baseData.msg,alignment: Alignment.center); + } + } + + aginOrder(OrderInfo orderInfo) { + // Navigator.of(context).pushNamed( + // '/router/union_detail_page', + // arguments: {"id": storeId}, + // ); + // String storeId = (orderInfo != null && + // orderInfo.storeVO != null) + // ? (orderInfo.storeVO.id ?? "") + // : ""; + + if (orderInfo.storeVO.posType.code == "NORMALSTORE") { + Scan.toScan( + context, + orderInfo.storeVO.id, + orderInfo.tenantCode, + orderInfo.storeVO.storeName, + ); + } else { + Navigator.of(context).pushNamed( + '/router/store_order', + arguments: { + "id": orderInfo.storeVO.id, + "tenant": orderInfo.tenantCode, + "storeName": orderInfo.storeVO.storeName + }, + ); + } + } + + @override + Widget build(BuildContext context) { + super.build(context); + return SmartRefresher( + controller: refreshController, + enablePullDown: true, + enablePullUp: true, + physics: BouncingScrollPhysics(), + header: MyHeader(), + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); + }, + ), + onRefresh: _onRefresh, + onLoading: queryOrder, + child: (orderInfos != null && orderInfos.length > 0) + ? ListView.builder( + itemCount: orderInfos != null ? orderInfos.length : 0, + itemBuilder: (context, position) { + return InkWell( + onTap: () { + Navigator.of(context).pushNamed('/router/order_details', + arguments: {"id": orderInfos[position].id,"jumpState":2}); + }, + child: orderItem(orderInfos[position]), + ); + }) + : NoDataView( + src: "assets/image/ding_dan.webp", + isShowBtn: false, + text: "目前暂无订单,快去下一单吧~", + fontSize: 16.sp, + margin: EdgeInsets.only(top: 120), + ), + ); } String orderAllGoods(OrderInfo orderInfo) { @@ -536,130 +658,6 @@ class _OrderHistoryList extends State<OrderHistoryList> ); } - minLogin(OrderInfo orderInfo) { - apiService.minLogin(orderInfo.storeId).catchError((onError) { - debugPrint(onError); - }).then((baseData) { - if (baseData != null && baseData.isSuccess) { - Map<String, dynamic> minStoreInfo = baseData.data; - String minToken = minStoreInfo["token"]; - String tenant = orderInfo.tenantCode; - String storeId = orderInfo.storeId; - SharedPreferences.getInstance().then( - (value) => { - value.setString('minToken', minToken), - value.setString('tenant', tenant), - value.setString('storeId', storeId), - }, - ); - paySelected( - orderInfo, - MinApiService( - Dio(), - context: context, - token: minToken, - tenant: tenant, - storeId: storeId, - )); - } - }); - } - - queryDetails(id) async { - if (apiService == null) { - SharedPreferences value = await SharedPreferences.getInstance(); - apiService = ApiService(Dio(), - context: context, token: value.getString("token"), showLoading: true); - } - BaseData<OrderInfo> baseData = - await apiService.orderDetail(id).catchError((error) {}); - if (baseData != null && baseData.isSuccess) { - return baseData.data; - } - } - - UserInfo userInfo; - - queryUserBalance() async { - BaseData<UserInfo> baseData = - await apiService.queryInfo().catchError((onError) {}); - if (baseData != null && baseData.isSuccess) { - userInfo = baseData.data; - if (mounted) setState(() {}); - }else { - SmartDialog.showToast(baseData.msg, alignment: Alignment.center); - } - } - - paySelected(OrderInfo orderInfo, MinApiService minService) async { - var payChannel = await showModalBottomSheet( - context: context, - backgroundColor: Colors.transparent, - builder: (context) { - return OrderPaySelected(userInfo); - }, - ); - if (payChannel != null && payChannel > 0) { - orderInfo = await queryDetails(orderInfo.id); - OrderUtils.carryOnPay( - payChannel, - minService, - orderInfo, - (BaseData baseData) { - SmartDialog.showToast( - baseData?.msg == "ok" ? "订单支付成功" : baseData?.msg, - alignment: Alignment.center); - Future.delayed(Duration(seconds: 3), () { - _onRefresh(); - }); - }, - ); - } - } - - payResult(BaseData baseData) {} - - orderCancel(String orderId) async { - BaseData baseData = - await apiService.orderCancel(orderId).catchError((onError) {}); - if (baseData != null && baseData.isSuccess) { - SmartDialog.showToast("订单取消成功"); - _onRefresh(); - }else{ - if(baseData.msg != null) - SmartDialog.showToast(baseData.msg,alignment: Alignment.center); - } - } - - aginOrder(OrderInfo orderInfo) { - // Navigator.of(context).pushNamed( - // '/router/union_detail_page', - // arguments: {"id": storeId}, - // ); - // String storeId = (orderInfo != null && - // orderInfo.storeVO != null) - // ? (orderInfo.storeVO.id ?? "") - // : ""; - - if (orderInfo.storeVO.posType.code == "NORMALSTORE") { - Scan.toScan( - context, - orderInfo.storeVO.id, - orderInfo.tenantCode, - orderInfo.storeVO.storeName, - ); - } else { - Navigator.of(context).pushNamed( - '/router/store_order', - arguments: { - "id": orderInfo.storeVO.id, - "tenant": orderInfo.tenantCode, - "storeName": orderInfo.storeVO.storeName - }, - ); - } - } - String totalPrice(orderInfo) { if (orderInfo == null) return ""; double totalPrice = (double.tryParse(orderInfo.orderSum) + diff --git a/lib/retrofit/data/member_recharge_list.dart b/lib/retrofit/data/member_recharge_list.dart new file mode 100644 index 00000000..30c207d0 --- /dev/null +++ b/lib/retrofit/data/member_recharge_list.dart @@ -0,0 +1,159 @@ +/// id : "1681490552371019776" +/// rechargeMoney : "100.00" +/// giftdMoney : "10.00" +/// limitNum : 0 +/// gitfdCouponId : null +/// startDate : null +/// endDate : null +/// startTime : null +/// endTime : null +/// tenantCode : "1175" +/// createTime : "2023-07-21 09:22:53" +/// isDeleted : 0 +/// rechargeType : 0 +/// remark : "充值100.00 赠送10.00" +/// sortValue : 0 +/// useNum : 0 + +class MemberRechargeList { + MemberRechargeList({ + String id, + String rechargeMoney, + String giftdMoney, + num limitNum, + dynamic gitfdCouponId, + dynamic startDate, + dynamic endDate, + dynamic startTime, + dynamic endTime, + String tenantCode, + String createTime, + num isDeleted, + num rechargeType, + String remark, + num sortValue, + num useNum,}){ + _id = id; + _rechargeMoney = rechargeMoney; + _giftdMoney = giftdMoney; + _limitNum = limitNum; + _gitfdCouponId = gitfdCouponId; + _startDate = startDate; + _endDate = endDate; + _startTime = startTime; + _endTime = endTime; + _tenantCode = tenantCode; + _createTime = createTime; + _isDeleted = isDeleted; + _rechargeType = rechargeType; + _remark = remark; + _sortValue = sortValue; + _useNum = useNum; +} + + MemberRechargeList.fromJson(dynamic json) { + _id = json['id']; + _rechargeMoney = json['rechargeMoney']; + _giftdMoney = json['giftdMoney']; + _limitNum = json['limitNum']; + _gitfdCouponId = json['gitfdCouponId']; + _startDate = json['startDate']; + _endDate = json['endDate']; + _startTime = json['startTime']; + _endTime = json['endTime']; + _tenantCode = json['tenantCode']; + _createTime = json['createTime']; + _isDeleted = json['isDeleted']; + _rechargeType = json['rechargeType']; + _remark = json['remark']; + _sortValue = json['sortValue']; + _useNum = json['useNum']; + } + String _id; + String _rechargeMoney; + String _giftdMoney; + num _limitNum; + dynamic _gitfdCouponId; + dynamic _startDate; + dynamic _endDate; + dynamic _startTime; + dynamic _endTime; + String _tenantCode; + String _createTime; + num _isDeleted; + num _rechargeType; + String _remark; + num _sortValue; + num _useNum; +MemberRechargeList copyWith({ String id, + String rechargeMoney, + String giftdMoney, + num limitNum, + dynamic gitfdCouponId, + dynamic startDate, + dynamic endDate, + dynamic startTime, + dynamic endTime, + String tenantCode, + String createTime, + num isDeleted, + num rechargeType, + String remark, + num sortValue, + num useNum, +}) => MemberRechargeList( id: id ?? _id, + rechargeMoney: rechargeMoney ?? _rechargeMoney, + giftdMoney: giftdMoney ?? _giftdMoney, + limitNum: limitNum ?? _limitNum, + gitfdCouponId: gitfdCouponId ?? _gitfdCouponId, + startDate: startDate ?? _startDate, + endDate: endDate ?? _endDate, + startTime: startTime ?? _startTime, + endTime: endTime ?? _endTime, + tenantCode: tenantCode ?? _tenantCode, + createTime: createTime ?? _createTime, + isDeleted: isDeleted ?? _isDeleted, + rechargeType: rechargeType ?? _rechargeType, + remark: remark ?? _remark, + sortValue: sortValue ?? _sortValue, + useNum: useNum ?? _useNum, +); + String get id => _id; + String get rechargeMoney => _rechargeMoney; + String get giftdMoney => _giftdMoney; + num get limitNum => _limitNum; + dynamic get gitfdCouponId => _gitfdCouponId; + dynamic get startDate => _startDate; + dynamic get endDate => _endDate; + dynamic get startTime => _startTime; + dynamic get endTime => _endTime; + String get tenantCode => _tenantCode; + String get createTime => _createTime; + num get isDeleted => _isDeleted; + num get rechargeType => _rechargeType; + String get remark => _remark; + num get sortValue => _sortValue; + num get useNum => _useNum; + + Map<String, dynamic> toJson() { + final map = <String, dynamic>{}; + map['id'] = _id; + map['rechargeMoney'] = _rechargeMoney; + map['giftdMoney'] = _giftdMoney; + map['limitNum'] = _limitNum; + map['gitfdCouponId'] = _gitfdCouponId; + map['startDate'] = _startDate; + map['endDate'] = _endDate; + map['startTime'] = _startTime; + map['endTime'] = _endTime; + map['tenantCode'] = _tenantCode; + map['createTime'] = _createTime; + map['isDeleted'] = _isDeleted; + map['rechargeType'] = _rechargeType; + map['remark'] = _remark; + map['sortValue'] = _sortValue; + map['useNum'] = _useNum; + return map; + } + +} \ No newline at end of file diff --git a/lib/retrofit/min_api.dart b/lib/retrofit/min_api.dart index 6415e490..c8cf737b 100644 --- a/lib/retrofit/min_api.dart +++ b/lib/retrofit/min_api.dart @@ -19,6 +19,7 @@ import 'data/activity_order_list.dart'; import 'data/findMiNiGroupList.dart'; import 'data/home_recommend_list.dart'; import 'data/launch_join_act.dart'; +import 'data/member_recharge_list.dart'; import 'data/miNiDetail.dart'; import 'data/settleOrderInfo.dart'; import 'data/shoppingCart.dart'; @@ -243,4 +244,13 @@ abstract class MinApiService { @POST("promotion/useMemberCoupon") Future<BaseData> useMemberCoupon(@Body() Map<String, dynamic> param); + ///商户充值 + @POST("/member/recharge") + Future<BaseData<dynamic>> memberRecharge(@Body() Map<String, dynamic> param); + + ///充值列表 + @GET("/store/getRechargePreferential") + Future<BaseData<List<MemberRechargeList>>> memberRechargeList(); + + } diff --git a/lib/retrofit/min_api.g.dart b/lib/retrofit/min_api.g.dart index a1aac3c6..215825a0 100644 --- a/lib/retrofit/min_api.g.dart +++ b/lib/retrofit/min_api.g.dart @@ -651,4 +651,49 @@ class _MinApiService implements MinApiService { ); return value; } + + @override + Future<BaseData<dynamic>> memberRecharge(param) async { + ArgumentError.checkNotNull(param, 'param'); + const _extra = <String, dynamic>{}; + final queryParameters = <String, dynamic>{}; + final _data = <String, dynamic>{}; + _data.addAll(param ?? <String, dynamic>{}); + final _result = await _dio.request<Map<String, dynamic>>('//member/recharge', + queryParameters: queryParameters, + options: RequestOptions( + method: 'POST', + headers: <String, dynamic>{}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData<dynamic>.fromJson( + _result.data, + (json) => json as dynamic, + ); + return value; + } + + @override + Future<BaseData<List<MemberRechargeList>>> memberRechargeList() async { + const _extra = <String, dynamic>{}; + final queryParameters = <String, dynamic>{}; + final _data = <String, dynamic>{}; + final _result = await _dio.request<Map<String, dynamic>>( + '/store/getRechargePreferential', + queryParameters: queryParameters, + options: RequestOptions( + method: 'GET', + headers: <String, dynamic>{}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData<List<MemberRechargeList>>.fromJson( + _result.data, + (json) => (json as List<dynamic>) + .map<MemberRechargeList>( + (i) => MemberRechargeList.fromJson(i as Map<String, dynamic>)) + .toList()); + return value; + } } diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index 4a602f8e..53dc79e9 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -6,7 +6,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; -import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/article.dart'; @@ -14,12 +13,10 @@ import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/comunity_comment.dart'; import 'package:huixiang/retrofit/data/coupon.dart'; import 'package:huixiang/retrofit/data/farmers_list.dart'; -import 'package:huixiang/retrofit/data/login_info.dart'; import 'package:huixiang/retrofit/data/order_info.dart'; import 'package:huixiang/view_widget/login_tips_dialog.dart'; import 'package:retrofit/retrofit.dart'; -import '../utils/flutter_utils.dart'; import 'data/achievement_detail_list.dart'; import 'data/activity_pos.dart'; import 'data/address.dart'; @@ -50,7 +47,6 @@ import 'data/msg_stats.dart'; import 'data/page.dart'; import 'data/rank.dart'; import 'data/rechargeActLists.dart'; -import 'data/recharge_list.dart'; import 'data/second_card_list.dart'; import 'data/sign_info.dart'; import 'data/social_info.dart'; @@ -89,6 +85,8 @@ abstract class ApiService { if (pay) { headers["Environment"] = "app"; } + if (kReleaseMode) + baseUrl = serviceBaseUrl; if (isIp) baseUrl = ipBaseUrl; dio.options = BaseOptions( connectTimeout: 60000, @@ -150,10 +148,6 @@ abstract class ApiService { debugPrint("\n"); }), ); - - if (kReleaseMode) { - baseUrl = serviceBaseUrl; - } return _ApiService(dio, baseUrl: baseUrl); } @@ -230,8 +224,8 @@ abstract class ApiService { Future<BaseData<dynamic>> recharge(@Body() Map<String, dynamic> param); ///充值活动列表 - @GET("/wallet/rechargeActList") - Future<BaseData<RechargeActLists>> rechargeActList(); + @GET("/wallet/rechargeActList?tenantCode={tenantCode}") + Future<BaseData<RechargeActLists>> rechargeActList(@Path("tenantCode") String tenantCode); ///领取优惠券 @GET("/coupon/receive?couponId={couponId}") diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index 4e59be99..86f7f0ee 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -322,12 +322,12 @@ class _ApiService implements ApiService { } @override - Future<BaseData<RechargeActLists>> rechargeActList() async { + Future<BaseData<RechargeActLists>> rechargeActList(tenantCode) async { const _extra = <String, dynamic>{}; final queryParameters = <String, dynamic>{}; final _data = <String, dynamic>{}; final _result = await _dio.request<Map<String, dynamic>>( - '/wallet/rechargeActList', + '/wallet/rechargeActList?tenantCode=$tenantCode', queryParameters: queryParameters, options: RequestOptions( method: 'GET', diff --git a/lib/store/store_view/shop_goods.dart b/lib/store/store_view/shop_goods.dart index 3baaa943..3c0fede4 100644 --- a/lib/store/store_view/shop_goods.dart +++ b/lib/store/store_view/shop_goods.dart @@ -359,7 +359,7 @@ class _ShopGoods extends State<ShopGoods> { // SmartDialog.showToast("库存不足", // alignment: Alignment.center); // } else - if (_jumpType == -1) + if (_jumpType == -1) queryMiNiDetail(widget.productListBean.id); else if (_jumpType == 0) widget.add(widget.shoppingCartSkuItemListBean); @@ -497,6 +497,7 @@ class _ShopGoods extends State<ShopGoods> { SizedBox( height: 4.h, ), + ///VIP价格(暂时弃用) // if (widget.productListBean.vipPrice != null) // Row( @@ -645,9 +646,12 @@ class _ShopGoods extends State<ShopGoods> { // 新版桌子码跳转 // http://miniscan.lotus-wallet.com/placeorder?tenant_code=1194&table_id=1669609340031467520&store_id=1637659387134738432 Uri uri = Uri.parse(result); - String tableId = uri.queryParameters["tableId"] ?? uri.queryParameters["table_id"]; - String tenantCode = uri.queryParameters["tenantCode"] ?? uri.queryParameters["tenant_code"]; - String shopId = uri.queryParameters["shopId"] ?? uri.queryParameters["store_id"]; + String tableId = + uri.queryParameters["tableId"] ?? uri.queryParameters["table_id"]; + String tenantCode = uri.queryParameters["tenantCode"] ?? + uri.queryParameters["tenant_code"]; + String shopId = + uri.queryParameters["shopId"] ?? uri.queryParameters["store_id"]; if (tableId != null && tableId != "" && tenantCode != null && diff --git a/lib/union/union_list.dart b/lib/union/union_list.dart index 439610b0..cc753553 100644 --- a/lib/union/union_list.dart +++ b/lib/union/union_list.dart @@ -75,11 +75,14 @@ class _UnionList extends State<UnionList> with AutomaticKeepAliveClientMixin { }).catchError((error) { SmartDialog.showToast(AppUtils.dioErrorTypeToString(error.type), alignment: Alignment.center); + _refreshController.refreshFailed(); }); if (baseData != null && baseData.isSuccess) { storeList = baseData.data; + _refreshController.refreshCompleted(); + } else { + _refreshController.refreshFailed(); } - _refreshController.refreshCompleted(); EasyLoading.dismiss(); setState(() {}); } @@ -299,25 +302,28 @@ class _UnionList extends State<UnionList> with AutomaticKeepAliveClientMixin { children: []..addAll( itemServer(store != null ? store.businessService : "")), ), - SizedBox(height: store.businessService == ""?40.h:23.h), - if(storeList[position].productShow != null) - Container( - height: 100.h, - child: ListView.builder( - padding: EdgeInsets.zero, - itemCount: (storeList[position].productShow?.length ??0) > 3 ?3:storeList[position].productShow?.length ?? 0, - scrollDirection: Axis.horizontal, - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - return GestureDetector( - onTap: () {}, - child: unionGoodsItem( - storeList[position].productShow[index]), - ); - }, + SizedBox(height: store.businessService == "" ? 40.h : 23.h), + if (storeList[position].productShow != null) + Container( + height: 100.h, + child: ListView.builder( + padding: EdgeInsets.zero, + itemCount: + (storeList[position].productShow?.length ?? 0) > 3 + ? 3 + : storeList[position].productShow?.length ?? 0, + scrollDirection: Axis.horizontal, + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return GestureDetector( + onTap: () {}, + child: unionGoodsItem( + storeList[position].productShow[index]), + ); + }, + ), ), - ), ], )) ], @@ -352,7 +358,6 @@ class _UnionList extends State<UnionList> with AutomaticKeepAliveClientMixin { .toList(); } - /// Widget unionGoodsItem(ProductShow productShow) { return Container( width: 74.w, @@ -369,16 +374,18 @@ class _UnionList extends State<UnionList> with AutomaticKeepAliveClientMixin { errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), - Padding(padding:EdgeInsets.only(top: 8.h), - child: Text( - productShow?.productName ?? "", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Color(0xFFA29E9E), - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, + Padding( + padding: EdgeInsets.only(top: 8.h), + child: Text( + productShow?.productName ?? "", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + ), ), - ),), + ), ], ), ); diff --git a/lib/view_widget/my_appbar.dart b/lib/view_widget/my_appbar.dart index 7a3ce7c5..52760e27 100644 --- a/lib/view_widget/my_appbar.dart +++ b/lib/view_widget/my_appbar.dart @@ -70,8 +70,7 @@ class MyAppBar extends StatelessWidget implements PreferredSizeWidget { }, child: Container( alignment: Alignment.centerRight, - margin: EdgeInsets.only(left: 12,), - padding: EdgeInsets.all(6), + padding: EdgeInsets.only(top: 6.h,bottom: 6.h,left:20.w,right:6.w), child: Icon( Icons.arrow_back_ios, color: leadingColor, diff --git a/lib/view_widget/recharge_details_dialog.dart b/lib/view_widget/recharge_details_dialog.dart index 5d180df4..aa93077e 100644 --- a/lib/view_widget/recharge_details_dialog.dart +++ b/lib/view_widget/recharge_details_dialog.dart @@ -1,15 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; -import 'package:huixiang/generated/l10n.dart'; -import 'package:huixiang/retrofit/data/coupon.dart'; -import 'package:huixiang/retrofit/data/recharge_list.dart'; -import 'package:huixiang/retrofit/data/store.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:huixiang/store/scan.dart'; import 'package:huixiang/utils/font_weight.dart'; -import 'package:huixiang/view_widget/border_text.dart'; -import 'package:huixiang/view_widget/custom_image.dart'; -import 'package:huixiang/view_widget/round_button.dart'; import '../retrofit/data/rechargeActLists.dart';