RoomCardList.dart 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. super.initState();
  59. Future.delayed(Duration.zero, () {
  60. getList();
  61. });
  62. _controller = new ScrollController();
  63. _controller.addListener(() {
  64. if (_controller.position.pixels == _controller.position.maxScrollExtent &&
  65. canNext) {
  66. currentPage++;
  67. getList();
  68. }
  69. if (_controller.position.pixels >= 135) {
  70. setState(() {
  71. topshowCard = true;
  72. });
  73. } else {
  74. setState(() {
  75. topshowCard = false;
  76. });
  77. }
  78. });
  79. }
  80. @override
  81. void dispose() {
  82. super.dispose();
  83. _controller.dispose();
  84. }
  85. @override
  86. Widget build(BuildContext context) {
  87. return StoreConnector<AppState, UserInfo>(
  88. converter: (Store store) => store.state.userInfo,
  89. builder: (context, userInfo) {
  90. return Scaffold(
  91. appBar: AppBar(
  92. title: Text.rich(TextSpan(children: [
  93. TextSpan(text: "房卡人数"),
  94. TextSpan(
  95. text:
  96. topshowCard ? (":" + userInfo.houseCard.toString()) : '',
  97. style: TextStyle(fontSize: 16),
  98. ),
  99. ])),
  100. centerTitle: true,
  101. ),
  102. body: RefreshIndicator(
  103. color: PRIMARY_COLOR,
  104. backgroundColor: Colors.white,
  105. onRefresh: () async {
  106. await Future.delayed(const Duration(seconds: 1));
  107. setState(() {
  108. list = [];
  109. currentPage = 1;
  110. });
  111. getList();
  112. },
  113. child: Container(
  114. color: BG_COLOR,
  115. child: CustomScrollView(
  116. physics: AlwaysScrollableScrollPhysics(),
  117. controller: _controller,
  118. slivers: <Widget>[
  119. SliverToBoxAdapter(
  120. child: Container(
  121. height: 135,
  122. color: Color(0xFF27273B),
  123. child: Column(
  124. mainAxisAlignment: MainAxisAlignment.center,
  125. children: <Widget>[
  126. Text(userInfo.houseCard.toString(),
  127. style: TextStyle(
  128. color: PRIMARY_COLOR,
  129. fontSize: 38,
  130. fontWeight: FontWeight.w500,
  131. height: 1.4)),
  132. Text('剩余人数名额',
  133. style: TextStyle(
  134. color: PRIMARY_COLOR,
  135. fontSize: 12,
  136. height: 1.4))
  137. ],
  138. ),
  139. ),
  140. ),
  141. SliverList(
  142. delegate: new SliverChildBuilderDelegate(
  143. (BuildContext context, int index) {
  144. if (index == 0) {
  145. return Padding(
  146. padding: EdgeInsets.fromLTRB(15, 20, 15, 15),
  147. child: Text('名额明细',
  148. style: TextStyle(
  149. fontSize: 16,
  150. color: Colors.white,
  151. fontWeight: FontWeight.w500)),
  152. );
  153. }
  154. //创建列表项
  155. return new Container(
  156. padding: EdgeInsets.all(15),
  157. decoration: BoxDecoration(
  158. border: Border(
  159. top: BorderSide(
  160. width: 1,
  161. color: Color(0xFF27273B),
  162. style: BorderStyle.solid))),
  163. child: Row(
  164. children: <Widget>[
  165. Container(
  166. width: 93,
  167. constraints: BoxConstraints(
  168. maxWidth: 93, minWidth: 93),
  169. // color: PRIMARY_COLOR,
  170. child: Text(list[index - 1].money.toString(),
  171. style: TextStyle(
  172. fontSize: 20,
  173. color: Colors.white,
  174. fontWeight: FontWeight.w500)),
  175. ),
  176. Expanded(
  177. flex: 1,
  178. child: Column(
  179. crossAxisAlignment:
  180. CrossAxisAlignment.start,
  181. children: <Widget>[
  182. Text(list[index - 1].remark,
  183. style: TextStyle(
  184. fontSize: 14,
  185. color: Colors.white)),
  186. Text(
  187. readTimestamp(
  188. list[index - 1].createTime,
  189. 'yyyy.MM.dd HH:mm'),
  190. style: TextStyle(
  191. color: Color(0xFF727785),
  192. fontSize: 12,
  193. fontWeight: FontWeight.w400),
  194. )
  195. ],
  196. ),
  197. )
  198. ],
  199. ),
  200. );
  201. }, childCount: list.length + 1),
  202. ),
  203. SliverToBoxAdapter(
  204. child: list.length == 0
  205. ? Container(
  206. child: Column(
  207. children: <Widget>[
  208. Container(
  209. decoration: BoxDecoration(
  210. border: Border(
  211. top: BorderSide(
  212. width: 1,
  213. color: Color(0xFF27273B)))),
  214. height: 66,
  215. ),
  216. Image.asset('images/icon_kongbai.png'),
  217. Container(
  218. height: 20,
  219. ),
  220. Text('暂无相关明细',
  221. style: TextStyle(
  222. color: Color(0xFF575B7D),
  223. fontSize: 14))
  224. ],
  225. ),
  226. )
  227. : Container(),
  228. )
  229. ]),
  230. ),
  231. ),
  232. floatingActionButton: Padding(
  233. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
  234. child: LinearButton(
  235. btntext: '增加房卡人数',
  236. onTapHomeMenu: () {
  237. showDialog(4);
  238. },
  239. ),
  240. ),
  241. floatingActionButtonLocation:
  242. FloatingActionButtonLocation.centerDocked,
  243. );
  244. });
  245. }
  246. }