diff --git a/lib/dialog/tip_dialog/tip_dialog.dart b/lib/dialog/tip_dialog/tip_dialog.dart index af49407..bb473ad 100644 --- a/lib/dialog/tip_dialog/tip_dialog.dart +++ b/lib/dialog/tip_dialog/tip_dialog.dart @@ -4,7 +4,9 @@ import 'package:zhiying_comm/zhiying_comm.dart'; class TipDialog extends StatelessWidget { String title; - TipDialog({this.title = "温馨提示", this.content}); + String btnText; + + TipDialog({this.title = "温馨提示", this.content, this.btnText = "知道了"}); String content; @@ -23,12 +25,27 @@ class TipDialog extends StatelessWidget { margin: EdgeInsets.only(left: 91.w, right: 91.w), child: Column( children: [ - Padding( - padding: const EdgeInsets.only(top: 16), - child: Text( - title, - style: TextStyle(fontSize: 30.sp,fontWeight: FontWeight.w400), - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + SizedBox( + width: 48, + + ), + Text( + title, + style: TextStyle( + fontSize: 30.sp, fontWeight: FontWeight.w400), + ), + SizedBox( + width: 48, + child: IconButton( + icon: Icon(Icons.close), + onPressed: () { + Navigator.pop(context, false); + }), + ), + ], ), Container( margin: EdgeInsets.all(16), @@ -50,10 +67,10 @@ class TipDialog extends StatelessWidget { shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(50)), onPressed: () { - Navigator.pop(context); + Navigator.pop(context,true); }, child: Text( - "知道了", + btnText, style: TextStyle( color: HexColor.fromHex("#FFFFFF"), fontSize: 26.sp), diff --git a/lib/pages/withdraw_page/bloc/withdraw_bloc.dart b/lib/pages/withdraw_page/bloc/withdraw_bloc.dart index 06ec4cc..963dd86 100644 --- a/lib/pages/withdraw_page/bloc/withdraw_bloc.dart +++ b/lib/pages/withdraw_page/bloc/withdraw_bloc.dart @@ -1,6 +1,11 @@ import 'dart:async'; import 'dart:convert' as convert; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart'; +import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_data_model.dart'; import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_model.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; @@ -13,6 +18,12 @@ class WithdrawBloc extends BlocBase { Stream get outData => _dataController.stream; + WithdrawDataModel withdrawDataModel; + + Map aliPayModel; + + String skipIdentifier; + @override void dispose() { _dataController.close(); @@ -20,6 +31,7 @@ class WithdrawBloc extends BlocBase { } void loadData(String skipIdentifier) async { + this.skipIdentifier = skipIdentifier; NetUtil.request('/api/v1/mod/${skipIdentifier.toString()}', method: NetMethod.GET, onCache: (data) { _loadData(data); @@ -28,6 +40,14 @@ class WithdrawBloc extends BlocBase { }); } + ///加载数据 + void loadWithdrawData() { + NetUtil.request("/api/v1/user/cash_out", onSuccess: (data) { + withdrawDataModel = WithdrawDataModel.fromJson(data); + _dataController.add(_model); + }); + } + void _loadData(dynamic data) { try { Map json = Map.from(data); @@ -50,4 +70,54 @@ class WithdrawBloc extends BlocBase { Logger.error(err); } } + + ///提交提现申请 + void submitApply(BuildContext context, String money) async { + num amount = num.tryParse(money); + if (amount != null && amount > 0) { + var result = await showDialog( + context: context, + child: TipDialog( + btnText: "确定", + content: "确定要提现?", + )); + + if (result == null || !result) { + return; + } + + NetUtil.request("/api/v1/user/cash_out", + method: NetMethod.POST, + params: {'amount': amount.toString()}, onSuccess: (data) { + showDialog( + context: context, + child: TipDialog( + content: "提现申请已成功提交,请耐心等候审核通过", + )); + loadData(skipIdentifier); + loadWithdrawData(); + }, onError: (data) { + showDialog( + context: context, + child: TipDialog( + content: "提现申请提交失败!,请稍后再试", + )); + }); + } else { + showDialog( + context: context, + child: TipDialog( + content: "请输入正确的金额!", + )); + } + } + + ///支付宝是否绑定请求 + getAlipayStatus(){ + NetUtil.request("/api/v1/settings/account/security",onSuccess: (data){ + aliPayModel=data; + _dataController.add(_model); + }); + } + } diff --git a/lib/pages/withdraw_page/models/withdraw_data_model.dart b/lib/pages/withdraw_page/models/withdraw_data_model.dart new file mode 100644 index 0000000..0089ea8 --- /dev/null +++ b/lib/pages/withdraw_page/models/withdraw_data_model.dart @@ -0,0 +1,21 @@ +class WithdrawDataModel { + String finValue; + String isBindAlipay; + String alipayUserName; + + WithdrawDataModel({this.finValue, this.isBindAlipay, this.alipayUserName}); + + WithdrawDataModel.fromJson(Map json) { + finValue = json['fin_value']; + isBindAlipay = json['is_bind_alipay']; + alipayUserName = json['alipay_user_name']; + } + + Map toJson() { + final Map data = new Map(); + data['fin_value'] = this.finValue; + data['is_bind_alipay'] = this.isBindAlipay; + data['alipay_user_name'] = this.alipayUserName; + return data; + } +} diff --git a/lib/pages/withdraw_page/models/withdraw_model.dart b/lib/pages/withdraw_page/models/withdraw_model.dart index 52350a9..4dd997e 100644 --- a/lib/pages/withdraw_page/models/withdraw_model.dart +++ b/lib/pages/withdraw_page/models/withdraw_model.dart @@ -1,3 +1,5 @@ +import 'package:zhiying_comm/zhiying_comm.dart'; + class WithdrawModel { String appBarName; String appBarNameColor; @@ -27,6 +29,8 @@ class WithdrawModel { String cashOutBtnTextUnavailableColor; String cashOutBtnTextUnavailableBgColor; String cashOutTips; + SkipModel detailSkipModel; + SkipModel gotoAliPay; WithdrawModel( {this.appBarName, @@ -99,6 +103,13 @@ class WithdrawModel { cashOutBtnTextUnavailableBgColor = json['cash_out_btn_text_unavailable_bg_color']; cashOutTips = json['cash_out_tips']; + + if(json['app_bar_right_skip_identifier']!=null){ + detailSkipModel=SkipModel.fromJson(json['app_bar_right_skip_identifier']); + } + if(json['alipay_goto_skip_identifier']!=null){ + gotoAliPay=SkipModel.fromJson(json['alipay_goto_skip_identifier']); + } } Map toJson() { diff --git a/lib/pages/withdraw_page/withdraw_page.dart b/lib/pages/withdraw_page/withdraw_page.dart index 81e173b..18ccdb6 100644 --- a/lib/pages/withdraw_page/withdraw_page.dart +++ b/lib/pages/withdraw_page/withdraw_page.dart @@ -1,9 +1,11 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:zhiying_base_widget/pages/bil_detail_page/bil_detail_page.dart'; import 'package:zhiying_base_widget/pages/withdraw_page/bloc/withdraw_bloc.dart'; import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_model.dart'; import 'package:zhiying_base_widget/pages/withdraw_page/withdraw_page_sk.dart'; +import 'package:zhiying_base_widget/utils/contants.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; @@ -24,51 +26,12 @@ class _WithdrawPageState extends State { onTap: () { FocusScope.of(context).requestFocus(FocusNode()); }, - child: Scaffold( - appBar: _createNav(), - backgroundColor: Colors.white, - body: SafeArea( - child: BlocProvider( - bloc: WithdrawBloc(), - child: _WithdrawContainer(widget.data), - ), - ), - ), - ); - } - - // 导航栏 - Widget _createNav() { - return CupertinoNavigationBar( - leading: Navigator.canPop(context) - ? GestureDetector( - child: Container( - padding: EdgeInsets.zero, - child: Icon( - Icons.arrow_back_ios, - size: 20, - ), - ), - onTap: () { - if (Navigator.canPop(context)) { - Navigator.pop(context); - } - }, - ) - : Container(), - middle: Text( - '提现', - style: TextStyle( - fontSize: 15, - color: Color(0xff333333), - ), - ), - trailing: GestureDetector( - child: Text( - '明细', - style: TextStyle(fontSize: 13, color: Color(0xff333333)), + child: Container( + color: Colors.white, + child: BlocProvider( + bloc: WithdrawBloc(), + child: _WithdrawContainer(widget.data), ), - onTap: () {}, ), ); } @@ -88,7 +51,7 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { int _currentIndex = 0; TextEditingController _controller = TextEditingController(); - bool _submitable = false; + bool _submitable = true; bool _inputable = false; @override @@ -96,42 +59,92 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { _bloc = BlocProvider.of(context); if (widget.data.containsKey('skip_identifier')) { _bloc.loadData(widget.data['skip_identifier']); + _bloc.loadWithdrawData(); + _bloc.getAlipayStatus(); } super.initState(); } + reload() { + _bloc.loadData(widget.data['skip_identifier']); + _bloc.loadWithdrawData(); + _bloc.getAlipayStatus(); + } + @override Widget build(BuildContext context) { - return SingleChildScrollView( - child: StreamBuilder( - stream: _bloc.outData, - builder: (BuildContext context, AsyncSnapshot snapshot) { - WithdrawModel model = snapshot.data; - if (model == null) { - return WithdrawPageSketelon(); - } + return StreamBuilder( + stream: _bloc.outData, + builder: (context, asny) { + WithdrawModel model = asny.data; + if (model == null) { + return WithdrawPageSketelon(); + } + + return Scaffold( + backgroundColor: HexColor.fromHex('#FFFFFFFF'), + appBar: _createNav(model), + body: SafeArea( + child: SingleChildScrollView( + child: Container( + margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 8), + child: Column( + children: [ + _createHeader(model), + _createVerify(model), + _createPrice(model), + _createInput(model), + _createSubmit(model), + _createDesc(model), + ], + ), + )), + ), + ); + }); + } - return Container( - margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 8), - child: Column( - children: [ - _createHeader(model), - _createVerify(model), - _createPrice(model), - _createInput(model), - _createSubmit(model), - _createDesc(model), - ], + // 导航栏 + Widget _createNav(WithdrawModel model) { + return CupertinoNavigationBar( + leading: Navigator.canPop(context) + ? GestureDetector( + child: Container( + padding: EdgeInsets.zero, + child: Icon( + Icons.arrow_back_ios, + size: 20, + ), ), - ); - }), - // child: Column( - // children: [], - // ), + onTap: () { + if (Navigator.canPop(context)) { + Navigator.pop(context); + } + }, + ) + : Container(), + middle: Text( + model.appBarName, + style: TextStyle( + fontSize: 15, + color: HexColor.fromHex(model.appBarNameColor), + ), + ), + trailing: GestureDetector( + child: Text( + model.appBarRightText, + style: TextStyle(fontSize: 13, color: Color(0xff333333)), + ), + onTap: () { + RouterUtil.route( + model.detailSkipModel, model.detailSkipModel.toJson(), context); + }, + ), ); } Widget _createHeader(WithdrawModel model) { + var data = _bloc.withdrawDataModel; return Container( width: double.infinity, height: 97, @@ -152,16 +165,16 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - '¥0.03', + data?.finValue ?? "", style: TextStyle( color: Colors.white, fontSize: 30, ), ), Text( - '可提现总余额', + model?.availableCashOutText ?? "", style: TextStyle( - color: Colors.white, + color: HexColor.fromHex(model.availableCashOutTextColor), fontSize: 14, ), ), @@ -174,28 +187,57 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { } Widget _createVerify(WithdrawModel model) { + var data = _bloc.withdrawDataModel; + var param = { + 'status': _bloc.aliPayModel, + Constants.SkipIdentifierName: model.gotoAliPay.skipIdentifier, + 'data': _bloc.aliPayModel + }; return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { Logger.debug('绑定支付宝'); + RouterUtil.route( + model.gotoAliPay, + { + 'status': _bloc.aliPayModel, + Constants.SkipIdentifierName: model.gotoAliPay.skipIdentifier, + 'data': param + }, + context) + .then((value) { + reload(); + }); }, child: Container( margin: EdgeInsets.only(top: 8, bottom: 8), child: Row( children: [ CachedNetworkImage( - imageUrl: model.unbindAlipayImg, + imageUrl: (data?.alipayUserName == null || + data?.alipayUserName.length == 0) + ? model.unbindAlipayImg + : model.bindAlipayImg, height: 23, ), Expanded( child: Padding( padding: const EdgeInsets.only(left: 8, right: 8), child: Text( - model.unbindAlipayText, + (data?.alipayUserName == null || + data?.alipayUserName.length == 0) + ? model.unbindAlipayText + : data.alipayUserName, style: TextStyle(fontSize: 11, color: Color(0xff999999)), ), ), ), + Text( + (data?.alipayUserName == null || data?.alipayUserName.length == 0) + ? model.unbindAlipayGotoText + : model.bindAlipayGotoText, + style: TextStyle(fontSize: 11, color: Color(0xff999999)), + ), Icon( Icons.arrow_forward_ios, size: 12, @@ -208,6 +250,10 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { } Widget _createPrice(WithdrawModel model) { + if (_controller.text.length == 0 && + model.cashOutDashbordItems[_currentIndex].name != "自定义") { + _controller.text = model.cashOutDashbordItems[0].value; + } return GridView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), @@ -301,6 +347,8 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { onChanged: (value) { _checkSubmit(value); }, + placeholderStyle: + TextStyle(fontSize: 26, color: Colors.grey[400]), ), ), Container( @@ -315,22 +363,31 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { } Widget _createSubmit(WithdrawModel model) { - return Container( - height: 50, - decoration: BoxDecoration( - color: _submitable - ? HexColor.fromHex(model.cashOutBtnTextAvailableBgColor ?? '') - : HexColor.fromHex(model.cashOutBtnTextUnavailableBgColor ?? ''), - borderRadius: BorderRadius.circular(7.5), - ), - child: Center( - child: Text( - model.cashOutBtnText ?? '', - style: TextStyle( - fontSize: 15, - color: _submitable - ? HexColor.fromHex(model.cashOutBtnTextAvailableColor ?? '') - : HexColor.fromHex(model.cashOutBtnTextUnavailableColor ?? ''), + return GestureDetector( + onTap: () { + ///提现 + if (_submitable) { + _bloc.submitApply(context, _controller.text); + } + }, + child: Container( + height: 50, + decoration: BoxDecoration( + color: _submitable + ? HexColor.fromHex(model.cashOutBtnTextAvailableBgColor ?? '') + : HexColor.fromHex(model.cashOutBtnTextUnavailableBgColor ?? ''), + borderRadius: BorderRadius.circular(7.5), + ), + child: Center( + child: Text( + model.cashOutBtnText ?? '', + style: TextStyle( + fontSize: 15, + color: _submitable + ? HexColor.fromHex(model.cashOutBtnTextAvailableColor ?? '') + : HexColor.fromHex( + model.cashOutBtnTextUnavailableColor ?? ''), + ), ), ), ), @@ -365,7 +422,18 @@ class _WithdrawContainerState extends State<_WithdrawContainer> { } void _checkSubmit(String value) { - _submitable = value.length > 0; + try { + if (num.tryParse(value) != null && + num.tryParse(value) < + num.tryParse(_bloc.withdrawDataModel.finValue)) { + _submitable = true; + } else { + _submitable = false; + } + } catch (e, s) { + print(e); + print(s); + } setState(() {}); } } diff --git a/lib/register.dart b/lib/register.dart index e7db5de..7ca9d0b 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -158,7 +158,7 @@ class BaseWidgetRegister { /// 消息设置 PageFactory.regist('pub.flutter.message_settings', (model) => MessageSettingsPage(model)); /// 钱包明细 - PageFactory.regist('pub.flutter.my_bil', (model) => BilDetailPage(model)); + PageFactory.regist('pub.flutter.my_wallet_detail', (model) => BilDetailPage(model)); } // 注册控件