buy_service.dart 38 KB

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