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.

721 lines
32 KiB

import 'dart:convert';
3 years ago
import 'dart:io';
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter/services.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';
4 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
3 years ago
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';
3 years ago
import 'package:huixiang/utils/flutter_utils.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/utils/min.dart';
4 years ago
import 'package:huixiang/view_widget/item_input_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
3 years ago
import 'package:huixiang/view_widget/recharge_details_dialog.dart';
4 years ago
import 'package:huixiang/view_widget/round_button.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tobias/tobias.dart' as tobias;
import 'package:tobias/tobias.dart';
4 years ago
class RechargePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _RechargePage();
}
}
class _RechargePage extends State<RechargePage> {
ApiService apiService;
TextEditingController controller = TextEditingController();
VipRuleDetails vipRuleDetails;
List<VipBenefitList> vipBenefitList = [];
4 years ago
Color color = Colors.black;
double discount = 100;
3 years ago
List<RechargeList> rechargeA;
int selectIndex = 0;
UserInfo userInfo;
3 years ago
String mBalance = "0";
dynamic payListen;
4 years ago
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) {
apiService = ApiService(Dio(),
context: context, token: value.getString("token"), pay: true);
queryBenefitList();
queryRuleDetails();
3 years ago
queryRechargeList();
queryUserBalance();
});
payListen = weChatResponseEventHandler.listen((event) async {
3 years ago
print("payCallback: ${event.errCode}");
3 years ago
if (event.errCode == 0) {
3 years ago
queryUserBalance();
Navigator.of(context).pop();
3 years ago
SmartDialog.showToast("充值成功", alignment: Alignment.center);
}
else{
SmartDialog.showToast("充值失败", alignment: Alignment.center);
return;
}
3 years ago
});
}
@override
void dispose() {
super.dispose();
if(payListen!=null)
payListen.cancel();
}
///会员权益列表
queryBenefitList() async {
3 years ago
BaseData<List<VipBenefitList>> baseData =
await apiService.benefitList().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
setState(() {
vipBenefitList.clear();
vipBenefitList.addAll(baseData.data);
vipBenefitList.forEach((element) {
3 years ago
if (element.have &&
element.config != null &&
element.code == "RECHARGE") {
discount = double.parse(element.config);
}
});
});
}
EasyLoading.dismiss();
}
3 years ago
queryUserBalance() async {
BaseData<UserInfo> baseData =
3 years ago
await apiService.queryInfo().catchError((onError) {});
3 years ago
if (baseData != null && baseData.isSuccess) {
userInfo = baseData.data;
3 years ago
mBalance = userInfo?.money ?? "0";
3 years ago
if (mounted) setState(() {});
}
}
///会员权益介绍/规则/说明/储值说明
queryRuleDetails() async {
BaseData<VipRuleDetails> baseData =
3 years ago
await apiService.vipBenefit().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
setState(() {
vipRuleDetails = baseData.data;
});
}
EasyLoading.dismiss();
}
3 years ago
///充值列表
queryRechargeList() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
3 years ago
BaseData<List<RechargeList>> baseData =
await apiService.rechargeAct().catchError((onError) {});
3 years ago
if (baseData != null && baseData.isSuccess) {
setState(() {
rechargeA = baseData.data;
});
}
EasyLoading.dismiss();
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).chongzhi,
titleColor: Colors.black,
titleSize: 18.sp,
background: Color(0xFFFFFFFF),
leadingColor: Colors.black,
4 years ago
),
3 years ago
body: Container(
color: Color(0xFFFFFFFF),
3 years ago
child: SingleChildScrollView(
child: Container(
child: Stack(
children: [
Column(
children: [
SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Container(
3 years ago
child: Column(
3 years ago
children: [
3 years ago
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),
fontWeight:
MyFontWeight.semi_bold),
)),
Text.rich(
TextSpan(children: [
TextSpan(
text: "$mBalance",
style: TextStyle(
fontSize: 26.sp,
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();
// },
// ),
// },
// ),
// ),
// )
// ],
// ),
],
)),
Container(
width: double.infinity,
margin: EdgeInsets.only(
bottom: 22.h, left: 16, right: 16),
padding: EdgeInsets.only(
top: 20.h,
bottom: 20.h,
3 years ago
),
3 years ago
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(4),
// ),
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
3 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
3 years ago
Padding(
padding: EdgeInsets.only(bottom: 16.h),
child: Text(
S.of(context).zhifufangshi,
style: TextStyle(
fontSize: 16.sp,
color: Colors.black,
fontWeight: FontWeight.bold,
3 years ago
),
),
),
3 years ago
GestureDetector(
onTap: () {
setState(() {
checkIndex = 2;
3 years ago
});
},
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(
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),
3 years ago
],
),
),
3 years ago
],
),
3 years ago
),
3 years ago
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),
// ),
// ),
// ],
// ),
// )
)
3 years ago
],
),
3 years ago
),
3 years ago
)
],
),
3 years ago
],
),
),
3 years ago
),
),
4 years ago
);
}
var checkIndex = 2;
4 years ago
3 years ago
Widget rechargeList() {
3 years ago
return ListView.builder(
padding: EdgeInsets.zero,
itemCount: rechargeA == null ? 0 : rechargeA.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
3 years ago
physics: BouncingScrollPhysics(),
3 years ago
itemBuilder: (context, position) {
3 years ago
return GestureDetector(
3 years ago
onTap: () {
setState(() {
selectIndex = position;
});
},
child: rechargeItem(rechargeA[position], position));
3 years ago
},
);
}
3 years ago
Widget rechargeItem(RechargeList rechargeA, index) {
3 years ago
return Container(
3 years ago
width: double.infinity,
3 years ago
height: 69.h,
decoration: BoxDecoration(
3 years ago
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,
3 years ago
children: [
3 years ago
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(rechargeA.rechargeMoney) ?? 0)}",
style: TextStyle(
fontSize: 18.sp,
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(rechargeA.rechargeMoney) ?? 0) + (double.tryParse(rechargeA.giftdMoney) ?? 0) + ((double.tryParse(rechargeA.rechargeMoney) ?? 0) - ((double.tryParse(rechargeA.rechargeMoney) ?? 0) * (discount / 100))))}",
style: TextStyle(
fontSize: 18.sp,
color: selectIndex == index ? Color(0xFF353535) : Color(0xFF868686),
fontWeight: MyFontWeight.semi_bold),
),
]),
3 years ago
),
3 years ago
SizedBox(
height: 4.h,
3 years ago
),
3 years ago
GestureDetector(
onTap: (){
setState(() {
if(selectIndex == index)
3 years ago
showRecharge(index);
3 years ago
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
3 years ago
crossAxisAlignment: CrossAxisAlignment.center,
3 years ago
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),
),
],
)
),
],
))
3 years ago
],
));
}
4 years ago
Widget checkView(var index) {
return Container(
padding: EdgeInsets.only(right: 16.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,
),
4 years ago
);
}
3 years ago
///充值说明底部弹窗
3 years ago
showRecharge(index) {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return RechargeWidget(rechargeA[index]);
});
}
3 years ago
recharge() async {
3 years ago
// 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;
// }
3 years ago
BaseData<dynamic> baseData = await apiService.recharge({
"amount": 0,
"rechargeActId": rechargeA[selectIndex].id,
"rechargeType": checkIndex
3 years ago
}).catchError((error) {});
if (baseData != null && baseData.isSuccess) {
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);
Navigator.of(context).pop();
} else {
SmartDialog.showToast(payRes['memo'], alignment: Alignment.center);
}
})
}
});
}
3 years ago
} else {
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
}
3 years ago
}
4 years ago
}