withdraw_page.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/pay_way_bean_entity.dart';
  3. import 'package:bbyyy/beans/user_bean_entity.dart';
  4. import 'package:bbyyy/beans/withdraw_pricing_bean_entity.dart';
  5. import 'package:bbyyy/https/MyDio.dart';
  6. import 'package:bbyyy/my_tools/dims.dart';
  7. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  8. import 'package:bbyyy/my_tools/event_bus.dart';
  9. import 'package:bbyyy/my_tools/my_colors.dart';
  10. import 'package:bbyyy/my_tools/my_cookie.dart';
  11. import 'package:bbyyy/my_tools/my_tools.dart';
  12. import 'package:bbyyy/my_tools/my_views.dart';
  13. import 'package:bbyyy/paegs/mine_page/bind_alipay_page/bind_alipay_page.dart';
  14. import 'package:bbyyy/pay/pay_tools.dart';
  15. import 'package:flustars/flustars.dart';
  16. import 'package:flutter/cupertino.dart';
  17. import 'package:flutter/gestures.dart';
  18. import 'package:flutter/material.dart';
  19. import 'package:flutter/services.dart';
  20. class WithdrawPage extends StatefulWidget {
  21. @override
  22. _WithdrawPageState createState() => _WithdrawPageState();
  23. }
  24. class _WithdrawPageState extends State<WithdrawPage> {
  25. TextEditingController _controller = TextEditingController();
  26. int withdrawalStatus = 0; //0--未提现 1--提现中 2--提现完成
  27. double percentFee = 0.0;
  28. double extraFee = 0.0;
  29. double threshold = 0.0;
  30. double maxPerHand = 0.0;
  31. double minPerHand = 0.0;
  32. int withdrawalPath = -1; // 1---支付宝 2---微信
  33. List<PayWayBeanData> payWays;
  34. bool showAlipay = false;
  35. bool showWeChat = false;
  36. @override
  37. void initState() {
  38. // TODO: implement initState
  39. super.initState();
  40. queryPersonalInformation();
  41. queryWithdrawalInstructions();
  42. Future.delayed(Duration.zero, () {
  43. checkPaymentMethod((response, hasError) {
  44. if (!hasError) {
  45. PayWayBeanEntity entity =
  46. PayWayBeanEntity().fromJson(json.decode(response.toString()));
  47. payWays = entity.data;
  48. showWeChat = payWays[payWays.indexWhere((element) => element.way==2)].withdraw;
  49. showAlipay = payWays[payWays.indexWhere((element) => element.way==1)].withdraw;
  50. if (MyCookie().userBean.wxOpenid.isNotEmpty&&payWays[payWays.indexWhere((element) => element.way==2)].withdraw) {
  51. withdrawalPath = 2;
  52. } else if (MyCookie().userBean.aliPayAccount.isNotEmpty&&payWays[payWays.indexWhere((element) => element.way==1)].withdraw) {
  53. withdrawalPath = 1;
  54. }
  55. setState(() {
  56. });
  57. }
  58. }, (e) {});
  59. });
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. return GestureDetector(
  64. onTap: () {
  65. MyTools().hideKeyboard(context);
  66. },
  67. behavior: HitTestBehavior.translucent,
  68. child: Scaffold(
  69. backgroundColor: MyColors.cF7F7F7,
  70. body: Column(
  71. children: [
  72. MyViews().myAppBar('申请提现', context, [
  73. GestureDetector(
  74. onTap: () {
  75. MyTools().toPage(context, BindAlipayPage(), (then) {
  76. setState(() {});
  77. });
  78. },
  79. behavior: HitTestBehavior.translucent,
  80. child: Container(
  81. padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  82. child: Text(
  83. '修改绑定',
  84. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  85. ),
  86. ),
  87. ),
  88. ]),
  89. Expanded(
  90. child: SingleChildScrollView(
  91. child: Column(
  92. children: [
  93. if(showAlipay)GestureDetector(
  94. onTap: () {
  95. if(!payWays[payWays.indexWhere((element) => element.way==1)].withdraw){
  96. showToast('支付宝提现暂时维护中');
  97. return;
  98. }
  99. if (MyCookie().userBean.aliPayAccount.isEmpty) {
  100. showToast('未绑定支付宝');
  101. } else {
  102. setState(() {
  103. withdrawalPath = 1;
  104. });
  105. }
  106. },
  107. behavior: HitTestBehavior.translucent,
  108. child: Container(
  109. margin: EdgeInsets.fromLTRB(17, 24, 17, 0),
  110. child: Row(
  111. children: [
  112. Container(
  113. decoration: BoxDecoration(
  114. color: withdrawalPath == 1
  115. ? MyColors.cFF4233
  116. : MyColors.cD0D0D0,
  117. borderRadius: BorderRadius.circular(9)),
  118. height: 18,
  119. width: 18,
  120. child: Icon(
  121. Icons.check,
  122. color: Colors.white,
  123. size: 14,
  124. ),
  125. alignment: Alignment.center,
  126. margin: EdgeInsets.only(right: 10),
  127. ),
  128. MyViews().myText(
  129. '提现到支付宝:${MyCookie().userBean.aliPayAccount.isEmpty ? '未绑定支付宝' : MyCookie().userBean.aliPayAccount}',
  130. MyColors.c666666,
  131. 15),
  132. ],
  133. ),
  134. ),
  135. ),
  136. if(showWeChat)GestureDetector(
  137. onTap: () {
  138. if(!payWays[payWays.indexWhere((element) => element.way==2)].withdraw){
  139. showToast('微信提现暂时维护中');
  140. return;
  141. }
  142. if (MyCookie().userBean.wxOpenid.isEmpty) {
  143. showToast('未绑定微信');
  144. } else {
  145. setState(() {
  146. withdrawalPath = 2;
  147. });
  148. }
  149. },
  150. behavior: HitTestBehavior.translucent,
  151. child: Container(
  152. margin: EdgeInsets.fromLTRB(17, 24, 17, 0),
  153. child: Row(
  154. children: [
  155. Container(
  156. decoration: BoxDecoration(
  157. color: withdrawalPath == 2
  158. ? MyColors.cFF4233
  159. : MyColors.cD0D0D0,
  160. borderRadius: BorderRadius.circular(9)),
  161. height: 18,
  162. width: 18,
  163. child: Icon(
  164. Icons.check,
  165. color: Colors.white,
  166. size: 14,
  167. ),
  168. alignment: Alignment.center,
  169. margin: EdgeInsets.only(right: 10),
  170. ),
  171. MyViews().myText('提现到微信:', MyColors.c666666, 15),
  172. MyCookie().userBean.wxOpenid.isEmpty
  173. ? MyViews()
  174. .myText('未绑定微信', MyColors.c666666, 15)
  175. : Row(
  176. children: [
  177. Container(
  178. margin: EdgeInsets.only(right: 10),
  179. child: ClipRRect(
  180. borderRadius:
  181. BorderRadius.circular(12),
  182. child: MyViews().netImg(
  183. MyCookie().userBean.wxPicture,
  184. 24,
  185. 24),
  186. ),
  187. ),
  188. MyViews().myText(
  189. MyCookie().userBean.wxName,
  190. MyColors.c666666,
  191. 15)
  192. ],
  193. )
  194. ],
  195. ),
  196. ),
  197. ),
  198. Container(
  199. decoration: BoxDecoration(
  200. color: Colors.white,
  201. borderRadius: BorderRadius.circular(4),
  202. ),
  203. margin:
  204. EdgeInsets.symmetric(horizontal: 17, vertical: 14),
  205. padding:
  206. EdgeInsets.symmetric(horizontal: 20, vertical: 15),
  207. child: Column(
  208. children: [
  209. MyViews().myText('提现金额', MyColors.c333333, 16),
  210. Container(
  211. margin: EdgeInsets.only(top: 15),
  212. child: Row(
  213. children: [
  214. Text(
  215. '¥',
  216. style: TextStyle(
  217. color: MyColors.c333333, fontSize: 30),
  218. ),
  219. Expanded(
  220. child: TextField(
  221. inputFormatters: [
  222. FilteringTextInputFormatter.allow(
  223. RegExp("[0-9.]")),
  224. ],
  225. controller: _controller,
  226. cursorColor: MyColors.cFF4233,
  227. cursorWidth: 1.0,
  228. decoration: InputDecoration(
  229. border: InputBorder.none,
  230. disabledBorder: InputBorder.none,
  231. enabledBorder: InputBorder.none,
  232. focusedBorder: InputBorder.none,
  233. hintText: '请输入金额',
  234. hintStyle: TextStyle(
  235. color: MyColors.c999999,
  236. fontSize: 16),
  237. isDense: true,
  238. contentPadding:
  239. const EdgeInsets.fromLTRB(
  240. 14, 4.5, 8, 4.5)),
  241. maxLines: 1,
  242. style: TextStyle(
  243. color: MyColors.c333333,
  244. fontSize: 30,
  245. fontWeight: FontWeight.bold,
  246. height: 1.3,
  247. letterSpacing: 0.2),
  248. keyboardType: TextInputType.number,
  249. onChanged: (t) {
  250. try {
  251. double amount = double.parse(t);
  252. if (amount > 0) {
  253. withdrawalStatus = 0;
  254. setState(() {});
  255. }
  256. } catch (e) {
  257. withdrawalStatus = 1;
  258. }
  259. setState(() {});
  260. },
  261. ),
  262. )
  263. ],
  264. ),
  265. ),
  266. Container(
  267. margin: EdgeInsets.only(top: 4, bottom: 15),
  268. color: MyColors.cE7E7E7,
  269. height: 0.5,
  270. ),
  271. RichText(
  272. text: TextSpan(
  273. text: '当前零钱余额',
  274. style: TextStyle(
  275. color: MyColors.c999999, fontSize: 15),
  276. children: [
  277. TextSpan(
  278. text: '${MyCookie().userBean.balance}',
  279. style: TextStyle(
  280. color: MyColors.cFF4233, fontSize: 15),
  281. ),
  282. TextSpan(
  283. text: '元,',
  284. style: TextStyle(
  285. color: MyColors.c999999, fontSize: 15),
  286. ),
  287. TextSpan(
  288. text: '全部提现',
  289. style: TextStyle(
  290. color: MyColors.cFF4233,
  291. fontSize: 15),
  292. recognizer: TapGestureRecognizer()
  293. ..onTap = () {
  294. _controller.text = MyCookie()
  295. .userBean
  296. .balance
  297. .toString();
  298. setState(() {});
  299. }),
  300. ]),
  301. ),
  302. GestureDetector(
  303. onTap: () {
  304. if(withdrawalPath==-1){
  305. showToast('请选择提现方式');
  306. return;
  307. }
  308. if (withdrawalStatus == 0) {
  309. withdrawalStatus = 1;
  310. withdraw();
  311. } else {}
  312. },
  313. behavior: HitTestBehavior.translucent,
  314. child: Container(
  315. decoration: BoxDecoration(
  316. color: withdrawalStatus == 0
  317. ? MyColors.cFF4233
  318. : MyColors.cEFEFEF,
  319. borderRadius: BorderRadius.circular(20)),
  320. child: MyViews().myText('提现', Colors.white, 14),
  321. alignment: Alignment.center,
  322. height: 40,
  323. margin: EdgeInsets.only(top: 20, bottom: 15),
  324. ),
  325. ),
  326. Container(
  327. margin: EdgeInsets.only(bottom: 8),
  328. child: RichText(
  329. text: TextSpan(
  330. text: '您的提现手续费为:',
  331. style: TextStyle(
  332. color: MyColors.c999999, fontSize: 14),
  333. children: [
  334. TextSpan(
  335. text:
  336. '${NumUtil.multiply(percentFee, 100)}%${extraFee == 0 ? '' : '+$extraFee'}',
  337. style: TextStyle(
  338. color: MyColors.cE2A62D,
  339. fontSize: 14),
  340. ),
  341. // TextSpan(
  342. // text: '元',
  343. // style: TextStyle(
  344. // color: MyColors.c999999,
  345. // fontSize: 14),
  346. // ),
  347. ]),
  348. ),
  349. ),
  350. Visibility(
  351. visible: maxPerHand != 0,
  352. child: Container(
  353. margin: EdgeInsets.only(bottom: 8),
  354. child: RichText(
  355. text: TextSpan(
  356. text: '单笔最高限额:',
  357. style: TextStyle(
  358. color: MyColors.c999999, fontSize: 14),
  359. children: [
  360. TextSpan(
  361. text: '$maxPerHand',
  362. style: TextStyle(
  363. color: MyColors.cE2A62D,
  364. fontSize: 14),
  365. ),
  366. TextSpan(
  367. text: '元',
  368. style: TextStyle(
  369. color: MyColors.c999999,
  370. fontSize: 14),
  371. ),
  372. ]),
  373. ),
  374. ),
  375. ),
  376. Visibility(
  377. visible: minPerHand != 0,
  378. child: Container(
  379. margin: EdgeInsets.only(bottom: 8),
  380. child: RichText(
  381. text: TextSpan(
  382. text: '单笔最低限额:',
  383. style: TextStyle(
  384. color: MyColors.c999999, fontSize: 14),
  385. children: [
  386. TextSpan(
  387. text: '$minPerHand',
  388. style: TextStyle(
  389. color: MyColors.cE2A62D,
  390. fontSize: 14),
  391. ),
  392. TextSpan(
  393. text: '元',
  394. style: TextStyle(
  395. color: MyColors.c999999,
  396. fontSize: 14),
  397. ),
  398. ]),
  399. ),
  400. ),
  401. ),
  402. Visibility(
  403. visible: threshold != 0,
  404. child: RichText(
  405. text: TextSpan(
  406. text: '当日免手续费提现额度:',
  407. style: TextStyle(
  408. color: MyColors.c999999, fontSize: 14),
  409. children: [
  410. TextSpan(
  411. text: '$threshold',
  412. style: TextStyle(
  413. color: MyColors.cE2A62D,
  414. fontSize: 14),
  415. ),
  416. TextSpan(
  417. text: '元',
  418. style: TextStyle(
  419. color: MyColors.c999999,
  420. fontSize: 14),
  421. ),
  422. ]),
  423. ),
  424. ),
  425. ],
  426. crossAxisAlignment: CrossAxisAlignment.start,
  427. ),
  428. )
  429. ],
  430. ),
  431. ),
  432. ),
  433. ],
  434. ),
  435. ),
  436. );
  437. }
  438. void withdraw() {
  439. try {
  440. double amount = double.parse(_controller.text.toString());
  441. if (amount <= MyCookie().userBean.balance && amount >= minPerHand) {
  442. var j = {
  443. 'user_uid': MyCookie().getUID(),
  444. 'way':withdrawalPath,
  445. 'amount': amount
  446. };
  447. if(withdrawalPath==2){
  448. j['wx_openid'] = MyCookie().userBean.wxOpenid;
  449. }
  450. print(j.toString());
  451. MyDio().post('/pay/withdraw',j , (response, hasError) {
  452. if (!hasError) {
  453. showToast('提现成功');
  454. withdrawalStatus = 2;
  455. queryPersonalInformation();
  456. } else {
  457. setState(() {
  458. withdrawalStatus = 0;
  459. });
  460. }
  461. }, (error) {
  462. setState(() {
  463. withdrawalStatus = 0;
  464. });
  465. });
  466. } else if (amount > MyCookie().userBean.balance) {
  467. setState(() {
  468. withdrawalStatus = 0;
  469. });
  470. showSimpleDialog('您的余额不足。', context, () {
  471. Navigator.pop(context);
  472. });
  473. } else {
  474. setState(() {
  475. withdrawalStatus = 0;
  476. });
  477. showSimpleDialog('提现失败:提现金额不能低于$minPerHand元。', context, () {
  478. Navigator.pop(context);
  479. });
  480. }
  481. } catch (e) {
  482. setState(() {
  483. withdrawalStatus = 0;
  484. EasyLoading.dismiss();
  485. });
  486. showSimpleDialog('输入内容有误,请重新输入', context, () {
  487. Navigator.pop(context);
  488. });
  489. }
  490. }
  491. void queryPersonalInformation() {
  492. MyDio().query({
  493. "key": "user",
  494. "filters": {
  495. "conditions": ["uid == ${MyCookie().getUID()}"]
  496. },
  497. "dims": userDims,
  498. "paging": [1, 20]
  499. }, (response, hasError) {
  500. if (!hasError) {
  501. UserBeanEntity entity =
  502. UserBeanEntity().fromJson(json.decode(response.data.toString()));
  503. MyCookie().userBean = entity.data.data[0];
  504. EventBus().emit('userChange');
  505. setState(() {});
  506. if (withdrawalStatus == 2) {
  507. Navigator.pop(context);
  508. }
  509. }
  510. }, (error) {});
  511. }
  512. void queryWithdrawalInstructions() {
  513. MyDio().query({
  514. "key": "withdraw_pricing",
  515. "filters": {},
  516. "dims": withdrawPricingDims,
  517. "paging": [1, 20]
  518. }, (response, hasError) {
  519. if (!hasError) {
  520. WithdrawPricingBeanEntity entity = WithdrawPricingBeanEntity()
  521. .fromJson(json.decode(response.data.toString()));
  522. if (entity.data.data.isNotEmpty) {
  523. percentFee = entity.data.data[0].percentFee;
  524. extraFee = entity.data.data[0].extraFee;
  525. threshold = entity.data.data[0].threshold;
  526. maxPerHand = entity.data.data[0].maxPerHand;
  527. minPerHand = entity.data.data[0].minPerHand;
  528. }
  529. }
  530. setState(() {});
  531. }, (error) {});
  532. }
  533. }