import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:makemoney/api/extract_api.dart';
|
import 'package:makemoney/api/user_api.dart';
|
import 'package:makemoney/model/user/extract_money_model.dart';
|
import 'package:makemoney/ui/widget/button.dart';
|
import 'package:makemoney/ui/widget/dialog.dart';
|
import 'package:makemoney/utils/ui_constant.dart';
|
import 'package:makemoney/utils/ui_utils.dart';
|
import 'package:makemoney/utils/wx_util.dart';
|
|
import '../../ui/widget/nav.dart';
|
|
class BalancePage extends StatefulWidget {
|
BalancePage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_BalancePageState createState() => _BalancePageState();
|
}
|
|
class _BalancePageState extends State<BalancePage>
|
with SingleTickerProviderStateMixin {
|
static const Color EXTRACT_ITEM_FONT_COLOR = Color(0xFF999999);
|
static const Color EXTRACT_ITEM_FONT_HIGHLIGHT_COLOR = Colors.white;
|
|
String _balance = "0.00";
|
String? _extracting;
|
|
bool _needBindWX = false;
|
List<ExtractMoneyModel> extractMoneyList = [];
|
int selectedIndex = 0;
|
|
@override
|
void initState() {
|
super.initState();
|
WXAuthUtil.init(context, (s) {
|
UserApiUtil.bindWX(context, s).then((value) {
|
if (value == null) {
|
return;
|
}
|
if (value["code"] == 0) {
|
ToastUtil.toast("微信绑定成功", context);
|
_getExtractInfo();
|
return;
|
}
|
ToastUtil.toast(value["msg"], context);
|
});
|
});
|
_refresh();
|
}
|
|
void _refresh() {
|
_getExtractInfo();
|
_getExtractDenominationList();
|
}
|
|
void _getExtractInfo() async {
|
Map<String, dynamic>? result = await ExtractApiUtil.getExtractInfo(context);
|
if (result == null) {
|
return;
|
}
|
if (result["code"] != 0) {
|
ToastUtil.toast(result["msg"], context);
|
return;
|
}
|
var data = result["data"];
|
setState(() {
|
_balance = data["balance"];
|
_extracting = data["extracting"];
|
_needBindWX = data["needBindWX"];
|
});
|
}
|
|
void _getExtractDenominationList() async {
|
Map<String, dynamic>? result =
|
await ExtractApiUtil.getExtractDenominationList(context);
|
if (result == null) {
|
return;
|
}
|
if (result["code"] != 0) {
|
ToastUtil.toast(result["msg"], context);
|
return;
|
}
|
List<dynamic> list = result["data"]["list"];
|
List<ExtractMoneyModel> tempList = [];
|
list.forEach((element) {
|
tempList.add(ExtractMoneyModel.fromJson(element));
|
});
|
setState(() {
|
extractMoneyList = tempList;
|
});
|
}
|
|
void _extract(String money) async {
|
Map<String, dynamic>? result = await ExtractApiUtil.extract(context, money);
|
if (result == null) {
|
return;
|
}
|
if (result["code"] != 0) {
|
if (result["code"] == 501) {
|
} else {
|
ToastUtil.toast(result["msg"], context);
|
}
|
return;
|
} else {
|
ToastUtil.toast("申请提现成功", context);
|
_refresh();
|
}
|
}
|
|
void _addLittleMoneyExtractTimes() async {
|
Map<String, dynamic>? result =
|
await ExtractApiUtil.addLittleMoneyExtractTimes(context);
|
if (result == null) {
|
return;
|
}
|
if (result["code"] != 0) {
|
ToastUtil.toast(result["msg"], context);
|
return;
|
}
|
}
|
|
BoxDecoration getItemDecoration(Color bgColor, Color shadowColor) {
|
return BoxDecoration(
|
borderRadius: const BorderRadius.all(Radius.elliptical(10, 10)),
|
color: bgColor,
|
boxShadow: [
|
BoxShadow(
|
color: shadowColor,
|
blurRadius: 2.0,
|
offset: const Offset(0.0, 5.0), //阴影y轴偏移量
|
spreadRadius: 1 //阴影扩散程度
|
)
|
]);
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: const Color(0xFFF0F0F0),
|
body: Column(
|
children: [
|
TopNavBar(title: "余额"),
|
Expanded(
|
child: Container(
|
padding: const EdgeInsets.only(left: 10, right: 10),
|
child: Column(children: [
|
const SizedBox(
|
height: 10,
|
),
|
//余额视图
|
AspectRatio(
|
aspectRatio: 3.3875,
|
child: Stack(
|
alignment: Alignment.bottomCenter,
|
children: [
|
Image.asset(
|
"assets/imgs/mine/ic_balance_bg.png"),
|
Container(
|
margin: const EdgeInsets.only(
|
left: 20, top: 14, bottom: 10),
|
child: Column(
|
crossAxisAlignment:
|
CrossAxisAlignment.start,
|
mainAxisSize: MainAxisSize.min,
|
children: [
|
const Text(
|
"可用余额",
|
style: TextStyle(
|
color: Colors.white,
|
fontSize: 12),
|
),
|
const SizedBox(
|
height: 5,
|
),
|
Text.rich(TextSpan(
|
text: _balance,
|
style: const TextStyle(
|
color: Colors.white,
|
fontSize: 30),
|
children: const [
|
TextSpan(
|
text: "元",
|
style: TextStyle(
|
color: Colors.white,
|
fontSize: 15))
|
])),
|
Expanded(child: Container()),
|
_extracting != null
|
? Row(
|
crossAxisAlignment:
|
CrossAxisAlignment.center,
|
children: [
|
Text(
|
"提现中:$_extracting元",
|
style: const TextStyle(
|
color: Colors.white,
|
fontSize: 12),
|
),
|
const SizedBox(
|
width: 5,
|
),
|
InkWell(
|
onTap: () {
|
DialogUtil.showDialog(
|
context,
|
MyAlertDialog(
|
"温馨提示",
|
"将会在3个工作日内完成人工审核。",
|
() {
|
popPage(
|
context);
|
},
|
sureName: "好的",
|
));
|
},
|
child: Image.asset(
|
"assets/imgs/mine/icon_balance_question.png",
|
height: 12,
|
)),
|
])
|
: Container(),
|
],
|
)),
|
])),
|
|
//绑定微信
|
!_needBindWX
|
? Container()
|
: InkWell(
|
onTap: () {
|
WXAuthUtil.startAuth(context);
|
},
|
child: Container(
|
padding:
|
const EdgeInsets.fromLTRB(13, 10, 5, 10),
|
margin: const EdgeInsets.only(top: 12),
|
decoration: BoxDecoration(
|
borderRadius: BorderRadius.circular(13),
|
color: Colors.white),
|
child: Row(
|
children: [
|
Image.asset(
|
"assets/imgs/mine/icon_balance_wx.png",
|
height: 34,
|
),
|
const SizedBox(
|
width: 12.5,
|
),
|
const Text("绑定微信",
|
style: TextStyle(
|
color: Colors.black, fontSize: 15)),
|
Expanded(child: Container()),
|
const Text("去绑定",
|
style: TextStyle(
|
color: Color(0xFF333333),
|
fontSize: 11)),
|
const Icon(
|
Icons.chevron_right,
|
size: 30,
|
color: Color(0xff2222222),
|
)
|
],
|
),
|
)),
|
const SizedBox(
|
height: 12,
|
),
|
Expanded(
|
child: Container(
|
padding:
|
const EdgeInsets.fromLTRB(12, 12, 12, 12),
|
decoration: const BoxDecoration(
|
borderRadius: BorderRadius.only(
|
topLeft: Radius.circular(13),
|
topRight: Radius.circular(13)),
|
color: Colors.white),
|
child: Column(children: [
|
GridView.builder(
|
shrinkWrap: true,
|
padding: EdgeInsets.zero,
|
gridDelegate:
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
crossAxisCount: 3,
|
mainAxisSpacing: 10,
|
crossAxisSpacing: 15),
|
physics:
|
const NeverScrollableScrollPhysics(),
|
itemCount: extractMoneyList.length,
|
itemBuilder:
|
(BuildContext context, int index) {
|
if (index == selectedIndex) {
|
return getItemViewSelected(
|
extractMoneyList[index],
|
index,
|
() {});
|
} else {
|
return getItemView(
|
extractMoneyList[index], index, () {
|
setState(() {
|
selectedIndex = index;
|
});
|
});
|
}
|
}),
|
const SizedBox(
|
height: 10,
|
),
|
MyFillButton(
|
"提 现",
|
10,
|
fontSize: 15,
|
height: 42,
|
color: ColorConstant.theme,
|
onClick: () {
|
if (extractMoneyList.length <=
|
selectedIndex) {
|
return;
|
}
|
|
if (double.parse(_balance) <
|
double.parse(
|
extractMoneyList[selectedIndex]
|
.money!)) {
|
ToastUtil.toast("余额不足", context);
|
return;
|
}
|
_extract(
|
extractMoneyList[selectedIndex].money!);
|
},
|
)
|
]))),
|
])))
|
],
|
));
|
}
|
|
Widget getItemView(ExtractMoneyModel extractMoneyModel, int index,
|
GestureTapCallback onTap) {
|
return InkWell(
|
onTap: () {
|
onTap();
|
},
|
child: AspectRatio(
|
aspectRatio: 1,
|
child: Stack(children: [
|
Container(
|
decoration: BoxDecoration(
|
borderRadius: BorderRadius.circular(6),
|
border: Border.all(color: const Color(0xFF999999), width: 1.5),
|
),
|
child: _getItemViewContent(extractMoneyModel, index),
|
)
|
])),
|
);
|
}
|
|
Widget getItemViewSelected(ExtractMoneyModel extractMoneyModel, int index,
|
GestureTapCallback onTap) {
|
return InkWell(
|
onTap: () {
|
onTap();
|
},
|
child: ClipRRect(
|
borderRadius: BorderRadius.circular(6),
|
child: AspectRatio(
|
aspectRatio: 1,
|
child: Stack(children: [
|
Container(
|
decoration: const BoxDecoration(
|
gradient: LinearGradient(
|
begin: Alignment.topCenter,
|
end: Alignment.bottomCenter,
|
colors: [
|
Color(0xFFF49984),
|
Color(0xFFF26080),
|
],
|
),
|
),
|
child: _getItemViewContent(extractMoneyModel, index),
|
),
|
Positioned(
|
right: 0,
|
bottom: 0,
|
child: Image.asset(
|
"assets/imgs/mine/icon_balance_extract_checked.png",
|
width: 28,
|
))
|
]))),
|
);
|
}
|
|
Widget _getItemViewContent(ExtractMoneyModel extractMoneyModel, int index) {
|
return Column(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
children: [
|
Container(
|
height: 12.5,
|
alignment: Alignment.topCenter,
|
child: extractMoneyModel.tag != null
|
? Stack(
|
alignment: Alignment.topCenter,
|
children: [
|
Image.asset(
|
"assets/imgs/mine/ic_balanceicon_extract_tag.png",
|
height: 12.5,
|
),
|
Positioned(
|
top: 0,
|
child: Text(
|
extractMoneyModel.tag!,
|
style: const TextStyle(
|
fontSize: 7, color: Color(0xFFFFF9D0)),
|
))
|
],
|
)
|
: Container(),
|
),
|
Text.rich(TextSpan(
|
text: extractMoneyModel.money,
|
style: TextStyle(
|
fontSize: 27,
|
color: index == selectedIndex
|
? EXTRACT_ITEM_FONT_HIGHLIGHT_COLOR
|
: EXTRACT_ITEM_FONT_COLOR),
|
children: [
|
TextSpan(
|
text: "元",
|
style: TextStyle(
|
fontSize: 15,
|
color: index == selectedIndex
|
? EXTRACT_ITEM_FONT_HIGHLIGHT_COLOR
|
: EXTRACT_ITEM_FONT_COLOR),
|
)
|
])),
|
Text(
|
"提现",
|
style: TextStyle(
|
fontSize: 15,
|
color: (index == selectedIndex
|
? EXTRACT_ITEM_FONT_HIGHLIGHT_COLOR
|
: EXTRACT_ITEM_FONT_COLOR)),
|
),
|
],
|
);
|
}
|
}
|