From a1ffe977937e9a4595a5d78a3333fc6311cd162f Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Fri, 5 Feb 2021 17:17:47 +0800 Subject: [PATCH] dock interface:questionnaire/list, add questionnaire page --- lib/constants/api.dart | 3 + lib/constants/application_objects.dart | 3 +- lib/model/manager/questinnaire_model.dart | 92 ++++++++ .../event_activity/event_voting_page.dart | 5 +- .../questionnaire_page.dart | 219 ++++++++++-------- 5 files changed, 227 insertions(+), 95 deletions(-) create mode 100644 lib/model/manager/questinnaire_model.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 9026c6e6..d21b7f4a 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -154,6 +154,9 @@ class _Manager { ///活动投票:用户投票 String get vote => '/user/eventVoting/vote'; + + ///问卷调查:app查询所有的问卷调查list + String get questionnaireList => '/user/questionnaire/list'; } class _Community { diff --git a/lib/constants/application_objects.dart b/lib/constants/application_objects.dart index b5f60b11..811ca7f1 100644 --- a/lib/constants/application_objects.dart +++ b/lib/constants/application_objects.dart @@ -1,4 +1,5 @@ // Flutter imports: +import 'package:akuCommunity/pages/questionnaire_page/questionnaire_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; @@ -66,7 +67,7 @@ List appObjects = [ AO('物品出门', R.ASSETS_APPLICATIONS_GOODS_OUT_PNG, GoodsDetoPage()), AO('投诉表扬', R.ASSETS_APPLICATIONS_COMPLAINT_PNG, AdvicePage(type: AdviceType.COMPLAIN)), - AO('问卷调查', R.ASSETS_APPLICATIONS_QUESTION_PNG, QuestionnaireDetailsPage()), + AO('问卷调查', R.ASSETS_APPLICATIONS_QUESTION_PNG, QuestionnairePage()), AO('装修管理', R.ASSETS_APPLICATIONS_DECORATION_PNG, FitupManagePage()), AO('借还管理', R.ASSETS_APPLICATIONS_BORROW_PNG, GoodsManagePage()), AO('一键报警', R.ASSETS_APPLICATIONS_POLICE_PNG, AlarmPage()), diff --git a/lib/model/manager/questinnaire_model.dart b/lib/model/manager/questinnaire_model.dart new file mode 100644 index 00000000..e6141eea --- /dev/null +++ b/lib/model/manager/questinnaire_model.dart @@ -0,0 +1,92 @@ +import 'package:akuCommunity/model/common/img_model.dart'; + +class QuestionnaireModel { + int id; + String title; + String description; + String beginDate; + String endDate; + int status; + int answerNum; + List imgUrls; + List headImgURls; + + QuestionnaireModel( + {this.id, + this.title, + this.description, + this.beginDate, + this.endDate, + this.status, + this.answerNum, + this.imgUrls, + this.headImgURls}); + + QuestionnaireModel.fromJson(Map json) { + id = json['id']; + title = json['title']; + description = json['description']; + beginDate = json['beginDate']; + endDate = json['endDate']; + status = json['status']; + answerNum = json['answerNum']; + if (json['imgUrls'] != null) { + imgUrls = new List(); + json['imgUrls'].forEach((v) { + imgUrls.add(new ImgModel.fromJson(v)); + }); + }else imgUrls=[]; + if (json['headImgURls'] != null) { + headImgURls = new List(); + json['headImgURls'].forEach((v) { + headImgURls.add(new ImgModel.fromJson(v)); + }); + }else headImgURls=[]; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['title'] = this.title; + data['description'] = this.description; + data['beginDate'] = this.beginDate; + data['endDate'] = this.endDate; + data['status'] = this.status; + data['answerNum'] = this.answerNum; + if (this.imgUrls != null) { + data['imgUrls'] = this.imgUrls.map((v) => v.toJson()).toList(); + } + if (this.headImgURls != null) { + data['headImgURls'] = this.headImgURls.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class ImgUrls { + String url; + String size; + int longs; + int paragraph; + int sort; + + ImgUrls({this.url, this.size, this.longs, this.paragraph, this.sort}); + + ImgUrls.fromJson(Map json) { + url = json['url']; + size = json['size']; + longs = json['longs']; + paragraph = json['paragraph']; + sort = json['sort']; + } + + Map toJson() { + final Map data = new Map(); + data['url'] = this.url; + data['size'] = this.size; + data['longs'] = this.longs; + data['paragraph'] = this.paragraph; + data['sort'] = this.sort; + return data; + } +} diff --git a/lib/pages/event_activity/event_voting_page.dart b/lib/pages/event_activity/event_voting_page.dart index 02b151d5..4ef5730b 100644 --- a/lib/pages/event_activity/event_voting_page.dart +++ b/lib/pages/event_activity/event_voting_page.dart @@ -39,12 +39,13 @@ class _EventVotingPageState extends State { switch (status) { case 1: case 2: - return '去投票'; + return '去参与'; case 3: return '已结束'; case 4: - return '已投票'; + return '已填写'; default: + return ''; } } diff --git a/lib/pages/questionnaire_page/questionnaire_page.dart b/lib/pages/questionnaire_page/questionnaire_page.dart index 748dca6a..a52baec7 100644 --- a/lib/pages/questionnaire_page/questionnaire_page.dart +++ b/lib/pages/questionnaire_page/questionnaire_page.dart @@ -1,16 +1,12 @@ -// Flutter imports: -import 'package:flutter/cupertino.dart'; +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/manager/questinnaire_model.dart'; +import 'package:akuCommunity/pages/things_page/widget/bee_list_view.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:akuCommunity/widget/others/stack_avatar.dart'; import 'package:flutter/material.dart'; - -// Package imports: -import 'package:pull_to_refresh/pull_to_refresh.dart'; - -// Project imports: -import 'package:akuCommunity/pages/questionnaire_page/questionnaire_details_page/questionnaire_details_page.dart'; -import 'package:akuCommunity/routers/page_routers.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:akuCommunity/utils/headers.dart'; -import 'package:akuCommunity/widget/bee_scaffold.dart'; -import 'package:akuCommunity/widget/community_card.dart'; class QuestionnairePage extends StatefulWidget { QuestionnairePage({Key key}) : super(key: key); @@ -20,100 +16,139 @@ class QuestionnairePage extends StatefulWidget { } class _QuestionnairePageState extends State { - List images = [ - "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1151143562,4115642159&fm=26&gp=0.jpg", - "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2551412680,857245643&fm=26&gp=0.jpg", - "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3604827221,1047385274&fm=26&gp=0.jpg", - ]; - List> _listView = [ - { - 'imagePath': - 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600076026158&di=da8cffada3104f26e80cea2c7f54ce70&imgtype=0&src=http%3A%2F%2F0429.zxdyw.com%2FU_Image%2F2017%2F0925%2Fe%2F20170925104340_9160.jpg', - 'title': '狮子王画室课程满意程度', - 'subtitle': '亲爱的家长朋友,您好很高心为您的孩子选…', - 'timeZone': '06月17日 15:20至06月17日 18:00', - 'peopleNum': 37, - 'isOver': false, - 'isVote': true - }, - { - 'imagePath': - 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600076048900&di=ac816ae35f05e5f1d959449d36efa6d3&imgtype=0&src=http%3A%2F%2Fimage.ludedc.com%2Fimage%2F20151125%2F251632264b19f55f136042.jpg', - 'title': '小区色绿环保,绿色种植比例调查问卷', - 'subtitle': '各位业主,您好,本着小区结合现代化发展…', - 'timeZone': '06月01日 13:20至06月01日 18:00', - 'peopleNum': 989, - 'isOver': false, - 'isVote': true - }, - { - 'imagePath': - 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600076094434&di=8f88dc7dab7e716a0db1bde7dc55309b&imgtype=0&src=http%3A%2F%2Fqcloud.dpfile.com%2Fpc%2FceOXxAYp_7zhCWKRpYBCahIE_4Q5VlY5lWZsONVu0ahouI64PLnDNyiI08ZHM8ZfTYGVDmosZWTLal1WbWRW3A.jpg', - 'title': '美嘉舞蹈工作室问卷调查', - 'subtitle': '各位家长,应照舞蹈室的委托,开展一次问…', - 'timeZone': '06月01日 13:20至06月01日 18:00', - 'peopleNum': 989, - 'isOver': true, - 'isVote': false - } - ]; - RefreshController _refreshController = - RefreshController(initialRefresh: false); - + EasyRefreshController _easyRefreshController; @override void initState() { super.initState(); } - void _onRefresh() async { - await Future.delayed(Duration(milliseconds: 1500)); - - _refreshController.refreshCompleted(); - } - - void _onLoading() async { - await Future.delayed(Duration(milliseconds: 1500)); - - if (mounted) setState(() {}); - _refreshController.loadComplete(); + String _getButtonText(int status) { + switch (status) { + case 1: + case 2: + return '去投票'; + case 3: + return '已结束'; + case 4: + return '已投票'; + default: + return ''; + } } - void detailsRouter(String imagePath, title) { - QuestionnaireDetailsPage(bundle: Bundle() - ..putMap('details', { - 'title': title, - 'imagePath': imagePath, - }),).to; + Widget _buildCard(QuestionnaireModel model) { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8.w), + color: kForeGroundColor, + ), + width: double.infinity, + // height: 236.w, + padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 12.w), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + children: [ + Container( + decoration: + BoxDecoration(borderRadius: BorderRadius.circular(8.w)), + width: 160.w, + height: 120.w, + child: ClipRRect( + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_LOGO_PNG, + image: API.image(model.imgUrls.first.url)), + ), + ), + 20.w.widthBox, + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + model.title.text.black.size(28.sp).make(), + 6.w.heightBox, + model.description.text + .color(ktextSubColor) + .size(28.sp) + .maxLines(1) + .overflow(TextOverflow.ellipsis) + .make(), + 6.w.heightBox, + RichText( + text: TextSpan( + text: '参与时间:', + style: TextStyle( + color: ktextSubColor, + fontSize: 24.sp, + ), + children: [ + TextSpan( + style: TextStyle( + color: ktextPrimary, + fontSize: 24.sp, + ), + text: model.beginDate + '至' + model.endDate, + ), + ])), + ], + ).expand() + ], + ), + 40.w.heightBox, + Row( + children: [ + StackAvatar( + avatars: model.headImgURls.map((e) => e.url).toList()), + 26.w.widthBox, + '${model.answerNum}人已参加'.text.black.size(20.sp).make(), + Spacer(), + MaterialButton( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(22.w)), + color: model.status == 3 ? kDarkSubColor : kPrimaryColor, + minWidth: 120.w, + height: 44.w, + // padding: + // EdgeInsets.symmetric(horizontal: 30.w, vertical: 8.w), + elevation: 0, + onPressed: () {}, + child: (_getButtonText(model.status)) + .text + .black + .size(20.sp) + .bold + .make(), + ), + ], + ) + ], + ), + ); } @override Widget build(BuildContext context) { return BeeScaffold( title: '问卷调查', - body: RefreshConfiguration( - hideFooterWhenNotFull: true, - child: SmartRefresher( - controller: _refreshController, - header: WaterDropHeader(), - footer: ClassicFooter(), - onRefresh: _onRefresh, - onLoading: _onLoading, - enablePullUp: true, - child: ListView.builder( - itemBuilder: (BuildContext context, int index) => CommunityCard( - imagePath: _listView[index]['imagePath'], - title: _listView[index]['title'], - subtitle: _listView[index]['subtitle'], - timeZone: _listView[index]['timeZone'], - headList: images, - isOver: _listView[index]['isOver'], - peopleNum: _listView[index]['peopleNum'], - fun: detailsRouter, - ), - itemCount: _listView.length, - ), - ), - ), + body: BeeListView( + path: API.manager.questionnaireList, + controller: _easyRefreshController, + convert: (model) { + return model.tableList + .map((e) => QuestionnaireModel.fromJson(e)) + .toList(); + }, + builder: (items) { + return ListView.separated( + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 20.w), + itemBuilder: (context, index) { + return _buildCard(items[index]); + }, + separatorBuilder: (_, __) { + return 24.w.heightBox; + }, + itemCount: items.length); + }), ); } }