基础组件库
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

476 行
14 KiB

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