基础组件库
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

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