You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
954 lines
38 KiB
954 lines
38 KiB
import 'dart:io'; |
|
|
|
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:fluwx/fluwx.dart'; |
|
import 'package:huixiang/data/preferential.dart'; |
|
import 'package:huixiang/data/recharge_act.dart'; |
|
import 'package:huixiang/data/vip_benefit.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/data/base_data.dart'; |
|
import 'package:huixiang/data/user_info.dart'; |
|
import 'package:huixiang/data/vip_rule_details.dart'; |
|
import 'package:huixiang/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: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'; |
|
|
|
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() { |
|
return _RechargePage(); |
|
} |
|
} |
|
|
|
class _RechargePage extends State<RechargePage> { |
|
ApiService? apiService; |
|
TextEditingController controller = TextEditingController(); |
|
VipRuleDetails? vipRuleDetails; |
|
List<VipBenefit> vipBenefitList = []; |
|
Color color = Colors.black; |
|
double discount = 100; |
|
int selectIndex = 0; |
|
UserInfo? userInfo; |
|
String mBalance = "0"; |
|
|
|
RechargeAct? rechargeActLists; |
|
int selectStoreIndex = 0; |
|
String? recommendName; |
|
final RefreshController refreshController = RefreshController(); |
|
int _loadCount = 0; |
|
|
|
Fluwx fluwx = Fluwx(); |
|
Tobias tobias = Tobias(); |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
SharedPreferences.getInstance().then((value) => { |
|
apiService = ApiService(Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
showLoading: false), |
|
_onRefresh() |
|
}); |
|
fluwx.addSubscriber((event) async { |
|
print("payCallback: ${event.errCode}"); |
|
if (event.errCode == 0) { |
|
queryUserBalance(); |
|
Navigator.of(context).pop(); |
|
SmartDialog.showToast("充值成功", alignment: Alignment.center); |
|
} else { |
|
SmartDialog.showToast("充值失败", alignment: Alignment.center); |
|
return; |
|
} |
|
}); |
|
} |
|
|
|
|
|
///会员权益列表 |
|
queryBenefitList() async { |
|
try { |
|
BaseData<List<VipBenefit>>? baseData = await apiService?.benefitList().catchError((onError) {}); |
|
if (baseData?.isSuccess ?? false) { |
|
vipBenefitList.clear(); |
|
vipBenefitList.addAll(baseData!.data!); |
|
vipBenefitList.forEach((element) { |
|
if ((element.have ?? false) && element.code == "RECHARGE") { |
|
discount = double.parse("${element.config}"); |
|
} |
|
}); |
|
} |
|
} finally { |
|
addLoadCount(); |
|
} |
|
} |
|
|
|
queryUserBalance() async { |
|
try { |
|
BaseData<UserInfo>? baseData = await apiService?.queryInfo().catchError((onError) { |
|
SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type), |
|
alignment: Alignment.center); |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
}); |
|
if (baseData?.isSuccess ?? false) { |
|
userInfo = baseData?.data; |
|
mBalance = userInfo?.money ?? "0"; |
|
} |
|
} finally { |
|
addLoadCount(); |
|
} |
|
} |
|
|
|
///会员权益介绍/规则/说明/储值说明 |
|
queryRuleDetails() async { |
|
try { |
|
BaseData<VipRuleDetails>? baseData = await apiService?.vipBenefit().catchError((onError) {}); |
|
if (baseData?.isSuccess ?? false) { |
|
vipRuleDetails = baseData!.data; |
|
} |
|
} finally { |
|
addLoadCount(); |
|
} |
|
} |
|
|
|
///充值列表 |
|
queryRechargeActList() async { |
|
try { |
|
BaseData<RechargeAct>? baseData = await apiService?.rechargeActList("admin").catchError((onError) {}); |
|
if (baseData?.isSuccess ?? false) { |
|
rechargeActLists = baseData!.data; |
|
} |
|
} finally { |
|
addLoadCount(); |
|
} |
|
} |
|
|
|
_onRefresh() async { |
|
EasyLoading.show(status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); |
|
// SharedPreferences value = await SharedPreferences.getInstance(); |
|
queryBenefitList(); |
|
queryRuleDetails(); |
|
queryRechargeActList(); |
|
queryUserBalance(); |
|
} |
|
|
|
addLoadCount() { |
|
_loadCount += 1; |
|
if (_loadCount == 4) { |
|
_loadCount = 0; |
|
EasyLoading.dismiss(); |
|
if (refreshController.isRefresh) refreshController.refreshCompleted(); |
|
if (mounted) setState(() {}); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: MyAppBar( |
|
title: S.of(context).chongzhi, |
|
titleColor: Colors.black, |
|
titleSize: 18.sp, |
|
background: Color(0xFFFFFFFF), |
|
leadingColor: Colors.black, |
|
), |
|
body: Container( |
|
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: [ |
|
// 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), |
|
)), |
|
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?.preferentialList?.isNotEmpty ?? false) |
|
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, |
|
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), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
), |
|
if (rechargeActLists?.isOpen ?? false) |
|
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, |
|
), |
|
SizedBox(width: 8.w), |
|
Expanded( |
|
child: Text( |
|
recommendName ?? "为喜爱门店打call!(可选)", |
|
style: TextStyle( |
|
fontWeight: MyFontWeight.regular, |
|
fontSize: 12.sp, |
|
color: (recommendName != null) |
|
? Color(0xFF32A060) |
|
: Color(0xFF868686), |
|
), |
|
)), |
|
Icon( |
|
Icons.arrow_forward_ios, |
|
size: 16, |
|
), |
|
], |
|
)), |
|
), |
|
if (rechargeActLists?.preferentialList?.isNotEmpty ?? false) |
|
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), |
|
// ), |
|
// ), |
|
// ], |
|
// ), |
|
// ) |
|
) |
|
], |
|
), |
|
), |
|
), |
|
)), |
|
); |
|
} |
|
|
|
var checkIndex = 2; |
|
|
|
Widget rechargeList() { |
|
return (rechargeActLists?.preferentialList?.isNotEmpty ?? false) |
|
? ListView.builder( |
|
padding: EdgeInsets.zero, |
|
itemCount: 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), |
|
); |
|
}, |
|
) |
|
: 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 preferential, index) { |
|
return Container( |
|
width: double.infinity, |
|
height: 69.h, |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(4), |
|
border: Border.all( |
|
color: selectIndex == index ? Color(0xFF32A060) : Color(0xFFFAFAFA), |
|
width: selectIndex == index ? 1 : 0, |
|
), |
|
color: selectIndex == index ? Color(0XFFF0FAF4) : Color(0xFFFAFAFA), |
|
), |
|
margin: EdgeInsets.only(bottom: 14.w), |
|
padding: EdgeInsets.only(left: 16), |
|
child: Flex( |
|
direction: Axis.horizontal, |
|
children: [ |
|
Expanded( |
|
flex: 1, |
|
child: Container( |
|
child: Text.rich( |
|
TextSpan(children: [ |
|
TextSpan( |
|
text: "储值 ", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: selectIndex == index |
|
? Color(0xFF4D4D4D) |
|
: Color(0xFF868686), |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
TextSpan( |
|
text: |
|
"${AppUtils.calculateDouble(double.tryParse("${preferential.rechargeMoney}") ?? 0)}元", |
|
style: TextStyle( |
|
fontSize: 18.sp, |
|
fontFamily: 'JDZhengHT', |
|
color: selectIndex == index |
|
? Color(0xFF353535) |
|
: Color(0xFF868686), |
|
fontWeight: MyFontWeight.semi_bold, |
|
), |
|
), |
|
]), |
|
), |
|
)), |
|
Container( |
|
width: 1.w, |
|
height: 37.h, |
|
color: |
|
selectIndex == index ? Color(0xFF32A060) : Color(0xFF979797), |
|
margin: EdgeInsets.only(right: 16.w, left: 12), |
|
), |
|
Expanded( |
|
flex: 2, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text.rich( |
|
TextSpan(children: [ |
|
TextSpan( |
|
text: "实际到账 ", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: selectIndex == index |
|
? Color(0xFF353535) |
|
: Color(0xFF868686), |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
TextSpan( |
|
text: |
|
"${AppUtils.calculateDouble((double.tryParse("${preferential.rechargeMoney}") ?? 0) + (double.tryParse("${preferential.giftdMoney}") ?? 0) + ((double.tryParse("${preferential.rechargeMoney}") ?? 0) - ((double.tryParse("${preferential.rechargeMoney}") ?? 0) * (discount / 100))))}元", |
|
style: TextStyle( |
|
fontSize: 18.sp, |
|
fontFamily: 'JDZhengHT', |
|
color: selectIndex == index |
|
? Color(0xFF353535) |
|
: Color(0xFF868686), |
|
fontWeight: MyFontWeight.semi_bold, |
|
), |
|
), |
|
]), |
|
), |
|
SizedBox( |
|
height: 4.h, |
|
), |
|
GestureDetector( |
|
onTap: () { |
|
setState(() { |
|
if (selectIndex == index) showRecharge(index); |
|
}); |
|
}, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
"充值说明", |
|
style: TextStyle( |
|
color: selectIndex == index |
|
? Color(0xFF4D4D4D) |
|
: Color(0xFF868686), |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
Icon( |
|
Icons.chevron_right, |
|
size: 20, |
|
color: selectIndex == index |
|
? Color(0xFF353535) |
|
: Color(0xFF868686), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget checkView(var index) { |
|
return Container( |
|
padding: EdgeInsets.only(right: 16.w, left: 46.w), |
|
alignment: Alignment.center, |
|
child: Image.asset( |
|
checkIndex != index |
|
? "assets/image/icon_radio_unselected.webp" |
|
: "assets/image/icon_radio_selected.webp", |
|
width: 15.w, |
|
height: 15.h, |
|
), |
|
); |
|
} |
|
|
|
///充值说明底部弹窗 |
|
showRecharge(index) { |
|
showModalBottomSheet( |
|
context: context, |
|
backgroundColor: Colors.transparent, |
|
builder: (context) { |
|
return RechargeWidget(rechargeActLists?.preferentialList?[index]); |
|
}); |
|
} |
|
|
|
///选择推荐门店 |
|
showRecommendStore() { |
|
showModalBottomSheet( |
|
context: context, |
|
backgroundColor: Colors.transparent, |
|
builder: (BuildContext context) { |
|
return StatefulBuilder(builder: ( |
|
context, |
|
state, |
|
) { |
|
return Container( |
|
height: 355.h, |
|
decoration: BoxDecoration( |
|
color: Color(0xFFFAFAFA), |
|
borderRadius: BorderRadius.only( |
|
topLeft: Radius.circular(6), |
|
topRight: Radius.circular(6), |
|
), |
|
), |
|
child: Column( |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
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), |
|
), |
|
), |
|
)), |
|
GestureDetector( |
|
onTap: () { |
|
setState(() { |
|
Navigator.of(context).pop(); |
|
}); |
|
}, |
|
child: Icon( |
|
Icons.clear, |
|
color: Colors.black, |
|
size: 18, |
|
), |
|
), |
|
SizedBox(width: 14), |
|
], |
|
), |
|
Container( |
|
height: 1, |
|
color: Color(0xFFF2F2F2), |
|
margin: EdgeInsets.only(bottom: 13.h), |
|
), |
|
Expanded( |
|
child: ListView.builder( |
|
physics: BouncingScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () { |
|
state(() { |
|
selectStoreIndex = position; |
|
}); |
|
}, |
|
child: recommendStoreItem(position), |
|
); |
|
}, |
|
itemCount: rechargeActLists?.channels?.length ?? 0, |
|
), |
|
), |
|
GestureDetector( |
|
onTap: () { |
|
setState(() { |
|
recommendName = |
|
rechargeActLists?.channels?[selectStoreIndex]; |
|
Navigator.of(context).pop(); |
|
}); |
|
}, |
|
child: Container( |
|
width: double.infinity, |
|
height: 40.h, |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(100), |
|
color: Color(0xFF32A060), |
|
), |
|
alignment: Alignment.center, |
|
margin: EdgeInsets.only( |
|
top: 14.h, bottom: 30.h, left: 16.w, right: 16.w), |
|
child: Text( |
|
S.of(context).queding, |
|
style: TextStyle( |
|
fontWeight: MyFontWeight.bold, |
|
fontSize: 16.sp, |
|
color: Color(0xFFFFFFFF), |
|
), |
|
), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
}); |
|
}, |
|
); |
|
} |
|
|
|
Widget recommendStoreItem(index) { |
|
return Container( |
|
height: 52, |
|
margin: EdgeInsets.only(bottom: 12, left: 14, right: 14), |
|
width: double.infinity, |
|
decoration: BoxDecoration( |
|
borderRadius: new BorderRadius.circular(6), |
|
border: Border.all( |
|
color: |
|
selectStoreIndex == index ? Color(0xFF32A060) : Color(0xFFF7F7F7), |
|
width: selectStoreIndex == index ? 1 : 0, |
|
), |
|
color: |
|
selectStoreIndex == index ? Color(0xFFF0FAF4) : Color(0xFFF7F7F7), |
|
), |
|
alignment: Alignment.centerLeft, |
|
padding: EdgeInsets.only( |
|
left: 12, |
|
), |
|
child: Text( |
|
rechargeActLists?.channels?[index] ?? "", |
|
style: TextStyle( |
|
fontWeight: MyFontWeight.bold, |
|
fontSize: 14.sp, |
|
color: selectStoreIndex == index ? Color(0xFF32A060) : Colors.black, |
|
), |
|
), |
|
); |
|
} |
|
|
|
///充值 |
|
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; |
|
// } |
|
BaseData<dynamic>? baseData = await apiService?.recharge({ |
|
"amount": 0, |
|
"rechargeActId": rechargeActLists?.preferentialList?[selectIndex].id, |
|
"rechargeType": checkIndex, |
|
"channel": recommendName, |
|
}).catchError((error) {}); |
|
if (baseData?.isSuccess ?? false) { |
|
if (checkIndex == 2) { |
|
if (Platform.isAndroid) { |
|
if (!(await Min.isInitialize())) { |
|
// 小程序的微信支付和app的充值支付使用同一个WXPayEntryActivity回调, |
|
// 然而充值时小程序未初始化会导致回调内部代码调用getPackage空指针, |
|
// 故而在此初始化一下 |
|
await Min.initialize(); |
|
} |
|
} |
|
WxPay? wxPay = WxPay.fromJson(baseData?.data); |
|
if (wxPay?.isAnyEmpty() ?? false) { |
|
return; |
|
} |
|
await fluwx.registerApi( |
|
appId: wxPay.appId!, |
|
doOnAndroid: true, |
|
universalLink: "https://hx.lotus-wallet.com/app/", |
|
); |
|
fluwx.pay( |
|
which: Payment( |
|
appId: wxPay.appId!, |
|
partnerId: wxPay.partnerId!, |
|
prepayId: wxPay.prepayId!, |
|
packageValue: wxPay.packageValue!, |
|
nonceStr: wxPay.nonceStr!, |
|
timestamp: int.tryParse(wxPay.timeStamp!) ?? 0, |
|
sign: wxPay.sign!, |
|
), |
|
); |
|
} else { |
|
tobias.isAliPayInstalled.then((value) => { |
|
// 判断是否安装了支付宝 |
|
if (!value) |
|
{SmartDialog.showToast("请安装支付宝", alignment: Alignment.center)} |
|
else |
|
{ |
|
tobias.pay(baseData?.data["body"]).then((payRes) { |
|
if (payRes['resultStatus'] == 9000 || |
|
payRes['resultStatus'] == '9000') { |
|
SmartDialog.showToast("充值成功", |
|
alignment: Alignment.center); |
|
Navigator.of(context).pop(); |
|
} else { |
|
SmartDialog.showToast(payRes['memo'], |
|
alignment: Alignment.center); |
|
} |
|
}) |
|
} |
|
}); |
|
} |
|
} else { |
|
SmartDialog.showToast("${baseData?.msg}", alignment: Alignment.center); |
|
} |
|
} |
|
}
|
|
|