mine_page.dart 22 KB

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