order_information_page.dart 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/my_coupon_bean_entity.dart';
  3. import 'package:bbyyy/beans/pay_way_bean_entity.dart';
  4. import 'package:bbyyy/beans/user_balance_entity.dart';
  5. import 'package:bbyyy/https/MyDio.dart';
  6. import 'package:bbyyy/https/url.dart';
  7. import 'package:bbyyy/my_tools/const.dart';
  8. import 'package:bbyyy/my_tools/dims.dart';
  9. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  10. import 'package:bbyyy/my_tools/event_bus.dart';
  11. import 'package:bbyyy/my_tools/my_colors.dart';
  12. import 'package:bbyyy/my_tools/my_cookie.dart';
  13. import 'package:bbyyy/my_tools/my_tools.dart';
  14. import 'package:bbyyy/my_tools/my_views.dart';
  15. import 'package:bbyyy/paegs/mine_page/coupon_page/coupon_view.dart';
  16. import 'package:bbyyy/paegs/pay_page/pay_page.dart';
  17. import 'package:bbyyy/pay/pay_tools.dart';
  18. import 'package:flustars/flustars.dart';
  19. import 'package:flutter/cupertino.dart';
  20. import 'package:flutter/material.dart';
  21. import 'package:flutter_svg/svg.dart';
  22. import 'package:pull_to_refresh/pull_to_refresh.dart';
  23. class OrderInformationPage extends StatefulWidget {
  24. int orderType;
  25. double amount;
  26. int uid;
  27. String sellName;
  28. int sellUid;
  29. String sellPic;
  30. String buyerName;
  31. int buyerUid;
  32. String buyerPic;
  33. int commodityCount;
  34. String commodityCover;
  35. String commodityTitle;
  36. bool cancelOrder;
  37. OrderInformationPage(this.cancelOrder,
  38. {this.orderType,
  39. this.sellName,
  40. this.sellPic,
  41. this.sellUid,
  42. this.amount,
  43. this.buyerName,
  44. this.uid,
  45. this.buyerUid,
  46. this.buyerPic,
  47. this.commodityCover,
  48. this.commodityTitle,
  49. this.commodityCount});
  50. @override
  51. _OrderInformationPageState createState() => _OrderInformationPageState();
  52. }
  53. class _OrderInformationPageState extends State<OrderInformationPage> {
  54. int payWay = 0; //0; //钱包 1; //支付宝支付 2; //微信支付
  55. List<PayWayBeanData> payWays;
  56. String coupon = '未选择优惠券';
  57. MyCouponBeanDataData couponData;
  58. double balance = 0.0;
  59. @override
  60. void initState() {
  61. // TODO: implement initState
  62. super.initState();
  63. Future.delayed(Duration.zero, () {
  64. EasyLoading.show();
  65. checkPaymentMethod((response, hasError) {
  66. if (!hasError) {
  67. PayWayBeanEntity entity =
  68. PayWayBeanEntity().fromJson(json.decode(response.toString()));
  69. payWays = entity.data;
  70. getUserWalletBalance((re, hE) {
  71. if (!hE) {
  72. UserBalanceEntity balance =
  73. UserBalanceEntity().fromJson(json.decode(re.data.toString()));
  74. this.balance = balance.data;
  75. if (widget.amount > balance.data) {
  76. payWays.forEach((element) {
  77. if (element.pay) {
  78. payWay = element.way;
  79. }
  80. });
  81. }
  82. EasyLoading.dismiss();
  83. setState(() {});
  84. }
  85. }, (e) {
  86. EasyLoading.dismiss();
  87. }, context);
  88. }
  89. }, (error) {
  90. EasyLoading.dismiss();
  91. });
  92. });
  93. }
  94. @override
  95. Widget build(BuildContext context) {
  96. return Scaffold(
  97. backgroundColor: MyColors.cEFEFEF,
  98. body: Column(
  99. children: [
  100. MyViews().myAppBar('订单信息', context, []),
  101. Container(
  102. height: 10,
  103. color: MyColors.cEFEFEF,
  104. ),
  105. Expanded(
  106. child: SingleChildScrollView(
  107. child: Column(
  108. children: [
  109. Container(
  110. child: orderInformation(),
  111. color: Colors.white,
  112. padding: EdgeInsets.symmetric(vertical: 10),
  113. ),
  114. Container(
  115. height: 10,
  116. color: MyColors.cEFEFEF,
  117. ),
  118. Container(
  119. color: Colors.white,
  120. child: Row(
  121. children: [
  122. MyViews().myText('支付方式', MyColors.c333333, 14),
  123. GestureDetector(
  124. onTap: () {
  125. showPayWayPicker();
  126. },
  127. behavior: HitTestBehavior.translucent,
  128. child: Row(
  129. children: [
  130. SvgPicture.asset(
  131. payWayIcon(payWay),
  132. width: 20,
  133. height: 20,
  134. ),
  135. Container(
  136. child: MyViews().myText(
  137. payWayText(payWay), MyColors.c333333, 13),
  138. margin: EdgeInsets.only(left: 6, right: 6),
  139. ),
  140. SvgPicture.asset(
  141. 'images/svg/箭头.svg',
  142. color: MyColors.c999999,
  143. width: 6,
  144. height: 11,
  145. ),
  146. ],
  147. ),
  148. )
  149. ],
  150. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  151. ),
  152. alignment: Alignment.centerLeft,
  153. padding: EdgeInsets.all(10),
  154. ),
  155. Container(
  156. height: 10,
  157. color: MyColors.cEFEFEF,
  158. ),
  159. Container(
  160. color: Colors.white,
  161. child: Row(
  162. children: [
  163. MyViews().myText('优惠券', MyColors.c333333, 16),
  164. GestureDetector(
  165. onTap: () {
  166. MyTools().toPage(context, ChooseACoupon(), (then) {
  167. if (then is MyCouponBeanDataData) {
  168. couponData = then;
  169. coupon = couponType(couponData.type) +
  170. ': ${couponData.amount}元';
  171. setState(() {});
  172. }
  173. });
  174. },
  175. behavior: HitTestBehavior.translucent,
  176. child: Row(
  177. children: [
  178. Container(
  179. child: MyViews()
  180. .myText(coupon, MyColors.c333333, 13),
  181. margin: EdgeInsets.only(left: 6, right: 6),
  182. ),
  183. SvgPicture.asset(
  184. 'images/svg/箭头.svg',
  185. color: MyColors.c999999,
  186. width: 6,
  187. height: 11,
  188. ),
  189. ],
  190. ),
  191. )
  192. ],
  193. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  194. ),
  195. alignment: Alignment.centerLeft,
  196. padding: EdgeInsets.all(10),
  197. ),
  198. ],
  199. ),
  200. ),
  201. ),
  202. Container(
  203. color: Colors.white,
  204. child: SafeArea(
  205. top: false,
  206. child: Container(
  207. color: Colors.white,
  208. padding: EdgeInsets.only(right: 10, left: 10),
  209. height: 60,
  210. child: Row(
  211. children: [
  212. Row(
  213. children: [
  214. MyViews().myText('合计:', MyColors.c333333, 16),
  215. MyViews().myText(
  216. '¥${couponData == null ? widget.amount.toStringAsFixed(2) : NumUtil.subtract(widget.amount, couponData.amount) < 0 ? 0.0.toStringAsFixed(2) : NumUtil.subtract(widget.amount, couponData.amount).toStringAsFixed(2)}',
  217. MyColors.cFF4233,
  218. 18),
  219. ],
  220. ),
  221. Expanded(
  222. child: Row(
  223. children: [
  224. GestureDetector(
  225. onTap: () {
  226. toPayPage();
  227. },
  228. behavior: HitTestBehavior.translucent,
  229. child: Container(
  230. decoration: BoxDecoration(
  231. borderRadius: BorderRadius.circular(20),
  232. color: MyColors.cFF4233),
  233. height: 40,
  234. width: 160,
  235. child:
  236. MyViews().myText('确 认', Colors.white, 14),
  237. alignment: Alignment.center),
  238. )
  239. ],
  240. mainAxisAlignment: MainAxisAlignment.end,
  241. ),
  242. )
  243. ],
  244. ),
  245. ),
  246. ),
  247. )
  248. ],
  249. ),
  250. );
  251. }
  252. Widget orderInformation() {
  253. if (widget.orderType == orderTypeThirdPlatform) {
  254. //第三方平台订单
  255. return Container(
  256. margin: EdgeInsets.symmetric(horizontal: 12),
  257. child: Row(
  258. children: [
  259. Container(
  260. child: SvgPicture.asset(
  261. 'images/svg/第三方.svg',
  262. height: 45,
  263. width: 45,
  264. ),
  265. margin: EdgeInsets.only(right: 8),
  266. height: 60,
  267. width: 60,
  268. decoration: BoxDecoration(
  269. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  270. alignment: Alignment.center,
  271. ),
  272. Expanded(
  273. child: Container(
  274. height: 60,
  275. child: Column(
  276. children: [
  277. MyViews()
  278. .myText('第三方订单(${widget.uid})', MyColors.c333333, 13),
  279. Row(
  280. children: [
  281. MyViews()
  282. .myText('¥${widget.amount}', MyColors.cFF4233, 12),
  283. MyViews().myText(
  284. 'x${widget.commodityCount}', MyColors.c999999, 12),
  285. ],
  286. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  287. )
  288. ],
  289. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  290. crossAxisAlignment: CrossAxisAlignment.start,
  291. ),
  292. ),
  293. ),
  294. ],
  295. ),
  296. );
  297. } else if (widget.orderType == orderTypeAnnualFee) {
  298. //平台年费
  299. return Container(
  300. margin: EdgeInsets.symmetric(horizontal: 12),
  301. child: Row(
  302. children: [
  303. Container(
  304. child: Image.asset(
  305. 'images/app_logo.png',
  306. height: 45,
  307. width: 45,
  308. ),
  309. margin: EdgeInsets.only(right: 8),
  310. height: 60,
  311. width: 60,
  312. decoration: BoxDecoration(
  313. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  314. alignment: Alignment.center,
  315. ),
  316. Expanded(
  317. child: Container(
  318. height: 60,
  319. child: Column(
  320. children: [
  321. MyViews().myText('平台年费', MyColors.c333333, 13),
  322. Row(
  323. children: [
  324. MyViews()
  325. .myText('¥${widget.amount}', MyColors.cFF4233, 12),
  326. MyViews().myText(
  327. 'x${widget.commodityCount}', MyColors.c999999, 12),
  328. ],
  329. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  330. )
  331. ],
  332. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  333. crossAxisAlignment: CrossAxisAlignment.start,
  334. ),
  335. ),
  336. ),
  337. ],
  338. ),
  339. );
  340. } else if (widget.orderType == orderTypeAdvertise) {
  341. //平台广告订单
  342. return Container(
  343. margin: EdgeInsets.symmetric(horizontal: 12),
  344. child: Row(
  345. children: [
  346. Container(
  347. child: SvgPicture.asset(
  348. 'images/svg/平台广告.svg',
  349. height: 45,
  350. width: 45,
  351. ),
  352. margin: EdgeInsets.only(right: 8),
  353. height: 60,
  354. width: 60,
  355. decoration: BoxDecoration(
  356. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  357. alignment: Alignment.center,
  358. ),
  359. Expanded(
  360. child: Container(
  361. height: 60,
  362. child: Column(
  363. children: [
  364. MyViews().myText('广告费', MyColors.c333333, 13),
  365. Row(
  366. children: [
  367. MyViews()
  368. .myText('¥${widget.amount}', MyColors.cFF4233, 12),
  369. MyViews().myText(
  370. 'x${widget.commodityCount}', MyColors.c999999, 12),
  371. ],
  372. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  373. )
  374. ],
  375. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  376. crossAxisAlignment: CrossAxisAlignment.start,
  377. ),
  378. ),
  379. ),
  380. ],
  381. ),
  382. );
  383. } else if (widget.orderType == orderTypeCommodity) {
  384. //商品订单
  385. return Container(
  386. margin: EdgeInsets.only(left: 10, right: 10),
  387. child: Row(
  388. children: [
  389. MyViews().netImg(imgURL(widget.commodityCover), 60, 60,
  390. placeholder: 'images/svg/goodsDefImg.svg'),
  391. Expanded(
  392. child: Container(
  393. padding: EdgeInsets.only(left: 8),
  394. height: 60,
  395. child: Column(
  396. children: [
  397. Text(
  398. '${widget.commodityTitle}',
  399. style: TextStyle(color: MyColors.c333333, fontSize: 13),
  400. maxLines: 2,
  401. overflow: TextOverflow.ellipsis,
  402. softWrap: true,
  403. ),
  404. Row(
  405. children: [
  406. Text(
  407. '¥${double.parse('${widget.amount}').toStringAsFixed(2)}',
  408. style:
  409. TextStyle(color: MyColors.cFF4233, fontSize: 12),
  410. ),
  411. Text(
  412. 'x${widget.commodityCount}',
  413. style:
  414. TextStyle(color: MyColors.c999999, fontSize: 12),
  415. ),
  416. ],
  417. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  418. crossAxisAlignment: CrossAxisAlignment.start,
  419. ),
  420. ],
  421. crossAxisAlignment: CrossAxisAlignment.start,
  422. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  423. ),
  424. ),
  425. )
  426. ],
  427. ),
  428. );
  429. } else if (widget.orderType == orderTypeVirtualProduct) {
  430. //虚拟物品
  431. return Container(
  432. margin: EdgeInsets.only(left: 10, right: 10),
  433. child: Row(
  434. children: [
  435. Container(
  436. child: SvgPicture.asset(
  437. 'images/svg/虚拟物品.svg',
  438. height: 45,
  439. width: 45,
  440. ),
  441. margin: EdgeInsets.only(right: 8),
  442. height: 60,
  443. width: 60,
  444. decoration: BoxDecoration(
  445. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  446. alignment: Alignment.center,
  447. ),
  448. Expanded(
  449. child: Container(
  450. padding: EdgeInsets.only(left: 8),
  451. height: 60,
  452. child: Column(
  453. children: [
  454. Text(
  455. '虚拟道具',
  456. style: TextStyle(color: MyColors.c333333, fontSize: 13),
  457. maxLines: 2,
  458. overflow: TextOverflow.ellipsis,
  459. softWrap: true,
  460. ),
  461. Row(
  462. children: [
  463. Text(
  464. '¥${double.parse('${widget.amount}').toStringAsFixed(2)}',
  465. style:
  466. TextStyle(color: MyColors.cFF4233, fontSize: 12),
  467. ),
  468. Text(
  469. 'x${widget.commodityCount}',
  470. style:
  471. TextStyle(color: MyColors.c999999, fontSize: 12),
  472. ),
  473. ],
  474. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  475. crossAxisAlignment: CrossAxisAlignment.start,
  476. ),
  477. ],
  478. crossAxisAlignment: CrossAxisAlignment.start,
  479. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  480. ),
  481. ),
  482. )
  483. ],
  484. ),
  485. );
  486. } else if (widget.orderType == orderTypeOfflineTransfer) {
  487. //线下付款
  488. return Container(
  489. margin: EdgeInsets.only(left: 10, right: 10),
  490. child: Row(
  491. children: [
  492. Container(
  493. child: SvgPicture.asset(
  494. 'images/svg/线下付款.svg',
  495. height: 45,
  496. width: 45,
  497. ),
  498. margin: EdgeInsets.only(right: 8),
  499. height: 60,
  500. width: 60,
  501. decoration: BoxDecoration(
  502. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  503. alignment: Alignment.center,
  504. ),
  505. Expanded(
  506. child: Container(
  507. padding: EdgeInsets.only(left: 8),
  508. height: 60,
  509. child: Column(
  510. children: [
  511. Text(
  512. '到店付款',
  513. style: TextStyle(color: MyColors.c333333, fontSize: 13),
  514. maxLines: 2,
  515. overflow: TextOverflow.ellipsis,
  516. softWrap: true,
  517. ),
  518. Row(
  519. children: [
  520. Text(
  521. '¥${double.parse('${widget.amount}').toStringAsFixed(2)}',
  522. style:
  523. TextStyle(color: MyColors.cFF4233, fontSize: 12),
  524. ),
  525. Text(
  526. 'x${widget.commodityCount}',
  527. style:
  528. TextStyle(color: MyColors.c999999, fontSize: 12),
  529. ),
  530. ],
  531. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  532. crossAxisAlignment: CrossAxisAlignment.start,
  533. ),
  534. ],
  535. crossAxisAlignment: CrossAxisAlignment.start,
  536. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  537. ),
  538. ),
  539. )
  540. ],
  541. ),
  542. );
  543. } else {
  544. return Container(
  545. margin: EdgeInsets.only(left: 10, right: 10),
  546. child: Row(
  547. children: [
  548. MyViews().netImg(imgURL(widget.commodityCover), 82, 84,
  549. placeholder: 'images/svg/goodsDefImg.svg'),
  550. Expanded(
  551. child: Container(
  552. padding: EdgeInsets.only(left: 8),
  553. height: 82,
  554. child: Column(
  555. children: [
  556. Text(
  557. '${widget.commodityTitle}',
  558. style: TextStyle(color: MyColors.c333333, fontSize: 13),
  559. maxLines: 2,
  560. overflow: TextOverflow.ellipsis,
  561. softWrap: true,
  562. ),
  563. Row(
  564. children: [
  565. Text(
  566. '¥${double.parse('${widget.amount}').toStringAsFixed(2)}',
  567. style:
  568. TextStyle(color: MyColors.cFF4233, fontSize: 12),
  569. ),
  570. Text(
  571. 'x${widget.commodityCount}',
  572. style:
  573. TextStyle(color: MyColors.c999999, fontSize: 12),
  574. ),
  575. ],
  576. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  577. crossAxisAlignment: CrossAxisAlignment.start,
  578. ),
  579. ],
  580. crossAxisAlignment: CrossAxisAlignment.start,
  581. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  582. ),
  583. ),
  584. )
  585. ],
  586. ),
  587. );
  588. }
  589. }
  590. void toPayPage() {
  591. MyTools().toPage(
  592. context,
  593. PayPage(
  594. widget.uid, widget.cancelOrder, widget.amount, payWay, couponData),
  595. (then) {
  596. if (then is int) {
  597. if (then == 1) {
  598. Navigator.pop(context, then);
  599. }
  600. }
  601. });
  602. }
  603. String payWayIcon(int payWay) {
  604. switch (payWay) {
  605. case 1:
  606. return 'images/svg/支付宝.svg';
  607. case 2:
  608. return 'images/svg/微信.svg';
  609. case 0:
  610. return 'images/svg/积分支付.svg';
  611. default:
  612. return 'images/svg/支付宝.svg';
  613. }
  614. }
  615. String payWayText(int payWay) {
  616. switch (payWay) {
  617. case 1:
  618. return '支付宝';
  619. case 2:
  620. return '微信';
  621. case 0:
  622. return '积分支付';
  623. default:
  624. return '支付宝';
  625. }
  626. }
  627. void showPayWayPicker() {
  628. bool aliPay = payWays[payWays.indexWhere((element) => element.way==1)].pay;
  629. bool weChat = payWays[payWays.indexWhere((element) => element.way==2)].pay;
  630. showCupertinoModalPopup(
  631. context: context,
  632. builder: (BuildContext context) {
  633. return CupertinoActionSheet(
  634. title: MyViews()
  635. .myText('选择支付方式', MyColors.c333333, 20),
  636. actions: [
  637. CupertinoActionSheetAction(
  638. child: Row(
  639. children: [
  640. SvgPicture.asset(
  641. 'images/svg/支付宝.svg',
  642. width: 24,
  643. height: 24,
  644. ),
  645. Container(
  646. child: MyViews().myText(aliPay?'支付宝支付':'支付宝支付(暂不可用)',
  647. aliPay?MyColors.c333333:MyColors.cEFEFEF, 16),
  648. margin: EdgeInsets.only(
  649. left: 6, right: 6),
  650. ),
  651. ],
  652. mainAxisAlignment:
  653. MainAxisAlignment.center,
  654. ),
  655. onPressed: (() {
  656. if(aliPay){
  657. payWay = 1;
  658. setState(() {});
  659. Navigator.pop(context, 'Edit');
  660. }else{
  661. showToast('支付宝支付暂不可用');
  662. }
  663. }),
  664. ),
  665. CupertinoActionSheetAction(
  666. child: Row(
  667. children: [
  668. SvgPicture.asset(
  669. 'images/svg/微信.svg',
  670. width: 24,
  671. height: 24,
  672. ),
  673. Container(
  674. child: MyViews().myText(
  675. weChat?'微信支付':'微信支付(暂不可用)', weChat?MyColors.c333333:MyColors.c999999, 16),
  676. margin: EdgeInsets.only(
  677. left: 6, right: 6),
  678. ),
  679. ],
  680. mainAxisAlignment:
  681. MainAxisAlignment.center,
  682. ),
  683. onPressed: (() {
  684. if(weChat){
  685. payWay = 2;
  686. setState(() {});
  687. Navigator.pop(context, 'Edit');
  688. }else{
  689. showToast('微信支付暂不可用');
  690. }
  691. }),
  692. ),
  693. CupertinoActionSheetAction(
  694. child: Row(
  695. children: [
  696. SvgPicture.asset(
  697. 'images/svg/积分支付.svg',
  698. width: 24,
  699. height: 24,
  700. ),
  701. Container(
  702. child: MyViews().myText(
  703. '积分支付', MyColors.c333333, 16),
  704. margin: EdgeInsets.only(
  705. left: 6, right: 6),
  706. ),
  707. Container(
  708. child: MyViews().myText(
  709. '当前积分${balance.toStringAsFixed(2)}', MyColors.cFF4233, 16),
  710. margin: EdgeInsets.only(
  711. left: 6, right: 6),
  712. ),
  713. ],
  714. mainAxisAlignment:
  715. MainAxisAlignment.center,
  716. ),
  717. onPressed: (() {
  718. payWay = 0;
  719. setState(() {});
  720. Navigator.pop(context, 'Edit');
  721. }),
  722. ),
  723. ],
  724. cancelButton: CupertinoActionSheetAction(
  725. child: Text("取消"),
  726. isDefaultAction: true,
  727. onPressed: (() {
  728. Navigator.pop(context, 'Cancel');
  729. }),
  730. ),
  731. );
  732. });
  733. }
  734. }
  735. class ChooseACoupon extends StatefulWidget {
  736. @override
  737. _ChooseACouponState createState() => _ChooseACouponState();
  738. }
  739. class _ChooseACouponState extends State<ChooseACoupon> {
  740. int page = 1;
  741. RefreshController controller = RefreshController(initialRefresh: true);
  742. List<MyCouponBeanDataData> coupons = [];
  743. @override
  744. void initState() {
  745. // TODO: implement initState
  746. super.initState();
  747. EventBus().on('showCouponIndex', (arg) {
  748. setState(() {});
  749. });
  750. }
  751. @override
  752. void dispose() {
  753. // TODO: implement dispose
  754. super.dispose();
  755. EventBus().off('showCouponIndex');
  756. }
  757. @override
  758. Widget build(BuildContext context) {
  759. return Scaffold(
  760. backgroundColor: MyColors.cF7F7F7,
  761. body: Column(
  762. children: [
  763. MyViews().myAppBar('优惠券', context, []),
  764. Expanded(
  765. child: SmartRefresher(
  766. controller: controller,
  767. onRefresh: onRefresh,
  768. onLoading: onLoading,
  769. enablePullUp: true,
  770. enablePullDown: true,
  771. child: coupons.length == 0
  772. ? SingleChildScrollView(child: noData())
  773. : ListView.builder(
  774. itemBuilder: (c, index) {
  775. return GestureDetector(
  776. onTap: () {
  777. Navigator.pop(context, coupons[index]);
  778. },
  779. behavior: HitTestBehavior.translucent,
  780. child: CouponView().ticketItem(coupons[index]),
  781. );
  782. },
  783. itemCount: coupons.length,
  784. padding: EdgeInsets.only(
  785. top: 5, left: 24, right: 24, bottom: 20),
  786. ),
  787. ),
  788. ),
  789. ],
  790. ),
  791. );
  792. }
  793. void onRefresh() {
  794. page = 1;
  795. checkCoupons();
  796. }
  797. void onLoading() {
  798. page++;
  799. checkCoupons();
  800. }
  801. checkCoupons() {
  802. MyDio().query({
  803. "key": "coupon",
  804. "filters": {
  805. "conditions": ["user_uid==${MyCookie().getUID()}", "used == false"]
  806. },
  807. "dims": couponDims,
  808. "paging": [page, 20]
  809. }, (response, hasError) {
  810. if (!hasError) {
  811. MyCouponBeanEntity entity = MyCouponBeanEntity()
  812. .fromJson(json.decode(response.data.toString()));
  813. if (page == 1) {
  814. coupons.clear();
  815. }
  816. coupons.addAll(entity.data.data);
  817. setState(() {});
  818. }
  819. endRe(controller);
  820. }, (error) {
  821. endRe(controller);
  822. });
  823. }
  824. }