gang_page.dart 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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:bbyyy/paegs/mine_page/order_page/order_page.dart';
  18. import 'package:flutter/cupertino.dart';
  19. import 'package:flutter/material.dart';
  20. import 'package:flutter_svg/svg.dart';
  21. import 'package:lpinyin/lpinyin.dart';
  22. import 'package:pull_to_refresh/pull_to_refresh.dart';
  23. import 'application_page/application_page.dart';
  24. class GangPage extends StatefulWidget {
  25. @override
  26. _GangPageState createState() => _GangPageState();
  27. }
  28. class _GangPageState extends State<GangPage>
  29. with AutomaticKeepAliveClientMixin {
  30. List<PopupMenuItem> popItems = [];
  31. List<MyShopBeanDataData> data = [];
  32. List<MyShopBeanDataData> applications = [];
  33. int page = 1;
  34. RefreshController controller = RefreshController(initialRefresh: true);
  35. bool needRE = false;
  36. int sIndex = 0;
  37. @override
  38. void initState() {
  39. // TODO: implement initState
  40. super.initState();
  41. EventBus().on('needRE', (arg) {
  42. print(arg);
  43. needRE = arg;
  44. });
  45. if (!MyCookie().underReview)
  46. popItems.add(PopupMenuItem(
  47. child: Text(
  48. '创建货帮',
  49. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  50. ),
  51. value: '创建货帮',
  52. ));
  53. popItems.add(PopupMenuItem(
  54. child: Text(
  55. '加入货帮',
  56. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  57. ),
  58. value: '加入货帮',
  59. ));
  60. }
  61. @override
  62. void dispose() {
  63. // TODO: implement dispose
  64. super.dispose();
  65. EventBus().off('needRE');
  66. }
  67. @override
  68. Widget build(BuildContext context) {
  69. return Scaffold(
  70. body: Stack(
  71. children: [
  72. appBar(context),
  73. Container(
  74. margin:
  75. EdgeInsets.only(top: MediaQuery.of(context).padding.top + 50),
  76. decoration: BoxDecoration(
  77. color: Colors.white,
  78. borderRadius: BorderRadius.only(
  79. topLeft: Radius.circular(16),
  80. topRight: Radius.circular(16))),
  81. child: SmartRefresher(
  82. controller: controller,
  83. onRefresh: onRefresh,
  84. onLoading: onLoading,
  85. enablePullDown: true,
  86. enablePullUp: false,
  87. child: ListView.builder(
  88. padding: EdgeInsets.only(right: 20),
  89. itemBuilder: (c, index) {
  90. return getGangItem(data[index]);
  91. },
  92. itemCount: data.length,
  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. 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),
  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. if (data.shopState == shopStateNormal) {
  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. } else {
  316. String s = '';
  317. if(data.shopState==shopStateArrearage){
  318. s = '欠费';
  319. }
  320. else if(data.shopState==shopStateBanned){
  321. s = '被禁';
  322. }
  323. else if(data.shopState==shopStateClosed){
  324. s = '关闭';
  325. }
  326. showSimpleDialog('该店铺已$s,请尽快处理', context, (){
  327. if(data.shopState==shopStateArrearage){
  328. MyTools().toPage(
  329. context,
  330. OrderPage(
  331. index: 2,
  332. ), (then) {
  333. onRefresh();
  334. });
  335. }
  336. else if(data.shopState==shopStateBanned){
  337. Navigator.pop(context);
  338. }
  339. else if(data.shopState==shopStateClosed){
  340. Navigator.pop(context);
  341. }
  342. });
  343. }
  344. },
  345. behavior: HitTestBehavior.translucent,
  346. child: Container(
  347. height: 73,
  348. child: Column(
  349. children: [
  350. Expanded(
  351. child: Row(
  352. children: [
  353. Container(
  354. margin: EdgeInsets.only(left: 14, right: 14),
  355. child: ClipRRect(
  356. child: MyViews().netImg(imgURL(data.shopPic), 45, 45,
  357. placeholder: 'images/svg/占位图.svg'),
  358. borderRadius: BorderRadius.all(Radius.circular(4)),
  359. ),
  360. ),
  361. Expanded(
  362. child: Container(
  363. height: 45,
  364. child: Column(
  365. children: [
  366. Row(
  367. children: [
  368. Expanded(
  369. child: Text(
  370. data.shopName,
  371. style: TextStyle(
  372. color: MyColors.c333333, fontSize: 15),
  373. )),
  374. Visibility(
  375. child: Container(
  376. decoration: BoxDecoration(
  377. color: MyColors.cFFCD00,
  378. borderRadius: BorderRadius.only(
  379. topLeft: Radius.circular(6),
  380. bottomRight: Radius.circular(6))),
  381. height: 18,
  382. width: 30,
  383. child: Text(
  384. '自建',
  385. style: TextStyle(
  386. color: Colors.white, fontSize: 10),
  387. ),
  388. alignment: Alignment.center,
  389. padding: EdgeInsets.only(bottom: 2),
  390. ),
  391. visible: data.ownerUid == MyCookie().getUID(),
  392. ),
  393. ],
  394. ),
  395. Row(
  396. children: [
  397. Visibility(
  398. visible: !data.privateShop,
  399. child: Container(
  400. decoration: BoxDecoration(
  401. border: Border.all(
  402. color: MyColors.cFF4233, width: 1),
  403. borderRadius: BorderRadius.circular(8),
  404. ),
  405. height: 16,
  406. width: 28,
  407. child: Text(
  408. '公开',
  409. style: TextStyle(
  410. color: MyColors.cFF4233,
  411. fontSize: 10),
  412. ),
  413. alignment: Alignment.center,
  414. margin: EdgeInsets.only(right: 5),
  415. ),
  416. ),
  417. Expanded(
  418. child: Text(
  419. 'ID:${data.shopUid}',
  420. style: TextStyle(
  421. color: MyColors.c888888, fontSize: 12),
  422. ),
  423. ),
  424. Visibility(
  425. child: Container(
  426. decoration: BoxDecoration(
  427. color: MyColors.cFF4233,
  428. borderRadius: BorderRadius.only(
  429. topLeft: Radius.circular(6),
  430. bottomRight: Radius.circular(6))),
  431. height: 18,
  432. width: 30,
  433. child: Text(
  434. '欠费',
  435. style: TextStyle(
  436. color: Colors.white, fontSize: 10),
  437. ),
  438. alignment: Alignment.center,
  439. padding: EdgeInsets.only(bottom: 2),
  440. ),
  441. visible: data.shopState == shopStateArrearage,
  442. ),
  443. ],
  444. )
  445. ],
  446. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  447. ),
  448. ),
  449. )
  450. ],
  451. ),
  452. ),
  453. Container(
  454. margin: EdgeInsets.only(left: 73),
  455. height: 0.5,
  456. color: MyColors.cE7E7E7,
  457. )
  458. ],
  459. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  460. ),
  461. ),
  462. );
  463. }
  464. }
  465. @override
  466. // TODO: implement wantKeepAlive
  467. bool get wantKeepAlive => true;
  468. queryGang() {
  469. var dJson;
  470. var conditions1 = [
  471. "role!=$shopUserOwner",
  472. "user_uid==${MyCookie().getUID()}",
  473. "review_state==1"
  474. ];
  475. var conditions2 = [
  476. "role==$shopUserOwner",
  477. "user_uid==${MyCookie().getUID()}"
  478. ];
  479. if (sIndex == 0) {
  480. conditions1.add('private_shop==true');
  481. dJson = {
  482. "key": "shop_user",
  483. "filters": {
  484. "or": true,
  485. "conditions": conditions1,
  486. "filters": [
  487. {"conditions": conditions2}
  488. ]
  489. },
  490. "dims": shopUserDims,
  491. "paging": [page, 5000],
  492. "order_by": ["shop_name,DESC"]
  493. };
  494. } else {
  495. conditions1.add('private_shop==false');
  496. dJson = {
  497. "key": "shop_user",
  498. "filters": {"conditions": conditions1},
  499. "dims": shopUserDims,
  500. "paging": [page, 5000],
  501. "order_by": ["shop_name,DESC"]
  502. };
  503. }
  504. // if (sIndex == 1) {
  505. // conditions1.add('collected == true');
  506. // conditions2.add('collected == true');
  507. // }
  508. MyDio().query(dJson, (response, hasError) {
  509. if (!hasError) {
  510. MyShopBeanEntity entity =
  511. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  512. if (page == 1) {
  513. data.clear();
  514. }
  515. data.addAll(entity.data.data);
  516. // data.sort((a, b) {
  517. // String aT = PinyinHelper.getShortPinyin(a.shopName);
  518. // String bT = PinyinHelper.getShortPinyin(b.shopName);
  519. // return aT.compareTo(bT);
  520. // });
  521. data.forEach((element) {
  522. element.tagIndex = PinyinHelper.getPinyinE(element.shopName).toLowerCase();
  523. });
  524. data.sort((left,right)=>left.tagIndex.compareTo(right.tagIndex));
  525. if (applications.isNotEmpty&&page==1&&sIndex == 0) {
  526. MyShopBeanDataData shopB = MyShopBeanDataData();
  527. shopB.shopName = '0';
  528. // add hotCityList.
  529. data.insert(0, shopB);
  530. }
  531. // _handleList(data);
  532. setState(() {
  533. endRe(controller);
  534. });
  535. }
  536. }, (error) {});
  537. }
  538. void _handleList(List<MyShopBeanDataData> list) {
  539. List<MyShopBeanDataData> selfBuilt = [];
  540. list.forEach((element) {
  541. if (element.ownerUid == MyCookie().getUID()) {
  542. selfBuilt.add(element);
  543. }
  544. });
  545. selfBuilt.forEach((element) {
  546. list.removeWhere((data) => data.id == element.id);
  547. });
  548. if (list.isEmpty && selfBuilt.isEmpty) return;
  549. for (int i = 0, length = list.length; i < length; i++) {
  550. String pinyin = PinyinHelper.getPinyinE(list[i].shopName);
  551. String tag = pinyin.substring(0, 1).toUpperCase();
  552. if (RegExp('[A-Z]').hasMatch(tag)) {
  553. list[i].tagIndex = tag;
  554. } else {
  555. list[i].tagIndex = '#';
  556. }
  557. }
  558. // A-Z sort.
  559. SuspensionUtil.sortListBySuspensionTag(list);
  560. data.insertAll(0, selfBuilt);
  561. if (applications.isNotEmpty) {
  562. MyShopBeanDataData shopB = MyShopBeanDataData();
  563. shopB.shopName = '★';
  564. // add hotCityList.
  565. data.insert(0, shopB);
  566. }
  567. // show sus tag.
  568. SuspensionUtil.setShowSuspensionStatus(data);
  569. setState(() {});
  570. }
  571. enquiryApplication() {
  572. MyDio().query({
  573. "key": "shop_user",
  574. "filters": {
  575. "conditions": ["owner_uid==${MyCookie().getUID()}", "review_state==0"]
  576. },
  577. "dims": shopUserDims,
  578. "paging": [1, 2000]
  579. }, (response, hasError) {
  580. if (!hasError) {
  581. MyShopBeanEntity entity =
  582. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  583. applications.clear();
  584. applications.addAll(entity.data.data);
  585. }
  586. setState(() {
  587. endRe(controller);
  588. });
  589. }, (error) {});
  590. }
  591. void onRefresh() {
  592. page = 1;
  593. queryGang();
  594. enquiryApplication();
  595. }
  596. void onLoading() {
  597. page++;
  598. queryGang();
  599. enquiryApplication();
  600. }
  601. }