基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

493 lines
15 KiB

  1. import 'package:event_bus/event_bus.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:zhiying_base_widget/pages/bil_detail_page/bil_detail_page.dart';
  6. import 'package:zhiying_base_widget/pages/withdraw_page/bloc/withdraw_bloc.dart';
  7. import 'package:zhiying_base_widget/pages/withdraw_page/models/withdraw_model.dart';
  8. import 'package:zhiying_base_widget/pages/withdraw_page/withdraw_page_sk.dart';
  9. import 'package:zhiying_base_widget/utils/contants.dart';
  10. import 'package:zhiying_comm/util/base_bloc.dart';
  11. import 'package:zhiying_comm/util/event_util/event_util.dart';
  12. import 'package:zhiying_comm/util/event_util/login_success_event.dart';
  13. import 'package:zhiying_comm/zhiying_comm.dart';
  14. /*提现页面*/
  15. class WithdrawPage extends StatefulWidget {
  16. final Map<String, dynamic> data;
  17. const WithdrawPage(this.data, {Key key}) : super(key: key);
  18. @override
  19. _WithdrawPageState createState() => _WithdrawPageState();
  20. }
  21. class _WithdrawPageState extends State<WithdrawPage> {
  22. @override
  23. Widget build(BuildContext context) {
  24. return GestureDetector(
  25. onTap: () {
  26. FocusScope.of(context).requestFocus(FocusNode());
  27. },
  28. child: Container(
  29. color: Colors.white,
  30. child: BlocProvider<WithdrawBloc>(
  31. bloc: WithdrawBloc(),
  32. child: _WithdrawContainer(widget.data),
  33. ),
  34. ),
  35. );
  36. }
  37. }
  38. class _WithdrawContainer extends StatefulWidget {
  39. final Map<String, dynamic> data;
  40. const _WithdrawContainer(this.data, {Key key}) : super(key: key);
  41. @override
  42. _WithdrawContainerState createState() => _WithdrawContainerState();
  43. }
  44. class _WithdrawContainerState extends State<_WithdrawContainer> {
  45. WithdrawBloc _bloc;
  46. int _currentIndex = 0;
  47. TextEditingController _controller = TextEditingController();
  48. bool _submitable = false;
  49. bool _inputable = false;
  50. @override
  51. void initState() {
  52. _bloc = BlocProvider.of<WithdrawBloc>(context);
  53. if (widget.data.containsKey('skip_identifier')) {
  54. _bloc.loadData(widget.data['skip_identifier']);
  55. _bloc.loadWithdrawData();
  56. _bloc.getAlipayStatus();
  57. }
  58. EventUtil.instance.on<LoginSuccessEvent>().listen((event) {
  59. reload();
  60. });
  61. super.initState();
  62. }
  63. reload() {
  64. _bloc.loadData(widget.data['skip_identifier']);
  65. _bloc.loadWithdrawData();
  66. _bloc.getAlipayStatus();
  67. }
  68. @override
  69. Widget build(BuildContext context) {
  70. return StreamBuilder(
  71. stream: _bloc.outData,
  72. builder: (context, asny) {
  73. WithdrawModel model = asny.data;
  74. if (model == null) {
  75. return WithdrawPageSketelon();
  76. }
  77. return Scaffold(
  78. backgroundColor: HexColor.fromHex('#FFFFFFFF'),
  79. appBar: _createNav(model),
  80. body: SafeArea(
  81. child: SingleChildScrollView(
  82. child: Container(
  83. margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 8),
  84. child: Column(
  85. children: <Widget>[
  86. _createHeader(model),
  87. _createVerify(model),
  88. _createPrice(model),
  89. _createInput(model),
  90. _createSubmit(model),
  91. _createDesc(model),
  92. ],
  93. ),
  94. )),
  95. ),
  96. );
  97. });
  98. }
  99. // 导航栏
  100. Widget _createNav(WithdrawModel model) {
  101. return AppBar(
  102. elevation: 1,
  103. brightness: Brightness.light,
  104. backgroundColor: HexColor.fromHex(model?.appBarBgColor??""),
  105. leading: Navigator.canPop(context)
  106. ? GestureDetector(
  107. child: Container(
  108. padding: EdgeInsets.zero,
  109. child: Icon(
  110. Icons.arrow_back_ios,
  111. size: 20,
  112. ),
  113. ),
  114. onTap: () {
  115. if (Navigator.canPop(context)) {
  116. Navigator.pop(context);
  117. }
  118. },
  119. )
  120. : Container(),
  121. centerTitle: true,
  122. title: Text(
  123. model.appBarName,
  124. style: TextStyle(
  125. fontSize: 15,
  126. color: HexColor.fromHex(model.appBarNameColor),
  127. ),
  128. ),
  129. actions:<Widget>[ GestureDetector(
  130. child: Center(
  131. child: Padding(
  132. padding: EdgeInsets.only(right: 16),
  133. child: Text(
  134. model.appBarRightText,
  135. style: TextStyle(fontSize: 13, color: HexColor.fromHex(model?.appBarNameColor??"")),
  136. ),
  137. ),
  138. ),
  139. onTap: () {
  140. RouterUtil.route(
  141. model.detailSkipModel, model.detailSkipModel.toJson(), context);
  142. },
  143. )],
  144. );
  145. }
  146. Widget _createHeader(WithdrawModel model) {
  147. var data = _bloc.withdrawDataModel;
  148. return Container(
  149. width: double.infinity,
  150. height: 97,
  151. decoration: BoxDecoration(
  152. color: Colors.white, borderRadius: BorderRadius.circular(10)),
  153. child: Stack(
  154. children: <Widget>[
  155. Container(
  156. width: double.infinity,
  157. height: double.infinity,
  158. child: CachedNetworkImage(
  159. imageUrl: model.availableCashOutBgImg ?? '',
  160. fit: BoxFit.fill,
  161. ),
  162. ),
  163. Center(
  164. child: Column(
  165. mainAxisAlignment: MainAxisAlignment.center,
  166. children: <Widget>[
  167. Text(
  168. data?.finValue ?? "",
  169. style: TextStyle(
  170. color: Colors.white,
  171. fontSize: 30,
  172. ),
  173. ),
  174. Text(
  175. model?.availableCashOutText ?? "",
  176. style: TextStyle(
  177. color: HexColor.fromHex(model.availableCashOutTextColor),
  178. fontSize: 14,
  179. ),
  180. ),
  181. ],
  182. ),
  183. )
  184. ],
  185. ),
  186. );
  187. }
  188. Widget _createVerify(WithdrawModel model) {
  189. var data = _bloc.withdrawDataModel;
  190. var param = {
  191. 'status': _bloc.aliPayModel,
  192. Constants.SkipIdentifierName: model.gotoAliPay.skipIdentifier,
  193. 'data': _bloc.aliPayModel
  194. };
  195. return GestureDetector(
  196. behavior: HitTestBehavior.opaque,
  197. onTap: () {
  198. Logger.debug('绑定支付宝');
  199. RouterUtil.route(
  200. model.gotoAliPay,
  201. {
  202. 'status': _bloc.aliPayModel,
  203. Constants.SkipIdentifierName: model.gotoAliPay.skipIdentifier,
  204. 'data': param
  205. },
  206. context)
  207. .then((value) {
  208. reload();
  209. });
  210. },
  211. child: Container(
  212. margin: EdgeInsets.only(top: 8, bottom: 8),
  213. child: Row(
  214. children: <Widget>[
  215. CachedNetworkImage(
  216. imageUrl: (data?.alipayUserName == null ||
  217. data?.alipayUserName.length == 0)
  218. ? model.unbindAlipayImg
  219. : model.bindAlipayImg,
  220. height: 23,
  221. ),
  222. Expanded(
  223. child: Padding(
  224. padding: const EdgeInsets.only(left: 8, right: 8),
  225. child: Text(
  226. (data?.alipayUserName == null ||
  227. data?.alipayUserName.length == 0)
  228. ? model.unbindAlipayText
  229. : data.alipayUserName,
  230. style: TextStyle(fontSize: 11, color: Color(0xff999999)),
  231. ),
  232. ),
  233. ),
  234. Text(
  235. (data?.alipayUserName == null || data?.alipayUserName.length == 0)
  236. ? model.unbindAlipayGotoText
  237. : model.bindAlipayGotoText,
  238. style: TextStyle(fontSize: 11, color: Color(0xff999999)),
  239. ),
  240. Icon(
  241. Icons.arrow_forward_ios,
  242. size: 12,
  243. color: Color(0xff999999),
  244. )
  245. ],
  246. ),
  247. ),
  248. );
  249. }
  250. Widget _createPrice(WithdrawModel model) {
  251. if (_controller.text.length == 0 &&
  252. model.cashOutDashbordItems[_currentIndex].name != "自定义") {
  253. _controller.text = model.cashOutDashbordItems[0].value;
  254. }
  255. return GridView.builder(
  256. shrinkWrap: true,
  257. physics: NeverScrollableScrollPhysics(),
  258. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  259. crossAxisCount: 3,
  260. crossAxisSpacing: 10,
  261. mainAxisSpacing: 10,
  262. childAspectRatio: 2.5,
  263. ),
  264. itemCount: model?.cashOutDashbordItems?.length ?? 0,
  265. itemBuilder: (BuildContext context, int index) {
  266. WithdrawDashbordItems item = model.cashOutDashbordItems[index];
  267. return GestureDetector(
  268. onTap: () {
  269. _controller.text = item.value;
  270. _currentIndex = index;
  271. _inputable = item.value == null || item.value == '';
  272. _checkSubmit(item.value);
  273. },
  274. child: Container(
  275. decoration: BoxDecoration(
  276. color: index == _currentIndex
  277. ? HexColor.fromHex(
  278. model.cashOutDashbordItemsSelectedBgColor ?? '')
  279. : HexColor.fromHex(
  280. model.cashOutDashbordItemsUnselectedBgColor ?? ''),
  281. borderRadius: BorderRadius.circular(5),
  282. border: Border.all(
  283. color: index == _currentIndex
  284. ? HexColor.fromHex(
  285. model.cashOutDashbordItemsSelectedColor ?? '')
  286. : HexColor.fromHex('#d2d2d2'),
  287. ),
  288. ),
  289. child: Center(
  290. child: Text(
  291. item.name,
  292. style: TextStyle(
  293. fontSize: 14,
  294. color: index == _currentIndex
  295. ? HexColor.fromHex(
  296. model.cashOutDashbordItemsSelectedColor ?? '')
  297. : HexColor.fromHex(
  298. model.cashOutDashbordItemsUnselectedColor ?? ''),
  299. ),
  300. ),
  301. ),
  302. ),
  303. );
  304. },
  305. );
  306. }
  307. Widget _createInput(WithdrawModel model) {
  308. return Padding(
  309. padding: const EdgeInsets.only(top: 8.0),
  310. child: Column(
  311. crossAxisAlignment: CrossAxisAlignment.start,
  312. mainAxisAlignment: MainAxisAlignment.start,
  313. children: <Widget>[
  314. Text(
  315. '提现金额',
  316. style: TextStyle(
  317. fontWeight: FontWeight.bold,
  318. color: Color(0xff333333),
  319. ),
  320. ),
  321. Container(
  322. width: double.infinity,
  323. height: 50,
  324. child: CupertinoTextField(
  325. placeholder: '输入提现金额',
  326. controller: _controller,
  327. enabled: _inputable,
  328. style: TextStyle(
  329. fontSize: 30,
  330. color: Color(0xff333333),
  331. fontFamily: 'Din-Bold',
  332. package: 'zhiying_comm',
  333. ),
  334. decoration: BoxDecoration(color: Colors.transparent),
  335. keyboardType: TextInputType.numberWithOptions(decimal: true),
  336. textInputAction: TextInputAction.done,
  337. inputFormatters: [
  338. WhitelistingTextInputFormatter(RegExp("[0-9.]")), //只允许输入小数
  339. ],
  340. prefix: Text(
  341. '¥',
  342. style: TextStyle(fontSize: 20),
  343. ),
  344. onChanged: (value) {
  345. _checkSubmit(value);
  346. },
  347. placeholderStyle:
  348. TextStyle(fontSize: 26, color: Colors.grey[400]),
  349. ),
  350. ),
  351. Container(
  352. margin: EdgeInsets.only(top: 5, bottom: 20),
  353. width: double.infinity,
  354. height: 0.5,
  355. color: Color(0xffe4e4e4),
  356. ),
  357. ],
  358. ),
  359. );
  360. }
  361. Widget _createSubmit(WithdrawModel model) {
  362. // String value = model.cashOutDashbordItems[_currentIndex].value;
  363. // try {
  364. // if (num.tryParse(value) != null &&
  365. // null != _bloc.withdrawDataModel &&
  366. // num.tryParse(value) <
  367. // num.tryParse(_bloc.withdrawDataModel.finValue)) {
  368. // _submitable = true;
  369. // } else {
  370. // _submitable = false;
  371. // }
  372. // } catch (e, s) {
  373. // print(e);
  374. // print(s);
  375. // }
  376. try {
  377. var currentWithdraw = num.tryParse(_controller.text);
  378. var finValue = num.tryParse(_bloc.withdrawDataModel.finValue);
  379. if (currentWithdraw != null &&
  380. currentWithdraw != 0 &&
  381. finValue != null &&
  382. finValue != 0 &&
  383. currentWithdraw <= finValue) {
  384. _submitable = true;
  385. } else {
  386. _submitable = false;
  387. }
  388. } catch (e, s) {
  389. print(e);
  390. print(s);
  391. }
  392. return GestureDetector(
  393. onTap: () {
  394. ///提现
  395. if (_submitable) {
  396. _bloc.submitApply(context, _controller.text);
  397. }
  398. },
  399. child: Container(
  400. height: 50,
  401. decoration: BoxDecoration(
  402. color: _submitable
  403. ? HexColor.fromHex(model.cashOutBtnTextAvailableBgColor ?? '')
  404. : HexColor.fromHex(model.cashOutBtnTextUnavailableBgColor ?? ''),
  405. borderRadius: BorderRadius.circular(7.5),
  406. ),
  407. child: Center(
  408. child: Text(
  409. model.cashOutBtnText ?? '',
  410. style: TextStyle(
  411. fontSize: 15,
  412. color: _submitable
  413. ? HexColor.fromHex(model.cashOutBtnTextAvailableColor ?? '')
  414. : HexColor.fromHex(
  415. model.cashOutBtnTextUnavailableColor ?? ''),
  416. ),
  417. ),
  418. ),
  419. ),
  420. );
  421. }
  422. Widget _createDesc(WithdrawModel model) {
  423. return Column(
  424. crossAxisAlignment: CrossAxisAlignment.start,
  425. mainAxisAlignment: MainAxisAlignment.start,
  426. children: <Widget>[
  427. Container(
  428. width: double.infinity,
  429. margin: EdgeInsets.only(top: 8),
  430. child: Text(
  431. '提现说明',
  432. style: TextStyle(
  433. fontWeight: FontWeight.bold,
  434. color: Color(0xff333333),
  435. ),
  436. ),
  437. ),
  438. Text(
  439. model.cashOutTips ?? '',
  440. style: TextStyle(
  441. color: Color(0xff999999),
  442. fontSize: 14,
  443. ),
  444. ),
  445. ],
  446. );
  447. }
  448. ///检查提现按钮是否可用
  449. void _checkSubmit(String value) {
  450. // try {
  451. // var currentValue = num.tryParse(value);
  452. // var finValue = num.tryParse(_bloc.withdrawDataModel.finValue);
  453. //
  454. // if (currentValue != null &&
  455. // currentValue != 0 &&
  456. // currentValue <= finValue &&
  457. // finValue != 0) {
  458. // _submitable = true;
  459. // } else {
  460. // _submitable = false;
  461. // }
  462. // } catch (e, s) {
  463. // print(e);
  464. // print(s);
  465. // }
  466. setState(() {});
  467. }
  468. }