import 'dart:convert'; 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_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/set_alipay_page.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 { TextEditingController _controller = TextEditingController(); int withdrawalStatus = 0; //0--未提现 1--提现中 2--提现完成 double percentFee = 0.0; double extraFee = 0.0; double threshold = 0.0; double maxPerHand = 0.0; double minPerHand = 0.0; @override void initState() { // TODO: implement initState super.initState(); queryPersonalInformation(); queryWithdrawalInstructions(); } @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, SetAlipayPage(), (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: [ Container( margin: EdgeInsets.fromLTRB(17, 24, 17, 0), child: Row( children: [ Container( decoration: BoxDecoration( color: MyColors.cFF4233, 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}', 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.]")), ], 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{ 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: '${MyCookie().userBean.balance}', 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 = MyCookie() .userBean .balance .toString(); setState(() {}); }), ]), ), GestureDetector( onTap: () { 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() { try { double amount = double.parse(_controller.text.toString()); if (amount <= MyCookie().userBean.balance && amount >= minPerHand) { MyDio().post('/pay/withdraw', { 'user_uid': MyCookie().getUID(), 'amount': amount }, (response, hasError) { if (!hasError) { showToast('提现成功'); withdrawalStatus = 2; queryPersonalInformation(); } else { setState(() { withdrawalStatus = 0; }); } }, (error) { setState(() { withdrawalStatus = 0; }); }); } else if (amount > MyCookie().userBean.balance) { setState(() { withdrawalStatus = 0; }); showSimpleDialog('您的余额不足。', context, () { Navigator.pop(context); }); } else { setState(() { withdrawalStatus = 0; }); showSimpleDialog('提现失败:提现金额不能低于$minPerHand元。', context, () { Navigator.pop(context); }); } } catch (e) { 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]; 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) {}); } }