buy_service.dart 46 KB

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