mine_page.dart 24 KB

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