From 989f9072a0e91b7b9c1191bf4010f68af4111d04 Mon Sep 17 00:00:00 2001 From: datang Date: Mon, 16 May 2022 08:49:09 +0800 Subject: [PATCH] push --- .../facility_preorder_date_picker.dart | 103 +++++++++++------- .../facility/facility_type_detail_card.dart | 1 + lib/widget/buttons/bee_check_radio.dart | 33 +++++- 3 files changed, 96 insertions(+), 41 deletions(-) diff --git a/lib/ui/community/facility/facility_preorder_date_picker.dart b/lib/ui/community/facility/facility_preorder_date_picker.dart index 44b978b9..4f4fb5c7 100644 --- a/lib/ui/community/facility/facility_preorder_date_picker.dart +++ b/lib/ui/community/facility/facility_preorder_date_picker.dart @@ -25,25 +25,16 @@ class FacilityPreorderDatePicker extends StatefulWidget { _FacilityPreorderDatePickerState(); } -class _FacilityPreorderDatePickerState extends State { +class _FacilityPreorderDatePickerState + extends State { List get _num => List.generate( getNum(widget.typeModel.openEndDT!) - getNum(widget.typeModel.openStartDT!), (index) => index + 1); DateTime? start; - List models=[]; + List models = []; - static Future> getPreorderData(int id) async { - BaseModel model = - await NetUtil().get(SAASAPI.facilities.allAppointmentPeriod, params: { - 'facilitiesManageId': id, - 'todayDate': DateTime.now(), - }); - if (model.success) { - return (model.data as List).toList(); - } - return []; - } + List _selectIndex = []; @override Widget build(BuildContext context) { @@ -62,7 +53,10 @@ class _FacilityPreorderDatePickerState extends State children: [ _datesList(index), 20.hb, - Divider(height: 1.0,color: Colors.black12,), + Divider( + height: 1.0, + color: Colors.black12, + ), ], ); }, @@ -74,52 +68,81 @@ class _FacilityPreorderDatePickerState extends State } Widget _datesList(int index) { - DateTime start=widget.typeModel.openStartDT!; - ()async{ + DateTime start = widget.typeModel.openStartDT!; + () async { BaseModel model = - await NetUtil().get(SAASAPI.facilities.allAppointmentPeriod, params: { + await NetUtil().get(SAASAPI.facilities.allAppointmentPeriod, params: { 'facilitiesManageId': widget.typeModel.id, 'todayDate': DateTime.now(), }); if (model.success) { - models=(model.data as List).toList(); + models = (model.data as List).toList(); } }; return GestureDetector( - onTap: (){ - + onTap: () { + print(getNum(start)+index); + if(!models.contains(getNum(start)+index)||start.add(Duration(minutes: 30 * index)).isAfter(DateTime.now())){ + if (_selectIndex.contains(index)) { + _selectIndex.remove(index); + } else { + _selectIndex.add(index); + } + } + setState(() {}); }, - child:Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - BeeCheckRadio( - value: getNum(start)+index, - groupValue: models, - backColor: start.isAfter(DateTime.now())?Colors.grey:Colors.white, - ), - 30.wb, - Text( - '${DateUtil.formatDate(start.add(Duration(minutes: 30*index)),format: 'HH:mm')}' - '~${DateUtil.formatDate(start.add(Duration(minutes: 30*(index+1))),format: 'HH:mm')}', + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + BeeCheckRadio( + value: index, + groupValue: _selectIndex, + canCheck: models.contains(getNum(start)+index), + ), + 30.wb, + Text( + '${DateUtil.formatDate(start.add(Duration(minutes: 30 * index)), format: 'HH:mm')}' + '~${DateUtil.formatDate(start.add(Duration(minutes: 30 * (index + 1))), format: 'HH:mm')}', style: TextStyle( fontSize: 30.sp, ), - ), - Spacer(), - start.isAfter(DateTime.now())?'已过期'.text.size(30.sp).color(Colors.black.withOpacity(0.45)).make(): - models.contains(getNum(start))?'已被他人预约'.text.size(30.sp).color(Colors.black.withOpacity(0.45)).make():SizedBox(), - ], - ), + ), + Spacer(), + isPass(start.add(Duration(minutes: 30 * index))) + ? '已过期' + .text + .size(30.sp) + .color(Colors.black.withOpacity(0.45)) + .make() + : models.contains(getNum(start)+index) + ? '已被他人预约' + .text + .size(30.sp) + .color(Colors.black.withOpacity(0.45)) + .make() + : SizedBox(), + ], + ), ); } } +bool isPass(DateTime date){ + if(date.hour 0) { - return hour * 2 + 1; + return hour * 2; } - return hour * 2; + return hour * 2 + 1; } diff --git a/lib/ui/community/facility/facility_type_detail_card.dart b/lib/ui/community/facility/facility_type_detail_card.dart index 88b883c7..d87f0761 100644 --- a/lib/ui/community/facility/facility_type_detail_card.dart +++ b/lib/ui/community/facility/facility_type_detail_card.dart @@ -1,3 +1,4 @@ +import 'package:common_utils/common_utils.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; diff --git a/lib/widget/buttons/bee_check_radio.dart b/lib/widget/buttons/bee_check_radio.dart index c5f4b285..d3e90b9e 100644 --- a/lib/widget/buttons/bee_check_radio.dart +++ b/lib/widget/buttons/bee_check_radio.dart @@ -10,6 +10,7 @@ class BeeCheckRadio extends StatefulWidget { final Widget? indent; final Color? backColor; final double? size; + final bool? canCheck; BeeCheckRadio( {Key? key, @@ -17,7 +18,8 @@ class BeeCheckRadio extends StatefulWidget { this.groupValue, this.indent, this.backColor, - this.size}) + this.size, + this.canCheck,}) : super(key: key); @override @@ -35,6 +37,35 @@ class _BeeCheckRadioState extends State { @override Widget build(BuildContext context) { + if(widget.canCheck!=null&&widget.canCheck!){ + return AnimatedContainer( + height: widget.size ?? 40.w, + width: widget.size ?? 40.w, + decoration: BoxDecoration( + color: Color(0xFF979797), + border: Border.all( + color: Color(0xFF979797), + width: 3.w, + ), + borderRadius: BorderRadius.circular((widget.size??40.w)/2), + ), + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + alignment: Alignment.center, + child: AnimatedOpacity( + duration: Duration(milliseconds: 500), + curve: Curves.easeInOutCubic, + opacity: 1, + child: + Icon( + CupertinoIcons.checkmark, + color: Colors.white, + size: 28.w, + ), + ), + ); + } + else return AnimatedContainer( height: widget.size ?? 40.w, width: widget.size ?? 40.w,