order_information_page.dart 31 KB

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