buy_service.dart 43 KB

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