order_information_page.dart 30 KB

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