From 14a5fda4623feaec2302ad31c3c0b0f85025fd01 Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Mon, 8 Feb 2021 11:10:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=AD=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E6=88=90=E9=97=AE=E5=8D=B7=E8=B0=83=E6=9F=A5?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/quetionnaire_submit_model.dart | 50 ++++++++ .../questionnaire_detail_page.dart | 113 +++++++++++------- .../questionnaire_truefalse.dart | 69 +++++++++++ 3 files changed, 192 insertions(+), 40 deletions(-) create mode 100644 lib/model/manager/quetionnaire_submit_model.dart create mode 100644 lib/ui/manager/questionnaire/questionnaire_truefalse.dart diff --git a/lib/model/manager/quetionnaire_submit_model.dart b/lib/model/manager/quetionnaire_submit_model.dart new file mode 100644 index 00000000..8219ac8c --- /dev/null +++ b/lib/model/manager/quetionnaire_submit_model.dart @@ -0,0 +1,50 @@ +// class QuestionnaireSubmitModel { +// int id; +// List appQuestionnaireAnswerSubmits; + +// QuestionnaireSubmitModel({this.id, this.appQuestionnaireAnswerSubmits}); + +// QuestionnaireSubmitModel.fromJson(Map json) { +// id = json['id']; +// if (json['appQuestionnaireAnswerSubmits'] != null) { +// appQuestionnaireAnswerSubmits = new List(); +// json['appQuestionnaireAnswerSubmits'].forEach((v) { +// appQuestionnaireAnswerSubmits +// .add(new AppQuestionnaireAnswerSubmits.fromJson(v)); +// }); +// } +// } + +// Map toJson() { +// final Map data = new Map(); +// data['id'] = this.id; +// if (this.appQuestionnaireAnswerSubmits != null) { +// data['appQuestionnaireAnswerSubmits'] = +// this.appQuestionnaireAnswerSubmits.map((v) => v.toJson()).toList(); +// } +// return data; +// } +// } + +class AppQuestionnaireAnswerSubmits { + int topicId; + List choiceAnswer; + String shortAnswer; + + AppQuestionnaireAnswerSubmits( + {this.topicId, this.choiceAnswer, this.shortAnswer}); + + AppQuestionnaireAnswerSubmits.fromJson(Map json) { + topicId = json['topicId']; + choiceAnswer = json['choiceAnswer'].cast(); + shortAnswer = json['shortAnswer']; + } + + Map toJson() { + final Map data = new Map(); + data['topicId'] = this.topicId; + data['choiceAnswer'] = this.choiceAnswer; + data['shortAnswer'] = this.shortAnswer; + return data; + } +} diff --git a/lib/ui/manager/questionnaire/questionnaire_detail_page.dart b/lib/ui/manager/questionnaire/questionnaire_detail_page.dart index e09bcdda..fb733295 100644 --- a/lib/ui/manager/questionnaire/questionnaire_detail_page.dart +++ b/lib/ui/manager/questionnaire/questionnaire_detail_page.dart @@ -1,12 +1,13 @@ import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/model/manager/questionnaire_detail_model.dart'; +import 'package:akuCommunity/model/manager/quetionnaire_submit_model.dart'; import 'package:akuCommunity/pages/manager_func.dart'; import 'package:akuCommunity/ui/manager/questionnaire/questionnaire_siglecheck.dart'; +import 'package:akuCommunity/ui/manager/questionnaire/questionnaire_truefalse.dart'; import 'package:akuCommunity/ui/manager/questionnaire/questionnarie_raido_check.dart'; import 'package:akuCommunity/widget/bee_divider.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; -import 'package:akuCommunity/widget/buttons/bee_single_check.dart'; import 'package:akuCommunity/widget/buttons/bottom_button.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -26,16 +27,14 @@ class QuestionnaireDetailPage extends StatefulWidget { class _QuestionnaireDetailPageState extends State { QuestionnaireDetialModel _model; bool _onload = true; - int _select; - List _radio = []; - int _expanded; - String _expand; - String _short; + + List _submitModels = []; Widget _emptyWidget() { return Container(); } - Widget _expandedCheck(String title, List answers) { + Widget _expandedCheck(String title, List answers, + List submitModels, int index) { return Container( width: double.infinity, child: Column( @@ -57,8 +56,8 @@ class _QuestionnaireDetailPageState extends State { actions: answers .map((e) => CupertinoActionSheetAction( onPressed: () { - _expanded = e.id; - _expand = e.answer; + submitModels[index].choiceAnswer.first = e.id; + submitModels[index].shortAnswer = e.answer; Get.back(); setState(() {}); }, @@ -81,7 +80,7 @@ class _QuestionnaireDetailPageState extends State { width: double.infinity, padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 28.w), - child: (_expand ?? '请选择') + child: (submitModels[index].shortAnswer ?? '请选择') .text .color(ktextSubColor) .size(28.sp) @@ -101,7 +100,8 @@ class _QuestionnaireDetailPageState extends State { ); } - Widget _shortAnswer(String title) { + Widget _shortAnswer(String title, + List submitModels, int index) { return Container( width: double.infinity, child: Column( @@ -127,7 +127,7 @@ class _QuestionnaireDetailPageState extends State { EdgeInsets.symmetric(horizontal: 32.w, vertical: 28.w), isDense: true), onChanged: (value) { - _short = value; + submitModels[index].shortAnswer = value; setState(() {}); }, ), @@ -137,6 +137,54 @@ class _QuestionnaireDetailPageState extends State { ); } + Widget _topicWidget(QuestionnaireTopicVoList questionModel, + List submitModels, int index) { + switch (questionModel.type) { + case 1: + return QuestionnaireSingleCheck( + title: questionModel.topic, + selected: submitModels[index].choiceAnswer.first, + onPressed: (id) { + submitModels[index].choiceAnswer.first = id; + setState(() {}); + }, + answers: questionModel.questionnaireChoiceVoList); + + case 2: + return QuestionnaireRadioCheck( + title: questionModel.topic, + selected: submitModels[index].choiceAnswer, + answers: questionModel.questionnaireChoiceVoList, + onPressed: (id) { + if (submitModels[index].choiceAnswer.contains(id)) { + submitModels[index].choiceAnswer.remove(id); + } else { + submitModels[index].choiceAnswer.add(id); + } + setState(() {}); + }, + ); + + case 3: + return _expandedCheck(questionModel.topic, + questionModel.questionnaireChoiceVoList, submitModels, index); + case 4: + return QuestionnaireTruefalse( + title: questionModel.topic, + selected: submitModels[index].choiceAnswer.first, + onPressed: (id) { + submitModels[index].choiceAnswer.first = id; + setState(() {}); + }, + ); + case 5: + return _shortAnswer(questionModel.topic, submitModels, index); + + default: + return Container(); + } + } + @override Widget build(BuildContext context) { return BeeScaffold( @@ -147,6 +195,13 @@ class _QuestionnaireDetailPageState extends State { onRefresh: () async { _model = await ManagerFunc.questionnairefindById(widget.id); _onload = false; + _submitModels = _model.questionnaireTopicVoList + .map((e) => AppQuestionnaireAnswerSubmits( + topicId: e.id, + choiceAnswer: [-1], + )) + .toList(); + print(_submitModels); setState(() {}); }, child: _onload @@ -180,34 +235,12 @@ class _QuestionnaireDetailPageState extends State { .size(28.sp) .make(), 130.w.heightBox, - QuestionnaireSingleCheck( - title: 'title', - selected: _select, - onPressed: (id) { - _select = id; - setState(() {}); - }, - answers: _model.questionnaireTopicVoList.first - .questionnaireChoiceVoList), - QuestionnaireRadioCheck( - title: 'title', - selected: _radio, - answers: _model.questionnaireTopicVoList.first - .questionnaireChoiceVoList, - onPressed: (id) { - if (_radio.contains(id)) { - _radio.remove(id); - } else { - _radio.add(id); - } - setState(() {}); - }, - ), - _expandedCheck( - 'title', - _model.questionnaireTopicVoList.first - .questionnaireChoiceVoList), - _shortAnswer('title') + ...List.generate( + _model.questionnaireTopicVoList.length, + (index) => _topicWidget( + _model.questionnaireTopicVoList[index], + _submitModels, + index)).sepWidget(separate: 80.w.heightBox), ], ), ), diff --git a/lib/ui/manager/questionnaire/questionnaire_truefalse.dart b/lib/ui/manager/questionnaire/questionnaire_truefalse.dart new file mode 100644 index 00000000..8fad657a --- /dev/null +++ b/lib/ui/manager/questionnaire/questionnaire_truefalse.dart @@ -0,0 +1,69 @@ +import 'package:akuCommunity/widget/buttons/bee_single_check.dart'; +import 'package:flutter/material.dart'; +import 'package:velocity_x/velocity_x.dart'; +import 'package:akuCommunity/utils/headers.dart'; + +class QuestionnaireTruefalse extends StatefulWidget { + final String title; + final int selected; + final Function(int id) onPressed; + QuestionnaireTruefalse({Key key, this.title, this.selected, this.onPressed}) + : super(key: key); + + @override + _QuestionnaireTruefalseState createState() => _QuestionnaireTruefalseState(); +} + +class _QuestionnaireTruefalseState extends State { + @override + Widget build(BuildContext context) { + return Container( + width: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + widget.title.text.black.size(32.sp).bold.make(), + 64.w.heightBox, + Padding( + padding: EdgeInsets.symmetric(horizontal: 96.w), + child: Flex( + direction: Axis.horizontal, + children: [ + Row( + children: [ + GestureDetector( + onTap: () { + widget.onPressed(1); + }, + child: BeeSingleCheck( + value: 1, + groupValue: widget.selected, + ), + ), + 16.w.widthBox, + '正确'.text.black.size(28.sp).make(), + ], + ).expand(flex: 1), + Row( + children: [ + GestureDetector( + onTap: () { + widget.onPressed(0); + }, + child: BeeSingleCheck( + value: 0, + groupValue: widget.selected, + ), + ), + 16.w.widthBox, + '错误'.text.black.size(28.sp).make(), + ], + ).expand(flex: 1), + ], + ), + ) + ], + ), + ); + } +}