gang_page.dart 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. import 'dart:convert';
  2. import 'package:azlistview/azlistview.dart';
  3. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  4. import 'package:bbyyy/https/MyDio.dart';
  5. import 'package:bbyyy/https/url.dart';
  6. import 'package:bbyyy/my_tools/const.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/gang_page/create_a_gang_page/create_a_gang_page.dart';
  14. import 'package:bbyyy/paegs/gang_page/gang_in_page/gang_in_page.dart';
  15. import 'package:bbyyy/paegs/gang_page/join_the_gang_page/join_the_gang_page.dart';
  16. import 'package:bbyyy/paegs/gang_page/query_gang_page/query_gang_page.dart';
  17. import 'package:flutter/cupertino.dart';
  18. import 'package:flutter/material.dart';
  19. import 'package:flutter_svg/svg.dart';
  20. import 'package:lpinyin/lpinyin.dart';
  21. import 'package:pull_to_refresh/pull_to_refresh.dart';
  22. import 'application_page/application_page.dart';
  23. class GangPage extends StatefulWidget {
  24. @override
  25. _GangPageState createState() => _GangPageState();
  26. }
  27. class _GangPageState extends State<GangPage>
  28. with AutomaticKeepAliveClientMixin {
  29. List<PopupMenuItem> popItems = [];
  30. List<MyShopBeanDataData> data = [];
  31. List<MyShopBeanDataData> applications = [];
  32. int page = 1;
  33. RefreshController controller = RefreshController(initialRefresh: true);
  34. bool needRE = false;
  35. int sIndex = 0;
  36. @override
  37. void initState() {
  38. // TODO: implement initState
  39. super.initState();
  40. EventBus().on('needRE', (arg) {
  41. print(arg);
  42. needRE = arg;
  43. });
  44. if (!MyCookie().underReview)
  45. popItems.add(PopupMenuItem(
  46. child: Text(
  47. '创建货帮',
  48. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  49. ),
  50. value: '创建货帮',
  51. ));
  52. popItems.add(PopupMenuItem(
  53. child: Text(
  54. '加入货帮',
  55. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  56. ),
  57. value: '加入货帮',
  58. ));
  59. }
  60. @override
  61. void dispose() {
  62. // TODO: implement dispose
  63. super.dispose();
  64. EventBus().off('needRE');
  65. }
  66. @override
  67. Widget build(BuildContext context) {
  68. return Scaffold(
  69. body: Stack(
  70. children: [
  71. appBar(context),
  72. Container(
  73. margin:
  74. EdgeInsets.only(top: MediaQuery.of(context).padding.top + 50),
  75. decoration: BoxDecoration(
  76. color: Colors.white,
  77. borderRadius: BorderRadius.only(
  78. topLeft: Radius.circular(16),
  79. topRight: Radius.circular(16))),
  80. child: SmartRefresher(
  81. controller: controller,
  82. onRefresh: onRefresh,
  83. onLoading: onLoading,
  84. enablePullDown: true,
  85. enablePullUp: true,
  86. child: AzListView(
  87. padding: EdgeInsets.only(right: 20),
  88. itemBuilder: (c, index) {
  89. return getGangItem(data[index]);
  90. },
  91. itemCount: data.length,
  92. data: data,
  93. ),
  94. ),
  95. )
  96. ],
  97. ),
  98. );
  99. }
  100. Container appBar(BuildContext context) {
  101. return Container(
  102. decoration: BoxDecoration(
  103. gradient: LinearGradient(
  104. colors: MyColors.lg,
  105. ),
  106. ),
  107. height: 152,
  108. child: SafeArea(
  109. bottom: false,
  110. child: Stack(
  111. children: [
  112. Container(
  113. height: 50,
  114. child: Row(
  115. children: [
  116. GestureDetector(
  117. onTap: () {
  118. setState(() {
  119. sIndex = 0;
  120. controller.requestRefresh();
  121. });
  122. },
  123. child: Text(
  124. '货帮',
  125. style: TextStyle(
  126. color: Colors.white,
  127. fontSize: sIndex == 0 ? 16 : 15,
  128. fontWeight: sIndex == 0
  129. ? FontWeight.bold
  130. : FontWeight.normal),
  131. ),
  132. ),
  133. Container(
  134. width: 56,
  135. ),
  136. GestureDetector(
  137. onTap: () {
  138. setState(() {
  139. sIndex = 1;
  140. controller.requestRefresh();
  141. });
  142. },
  143. child: Text(
  144. '关注',
  145. style: TextStyle(
  146. color: Colors.white,
  147. fontSize: sIndex == 1 ? 16 : 15,
  148. fontWeight: sIndex == 1
  149. ? FontWeight.bold
  150. : FontWeight.normal),
  151. ),
  152. ),
  153. ],
  154. mainAxisAlignment: MainAxisAlignment.center,
  155. ),
  156. alignment: Alignment.center,
  157. ),
  158. Row(
  159. children: [
  160. GestureDetector(
  161. onTap: () {
  162. MyTools().toPage(context, QueryGangPage(), (then) {});
  163. },
  164. behavior: HitTestBehavior.translucent,
  165. child: Container(
  166. child: SvgPicture.asset(
  167. 'images/svg/搜索.svg',
  168. color: Colors.white,
  169. ),
  170. width: 50,
  171. height: 50,
  172. padding: EdgeInsets.all(15),
  173. ),
  174. ),
  175. Container(
  176. height: 50,
  177. child: PopupMenuButton(
  178. itemBuilder: (BuildContext context) {
  179. return popItems;
  180. },
  181. onSelected: (v) {
  182. if (v == '加入货帮') {
  183. MyTools().toPage(context, JoinTheGangPage(), (then) {
  184. controller.requestRefresh();
  185. });
  186. } else if (v == '创建货帮') {
  187. MyTools().toPage(context, CreateAGangPage(), (then) {
  188. controller.requestRefresh();
  189. });
  190. }
  191. },
  192. child: Container(
  193. padding: EdgeInsets.all(8),
  194. margin: EdgeInsets.only(right: 6),
  195. child: SvgPicture.asset('images/svg/添加.svg'),
  196. ),
  197. ),
  198. alignment: Alignment.centerRight,
  199. ),
  200. ],
  201. mainAxisAlignment: MainAxisAlignment.end,
  202. )
  203. ],
  204. alignment: Alignment.topCenter,
  205. ),
  206. ),
  207. alignment: Alignment.topCenter,
  208. );
  209. }
  210. Widget getGangItem(MyShopBeanDataData data) {
  211. if (data.shopPic == null) {
  212. return GestureDetector(
  213. onTap: () {
  214. MyTools().toPage(context, ApplicationPage(), (then) {
  215. controller.requestRefresh();
  216. });
  217. },
  218. behavior: HitTestBehavior.translucent,
  219. child: Container(
  220. height: 73,
  221. child: Column(
  222. children: [
  223. Expanded(
  224. child: Row(
  225. children: [
  226. Container(
  227. margin: EdgeInsets.only(left: 14, right: 14),
  228. child: SvgPicture.asset(
  229. 'images/svg/入帮申请.svg',
  230. height: 45,
  231. width: 45,
  232. ),
  233. ),
  234. Expanded(
  235. child: Container(
  236. height: 45,
  237. padding: EdgeInsets.only(right: 14),
  238. child: Column(
  239. children: [
  240. Row(
  241. children: [
  242. Expanded(
  243. child: Text(
  244. '入帮申请',
  245. style: TextStyle(
  246. color: MyColors.c333333, fontSize: 15),
  247. )),
  248. Text(
  249. '',
  250. style: TextStyle(
  251. color: MyColors.c888888, fontSize: 12),
  252. ),
  253. ],
  254. ),
  255. Row(
  256. children: [
  257. Expanded(
  258. child: Text(
  259. applications.length == 0
  260. ? '暂无申请'
  261. : '你有新的申请消息',
  262. style: TextStyle(
  263. color: MyColors.c888888, fontSize: 12),
  264. ),
  265. ),
  266. Visibility(
  267. visible: applications.length != 0,
  268. child: Container(
  269. decoration: BoxDecoration(
  270. color: MyColors.cFF4233,
  271. borderRadius: BorderRadius.all(
  272. Radius.circular(8))),
  273. constraints: BoxConstraints(minWidth: 16),
  274. height: 16,
  275. padding: EdgeInsets.only(left: 5, right: 5),
  276. child: Text(
  277. '${applications.length}',
  278. style: TextStyle(
  279. color: Colors.white, fontSize: 8),
  280. ),
  281. alignment: Alignment.center,
  282. ),
  283. )
  284. ],
  285. )
  286. ],
  287. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  288. ),
  289. ),
  290. )
  291. ],
  292. ),
  293. ),
  294. Container(
  295. margin: EdgeInsets.only(left: 73, right: 14),
  296. height: 0.5,
  297. color: MyColors.cE7E7E7,
  298. )
  299. ],
  300. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  301. ),
  302. ),
  303. );
  304. } else {
  305. return GestureDetector(
  306. onTap: () {
  307. MyTools().toPage(context, GangInPage(data, null), (then) {
  308. if (then == '删除货帮') {
  309. controller.requestRefresh();
  310. } else if (needRE) {
  311. needRE = false;
  312. controller.requestRefresh();
  313. }
  314. });
  315. },
  316. behavior: HitTestBehavior.translucent,
  317. child: Container(
  318. height: 73,
  319. child: Column(
  320. children: [
  321. Expanded(
  322. child: Row(
  323. children: [
  324. Container(
  325. margin: EdgeInsets.only(left: 14, right: 14),
  326. child: ClipRRect(
  327. child: MyViews().netImg(imgURL(data.shopPic), 45, 45,
  328. placeholder: 'images/svg/占位图.svg'),
  329. borderRadius: BorderRadius.all(Radius.circular(4)),
  330. ),
  331. ),
  332. Expanded(
  333. child: Container(
  334. height: 45,
  335. padding: EdgeInsets.only(right: 14),
  336. child: Column(
  337. children: [
  338. Row(
  339. children: [
  340. Expanded(
  341. child: Text(
  342. data.shopName,
  343. style: TextStyle(
  344. color: MyColors.c333333, fontSize: 15),
  345. )),
  346. Visibility(
  347. child: Container(
  348. decoration: BoxDecoration(
  349. color: MyColors.cFFCD00,
  350. borderRadius: BorderRadius.only(
  351. topLeft: Radius.circular(6),
  352. bottomRight: Radius.circular(6))),
  353. height: 18,
  354. width: 30,
  355. child: Text(
  356. '自建',
  357. style: TextStyle(
  358. color: Colors.white, fontSize: 10),
  359. ),
  360. alignment: Alignment.center,
  361. padding: EdgeInsets.only(bottom: 2),
  362. ),
  363. visible: data.ownerUid == MyCookie().getUID(),
  364. ),
  365. ],
  366. ),
  367. Row(
  368. children: [
  369. Visibility(
  370. visible: !data.privateShop,
  371. child: Container(
  372. decoration: BoxDecoration(
  373. border: Border.all(
  374. color: MyColors.cFF4233, width: 1),
  375. borderRadius: BorderRadius.circular(8),
  376. ),
  377. height: 16,
  378. width: 28,
  379. child: Text(
  380. '公开',
  381. style: TextStyle(
  382. color: MyColors.cFF4233,
  383. fontSize: 10),
  384. ),
  385. alignment: Alignment.center,
  386. margin: EdgeInsets.only(right: 5),
  387. ),
  388. ),
  389. Expanded(
  390. child: Text(
  391. 'ID:${data.shopUid}',
  392. style: TextStyle(
  393. color: MyColors.c888888, fontSize: 12),
  394. ),
  395. ),
  396. Visibility(
  397. child: Container(
  398. decoration: BoxDecoration(
  399. color: MyColors.cFF4233,
  400. borderRadius: BorderRadius.only(
  401. topLeft: Radius.circular(6),
  402. bottomRight: Radius.circular(6))),
  403. height: 18,
  404. width: 30,
  405. child: Text(
  406. '欠费',
  407. style: TextStyle(
  408. color: Colors.white, fontSize: 10),
  409. ),
  410. alignment: Alignment.center,
  411. padding: EdgeInsets.only(bottom: 2),
  412. ),
  413. visible: data.shopState == shopStateArrearage,
  414. ),
  415. ],
  416. )
  417. ],
  418. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  419. ),
  420. ),
  421. )
  422. ],
  423. ),
  424. ),
  425. Container(
  426. margin: EdgeInsets.only(left: 73, right: 14),
  427. height: 0.5,
  428. color: MyColors.cE7E7E7,
  429. )
  430. ],
  431. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  432. ),
  433. ),
  434. );
  435. }
  436. }
  437. @override
  438. // TODO: implement wantKeepAlive
  439. bool get wantKeepAlive => true;
  440. queryGang() {
  441. var dJson;
  442. var conditions1 = [
  443. "role!=$shopUserOwner",
  444. "user_uid==${MyCookie().getUID()}",
  445. "review_state==1"
  446. ];
  447. var conditions2 = [
  448. "role==$shopUserOwner",
  449. "user_uid==${MyCookie().getUID()}"
  450. ];
  451. if (sIndex == 0) {
  452. conditions1.add('private_shop==true');
  453. dJson = {
  454. "key": "shop_user",
  455. "filters": {
  456. "or": true,
  457. "conditions": conditions1,
  458. "filters": [
  459. {"conditions": conditions2}
  460. ]
  461. },
  462. "dims": shopUserDims,
  463. "paging": [page, 1000],
  464. "order_by": ["shop_name,DESC"]
  465. };
  466. } else {
  467. conditions1.add('private_shop==false');
  468. dJson = {
  469. "key": "shop_user",
  470. "filters": {"conditions": conditions1},
  471. "dims": shopUserDims,
  472. "paging": [page, 1000],
  473. "order_by": ["shop_name,DESC"]
  474. };
  475. }
  476. // if (sIndex == 1) {
  477. // conditions1.add('collected == true');
  478. // conditions2.add('collected == true');
  479. // }
  480. MyDio().query(dJson, (response, hasError) {
  481. if (!hasError) {
  482. MyShopBeanEntity entity =
  483. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  484. if (page == 1) {
  485. data.clear();
  486. }
  487. data.addAll(entity.data.data);
  488. // data.sort((a, b) {
  489. // String aT = PinyinHelper.getShortPinyin(a.shopName);
  490. // String bT = PinyinHelper.getShortPinyin(b.shopName);
  491. // return aT.compareTo(bT);
  492. // });
  493. _handleList(data);
  494. setState(() {
  495. endRe(controller);
  496. });
  497. }
  498. }, (error) {});
  499. }
  500. void _handleList(List<MyShopBeanDataData> list) {
  501. List<MyShopBeanDataData> selfBuilt = [];
  502. list.forEach((element) {
  503. if (element.ownerUid == MyCookie().getUID()) {
  504. selfBuilt.add(element);
  505. }
  506. });
  507. selfBuilt.forEach((element) {
  508. list.removeWhere((data) => data.id == element.id);
  509. });
  510. if (list.isEmpty && selfBuilt.isEmpty) return;
  511. for (int i = 0, length = list.length; i < length; i++) {
  512. String pinyin = PinyinHelper.getPinyinE(list[i].shopName);
  513. String tag = pinyin.substring(0, 1).toUpperCase();
  514. if (RegExp('[A-Z]').hasMatch(tag)) {
  515. list[i].tagIndex = tag;
  516. } else {
  517. list[i].tagIndex = '#';
  518. }
  519. }
  520. // A-Z sort.
  521. SuspensionUtil.sortListBySuspensionTag(list);
  522. data.insertAll(0, selfBuilt);
  523. if (applications.isNotEmpty) {
  524. MyShopBeanDataData shopB = MyShopBeanDataData();
  525. shopB.shopName = '★';
  526. // add hotCityList.
  527. data.insert(0, shopB);
  528. }
  529. // show sus tag.
  530. SuspensionUtil.setShowSuspensionStatus(data);
  531. setState(() {});
  532. }
  533. enquiryApplication() {
  534. MyDio().query({
  535. "key": "shop_user",
  536. "filters": {
  537. "conditions": ["owner_uid==${MyCookie().getUID()}", "review_state==0"]
  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. applications.clear();
  546. applications.addAll(entity.data.data);
  547. }
  548. setState(() {
  549. endRe(controller);
  550. });
  551. }, (error) {});
  552. }
  553. void onRefresh() {
  554. page = 1;
  555. queryGang();
  556. enquiryApplication();
  557. }
  558. void onLoading() {
  559. page++;
  560. queryGang();
  561. enquiryApplication();
  562. }
  563. }