From be9c1e8ce25259016fcbc0955d6dc9413907d46f Mon Sep 17 00:00:00 2001 From: w-R <953969641@qq.com> Date: Wed, 23 Mar 2022 16:13:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E5=80=BC=E6=9B=B4=E6=94=B9;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/message/system_details.dart | 6 +- lib/mine/mine_view/wallet_coupon_view.dart | 54 +------ lib/mine/recharge_page.dart | 159 +++++++++++++-------- lib/retrofit/data/recharge_list.dart | 78 ++++++++++ lib/retrofit/retrofit_api.dart | 9 +- lib/retrofit/retrofit_api.g.dart | 23 ++- lib/utils/flutter_utils.dart | 14 ++ 7 files changed, 223 insertions(+), 120 deletions(-) create mode 100644 lib/retrofit/data/recharge_list.dart diff --git a/lib/message/system_details.dart b/lib/message/system_details.dart index c6c2a634..0a14b538 100644 --- a/lib/message/system_details.dart +++ b/lib/message/system_details.dart @@ -365,10 +365,10 @@ class _SystemDetails extends State { children: [ Image.asset( (message.typed == 1) - ? "assets/image/icon_system_message.png" + ? "assets/image/icon_system_message.webp" : (message.typed == 2) - ? "assets/image/icon_system_message.png" - : "assets/image/c_z.png", + ? "assets/image/icon_system_message.webp" + : "assets/image/c_z.webp", width: 24.w, height: 24.h, ), diff --git a/lib/mine/mine_view/wallet_coupon_view.dart b/lib/mine/mine_view/wallet_coupon_view.dart index 5a76028e..70763885 100644 --- a/lib/mine/mine_view/wallet_coupon_view.dart +++ b/lib/mine/mine_view/wallet_coupon_view.dart @@ -31,59 +31,7 @@ class _WalletCoupon extends State { ), ], ), - child: (Theme.of(context).platform == TargetPlatform.android) - ? GestureDetector( - onTap: () { - SharedPreferences.getInstance().then((value) { - if (value.getString("token") == null || - value.getString("token") == "") { - LoginTipsDialog().show(context); - return; - } - Navigator.of(context).pushNamed('/router/roll_center_page'); - }); - }, - child: Row( - children: [ - Image.asset( - "assets/image/icon_mine_invoice_assistant.webp", - width: 48.h, - height: 48.h, - ), - SizedBox( - width: 12.w, - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - S.of(context).lingquanzhongxin, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontWeight: MyFontWeight.medium, - fontSize: 16.sp, - color: Color(0xFF353535), - ), - ), - SizedBox( - height: 3, - ), - Text( - "联盟下单享不停、海量优惠券等你来领!", - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontWeight: MyFontWeight.medium, - fontSize: 12.sp, - color: Color(0xFF7B7B7B), - ), - ), - ], - ), - ) - ], - )) - : Row( + child: Row( children: [ Expanded( flex: 1, diff --git a/lib/mine/recharge_page.dart b/lib/mine/recharge_page.dart index 166f7edf..1aa782a8 100644 --- a/lib/mine/recharge_page.dart +++ b/lib/mine/recharge_page.dart @@ -9,10 +9,13 @@ 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/recharge_list.dart'; +import 'package:huixiang/retrofit/data/user_info.dart'; import 'package:huixiang/retrofit/data/vip_benefit_list.dart'; import 'package:huixiang/retrofit/data/vip_rule_details.dart'; import 'package:huixiang/retrofit/data/wx_pay.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; +import 'package:huixiang/utils/flutter_utils.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/min.dart'; import 'package:huixiang/view_widget/item_input_widget.dart'; @@ -35,6 +38,10 @@ class _RechargePage extends State { List vipBenefitList = []; Color color = Colors.black; double discount = 100; + List rechargeA; + int selectIndex = 0; + UserInfo userInfo; + dynamic mBalance; @override void initState() { @@ -45,11 +52,13 @@ class _RechargePage extends State { context: context, token: value.getString("token"), pay: true); queryBenefitList(); queryRuleDetails(); + queryRechargeList(); + queryUserBalance(); }); weChatResponseEventHandler.listen((event) async { print("payCallback: ${event.errCode}"); if (event.errCode == 0) { - Navigator.of(context).pop(); + queryUserBalance(); SmartDialog.showToast("充值成功", alignment: Alignment.center); } // else{ @@ -79,6 +88,16 @@ class _RechargePage extends State { EasyLoading.dismiss(); } + queryUserBalance() async { + BaseData baseData = + await apiService.queryInfo().catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + userInfo = baseData.data; + mBalance = double.tryParse(userInfo?.money ?? "0"); + if (mounted) setState(() {}); + } + } + ///会员权益介绍/规则/说明/储值说明 queryRuleDetails() async { BaseData baseData = @@ -91,6 +110,25 @@ class _RechargePage extends State { EasyLoading.dismiss(); } + ///充值列表 + queryRechargeList() async { + if (apiService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService( + Dio(), + context: context, + token: value.getString("token"), + ); + } + BaseData> baseData = await apiService.rechargeAct().catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + setState(() { + rechargeA = baseData.data; + }); + } + EasyLoading.dismiss(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -168,7 +206,7 @@ class _RechargePage extends State { Text.rich( TextSpan(children: [ TextSpan( - text: "0.00", + text: "$mBalance", style: TextStyle( fontSize: 26.sp, color: Color(0xFF181818), @@ -199,12 +237,6 @@ class _RechargePage extends State { color: Colors.white, child: Html( data: "注意:${vipRuleDetails?.recharge ?? ""}", - style:{ - "html":Style( - color: Color(0xFF000000), - fontWeight: MyFontWeight.medium, - ) - }, customImageRenders: { networkSourceMatcher(): networkImageRender( loadingWidget: () { @@ -418,7 +450,7 @@ class _RechargePage extends State { Widget rechargeList() { return GridView.builder( - itemCount: 6, + itemCount: rechargeA == null ? 0 : rechargeA.length, shrinkWrap: true, physics: BouncingScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( @@ -432,59 +464,64 @@ class _RechargePage extends State { ), itemBuilder: (context, index) { return GestureDetector( - onTap: () {}, - child: rechargeItem(), + onTap: () { + setState(() { + selectIndex = index; + }); + }, + child: rechargeItem(rechargeA[index],index), ); }, ); } - Widget rechargeItem() { - return Stack( + Widget rechargeItem(RechargeList rechargeA,index) { + return Container( + child: Stack( alignment: Alignment.bottomRight, children: [ Container( - alignment: Alignment.center, - height: 69.h, - decoration: BoxDecoration( - color: Color(0xFFFAFAFA), - // color: Color(0x2432A060), - borderRadius: BorderRadius.circular(4), - ), - // margin: EdgeInsets.only(right: 11,bottom: 16), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - "100元", - textAlign: TextAlign.center, - style: TextStyle( - color: Color(0xFF868686), - fontWeight: MyFontWeight.medium, - fontSize: 21.sp, + alignment: Alignment.center, + height: 69.h, + decoration: BoxDecoration( + color: selectIndex == index ?Color(0x2432A060) : Color(0xFFFAFAFA), + borderRadius: BorderRadius.circular(4), + ), + // margin: EdgeInsets.only(right: 11,bottom: 16), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "${AppUtils.calculateDouble(double.tryParse(rechargeA.rechargeMoney)??0)}元", + textAlign: TextAlign.center, + style: TextStyle( + color: Color(0xFF868686), + fontWeight: MyFontWeight.medium, + fontSize:18.sp, + ), ), - ), - SizedBox(height:2,), - Text( - "实际到账:120元", - textAlign: TextAlign.center, - style: TextStyle( - color: Color(0xFF868686), - fontWeight: MyFontWeight.regular, - fontSize:12.sp, + SizedBox(height:2,), + Text( + "实际到账:${AppUtils.calculateDouble((double.tryParse(rechargeA.rechargeMoney)??0) + (double.tryParse(rechargeA.giftdMoney)??0) +((double.tryParse(rechargeA.rechargeMoney)??0) - ((double.tryParse(rechargeA.rechargeMoney)??0) * (discount/100))))}元", + textAlign: TextAlign.center, + style: TextStyle( + color: Color(0xFF868686), + fontWeight: MyFontWeight.regular, + fontSize:10.sp, + ), ), - ), - ], + ], + ), ), - ), + if(selectIndex == index) Image.asset( - "assets/image/recharge.png", + "assets/image/recharge.png", width: 20, height:20, ), ], - ); + )); } Widget checkView(var index) { @@ -502,19 +539,19 @@ class _RechargePage extends State { } recharge() async { - String money = controller.text; - if (money == null || money == "") { - SmartDialog.showToast(S.of(context).qingshuruchongzhijine, - alignment: Alignment.center); - return; - } - int amount = int.tryParse(money); - if (checkIndex == 1) { - if (amount < 100) { - SmartDialog.showToast(S.of(context).chongzhizuixiaojine(100), - alignment: Alignment.center); - return; - } + // String money = controller.text; + // if (money == null || money == "") { + // SmartDialog.showToast(S.of(context).qingshuruchongzhijine, + // alignment: Alignment.center); + // return; + // } + // int amount = int.tryParse(money); + // if (checkIndex == 1) { + // if (amount < 100) { + // SmartDialog.showToast(S.of(context).chongzhizuixiaojine(100), + // alignment: Alignment.center); + // return; + // } if (Platform.isAndroid) { if (!(await Min.isInitialize())) { @@ -526,7 +563,7 @@ class _RechargePage extends State { } BaseData baseData = await apiService.recharge( - {"amount": amount, "rechargeType": 2}).catchError((error) {}); + {"amount": 0,"rechargeActId":rechargeA[selectIndex].id, "rechargeType": 2}).catchError((error) {}); if (baseData != null && baseData.isSuccess) { WxPay wxPay = WxPay.fromJson(baseData.data); await registerWxApi( @@ -547,5 +584,5 @@ class _RechargePage extends State { SmartDialog.showToast(baseData.msg, alignment: Alignment.center); } } - } + // } } diff --git a/lib/retrofit/data/recharge_list.dart b/lib/retrofit/data/recharge_list.dart new file mode 100644 index 00000000..4e6c5d71 --- /dev/null +++ b/lib/retrofit/data/recharge_list.dart @@ -0,0 +1,78 @@ +/// id : "1494622230208839681" +/// rechargeMoney : "100.00" +/// giftdMoney : "0.00" +/// gitfdCouponId : null +/// tenantCode : "admin" +/// createTime : "2022-03-23 10:53:37" +/// isDeleted : 0 +/// rechargeType : 0 +/// remark : "充充充" + +class RechargeList { + RechargeList({ + String id, + String rechargeMoney, + String giftdMoney, + dynamic gitfdCouponId, + String tenantCode, + String createTime, + int isDeleted, + int rechargeType, + String remark,}){ + _id = id; + _rechargeMoney = rechargeMoney; + _giftdMoney = giftdMoney; + _gitfdCouponId = gitfdCouponId; + _tenantCode = tenantCode; + _createTime = createTime; + _isDeleted = isDeleted; + _rechargeType = rechargeType; + _remark = remark; +} + + RechargeList.fromJson(dynamic json) { + _id = json['id']; + _rechargeMoney = json['rechargeMoney']; + _giftdMoney = json['giftdMoney']; + _gitfdCouponId = json['gitfdCouponId']; + _tenantCode = json['tenantCode']; + _createTime = json['createTime']; + _isDeleted = json['isDeleted']; + _rechargeType = json['rechargeType']; + _remark = json['remark']; + } + String _id; + String _rechargeMoney; + String _giftdMoney; + dynamic _gitfdCouponId; + String _tenantCode; + String _createTime; + int _isDeleted; + int _rechargeType; + String _remark; + + String get id => _id; + String get rechargeMoney => _rechargeMoney; + String get giftdMoney => _giftdMoney; + dynamic get gitfdCouponId => _gitfdCouponId; + String get tenantCode => _tenantCode; + String get createTime => _createTime; + int get isDeleted => _isDeleted; + int get rechargeType => _rechargeType; + String get remark => _remark; + + Map toJson() { + final map = {}; + map['id'] = _id; + map['rechargeMoney'] = _rechargeMoney; + map['giftdMoney'] = _giftdMoney; + map['gitfdCouponId'] = _gitfdCouponId; + map['tenantCode'] = _tenantCode; + map['createTime'] = _createTime; + map['isDeleted'] = _isDeleted; + map['rechargeType'] = _rechargeType; + map['remark'] = _remark; + return map; + } + +} \ No newline at end of file diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index 130c0cc8..3fe839b8 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -43,6 +43,7 @@ import 'data/message.dart'; import 'data/msg_stats.dart'; import 'data/page.dart'; import 'data/rank.dart'; +import 'data/recharge_list.dart'; import 'data/second_card_list.dart'; import 'data/sign_info.dart'; import 'data/social_info.dart'; @@ -63,8 +64,8 @@ part 'retrofit_api.g.dart'; // const base_url = "http://platform.prod.kunqi.lotus-wallet.com/app/"; ///222 // const baseUrl = "http://platform.prod.kunqi.lotus-wallet.com/app/"; ///222 -const base_url = "http://192.168.10.236:8766/app/"; ///费韬 -const baseUrl = "http://192.168.10.236:8766/app/"; ///费韬 +const base_url = "http://192.168.10.236:8776/app/"; ///费韬 +const baseUrl = "http://192.168.10.236:8776/app/"; ///费韬 // const base_url = "http://192.168.10.37:8766/app/"; // const baseUrl = "http://192.168.10.37:8766/app/"; @@ -218,6 +219,10 @@ abstract class ApiService { @POST("/wallet/recharge") Future> recharge(@Body() Map param); + ///充值活动列表 + @GET("/wallet/rechargeAct") + Future>> rechargeAct(); + ///领取优惠券 @GET("/coupon/receive?couponId={couponId}") Future receiveCoupon(@Path("couponId") String couponId); diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index 71baf8d6..33d0301a 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -9,7 +9,7 @@ part of 'retrofit_api.dart'; class _ApiService implements ApiService { _ApiService(this._dio, {this.baseUrl}) { ArgumentError.checkNotNull(_dio, '_dio'); - baseUrl ??= 'http://192.168.10.236:8766/app/'; + baseUrl ??= 'http://192.168.10.236:8776/app/'; } final Dio _dio; @@ -298,6 +298,27 @@ class _ApiService implements ApiService { return value; } + @override + Future>> rechargeAct() async { + const _extra = {}; + final queryParameters = {}; + final _data = {}; + final _result = await _dio.request>('/wallet/rechargeAct', + queryParameters: queryParameters, + options: RequestOptions( + method: 'GET', + headers: {}, + extra: _extra, + baseUrl: baseUrl), + data: _data); + final value = BaseData>.fromJson( + _result.data, + (json) => (json as List) + .map((i) => RechargeList.fromJson(i as Map)) + .toList()); + return value; + } + @override Future> receiveCoupon(couponId) async { ArgumentError.checkNotNull(couponId, 'couponId'); diff --git a/lib/utils/flutter_utils.dart b/lib/utils/flutter_utils.dart index d9b016bc..7e08db55 100644 --- a/lib/utils/flutter_utils.dart +++ b/lib/utils/flutter_utils.dart @@ -15,6 +15,20 @@ class AppUtils { return "${numberFormat.format(mi / 1000)}"; } + static String trimEnd(String resString,String char){ + while(resString.endsWith(char)){ + resString = resString.substring(0,resString.length - 1); + } + return resString; + } + + ///金额保留整数/后两位 + static String calculateDouble(double res){ + String resString = res.toStringAsFixed(2); + resString = trimEnd(resString, "0"); + resString = trimEnd(resString, "."); + return resString; + } static Future coordConvert(BMFCoordinate latLng) async { return BMFCalculateUtils.coordConvert(