mine_page.dart 25 KB

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