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.

824 lines
27 KiB

4 years ago
import 'dart:convert';
import 'dart:io';
4 years ago
import 'package:dio/dio.dart';
import 'package:flare_flutter/base/actor_ellipse.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/examine_instance.dart';
4 years ago
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/data/user_bill.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
4 years ago
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/classic_header.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/no_data_view.dart';
4 years ago
import 'package:huixiang/view_widget/round_button.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class MineWalletPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MineWalletPage();
}
}
class _MineWalletPage extends State<MineWalletPage> {
dynamic pBalance = 0; //平台总余额
dynamic mBalance = 0; // 余额
dynamic mgreenMoney = 0;
dynamic activityMoney = 0;
4 years ago
@override
void initState() {
super.initState();
loadBalance();
}
UserInfo userInfo;
ApiService apiService;
int current = 1;
List<UserBill> userBills = [];
loadBalance() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
userInfo =
UserInfo.fromJson(jsonDecode(sharedPreferences.getString('user')));
mgreenMoney = double.tryParse(userInfo.greenMoney);
mBalance = double.tryParse(userInfo.money);
pBalance = mgreenMoney + mBalance;
activityMoney = double.tryParse(userInfo.activityMoney);
4 years ago
if (mounted) setState(() {});
String token = sharedPreferences.getString("token");
apiService = ApiService(Dio(), context: context, token: token);
loadBillInfo();
}
_onRefresh() {
current = 1;
loadBillInfo();
}
4 years ago
queryUserBalance() async {
BaseData<UserInfo> baseData =
await apiService.queryInfo().catchError((onError) {});
4 years ago
if (baseData != null && baseData.isSuccess) {
3 years ago
userInfo = baseData.data;
mgreenMoney = double.tryParse(userInfo.greenMoney);
activityMoney = double.tryParse(userInfo.activityMoney);
mBalance = double.tryParse(userInfo.money);
pBalance = mBalance + mgreenMoney;
if (mounted) setState(() {});
4 years ago
}
}
4 years ago
loadBillInfo() async {
4 years ago
queryUserBalance();
3 years ago
BaseData<PageInfo<UserBill>> baseData = await apiService.queryBillInfo({
4 years ago
"current": current,
4 years ago
"model": {"category": "", "title": "bill_title_balance", "type": ""},
4 years ago
"order": "descending",
"size": 10,
"sort": "id"
}).catchError((onError) {
refreshController.refreshFailed();
refreshController.loadFailed();
});
if (baseData != null && baseData.isSuccess) {
if (current == 1) {
userBills.clear();
}
3 years ago
userBills.addAll(baseData.data.records);
4 years ago
refreshController.refreshCompleted();
refreshController.loadComplete();
3 years ago
if (current * 10 > int.tryParse(baseData.data.total)) {
4 years ago
refreshController.loadNoData();
} else {
current += 1;
}
} else {
refreshController.refreshFailed();
refreshController.loadFailed();
}
if (mounted) setState(() {});
}
RefreshController refreshController = RefreshController();
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).huixiangqianbao,
4 years ago
titleColor: Colors.black,
background: Color(0xFFF7F7F7),
leadingColor: Colors.black,
4 years ago
),
4 years ago
body: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: true,
physics: BouncingScrollPhysics(),
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: _onRefresh,
onLoading: loadBillInfo,
child: SingleChildScrollView(
child: Container(
color: Color(0xFFF7F7F7),
child: Column(
children: [
balance(),
// rechargeWithdrawal(),
4 years ago
balanceHistory(),
],
),
4 years ago
),
),
),
);
}
Widget balanceHistory() {
return Container(
4 years ago
margin: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 0),
padding: EdgeInsets.fromLTRB(24.w, 24.h, 24.w, 24.h),
4 years ago
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(25),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).xiaofeijilu,
4 years ago
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
4 years ago
fontSize: 16.sp,
4 years ago
),
),
SizedBox(
4 years ago
height: 16.h,
4 years ago
),
Container(
child: (userBills == null || userBills.length == 0)
? NoDataView(
src: "assets/image/xiao_fei.webp",
isShowBtn: false,
text: S.of(context).muqianwujilu,
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h),
)
: ListView.builder(
itemCount: userBills != null ? userBills.length : 0,
shrinkWrap: true,
padding: EdgeInsets.only(bottom: 20.h),
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return historyItem(userBills[position], position);
},
),
4 years ago
),
],
),
);
}
4 years ago
Widget historyItem(UserBill userBill, position) {
4 years ago
return Container(
margin: EdgeInsets.only(top: 10.h, bottom: 10.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 7,
child: Text(
userBill.name,
style: TextStyle(
color: Colors.black,
fontSize: 12.sp,
),
)),
Expanded(
flex: 4,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: calculateBalance(userBill, 0)
.map(
(e) => e == S.of(context).yue
? Container(
width: e == S.of(context).yue
? (12.sp * 4)
: double.infinity,
alignment: Alignment.centerRight,
child: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
.toList(),
),
),
],
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 7,
child: Text(
userBill.createTime,
style: TextStyle(
color: Color(0xFF727272),
fontSize: 10.sp,
),
),
),
if (calculateBalance(userBill, 1).isNotEmpty)
Expanded(
flex: 4,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: calculateBalance(userBill, 1)
.map(
(e) => e == S.of(context).yue
? Container(
width: e == S.of(context).yue
? (12.sp * 4)
: double.infinity,
alignment: Alignment.centerRight,
child: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
.toList(),
4 years ago
),
4 years ago
),
],
),
SizedBox(
height: 4,
),
Row(
children: [
Expanded(
flex: 7,
child: Text(
S.of(context).pingtaizongyue(userBill.balance),
style: TextStyle(
color: Color(0xFF727272),
fontSize: 10.sp,
),
),
),
if (calculateBalance(userBill, 2).isNotEmpty)
Expanded(
flex: 4,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: calculateBalance(userBill, 2)
.map(
(e) => e == S.of(context).yue
? Container(
width: e == S.of(context).yue
? (12.sp * 4)
: double.infinity,
alignment: Alignment.centerRight,
child: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
: Text(
e,
style: TextStyle(
color: Color(0xFF20662A),
fontWeight: FontWeight.bold,
fontSize: 12.sp,
),
),
)
.toList(),
),
),
],
),
4 years ago
],
),
);
}
bool isZero(String money) {
if (money == null || money.isEmpty) return true;
double zero = double.tryParse(money);
return zero == 0;
}
List<String> calculateBalance(UserBill userBill, int index) {
double tbalance = double.tryParse(userBill.number ?? "0");
/// 总余额
String surplusGreenMoney = userBill.surplusGreenMoney;
String surplusActivityMoney = userBill.surplusActivityMoney;
double surplusMoney = double.tryParse(surplusGreenMoney ?? "0");
double surplusActivity = double.tryParse(surplusActivityMoney ?? "0");
// double balance = tbalance - (surplusMoney ?? 0) - (surplusActivity ?? 0);
String greenMoney = userBill.greenMoney;
String activityMoney = userBill.activityMoney;
double money = double.tryParse(greenMoney ?? "0");
double activity = double.tryParse(activityMoney ?? "0");
if (index == 0) {
if (money > 0) {
return [S.of(context).lvbiyue, "${userBill.pm == 0 ? '-' : '+'}$money"];
}
if (activity > 0) {
return [
S.of(context).huodongyue,
"${userBill.pm == 0 ? '-' : '+'}$activity"
];
}
if (tbalance > 0) {
return [S.of(context).yue, "${userBill.pm == 0 ? '-' : '+'}$tbalance"];
}
return [];
} else if (index == 1) {
if (money > 0 && activity > 0) {
return [
S.of(context).huodongyue,
"${userBill.pm == 0 ? '-' : '+'}$activity"
];
}
if (money > 0 && (tbalance - money) > 0) {
return [
S.of(context).yue,
"${userBill.pm == 0 ? '-' : '+'}${(tbalance - money)}"
];
} else {
return [];
}
} else {
if (activity > 0 && money > 0) {
return [
S.of(context).yue,
"${userBill.pm == 0 ? '-' : '+'}${(tbalance - money - activity)}"
];
} else {
return [];
}
}
}
//assets/image/recharge,Btn.png
4 years ago
Widget balance() {
return Container(
margin: EdgeInsets.fromLTRB(14.w, 16.h, 14.w, 8.h),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(25),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
),
],
),
child: IntrinsicHeight(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//24.w, 24.h, 24.w, 24.h
Padding(
padding: EdgeInsets.only(
left: 24.w,
top: 24.h,
),
child: Text(
S.of(context).zongzichanyuan,
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
),
),
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 24.w,
),
Text(
"$pBalance",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 50.sp,
color: Colors.white,
),
),
Spacer(
flex: 1,
),
InkWell(
onTap: () {
toRecharge();
},
child: SizedBox(
width: 87.w,
height: 46.h,
child: Stack(
children: [
Positioned.fill(
child: Image.asset(
"assets/image/rechargeBtn.png",
height: 46.h,
width: 87.w,
fit: BoxFit.fill,
),
),
Positioned(
left: 14.w,
top: 0,
bottom: 0,
child: Container(
alignment: Alignment.centerLeft,
child: Text(
S.of(context).chongzhi,
style: TextStyle(
fontSize: 18.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
),
),
],
),
),
),
],
),
flex: 1,
),
SizedBox(
height: 22.h,
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: 24.w,
),
child: Row(
children: [
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${S.of(context).yue}(含活动)",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Colors.white,
),
),
SizedBox(
height: 4.h,
),
Text(
"$mBalance",
style: TextStyle(
fontSize: 18.sp,
fontWeight: MyFontWeight.semi_bold,
color: Colors.white,
),
),
],
),
),
SizedBox(
height: 8.h,
),
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).huodongyue,
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Colors.white,
),
),
SizedBox(
height: 4.h,
),
Text(
"$activityMoney",
style: TextStyle(
fontSize: 18.sp,
fontWeight: MyFontWeight.semi_bold,
color: Colors.white,
),
),
],
),
),
SizedBox(
height: 8.h,
),
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).lvbiyue,
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Colors.white,
),
),
SizedBox(
height: 4.h,
),
Text(
"$mgreenMoney",
style: TextStyle(
fontSize: 18.sp,
fontWeight: MyFontWeight.semi_bold,
color: Colors.white,
),
),
],
),
),
],
),
),
SizedBox(
height: 24.h,
),
],
),
),
);
}
// Widget balance1() {
// return Container(
// width: double.infinity,
// margin: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 8.h),
// padding: EdgeInsets.fromLTRB(24.w, 24.h, 24.w, 24.h),
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(8),
// boxShadow: [
// BoxShadow(
// color: Colors.black.withAlpha(25),
// offset: Offset(0, 3),
// blurRadius: 14,
// spreadRadius: 0,
// ),
// ],
// ),
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Stack(
// alignment: Alignment.center,
// children: [
// Align(
// alignment: Alignment.center,
// child: Text(
// S.of(context).zongzichan,
// style: TextStyle(
// fontWeight: MyFontWeight.semi_bold,
// color: Color(0xFF353535),
// fontSize: 16.sp,
// ),
// ),
// ),
// // GestureDetector(
// // onTap: () {
// // queryUserBalance();
// // },
// // child: Row(
// // mainAxisAlignment: MainAxisAlignment.end,
// // children: [
// // Icon(
// // Icons.refresh,
// // size: 20,
// // color: Color(0xFF8A8A8A),
// // ),
// // Text(
// // S.of(context).shuaxin,
// // style: TextStyle(
// // color: Color(0xFF353535),
// // fontSize: 12.sp,
// // ),
// // ),
// // ],
// // ),
// // ),
// ],
// ),
// SizedBox(
// height: 16.h,
// ),
// Text(
// "$mBalance",
// style: TextStyle(
// fontWeight: MyFontWeight.medium,
// color: Color(0xFF353535),
// fontSize: 50.sp,
// ),
// ),
// // SizedBox(
// // height: 4.h,
// // ),
// // Text(
// // S.of(context).keyongyue,
// // style: TextStyle(
// // color: Color(0xFF20662A),
// // fontSize: 16.sp,
// // fontWeight: MyFontWeight.regular
// // ),
// // ),
// SizedBox(
// height: 24.h,
// ),
// InkWell(
// onTap: () {
// toRecharge();
// },
// child: RoundButton(
// width: 104.w,
// text: S.of(context).lijichongzhi,
// textColor: Colors.white,
// fontWeight: MyFontWeight.semi_bold,
// radius: 15,
// backgroup: Color(0xFF32A060),
// fontSize: 14.sp,
// padding: EdgeInsets.symmetric(vertical: 5.h),
// ),
// ),
// ],
// ),
// );
// }
4 years ago
4 years ago
toRecharge() async {
await Navigator.of(context).pushNamed('/router/recharge_page');
loadBillInfo();
}
//充值/提现
// Widget rechargeWithdrawal() {
// return Row(
// children: [
// Expanded(
// child: InkWell(
// onTap: () {
// toRecharge();
// },
// child: Container(
// margin: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 16.h),
// padding: EdgeInsets.fromLTRB(0, 7.h, 0, 7.h),
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(8),
// boxShadow: [
// BoxShadow(
// color: Colors.black.withAlpha(12),
// offset: Offset(0, 3),
// blurRadius: 14,
// spreadRadius: 0,
// )
// ]),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Image.asset(
// "assets/image/icon_wallet_recharge.webp",
// width: 40.w,
// height: 40.h,
// ),
// Text(
// S.of(context).chongzhi,
// style: TextStyle(
// fontWeight: FontWeight.bold,
// fontSize: 16.sp,
// color: Colors.black,
// ),
// )
// ],
// ),
// ),
// ),
// flex: 1,
// ),
// Expanded(
// child: Container(
// margin: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 16.h),
// padding: EdgeInsets.fromLTRB(0, 7.h, 0, 7.h),
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.all(Radius.circular(8)),
// boxShadow: [
// BoxShadow(
// color: Colors.black.withAlpha(12),
// offset: Offset(0, 3),
// blurRadius: 14,
// spreadRadius: 0)
// ]),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Image.asset(
// "assets/image/icon_wallet_withdrawal.webp",
// width: 40.w,
// height: 40.w,
// ),
// Text(
// S.of(context).tixian,
// style: TextStyle(
// fontWeight: FontWeight.bold,
// fontSize: 16.sp,
// color: Colors.black,
// ),
// )
// ],
// ),
// ),
// flex: 1,
// ),
// ],
// );
// }
4 years ago
}