withdraw_page.dart 18 KB

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