完成活动管理接口对接

hmxc
小赖 4 years ago
parent 93e944e557
commit b4f9c87d3e

@ -38,4 +38,10 @@ class _User {
class _Manage { class _Manage {
/// ///
String get fixers => '/user/repair/findRepairOrganization'; String get fixers => '/user/repair/findRepairOrganization';
///app
String get acitivityList => '/user/activity/list';
///app id
String get activityDetail => '/user/activity/findById';
} }

@ -0,0 +1,66 @@
import 'package:aku_community_manager/models/common/img_model.dart';
import 'package:common_utils/common_utils.dart';
class ActivityDetailModel {
int id;
String title;
String content;
String activityStartTime;
String activityEndTime;
String location;
String registrationEndTime;
List<ImgModel> imgUrls;
ImgModel get firstImg {
if (imgUrls.isEmpty)
return null;
else
return imgUrls.first;
}
DateTime get registrationEnd => DateUtil.getDateTime(registrationEndTime);
DateTime get activityStart => DateUtil.getDateTime(activityStartTime);
DateTime get activityEnd => DateUtil.getDateTime(activityEndTime);
ActivityDetailModel(
{this.id,
this.title,
this.content,
this.activityStartTime,
this.activityEndTime,
this.location,
this.registrationEndTime,
this.imgUrls});
ActivityDetailModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
title = json['title'];
content = json['content'];
activityStartTime = json['activityStartTime'];
activityEndTime = json['activityEndTime'];
location = json['location'];
registrationEndTime = json['registrationEndTime'];
if (json['imgUrls'] != null) {
imgUrls = new List<ImgModel>();
json['imgUrls'].forEach((v) {
imgUrls.add(new ImgModel.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['title'] = this.title;
data['content'] = this.content;
data['activityStartTime'] = this.activityStartTime;
data['activityEndTime'] = this.activityEndTime;
data['location'] = this.location;
data['registrationEndTime'] = this.registrationEndTime;
if (this.imgUrls != null) {
data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList();
}
return data;
}
}

@ -0,0 +1,67 @@
import 'package:aku_community_manager/models/common/img_model.dart';
import 'package:common_utils/common_utils.dart';
class ActivityItemModel {
int id;
String title;
String sponsorName;
String location;
String registrationStartTime;
String registrationEndTime;
String createDate;
List<ImgModel> imgUrls;
ImgModel get firstImg {
if (imgUrls.isEmpty)
return null;
else
return imgUrls.first;
}
DateTime get create => DateUtil.getDateTime(createDate);
DateTime get registrationStart => DateUtil.getDateTime(registrationStartTime);
DateTime get registrationEnd => DateUtil.getDateTime(registrationEndTime);
ActivityItemModel(
{this.id,
this.title,
this.sponsorName,
this.location,
this.registrationStartTime,
this.registrationEndTime,
this.createDate,
this.imgUrls});
ActivityItemModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
title = json['title'];
sponsorName = json['sponsorName'];
location = json['location'];
registrationStartTime = json['registrationStartTime'];
registrationEndTime = json['registrationEndTime'];
createDate = json['createDate'];
if (json['imgUrls'] != null) {
imgUrls = new List<ImgModel>();
json['imgUrls'].forEach((v) {
imgUrls.add(new ImgModel.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['title'] = this.title;
data['sponsorName'] = this.sponsorName;
data['location'] = this.location;
data['registrationStartTime'] = this.registrationStartTime;
data['registrationEndTime'] = this.registrationEndTime;
data['createDate'] = this.createDate;
if (this.imgUrls != null) {
data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList();
}
return data;
}
}

@ -1,19 +1,24 @@
// Flutter imports: // Flutter imports:
import 'package:aku_community_manager/const/api.dart';
import 'package:aku_community_manager/models/manager/activity_detail_model.dart';
import 'package:aku_community_manager/utils/network/base_model.dart';
import 'package:aku_community_manager/utils/network/net_util.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// Package imports: // Package imports:
import 'package:common_utils/common_utils.dart'; import 'package:common_utils/common_utils.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:velocity_x/velocity_x.dart';
// Project imports: // Project imports:
import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/style/app_style.dart';
import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:aku_community_manager/tools/screen_tool.dart';
import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/tools/widget_tool.dart';
import 'package:aku_community_manager/ui/sub_pages/activity_manager/fake_activity_model.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart';
class ActivityDetailPage extends StatefulWidget { class ActivityDetailPage extends StatefulWidget {
final FakeActivityManagerModel model; final int id;
ActivityDetailPage({Key key, @required this.model}) : super(key: key); ActivityDetailPage({Key key, @required this.id}) : super(key: key);
@override @override
_ActivityDetailPageState createState() => _ActivityDetailPageState(); _ActivityDetailPageState createState() => _ActivityDetailPageState();
@ -21,61 +26,73 @@ class ActivityDetailPage extends StatefulWidget {
class _ActivityDetailPageState extends State<ActivityDetailPage> { class _ActivityDetailPageState extends State<ActivityDetailPage> {
static const String format = 'yyyy年MM月dd日HH:mm'; static const String format = 'yyyy年MM月dd日HH:mm';
ActivityDetailModel _detailModel;
String get startDate => String get startDate =>
DateUtil.formatDate(widget.model.dateStart, format: format); DateUtil.formatDate(_detailModel.activityStart, format: format);
String get endDate => String get endDate =>
DateUtil.formatDate(widget.model.dateEnd, format: format); DateUtil.formatDate(_detailModel.activityEnd, format: format);
String get checkInDate => String get checkInDate =>
DateUtil.formatDate(widget.model.checkInDate, format: format); DateUtil.formatDate(_detailModel.registrationEnd, format: format);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AkuScaffold( return AkuScaffold(
title: '活动详情', title: '活动详情',
body: ListView( body: EasyRefresh(
children: [ firstRefresh: true,
Hero( header: MaterialHeader(),
tag: widget.model.title, onRefresh: () async {
child: Image.asset( BaseModel model = await NetUtil().get(
widget.model.imgPath, API.manage.activityDetail,
height: 228.w, params: {'activityId': widget.id},
fit: BoxFit.cover, );
), _detailModel = ActivityDetailModel.fromJson(model.data);
), setState(() {});
Padding( },
padding: EdgeInsets.symmetric( child: _detailModel == null
vertical: 24.w, ? SizedBox()
horizontal: 32.w, : ListView(
), children: [
child: Column( FadeInImage.assetNetwork(
mainAxisSize: MainAxisSize.min, placeholder: R.ASSETS_PLACEHOLDER_WEBP,
children: [ image: _detailModel.firstImg?.url ?? '',
Text( fit: BoxFit.cover,
widget.model.title,
style: TextStyle(
color: AppStyle.primaryTextColor,
fontSize: 36.sp,
fontWeight: FontWeight.bold,
), ),
), Padding(
AkuBox.h(16), padding: EdgeInsets.symmetric(
Text( vertical: 24.w,
widget.model.article, horizontal: 32.w,
style: TextStyle( ),
color: AppStyle.primaryTextColor, child: Column(
fontSize: 28.sp, mainAxisSize: MainAxisSize.min,
children: [
Text(
_detailModel.title,
style: TextStyle(
color: AppStyle.primaryTextColor,
fontSize: 36.sp,
fontWeight: FontWeight.bold,
),
),
AkuBox.h(16),
Text(
_detailModel.content,
style: TextStyle(
color: AppStyle.primaryTextColor,
fontSize: 28.sp,
),
),
AkuBox.h(40),
_buildTile('开始时间', startDate),
_buildTile('结束时间', endDate),
_buildTile('地点', _detailModel.location),
_buildTile('参与人数', '不限'),
_buildTile('报名截止', checkInDate),
],
),
), ),
), ],
AkuBox.h(40), ),
_buildTile('开始时间', startDate),
_buildTile('结束时间', endDate),
_buildTile('地点', widget.model.location),
_buildTile('参与人数', widget.model.people),
_buildTile('报名截止', checkInDate),
],
),
),
],
), ),
); );
} }

@ -1,4 +1,6 @@
// Flutter imports: // Flutter imports:
import 'package:aku_community_manager/models/manager/activity_item_model.dart';
import 'package:aku_community_manager/ui/sub_pages/activity_manager/activity_detail_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// Package imports: // Package imports:
@ -9,26 +11,21 @@ import 'package:get/route_manager.dart';
import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/style/app_style.dart';
import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:aku_community_manager/tools/screen_tool.dart';
import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/tools/widget_tool.dart';
import 'package:aku_community_manager/ui/sub_pages/activity_manager/activity_detail_page.dart';
import 'package:aku_community_manager/ui/sub_pages/activity_manager/fake_activity_model.dart';
class ActivityManagerCard extends StatelessWidget { class ActivityManagerCard extends StatelessWidget {
final ActivityItemModel model;
const ActivityManagerCard({Key key, @required this.model}) : super(key: key);
String get startDate => String get startDate =>
DateUtil.formatDate(model.dateStart, format: 'yyyy-MM-dd'); DateUtil.formatDate(model.registrationStart, format: 'yyyy-MM-dd');
String get endDate => String get endDate =>
DateUtil.formatDate(model.dateEnd, format: 'yyyy-MM-dd'); DateUtil.formatDate(model.registrationEnd, format: 'yyyy-MM-dd');
final FakeActivityManagerModel model;
const ActivityManagerCard({Key key, @required this.model}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
margin: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w), margin: EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w),
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
Get.to(ActivityDetailPage(model: model)); Get.to(ActivityDetailPage(id: model.id));
}, },
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -41,8 +38,9 @@ class ActivityManagerCard extends StatelessWidget {
width: double.infinity, width: double.infinity,
child: Hero( child: Hero(
tag: model.title, tag: model.title,
child: Image.asset( child: FadeInImage.assetNetwork(
model.imgPath, placeholder: R.ASSETS_PLACEHOLDER_WEBP,
image: model.firstImg?.url ?? '',
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),
@ -63,7 +61,7 @@ class ActivityManagerCard extends StatelessWidget {
), ),
), ),
AkuBox.h(12), AkuBox.h(12),
_buildTile('主办方:', model.hostName), _buildTile('主办方:', model.sponsorName),
_buildTile('地点:', model.location), _buildTile('地点:', model.location),
_buildTile('报名时间:', '$startDate\$endDate'), _buildTile('报名时间:', '$startDate\$endDate'),
], ],

@ -1,10 +1,14 @@
// Flutter imports: // Flutter imports:
import 'package:aku_community_manager/const/api.dart';
import 'package:aku_community_manager/models/manager/activity_item_model.dart';
import 'package:aku_community_manager/ui/widgets/common/bee_list_view.dart';
import 'package:aku_community_manager/utils/network/base_list_model.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// Project imports: // Project imports:
import 'package:aku_community_manager/ui/sub_pages/activity_manager/activity_manager_card.dart'; import 'package:aku_community_manager/ui/sub_pages/activity_manager/activity_manager_card.dart';
import 'package:aku_community_manager/ui/sub_pages/activity_manager/fake_activity_model.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
class ActivityManagerPage extends StatefulWidget { class ActivityManagerPage extends StatefulWidget {
ActivityManagerPage({Key key}) : super(key: key); ActivityManagerPage({Key key}) : super(key: key);
@ -14,16 +18,27 @@ class ActivityManagerPage extends StatefulWidget {
} }
class _ActivityManagerPageState extends State<ActivityManagerPage> { class _ActivityManagerPageState extends State<ActivityManagerPage> {
EasyRefreshController _refreshController = EasyRefreshController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AkuScaffold( return AkuScaffold(
title: '活动管理', title: '活动管理',
body: ListView.builder( body: BeeListView(
itemBuilder: (context, index) { builder: (List<dynamic> items) {
final model = fakeAcitivityManagerModels[index]; return ListView.builder(
return ActivityManagerCard(model: model); itemBuilder: (context, index) {
return ActivityManagerCard(model: items[index]);
},
itemCount: items.length,
);
}, },
itemCount: fakeAcitivityManagerModels.length, controller: _refreshController,
convert: (BaseListModel model) {
return model.tableList
.map((e) => ActivityItemModel.fromJson(e))
.toList();
},
path: API.manage.acitivityList,
), ),
); );
} }

@ -1,58 +0,0 @@
// Project imports:
import 'package:aku_community_manager/const/resource.dart';
class FakeActivityManagerModel {
String title;
String imgPath;
String location;
String hostName;
String article;
String people;
DateTime dateStart;
DateTime dateEnd;
DateTime checkInDate;
FakeActivityManagerModel({
this.title,
this.imgPath,
this.location,
this.hostName,
this.article,
this.people,
this.dateStart,
this.dateEnd,
this.checkInDate,
});
}
List<FakeActivityManagerModel> fakeAcitivityManagerModels = [
FakeActivityManagerModel(
title: '华茂悦峰社区第三届六一亲子活动',
imgPath: R.ASSETS_STATIC_TEMP_F1_WEBP,
location: '中央活动区',
hostName: '深圳万科物业有限公司',
article:
'''为丰富文化体育生活,不断增进小区凝聚力和人与人之间的协作能力,市委政法委机关党办、机关工会联合举办“我参与、我健康、我快乐”系列主题活动。
姿
''',
people: '不限',
dateStart: DateTime(2020, 4, 12, 12, 0),
dateEnd: DateTime(2020, 4, 15, 12, 0),
checkInDate: DateTime(2020, 4, 13, 12, 0),
),
FakeActivityManagerModel(
title: '宁化社区第一届煎蛋比赛报名开始',
imgPath: R.ASSETS_STATIC_TEMP_F5_WEBP,
location: '中央活动区',
hostName: '深圳万科物业有限公司',
article:
'''为丰富文化体育生活,不断增进小区凝聚力和人与人之间的协作能力,市委政法委机关党办、机关工会联合举办“我参与、我健康、我快乐”系列主题活动。
姿
''',
people: '不限',
dateStart: DateTime(2020, 4, 12, 12, 0),
dateEnd: DateTime(2020, 4, 15, 12, 0),
checkInDate: DateTime(2020, 4, 13, 12, 0),
),
];

@ -0,0 +1,120 @@
// Flutter imports:
import 'package:aku_community_manager/utils/network/base_list_model.dart';
import 'package:aku_community_manager/utils/network/net_util.dart';
import 'package:flutter/material.dart';
// Package imports:
import 'package:flutter_easyrefresh/easy_refresh.dart';
/// ## BeeListView
///```dart
///BeeListView(
/// path: API.someAPI,
/// convert: (model) {
/// return model.tableList
/// .map((e) => SomeModel.fromJson(e))
/// .toList();
/// },
/// controller: _refreshController,
/// builder: (items) {
/// return ListView.builder(
/// itemBuilder: (context, index) {
/// return _buildSomeItem(items[index]);
/// },
/// itemCount: items.length,
/// );
/// },
///)
///```
class BeeListView<T> extends StatefulWidget {
///API path
final String path;
///same as EasyRefreshController
final EasyRefreshController controller;
///
///
///BaseListModel to T
///
///T is a tableList item.
///
///```dart
///...
///convert: (model) {
/// return model.tableList
/// .map((e) => SomeModel.fromJson(e))
/// .toList();
///},
///...
///```
final List<T> Function(BaseListModel model) convert;
///
final Widget Function(List<T> items) builder;
///
final int size;
///
final Map<String, dynamic> extraParams;
BeeListView({
Key key,
@required this.path,
@required this.controller,
@required this.convert,
@required this.builder,
this.size = 10,
this.extraParams,
}) : super(key: key);
@override
_BeeListViewState<T> createState() => _BeeListViewState<T>();
}
class _BeeListViewState<T> extends State<BeeListView> {
int _pageNum = 1;
BaseListModel _model = BaseListModel.zero();
List<T> _models = [];
Map<String, dynamic> get _params {
Map<String, dynamic> tempMap = {
'pageNum': _pageNum,
'size': widget.size,
};
tempMap.addAll(widget.extraParams ?? {});
return tempMap;
}
@override
Widget build(BuildContext context) {
return EasyRefresh(
controller: widget.controller,
header: MaterialHeader(),
footer: MaterialFooter(),
onRefresh: () async {
_pageNum = 1;
_model = await NetUtil().getList(
widget.path,
params: _params,
);
_models = widget.convert(_model);
widget.controller?.resetLoadState();
setState(() {});
},
firstRefresh: true,
onLoad: () async {
_pageNum++;
_model = await NetUtil().getList(
widget.path,
params: _params,
);
_models.addAll(widget.convert(_model) as List<T>);
if (_pageNum >= _model.pageCount)
widget.controller.finishLoad(noMore: true);
setState(() {});
},
child: widget.builder(_models),
);
}
}
Loading…
Cancel
Save