You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
6.0 KiB

import 'package:akuCommunity/model/common/img_model.dart';
import 'package:flutter/material.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.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/ui/manager/questionnaire/questionnaire_detail_page.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:akuCommunity/widget/bee_scaffold.dart';
import 'package:akuCommunity/widget/others/stack_avatar.dart';
class QuestionnairePage extends StatefulWidget {
QuestionnairePage({Key key}) : super(key: key);
@override
_QuestionnairePageState createState() => _QuestionnairePageState();
}
class _QuestionnairePageState extends State<QuestionnairePage> {
EasyRefreshController _easyRefreshController = EasyRefreshController();
@override
void initState() {
super.initState();
}
String _getButtonText(int status) {
switch (status) {
case 1:
case 2:
return '去投票';
case 3:
return '已结束';
case 4:
return '已投票';
default:
return '';
}
}
Widget _buildCard(QuestionnaireModel model) {
return GestureDetector(
onTap: () {
Get.to(() => QuestionnaireDetailPage(
id: model.id,
));
},
child: 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_PLACEHOLDER_WEBP,
image: API.image(ImgModel.first(model.imgUrls)),
),
),
),
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: DateUtil.formatDateStr(model.beginDate,
format: "MM月dd日 HH:mm") +
'' +
DateUtil.formatDateStr(model.endDate,
format: "MM月dd日 HH:mm"),
),
])),
],
).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: () {
Get.to(() => QuestionnaireDetailPage(
id: model.id,
));
},
child: (_getButtonText(model.status))
.text
.black
.size(20.sp)
.bold
.make(),
),
],
)
],
),
).material(color: Colors.transparent),
);
}
@override
void dispose() {
_easyRefreshController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BeeScaffold(
title: '问卷调查',
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);
}),
);
}
}