RoomCardList.dart 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import 'package:flutter/material.dart';
  2. import '../styles/colors.dart';
  3. import 'package:redux/redux.dart';
  4. import 'package:flutter_redux/flutter_redux.dart';
  5. import '../redux/AppState.dart';
  6. import '../model/UserInfo.dart';
  7. import '../net/HttpManager.dart';
  8. import '../styles/totast.dart';
  9. import '../net/Result.dart';
  10. import '../model/MemberHouseCard.dart';
  11. import 'dart:ui';
  12. import '../widget/LinearButton.dart';
  13. import '../widget/Dialog.dart';
  14. class RoomCardList extends StatefulWidget {
  15. @override
  16. RoomCardListState createState() => RoomCardListState();
  17. }
  18. class RoomCardListState extends State<RoomCardList> {
  19. bool topshowCard = false;
  20. ScrollController _controller;
  21. int currentPage = 0;
  22. bool canNext = false;
  23. List<MemberHouseCard> list = [];
  24. Future<void> getList() async {
  25. canNext = false;
  26. Toast.show(context, '加载中', -1, 'loading');
  27. Result res = await HttpManager.get('memberHouseCard/page', data: {
  28. 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
  29. 'currentPage': currentPage,
  30. 'pageNumber': 20
  31. });
  32. Toast.hide();
  33. if (res.success) {
  34. if (currentPage == 1) {
  35. list = [];
  36. }
  37. setState(() {
  38. for (var item in res.data['pp']) {
  39. MemberHouseCard jsonp = MemberHouseCard.fromJson(item);
  40. list.add(jsonp);
  41. }
  42. });
  43. if (res.data['page']['totalNumber'] > currentPage) {
  44. canNext = true;
  45. }
  46. } else {}
  47. }
  48. Future<void> showDialog(id) async {
  49. Toast.show(context, '加载中', -1, 'loading');
  50. Result res = await HttpManager.get('alertMessage/getOne', data: {'id': id});
  51. Toast.hide();
  52. if (res.success) {
  53. MyDialog.showDialog(context, res.data['remark']);
  54. }
  55. }
  56. @override
  57. void initState() {
  58. // TODO: implement initState
  59. super.initState();
  60. Future.delayed(Duration.zero, () {
  61. getList();
  62. });
  63. _controller = new ScrollController();
  64. _controller.addListener(() {
  65. if (_controller.position.pixels == _controller.position.maxScrollExtent &&
  66. canNext) {
  67. currentPage++;
  68. getList();
  69. }
  70. if (_controller.position.pixels >= 135) {
  71. setState(() {
  72. topshowCard = true;
  73. });
  74. } else {
  75. setState(() {
  76. topshowCard = false;
  77. });
  78. }
  79. });
  80. }
  81. @override
  82. void dispose() {
  83. // TODO: implement dispose
  84. super.dispose();
  85. _controller.dispose();
  86. }
  87. @override
  88. Widget build(BuildContext context) {
  89. return StoreConnector<AppState, UserInfo>(
  90. converter: (Store store) => store.state.userInfo,
  91. builder: (context, userInfo) {
  92. return Scaffold(
  93. appBar: AppBar(
  94. title: Text.rich(TextSpan(children: [
  95. TextSpan(text: "房卡人数"),
  96. TextSpan(
  97. text:
  98. topshowCard ? (":" + userInfo.houseCard.toString()) : '',
  99. style: TextStyle(fontSize: 16),
  100. ),
  101. ])),
  102. centerTitle: true,
  103. ),
  104. body: RefreshIndicator(
  105. color: PRIMARY_COLOR,
  106. backgroundColor: Colors.white,
  107. onRefresh: () async {
  108. await Future.delayed(const Duration(seconds: 1));
  109. setState(() {
  110. list = [];
  111. currentPage = 1;
  112. });
  113. getList();
  114. },
  115. child: Container(
  116. color: BG_COLOR,
  117. child: CustomScrollView(
  118. physics: AlwaysScrollableScrollPhysics(),
  119. controller: _controller,
  120. slivers: <Widget>[
  121. SliverToBoxAdapter(
  122. child: Container(
  123. height: 135,
  124. color: Color(0xFF27273B),
  125. child: Column(
  126. mainAxisAlignment: MainAxisAlignment.center,
  127. children: <Widget>[
  128. Text(userInfo.houseCard.toString(),
  129. style: TextStyle(
  130. color: PRIMARY_COLOR,
  131. fontSize: 38,
  132. fontWeight: FontWeight.w500,
  133. height: 1.4)),
  134. Text('剩余人数名额',
  135. style: TextStyle(
  136. color: PRIMARY_COLOR,
  137. fontSize: 12,
  138. height: 1.4))
  139. ],
  140. ),
  141. ),
  142. ),
  143. SliverList(
  144. delegate: new SliverChildBuilderDelegate(
  145. (BuildContext context, int index) {
  146. if (index == 0) {
  147. return Padding(
  148. padding: EdgeInsets.fromLTRB(15, 20, 15, 15),
  149. child: Text('名额明细',
  150. style: TextStyle(
  151. fontSize: 16,
  152. color: Colors.white,
  153. fontWeight: FontWeight.w500)),
  154. );
  155. }
  156. //创建列表项
  157. return new Container(
  158. padding: EdgeInsets.all(15),
  159. decoration: BoxDecoration(
  160. border: Border(
  161. top: BorderSide(
  162. width: 1,
  163. color: Color(0xFF27273B),
  164. style: BorderStyle.solid))),
  165. child: Row(
  166. children: <Widget>[
  167. Container(
  168. width: 93,
  169. constraints: BoxConstraints(
  170. maxWidth: 93, minWidth: 93),
  171. // color: PRIMARY_COLOR,
  172. child: Text(list[index - 1].money.toString(),
  173. style: TextStyle(
  174. fontSize: 20,
  175. color: Colors.white,
  176. fontWeight: FontWeight.w500)),
  177. ),
  178. Expanded(
  179. flex: 1,
  180. child: Column(
  181. crossAxisAlignment:
  182. CrossAxisAlignment.start,
  183. children: <Widget>[
  184. Text(list[index - 1].remark,
  185. style: TextStyle(
  186. fontSize: 14,
  187. color: Colors.white)),
  188. Text(
  189. readTimestamp(
  190. list[index - 1].createTime,
  191. 'yyyy.MM.dd HH:mm'),
  192. style: TextStyle(
  193. color: Color(0xFF727785),
  194. fontSize: 12,
  195. fontWeight: FontWeight.w400),
  196. )
  197. ],
  198. ),
  199. )
  200. ],
  201. ),
  202. );
  203. }, childCount: list.length + 1),
  204. ),
  205. SliverToBoxAdapter(
  206. child: list.length == 0
  207. ? Container(
  208. child: Column(
  209. children: <Widget>[
  210. Container(
  211. decoration: BoxDecoration(
  212. border: Border(
  213. top: BorderSide(
  214. width: 1,
  215. color: Color(0xFF27273B)))),
  216. height: 66,
  217. ),
  218. Image.asset('images/icon_kongbai.png'),
  219. Container(
  220. height: 20,
  221. ),
  222. Text('暂无相关明细',
  223. style: TextStyle(
  224. color: Color(0xFF575B7D),
  225. fontSize: 14))
  226. ],
  227. ),
  228. )
  229. : Container(),
  230. )
  231. ]),
  232. ),
  233. ),
  234. floatingActionButton: Padding(
  235. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
  236. child: LinearButton(
  237. btntext: '增加房卡人数',
  238. onTapHomeMenu: () {
  239. showDialog(4);
  240. },
  241. ),
  242. ),
  243. floatingActionButtonLocation:
  244. FloatingActionButtonLocation.centerDocked,
  245. );
  246. });
  247. }
  248. }