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.
446 lines
13 KiB
446 lines
13 KiB
import 'dart:convert'; |
|
|
|
import 'package:dio/dio.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:fluttertoast/fluttertoast.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/user_bill.dart'; |
|
import 'package:huixiang/retrofit/data/user_info.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/view_widget/classic_header.dart'; |
|
import 'package:huixiang/view_widget/my_footer.dart'; |
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
class MineWalletPage extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _MineWalletPage(); |
|
} |
|
} |
|
|
|
class _MineWalletPage extends State<MineWalletPage> { |
|
dynamic mBalance = 0; |
|
|
|
@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'))); |
|
mBalance = double.tryParse(userInfo.money).toInt(); |
|
|
|
if (mounted) setState(() {}); |
|
String token = sharedPreferences.getString("token"); |
|
apiService = ApiService(Dio(), context: context, token: token); |
|
loadBillInfo(); |
|
} |
|
|
|
_onRefresh() { |
|
current = 1; |
|
loadBillInfo(); |
|
} |
|
|
|
queryUserBalance() async { |
|
BaseData baseData = await apiService.queryInfo(); |
|
if (baseData != null && baseData.isSuccess) { |
|
userInfo = UserInfo.fromJson(baseData.data); |
|
mBalance = double.tryParse(userInfo.money).toInt(); |
|
if (mounted) setState(() {}); |
|
setState(() {}); |
|
} else { |
|
Fluttertoast.showToast(msg: baseData.msg); |
|
} |
|
} |
|
|
|
loadBillInfo() async { |
|
queryUserBalance(); |
|
BaseData baseData = await apiService.queryBillInfo({ |
|
"current": current, |
|
"model": {"category": "", "title": "bill_tenant_balance", "type": ""}, |
|
"order": "descending", |
|
"size": 10, |
|
"sort": "id" |
|
}).catchError((onError) { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
}); |
|
if (baseData != null && baseData.isSuccess) { |
|
PageInfo pageInfo = PageInfo.fromJson(baseData.data); |
|
if (current == 1) { |
|
userBills.clear(); |
|
} |
|
userBills |
|
.addAll(pageInfo.records.map((e) => UserBill.fromJson(e)).toList()); |
|
refreshController.refreshCompleted(); |
|
refreshController.loadComplete(); |
|
if (current * 10 > int.tryParse(pageInfo.total)) { |
|
refreshController.loadNoData(); |
|
} else { |
|
current += 1; |
|
} |
|
} else { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
Fluttertoast.showToast(msg: baseData.msg); |
|
} |
|
if (mounted) setState(() {}); |
|
} |
|
|
|
RefreshController refreshController = RefreshController(); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: AppBar( |
|
title: Text( |
|
S.of(context).wodeqianbao, |
|
style: TextStyle( |
|
color: Colors.black, |
|
fontWeight: FontWeight.bold, |
|
), |
|
), |
|
centerTitle: false, |
|
backgroundColor: Color(0xFFF7F7F7), |
|
elevation: 0, |
|
leading: GestureDetector( |
|
onTap: () { |
|
Navigator.of(context).pop(); |
|
}, |
|
child: Container( |
|
alignment: Alignment.centerRight, |
|
margin: EdgeInsets.only(left: 10.w), |
|
padding: EdgeInsets.all(6), |
|
child: Icon( |
|
Icons.arrow_back_ios, |
|
color: Colors.black, |
|
size: 24, |
|
), |
|
), |
|
), |
|
titleSpacing: 2, |
|
leadingWidth: 56.w, |
|
), |
|
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(), |
|
balanceHistory(), |
|
], |
|
), |
|
), |
|
), |
|
), |
|
); |
|
} |
|
|
|
Widget balanceHistory() { |
|
return Container( |
|
margin: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 0), |
|
padding: EdgeInsets.fromLTRB(24.w, 24.h, 24.w, 24.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: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
S.of(context).lishijilu, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
color: Colors.black, |
|
fontSize: 16.sp, |
|
), |
|
), |
|
SizedBox( |
|
height: 16.h, |
|
), |
|
// Row( |
|
// children: [ |
|
// Container( |
|
// width: 3, |
|
// height: 15, |
|
// color: Color(0xFF20662A), |
|
// ), |
|
// SizedBox( |
|
// width: 3, |
|
// ), |
|
// Text( |
|
// "09/2021", |
|
// style: TextStyle( |
|
// color: Color(0xFF353535), |
|
// fontSize: 14, |
|
// ), |
|
// ), |
|
// ], |
|
// ), |
|
Container( |
|
margin: EdgeInsets.only(top: 14), |
|
child: ListView.builder( |
|
itemCount: userBills != null ? userBills.length : 0, |
|
shrinkWrap: true, |
|
padding: EdgeInsets.only(bottom: 20), |
|
physics: NeverScrollableScrollPhysics(), |
|
itemBuilder: (context, position) { |
|
return historyItem(userBills[position], position); |
|
}), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget historyItem(UserBill userBill, position) { |
|
return Container( |
|
margin: EdgeInsets.only(top: 10, bottom: 10), |
|
child: Row( |
|
children: [ |
|
Image.asset( |
|
userBill.pm == 0 |
|
? "assets/image/icon_wallet_withdrawal.png" |
|
: "assets/image/icon_wallet_recharge.png", |
|
width: 34, |
|
height: 34, |
|
), |
|
SizedBox( |
|
width: 12, |
|
), |
|
Expanded( |
|
flex: 1, |
|
child: Container( |
|
height: 34, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
userBill.name, |
|
style: TextStyle( |
|
color: Colors.black, |
|
fontSize: 12, |
|
), |
|
), |
|
Text( |
|
userBill.createTime, |
|
style: TextStyle( |
|
color: Color(0xFF727272), |
|
fontSize: 10.sp, |
|
), |
|
) |
|
], |
|
), |
|
), |
|
), |
|
Container( |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.end, |
|
children: [ |
|
Text( |
|
userBill.pm == 0 |
|
? "-${userBill.number}" |
|
: "+${userBill.number}", |
|
style: TextStyle( |
|
color: Colors.black, |
|
fontSize: 12.sp, |
|
), |
|
), |
|
Text( |
|
S.of(context).yue_(userBill.balance), |
|
style: TextStyle( |
|
color: Color(0xFF727272), |
|
fontSize: 10.sp, |
|
), |
|
) |
|
], |
|
), |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget balance() { |
|
return Container( |
|
width: double.infinity, |
|
margin: EdgeInsets.fromLTRB(16, 16, 16, 8), |
|
padding: EdgeInsets.fromLTRB(24, 24, 24, 24), |
|
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: Column( |
|
children: [ |
|
Text( |
|
S.of(context).zhanghuyue, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
color: Color(0xFF353535), |
|
fontSize: 16), |
|
), |
|
Text( |
|
"$mBalance", |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
color: Color(0xFF353535), |
|
fontSize: 60), |
|
), |
|
Text( |
|
S.of(context).keyongyue, |
|
style: TextStyle( |
|
color: Color(0xFF20662A), |
|
fontSize: 16, |
|
), |
|
), |
|
SizedBox( |
|
height: 24, |
|
), |
|
InkWell( |
|
onTap: () { |
|
queryUserBalance(); |
|
}, |
|
child: RoundButton( |
|
icons: Icon( |
|
Icons.refresh, |
|
color: Colors.white, |
|
), |
|
text: S.of(context).shuaxinyue, |
|
textColor: Colors.white, |
|
radius: 15, |
|
backgroup: Color(0xFF20662A), |
|
fontSize: 12, |
|
padding: EdgeInsets.fromLTRB(12, 4, 12, 4), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget rechargeWithdrawal() { |
|
return Row( |
|
children: [ |
|
Expanded( |
|
child: InkWell( |
|
onTap: () { |
|
Navigator.of(context).pushNamed('/router/recharge_page'); |
|
}, |
|
child: Container( |
|
margin: EdgeInsets.fromLTRB(16, 16, 16, 16), |
|
padding: EdgeInsets.fromLTRB(0, 7, 0, 7), |
|
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_recharge.png", |
|
width: 40, |
|
height: 40, |
|
), |
|
Text( |
|
S.of(context).chongzhi, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 16, |
|
color: Colors.black), |
|
) |
|
], |
|
), |
|
), |
|
), |
|
flex: 1, |
|
), |
|
Expanded( |
|
child: Container( |
|
margin: EdgeInsets.fromLTRB(16, 16, 16, 16), |
|
padding: EdgeInsets.fromLTRB(0, 7, 0, 7), |
|
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.png", |
|
width: 40, |
|
height: 40, |
|
), |
|
Text( |
|
S.of(context).tixian, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 16, |
|
color: Colors.black), |
|
) |
|
], |
|
), |
|
), |
|
flex: 1, |
|
), |
|
], |
|
); |
|
} |
|
}
|
|
|