buy_service.dart 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. import 'dart:convert';
  2. import 'dart:math';
  3. import 'package:flustars/flustars.dart' as FlutterStars;
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_alipay/flutter_alipay.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:flutter_spinkit/flutter_spinkit.dart';
  8. import 'package:fluwx/fluwx.dart' as fluwx;
  9. import 'package:liftmanager/common/common.dart';
  10. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  11. import 'package:liftmanager/internal/bbs/model/liftcase_model.dart';
  12. import 'package:liftmanager/net/api_service.dart';
  13. import 'package:liftmanager/res/resources.dart';
  14. import 'package:liftmanager/routers/fluro_navigator.dart';
  15. import 'package:liftmanager/utils/fast_notification.dart';
  16. import 'package:liftmanager/utils/theme_utils.dart';
  17. import 'package:liftmanager/utils/time_format.dart';
  18. import 'package:liftmanager/utils/toast.dart';
  19. import 'package:liftmanager/widgets/app_bar.dart';
  20. import 'package:liftmanager/widgets/load_image.dart';
  21. class BuyService extends StatefulWidget {
  22. BuyService(this.id);
  23. final String id;
  24. @override
  25. State<StatefulWidget> createState() {
  26. return BuyServiceState();
  27. }
  28. }
  29. class BuyServiceState extends State<BuyService> {
  30. // ExpertListState({Key key}) : super(key: key);
  31. bool sortBool = true;
  32. String couponChiose = '请选择';
  33. String redChiose = '请选择';
  34. String typeName = "卡券";
  35. String questionType;
  36. int typeIdssCoupon;
  37. int typeIdssRed;
  38. double priceCoupon = 0.0;
  39. double priceRed = 0.0;
  40. double priceTotal = 0.0;
  41. // int dataId;
  42. // String expertName;
  43. // double expertFee;
  44. // double apiExpertFee = 0.0;
  45. bool _hasData = false;
  46. @override
  47. initState() {
  48. super.initState();
  49. setSchema();
  50. _initFluwx();
  51. // getDataId();
  52. // getType();
  53. // getExpertName();
  54. // getExpertFee();
  55. getBrandDetail();
  56. getCoupon();
  57. indexNow = 0;
  58. }
  59. _initFluwx() async {
  60. await fluwx.registerWxApi(
  61. appId: "wx0f10e6386fb9969e",
  62. doOnAndroid: true,
  63. doOnIOS: true,
  64. universalLink: "https://www.edtyun.com/");
  65. var result = await fluwx.isWeChatInstalled();
  66. setState(() {});
  67. }
  68. void setSchema() async {
  69. // await FlutterAlipay.setIosUrlSchema("tytylift");
  70. await FlutterAlipay.setIosUrlSchema("com.tyty.lift.managers");
  71. }
  72. LiftCasesDetailModel detailObj;
  73. getBrandDetail() {
  74. NewApiService().getLiftcaseDetail(widget.id, onSuccess: (res) {
  75. detailObj = res;
  76. priceTotal = detailObj.totalCost;
  77. print(priceTotal);
  78. print(123);
  79. _hasData = true;
  80. setState(() {});
  81. }, onError: (code, msg) {
  82. toasts(msg);
  83. });
  84. }
  85. List<dynamic> couponList = [];
  86. Future getCouponList(type) async {
  87. couponList = [];
  88. await NewApiService().getCouponListNoPage(type, detailObj.totalCost,
  89. onSuccess: (res) {
  90. if (res != null) {
  91. couponList = res;
  92. print(jsonEncode(res));
  93. print(111222);
  94. setState(() {});
  95. }
  96. }, onError: (code, msg) {
  97. toasts(msg);
  98. });
  99. }
  100. // 根据orderNo获取支付宝订单信息
  101. Future getAlipayOrderInfo(ordersNo) async {
  102. await NewApiService().aliPay(
  103. orders: ordersNo,
  104. liftCaseType: detailObj.dataTable,
  105. onSuccess: (res) {
  106. callAlipay(res);
  107. },
  108. onError: (code, msg) {
  109. toasts(msg);
  110. });
  111. }
  112. dynamic _wxPay;
  113. wxMethod(_payInfo) {
  114. print(_payInfo["appid"]);
  115. fluwx
  116. .payWithWeChat(
  117. appId: _payInfo["appid"],
  118. partnerId: _payInfo["partnerid"],
  119. prepayId: _payInfo["prepayid"],
  120. packageValue: _payInfo["package"],
  121. nonceStr: _payInfo["noncestr"],
  122. timeStamp: int.parse(_payInfo["timestamp"]),
  123. sign: _payInfo["sign"])
  124. .then((data) {
  125. print(data);
  126. });
  127. _wxPay?.cancel();
  128. _wxPay = fluwx.responseFromPayment
  129. .listen((fluwx.WeChatPaymentResponse response) async {
  130. print("WeChatPaymentResponse" + response.errCode.toString());
  131. if (response.errCode == -2) {
  132. //支付取消
  133. toasts("支付取消");
  134. } else if (response.errCode == -1) {
  135. //支付失败
  136. toasts("支付失败");
  137. } else if (response.errCode == 0) {
  138. //支付成功
  139. upDataMoney();
  140. if (detailObj.dataTable == 1) {
  141. getRoom();
  142. } else {
  143. Navigator.of(context)..pop()..pop();
  144. }
  145. }
  146. });
  147. }
  148. // 根据orderNo获取wx订单信息
  149. Future getWxOrderInfo(ordersNo) async {
  150. // int liftCaseType;
  151. // questionType == "1" ? liftCaseType = 1 : liftCaseType = 2;
  152. await NewApiService().wxPay(
  153. orders: ordersNo,
  154. liftCaseType: detailObj.dataTable,
  155. onSuccess: (res) {
  156. wxMethod(res);
  157. },
  158. onError: (code, msg) {
  159. toasts(msg);
  160. });
  161. }
  162. //余额支付
  163. Future lastMoneyPay(orders) async {
  164. int liftCaseType;
  165. String payType;
  166. detailObj.dataTable == 1 ? liftCaseType = 1 : liftCaseType = 2;
  167. detailObj.dataTable == 1 ? payType = "CASE" : payType = "CALL";
  168. await NewApiService().getAlipayBalanceApp({
  169. "payType": payType,
  170. "orders": orders,
  171. "liftCaseType": liftCaseType,
  172. "userId": FlutterStars.SpUtil.getString(Constant.userId),
  173. }, onSuccess: (res) {
  174. // moneyList = res;
  175. upDataMoney();
  176. if (detailObj.dataTable == 1) {
  177. getRoom();
  178. } else {
  179. Navigator.of(context)..pop()..pop();
  180. }
  181. }, onError: (code, msg) {
  182. toasts(msg);
  183. });
  184. }
  185. //根据专家Id和诊单Id获取orderId
  186. Future generateOrder(int type) async {
  187. if (detailObj.orderNo != null) {
  188. if (type == 0) {
  189. showAlert(
  190. context,
  191. "提示",
  192. "确定支付?",
  193. "确定",
  194. () {
  195. lastMoneyPay(detailObj.orderNo);
  196. NavigatorUtils.goBack(context);
  197. },
  198. txt2: "取消",
  199. onPre2: () {
  200. NavigatorUtils.goBack(context);
  201. },
  202. );
  203. } else if (type == 1) {
  204. getAlipayOrderInfo(detailObj.orderNo);
  205. } else if (type == 2) {
  206. getWxOrderInfo(detailObj.orderNo);
  207. }
  208. } else {
  209. await NewApiService().generateOrder({
  210. "id": detailObj.id,
  211. "chargerId": detailObj.chargerId,
  212. "couponId": typeIdssCoupon,
  213. "packetId": typeIdssRed
  214. }, onSuccess: (res) {
  215. print(res);
  216. if (res != null) {
  217. if (type == 0) {
  218. lastMoneyPay(res);
  219. } else if (type == 1) {
  220. getAlipayOrderInfo(res);
  221. } else if (type == 2) {
  222. getWxOrderInfo(res);
  223. }
  224. }
  225. print(555);
  226. }, onError: (code, msg) {
  227. toasts(msg);
  228. });
  229. }
  230. }
  231. upDataMoney() {
  232. String initThisUserMoney = randomInt(1111, 9999).toString() +
  233. DateTime.now().millisecondsSinceEpoch.toString();
  234. FastNotification.push("initUserMoney", initThisUserMoney);
  235. }
  236. randomInt(int min, int max) {
  237. return new Random().nextInt(max) % (max - min + 1) + min;
  238. }
  239. //支付完成后用诊单Id获取房间号
  240. Future getRoom() async {
  241. // Navigator.of(context)..pop()..pop();
  242. await NewApiService().findOne(widget.id, onSuccess: (res) {
  243. print(res);
  244. String roomId = res.sessionid;
  245. toasts("支付成功,即将进入聊天室!");
  246. NavigatorUtils.push(context,
  247. "${BbsRouter.chatRoom}?id=$roomId&type=someToOne&toUserId=''");
  248. // toasts("欢迎使用,请在使用过程中注意个人信息及财产安全!");
  249. print(666);
  250. }, onError: (code, msg) {
  251. toasts(msg);
  252. });
  253. }
  254. @override
  255. void dispose() {
  256. // setExpertFee(0.0);
  257. super.dispose();
  258. }
  259. void callAlipay(String _payInfo) async {
  260. AlipayResult payResult;
  261. try {
  262. print("The pay info is : " + _payInfo);
  263. payResult = await FlutterAlipay.pay(_payInfo);
  264. } on Exception catch (e) {
  265. payResult = null;
  266. }
  267. print(payResult);
  268. if (payResult != null) {
  269. if (payResult.resultStatus == "9000") {
  270. upDataMoney();
  271. if (detailObj.dataTable == 1) {
  272. getRoom();
  273. } else {
  274. Navigator.of(context)..pop()..pop();
  275. }
  276. } else {
  277. toasts(payResult.memo);
  278. }
  279. } else {
  280. toasts("支付异常");
  281. }
  282. }
  283. String balance = '0';
  284. Future getCoupon() async {
  285. await NewApiService().getUserCoupons(onSuccess: (res) {
  286. if (res != null) {
  287. balance = res["balance"].toString();
  288. setState(() {});
  289. print(6666544);
  290. }
  291. }, onError: (code, msg) {
  292. toasts(msg);
  293. });
  294. }
  295. static const payType = [
  296. {
  297. "icon": "tab_first/pay_yue",
  298. "title": "账户余额",
  299. "price": "",
  300. },
  301. {
  302. "icon": "tab_first/pay_zhifubao",
  303. "title": "支付宝",
  304. },
  305. {
  306. "icon": "tab_first/pay_winxin",
  307. "title": "微信",
  308. },
  309. ];
  310. List<String> labelList = ["特邀专家", "回复及时"];
  311. List<String> sortListChiose = [
  312. "综合排序",
  313. "咨询人数",
  314. "评论星级",
  315. "回复速度",
  316. ];
  317. getScenario(int type) {
  318. String str;
  319. if (type == 0) {
  320. str = "全场通用";
  321. } else if (type == 1) {
  322. str = "出诊问诊服务";
  323. } else if (type == 2) {
  324. str = "题库";
  325. } else if (type == 3) {
  326. str = "视频";
  327. }
  328. return str;
  329. }
  330. int indexNow = 999;
  331. String checkFalse = "tab_first/check_false";
  332. String checkTrue = "tab_first/check_true";
  333. @override
  334. Widget build(BuildContext context) {
  335. double width = MediaQuery.of(context).size.width;
  336. double height = MediaQuery.of(context).size.height;
  337. return Container(
  338. child: Scaffold(
  339. appBar: MyAppBar(
  340. centerTitle: "购买服务",
  341. ),
  342. body: _hasData
  343. ? Container(
  344. child: Stack(
  345. children: <Widget>[
  346. Container(
  347. // padding: EdgeInsets.only(top:70),
  348. child: ListView(children: <Widget>[
  349. Container(
  350. padding: EdgeInsets.all(ScreenUtil().setWidth(15)),
  351. decoration: BoxDecoration(
  352. border: Border(
  353. bottom: BorderSide(
  354. width: 5, color: Color(0xfff5f5f5)),
  355. ),
  356. ),
  357. child: Row(
  358. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  359. children: <Widget>[
  360. Row(
  361. crossAxisAlignment:
  362. CrossAxisAlignment.center,
  363. children: <Widget>[
  364. Text(
  365. detailObj.dataTable == 1
  366. ? "问诊服务"
  367. : "出诊服务",
  368. style: TextStyle(
  369. color: Color(0xff333333),
  370. fontSize: ScreenUtil().setSp(16)),
  371. textAlign: TextAlign.start,
  372. ),
  373. // Container(
  374. // padding: EdgeInsets.only(
  375. // left: ScreenUtil().setWidth(10)),
  376. // child: Text(
  377. // detailObj.name ?? "",
  378. // style: TextStyle(
  379. // color: Color(0xff666666),
  380. // fontSize: ScreenUtil().setSp(16)),
  381. // textAlign: TextAlign.start,
  382. // ),
  383. // )
  384. ]),
  385. Container(
  386. child: Text(
  387. detailObj.totalCost != null
  388. ? detailObj.totalCost.toString()
  389. : "0.0",
  390. style: TextStyle(
  391. color: Colors.red,
  392. fontSize: ScreenUtil().setSp(16)),
  393. textAlign: TextAlign.end,
  394. ),
  395. )
  396. ])),
  397. // ChioseThis(list: quanListChiose,label: "优惠券",labelText: '无可用优惠券',value:quanChiose,fun:(index){
  398. // setState(() {
  399. // quanChiose = quanListChiose[index];
  400. // });
  401. // Navigator.maybePop(context);
  402. // }),
  403. detailObj.dataTable == 2
  404. ? Container(
  405. padding: EdgeInsets.only(
  406. left: ScreenUtil().setWidth(15),
  407. right: ScreenUtil().setWidth(15),
  408. top: ScreenUtil().setWidth(10),
  409. bottom: ScreenUtil().setWidth(10)),
  410. decoration: BoxDecoration(
  411. border: Border(
  412. bottom: BorderSide(
  413. width: 5, color: Color(0xfff5f5f5)),
  414. ),
  415. ),
  416. child: Row(
  417. mainAxisAlignment:
  418. MainAxisAlignment.spaceBetween,
  419. children: <Widget>[
  420. Text(
  421. "差旅费",
  422. style: TextStyle(
  423. color: Color(0xff222222),
  424. fontSize: ScreenUtil().setSp(14)),
  425. textAlign: TextAlign.start,
  426. ),
  427. Text(
  428. "¥${detailObj.travelCost.toString()}",
  429. style: TextStyle(
  430. color: Colors.red,
  431. fontSize: ScreenUtil().setSp(14)),
  432. textAlign: TextAlign.start,
  433. ),
  434. ]),
  435. )
  436. : Container(child: null),
  437. detailObj.dataTable == 2
  438. ? Container(
  439. padding: EdgeInsets.only(
  440. left: ScreenUtil().setWidth(15),
  441. right: ScreenUtil().setWidth(15),
  442. top: ScreenUtil().setWidth(10),
  443. bottom: ScreenUtil().setWidth(10)),
  444. decoration: BoxDecoration(
  445. border: Border(
  446. bottom: BorderSide(
  447. width: 5, color: Color(0xfff5f5f5)),
  448. ),
  449. ),
  450. child: Row(
  451. mainAxisAlignment:
  452. MainAxisAlignment.spaceBetween,
  453. children: <Widget>[
  454. Text(
  455. "服务费",
  456. style: TextStyle(
  457. color: Color(0xff222222),
  458. fontSize: ScreenUtil().setSp(14)),
  459. textAlign: TextAlign.start,
  460. ),
  461. Text(
  462. "¥${detailObj.serviceCost.toString()}",
  463. style: TextStyle(
  464. color: Colors.red,
  465. fontSize: ScreenUtil().setSp(14)),
  466. textAlign: TextAlign.start,
  467. ),
  468. ]),
  469. )
  470. : Container(child: null),
  471. detailObj.orderNo == null
  472. ? ChioseThisRight(
  473. label: "优惠券",
  474. labelText: '无可用优惠券',
  475. value: couponChiose,
  476. fun: () {
  477. setState(() {
  478. // brandChiose = brandListChiose[index];
  479. typeName = "卡券";
  480. sortBool = false;
  481. print(5656333);
  482. });
  483. getCouponList(1);
  484. // Navigator.maybePop(context);
  485. })
  486. : Container(child: null),
  487. detailObj.orderNo == null
  488. ? ChioseThisRight(
  489. label: "红包",
  490. labelText: '无可用红包',
  491. value: redChiose,
  492. fun: () {
  493. setState(() {
  494. // brandChiose = brandListChiose[index];
  495. typeName = "红包";
  496. sortBool = false;
  497. print(5656333);
  498. });
  499. getCouponList(2);
  500. // Navigator.maybePop(context);
  501. })
  502. : Container(child: null),
  503. // ChioseThis(list: redListChiose,label: "红包",labelText: '无可用红包',value:redChiose,fun:(index){
  504. // setState(() {
  505. // redChiose = redListChiose[index];
  506. // });
  507. // Navigator.maybePop(context);
  508. // }),
  509. Container(
  510. padding: EdgeInsets.only(
  511. left: ScreenUtil().setWidth(15),
  512. right: ScreenUtil().setWidth(15),
  513. top: ScreenUtil().setWidth(10),
  514. bottom: ScreenUtil().setWidth(10)),
  515. decoration: BoxDecoration(
  516. border: Border(
  517. bottom:
  518. BorderSide(width: 5, color: Color(0xfff5f5f5)),
  519. ),
  520. ),
  521. child: Row(
  522. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  523. children: <Widget>[
  524. Text(
  525. "共需支付",
  526. style: TextStyle(
  527. color: Color(0xff222222),
  528. fontSize: ScreenUtil().setSp(14)),
  529. textAlign: TextAlign.start,
  530. ),
  531. Text(
  532. "¥${detailObj.orderNo == null ? priceTotal.toStringAsFixed(2).toString() : detailObj.payCost != null ? detailObj.payCost.toStringAsFixed(2).toString() : "0.0"}",
  533. style: TextStyle(
  534. color: Colors.red,
  535. fontSize: ScreenUtil().setSp(14)),
  536. textAlign: TextAlign.start,
  537. ),
  538. ]),
  539. ),
  540. Container(
  541. padding: EdgeInsets.only(
  542. left: ScreenUtil().setWidth(15),
  543. right: ScreenUtil().setWidth(15),
  544. top: ScreenUtil().setWidth(10),
  545. bottom: ScreenUtil().setWidth(10)),
  546. decoration: BoxDecoration(
  547. border: Border(
  548. bottom: BorderSide(
  549. width: 0.5, color: Color(0xfff5f5f5)),
  550. ),
  551. ),
  552. child: Row(
  553. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  554. children: <Widget>[
  555. Text(
  556. "选择支付方式",
  557. style: TextStyle(
  558. color: Color(0xff000000),
  559. fontSize: ScreenUtil().setSp(16)),
  560. textAlign: TextAlign.start,
  561. ),
  562. ]),
  563. ),
  564. Container(
  565. padding: EdgeInsets.only(
  566. left: ScreenUtil().setWidth(15),
  567. bottom: ScreenUtil().setWidth(80),
  568. right: ScreenUtil().setWidth(15)),
  569. child: Column(
  570. children: payType.asMap().keys.map((i) {
  571. return Container(
  572. decoration: BoxDecoration(
  573. border: Border(
  574. bottom: BorderSide(
  575. width: 0.5, color: Color(0xfff5f5f5)),
  576. ),
  577. ),
  578. height: 60,
  579. child: InkWell(
  580. onTap: () {
  581. setState(() {
  582. indexNow = i;
  583. });
  584. print(indexNow);
  585. },
  586. child: Row(
  587. mainAxisAlignment:
  588. MainAxisAlignment.spaceBetween,
  589. children: <Widget>[
  590. Row(
  591. children: <Widget>[
  592. LoadAssetImage(
  593. // image: AssetImage(i['img']),
  594. payType[i]["icon"],
  595. width:
  596. ScreenUtil().setWidth(20),
  597. height:
  598. ScreenUtil().setWidth(20),
  599. // alignment: Alignment.centerLeft,
  600. ),
  601. Container(width: 5, child: null),
  602. Text(
  603. payType[i]["title"],
  604. style: TextStyle(
  605. color: Color(0xff000000),
  606. fontSize:
  607. ScreenUtil().setSp(14)),
  608. textAlign: TextAlign.start,
  609. ),
  610. Container(width: 5, child: null),
  611. Text(
  612. payType[i]["price"] != null
  613. ? "¥$balance"
  614. : "",
  615. style: TextStyle(
  616. color: Color(0xff999999),
  617. fontSize:
  618. ScreenUtil().setSp(16)),
  619. textAlign: TextAlign.start,
  620. ),
  621. ],
  622. ),
  623. Container(
  624. // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
  625. child: LoadAssetImage(
  626. // image: AssetImage(i['img']),
  627. indexNow == i
  628. ? checkTrue
  629. : checkFalse,
  630. width: ScreenUtil().setWidth(18),
  631. height: ScreenUtil().setWidth(18),
  632. // alignment: Alignment.centerLeft,
  633. ),
  634. ),
  635. ])),
  636. );
  637. }).toList(),
  638. ))
  639. ]),
  640. ),
  641. Positioned(
  642. bottom: 0,
  643. left: 0,
  644. child: Container(
  645. width: width,
  646. padding: EdgeInsets.only(
  647. top: ScreenUtil().setWidth(15),
  648. bottom: ScreenUtil().setWidth(15),
  649. left: ScreenUtil().setWidth(25),
  650. right: ScreenUtil().setWidth(25)),
  651. color: Colors.white,
  652. child: Container(
  653. height: 44,
  654. decoration: BoxDecoration(
  655. color: Colours.blue_app_main,
  656. borderRadius: BorderRadius.circular(22.0),
  657. // gradient: const LinearGradient(
  658. // colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  659. ),
  660. child: FlatButton(
  661. // padding: EdgeInsets.all(15.0),
  662. child: Text("立即购买"),
  663. textColor: Colors.white,
  664. onPressed: () {
  665. // NavigatorUtils.push(context, "${BbsRouter.chatRoom}?id=1111");
  666. if (priceTotal <= 0 && indexNow != 0) {
  667. toasts("支付金额为0,请使用余额支付!");
  668. return;
  669. }
  670. if (indexNow == 0) {
  671. generateOrder(0);
  672. // NavigatorUtils.push(context, BbsRouter.chatRoom);
  673. } else if (indexNow == 1) {
  674. generateOrder(1);
  675. // NewApiService().aliPayOrder(orders,
  676. // onSuccess: (res) {
  677. // callAlipay(res);
  678. // }, onError: (code, msg) {
  679. // toasts(msg);
  680. // });
  681. } else if (indexNow == 2) {
  682. generateOrder(2);
  683. } else {
  684. toasts("选择支付方式");
  685. }
  686. },
  687. ),
  688. ),
  689. )),
  690. !sortBool
  691. ? Positioned(
  692. top: 0,
  693. left: 0,
  694. child: GestureDetector(
  695. onTap: () {
  696. setState(() {
  697. sortBool = true;
  698. });
  699. },
  700. child: Container(
  701. width: width,
  702. height: height,
  703. color: Color.fromRGBO(0, 0, 0, 0.5)),
  704. ),
  705. )
  706. : Container(child: null),
  707. !sortBool
  708. ? Positioned(
  709. top: 0,
  710. right: 0,
  711. child: Container(
  712. width: width / 4 * 3,
  713. height: height,
  714. color: Colors.white,
  715. padding: EdgeInsets.all(10),
  716. child: ListView(
  717. children: <Widget>[
  718. Container(
  719. padding: EdgeInsets.only(
  720. left: 5, top: 5, bottom: 10),
  721. child: Text(
  722. typeName,
  723. style: TextStyle(
  724. color: Color(0xff666666),
  725. fontSize: ScreenUtil().setSp(16)),
  726. textAlign: TextAlign.start,
  727. ),
  728. ),
  729. InkWell(
  730. onTap: () {
  731. setState(() {
  732. priceTotal = detailObj.totalCost;
  733. sortBool = true;
  734. if (typeName == "卡券") {
  735. priceCoupon = 0.0;
  736. couponChiose = '请选择';
  737. typeIdssCoupon = null;
  738. } else if (typeName == "红包") {
  739. priceRed = 0.0;
  740. redChiose = '请选择';
  741. typeIdssRed = null;
  742. }
  743. print(priceCoupon);
  744. print(priceRed);
  745. print(123465798);
  746. if ((priceTotal -
  747. priceCoupon -
  748. priceRed) <
  749. 0) {
  750. priceTotal = 0;
  751. } else {
  752. priceTotal = priceTotal -
  753. priceCoupon -
  754. priceRed;
  755. }
  756. couponList = [];
  757. });
  758. },
  759. child: Container(
  760. // width: width / 4 - 17,
  761. padding: EdgeInsets.only(
  762. bottom: ScreenUtil().setWidth(10),
  763. left: ScreenUtil().setWidth(10),
  764. right: ScreenUtil().setWidth(10),
  765. top: ScreenUtil().setWidth(10)),
  766. margin: EdgeInsets.only(
  767. left: 5, right: 5, bottom: 5, top: 5),
  768. decoration: BoxDecoration(
  769. // border: Border(
  770. // bottom: BorderSide(width: 0.5, color: Colours.line),
  771. // ),
  772. color: Color(0xfff5f5f5)),
  773. child: Text(
  774. "不选择$typeName",
  775. style: TextStyle(
  776. color: Color(0xff000000),
  777. fontSize: ScreenUtil().setSp(14)),
  778. textAlign: TextAlign.center,
  779. ),
  780. ),
  781. ),
  782. couponList != null && couponList.length > 0
  783. ? Container(
  784. child: Wrap(
  785. alignment: WrapAlignment.start,
  786. crossAxisAlignment:
  787. WrapCrossAlignment.center,
  788. children: couponList
  789. .asMap()
  790. .keys
  791. .map<Widget>((index) {
  792. return hongbaoCell(index);
  793. // InkWell(
  794. // onTap: () {
  795. // setState(() {
  796. // priceTotal =
  797. // detailObj.totalCost;
  798. // sortBool = true;
  799. // if (typeName == "卡券") {
  800. // // if (priceTotal -
  801. // // couponList[index]
  802. // // .coupon
  803. // // .price >
  804. // // 0.0) {
  805. // // priceCoupon =
  806. // // couponList[index]
  807. // // .coupon
  808. // // .price;
  809. // // }else {
  810. // // priceTotal = 0.0;
  811. // // }
  812. // priceCoupon =
  813. // couponList[index]
  814. // .coupon
  815. // .discount;
  816. // couponChiose =
  817. // couponList[index]
  818. // .coupon
  819. // .name ??
  820. // "";
  821. // typeIdssCoupon =
  822. // couponList[index].id;
  823. // } else if (typeName == "红包") {
  824. // // if (priceTotal -
  825. // // couponList[index]
  826. // // .coupon
  827. // // .price >
  828. // // 0.0) {
  829. // // priceRed =
  830. // // couponList[index]
  831. // // .coupon
  832. // // .price;
  833. // // }else {
  834. // // priceTotal = 0.0;
  835. // // }
  836. // priceRed = couponList[index]
  837. // .coupon
  838. // .price;
  839. // redChiose =
  840. // couponList[index]
  841. // .coupon
  842. // .name ??
  843. // "";
  844. // typeIdssRed =
  845. // couponList[index].id;
  846. // }
  847. // if ((priceTotal -
  848. // priceCoupon -
  849. // priceRed) <
  850. // 0) {
  851. // priceTotal = 0;
  852. // } else {
  853. // priceTotal = priceTotal -
  854. // priceCoupon -
  855. // priceRed;
  856. // }
  857. // couponList = [];
  858. // });
  859. // },
  860. // child: Container(
  861. // // width: width / 4 - 17,
  862. // padding: EdgeInsets.only(
  863. // bottom: ScreenUtil()
  864. // .setWidth(10),
  865. // left: ScreenUtil()
  866. // .setWidth(10),
  867. // right: ScreenUtil()
  868. // .setWidth(10),
  869. // top: ScreenUtil()
  870. // .setWidth(10)),
  871. // margin: EdgeInsets.only(
  872. // left: 5,
  873. // right: 5,
  874. // bottom: 5,
  875. // top: 5),
  876. // decoration: BoxDecoration(
  877. // // border: Border(
  878. // // bottom: BorderSide(width: 0.5, color: Colours.line),
  879. // // ),
  880. // color: Color(0xfff5f5f5)),
  881. // child: Text(
  882. // couponList[index]
  883. // .coupon
  884. // .name ??
  885. // "",
  886. // style: typeName == "卡券"
  887. // ? TextStyle(
  888. // color: typeIdssCoupon ==
  889. // couponList[
  890. // index]
  891. // .id
  892. // ? Color(
  893. // 0xffff0000)
  894. // : Color(
  895. // 0xff000000),
  896. // fontSize: ScreenUtil()
  897. // .setSp(14))
  898. // : TextStyle(
  899. // color: typeIdssRed ==
  900. // couponList[
  901. // index]
  902. // .id
  903. // ? Color(
  904. // 0xffff0000)
  905. // : Color(
  906. // 0xff000000),
  907. // fontSize: ScreenUtil()
  908. // .setSp(14)),
  909. // textAlign: TextAlign.center,
  910. // ),
  911. // ),
  912. // );
  913. }).toList(),
  914. ))
  915. : Center(child: Text("暂无")),
  916. ],
  917. )))
  918. : Container(child: null),
  919. ],
  920. ))
  921. : Center(
  922. child: Text("正在加载..."),
  923. ),
  924. ),
  925. );
  926. }
  927. hongbaoCell(index) {
  928. // typeName == "卡券"
  929. return InkWell(
  930. onTap: () {
  931. setState(() {
  932. priceTotal = detailObj.totalCost;
  933. sortBool = true;
  934. if (typeName == "卡券") {
  935. priceCoupon = couponList[index].coupon.discount;
  936. couponChiose = couponList[index].coupon.name ?? "";
  937. typeIdssCoupon = couponList[index].id;
  938. } else if (typeName == "红包") {
  939. priceRed = couponList[index].coupon.price;
  940. redChiose = couponList[index].coupon.name ?? "";
  941. typeIdssRed = couponList[index].id;
  942. }
  943. if ((priceTotal - priceCoupon - priceRed) < 0) {
  944. priceTotal = 0;
  945. } else {
  946. priceTotal = priceTotal - priceCoupon - priceRed;
  947. }
  948. couponList = [];
  949. });
  950. },
  951. child: typeName == "红包"
  952. ? Container(
  953. margin: EdgeInsets.only(left: 0, right: 0, bottom: 5, top: 5),
  954. child: Stack(
  955. children: [
  956. Container(
  957. height: 80,
  958. width: 300,
  959. // color: Colors.red,
  960. child: LoadAssetImage(
  961. "hongbaoBg",
  962. fit: BoxFit.fill,
  963. ),
  964. ),
  965. Container(
  966. height: 80,
  967. width: 300,
  968. // width: width / 4 - 17,
  969. padding: EdgeInsets.only(
  970. bottom: ScreenUtil().setWidth(10),
  971. left: ScreenUtil().setWidth(10),
  972. right: ScreenUtil().setWidth(10),
  973. top: ScreenUtil().setWidth(10)),
  974. margin:
  975. EdgeInsets.only(left: 5, right: 5, bottom: 5, top: 5),
  976. child: Row(
  977. children: [
  978. Text('¥${couponList[index].coupon.price}',
  979. style:
  980. TextStyle(color: Colors.red, fontSize: 25)),
  981. Text(' ¥${couponList[index].coupon.name}',
  982. style:
  983. TextStyle(color: Colors.red, fontSize: 13)),
  984. Expanded(child: Container()),
  985. Text('立即使用',
  986. style:
  987. TextStyle(color: Colors.red, fontSize: 14)),
  988. ],
  989. )),
  990. Positioned(
  991. top: 0,
  992. left: 0,
  993. child: Container(
  994. color: Color(0xFFDDD9),
  995. child: Text(' 通用红包 ',
  996. style: TextStyle(color: Colors.red)),
  997. ))
  998. ],
  999. ))
  1000. : Container(
  1001. margin: EdgeInsets.only(left: 0, right: 0, bottom: 5, top: 5),
  1002. child: Stack(
  1003. children: [
  1004. Positioned(
  1005. top: 0,
  1006. left: -10,
  1007. // right: -30,
  1008. child: Container(
  1009. width: 300,
  1010. height: 122,
  1011. child: LoadAssetImage(
  1012. // image: AssetImage(i['img']),
  1013. "youhuijuanBg",
  1014. fit: BoxFit.fill,
  1015. // alignment: Alignment.centerLeft,
  1016. ),
  1017. )),
  1018. Container(
  1019. // decoration: BoxDecoration(
  1020. // border:Border.all(
  1021. // width:2,
  1022. // color:Colors.red
  1023. // )
  1024. // ),
  1025. width: 300,
  1026. height: 90,
  1027. child: Row(
  1028. children: <Widget>[
  1029. Container(
  1030. // padding: EdgeInsets.only(right: 10, left: 15),
  1031. child: Column(
  1032. crossAxisAlignment: CrossAxisAlignment.start,
  1033. mainAxisAlignment: MainAxisAlignment.center,
  1034. children: <Widget>[
  1035. Container(
  1036. width: 100,
  1037. child: Row(
  1038. crossAxisAlignment:
  1039. CrossAxisAlignment.end,
  1040. mainAxisAlignment:
  1041. MainAxisAlignment.center,
  1042. children: <Widget>[
  1043. Text(
  1044. '¥',
  1045. textAlign: TextAlign.left,
  1046. style: TextStyle(
  1047. fontSize: ScreenUtil().setSp(16),
  1048. color: Colors.white),
  1049. ),
  1050. Text(
  1051. // '999.0',
  1052. '${couponList[index].coupon?.discount ?? ''}',
  1053. textAlign: TextAlign.left,
  1054. style: TextStyle(
  1055. fontSize: ScreenUtil().setSp(20),
  1056. color: Colors.white,
  1057. fontWeight: FontWeight.bold),
  1058. ),
  1059. SizedBox(
  1060. width: 20,
  1061. )
  1062. ],
  1063. ),
  1064. ),
  1065. Container(
  1066. margin: EdgeInsets.only(left: 20),
  1067. padding: EdgeInsets.fromLTRB(5, 1, 5, 1),
  1068. child: Text(
  1069. // getScenario(provider
  1070. // .list[index]
  1071. // .coupon
  1072. // ?.scenario ??
  1073. // 0),
  1074. '代金劵',
  1075. textAlign: TextAlign.center,
  1076. style: TextStyle(
  1077. fontSize: ScreenUtil().setSp(11),
  1078. color: Colors.white),
  1079. ),
  1080. decoration: new BoxDecoration(
  1081. //背景
  1082. // color: Colors.white,
  1083. //设置四周圆角 角度
  1084. borderRadius: BorderRadius.all(
  1085. Radius.circular(4.0)),
  1086. //设置四周边框
  1087. border: Border.all(
  1088. width: 1, color: Colors.white),
  1089. ),
  1090. ),
  1091. ]),
  1092. ),
  1093. Container(
  1094. padding: EdgeInsets.only(top: 30),
  1095. child: Column(
  1096. crossAxisAlignment: CrossAxisAlignment.start,
  1097. children: <Widget>[
  1098. Text(
  1099. '${getScenario(couponList[index].coupon?.scenario ?? 0)}${couponList[index].coupon?.name ?? ""}',
  1100. textAlign: TextAlign.left,
  1101. style: TextStyle(
  1102. fontSize: ScreenUtil().setSp(14),
  1103. color: Color(0xff333333),
  1104. ),
  1105. ),
  1106. Text(
  1107. '有效时间: ' +
  1108. DateUtils.instance.getFormartData(
  1109. timeSamp: couponList[index]
  1110. .coupon
  1111. ?.validity ??
  1112. 0,
  1113. format: "yyyy.MM.dd HH:mm"),
  1114. textAlign: TextAlign.left,
  1115. style: TextStyle(
  1116. fontSize: ScreenUtil().setSp(11),
  1117. color: Color(0xff9F9C9F),
  1118. ),
  1119. ),
  1120. SizedBox(height: 5),
  1121. Container(
  1122. width: 230 * 0.5,
  1123. height: 0.5,
  1124. color: Color(0xffeeeeee),
  1125. child: null,
  1126. ),
  1127. SizedBox(height: 3),
  1128. Text(
  1129. couponList[index].coupon?.remark ?? "",
  1130. textAlign: TextAlign.left,
  1131. style: TextStyle(
  1132. fontSize: ScreenUtil().setSp(11),
  1133. color: Color(0xff9F9C9F),
  1134. ),
  1135. ),
  1136. ])),
  1137. ],
  1138. )),
  1139. ],
  1140. )),
  1141. );
  1142. }
  1143. Widget loadCircle() {
  1144. return Container(
  1145. padding: EdgeInsets.only(top: 10, bottom: 10),
  1146. color: ThemeUtils.getTabsBg(context),
  1147. child: Center(
  1148. child: SpinKitFadingCircle(
  1149. color: Colors.blueAccent,
  1150. size: 30.0,
  1151. ),
  1152. ),
  1153. );
  1154. }
  1155. }
  1156. class ChioseThisRight extends StatelessWidget {
  1157. ChioseThisRight(
  1158. {Key key,
  1159. this.value,
  1160. this.label,
  1161. this.fun,
  1162. this.labelText,
  1163. this.labelTextColor = const Color(0xffcccccc)})
  1164. : super(key: key);
  1165. String value;
  1166. String label;
  1167. Function fun;
  1168. String labelText;
  1169. Color labelTextColor;
  1170. @override
  1171. Widget build(BuildContext context) {
  1172. double width = MediaQuery.of(context).size.width;
  1173. return InkWell(
  1174. onTap: () {
  1175. fun();
  1176. },
  1177. child: Container(
  1178. padding: EdgeInsets.only(
  1179. top: ScreenUtil().setWidth(15), bottom: ScreenUtil().setWidth(15)),
  1180. margin: EdgeInsets.only(left: ScreenUtil().setWidth(15)),
  1181. decoration: BoxDecoration(
  1182. border: Border(
  1183. bottom: BorderSide(width: 0.5, color: Colours.line),
  1184. ),
  1185. ),
  1186. child: Row(
  1187. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1188. children: <Widget>[
  1189. Text(
  1190. label,
  1191. style: TextStyle(
  1192. color: Color(0xff222222),
  1193. // fontSize: ScreenUtil().setSp(14)
  1194. ),
  1195. textAlign: TextAlign.start,
  1196. ),
  1197. value.isEmpty
  1198. ? Container(
  1199. child: Row(children: <Widget>[
  1200. Text(
  1201. labelText,
  1202. style: TextStyle(
  1203. color: labelTextColor,
  1204. // fontSize: ScreenUtil().setSp(14)
  1205. ),
  1206. textAlign: TextAlign.start,
  1207. ),
  1208. Container(
  1209. padding: EdgeInsets.only(top: 3),
  1210. child: Icon(
  1211. Icons.keyboard_arrow_right,
  1212. size: 20.0,
  1213. color: labelTextColor,
  1214. ),
  1215. ),
  1216. SizedBox(width: 10)
  1217. ]),
  1218. )
  1219. : Container(
  1220. padding:
  1221. EdgeInsets.only(right: ScreenUtil().setWidth(15)),
  1222. child: Row(children: <Widget>[
  1223. Text(
  1224. value,
  1225. style: TextStyle(
  1226. color: Color(0xff222222),
  1227. fontSize: ScreenUtil().setSp(14)),
  1228. textAlign: TextAlign.start,
  1229. ),
  1230. ]),
  1231. ),
  1232. ]),
  1233. ),
  1234. );
  1235. }
  1236. }