order_information_page.dart 30 KB

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