messageList.dart 6.1 KB

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