main.dart 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:io';
  4. import 'package:amap_location/amap_location.dart';
  5. import 'package:bbyyy/beans/access_bean_entity.dart';
  6. import 'package:bbyyy/beans/template_bean_entity.dart';
  7. import 'package:bbyyy/beans/w_x_bean_entity.dart';
  8. import 'package:bbyyy/https/url.dart';
  9. import 'package:bbyyy/my_tools/event_bus.dart';
  10. import 'package:bbyyy/my_tools/my_cookie.dart';
  11. import 'package:bbyyy/my_tools/my_tools.dart';
  12. import 'package:bbyyy/paegs/login_page/login_page.dart';
  13. import 'package:bbyyy/paegs/pay_page/order_information_page.dart';
  14. import 'package:bbyyy/paegs/root_page/root_page.dart';
  15. import 'package:bbyyy/paegs/root_page/root_page_view.dart';
  16. import 'package:bbyyy/paegs/welcome_page/welcome_page.dart';
  17. import 'package:dio/dio.dart';
  18. import 'package:flustars/flustars.dart';
  19. import 'package:flutter/cupertino.dart';
  20. import 'package:flutter/material.dart';
  21. import 'package:flutter/services.dart';
  22. import 'package:flutter_local_notifications/flutter_local_notifications.dart';
  23. import 'package:flutter_localizations/flutter_localizations.dart';
  24. import 'package:flutter_svg/flutter_svg.dart';
  25. import 'package:fluwx/fluwx.dart';
  26. import 'package:pull_to_refresh/pull_to_refresh.dart';
  27. import 'package:rxdart/rxdart.dart';
  28. import 'beans/coupon_bean_entity.dart';
  29. import 'beans/my_shop_bean_entity.dart';
  30. import 'beans/new_order_bean_entity.dart';
  31. import 'beans/smart_order_bean_entity.dart';
  32. import 'beans/system_information_bean_entity.dart';
  33. import 'https/MyDio.dart';
  34. import 'https/my_request.dart';
  35. import 'my_tools/const.dart';
  36. import 'my_tools/dims.dart';
  37. import 'my_tools/easy_loading/easy_loading.dart';
  38. import 'my_tools/easy_loading/loading.dart';
  39. import 'my_tools/global.dart';
  40. import 'my_tools/my_colors.dart';
  41. import 'my_tools/my_views.dart';
  42. import 'my_tools/order.dart';
  43. import 'my_tools/pop_up_queue.dart';
  44. final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
  45. FlutterLocalNotificationsPlugin();
  46. final BehaviorSubject<ReceivedNotification> didReceiveLocalNotificationSubject =
  47. BehaviorSubject<ReceivedNotification>();
  48. final BehaviorSubject<String> selectNotificationSubject =
  49. BehaviorSubject<String>();
  50. class ReceivedNotification {
  51. ReceivedNotification({
  52. @required this.id,
  53. @required this.title,
  54. @required this.body,
  55. @required this.payload,
  56. });
  57. final int id;
  58. final String title;
  59. final String body;
  60. final String payload;
  61. }
  62. Future<void> main() async {
  63. if (Platform.isIOS) {
  64. AMapLocationClient.setApiKey('548414a843a2ec9c383e34341b8c84df');
  65. }
  66. WidgetsFlutterBinding.ensureInitialized();
  67. const AndroidInitializationSettings initializationSettingsAndroid =
  68. AndroidInitializationSettings('@mipmap/app_logo');
  69. /// Note: permissions aren't requested here just to demonstrate that can be
  70. /// done later
  71. final IOSInitializationSettings initializationSettingsIOS =
  72. IOSInitializationSettings(
  73. requestAlertPermission: true,
  74. requestBadgePermission: true,
  75. requestSoundPermission: true,
  76. onDidReceiveLocalNotification:
  77. (int id, String title, String body, String payload) async {
  78. didReceiveLocalNotificationSubject.add(ReceivedNotification(
  79. id: id, title: title, body: body, payload: payload));
  80. });
  81. const MacOSInitializationSettings initializationSettingsMacOS =
  82. MacOSInitializationSettings(
  83. requestAlertPermission: true,
  84. requestBadgePermission: true,
  85. requestSoundPermission: true);
  86. final InitializationSettings initializationSettings = InitializationSettings(
  87. android: initializationSettingsAndroid,
  88. iOS: initializationSettingsIOS,
  89. macOS: initializationSettingsMacOS);
  90. await flutterLocalNotificationsPlugin.initialize(initializationSettings,
  91. onSelectNotification: (String payload) async {
  92. if (payload != null) {
  93. if (payload == notifyTypeNewMsg) {
  94. RootPageView().bNIndex = 2;
  95. EventBus().emit('ChangePage');
  96. }
  97. debugPrint('notification payload: $payload');
  98. }
  99. selectNotificationSubject.add(payload);
  100. });
  101. runApp(MyApp());
  102. }
  103. class MyApp extends StatelessWidget with WidgetsBindingObserver {
  104. BuildContext buildContext;
  105. StateSetter ss;
  106. List<MyShopBeanDataData> shops = [];
  107. int shopIndex = 0;
  108. String clipboardT;
  109. int amountCompleted = 0;
  110. NewOrderBeanEntity newOrder;
  111. @override
  112. StatelessElement createElement() {
  113. // TODO: implement createElement
  114. WidgetsBinding.instance.addObserver(this);
  115. MyCookie().initP();
  116. _initFluwx();
  117. EventBus().on('hasNewOrder', (arg) {
  118. newOrder = arg;
  119. displayPendingOrders();
  120. });
  121. EventBus().on('systemInformation', (arg) {
  122. if (arg is SystemInformationBeanEntity) {
  123. showSystemMessages(arg);
  124. }
  125. });
  126. EventBus().on('检查粘贴板', (arg) {
  127. Timer(Duration(seconds: 1), () {
  128. getClipboardData();
  129. });
  130. });
  131. EventBus().on('hasCoupon', (arg) {
  132. if (arg is CouponBeanDataData) {
  133. couponBulletBox(arg);
  134. }
  135. });
  136. return super.createElement();
  137. }
  138. @override
  139. Widget build(BuildContext context) {
  140. return RefreshConfiguration(
  141. child: MaterialApp(
  142. navigatorKey: navigatorKey,
  143. theme: ThemeData(fontFamily: 'PingFang'),
  144. debugShowCheckedModeBanner: false,
  145. home: WelcomePage(),
  146. routes: {
  147. '/loginPage': (context) => LoginPage(),
  148. '/rootPage': (context) => RootPage(),
  149. },
  150. supportedLocales: [const Locale('zh', 'CH')],
  151. localizationsDelegates: [
  152. RefreshLocalizations.delegate,
  153. GlobalMaterialLocalizations.delegate,
  154. GlobalWidgetsLocalizations.delegate,
  155. const FallbackCupertinoLocalisationsDelegate(),
  156. ],
  157. builder: (BuildContext context, Widget child) {
  158. buildContext = context;
  159. return MediaQuery(
  160. data: MediaQuery.of(context)
  161. .copyWith(textScaleFactor: 1.0), //设置字体不随系统字体大小改变
  162. child: FlutterEasyLoading(
  163. child: child,
  164. ),
  165. );
  166. },
  167. ),
  168. hideFooterWhenNotFull: true,
  169. footerBuilder: () {
  170. return ClassicFooter(
  171. loadStyle: LoadStyle.ShowWhenLoading,
  172. );
  173. },
  174. );
  175. }
  176. @override
  177. void didChangeAppLifecycleState(AppLifecycleState state) {
  178. super.didChangeAppLifecycleState(state);
  179. if (state == AppLifecycleState.paused) {
  180. print('went to Background');
  181. }
  182. if (state == AppLifecycleState.resumed) {
  183. print('came back to Foreground');
  184. if (MyCookie().loginInformation != null) {
  185. Timer(Duration(seconds: 1), () {
  186. getClipboardData();
  187. });
  188. }
  189. }
  190. }
  191. //获取剪切板文字
  192. Future<void> getClipboardData() async {
  193. PopUpQueue().onShow = true;
  194. ClipboardData text = await Clipboard.getData(Clipboard.kTextPlain);
  195. try {
  196. print('Clipboard-----\n${text.text}');
  197. clipboardT = text.text;
  198. Clipboard.setData(ClipboardData(text: ''));
  199. getOnlineTemplate();
  200. } catch (e) {
  201. PopUpQueue().onShow = false;
  202. PopUpQueue().showNext();
  203. }
  204. }
  205. //获取线上模板
  206. void getOnlineTemplate() {
  207. MyDio().query({
  208. 'key': 'order_template',
  209. "dims": ["id", "sid", "template"],
  210. "filters": {}
  211. }, (response, hasError) {
  212. if (!hasError) {
  213. TemplateBeanEntity entity = TemplateBeanEntity()
  214. .fromJson(json.decode(response.data.toString()));
  215. checkOrder(entity.data);
  216. } else {
  217. PopUpQueue().onShow = false;
  218. PopUpQueue().showNext();
  219. }
  220. }, (error) {
  221. PopUpQueue().onShow = false;
  222. PopUpQueue().showNext();
  223. });
  224. }
  225. var orderHash;
  226. //匹配模板去除不是自己的订单
  227. void checkOrder(List<TemplateBeanData> data) {
  228. bool hasMatch = false;
  229. w:
  230. for (int i = 0; i < data.length; i++) {
  231. try {
  232. var res = parseString2(
  233. data[i].template.replaceAll('\r', ''), '''$clipboardT''');
  234. if (res != null) {
  235. print(data[i].template);
  236. print(json.encode(res));
  237. var order = parse2(res);
  238. order.removeWhere((element) =>
  239. !element.seller.name
  240. .contains(MyCookie().loginInformation.data.extra.name) &&
  241. !MyCookie()
  242. .loginInformation
  243. .data
  244. .extra
  245. .name
  246. .contains(element.seller.name));
  247. if (order.length > 0) {
  248. hasMatch = true;
  249. orderHash = computeOrderHash(res);
  250. getShop(order);
  251. }
  252. break w;
  253. }
  254. } catch (e) {}
  255. }
  256. if (!hasMatch) {
  257. PopUpQueue().onShow = false;
  258. PopUpQueue().showNext();
  259. }
  260. }
  261. //订单视图
  262. items(List<OrderInfo2> order) {
  263. List<Widget> items = [];
  264. order.forEach((element) {
  265. items.add(Container(
  266. child: Column(
  267. children: [
  268. Row(
  269. children: [
  270. Container(
  271. margin: EdgeInsets.only(left: 8, right: 7),
  272. child: ClipRRect(
  273. child: MyViews().netImg(
  274. imgURL(MyCookie().loginInformation.data.extra.picture),
  275. 35,
  276. 35),
  277. borderRadius: BorderRadius.circular(17.5),
  278. ),
  279. ),
  280. Expanded(
  281. child: Container(
  282. height: 35,
  283. child: Column(
  284. children: [
  285. Text(
  286. '付款人:${element.payer.name}',
  287. style: TextStyle(
  288. color: MyColors.c333333,
  289. fontSize: 13,
  290. decoration: TextDecoration.none,
  291. ),
  292. ),
  293. Text(
  294. '订单时间:${element.time}',
  295. style: TextStyle(
  296. color: MyColors.c666666,
  297. fontSize: 10,
  298. decoration: TextDecoration.none,
  299. ),
  300. ),
  301. ],
  302. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  303. crossAxisAlignment: CrossAxisAlignment.start,
  304. ),
  305. ),
  306. ),
  307. Container(
  308. margin: EdgeInsets.only(right: 10),
  309. child: Text(
  310. '¥${(element.payer.amount * element.factor).toStringAsFixed(2)}',
  311. style: TextStyle(
  312. color: MyColors.cFF4233,
  313. fontSize: 14,
  314. decoration: TextDecoration.none,
  315. ),
  316. ),
  317. ),
  318. ],
  319. crossAxisAlignment: CrossAxisAlignment.center,
  320. ),
  321. Container(
  322. height: 0.5,
  323. margin: EdgeInsets.only(right: 10, left: 50, top: 5),
  324. color: MyColors.cE7E7E7,
  325. )
  326. ],
  327. ),
  328. margin: EdgeInsets.only(top: 5),
  329. ));
  330. });
  331. return items;
  332. }
  333. bool saving = false;
  334. //获取用户所在店铺
  335. void getShop(List<OrderInfo2> order) {
  336. shopIndex = 0;
  337. MyDio().query({
  338. "key": "shop_user",
  339. "filters": {
  340. "or": true,
  341. "conditions": [
  342. "role!=0",
  343. "user_uid==${MyCookie().getUID()}",
  344. "review_state==1"
  345. ],
  346. "filters": [
  347. {
  348. "conditions": ["role==0", "user_uid==${MyCookie().getUID()}"]
  349. }
  350. ]
  351. },
  352. "dims": shopUserDims,
  353. "paging": [1, 20000]
  354. }, (response, hasError) {
  355. if (!hasError) {
  356. MyShopBeanEntity entity =
  357. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  358. shops = entity.data.data;
  359. shops.removeWhere((element) => !element.privateShop);
  360. if (shops.length == 0) {
  361. showToast('你还没有添加任何货帮,暂时不能发送智能订单');
  362. PopUpQueue().onShow = false;
  363. PopUpQueue().showNext();
  364. } else {
  365. EasyLoading.instance
  366. ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12)
  367. ..alignment = Alignment.bottomCenter
  368. ..loadingStyle = EasyLoadingStyle.light
  369. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  370. EasyLoading.show(
  371. indicator: Material(
  372. color: Colors.white,
  373. child: StatefulBuilder(
  374. builder: (c, s) {
  375. ss = s;
  376. return Column(
  377. children: [
  378. Container(
  379. child: Stack(
  380. children: [
  381. Container(
  382. child: MyViews()
  383. .myText('智能订单', MyColors.c333333, 14),
  384. alignment: Alignment.center,
  385. height: 22,
  386. ),
  387. Positioned(
  388. right: 0,
  389. child: GestureDetector(
  390. onTap: () {
  391. PopUpQueue().onShow = false;
  392. PopUpQueue().showNext();
  393. },
  394. behavior: HitTestBehavior.translucent,
  395. child: Container(
  396. child: Icon(
  397. Icons.close,
  398. size: 20,
  399. color: Colors.white,
  400. ),
  401. decoration: BoxDecoration(
  402. color: MyColors.cB6B6B6,
  403. borderRadius: BorderRadius.circular(11)),
  404. height: 22,
  405. width: 22,
  406. ),
  407. ),
  408. )
  409. ],
  410. alignment: Alignment.center,
  411. ),
  412. height: 30,
  413. padding: EdgeInsets.symmetric(horizontal: 12),
  414. ),
  415. Container(
  416. height: 5,
  417. color: MyColors.cF7F7F7,
  418. margin: EdgeInsets.only(top: 10),
  419. ),
  420. Column(
  421. children: items(order),
  422. ),
  423. Container(
  424. height: 5,
  425. color: MyColors.cF7F7F7,
  426. margin: EdgeInsets.only(top: 10),
  427. ),
  428. Visibility(
  429. child: Column(
  430. children: [
  431. Container(
  432. child: MyViews()
  433. .myText('货帮选择', MyColors.c333333, 13),
  434. margin: EdgeInsets.only(left: 7, top: 11),
  435. ),
  436. Container(
  437. margin: EdgeInsets.symmetric(
  438. horizontal: 7, vertical: 10),
  439. height: (shops.length * 1.0 / 2).ceil() *
  440. (double.parse(
  441. '${MediaQuery.of(buildContext).size.width - 74}') /
  442. 2 /
  443. 3.8 +
  444. 10) -
  445. 10,
  446. child: GridView(
  447. gridDelegate:
  448. SliverGridDelegateWithFixedCrossAxisCount(
  449. crossAxisCount: 2, //横轴三个子widget
  450. childAspectRatio: 3.8,
  451. crossAxisSpacing: 10,
  452. mainAxisSpacing: 8 //宽高比为1时,子widget
  453. ),
  454. children: shop(shops),
  455. padding: EdgeInsets.all(0),
  456. ),
  457. ),
  458. ],
  459. crossAxisAlignment: CrossAxisAlignment.start,
  460. ),
  461. visible: shops.length != 1,
  462. ),
  463. Container(
  464. height: 0.5,
  465. color: MyColors.cF7F7F7,
  466. margin: EdgeInsets.only(bottom: 10),
  467. ),
  468. Container(
  469. child: GestureDetector(
  470. onTap: () {
  471. if (saving) {
  472. return;
  473. } else {
  474. saving = true;
  475. EventBus().on('saveOrder', (arg) {
  476. amountCompleted++;
  477. if (amountCompleted == order.length) {
  478. amountCompleted = 0;
  479. EasyLoading.dismiss();
  480. showToast('发送成功');
  481. clipboardT = '';
  482. saving = false;
  483. EventBus().off('saveOrder');
  484. PopUpQueue().onShow = false;
  485. PopUpQueue().showNext();
  486. }
  487. });
  488. order.forEach((element) {
  489. sendOrder(element);
  490. });
  491. }
  492. },
  493. behavior: HitTestBehavior.translucent,
  494. child: Container(
  495. decoration: BoxDecoration(
  496. color: MyColors.cFF4233,
  497. borderRadius: BorderRadius.circular(20),
  498. ),
  499. height: 40,
  500. width: 150,
  501. child: MyViews().myText('发送订单', Colors.white, 14),
  502. alignment: Alignment.center,
  503. ),
  504. ),
  505. alignment: Alignment.center,
  506. )
  507. ],
  508. mainAxisAlignment: MainAxisAlignment.start,
  509. crossAxisAlignment: CrossAxisAlignment.start,
  510. );
  511. },
  512. ),
  513. ),
  514. );
  515. }
  516. } else {
  517. PopUpQueue().onShow = false;
  518. PopUpQueue().showNext();
  519. }
  520. }, (error) {
  521. PopUpQueue().onShow = false;
  522. PopUpQueue().showNext();
  523. });
  524. }
  525. //店铺视图
  526. shop(List<MyShopBeanDataData> shops) {
  527. List<Widget> items = [];
  528. for (int i = 0; i < shops.length; i++) {
  529. items.add(GestureDetector(
  530. onTap: () {
  531. shopIndex = i;
  532. ss(() {});
  533. },
  534. behavior: HitTestBehavior.translucent,
  535. child: Container(
  536. child: Row(
  537. children: [
  538. Container(
  539. margin: EdgeInsets.only(right: 5),
  540. child: ClipRRect(
  541. child: MyViews().netImg(imgURL(shops[i].shopPic), 30, 30),
  542. borderRadius: BorderRadius.circular(15),
  543. ),
  544. ),
  545. Expanded(
  546. child: Column(
  547. children: [
  548. Text(
  549. shops[i].shopName,
  550. style: TextStyle(
  551. color: i == shopIndex
  552. ? MyColors.cFF4233
  553. : MyColors.c666666,
  554. fontSize: 12,
  555. ),
  556. maxLines: 1,
  557. overflow: TextOverflow.ellipsis,
  558. softWrap: true,
  559. ),
  560. Text(
  561. 'ID:${shops[i].shopUid}',
  562. style: TextStyle(
  563. color: i == shopIndex
  564. ? MyColors.cFF4233
  565. : MyColors.c666666,
  566. fontSize: 10,
  567. ),
  568. maxLines: 1,
  569. overflow: TextOverflow.ellipsis,
  570. softWrap: true,
  571. ),
  572. ],
  573. crossAxisAlignment: CrossAxisAlignment.start,
  574. ),
  575. ),
  576. ],
  577. ),
  578. decoration: BoxDecoration(
  579. color: i == shopIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  580. borderRadius: BorderRadius.circular(4),
  581. ),
  582. constraints: BoxConstraints(maxWidth: 150),
  583. padding: EdgeInsets.symmetric(horizontal: 6, vertical: 6),
  584. ),
  585. ));
  586. }
  587. return items;
  588. }
  589. //发送订单
  590. void sendOrder(OrderInfo2 element) {
  591. MyDio().save({
  592. 'key': 'order',
  593. 'object': {
  594. 'uuid': orderHash,
  595. 'shop_uid': shops[shopIndex].shopUid,
  596. 'shop_pic': shops[shopIndex].shopPic,
  597. 'shop_name': shops[shopIndex].shopName,
  598. 'seller_pic': MyCookie().loginInformation.data.extra.picture,
  599. 'seller_uid': MyCookie().getUID(),
  600. 'seller_name': MyCookie().loginInformation.data.extra.name,
  601. 'buyer_name': element.payer.name,
  602. 'type': orderTypeThirdPlatform,
  603. 'amount': NumUtil.multiply(element.payer.amount, element.factor)
  604. }
  605. }, (response, hasError) {
  606. if (!hasError) {
  607. EventBus().emit('saveOrder');
  608. }
  609. }, (error) {});
  610. }
  611. //待支付订单视图
  612. void displayPendingOrders() {
  613. EasyLoading.instance
  614. ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12)
  615. ..alignment = Alignment.bottomCenter
  616. ..loadingStyle = EasyLoadingStyle.light
  617. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  618. EasyLoading.show(
  619. indicator: Material(
  620. color: Colors.white,
  621. child: Column(
  622. children: [
  623. Container(
  624. padding: EdgeInsets.symmetric(horizontal: 12),
  625. child: Row(
  626. children: [
  627. Container(
  628. margin: EdgeInsets.only(right: 7),
  629. child: ClipRRect(
  630. child: MyViews()
  631. .netImg(imgURL(newOrder.content.shopPic), 25, 25),
  632. borderRadius: BorderRadius.circular(12.5),
  633. ),
  634. ),
  635. MyViews().myText(
  636. '${newOrder.content.shopName}(${newOrder.content.shopUID})',
  637. MyColors.c333333,
  638. 14),
  639. ],
  640. ),
  641. ),
  642. Container(
  643. margin: EdgeInsets.only(top: 11, left: 12, right: 12, bottom: 11),
  644. height: 0.5,
  645. color: MyColors.cE7E7E7,
  646. ),
  647. Container(
  648. margin: EdgeInsets.symmetric(horizontal: 12),
  649. child: Row(
  650. children: [
  651. Container(
  652. child: SvgPicture.asset(
  653. newOrder.content.buyerPic == null
  654. ? 'images/svg/第三方.svg'
  655. : 'images/svg/线下付款.svg',
  656. height: 27,
  657. width: 27,
  658. ),
  659. margin: EdgeInsets.only(right: 8),
  660. height: 45,
  661. width: 45,
  662. decoration: BoxDecoration(
  663. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  664. alignment: Alignment.center,
  665. ),
  666. Expanded(
  667. child: Container(
  668. height: 45,
  669. child: Column(
  670. children: [
  671. MyViews().myText(
  672. newOrder.content.buyerPic == null
  673. ? '第三方订单'
  674. : '线下付款',
  675. MyColors.c333333,
  676. 13),
  677. Row(
  678. children: [
  679. MyViews().myText('¥${newOrder.content.amount}',
  680. MyColors.cFF4233, 12),
  681. MyViews().myText('x1', MyColors.c999999, 12),
  682. ],
  683. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  684. )
  685. ],
  686. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  687. crossAxisAlignment: CrossAxisAlignment.start,
  688. ),
  689. ),
  690. ),
  691. ],
  692. ),
  693. ),
  694. Container(
  695. height: 0.5,
  696. color: MyColors.cE7E7E7,
  697. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  698. ),
  699. Container(
  700. margin: EdgeInsets.symmetric(horizontal: 12),
  701. child: Row(
  702. children: [
  703. MyViews().myText('卖家信息:', MyColors.c333333, 13),
  704. Row(
  705. children: [
  706. Container(
  707. margin: EdgeInsets.only(right: 5),
  708. child: ClipRRect(
  709. child: MyViews().netImg(
  710. imgURL(newOrder.content.sellerPic), 23, 23),
  711. borderRadius: BorderRadius.circular(11.5),
  712. ),
  713. ),
  714. MyViews().myText(
  715. '${newOrder.content.sellerName}(${hideUID(newOrder.content.sellerUID.toString())})',
  716. MyColors.c333333,
  717. 13),
  718. ],
  719. )
  720. ],
  721. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  722. ),
  723. ),
  724. Container(
  725. height: 0.5,
  726. color: MyColors.cE7E7E7,
  727. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  728. ),
  729. Container(
  730. margin: EdgeInsets.symmetric(horizontal: 12),
  731. child: Row(
  732. children: [
  733. MyViews().myText('买家信息:', MyColors.c333333, 13),
  734. Row(
  735. children: [
  736. Container(
  737. margin: EdgeInsets.only(right: 5),
  738. child: ClipRRect(
  739. child: MyViews().netImg(
  740. newOrder.content.buyerPic == null
  741. ? ''
  742. : imgURL(newOrder.content.buyerPic),
  743. 23,
  744. 23),
  745. borderRadius: BorderRadius.circular(11.5),
  746. ),
  747. ),
  748. MyViews().myText(
  749. '${newOrder.content.buyerName} ${newOrder.content.buyerUID != null && newOrder.content.buyerUID.toString().length > 0 ? '(${newOrder.content.buyerUID})' : ''}',
  750. MyColors.c333333,
  751. 13),
  752. ],
  753. )
  754. ],
  755. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  756. ),
  757. ),
  758. Container(
  759. height: 0.5,
  760. color: MyColors.cE7E7E7,
  761. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  762. ),
  763. Container(
  764. margin: EdgeInsets.symmetric(horizontal: 12),
  765. child: Row(
  766. children: [
  767. MyViews().myText('下单时间:', MyColors.c333333, 13),
  768. MyViews().myText(
  769. '${newOrder.content.createTime}', MyColors.c333333, 13)
  770. ],
  771. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  772. ),
  773. ),
  774. Container(
  775. height: 0.5,
  776. color: MyColors.cE7E7E7,
  777. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  778. ),
  779. Container(
  780. margin: EdgeInsets.symmetric(horizontal: 20),
  781. child: Row(
  782. children: [
  783. Expanded(
  784. child: GestureDetector(
  785. onTap: () {
  786. PopUpQueue().onShow = false;
  787. PopUpQueue().showNext();
  788. },
  789. behavior: HitTestBehavior.translucent,
  790. child: Container(
  791. decoration: BoxDecoration(
  792. borderRadius: BorderRadius.only(
  793. topLeft: Radius.circular(20),
  794. bottomLeft: Radius.circular(20),
  795. ),
  796. border: Border.all(
  797. color: MyColors.cFF4233, width: 1)),
  798. height: 40,
  799. child: MyViews().myText('与我无瓜', MyColors.cFF4233, 14),
  800. alignment: Alignment.center),
  801. ),
  802. ),
  803. Expanded(
  804. child: GestureDetector(
  805. onTap: () {
  806. if (newOrder.content.buyerName
  807. .contains(MyCookie().getName()) ||
  808. MyCookie()
  809. .getName()
  810. .contains(newOrder.content.buyerName)) {
  811. EasyLoading.dismiss();
  812. payTheOrder();
  813. } else {
  814. showToast('该订单与你无关');
  815. PopUpQueue().onShow = false;
  816. PopUpQueue().showNext();
  817. }
  818. },
  819. behavior: HitTestBehavior.translucent,
  820. child: Container(
  821. decoration: BoxDecoration(
  822. borderRadius: BorderRadius.only(
  823. topRight: Radius.circular(20),
  824. bottomRight: Radius.circular(20),
  825. ),
  826. color: MyColors.cFF4233),
  827. height: 40,
  828. child: MyViews().myText('去支付', Colors.white, 14),
  829. alignment: Alignment.center),
  830. ),
  831. )
  832. ],
  833. ),
  834. )
  835. ],
  836. ),
  837. ),
  838. );
  839. }
  840. void payTheOrder() {
  841. //获取店铺信息
  842. MyDio().query({
  843. "key": "shop_user",
  844. "filters": {
  845. "conditions": ["shop_uid==${newOrder.content.shopUID}"]
  846. },
  847. "dims": shopUserDims,
  848. "paging": [1, 1],
  849. "order_by": ["shop_name,DESC"]
  850. }, (response, hasError) {
  851. if (!hasError) {
  852. MyShopBeanEntity entity =
  853. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  854. SmartOrderBeanDataData data = SmartOrderBeanDataData();
  855. data.sellerUid = newOrder.content.sellerUID;
  856. data.sellerName = newOrder.content.sellerName;
  857. data.sellerPic = newOrder.content.sellerPic;
  858. data.buyerUid = 0;
  859. data.buyerName = newOrder.content.buyerName;
  860. data.buyerPic = '';
  861. data.amount = newOrder.content.amount;
  862. data.uid = newOrder.content.uID;
  863. navigatorKey.currentState
  864. .push(MaterialPageRoute(
  865. builder: (context) => OrderInformationPage(
  866. false,
  867. orderType: orderTypeThirdPlatform,
  868. amount: newOrder.content.amount,
  869. uid: newOrder.content.uID,
  870. buyerUid: MyCookie().getUID(),
  871. buyerName: newOrder.content.buyerName,
  872. buyerPic: MyCookie().getPic(),
  873. commodityCount: 1,
  874. commodityTitle: '第三方订单',
  875. commodityCover: '',
  876. sellName: newOrder.content.sellerName,
  877. sellPic: newOrder.content.sellerPic,
  878. sellUid: newOrder.content.sellerUID,
  879. )))
  880. .then((value) {
  881. PopUpQueue().onShow = false;
  882. PopUpQueue().showNext();
  883. });
  884. // navigatorKey.currentState.push(MaterialPageRoute(
  885. // builder: (context) =>
  886. // GangInPage(entity.data.data[0], newOrder.content)));
  887. }
  888. }, (error) {});
  889. // getUserWalletBalance((re, hE) {
  890. // if (!hE) {
  891. // UserBalanceEntity balance =
  892. // UserBalanceEntity().fromJson(json.decode(re.data.toString()));
  893. // if (balance.data >= newOrder.content.amount) {
  894. // payOrder(payWayWallet, newOrder.content.uID, (re, hE) {
  895. // if (!hE) {
  896. // showToast('支付成功');
  897. // EventBus().emit('payAnOrder');
  898. // }
  899. // }, (e) {}, context);
  900. // } else {
  901. // payOrder(payWayAliPay, newOrder.content.uID, (re, hE) {
  902. // if (!hE) {
  903. // PayByAlipayBeanEntity entity = PayByAlipayBeanEntity()
  904. // .fromJson(json.decode(re.data.toString()));
  905. // EventBus().on('alipayPaymentCallback', (arg) {
  906. // EventBus().off('alipayPaymentCallback');
  907. // EasyLoading.dismiss();
  908. // showToast('支付成功');
  909. // EventBus().emit('reNoPayOrder');
  910. // });
  911. // print(entity.data);
  912. // EasyLoading.instance
  913. // ..contentPadding =
  914. // EdgeInsets.symmetric(horizontal: 20, vertical: 12)
  915. // ..alignment = Alignment.center
  916. // ..contentMargin = EdgeInsets.all(20);
  917. // EasyLoading.show();
  918. // aliPay(entity.data).then((value) {
  919. // print(json.encode(value));
  920. // AlipayResultBeanEntity e = AlipayResultBeanEntity()
  921. // .fromJson(json.decode(json.encode(value)));
  922. // try {
  923. // int r = int.parse(e.resultStatus);
  924. // if (r == 9000) {
  925. // showToast('支付成功');
  926. // } else {
  927. // showToast(aliPayResultStatus(r));
  928. // resetOrder(newOrder.content.uID, context);
  929. // }
  930. // } catch (e) {
  931. // EasyLoading.dismiss();
  932. // }
  933. // });
  934. // // EventBus().emit('payAnOrder');
  935. // }
  936. // }, (e) {}, context);
  937. // // showToast('积分余额不足');
  938. // }
  939. // }
  940. // }, (e) {}, context);
  941. }
  942. void showSystemMessages(SystemInformationBeanEntity arg) {
  943. EasyLoading.instance
  944. ..contentPadding = EdgeInsets.symmetric(horizontal: 12, vertical: 12)
  945. ..alignment = Alignment.center
  946. ..loadingStyle = EasyLoadingStyle.custom
  947. ..backgroundColor = Colors.transparent
  948. ..indicatorColor = Colors.black
  949. ..progressColor = Colors.black
  950. ..maskColor = Colors.black
  951. ..textColor = Colors.black
  952. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  953. EasyLoading.show(
  954. indicator: Material(
  955. color: Colors.transparent,
  956. child: Container(
  957. decoration: BoxDecoration(
  958. borderRadius: BorderRadius.circular(16),
  959. ),
  960. height: MediaQuery.of(buildContext).size.height - 200,
  961. padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
  962. child: Column(
  963. children: [
  964. Expanded(child: Container()),
  965. Container(
  966. decoration: BoxDecoration(
  967. color: Colors.white,
  968. borderRadius: BorderRadius.circular(16),
  969. ),
  970. child: Column(
  971. children: [
  972. Container(
  973. child: Text(
  974. '系统消息',
  975. style: TextStyle(
  976. color: MyColors.c333333,
  977. fontSize: 14,
  978. fontWeight: FontWeight.bold),
  979. ),
  980. margin:
  981. EdgeInsets.symmetric(horizontal: 26, vertical: 15),
  982. ),
  983. Container(
  984. child: Text(
  985. arg.content.content,
  986. style: TextStyle(color: MyColors.c333333, fontSize: 14),
  987. ),
  988. margin: EdgeInsets.symmetric(horizontal: 26),
  989. alignment: Alignment.centerLeft,
  990. ),
  991. Container(
  992. height: 0.5,
  993. color: MyColors.cE7E7E7,
  994. margin: EdgeInsets.only(bottom: 12, top: 12),
  995. ),
  996. GestureDetector(
  997. onTap: () {
  998. PopUpQueue().onShow = false;
  999. PopUpQueue().showNext();
  1000. },
  1001. behavior: HitTestBehavior.translucent,
  1002. child: Container(
  1003. width: 150,
  1004. margin: EdgeInsets.only(bottom: 14),
  1005. decoration: BoxDecoration(
  1006. borderRadius: BorderRadius.circular(20),
  1007. border:
  1008. Border.all(color: MyColors.cFF4233, width: 1.1),
  1009. color: Colors.white),
  1010. child: MyViews().myText('我知道了', MyColors.cFF4233, 14),
  1011. height: 40,
  1012. alignment: Alignment.center,
  1013. ),
  1014. )
  1015. ],
  1016. ),
  1017. ),
  1018. Expanded(child: Container()),
  1019. ],
  1020. ),
  1021. alignment: Alignment.center,
  1022. ),
  1023. ),
  1024. );
  1025. }
  1026. //优惠券弹框
  1027. void couponBulletBox(CouponBeanDataData data) {
  1028. EasyLoading.instance
  1029. ..contentPadding = EdgeInsets.symmetric(horizontal: 12, vertical: 12)
  1030. ..alignment = Alignment.center
  1031. ..loadingStyle = EasyLoadingStyle.custom
  1032. ..backgroundColor = Colors.transparent
  1033. ..indicatorColor = Colors.black
  1034. ..progressColor = Colors.black
  1035. ..maskColor = Colors.black
  1036. ..textColor = Colors.black
  1037. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  1038. EasyLoading.show(
  1039. indicator: Material(
  1040. color: Colors.transparent,
  1041. child: Stack(
  1042. children: [
  1043. Image.asset(
  1044. 'images/优惠券.png',
  1045. height: 640,
  1046. width: double.infinity,
  1047. ),
  1048. Container(
  1049. height: 640,
  1050. margin: EdgeInsets.only(top: 24),
  1051. child: Column(
  1052. children: [
  1053. Container(
  1054. margin: EdgeInsets.only(bottom: 5),
  1055. child: Text(
  1056. '抢红包啦',
  1057. style: TextStyle(
  1058. color: Colors.white,
  1059. fontSize: 24,
  1060. fontWeight: FontWeight.bold,
  1061. shadows: [
  1062. Shadow(
  1063. offset: Offset(1.0, 1.0),
  1064. blurRadius: 3.0,
  1065. color: MyColors.cDC1717,
  1066. )
  1067. ]),
  1068. ),
  1069. ),
  1070. Container(
  1071. decoration: BoxDecoration(
  1072. color: Colors.white,
  1073. borderRadius: BorderRadius.circular(8),
  1074. ),
  1075. height: 107,
  1076. width: double.infinity,
  1077. margin: EdgeInsets.symmetric(horizontal: 25, vertical: 27),
  1078. child: Column(
  1079. children: [
  1080. Text(
  1081. '平台红包大放送!',
  1082. style: TextStyle(
  1083. color: MyColors.c333333,
  1084. fontSize: 16,
  1085. fontWeight: FontWeight.bold),
  1086. ),
  1087. Text(
  1088. '立即去抢最高${data.max}元消费红包',
  1089. style: TextStyle(
  1090. color: MyColors.cFF4233,
  1091. fontSize: 14,
  1092. fontWeight: FontWeight.bold),
  1093. ),
  1094. Text(
  1095. '活动时间${data.distributeFromDate}至${data.distributeEndDate}',
  1096. style: TextStyle(
  1097. color: MyColors.c666666,
  1098. fontSize: 11,
  1099. fontWeight: FontWeight.bold),
  1100. ),
  1101. ],
  1102. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  1103. crossAxisAlignment: CrossAxisAlignment.start,
  1104. ),
  1105. padding: EdgeInsets.symmetric(horizontal: 26),
  1106. ),
  1107. Container(
  1108. margin: EdgeInsets.symmetric(horizontal: 25),
  1109. child: Row(
  1110. children: [
  1111. Expanded(
  1112. child: GestureDetector(
  1113. onTap: () {
  1114. EasyLoading.dismiss();
  1115. },
  1116. behavior: HitTestBehavior.translucent,
  1117. child: Container(
  1118. height: 34,
  1119. decoration: BoxDecoration(
  1120. borderRadius: BorderRadius.only(
  1121. topLeft: Radius.circular(17),
  1122. bottomLeft: Radius.circular(17),
  1123. ),
  1124. border: Border.all(
  1125. color: MyColors.cFFB455, width: 1),
  1126. color: Colors.white),
  1127. child: Text(
  1128. '我已参与',
  1129. style: TextStyle(
  1130. color: MyColors.cFFB455,
  1131. fontSize: 14,
  1132. ),
  1133. ),
  1134. alignment: Alignment.center,
  1135. ),
  1136. ),
  1137. ),
  1138. Expanded(
  1139. child: GestureDetector(
  1140. onTap: () {
  1141. grabACoupon(data.id);
  1142. },
  1143. behavior: HitTestBehavior.translucent,
  1144. child: Container(
  1145. height: 34,
  1146. decoration: BoxDecoration(
  1147. borderRadius: BorderRadius.only(
  1148. topRight: Radius.circular(17),
  1149. bottomRight: Radius.circular(17),
  1150. ),
  1151. color: MyColors.cFFB455),
  1152. child: Text(
  1153. '立即去抢',
  1154. style: TextStyle(
  1155. color: Colors.white,
  1156. fontSize: 14,
  1157. ),
  1158. ),
  1159. alignment: Alignment.center,
  1160. ),
  1161. ),
  1162. ),
  1163. ],
  1164. ),
  1165. )
  1166. ],
  1167. mainAxisAlignment: MainAxisAlignment.center,
  1168. ),
  1169. alignment: Alignment.center,
  1170. )
  1171. ],
  1172. ),
  1173. ),
  1174. );
  1175. }
  1176. _initFluwx() async {
  1177. await registerWxApi(
  1178. appId: AppID,
  1179. doOnAndroid: true,
  1180. doOnIOS: true,
  1181. universalLink: "https://oms.kunyueyun.com/");
  1182. var result = await isWeChatInstalled;
  1183. print("is installed $result");
  1184. weChatResponseEventHandler.listen((res) {
  1185. if (res is WeChatPaymentResponse) {
  1186. // do something here
  1187. print('res.type----${res.type}');
  1188. print('res.extData----${res.extData}');
  1189. print('res.errCode----${res.errCode}');
  1190. print('res.errStr----${res.errStr}');
  1191. print('res.isSuccessful----${res.isSuccessful}');
  1192. EventBus().emit('WeChatPaymentResponse', res.isSuccessful);
  1193. }
  1194. if (res is WeChatAuthResponse) {
  1195. print('res.type----${res.type}');
  1196. print('res.country----${res.country}');
  1197. print('res.lang----${res.lang}');
  1198. print('res.code----${res.code}');
  1199. print('res.state----${res.state}');
  1200. print(
  1201. 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=$AppID&secret=$AppSecret&code=${res.code}&grant_type=authorization_code');
  1202. Dio()
  1203. .get(
  1204. 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=$AppID&secret=$AppSecret&code=${res.code}&grant_type=authorization_code')
  1205. .then((value) {
  1206. print(value);
  1207. getWeChatInfo(value);
  1208. });
  1209. }
  1210. });
  1211. }
  1212. //获取微信用户信息
  1213. void getWeChatInfo(Response value) {
  1214. AccessBeanEntity accessBeanEntity =
  1215. AccessBeanEntity().fromJson(json.decode(value.toString()));
  1216. Dio()
  1217. .get(
  1218. 'https://api.weixin.qq.com/sns/userinfo?access_token=${accessBeanEntity.accessToken}&openid=${accessBeanEntity.openid}')
  1219. .then((value) {
  1220. print(value);
  1221. try {
  1222. WXBeanEntity entity =
  1223. WXBeanEntity().fromJson(json.decode(value.toString()));
  1224. saveWXInfo(entity);
  1225. } catch (e) {}
  1226. });
  1227. }
  1228. void saveWXInfo(WXBeanEntity entity) {
  1229. MyDio().update({
  1230. "key": "user",
  1231. "values": {
  1232. "id": MyCookie().loginInformation.data.extra.id,
  1233. "wx_picture": entity.headimgurl,
  1234. "wx_name": entity.nickname,
  1235. "wx_openid": entity.openid
  1236. }
  1237. }, (response, hasError) {
  1238. if (!hasError) {
  1239. MyCookie().userBean.wxOpenid =entity.openid;
  1240. MyCookie().userBean.wxName =entity.nickname;
  1241. MyCookie().userBean.wxPicture =entity.headimgurl;
  1242. EventBus().emit('bindToWeChat');
  1243. }
  1244. }, (error) {});
  1245. }
  1246. }
  1247. class FallbackCupertinoLocalisationsDelegate
  1248. extends LocalizationsDelegate<CupertinoLocalizations> {
  1249. const FallbackCupertinoLocalisationsDelegate();
  1250. @override
  1251. bool isSupported(Locale locale) => true;
  1252. @override
  1253. Future<CupertinoLocalizations> load(Locale locale) =>
  1254. DefaultCupertinoLocalizations.load(locale);
  1255. @override
  1256. bool shouldReload(FallbackCupertinoLocalisationsDelegate old) => false;
  1257. }