gang_page.dart 20 KB

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