buy_service.dart 43 KB

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