123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- import 'package:flutter/material.dart';
- import 'package:flutter_slidable/flutter_slidable.dart';
- import 'package:liftmanager/internal/message/message_router.dart';
- import 'package:liftmanager/internal/message/model/message_list_entity.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/res/resources.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- import 'package:liftmanager/utils/fast_notification.dart';
- import 'package:liftmanager/utils/toast.dart';
- import 'package:liftmanager/widgets/my_refresh_list.dart';
- import 'package:liftmanager/widgets/state_layout.dart';
- import 'package:oktoast/oktoast.dart';
- class MessageList extends StatefulWidget {
- const MessageList({Key key, @required this.index, this.returnMsgList})
- : super(key: key);
- final int index;
- final Function returnMsgList;
- @override
- _MessageListState createState() => _MessageListState();
- }
- class _MessageListState extends State<MessageList>
- with
- AutomaticKeepAliveClientMixin<MessageList>,
- SingleTickerProviderStateMixin {
- List<MessageListItem> _list = [];
- int _page = 1;
- int _maxPage = 999;
- StateType _stateType = StateType.loading;
- @override
- void initState() {
- super.initState();
- //Item数量
- // _maxPage = widget.index == 0 ? 1 : (widget.index == 1 ? 2 : 3);
- onRefresh();
- FastNotification.addListener("msgList", (friendsInit) async {
- if (mounted) {
- onRefresh();
- // FastNotification.push('msgListChage');
- setState(() {});
- }
- });
- }
- Future onRefresh() async {
- _stateType = StateType.loading;
- _page = 1;
- _maxPage = 999;
- ApiService(context: context).messageList(_page, 15, widget.index,
- onSuccess: (MessageListEntity data) {
- _stateType = StateType.empty;
- if (data != null) {
- if (_page == 1) {
- _list.clear();
- }
- if (data.rows.length < 10) {
- _maxPage = _page;
- }
- if (data != null) {
- _list.addAll(data.rows);
- }
- }
- widget.returnMsgList(_list);
- if (mounted) {
- setState(() {});
- }
- }, onError: (code, msg) {
- showToast(msg);
- });
- }
- Future _loadMore() async {
- _stateType = StateType.loading;
- _page += 1;
- ApiService(context: context).messageList(_page, 10, widget.index,
- onSuccess: (MessageListEntity data) {
- _stateType = StateType.empty;
- if (data.rows.length < 10) {
- _maxPage = _page;
- }
- _list.addAll(data.rows);
- _page++;
- // FastNotification.push('msgListChage', _list);
- widget.returnMsgList(_list);
- setState(() {});
- }, onError: (code, msg) {
- showToast(msg);
- });
- }
- ///电梯列表
- void _liftList(id) {
- // NavigatorUtils.push(context, MessageRouter.heavyLiftListPage + "?id=${id}");
- }
- ///项目详情
- void _projectDetail(id, projectStatus) {
- // NavigatorUtils.push(context, "${MessageRouter.heavyDetailPage}?id=${id}&status=${projectStatus}");
- }
- void _startProject(id) {
- showAlert(
- context,
- "提示",
- "现在开工?",
- "确定",
- () {
- NavigatorUtils.goBack(context);
- showLoading(context, "正在加载");
- ApiService(context: context).capitalBegin(id, onSuccess: (res) {
- dismissLoading(context);
- onRefresh();
- }, onError: (code, msg) {
- dismissLoading(context);
- toasts(msg);
- });
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- });
- }
- void _endProject(id) {
- showAlert(
- context,
- "提示",
- "现在开工?",
- "确定",
- () {
- ApiService(context: context).capitalBegin(id, onSuccess: (res) {
- if (res != null) {
- onRefresh();
- }
- }, onError: (code, msg) {
- toasts(msg);
- });
- },
- txt2: "取消",
- onPre2: () {
- NavigatorUtils.goBack(context);
- });
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- return MyListView(
- itemCount: _list.length,
- stateType: _stateType,
- onRefresh: onRefresh,
- loadMore: _loadMore,
- hasMore: _page < _maxPage,
- itemBuilder: (_, index) {
- return Slidable(
- key: UniqueKey(),
- actionPane: SlidableDrawerActionPane(),
- actionExtentRatio: 0.2,
- secondaryActions: <Widget>[
- Container(
- color: Color(0xffF94F45),
- alignment: Alignment.center,
- child: GestureDetector(
- onTap: () {
- // if (onDeleting != null) {
- // onDeleting();
- // }
- changeNoticeState([_list[index].id]);
- },
- child: Text(
- '删除',
- style: TextStyle(fontSize: 14, color: Colors.white),
- ),
- ),
- )
- ],
- child: InkWell(
- onTap: () async {
- await NavigatorUtils.pushResult(
- context,
- "${MessageRouter.messageDetailPage}?id=" +
- _list[index].id, (e) {
- onRefresh();
- });
- // await _onRefresh();
- },
- child: Container(
- margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(6.0),
- ),
- padding: const EdgeInsets.only(top: 10, bottom: 10),
- child: Column(
- children: <Widget>[
- Container(
- padding: EdgeInsets.only(left: 12, right: 12),
- child: Row(
- children: <Widget>[
- _list[index].viewFlag != 1
- ? ClipRRect(
- borderRadius: BorderRadius.circular(4),
- child: Container(
- color: Colors.red,
- width: 8,
- height: 8,
- ),
- )
- : Container(),
- _list[index].viewFlag != 1
- ? SizedBox(
- width: 9,
- )
- : Container(),
- Expanded(
- flex: 1,
- child: Text(
- _list[index].content,
- style: TextStyles.text15,
- overflow: TextOverflow.ellipsis,
- softWrap: false, //单行显示
- )),
- // Text(
- // "${_list[index].viewFlag == 1 ? '已读' : ''}",
- // style: TextStyle(
- // fontSize: 11, color: Color(0xFF999999)),
- // ),
- ],
- ),
- ),
- lineTxt("", "${_list[index].createTime}"),
- ],
- ),
- )),
- );
- });
- }
- Future changeNoticeState(idList) async {
- // clearData
- await NewApiService().deleteAllMessage(widget.index, ids: idList,
- onSuccess: (res) {
- // String initThisNotice = randomInt(1111, 9999).toString() +
- // DateTime.now().millisecondsSinceEpoch.toString();
- // FastNotification.push("initNotice", initThisNotice);
- showToast('删除成功');
- onRefresh();
- // FastNotification.push('msgListChage');
- setState(() {});
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- Widget lineTxt(title, value) {
- return Container(
- padding: EdgeInsets.only(left: 12, top: 5, right: 12),
- child: Row(
- children: <Widget>[
- Text("${title}",
- style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
- Expanded(
- flex: 1,
- child: Text(
- "${value}",
- textAlign: TextAlign.right,
- style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
- ),
- )
- ],
- ),
- );
- }
- @override
- bool get wantKeepAlive => true;
- }
|