mine_page.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  3. import 'package:bbyyy/beans/user_balance_entity.dart';
  4. import 'package:bbyyy/beans/user_bean_entity.dart';
  5. import 'package:bbyyy/https/MyDio.dart';
  6. import 'package:bbyyy/https/my_request.dart';
  7. import 'package:bbyyy/https/url.dart';
  8. import 'package:bbyyy/my_tools/dims.dart';
  9. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  10. import 'package:bbyyy/my_tools/event_bus.dart';
  11. import 'package:bbyyy/my_tools/my_colors.dart';
  12. import 'package:bbyyy/my_tools/my_cookie.dart';
  13. import 'package:bbyyy/my_tools/my_tools.dart';
  14. import 'package:bbyyy/my_tools/my_views.dart';
  15. import 'package:bbyyy/paegs/chat_page/chat_page.dart';
  16. import 'package:bbyyy/paegs/mine_page/my_goods_page/my_goods_page.dart';
  17. import 'package:bbyyy/paegs/mine_page/my_information_page/my_information_page.dart';
  18. import 'package:bbyyy/paegs/mine_page/order_page/order_page.dart';
  19. import 'package:bbyyy/paegs/mine_page/promotion_download_page/promotion_download_page.dart';
  20. import 'package:bbyyy/paegs/mine_page/punish_page/punish_page.dart';
  21. import 'package:bbyyy/paegs/mine_page/referrer_page/referrer_page.dart';
  22. import 'package:bbyyy/paegs/mine_page/set_page/set_page.dart';
  23. import 'package:bbyyy/paegs/mine_page/wallet_page/wallet_page.dart';
  24. import 'package:bbyyy/paegs/mine_page/wallet_page/withdraw_page/withdraw_page.dart';
  25. import 'package:bbyyy/pay/pay_tools.dart';
  26. import 'package:flutter/material.dart';
  27. import 'package:flutter/services.dart';
  28. import 'package:flutter_svg/flutter_svg.dart';
  29. import 'package:pull_to_refresh/pull_to_refresh.dart';
  30. import 'advertising_page/advertising_page.dart';
  31. import 'bind_alipay_page/bind_alipay_page.dart';
  32. import 'coupon_page/coupon_page.dart';
  33. import 'my_information_page/my_qr_page.dart';
  34. class MinePage extends StatefulWidget {
  35. @override
  36. _MinePageState createState() => _MinePageState();
  37. }
  38. class _MinePageState extends State<MinePage> {
  39. @override
  40. void initState() {
  41. // TODO: implement initState
  42. super.initState();
  43. EventBus().on('userChange', (arg) {
  44. setState(() {});
  45. });
  46. EventBus().on('appStoreReview', (arg) {
  47. setState(() {});
  48. });
  49. checkIfThereIsAShop();
  50. Future.delayed(Duration.zero,(){
  51. EasyLoading.show();
  52. getUserWalletBalance((re, hE) {
  53. if (!hE) {
  54. UserBalanceEntity balance =
  55. UserBalanceEntity().fromJson(json.decode(re.data.toString()));
  56. MyCookie().balance = balance.data;
  57. setState(() {
  58. EasyLoading.dismiss();
  59. });
  60. }
  61. }, (e) {
  62. EasyLoading.dismiss();
  63. }, context);
  64. });
  65. }
  66. @override
  67. void dispose() {
  68. // TODO: implement dispose
  69. super.dispose();
  70. EventBus().off('userChange');
  71. EventBus().off('appStoreReview');
  72. }
  73. RefreshController controller = RefreshController();
  74. @override
  75. Widget build(BuildContext context) {
  76. return Scaffold(
  77. body: SmartRefresher(
  78. controller: controller,
  79. onRefresh: onRefresh,
  80. child: SingleChildScrollView(
  81. child: Stack(
  82. children: [
  83. Image.asset(
  84. 'images/mine_bg.png',
  85. width: MediaQuery.of(context).size.width,
  86. height: MediaQuery.of(context).size.width / 750 * 462,
  87. ),
  88. Column(
  89. children: [
  90. SafeArea(
  91. bottom: false,
  92. child: Container(
  93. margin: EdgeInsets.only(
  94. top: 40,
  95. left: 20,
  96. right: 20,
  97. ),
  98. child: Row(
  99. children: [
  100. GestureDetector(
  101. onTap: () {
  102. MyTools().toPage(context, MyInformationPage(),
  103. (then) {
  104. queryPersonalInformation();
  105. });
  106. },
  107. behavior: HitTestBehavior.translucent,
  108. child: Container(
  109. margin: EdgeInsets.only(right: 10),
  110. decoration: BoxDecoration(
  111. color: Colors.white,
  112. borderRadius: BorderRadius.all(
  113. Radius.circular(30),
  114. ),
  115. ),
  116. height: 60,
  117. width: 60,
  118. child: ClipRRect(
  119. borderRadius: BorderRadius.all(
  120. Radius.circular(26),
  121. ),
  122. child: MyViews().netImg(
  123. imgURL(MyCookie()
  124. .loginInformation
  125. .data
  126. .extra
  127. .picture),
  128. 52,
  129. 52),
  130. ),
  131. alignment: Alignment.center,
  132. ),
  133. ),
  134. Expanded(
  135. child: Container(
  136. height: 60,
  137. child: Column(
  138. children: [
  139. Row(
  140. children: [
  141. Expanded(
  142. child: GestureDetector(
  143. onTap: () {
  144. MyTools().toPage(
  145. context, MyInformationPage(),
  146. (then) {
  147. queryPersonalInformation();
  148. });
  149. },
  150. child: Container(
  151. margin: EdgeInsets.only(right: 10),
  152. child: Text(
  153. MyCookie()
  154. .loginInformation
  155. .data
  156. .extra
  157. .name,
  158. style: TextStyle(
  159. color: Colors.white,
  160. fontSize: 18),
  161. maxLines: 1,
  162. overflow: TextOverflow.ellipsis,
  163. softWrap: true,
  164. ),
  165. ),
  166. ),
  167. ),
  168. Container(
  169. margin: EdgeInsets.only(left: 20),
  170. child: MyViews().myText(
  171. '¥${balanceDisplay(MyCookie().balance).toStringAsFixed(2)}',
  172. Colors.white,
  173. 24),
  174. ),
  175. ],
  176. mainAxisAlignment:
  177. MainAxisAlignment.spaceBetween,
  178. ),
  179. Row(
  180. children: [
  181. GestureDetector(
  182. onTap: (){
  183. showToast('已复制到剪切板');
  184. Clipboard.setData(ClipboardData(text: '${MyCookie().getUID()}'));
  185. },
  186. behavior: HitTestBehavior.translucent,
  187. child: Row(
  188. children: [
  189. Text(
  190. 'ID:${MyCookie().getUID()}',
  191. style: TextStyle(
  192. color: Colors.white,
  193. fontSize: 14,
  194. ),
  195. maxLines: 1,
  196. overflow: TextOverflow.ellipsis,
  197. softWrap: true,
  198. ),
  199. Container(margin: EdgeInsets.only(left: 10),child: Icon(Icons.copy,color: Colors.white,size: 14,))
  200. ],
  201. ),
  202. ),
  203. GestureDetector(
  204. onTap: () {
  205. MyTools().toPage(
  206. context, MyQRPage(), (then) {});
  207. },
  208. behavior: HitTestBehavior.translucent,
  209. child: Container(
  210. child: Row(
  211. children: [
  212. SvgPicture.asset(
  213. 'images/svg/二维码.svg',
  214. color: Colors.white,
  215. ),
  216. Container(
  217. width: 20,
  218. ),
  219. SvgPicture.asset(
  220. 'images/svg/箭头.svg',
  221. color: Colors.white,
  222. height: 12,
  223. width: 8,
  224. )
  225. ],
  226. ),
  227. ),
  228. )
  229. ],
  230. mainAxisAlignment:
  231. MainAxisAlignment.spaceBetween,
  232. ),
  233. ],
  234. mainAxisAlignment:
  235. MainAxisAlignment.spaceBetween,
  236. ),
  237. ),
  238. ),
  239. ],
  240. ),
  241. ),
  242. ),
  243. Card(
  244. margin: EdgeInsets.only(
  245. top:
  246. MediaQuery.of(context).size.width / 750 * 462 - 200,
  247. left: 20,
  248. right: 20),
  249. child: Padding(
  250. padding: EdgeInsets.only(top: 15, bottom: 13),
  251. child: Row(
  252. children: [
  253. GestureDetector(
  254. onTap: () {
  255. MyTools().toPage(context, WalletPage(), (then) {
  256. queryPersonalInformation();
  257. });
  258. },
  259. behavior: HitTestBehavior.translucent,
  260. child: Column(
  261. children: [
  262. SvgPicture.asset('images/svg/钱包.svg'),
  263. Container(
  264. margin: EdgeInsets.only(top: 11),
  265. child: Text(
  266. '流水',
  267. style: TextStyle(
  268. color: MyColors.c333333, fontSize: 14),
  269. ),
  270. )
  271. ],
  272. ),
  273. ),
  274. if (!MyCookie().underReview)
  275. GestureDetector(
  276. onTap: () {
  277. MyTools().toPage(context, CouponPage(), (then) {
  278. queryPersonalInformation();
  279. });
  280. },
  281. behavior: HitTestBehavior.translucent,
  282. child: Column(
  283. children: [
  284. SvgPicture.asset('images/svg/优惠券.svg'),
  285. Container(
  286. margin: EdgeInsets.only(top: 11),
  287. child: Text(
  288. '优惠券',
  289. style: TextStyle(
  290. color: MyColors.c333333,
  291. fontSize: 14),
  292. ))
  293. ],
  294. ),
  295. ),
  296. GestureDetector(
  297. onTap: () {
  298. MyTools().toPage(context, MyGoodsPage(), (then) {
  299. queryPersonalInformation();
  300. });
  301. },
  302. behavior: HitTestBehavior.translucent,
  303. child: Column(
  304. children: [
  305. SvgPicture.asset('images/svg/商品.svg'),
  306. Container(
  307. margin: EdgeInsets.only(top: 11),
  308. child: Text(
  309. '商品',
  310. style: TextStyle(
  311. color: MyColors.c333333,
  312. fontSize: 14),
  313. ))
  314. ],
  315. ),
  316. ),
  317. GestureDetector(
  318. onTap: () {
  319. if (MyCookie().userBean.aliPayAccount.isEmpty ||
  320. MyCookie().userBean.aliPayName.isEmpty) {
  321. MyTools().toPage(context, BindAlipayPage(),
  322. (then) {
  323. if (MyCookie()
  324. .userBean
  325. .aliPayAccount
  326. .isNotEmpty &&
  327. MyCookie()
  328. .userBean
  329. .aliPayName
  330. .isNotEmpty) {
  331. MyTools().toPage(context, WithdrawPage(),
  332. (then) {
  333. queryPersonalInformation();
  334. });
  335. }
  336. });
  337. } else {
  338. MyTools().toPage(context, WithdrawPage(),
  339. (then) {
  340. queryPersonalInformation();
  341. });
  342. }
  343. },
  344. behavior: HitTestBehavior.translucent,
  345. child: Column(
  346. children: [
  347. SvgPicture.asset('images/svg/提现.svg'),
  348. Container(
  349. margin: EdgeInsets.only(top: 11),
  350. child: Text(
  351. '提现',
  352. style: TextStyle(
  353. color: MyColors.c333333,
  354. fontSize: 14),
  355. ))
  356. ],
  357. ),
  358. )
  359. ],
  360. mainAxisAlignment: MainAxisAlignment.spaceAround,
  361. ),
  362. ),
  363. elevation: 2,
  364. shadowColor: MyColors.c21333333,
  365. ),
  366. functionItem('images/svg/订单.svg', '订单', () {
  367. MyTools().toPage(context, OrderPage(), (then) {
  368. queryPersonalInformation();
  369. });
  370. }),
  371. // if (showRe)
  372. // functionItem('images/svg/推荐人.svg', '推荐人', () {
  373. // MyTools().toPage(context, ReferrerPage(), (then) {});
  374. // }),
  375. functionItem('images/svg/绑定.svg', '提现账号', () {
  376. MyTools().toPage(context, BindAlipayPage(), (then) {
  377. queryPersonalInformation();
  378. });
  379. }),
  380. // if (!MyCookie().underReview)
  381. // functionItem('images/svg/广告.svg', '广告', () {
  382. // MyTools().toPage(context, AdvertisingPage(), (then) {});
  383. // }),
  384. functionItem('images/svg/处罚.svg', '投诉', () {
  385. MyTools().toPage(context, PunishPage(), (then) {
  386. queryPersonalInformation();
  387. });
  388. }),
  389. functionItem('images/svg/客服.svg', '客服', () {
  390. MyShopBeanDataData chatWith = MyShopBeanDataData();
  391. chatWith.userName = '客服';
  392. chatWith.userUid = 0;
  393. chatWith.userPic = '';
  394. MyTools().toPage(context, ChatPage(chatWith, null), (then) {
  395. queryPersonalInformation();
  396. });
  397. }),
  398. functionItem('images/svg/推广下载.svg', '推广下载', () {
  399. MyTools()
  400. .toPage(context, PromotionDownloadPage(), (then) {});
  401. }),
  402. GestureDetector(
  403. onTap: () {
  404. checkForUpdates(context, showT: true);
  405. },
  406. behavior: HitTestBehavior.translucent,
  407. child: Container(
  408. padding: EdgeInsets.only(left: 20, right: 20),
  409. child: Column(
  410. children: [
  411. Row(
  412. children: [
  413. Container(
  414. child: SvgPicture.asset(
  415. 'images/svg/更新.svg',
  416. color: MyColors.c333333,
  417. ),
  418. margin: EdgeInsets.only(
  419. right: 12, top: 15, bottom: 15),
  420. ),
  421. Expanded(
  422. child: Text(
  423. '更新',
  424. style: TextStyle(
  425. color: MyColors.c333333, fontSize: 15),
  426. )),
  427. Container(
  428. child: Text(
  429. MyCookie().packageInfo.version,
  430. style: TextStyle(
  431. color: MyColors.c333333, fontSize: 15),
  432. ),
  433. margin: EdgeInsets.only(right: 10),
  434. ),
  435. SvgPicture.asset('images/svg/箭头.svg')
  436. ],
  437. ),
  438. Container(
  439. height: 1,
  440. color: MyColors.cEFEFEF,
  441. )
  442. ],
  443. ),
  444. ),
  445. ),
  446. functionItem('images/svg/设置.svg', '设置', () {
  447. MyTools().toPage(context, SetPage(), (then) {
  448. queryPersonalInformation();
  449. });
  450. }),
  451. ],
  452. )
  453. ],
  454. ),
  455. ),
  456. ),
  457. );
  458. }
  459. functionItem(String svg, String title, onTap) {
  460. return GestureDetector(
  461. onTap: onTap,
  462. behavior: HitTestBehavior.translucent,
  463. child: Container(
  464. padding: EdgeInsets.only(left: 20, right: 20),
  465. child: Column(
  466. children: [
  467. Row(
  468. children: [
  469. Container(
  470. child: SvgPicture.asset(
  471. svg,
  472. color: MyColors.c333333,
  473. ),
  474. margin: EdgeInsets.only(right: 12, top: 15, bottom: 15),
  475. ),
  476. Expanded(
  477. child: Text(
  478. title,
  479. style: TextStyle(color: MyColors.c333333, fontSize: 15),
  480. )),
  481. SvgPicture.asset('images/svg/箭头.svg')
  482. ],
  483. ),
  484. Container(
  485. height: 1,
  486. color: MyColors.cEFEFEF,
  487. )
  488. ],
  489. ),
  490. ),
  491. );
  492. }
  493. void queryPersonalInformation() {
  494. MyDio().query({
  495. "key": "user",
  496. "filters": {
  497. "conditions": ["uid == ${MyCookie().getUID()}"]
  498. },
  499. "dims": userDims,
  500. "paging": [1, 20]
  501. }, (response, hasError) {
  502. if (!hasError) {
  503. UserBeanEntity entity =
  504. UserBeanEntity().fromJson(json.decode(response.data.toString()));
  505. MyCookie().userBean = entity.data.data[0];
  506. EventBus().emit('userChange');
  507. }
  508. endRe(controller);
  509. }, (error) {});
  510. }
  511. void onRefresh() {
  512. queryPersonalInformation();
  513. }
  514. bool showRe = false;
  515. void checkIfThereIsAShop() {
  516. MyDio().query({
  517. "key": "shop_user",
  518. "filters": {
  519. "conditions": [
  520. "review_state==1",
  521. "owner_uid==${MyCookie().getUID()}",
  522. "private_shop==true",
  523. "recommender_uid!=0"
  524. ]
  525. },
  526. "dims": shopUserDims,
  527. "paging": [1, 2000]
  528. }, (response, hasError) {
  529. if (!hasError) {
  530. MyShopBeanEntity entity =
  531. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  532. if (entity.data.data == null ||
  533. entity.data.data.isEmpty ||
  534. entity.data.data.length == 0) {
  535. showRe = false;
  536. } else {
  537. showRe = true;
  538. }
  539. setState(() {});
  540. }
  541. }, (error) {});
  542. }
  543. }