gang_page.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. Expanded(
  369. child: Text(
  370. 'ID:${data.shopUid}',
  371. style: TextStyle(
  372. color: MyColors.c888888, fontSize: 12),
  373. ),
  374. ),
  375. Visibility(
  376. child: Container(
  377. decoration: BoxDecoration(
  378. color: MyColors.cFF4233,
  379. borderRadius: BorderRadius.only(
  380. topLeft: Radius.circular(6),
  381. bottomRight: Radius.circular(6))),
  382. height: 18,
  383. width: 30,
  384. child: Text(
  385. '欠费',
  386. style: TextStyle(
  387. color: Colors.white, fontSize: 10),
  388. ),
  389. alignment: Alignment.center,
  390. padding: EdgeInsets.only(bottom: 2),
  391. ),
  392. visible: data.shopState == shopStateArrearage,
  393. ),
  394. ],
  395. )
  396. ],
  397. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  398. ),
  399. ),
  400. )
  401. ],
  402. ),
  403. ),
  404. Container(
  405. margin: EdgeInsets.only(left: 73, right: 14),
  406. height: 0.5,
  407. color: MyColors.cE7E7E7,
  408. )
  409. ],
  410. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  411. ),
  412. ),
  413. );
  414. }
  415. }
  416. @override
  417. // TODO: implement wantKeepAlive
  418. bool get wantKeepAlive => true;
  419. queryGang() {
  420. var dJson;
  421. var conditions1 = [
  422. "role!=$shopUserOwner",
  423. "user_uid==${MyCookie().getUID()}",
  424. "review_state==1"
  425. ];
  426. var conditions2 = [
  427. "role==$shopUserOwner",
  428. "user_uid==${MyCookie().getUID()}"
  429. ];
  430. if(sIndex == 0){
  431. conditions1.add('private_shop==true');
  432. dJson = {
  433. "key": "shop_user",
  434. "filters": {
  435. "or": true,
  436. "conditions": conditions1,
  437. "filters": [
  438. {"conditions": conditions2}
  439. ]
  440. },
  441. "dims": shopUserDims,
  442. "paging": [page, 1000],
  443. "order_by": ["shop_name,DESC"]
  444. };
  445. }else{
  446. conditions1.add('private_shop==false');
  447. dJson = {
  448. "key": "shop_user",
  449. "filters": {
  450. "conditions": conditions1
  451. },
  452. "dims": shopUserDims,
  453. "paging": [page, 1000],
  454. "order_by": ["shop_name,DESC"]
  455. };
  456. }
  457. // if (sIndex == 1) {
  458. // conditions1.add('collected == true');
  459. // conditions2.add('collected == true');
  460. // }
  461. MyDio().query(dJson, (response, hasError) {
  462. if (!hasError) {
  463. MyShopBeanEntity entity =
  464. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  465. if (page == 1) {
  466. data.clear();
  467. }
  468. data.addAll(entity.data.data);
  469. // data.sort((a, b) {
  470. // String aT = PinyinHelper.getShortPinyin(a.shopName);
  471. // String bT = PinyinHelper.getShortPinyin(b.shopName);
  472. // return aT.compareTo(bT);
  473. // });
  474. _handleList(data);
  475. setState(() {
  476. endRe(controller);
  477. });
  478. }
  479. }, (error) {});
  480. }
  481. void _handleList(List<MyShopBeanDataData> list) {
  482. List<MyShopBeanDataData> selfBuilt = [];
  483. list.forEach((element) {
  484. if(element.ownerUid==MyCookie().getUID()){
  485. selfBuilt.add(element);
  486. }
  487. });
  488. selfBuilt.forEach((element) {
  489. list.removeWhere((data) => data.id==element.id);
  490. });
  491. if (list.isEmpty) return;
  492. for (int i = 0, length = list.length; i < length; i++) {
  493. String pinyin = PinyinHelper.getPinyinE(list[i].shopName);
  494. String tag = pinyin.substring(0, 1).toUpperCase();
  495. if (RegExp('[A-Z]').hasMatch(tag)) {
  496. list[i].tagIndex = tag;
  497. } else {
  498. list[i].tagIndex = '#';
  499. }
  500. }
  501. // A-Z sort.
  502. SuspensionUtil.sortListBySuspensionTag(list);
  503. data.insertAll(0, selfBuilt);
  504. if (applications.isNotEmpty) {
  505. MyShopBeanDataData shopB = MyShopBeanDataData();
  506. shopB.shopName = '★';
  507. // add hotCityList.
  508. data.insert(0, shopB);
  509. }
  510. // show sus tag.
  511. SuspensionUtil.setShowSuspensionStatus(data);
  512. setState(() {});
  513. }
  514. enquiryApplication() {
  515. MyDio().query({
  516. "key": "shop_user",
  517. "filters": {
  518. "conditions": ["owner_uid==${MyCookie().getUID()}", "review_state==0"]
  519. },
  520. "dims": shopUserDims,
  521. "paging": [1, 2000]
  522. }, (response, hasError) {
  523. if (!hasError) {
  524. MyShopBeanEntity entity =
  525. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  526. applications.clear();
  527. applications.addAll(entity.data.data);
  528. }
  529. setState(() {
  530. endRe(controller);
  531. });
  532. }, (error) {});
  533. }
  534. void onRefresh() {
  535. page = 1;
  536. queryGang();
  537. enquiryApplication();
  538. }
  539. void onLoading() {
  540. page++;
  541. queryGang();
  542. enquiryApplication();
  543. }
  544. }