YSWithdrawal.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:ysairplane2/tools/YSNetWorking.dart';
  5. import 'package:ysairplane2/tools/YSTools.dart';
  6. class YSWithdrawal extends StatefulWidget {
  7. const YSWithdrawal({Key key}) : super(key: key);
  8. @override
  9. _YSWithdrawalState createState() => _YSWithdrawalState();
  10. }
  11. class _YSWithdrawalState extends State<YSWithdrawal> {
  12. //wexinLogo aliLogo
  13. List _typeArray = [{'img':'wexinLogo','title':''},{'img':'aliLogo','title':''}];
  14. int _selectedIndex = 0;
  15. double _balance = 0.00;
  16. TextEditingController _amountField = TextEditingController();
  17. @override
  18. void dispose() {
  19. _amountField.dispose();
  20. super.dispose();
  21. }
  22. @override
  23. void initState() {
  24. Future.delayed(Duration(seconds: 0)).then((value){
  25. _getWithdrawalData();
  26. });
  27. super.initState();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. appBar: CupertinoNavigationBar(
  33. leading: GestureDetector(
  34. onTap: (){Navigator.pop(context);},
  35. child: Icon(Icons.arrow_back_ios,size: 20,color: Color(0xFF000000),),
  36. ),
  37. middle: Text('提现',style: TextStyle(color: Color(0xFF000000),fontSize: 16,
  38. decoration: TextDecoration.none,fontWeight: FontWeight.w600),textAlign: TextAlign.center,),
  39. backgroundColor: Color(0xFFF5F6F8),
  40. border: Border.all(color: Colors.transparent,width: hsp(1)),
  41. ),
  42. backgroundColor: Color(0xFFF5F6F8),
  43. body: SingleChildScrollView(
  44. child: Container(
  45. width: MediaQuery.of(context).size.width,
  46. child: Column(
  47. children: [
  48. Container(
  49. height: hsp(150),
  50. padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
  51. child: GestureDetector(
  52. onTap: (){
  53. FocusScope.of(context).unfocus();
  54. int selectedIndex = _selectedIndex;
  55. showModalBottomSheet(
  56. context: context,
  57. builder: (context){
  58. return Container(
  59. height: hsp(500),
  60. child: Column(
  61. children: [
  62. Container(
  63. height: hsp(99),
  64. child: Row(
  65. children: [
  66. Container(width: hsp(40),),
  67. Text('选择提现账号',style: TextStyle(fontSize: zsp(30),color: Colors.black),),
  68. GestureDetector(
  69. onTap: (){Navigator.pop(context);},
  70. child: Icon(Icons.close,size: hsp(40),color: Colors.black,),
  71. )
  72. ],
  73. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  74. ),
  75. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  76. ),
  77. Divider(height: hsp(1),thickness: hsp(1),color: Color(0xFFF5F6F8),),
  78. StatefulBuilder(
  79. builder: (context,chooseSet){
  80. return Container(
  81. height: hsp(300),
  82. child: ListView.separated(
  83. padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
  84. itemBuilder: (context,index){
  85. Map item = _typeArray[index];
  86. return GestureDetector(
  87. onTap: (){
  88. chooseSet(() {
  89. selectedIndex = index;
  90. });
  91. },
  92. behavior: HitTestBehavior.opaque,
  93. child: Container(
  94. height: hsp(100),
  95. child: Row(
  96. children: [
  97. Image.asset('lib/images/${item['img']}.png',height: hsp(40),width: hsp(40),),
  98. Container(
  99. width: MediaQuery.of(context).size.width-hsp(140),
  100. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  101. child: Text('${item['title']}',style: TextStyle(fontSize: zsp(30),color: Colors.black),),
  102. ),
  103. Icon(selectedIndex==index?Icons.check_circle:Icons.radio_button_unchecked,
  104. size: hsp(40),color: Color(selectedIndex==index?0xFF007AFF:0xFFCCCCCC),),
  105. ],
  106. ),
  107. ),
  108. );
  109. },
  110. separatorBuilder: (context,index){
  111. return Divider(height: hsp(1),thickness: hsp(1),color: Color(0xFFF5F6F8),);
  112. },
  113. itemCount: _typeArray.length,
  114. ),
  115. );
  116. },
  117. ),
  118. GestureDetector(
  119. child: Container(
  120. height: hsp(80),
  121. margin: EdgeInsets.only(left: hsp(30),right: hsp(30)),
  122. decoration: BoxDecoration(
  123. color: Color(0xFF007AFF),
  124. borderRadius: BorderRadius.all(Radius.circular(5))
  125. ),
  126. alignment: Alignment.center,
  127. child: Text('确认',style: TextStyle(fontSize: zsp(30),color: Colors.white),),
  128. ),
  129. onTap: (){
  130. Navigator.pop(context);
  131. _selectedIndex = selectedIndex;
  132. setState(() {});
  133. },
  134. )
  135. ],
  136. ),
  137. );
  138. }
  139. );
  140. },
  141. child: Row(
  142. children: [
  143. Text('到账账号:',style: TextStyle(fontSize: zsp(30),color: Colors.black),),
  144. Image.asset('lib/images/${_typeArray[_selectedIndex]['img']}.png',height: hsp(40),width: hsp(40),),
  145. ConstrainedBox(
  146. constraints: BoxConstraints(
  147. maxWidth: MediaQuery.of(context).size.width/2
  148. ),
  149. child: Text(' ${_typeArray[_selectedIndex]['title']} ',style: TextStyle(fontSize: zsp(30),color: Colors.black),maxLines: 1,),
  150. ),
  151. Icon(Icons.keyboard_arrow_down,size: hsp(40),color: Color(0xFFCCCCCC),)
  152. ],
  153. ),
  154. ),
  155. ),
  156. Container(
  157. width: MediaQuery.of(context).size.width,
  158. padding: EdgeInsets.all(hsp(30)),
  159. decoration: BoxDecoration(
  160. color: Colors.white,
  161. borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
  162. ),
  163. child: Column(
  164. crossAxisAlignment: CrossAxisAlignment.start,
  165. children: [
  166. Text('提现金额',style: TextStyle(fontSize: zsp(30),color: Colors.black),),
  167. Container(
  168. margin: EdgeInsets.only(top: hsp(30),bottom: hsp(30)),
  169. height: hsp(100),
  170. child: CupertinoTextField(
  171. placeholder: '',
  172. decoration: BoxDecoration(),
  173. style: TextStyle(fontSize: zsp(60),color: Colors.black,fontWeight: FontWeight.bold),
  174. prefix: Text('¥',style: TextStyle(fontSize: zsp(40),color: Colors.black,fontWeight: FontWeight.bold),),
  175. keyboardType: TextInputType.number,
  176. inputFormatters: [NumberFormat()],
  177. controller: _amountField,
  178. ),
  179. ),
  180. RichText(
  181. text: TextSpan(
  182. text: '可提现金额:',
  183. style: TextStyle(fontSize: zsp(22),color: Color(0xFF999999)),
  184. children: [
  185. TextSpan(
  186. text: '¥$_balance',
  187. style: TextStyle(color: Colors.black)
  188. )
  189. ]
  190. ),
  191. ),
  192. GestureDetector(
  193. onTap: (){
  194. _postWithdrawalData();
  195. },
  196. child: Container(
  197. height: hsp(88),
  198. margin: EdgeInsets.only(left: hsp(40),right: hsp(40),top: hsp(60),bottom: hsp(30)),
  199. decoration: BoxDecoration(
  200. color: Color(0xFF007AFF),
  201. borderRadius: BorderRadius.all(Radius.circular(5))
  202. ),
  203. alignment: Alignment.center,
  204. child: Text('提现',style: TextStyle(fontSize: zsp(32),color: Colors.white),),
  205. ),
  206. )
  207. ],
  208. ),
  209. )
  210. ],
  211. ),
  212. ),
  213. ),
  214. );
  215. }
  216. _getWithdrawalData() async{
  217. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/withDrawInfo',parameter: {},isLoading: false,isToken: true);
  218. if(dict!=null){
  219. _typeArray[0]['title'] = dict['data']['paymentAccountWx'];
  220. _typeArray[1]['title'] = dict['data']['paymentAccountAlipay'];
  221. _balance = dict['data']['balance']*1.0;
  222. setState(() {});
  223. }
  224. }
  225. _postWithdrawalData() async{
  226. if(_amountField.text.isEmpty){
  227. ysFlutterToast(context, '请输入提现金额');
  228. return;
  229. }
  230. double amount = double.parse(_amountField.text);
  231. if(amount>_balance){
  232. ysFlutterToast(context, '提现金额不能大于余额');
  233. return;
  234. }
  235. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/commitWithDraw',
  236. parameter: {'paymentAccountWay':_selectedIndex==0?2:3,'price':amount},isLoading: true,isToken: true);
  237. if(dict!=null){
  238. ysFlutterToast(context, '已提交提现申请');
  239. Navigator.of(context).pop('');
  240. }
  241. }
  242. }