messageList.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/internal/message/message_router.dart';
  3. import 'package:liftmanager/internal/message/model/message_list_entity.dart';
  4. import 'package:liftmanager/net/api_service.dart';
  5. import 'package:liftmanager/res/resources.dart';
  6. import 'package:liftmanager/routers/fluro_navigator.dart';
  7. import 'package:liftmanager/utils/toast.dart';
  8. import 'package:liftmanager/widgets/my_refresh_list.dart';
  9. import 'package:liftmanager/widgets/state_layout.dart';
  10. import 'package:oktoast/oktoast.dart';
  11. class MessageList extends StatefulWidget {
  12. const MessageList({Key key, @required this.index}) : super(key: key);
  13. final int index;
  14. @override
  15. _MessageListState createState() => _MessageListState();
  16. }
  17. class _MessageListState extends State<MessageList>
  18. with
  19. AutomaticKeepAliveClientMixin<MessageList>,
  20. SingleTickerProviderStateMixin {
  21. List<MessageListItem> _list = [];
  22. int _page = 1;
  23. int _maxPage = 999;
  24. StateType _stateType = StateType.loading;
  25. @override
  26. void initState() {
  27. super.initState();
  28. //Item数量
  29. // _maxPage = widget.index == 0 ? 1 : (widget.index == 1 ? 2 : 3);
  30. _onRefresh();
  31. }
  32. Future _onRefresh() async {
  33. _stateType = StateType.loading;
  34. _page = 1;
  35. _maxPage = 999;
  36. ApiService(context: context).messageList(_page, 10, widget.index,
  37. onSuccess: (MessageListEntity data) {
  38. _stateType = StateType.empty;
  39. if (data != null) {
  40. if (_page == 1) {
  41. _list.clear();
  42. }
  43. if (data.rows.length < 10) {
  44. _maxPage = _page;
  45. }
  46. if (data != null) {
  47. _list.addAll(data.rows);
  48. }
  49. }
  50. setState(() {});
  51. }, onError: (code, msg) {
  52. showToast(msg);
  53. });
  54. }
  55. Future _loadMore() async {
  56. _stateType = StateType.loading;
  57. _page +=1;
  58. ApiService(context: context).messageList(_page, 10, widget.index,
  59. onSuccess: (MessageListEntity data) {
  60. _stateType = StateType.empty;
  61. if (data.rows.length < 10) {
  62. _maxPage = _page;
  63. }
  64. _list.addAll(data.rows);
  65. _page++;
  66. setState(() {});
  67. }, onError: (code, msg) {
  68. showToast(msg);
  69. });
  70. }
  71. ///电梯列表
  72. void _liftList(id) {
  73. // NavigatorUtils.push(context, MessageRouter.heavyLiftListPage + "?id=${id}");
  74. }
  75. ///项目详情
  76. void _projectDetail(id, projectStatus) {
  77. // NavigatorUtils.push(context, "${MessageRouter.heavyDetailPage}?id=${id}&status=${projectStatus}");
  78. }
  79. void _startProject(id) {
  80. showAlert(
  81. context,
  82. "提示",
  83. "现在开工?",
  84. "确定",
  85. () {
  86. NavigatorUtils.goBack(context);
  87. showLoading(context, "正在加载");
  88. ApiService(context: context).capitalBegin(id, onSuccess: (res) {
  89. dismissLoading(context);
  90. _onRefresh();
  91. }, onError: (code, msg) {
  92. dismissLoading(context);
  93. toasts(msg);
  94. });
  95. },
  96. txt2: "取消",
  97. onPre2: () {
  98. NavigatorUtils.goBack(context);
  99. });
  100. }
  101. void _endProject(id) {
  102. showAlert(
  103. context,
  104. "提示",
  105. "现在开工?",
  106. "确定",
  107. () {
  108. ApiService(context: context).capitalBegin(id, onSuccess: (res) {
  109. if (res != null) {
  110. _onRefresh();
  111. }
  112. }, onError: (code, msg) {
  113. toasts(msg);
  114. });
  115. },
  116. txt2: "取消",
  117. onPre2: () {
  118. NavigatorUtils.goBack(context);
  119. });
  120. }
  121. @override
  122. Widget build(BuildContext context) {
  123. super.build(context);
  124. return MyListView(
  125. itemCount: _list.length,
  126. stateType: _stateType,
  127. onRefresh: _onRefresh,
  128. loadMore: _loadMore,
  129. hasMore: _page < _maxPage,
  130. itemBuilder: (_, index) {
  131. return InkWell(
  132. onTap: () {
  133. NavigatorUtils.push(context,
  134. "${MessageRouter.messageDetailPage}?id=" + _list[index].id);
  135. },
  136. child: Container(
  137. margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  138. decoration: BoxDecoration(
  139. color: Colors.white,
  140. borderRadius: BorderRadius.circular(6.0),
  141. ),
  142. padding: const EdgeInsets.only(top: 10, bottom: 10),
  143. child: Column(
  144. children: <Widget>[
  145. Container(
  146. padding: EdgeInsets.only(left: 12,right: 12),
  147. child: Row(
  148. children: <Widget>[
  149. Expanded(
  150. flex: 1,
  151. child: Text(
  152. _list[index].content,
  153. style: TextStyles.text15,
  154. overflow: TextOverflow.ellipsis,
  155. softWrap: false, //单行显示
  156. )),
  157. Text(
  158. "${_list[index].viewFlag == 1 ? '已读' : ''}",
  159. style: TextStyle(
  160. fontSize: 11, color: Color(0xFF999999)),
  161. ),
  162. ],
  163. ),
  164. ),
  165. lineTxt("", "${_list[index].createTime}"),
  166. ],
  167. ),
  168. ));
  169. });
  170. }
  171. Widget lineTxt(title, value) {
  172. return Container(
  173. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  174. child: Row(
  175. children: <Widget>[
  176. Text("${title}",
  177. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  178. Expanded(
  179. flex: 1,
  180. child: Text(
  181. "${value}",
  182. textAlign: TextAlign.right,
  183. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  184. ),
  185. )
  186. ],
  187. ),
  188. );
  189. }
  190. @override
  191. bool get wantKeepAlive => true;
  192. }