buy_service.dart 57 KB

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