基础组件库
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

494 lignes
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: 17,
  126. color: HexColor.fromHex(model.appBarNameColor),
  127. fontWeight: FontWeight.w600
  128. ),
  129. ),
  130. actions:<Widget>[ GestureDetector(
  131. child: Center(
  132. child: Padding(
  133. padding: EdgeInsets.only(right: 16),
  134. child: Text(
  135. model.appBarRightText,
  136. style: TextStyle(fontSize: 13, color: HexColor.fromHex(model?.appBarNameColor??"")),
  137. ),
  138. ),
  139. ),
  140. onTap: () {
  141. RouterUtil.route(
  142. model.detailSkipModel, model.detailSkipModel.toJson(), context);
  143. },
  144. )],
  145. );
  146. }
  147. Widget _createHeader(WithdrawModel model) {
  148. var data = _bloc.withdrawDataModel;
  149. return Container(
  150. width: double.infinity,
  151. height: 97,
  152. decoration: BoxDecoration(
  153. color: Colors.white, borderRadius: BorderRadius.circular(10)),
  154. child: Stack(
  155. children: <Widget>[
  156. Container(
  157. width: double.infinity,
  158. height: double.infinity,
  159. child: CachedNetworkImage(
  160. imageUrl: model.availableCashOutBgImg ?? '',
  161. fit: BoxFit.fill,
  162. ),
  163. ),
  164. Center(
  165. child: Column(
  166. mainAxisAlignment: MainAxisAlignment.center,
  167. children: <Widget>[
  168. Text(
  169. data?.finValue ?? "",
  170. style: TextStyle(
  171. color: Colors.white,
  172. fontSize: 30,
  173. ),
  174. ),
  175. Text(
  176. model?.availableCashOutText ?? "",
  177. style: TextStyle(
  178. color: HexColor.fromHex(model.availableCashOutTextColor),
  179. fontSize: 14,
  180. ),
  181. ),
  182. ],
  183. ),
  184. )
  185. ],
  186. ),
  187. );
  188. }
  189. Widget _createVerify(WithdrawModel model) {
  190. var data = _bloc.withdrawDataModel;
  191. var param = {
  192. 'status': _bloc.aliPayModel,
  193. Constants.SkipIdentifierName: model.gotoAliPay.skipIdentifier,
  194. 'data': _bloc.aliPayModel
  195. };
  196. return GestureDetector(
  197. behavior: HitTestBehavior.opaque,
  198. onTap: () {
  199. Logger.debug('绑定支付宝');
  200. RouterUtil.route(
  201. model.gotoAliPay,
  202. {
  203. 'status': _bloc.aliPayModel,
  204. Constants.SkipIdentifierName: model.gotoAliPay.skipIdentifier,
  205. 'data': param
  206. },
  207. context)
  208. .then((value) {
  209. reload();
  210. });
  211. },
  212. child: Container(
  213. margin: EdgeInsets.only(top: 8, bottom: 8),
  214. child: Row(
  215. children: <Widget>[
  216. CachedNetworkImage(
  217. imageUrl: (data?.alipayUserName == null ||
  218. data?.alipayUserName.length == 0)
  219. ? model.unbindAlipayImg
  220. : model.bindAlipayImg,
  221. height: 23,
  222. ),
  223. Expanded(
  224. child: Padding(
  225. padding: const EdgeInsets.only(left: 8, right: 8),
  226. child: Text(
  227. (data?.alipayUserName == null ||
  228. data?.alipayUserName.length == 0)
  229. ? model.unbindAlipayText
  230. : data.alipayUserName,
  231. style: TextStyle(fontSize: 11, color: Color(0xff999999)),
  232. ),
  233. ),
  234. ),
  235. Text(
  236. (data?.alipayUserName == null || data?.alipayUserName.length == 0)
  237. ? model.unbindAlipayGotoText
  238. : model.bindAlipayGotoText,
  239. style: TextStyle(fontSize: 11, color: Color(0xff999999)),
  240. ),
  241. Icon(
  242. Icons.arrow_forward_ios,
  243. size: 12,
  244. color: Color(0xff999999),
  245. )
  246. ],
  247. ),
  248. ),
  249. );
  250. }
  251. Widget _createPrice(WithdrawModel model) {
  252. if (_controller.text.length == 0 &&
  253. model.cashOutDashbordItems[_currentIndex].name != "自定义") {
  254. _controller.text = model.cashOutDashbordItems[0].value;
  255. }
  256. return GridView.builder(
  257. shrinkWrap: true,
  258. physics: NeverScrollableScrollPhysics(),
  259. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  260. crossAxisCount: 3,
  261. crossAxisSpacing: 10,
  262. mainAxisSpacing: 10,
  263. childAspectRatio: 2.5,
  264. ),
  265. itemCount: model?.cashOutDashbordItems?.length ?? 0,
  266. itemBuilder: (BuildContext context, int index) {
  267. WithdrawDashbordItems item = model.cashOutDashbordItems[index];
  268. return GestureDetector(
  269. onTap: () {
  270. _controller.text = item.value;
  271. _currentIndex = index;
  272. _inputable = item.value == null || item.value == '';
  273. _checkSubmit(item.value);
  274. },
  275. child: Container(
  276. decoration: BoxDecoration(
  277. color: index == _currentIndex
  278. ? HexColor.fromHex(
  279. model.cashOutDashbordItemsSelectedBgColor ?? '')
  280. : HexColor.fromHex(
  281. model.cashOutDashbordItemsUnselectedBgColor ?? ''),
  282. borderRadius: BorderRadius.circular(5),
  283. border: Border.all(
  284. color: index == _currentIndex
  285. ? HexColor.fromHex(
  286. model.cashOutDashbordItemsSelectedColor ?? '')
  287. : HexColor.fromHex('#d2d2d2'),
  288. ),
  289. ),
  290. child: Center(
  291. child: Text(
  292. item.name,
  293. style: TextStyle(
  294. fontSize: 14,
  295. color: index == _currentIndex
  296. ? HexColor.fromHex(
  297. model.cashOutDashbordItemsSelectedColor ?? '')
  298. : HexColor.fromHex(
  299. model.cashOutDashbordItemsUnselectedColor ?? ''),
  300. ),
  301. ),
  302. ),
  303. ),
  304. );
  305. },
  306. );
  307. }
  308. Widget _createInput(WithdrawModel model) {
  309. return Padding(
  310. padding: const EdgeInsets.only(top: 8.0),
  311. child: Column(
  312. crossAxisAlignment: CrossAxisAlignment.start,
  313. mainAxisAlignment: MainAxisAlignment.start,
  314. children: <Widget>[
  315. Text(
  316. '提现金额',
  317. style: TextStyle(
  318. fontWeight: FontWeight.bold,
  319. color: Color(0xff333333),
  320. ),
  321. ),
  322. Container(
  323. width: double.infinity,
  324. height: 50,
  325. child: CupertinoTextField(
  326. placeholder: '输入提现金额',
  327. controller: _controller,
  328. enabled: _inputable,
  329. style: TextStyle(
  330. fontSize: 30,
  331. color: Color(0xff333333),
  332. fontFamily: 'Din-Bold',
  333. package: 'zhiying_comm',
  334. ),
  335. decoration: BoxDecoration(color: Colors.transparent),
  336. keyboardType: TextInputType.numberWithOptions(decimal: true),
  337. textInputAction: TextInputAction.done,
  338. inputFormatters: [
  339. WhitelistingTextInputFormatter(RegExp("[0-9.]")), //只允许输入小数
  340. ],
  341. prefix: Text(
  342. '¥',
  343. style: TextStyle(fontSize: 20),
  344. ),
  345. onChanged: (value) {
  346. _checkSubmit(value);
  347. },
  348. placeholderStyle:
  349. TextStyle(fontSize: 26, color: Colors.grey[400]),
  350. ),
  351. ),
  352. Container(
  353. margin: EdgeInsets.only(top: 5, bottom: 20),
  354. width: double.infinity,
  355. height: 0.5,
  356. color: Color(0xffe4e4e4),
  357. ),
  358. ],
  359. ),
  360. );
  361. }
  362. Widget _createSubmit(WithdrawModel model) {
  363. // String value = model.cashOutDashbordItems[_currentIndex].value;
  364. // try {
  365. // if (num.tryParse(value) != null &&
  366. // null != _bloc.withdrawDataModel &&
  367. // num.tryParse(value) <
  368. // num.tryParse(_bloc.withdrawDataModel.finValue)) {
  369. // _submitable = true;
  370. // } else {
  371. // _submitable = false;
  372. // }
  373. // } catch (e, s) {
  374. // print(e);
  375. // print(s);
  376. // }
  377. try {
  378. var currentWithdraw = num.tryParse(_controller.text);
  379. var finValue = num.tryParse(_bloc.withdrawDataModel.finValue);
  380. if (currentWithdraw != null &&
  381. currentWithdraw != 0 &&
  382. finValue != null &&
  383. finValue != 0 &&
  384. currentWithdraw <= finValue) {
  385. _submitable = true;
  386. } else {
  387. _submitable = false;
  388. }
  389. } catch (e, s) {
  390. print(e);
  391. print(s);
  392. }
  393. return GestureDetector(
  394. onTap: () {
  395. ///提现
  396. if (_submitable) {
  397. _bloc.submitApply(context, _controller.text);
  398. }
  399. },
  400. child: Container(
  401. height: 50,
  402. decoration: BoxDecoration(
  403. color: _submitable
  404. ? HexColor.fromHex(model.cashOutBtnTextAvailableBgColor ?? '')
  405. : HexColor.fromHex(model.cashOutBtnTextUnavailableBgColor ?? ''),
  406. borderRadius: BorderRadius.circular(7.5),
  407. ),
  408. child: Center(
  409. child: Text(
  410. model.cashOutBtnText ?? '',
  411. style: TextStyle(
  412. fontSize: 15,
  413. color: _submitable
  414. ? HexColor.fromHex(model.cashOutBtnTextAvailableColor ?? '')
  415. : HexColor.fromHex(
  416. model.cashOutBtnTextUnavailableColor ?? ''),
  417. ),
  418. ),
  419. ),
  420. ),
  421. );
  422. }
  423. Widget _createDesc(WithdrawModel model) {
  424. return Column(
  425. crossAxisAlignment: CrossAxisAlignment.start,
  426. mainAxisAlignment: MainAxisAlignment.start,
  427. children: <Widget>[
  428. Container(
  429. width: double.infinity,
  430. margin: EdgeInsets.only(top: 8),
  431. child: Text(
  432. '提现说明',
  433. style: TextStyle(
  434. fontWeight: FontWeight.bold,
  435. color: Color(0xff333333),
  436. ),
  437. ),
  438. ),
  439. Text(
  440. model.cashOutTips ?? '',
  441. style: TextStyle(
  442. color: Color(0xff999999),
  443. fontSize: 14,
  444. ),
  445. ),
  446. ],
  447. );
  448. }
  449. ///检查提现按钮是否可用
  450. void _checkSubmit(String value) {
  451. // try {
  452. // var currentValue = num.tryParse(value);
  453. // var finValue = num.tryParse(_bloc.withdrawDataModel.finValue);
  454. //
  455. // if (currentValue != null &&
  456. // currentValue != 0 &&
  457. // currentValue <= finValue &&
  458. // finValue != 0) {
  459. // _submitable = true;
  460. // } else {
  461. // _submitable = false;
  462. // }
  463. // } catch (e, s) {
  464. // print(e);
  465. // print(s);
  466. // }
  467. setState(() {});
  468. }
  469. }