diff --git a/lib/const/api.dart b/lib/const/api.dart index 3a364bb..6d91b4d 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -47,4 +47,7 @@ class _Manage { ///活动管理:管家app 根据活动管理主键id查询活动详情 String get activityDetail => '/user/activity/findById'; + + ///访客管理:管家app显示所有的访客信息 (包含条件搜索) + String get visitorList => '/user/visitor/list'; } diff --git a/lib/models/manager/visitor_item_model.dart b/lib/models/manager/visitor_item_model.dart new file mode 100644 index 0000000..b27ae96 --- /dev/null +++ b/lib/models/manager/visitor_item_model.dart @@ -0,0 +1,50 @@ +import 'package:common_utils/common_utils.dart'; + +class VisitorItemModel { + int id; + String roomName; + String name; + int isDrive; + String carNum; + String effectiveTime; + String visitDate; + int visitorStatus; + + DateTime get effective => DateUtil.getDateTime(effectiveTime); + DateTime get visit => + visitDate == null ? null : DateUtil.getDateTime(visitDate); + + VisitorItemModel( + {this.id, + this.roomName, + this.name, + this.isDrive, + this.carNum, + this.effectiveTime, + this.visitDate, + this.visitorStatus}); + + VisitorItemModel.fromJson(Map json) { + id = json['id']; + roomName = json['roomName']; + name = json['name']; + isDrive = json['isDrive']; + carNum = json['carNum']; + effectiveTime = json['effectiveTime']; + visitDate = json['visitDate']; + visitorStatus = json['visitorStatus']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['roomName'] = this.roomName; + data['name'] = this.name; + data['isDrive'] = this.isDrive; + data['carNum'] = this.carNum; + data['effectiveTime'] = this.effectiveTime; + data['visitDate'] = this.visitDate; + data['visitorStatus'] = this.visitorStatus; + return data; + } +} diff --git a/lib/ui/sub_pages/visitor_manager/visitor_manager_card.dart b/lib/ui/sub_pages/visitor_manager/visitor_manager_card.dart index 10cb374..2bfe763 100644 --- a/lib/ui/sub_pages/visitor_manager/visitor_manager_card.dart +++ b/lib/ui/sub_pages/visitor_manager/visitor_manager_card.dart @@ -2,6 +2,8 @@ import 'dart:math'; // Flutter imports: +import 'package:aku_community_manager/models/manager/visitor_item_model.dart'; +import 'package:common_utils/common_utils.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -14,19 +16,8 @@ import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/ui/sub_pages/visitor_manager/visitor_manager_page.dart'; class VisitorManagerCard extends StatefulWidget { - final String adress; - final String name; - final String plate; - final String time; - final VisitorStatus status; - VisitorManagerCard( - {Key key, - @required this.adress, - @required this.name, - this.plate, - this.time, - @required this.status}) - : super(key: key); + final VisitorItemModel model; + VisitorManagerCard({Key key, @required this.model}) : super(key: key); @override _VisitorManagerCardState createState() => _VisitorManagerCardState(); @@ -37,19 +28,47 @@ class _VisitorManagerCardState extends State { color: AppStyle.primaryTextColor, fontSize: 28.sp, ); - String _adress; - String _name; - String _plate; - String _time; - VisitorStatus _status; - @override - void initState() { - super.initState(); - _adress = widget.adress; - _name = widget.name; - _plate = widget.plate ?? '无信息'; - _time = widget.time ?? '无信息'; - _status = widget.status; + + String get _time { + if (widget.model.visit == null) + return '无信息'; + else + return DateUtil.formatDate( + widget.model.visit, + format: 'yyyy-MM-dd HH:mm', + ); + } + + // String get _visitorStatus { + // switch (widget.model.visitorStatus) { + // case 1: + // if (widget.model.effective.difference(DateTime.now()).isNegative) + // return '已过期'; + // return '未到'; + // case 2: + // return '已到'; + // case 3: + // return '已过期'; + // case 4: + // return '作废'; + // default: + // return '未知'; + // } + // } + + VisitorStatus get _visitorStatusEnum { + switch (widget.model.visitorStatus) { + case 1: + if (widget.model.effective.difference(DateTime.now()).isNegative) + return VisitorStatus.OUTDATE; + return VisitorStatus.NOT_VISIT; + case 2: + return VisitorStatus.VISIT_DONE; + case 3: + return VisitorStatus.OUTDATE; + default: + return null; + } } @override @@ -68,7 +87,7 @@ class _VisitorManagerCardState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - _adress, + widget.model.roomName, style: TextStyle( color: AppStyle.primaryTextColor, fontSize: 32.sp, @@ -84,7 +103,7 @@ class _VisitorManagerCardState extends State { ), AkuBox.w(8), Text( - '$_name先生', + widget.model.name, style: _textStyle, ), AkuBox.w(137), @@ -95,7 +114,7 @@ class _VisitorManagerCardState extends State { ), AkuBox.w(8), Text( - _plate, + widget.model.carNum ?? '无信息', style: _textStyle, ), Spacer(), @@ -122,7 +141,7 @@ class _VisitorManagerCardState extends State { child: Transform.rotate( angle: pi / 4, child: Image.asset( - _statusImage(_status), + _statusImage(_visitorStatusEnum), width: 140.w, height: 140.w, ), diff --git a/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart b/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart index 20c48ea..57b2963 100644 --- a/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart +++ b/lib/ui/sub_pages/visitor_manager/visitor_manager_page.dart @@ -1,4 +1,5 @@ // Flutter imports: +import 'package:aku_community_manager/ui/sub_pages/visitor_manager/visitor_manager_view.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -78,43 +79,12 @@ class _VisitorManagerPageState extends State preferredSize: Size.fromHeight(88.w)), body: TabBarView( controller: _tabController, - children: _tabs.map((e) => _buildListView(_tabs.indexOf(e))).toList(), + children: [ + VisitorManagerView(status: null), + VisitorManagerView(status: 1), + VisitorManagerView(status: 2), + VisitorManagerView(status: 3), + ], )); } - - Widget _buildListView(int index) { - List _selectCards; - switch (index) { - case 0: - _selectCards = _cards; - break; - case 1: - _selectCards = _cards - .where((element) => element.status == VisitorStatus.NOT_VISIT) - .toList(); - break; - case 2: - _selectCards = _cards - .where((element) => element.status == VisitorStatus.VISIT_DONE) - .toList(); - break; - case 3: - _selectCards = _cards - .where((element) => element.status == VisitorStatus.OUTDATE) - .toList(); - break; - } - return ListView( - padding: EdgeInsets.only(left: 32.w, right: 32.w), - children: _selectCards - .map((e) => VisitorManagerCard( - adress: e.adress, - name: e.name, - plate: e.plate, - time: e.time, - status: e.status, - )) - .toList(), - ); - } } diff --git a/lib/ui/sub_pages/visitor_manager/visitor_manager_view.dart b/lib/ui/sub_pages/visitor_manager/visitor_manager_view.dart new file mode 100644 index 0000000..9a1013b --- /dev/null +++ b/lib/ui/sub_pages/visitor_manager/visitor_manager_view.dart @@ -0,0 +1,46 @@ +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/models/manager/visitor_item_model.dart'; +import 'package:aku_community_manager/ui/sub_pages/visitor_manager/visitor_manager_card.dart'; +import 'package:aku_community_manager/ui/sub_pages/visitor_manager/visitor_manager_page.dart'; +import 'package:aku_community_manager/ui/widgets/common/bee_list_view.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; + +class VisitorManagerView extends StatefulWidget { + final int status; + VisitorManagerView({Key key, @required this.status}) : super(key: key); + + @override + _VisitorManagerViewState createState() => _VisitorManagerViewState(); +} + +class _VisitorManagerViewState extends State + with AutomaticKeepAliveClientMixin { + EasyRefreshController _refreshController = EasyRefreshController(); + @override + Widget build(BuildContext context) { + super.build(context); + return BeeListView( + path: API.manage.visitorList, + controller: _refreshController, + convert: (model) { + return model.tableList + .map((e) => VisitorItemModel.fromJson(e)) + .toList(); + }, + extraParams: {'visitorStatus': widget.status}, + builder: (items) { + return ListView.builder( + itemBuilder: (context, index) { + final VisitorItemModel item = items[index]; + return VisitorManagerCard(model: item); + }, + itemCount: items.length, + ); + }, + ); + } + + @override + bool get wantKeepAlive => true; +}