gang_page.dart 16 KB

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