| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656 |
- import 'dart:convert';
- import 'package:bbyyy/beans/pay_way_bean_entity.dart';
- import 'package:bbyyy/beans/user_bean_entity.dart';
- import 'package:bbyyy/beans/withdraw_pricing_bean_entity.dart';
- import 'package:bbyyy/https/MyDio.dart';
- import 'package:bbyyy/my_tools/dims.dart';
- import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
- import 'package:bbyyy/my_tools/event_bus.dart';
- import 'package:bbyyy/my_tools/my_apis.dart';
- import 'package:bbyyy/my_tools/my_colors.dart';
- import 'package:bbyyy/my_tools/my_cookie.dart';
- import 'package:bbyyy/my_tools/my_tools.dart';
- import 'package:bbyyy/my_tools/my_views.dart';
- import 'package:bbyyy/paegs/mine_page/bind_alipay_page/bind_alipay_page.dart';
- import 'package:bbyyy/pay/pay_tools.dart';
- import 'package:flustars/flustars.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/gestures.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- class WithdrawPage extends StatefulWidget {
- @override
- _WithdrawPageState createState() => _WithdrawPageState();
- }
- class _WithdrawPageState extends State<WithdrawPage> {
- TextEditingController _controller = TextEditingController();
- int withdrawalStatus = 1; //0--未提现 1--提现中 2--提现完成
- double percentFee = 0.0;
- double extraFee = 0.0;
- double threshold = 0.0;
- double maxPerHand = 0.0;
- double minPerHand = 0.0;
- int withdrawalPath = -1; // 1---支付宝 2---微信
- List<PayWayBeanData> payWays;
- bool showAlipay = false;
- bool showWeChat = false;
- bool showHandlingFee = false;
- double handlingFee = 0.0;
- double balance = 0.0;
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- queryPersonalInformation();
- queryWithdrawalInstructions();
- Future.delayed(Duration.zero, () {
- checkPaymentMethod((response, hasError) {
- if (!hasError) {
- PayWayBeanEntity entity =
- PayWayBeanEntity().fromJson(json.decode(response.toString()));
- payWays = entity.data;
- showWeChat =
- payWays[payWays.indexWhere((element) => element.way == 2)]
- .withdraw;
- showAlipay =
- payWays[payWays.indexWhere((element) => element.way == 1)]
- .withdraw;
- if (MyCookie().userBean.aliPayAccount.isNotEmpty &&
- payWays[payWays.indexWhere((element) => element.way == 1)]
- .withdraw) {
- withdrawalPath = 1;
- } else if (MyCookie().userBean.wxOpenid.isNotEmpty &&
- payWays[payWays.indexWhere((element) => element.way == 2)]
- .withdraw) {
- withdrawalPath = 2;
- }
- setState(() {});
- }
- }, (e) {});
- });
- }
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onTap: () {
- MyTools().hideKeyboard(context);
- },
- behavior: HitTestBehavior.translucent,
- child: Scaffold(
- backgroundColor: MyColors.cF7F7F7,
- body: Column(
- children: [
- MyViews().myAppBar('申请提现', context, [
- GestureDetector(
- onTap: () {
- MyTools().toPage(context, BindAlipayPage(), (then) {
- setState(() {});
- });
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
- child: Text(
- '修改绑定',
- style: TextStyle(color: MyColors.c333333, fontSize: 16),
- ),
- ),
- ),
- ]),
- Expanded(
- child: SingleChildScrollView(
- child: Column(
- children: [
- if (showAlipay)
- GestureDetector(
- onTap: () {
- if (!payWays[payWays
- .indexWhere((element) => element.way == 1)]
- .withdraw) {
- showToast('支付宝提现暂时维护中');
- return;
- }
- if (MyCookie().userBean.aliPayAccount.isEmpty) {
- showToast('未绑定支付宝');
- } else {
- setState(() {
- withdrawalPath = 1;
- });
- }
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- margin: EdgeInsets.fromLTRB(17, 24, 17, 0),
- child: Row(
- children: [
- Container(
- decoration: BoxDecoration(
- color: withdrawalPath == 1
- ? MyColors.cFF4233
- : MyColors.cD0D0D0,
- borderRadius: BorderRadius.circular(9)),
- height: 18,
- width: 18,
- child: Icon(
- Icons.check,
- color: Colors.white,
- size: 14,
- ),
- alignment: Alignment.center,
- margin: EdgeInsets.only(right: 10),
- ),
- MyViews().myText(
- '提现到支付宝:${MyCookie().userBean.aliPayAccount.isEmpty ? '未绑定支付宝' : MyCookie().userBean.aliPayAccount}',
- MyColors.c666666,
- 15),
- ],
- ),
- ),
- ),
- if (showWeChat)
- GestureDetector(
- onTap: () {
- // if (!payWays[payWays
- // .indexWhere((element) => element.way == 2)]
- // .withdraw) {
- // showToast('微信提现暂时维护中');
- // return;
- // }
- if (MyCookie().userBean.wxOpenid.isEmpty) {
- showToast('未绑定微信');
- } else {
- setState(() {
- withdrawalPath = 2;
- });
- }
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- margin: EdgeInsets.fromLTRB(17, 24, 17, 0),
- child: Row(
- children: [
- Container(
- decoration: BoxDecoration(
- color: withdrawalPath == 2
- ? MyColors.cFF4233
- : MyColors.cD0D0D0,
- borderRadius: BorderRadius.circular(9)),
- height: 18,
- width: 18,
- child: Icon(
- Icons.check,
- color: Colors.white,
- size: 14,
- ),
- alignment: Alignment.center,
- margin: EdgeInsets.only(right: 10),
- ),
- MyViews().myText('提现到微信:', MyColors.c666666, 15),
- MyCookie().userBean.wxOpenid.isEmpty
- ? MyViews()
- .myText('未绑定微信', MyColors.c666666, 15)
- : Row(
- children: [
- Container(
- margin: EdgeInsets.only(right: 10),
- child: ClipRRect(
- borderRadius:
- BorderRadius.circular(12),
- child: MyViews().netImg(
- MyCookie().userBean.wxPicture,
- 24,
- 24),
- ),
- ),
- MyViews().myText(
- MyCookie().userBean.wxName,
- MyColors.c666666,
- 15)
- ],
- )
- ],
- ),
- ),
- ),
- Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(4),
- ),
- margin:
- EdgeInsets.symmetric(horizontal: 17, vertical: 14),
- padding:
- EdgeInsets.symmetric(horizontal: 20, vertical: 15),
- child: Column(
- children: [
- MyViews().myText('提现金额', MyColors.c333333, 16),
- Container(
- margin: EdgeInsets.only(top: 15),
- child: Row(
- children: [
- Text(
- '¥',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 30),
- ),
- Expanded(
- child: TextField(
- inputFormatters: [
- FilteringTextInputFormatter.allow(
- RegExp("[0-9.]")),
- MoneyTextInputFormatter()
- ],
- controller: _controller,
- cursorColor: MyColors.cFF4233,
- cursorWidth: 1.0,
- decoration: InputDecoration(
- border: InputBorder.none,
- disabledBorder: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- hintText: '请输入金额',
- hintStyle: TextStyle(
- color: MyColors.c999999,
- fontSize: 16),
- isDense: true,
- contentPadding:
- const EdgeInsets.fromLTRB(
- 14, 4.5, 8, 4.5)),
- maxLines: 1,
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 30,
- fontWeight: FontWeight.bold,
- height: 1.3,
- letterSpacing: 0.2),
- keyboardType: TextInputType.number,
- onChanged: (t) {
- try {
- showH();
- double amount = double.parse(t);
- if (amount > 0) {
- withdrawalStatus = 0;
- setState(() {});
- }
- } catch (e) {
- withdrawalStatus = 1;
- }
- setState(() {});
- },
- ),
- )
- ],
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 4, bottom: 15),
- color: MyColors.cE7E7E7,
- height: 0.5,
- ),
- RichText(
- text: TextSpan(
- text: '当前零钱余额',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 15),
- children: [
- TextSpan(
- text: '${balanceDisplay(balance).toStringAsFixed(2)}',
- style: TextStyle(
- color: MyColors.cFF4233, fontSize: 15),
- ),
- TextSpan(
- text: '元,',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 15),
- ),
- TextSpan(
- text: '全部提现',
- style: TextStyle(
- color: MyColors.cFF4233,
- fontSize: 15),
- recognizer: TapGestureRecognizer()
- ..onTap = () {
- _controller.text = balance
- .toStringAsFixed(2);
- showH();
- setState(() {
- withdrawalStatus = 0;
- });
- }),
- ]),
- ),
- if (showHandlingFee)
- RichText(
- text: TextSpan(
- text: '手续费',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 15),
- children: [
- TextSpan(
- text: '${handlingFee.toStringAsFixed(2)}',
- style: TextStyle(
- color: MyColors.cFF4233,
- fontSize: 15),
- ),
- ]),
- ),
- if (showHandlingFee)
- RichText(
- text: TextSpan(
- text: '实际到账',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 15),
- children: [
- TextSpan(
- text:
- '${(double.parse(_controller.text.toString()) - handlingFee).toStringAsFixed(2)}',
- style: TextStyle(
- color: MyColors.cFF4233,
- fontSize: 15),
- ),
- ]),
- ),
- GestureDetector(
- onTap: () {
- if (withdrawalPath == -1) {
- showToast('请选择提现方式');
- return;
- }
- if (MyCookie().userBean.forbidWithdraw) {
- showSimpleDialog('你已经被冻结提现,请联系群主或客服。', context,
- () {
- Navigator.pop(context);
- });
- return;
- }
- if (withdrawalStatus == 0) {
- withdrawalStatus = 1;
- withdraw();
- } else {}
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- decoration: BoxDecoration(
- color: withdrawalStatus == 0
- ? MyColors.cFF4233
- : MyColors.cEFEFEF,
- borderRadius: BorderRadius.circular(20)),
- child: MyViews().myText('提现', Colors.white, 14),
- alignment: Alignment.center,
- height: 40,
- margin: EdgeInsets.only(top: 20, bottom: 15),
- ),
- ),
- Container(
- margin: EdgeInsets.only(bottom: 8),
- child: RichText(
- text: TextSpan(
- text: '您的提现手续费为:',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 14),
- children: [
- TextSpan(
- text:
- '${NumUtil.multiply(percentFee, 100)}%${extraFee == 0 ? '' : '+$extraFee'}',
- style: TextStyle(
- color: MyColors.cE2A62D,
- fontSize: 14),
- ),
- // TextSpan(
- // text: '元',
- // style: TextStyle(
- // color: MyColors.c999999,
- // fontSize: 14),
- // ),
- ]),
- ),
- ),
- Visibility(
- visible: maxPerHand != 0,
- child: Container(
- margin: EdgeInsets.only(bottom: 8),
- child: RichText(
- text: TextSpan(
- text: '单笔最高限额:',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 14),
- children: [
- TextSpan(
- text: '$maxPerHand',
- style: TextStyle(
- color: MyColors.cE2A62D,
- fontSize: 14),
- ),
- TextSpan(
- text: '元',
- style: TextStyle(
- color: MyColors.c999999,
- fontSize: 14),
- ),
- ]),
- ),
- ),
- ),
- Visibility(
- visible: minPerHand != 0,
- child: Container(
- margin: EdgeInsets.only(bottom: 8),
- child: RichText(
- text: TextSpan(
- text: '单笔最低限额:',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 14),
- children: [
- TextSpan(
- text: '$minPerHand',
- style: TextStyle(
- color: MyColors.cE2A62D,
- fontSize: 14),
- ),
- TextSpan(
- text: '元',
- style: TextStyle(
- color: MyColors.c999999,
- fontSize: 14),
- ),
- ]),
- ),
- ),
- ),
- Visibility(
- visible: threshold != 0,
- child: RichText(
- text: TextSpan(
- text: '当日免手续费提现额度:',
- style: TextStyle(
- color: MyColors.c999999, fontSize: 14),
- children: [
- TextSpan(
- text: '$threshold',
- style: TextStyle(
- color: MyColors.cE2A62D,
- fontSize: 14),
- ),
- TextSpan(
- text: '元',
- style: TextStyle(
- color: MyColors.c999999,
- fontSize: 14),
- ),
- ]),
- ),
- ),
- ],
- crossAxisAlignment: CrossAxisAlignment.start,
- ),
- )
- ],
- ),
- ),
- ),
- ],
- ),
- ),
- );
- }
- void withdraw() {
- EasyLoading.show();
- try {
- double amount = double.parse(_controller.text.toString());
- if (amount <= balance && amount >= minPerHand) {
- var j = {
- 'user_uid': MyCookie().getUID(),
- 'way': withdrawalPath,
- 'amount': amount
- };
- if (withdrawalPath == 2) {
- j['wx_openid'] = MyCookie().userBean.wxOpenid;
- }
- print(j.toString());
- MyDio().post(MyApis.getApi('withdraw'), j, (response, hasError) {
- if (!hasError) {
- showToast('提现成功');
- withdrawalStatus = 2;
- queryPersonalInformation();
- } else {
- setState(() {
- withdrawalStatus = 0;
- });
- }
- }, (error) {
- setState(() {
- withdrawalStatus = 0;
- });
- });
- } else if (amount > balance) {
- setState(() {
- withdrawalStatus = 0;
- });
- showSimpleDialog('您的余额不足。', context, () {
- Navigator.pop(context);
- });
- } else {
- setState(() {
- withdrawalStatus = 0;
- });
- showSimpleDialog('提现失败:提现金额不能低于$minPerHand元。', context, () {
- Navigator.pop(context);
- });
- }
- } catch (e) {
- EasyLoading.dismiss();
- setState(() {
- withdrawalStatus = 0;
- EasyLoading.dismiss();
- });
- showSimpleDialog('输入内容有误,请重新输入', context, () {
- Navigator.pop(context);
- });
- }
- }
- void queryPersonalInformation() {
- MyDio().query({
- "key": "user",
- "filters": {
- "conditions": ["uid == ${MyCookie().getUID()}"]
- },
- "dims": userDims,
- "paging": [1, 20]
- }, (response, hasError) {
- if (!hasError) {
- UserBeanEntity entity =
- UserBeanEntity().fromJson(json.decode(response.data.toString()));
- MyCookie().userBean = entity.data.data[0];
- balance = balanceDisplay(MyCookie().userBean.balance);
- EventBus().emit('userChange');
- setState(() {});
- if (withdrawalStatus == 2) {
- Navigator.pop(context);
- }
- }
- }, (error) {});
- }
- void queryWithdrawalInstructions() {
- MyDio().query({
- "key": "withdraw_pricing",
- "filters": {},
- "dims": withdrawPricingDims,
- "paging": [1, 20]
- }, (response, hasError) {
- if (!hasError) {
- WithdrawPricingBeanEntity entity = WithdrawPricingBeanEntity()
- .fromJson(json.decode(response.data.toString()));
- if (entity.data.data.isNotEmpty) {
- percentFee = entity.data.data[0].percentFee;
- extraFee = entity.data.data[0].extraFee;
- threshold = entity.data.data[0].threshold;
- maxPerHand = entity.data.data[0].maxPerHand;
- minPerHand = entity.data.data[0].minPerHand;
- }
- }
- setState(() {});
- }, (error) {});
- }
- showH() {
- try {
- double amount = double.parse(_controller.text.toString());
- if (amount >= minPerHand) {
- handlingFee = double.parse((double.parse(_controller.text.toString()) *
- percentFee *
- 100)
- .toStringAsFixed(0)) /
- 100 +
- extraFee;
- setState(() {
- showHandlingFee = true;
- });
- } else {
- setState(() {
- showHandlingFee = false;
- });
- }
- } catch (e) {
- setState(() {
- showHandlingFee = false;
- });
- }
- }
- }
- class MoneyTextInputFormatter extends TextInputFormatter {
- @override
- TextEditingValue formatEditUpdate(
- TextEditingValue oldValue, TextEditingValue newValue) {
- // TODO: implement formatEditUpdate
- String newvalueText = newValue.text;
- if (newvalueText == ".") {
- //第一个数为.
- newvalueText = "0.";
- } else if (newvalueText.contains(".")) {
- if (newvalueText.lastIndexOf(".") != newvalueText.indexOf(".")) {
- //输入了2个小数点
- newvalueText = newvalueText.substring(0, newvalueText.lastIndexOf('.'));
- } else if (newvalueText.length - 1 - newvalueText.indexOf(".") > 2) {
- //输入了1个小数点 小数点后两位
- newvalueText = newvalueText.substring(0, newvalueText.indexOf(".") + 3);
- }
- }
- return TextEditingValue(
- text: newvalueText,
- selection: new TextSelection.collapsed(offset: newvalueText.length),
- );
- }
- }
|