messageList.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_slidable/flutter_slidable.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/fast_notification.dart';
  9. import 'package:liftmanager/utils/toast.dart';
  10. import 'package:liftmanager/widgets/my_refresh_list.dart';
  11. import 'package:liftmanager/widgets/state_layout.dart';
  12. import 'package:oktoast/oktoast.dart';
  13. class MessageList extends StatefulWidget {
  14. const MessageList({Key key, @required this.index, this.returnMsgList})
  15. : super(key: key);
  16. final int index;
  17. final Function returnMsgList;
  18. @override
  19. _MessageListState createState() => _MessageListState();
  20. }
  21. class _MessageListState extends State<MessageList>
  22. with
  23. AutomaticKeepAliveClientMixin<MessageList>,
  24. SingleTickerProviderStateMixin {
  25. List<MessageListItem> _list = [];
  26. int _page = 1;
  27. int _maxPage = 999;
  28. StateType _stateType = StateType.loading;
  29. @override
  30. void initState() {
  31. super.initState();
  32. //Item数量
  33. // _maxPage = widget.index == 0 ? 1 : (widget.index == 1 ? 2 : 3);
  34. onRefresh();
  35. FastNotification.addListener("msgList", (friendsInit) async {
  36. if (mounted) {
  37. onRefresh();
  38. // FastNotification.push('msgListChage');
  39. setState(() {});
  40. }
  41. });
  42. }
  43. Future onRefresh() async {
  44. _stateType = StateType.loading;
  45. _page = 1;
  46. _maxPage = 999;
  47. ApiService(context: context).messageList(_page, 15, widget.index,
  48. onSuccess: (MessageListEntity data) {
  49. _stateType = StateType.empty;
  50. if (data != null) {
  51. if (_page == 1) {
  52. _list.clear();
  53. }
  54. if (data.rows.length < 10) {
  55. _maxPage = _page;
  56. }
  57. if (data != null) {
  58. _list.addAll(data.rows);
  59. }
  60. }
  61. widget.returnMsgList(_list);
  62. if (mounted) {
  63. setState(() {});
  64. }
  65. }, onError: (code, msg) {
  66. showToast(msg);
  67. });
  68. }
  69. Future _loadMore() async {
  70. _stateType = StateType.loading;
  71. _page += 1;
  72. ApiService(context: context).messageList(_page, 10, widget.index,
  73. onSuccess: (MessageListEntity data) {
  74. _stateType = StateType.empty;
  75. if (data.rows.length < 10) {
  76. _maxPage = _page;
  77. }
  78. _list.addAll(data.rows);
  79. _page++;
  80. // FastNotification.push('msgListChage', _list);
  81. widget.returnMsgList(_list);
  82. setState(() {});
  83. }, onError: (code, msg) {
  84. showToast(msg);
  85. });
  86. }
  87. ///电梯列表
  88. void _liftList(id) {
  89. // NavigatorUtils.push(context, MessageRouter.heavyLiftListPage + "?id=${id}");
  90. }
  91. ///项目详情
  92. void _projectDetail(id, projectStatus) {
  93. // NavigatorUtils.push(context, "${MessageRouter.heavyDetailPage}?id=${id}&status=${projectStatus}");
  94. }
  95. void _startProject(id) {
  96. showAlert(
  97. context,
  98. "提示",
  99. "现在开工?",
  100. "确定",
  101. () {
  102. NavigatorUtils.goBack(context);
  103. showLoading(context, "正在加载");
  104. ApiService(context: context).capitalBegin(id, onSuccess: (res) {
  105. dismissLoading(context);
  106. onRefresh();
  107. }, onError: (code, msg) {
  108. dismissLoading(context);
  109. toasts(msg);
  110. });
  111. },
  112. txt2: "取消",
  113. onPre2: () {
  114. NavigatorUtils.goBack(context);
  115. });
  116. }
  117. void _endProject(id) {
  118. showAlert(
  119. context,
  120. "提示",
  121. "现在开工?",
  122. "确定",
  123. () {
  124. ApiService(context: context).capitalBegin(id, onSuccess: (res) {
  125. if (res != null) {
  126. onRefresh();
  127. }
  128. }, onError: (code, msg) {
  129. toasts(msg);
  130. });
  131. },
  132. txt2: "取消",
  133. onPre2: () {
  134. NavigatorUtils.goBack(context);
  135. });
  136. }
  137. @override
  138. Widget build(BuildContext context) {
  139. super.build(context);
  140. return MyListView(
  141. itemCount: _list.length,
  142. stateType: _stateType,
  143. onRefresh: onRefresh,
  144. loadMore: _loadMore,
  145. hasMore: _page < _maxPage,
  146. itemBuilder: (_, index) {
  147. return Slidable(
  148. key: UniqueKey(),
  149. actionPane: SlidableDrawerActionPane(),
  150. actionExtentRatio: 0.2,
  151. secondaryActions: <Widget>[
  152. Container(
  153. color: Color(0xffF94F45),
  154. alignment: Alignment.center,
  155. child: GestureDetector(
  156. onTap: () {
  157. // if (onDeleting != null) {
  158. // onDeleting();
  159. // }
  160. changeNoticeState([_list[index].id]);
  161. },
  162. child: Text(
  163. '删除',
  164. style: TextStyle(fontSize: 14, color: Colors.white),
  165. ),
  166. ),
  167. )
  168. ],
  169. child: InkWell(
  170. onTap: () async {
  171. await NavigatorUtils.pushResult(
  172. context,
  173. "${MessageRouter.messageDetailPage}?id=" +
  174. _list[index].id, (e) {
  175. onRefresh();
  176. });
  177. // await _onRefresh();
  178. },
  179. child: Container(
  180. margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  181. decoration: BoxDecoration(
  182. color: Colors.white,
  183. borderRadius: BorderRadius.circular(6.0),
  184. ),
  185. padding: const EdgeInsets.only(top: 10, bottom: 10),
  186. child: Column(
  187. children: <Widget>[
  188. Container(
  189. padding: EdgeInsets.only(left: 12, right: 12),
  190. child: Row(
  191. children: <Widget>[
  192. _list[index].viewFlag != 1
  193. ? ClipRRect(
  194. borderRadius: BorderRadius.circular(4),
  195. child: Container(
  196. color: Colors.red,
  197. width: 8,
  198. height: 8,
  199. ),
  200. )
  201. : Container(),
  202. _list[index].viewFlag != 1
  203. ? SizedBox(
  204. width: 9,
  205. )
  206. : Container(),
  207. Expanded(
  208. flex: 1,
  209. child: Text(
  210. _list[index].content,
  211. style: TextStyles.text15,
  212. overflow: TextOverflow.ellipsis,
  213. softWrap: false, //单行显示
  214. )),
  215. // Text(
  216. // "${_list[index].viewFlag == 1 ? '已读' : ''}",
  217. // style: TextStyle(
  218. // fontSize: 11, color: Color(0xFF999999)),
  219. // ),
  220. ],
  221. ),
  222. ),
  223. lineTxt("", "${_list[index].createTime}"),
  224. ],
  225. ),
  226. )),
  227. );
  228. });
  229. }
  230. Future changeNoticeState(idList) async {
  231. // clearData
  232. await NewApiService().deleteAllMessage(widget.index, ids: idList,
  233. onSuccess: (res) {
  234. // String initThisNotice = randomInt(1111, 9999).toString() +
  235. // DateTime.now().millisecondsSinceEpoch.toString();
  236. // FastNotification.push("initNotice", initThisNotice);
  237. showToast('删除成功');
  238. onRefresh();
  239. // FastNotification.push('msgListChage');
  240. setState(() {});
  241. }, onError: (code, msg) {
  242. toasts(msg);
  243. });
  244. }
  245. Widget lineTxt(title, value) {
  246. return Container(
  247. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  248. child: Row(
  249. children: <Widget>[
  250. Text("${title}",
  251. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  252. Expanded(
  253. flex: 1,
  254. child: Text(
  255. "${value}",
  256. textAlign: TextAlign.right,
  257. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  258. ),
  259. )
  260. ],
  261. ),
  262. );
  263. }
  264. @override
  265. bool get wantKeepAlive => true;
  266. }