gang_page.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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/my_colors.dart';
  9. import 'package:bbyyy/my_tools/my_cookie.dart';
  10. import 'package:bbyyy/my_tools/my_tools.dart';
  11. import 'package:bbyyy/my_tools/my_views.dart';
  12. import 'package:bbyyy/paegs/gang_page/create_a_gang_page/create_a_gang_page.dart';
  13. import 'package:bbyyy/paegs/gang_page/gang_in_page/gang_in_page.dart';
  14. import 'package:bbyyy/paegs/gang_page/join_the_gang_page/join_the_gang_page.dart';
  15. import 'package:flutter/cupertino.dart';
  16. import 'package:flutter/material.dart';
  17. import 'package:flutter_svg/svg.dart';
  18. import 'package:lpinyin/lpinyin.dart';
  19. import 'package:pull_to_refresh/pull_to_refresh.dart';
  20. import 'application_page/application_page.dart';
  21. class GangPage extends StatefulWidget {
  22. @override
  23. _GangPageState createState() => _GangPageState();
  24. }
  25. class _GangPageState extends State<GangPage>
  26. with AutomaticKeepAliveClientMixin {
  27. List<PopupMenuItem> popItems = [];
  28. List<MyShopBeanDataData> data = [];
  29. List<MyShopBeanDataData> applications = [];
  30. int page = 1;
  31. RefreshController controller = RefreshController(initialRefresh: true);
  32. @override
  33. void initState() {
  34. // TODO: implement initState
  35. super.initState();
  36. popItems.add(PopupMenuItem(
  37. child: Text(
  38. '创建货帮',
  39. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  40. ),
  41. value: '创建货帮',
  42. ));
  43. popItems.add(PopupMenuItem(
  44. child: Text(
  45. '加入货帮',
  46. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  47. ),
  48. value: '加入货帮',
  49. ));
  50. }
  51. @override
  52. Widget build(BuildContext context) {
  53. return Scaffold(
  54. body: Stack(
  55. children: [
  56. Container(
  57. decoration: BoxDecoration(
  58. gradient: LinearGradient(
  59. colors: MyColors.lg,
  60. ),
  61. ),
  62. height: 152,
  63. child: SafeArea(
  64. child: Stack(
  65. children: [
  66. Container(
  67. height: 50,
  68. child: Text(
  69. '货帮',
  70. style: TextStyle(color: Colors.white, fontSize: 16),
  71. ),
  72. alignment: Alignment.center,
  73. ),
  74. Container(
  75. height: 50,
  76. child: PopupMenuButton(
  77. itemBuilder: (BuildContext context) {
  78. return popItems;
  79. },
  80. onSelected: (v) {
  81. if (v == '加入货帮') {
  82. MyTools().toPage(context, JoinTheGangPage(), (then) {
  83. controller.requestRefresh();
  84. });
  85. } else if (v == '创建货帮') {
  86. MyTools().toPage(context, CreateAGangPage(), (then) {
  87. controller.requestRefresh();
  88. });
  89. }
  90. },
  91. child: Container(
  92. padding: EdgeInsets.all(8),
  93. margin: EdgeInsets.only(right: 6),
  94. child: SvgPicture.asset('images/svg/添加.svg'),
  95. ),
  96. ),
  97. alignment: Alignment.centerRight,
  98. )
  99. ],
  100. alignment: Alignment.topCenter,
  101. ),
  102. ),
  103. alignment: Alignment.topCenter,
  104. ),
  105. Container(
  106. margin:
  107. EdgeInsets.only(top: MediaQuery.of(context).padding.top + 50),
  108. decoration: BoxDecoration(
  109. color: Colors.white,
  110. borderRadius: BorderRadius.only(
  111. topLeft: Radius.circular(16),
  112. topRight: Radius.circular(16))),
  113. child: SmartRefresher(
  114. controller: controller,
  115. onRefresh: onRefresh,
  116. onLoading: onLoading,
  117. enablePullDown: true,
  118. enablePullUp: true,
  119. child: AzListView(
  120. padding: EdgeInsets.only(right: 20),
  121. itemBuilder: (c, index) {
  122. return getGangItem(data[index]);
  123. },
  124. itemCount: data.length,
  125. data: data,
  126. ),
  127. ),
  128. )
  129. ],
  130. ),
  131. );
  132. }
  133. Widget getGangItem(MyShopBeanDataData data) {
  134. if (data.shopPic==null) {
  135. return GestureDetector(
  136. onTap: () {
  137. MyTools().toPage(context, ApplicationPage(), (then) {
  138. controller.requestRefresh();
  139. });
  140. },
  141. behavior: HitTestBehavior.translucent,
  142. child: Container(
  143. height: 73,
  144. child: Column(
  145. children: [
  146. Expanded(
  147. child: Row(
  148. children: [
  149. Container(
  150. margin: EdgeInsets.only(left: 14, right: 14),
  151. child: SvgPicture.asset(
  152. 'images/svg/入帮申请.svg',
  153. height: 45,
  154. width: 45,
  155. ),
  156. ),
  157. Expanded(
  158. child: Container(
  159. height: 45,
  160. padding: EdgeInsets.only(right: 14),
  161. child: Column(
  162. children: [
  163. Row(
  164. children: [
  165. Expanded(
  166. child: Text(
  167. '入帮申请',
  168. style: TextStyle(
  169. color: MyColors.c333333, fontSize: 15),
  170. )),
  171. Text(
  172. '',
  173. style: TextStyle(
  174. color: MyColors.c888888, fontSize: 12),
  175. ),
  176. ],
  177. ),
  178. Row(
  179. children: [
  180. Expanded(
  181. child: Text(
  182. applications.length == 0
  183. ? '暂无申请'
  184. : '你有新的申请消息',
  185. style: TextStyle(
  186. color: MyColors.c888888, fontSize: 12),
  187. ),
  188. ),
  189. Visibility(
  190. visible: applications.length != 0,
  191. child: Container(
  192. decoration: BoxDecoration(
  193. color: MyColors.cFF4233,
  194. borderRadius: BorderRadius.all(
  195. Radius.circular(8))),
  196. constraints: BoxConstraints(minWidth: 16),
  197. height: 16,
  198. padding: EdgeInsets.only(left: 5, right: 5),
  199. child: Text(
  200. '${applications.length}',
  201. style: TextStyle(
  202. color: Colors.white, fontSize: 8),
  203. ),
  204. alignment: Alignment.center,
  205. ),
  206. )
  207. ],
  208. )
  209. ],
  210. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  211. ),
  212. ),
  213. )
  214. ],
  215. ),
  216. ),
  217. Container(
  218. margin: EdgeInsets.only(left: 73, right: 14),
  219. height: 0.5,
  220. color: MyColors.cE7E7E7,
  221. )
  222. ],
  223. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  224. ),
  225. ),
  226. );
  227. } else {
  228. return GestureDetector(
  229. onTap: () {
  230. MyTools().toPage(context, GangInPage(data, null), (then) {
  231. if(then=='删除货帮'){
  232. controller.requestRefresh();
  233. }
  234. });
  235. },
  236. behavior: HitTestBehavior.translucent,
  237. child: Container(
  238. height: 73,
  239. child: Column(
  240. children: [
  241. Expanded(
  242. child: Row(
  243. children: [
  244. Container(
  245. margin: EdgeInsets.only(left: 14, right: 14),
  246. child: ClipRRect(
  247. child: MyViews().netImg(imgURL(data.shopPic), 45, 45,
  248. placeholder: 'images/svg/占位图.svg'),
  249. borderRadius: BorderRadius.all(Radius.circular(4)),
  250. ),
  251. ),
  252. Expanded(
  253. child: Container(
  254. height: 45,
  255. padding: EdgeInsets.only(right: 14),
  256. child: Column(
  257. children: [
  258. Row(
  259. children: [
  260. Expanded(
  261. child: Text(
  262. data.shopName,
  263. style: TextStyle(
  264. color: MyColors.c333333, fontSize: 15),
  265. )),
  266. Visibility(
  267. child: Container(
  268. decoration: BoxDecoration(
  269. color: MyColors.cFFCD00,
  270. borderRadius: BorderRadius.only(
  271. topLeft: Radius.circular(6),
  272. bottomRight: Radius.circular(6))),
  273. height: 18,
  274. width: 30,
  275. child: Text(
  276. '自建',
  277. style: TextStyle(
  278. color: Colors.white, fontSize: 10),
  279. ),
  280. alignment: Alignment.center,
  281. padding: EdgeInsets.only(bottom: 2),
  282. ),
  283. visible: data.role == shopUserOwner,
  284. ),
  285. ],
  286. ),
  287. Row(
  288. children: [
  289. Expanded(
  290. child: Text(
  291. 'ID:${data.shopUid}',
  292. style: TextStyle(
  293. color: MyColors.c888888, fontSize: 12),
  294. ),
  295. ),
  296. Visibility(
  297. child: Container(
  298. decoration: BoxDecoration(
  299. color: MyColors.cFF4233,
  300. borderRadius: BorderRadius.only(
  301. topLeft: Radius.circular(6),
  302. bottomRight: Radius.circular(6))),
  303. height: 18,
  304. width: 30,
  305. child: Text(
  306. '欠费',
  307. style: TextStyle(
  308. color: Colors.white, fontSize: 10),
  309. ),
  310. alignment: Alignment.center,
  311. padding: EdgeInsets.only(bottom: 2),
  312. ),
  313. visible: data.shopState == shopStateArrearage,
  314. ),
  315. ],
  316. )
  317. ],
  318. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  319. ),
  320. ),
  321. )
  322. ],
  323. ),
  324. ),
  325. Container(
  326. margin: EdgeInsets.only(left: 73, right: 14),
  327. height: 0.5,
  328. color: MyColors.cE7E7E7,
  329. )
  330. ],
  331. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  332. ),
  333. ),
  334. );
  335. }
  336. }
  337. @override
  338. // TODO: implement wantKeepAlive
  339. bool get wantKeepAlive => true;
  340. queryGang() {
  341. MyDio().query({
  342. "key": "shop_user",
  343. "filters": {
  344. "or": true,
  345. "conditions": [
  346. "role!=$shopUserOwner",
  347. "user_uid==${MyCookie().getUID()}",
  348. "review_state==1"
  349. ],
  350. "filters": [
  351. {
  352. "conditions": ["role==$shopUserOwner", "user_uid==${MyCookie().getUID()}"]
  353. }
  354. ]
  355. },
  356. "dims": shopUserDims,
  357. "paging": [page, 50],
  358. "order_by": ["shop_name,DESC"]
  359. }, (response, hasError) {
  360. if (!hasError) {
  361. MyShopBeanEntity entity =
  362. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  363. if (page == 1) {
  364. data.clear();
  365. }
  366. data.addAll(entity.data.data);
  367. // data.sort((a, b) {
  368. // String aT = PinyinHelper.getShortPinyin(a.shopName);
  369. // String bT = PinyinHelper.getShortPinyin(b.shopName);
  370. // return aT.compareTo(bT);
  371. // });
  372. _handleList(data);
  373. setState(() {
  374. endRe(controller);
  375. });
  376. }
  377. }, (error) {});
  378. }
  379. void _handleList(List<MyShopBeanDataData> list) {
  380. if (list.isEmpty) return;
  381. for (int i = 0, length = list.length; i < length; i++) {
  382. String pinyin = PinyinHelper.getPinyinE(list[i].shopName);
  383. String tag = pinyin.substring(0, 1).toUpperCase();
  384. if (RegExp('[A-Z]').hasMatch(tag)) {
  385. list[i].tagIndex = tag;
  386. } else {
  387. list[i].tagIndex = '#';
  388. }
  389. }
  390. // A-Z sort.
  391. SuspensionUtil.sortListBySuspensionTag(list);
  392. MyShopBeanDataData shopB = MyShopBeanDataData();
  393. shopB.shopName = '★';
  394. // add hotCityList.
  395. data.insert(0, shopB);
  396. // show sus tag.
  397. SuspensionUtil.setShowSuspensionStatus(data);
  398. setState(() {});
  399. }
  400. enquiryApplication() {
  401. MyDio().query({
  402. "key": "shop_user",
  403. "filters": {
  404. "conditions": ["owner_uid==${MyCookie().getUID()}", "review_state==0"]
  405. },
  406. "dims": shopUserDims,
  407. "paging": [1, 2000]
  408. }, (response, hasError) {
  409. if (!hasError) {
  410. MyShopBeanEntity entity =
  411. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  412. applications.clear();
  413. applications.addAll(entity.data.data);
  414. }
  415. setState(() {
  416. endRe(controller);
  417. });
  418. }, (error) {});
  419. }
  420. void onRefresh() {
  421. page = 1;
  422. queryGang();
  423. enquiryApplication();
  424. }
  425. void onLoading() {
  426. page++;
  427. queryGang();
  428. enquiryApplication();
  429. }
  430. }