mine_page.dart 23 KB

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