order_information_page.dart 30 KB

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