From 568004e8cb29f53bbefc946c4d361363739fee60 Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Thu, 13 Jul 2023 09:43:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../date_select/custom_page.dart | 74 ++++++++++++++++++ .../date_select/day_report_page.dart | 39 ++++------ .../date_select/monthly_report_page.dart | 52 ++++++------- .../date_select/week_report_page.dart | 78 ++++++++++--------- .../home/overview/trade_summary.dart | 69 +++++++++++----- lib/main.dart | 3 + lib/retrofit/retrofit_api.g.dart | 2 +- pubspec.yaml | 2 +- 8 files changed, 209 insertions(+), 110 deletions(-) create mode 100644 lib/business_system/date_select/custom_page.dart diff --git a/lib/business_system/date_select/custom_page.dart b/lib/business_system/date_select/custom_page.dart new file mode 100644 index 00000000..2f7076b3 --- /dev/null +++ b/lib/business_system/date_select/custom_page.dart @@ -0,0 +1,74 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:syncfusion_flutter_datepicker/datepicker.dart'; + +import '../../view_widget/my_appbar.dart'; + +class CustomPage extends StatefulWidget { + + @override + State createState() { + return _CustomPage(); + } +} + +class _CustomPage extends State{ + String customDate = ''; + String endCustomDate = ''; + + void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { + setState(() { + if (args.value is PickerDateRange) { + customDate = + DateFormat('yyyy年MM月dd日').format(args.value.startDate).toString() + + ' 至 ' + + DateFormat('yyyy年MM月dd日') + .format(args.value.endDate ?? args.value.startDate) + .toString(); + } + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: MyAppBar( + title: "时间选择", + titleColor: Colors.black, + leadingColor: Colors.black, + background: Colors.white, + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context, customDate,); + }, + child: Text( + "确定", + style: TextStyle( + color: Colors.black, + fontSize: 16, + ), + ), + ), + ], + ), + body: Stack( + children: [ + Positioned( + left: 0, + top: 0, + right: 0, + bottom: 0, + child: SfDateRangePicker( + onSelectionChanged: _onSelectionChanged, + selectionMode: DateRangePickerSelectionMode.range, + initialSelectedRange: PickerDateRange( + DateTime.now().subtract(const Duration(days: 4)), + DateTime.now().add(const Duration(days: 3))), + ), + ) + ], + )); + } +} diff --git a/lib/business_system/date_select/day_report_page.dart b/lib/business_system/date_select/day_report_page.dart index ca41ce18..008e3b9e 100644 --- a/lib/business_system/date_select/day_report_page.dart +++ b/lib/business_system/date_select/day_report_page.dart @@ -15,9 +15,7 @@ class DayReportPage extends StatefulWidget { class _DayReportPage extends State{ String _selectedDate = ''; - String _dateCount = ''; String _range = ''; - String _rangeCount = ''; @override void initState() { @@ -34,11 +32,7 @@ class _DayReportPage extends State{ .format(args.value.endDate ?? args.value.startDate) .toString(); } else if (args.value is DateTime) { - _selectedDate = args.value.toString(); - } else if (args.value is List) { - _dateCount = args.value.length.toString(); - } else { - _rangeCount = args.value.length.toString(); + _selectedDate = args.value.toString().substring(0,10); } }); } @@ -51,29 +45,26 @@ class _DayReportPage extends State{ titleColor: Colors.black, leadingColor: Colors.black, background: Colors.white, + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context, _selectedDate); + }, + child: Text( + "确定", + style: TextStyle( + color: Colors.black, + fontSize: 16, + ), + ), + ), + ], ), body: Stack( children: [ Positioned( left: 0, - right: 0, top: 0, - height: 80, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('Selected date: ' + _selectedDate), - Text('Selected date count: ' + _dateCount), - Text('Selected range: ' + _range), - Text('Selected ranges count: ' + _rangeCount) - ], - ), - ), - Positioned( - left: 0, - top: 80, right: 0, bottom: 0, child: SfDateRangePicker( diff --git a/lib/business_system/date_select/monthly_report_page.dart b/lib/business_system/date_select/monthly_report_page.dart index c7af9817..c4632fcf 100644 --- a/lib/business_system/date_select/monthly_report_page.dart +++ b/lib/business_system/date_select/monthly_report_page.dart @@ -14,26 +14,13 @@ class MonthlyReportPage extends StatefulWidget { } class _MonthlyReportPage extends State{ - String _selectedDate = ''; - String _dateCount = ''; - String _range = ''; - String _rangeCount = ''; + String _monthlyDate = ''; + final DateRangePickerController _controller = DateRangePickerController(); void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { setState(() { - if (args.value is PickerDateRange) { - _range = - DateFormat('dd/MM/yyyy').format(args.value.startDate).toString() + - ' - ' + - DateFormat('dd/MM/yyyy') - .format(args.value.endDate ?? args.value.startDate) - .toString(); - } else if (args.value is DateTime) { - _selectedDate = args.value.toString(); - } else if (args.value is List) { - _dateCount = args.value.length.toString(); - } else { - _rangeCount = args.value.length.toString(); + if (args.value is DateTime) { + _monthlyDate = args.value.toString().substring(0,10); } }); } @@ -46,6 +33,20 @@ class _MonthlyReportPage extends State{ titleColor: Colors.black, leadingColor: Colors.black, background: Colors.white, + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context, _monthlyDate); + }, + child: Text( + "确定", + style: TextStyle( + color: Colors.black, + fontSize: 16, + ), + ), + ), + ], ), body: Stack( children: [ @@ -59,10 +60,7 @@ class _MonthlyReportPage extends State{ mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Selected date: ' + _selectedDate), - Text('Selected date count: ' + _dateCount), - Text('Selected range: ' + _range), - Text('Selected ranges count: ' + _rangeCount) + Text('Selected date: ' + _monthlyDate), ], ), ), @@ -73,11 +71,13 @@ class _MonthlyReportPage extends State{ bottom: 0, child: SfDateRangePicker( onSelectionChanged: _onSelectionChanged, - selectionMode: DateRangePickerSelectionMode.range, - selectionShape: DateRangePickerSelectionShape.rectangle, - initialSelectedRange: PickerDateRange( - DateTime.now().subtract(const Duration(days: 4)), - DateTime.now().add(const Duration(days: 3))), + selectionMode: DateRangePickerSelectionMode.single, + // selectionShape: DateRangePickerSelectionShape.rectangle, + // initialSelectedRange: PickerDateRange( + // DateTime.now().subtract(const Duration(days: 4)), + // DateTime.now().add(const Duration(days: 3))), + view: DateRangePickerView.year, + controller: _controller, ), ) ], diff --git a/lib/business_system/date_select/week_report_page.dart b/lib/business_system/date_select/week_report_page.dart index f0c240d0..e9041873 100644 --- a/lib/business_system/date_select/week_report_page.dart +++ b/lib/business_system/date_select/week_report_page.dart @@ -14,26 +14,32 @@ class WeekReportPage extends StatefulWidget { } class _WeekReportPage extends State{ - String _selectedDate = ''; - String _dateCount = ''; String _range = ''; - String _rangeCount = ''; + String _endRange = ''; + final DateRangePickerController _controller = DateRangePickerController(); void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { setState(() { if (args.value is PickerDateRange) { - _range = - DateFormat('dd/MM/yyyy').format(args.value.startDate).toString() + - ' - ' + - DateFormat('dd/MM/yyyy') - .format(args.value.endDate ?? args.value.startDate) - .toString(); - } else if (args.value is DateTime) { - _selectedDate = args.value.toString(); - } else if (args.value is List) { - _dateCount = args.value.length.toString(); - } else { - _rangeCount = args.value.length.toString(); + final startDate = args.value.startDate; + final endDate = args.value.endDate; + if (endDate.difference(startDate).inDays > 6) { + _controller.selectedRange = PickerDateRange( + startDate.add(Duration(days: 6)), + endDate, + ); + } else { + _range = DateFormat('yyyy年MM月dd日').format(args.value.startDate).toString() + + ' 至 ' + + DateFormat('yyyy年MM月dd日') + .format(args.value.endDate ?? args.value.startDate) + .toString(); + _endRange = DateFormat('yyyy年MM月dd日').format(args.value.startDate).toString() + + ' 至 ' + + DateFormat('yyyy年MM月dd日') + .format(args.value.endDate ?? args.value.startDate) + .toString(); + } } }); } @@ -46,39 +52,37 @@ class _WeekReportPage extends State{ titleColor: Colors.black, leadingColor: Colors.black, background: Colors.white, + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context, _range,); + }, + child: Text( + "确定", + style: TextStyle( + color: Colors.black, + fontSize: 16, + ), + ), + ), + ], ), body: Stack( children: [ Positioned( left: 0, - right: 0, top: 0, - height: 80, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('Selected date: ' + _selectedDate), - Text('Selected date count: ' + _dateCount), - Text('Selected range: ' + _range), - Text('Selected ranges count: ' + _rangeCount) - ], - ), - ), - Positioned( - left: 0, - top: 80, right: 0, bottom: 0, child: SfDateRangePicker( onSelectionChanged: _onSelectionChanged, + minDate: DateTime.now().subtract(const Duration(days: 361)), + controller: _controller, // 添加控制器 + maxDate: DateTime.now().add(Duration(days: 365)), selectionMode: DateRangePickerSelectionMode.range, - startRangeSelectionColor:Color(0xFF30415B), - endRangeSelectionColor:Color(0xFF30415B), - initialSelectedRange: PickerDateRange( - DateTime.now().subtract(const Duration(days: 4)), - DateTime.now().add(const Duration(days: 3))), + startRangeSelectionColor: Color(0xFF30415B), + endRangeSelectionColor: Color(0xFF30415B), + todayHighlightColor: Color(0xFF30415B), ), ) ], diff --git a/lib/business_system/home/overview/trade_summary.dart b/lib/business_system/home/overview/trade_summary.dart index d0a7a7df..8bc7f5f1 100644 --- a/lib/business_system/home/overview/trade_summary.dart +++ b/lib/business_system/home/overview/trade_summary.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/my_footer.dart'; +import 'package:intl/intl.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -25,6 +26,15 @@ class _TradeSummary extends State { int operateSelect = 0; int expensesSelect = 0; int dateIndex = 0; + String selectedDate = ""; + String dayDate = "${DateTime.now().year}年${ DateTime.now().month}月${ DateTime.now().day}日"; + String weekDate =""; + String weekDateNum = "${DateTime.now().year}年${ DateTime.now().month}月${ DateTime.now().day}日 至 " + "${DateFormat("yyyy年MM月dd日").format(DateTime.parse(DateTime.now().add(Duration(days:6)).toString().substring(0,10)))}"; + String monthlyDate =""; + String monthlyDateNum = "${DateTime.now().year}年${ DateTime.now().month}月"; + String customDate =""; + String customDateNum = "${DateTime.now().year}年${ DateTime.now().month}月${ DateTime.now().day}日"; List lineChartSample2DataAmount = [LineChartSample2Data(0,40,"2023-03-09"), LineChartSample2Data(1,10,"2023-03-10"), @@ -200,20 +210,36 @@ class _TradeSummary extends State { behavior: HitTestBehavior.opaque, onTap: (){ if(dateIndex == 0){ - Navigator.of(context).pushNamed('/router/day_report_page'); + Navigator.of(context).pushNamed('/router/day_report_page').then((value) { + setState((){ + selectedDate = value; + }); + }); } else if(dateIndex == 1){ - Navigator.of(context).pushNamed('/router/week_report_page'); + Navigator.of(context).pushNamed('/router/week_report_page').then((value) { + setState((){ + weekDate = value; + }); + }); } else if(dateIndex == 2){ - Navigator.of(context).pushNamed('/router/monthly_report_page'); + Navigator.of(context).pushNamed('/router/monthly_report_page').then((value) { + setState((){ + monthlyDate = value; + }); + }); } else if(dateIndex == 3){ - Navigator.of(context).pushNamed('/router/monthly_report_page'); + Navigator.of(context).pushNamed('/router/custom_page').then((value){ + setState((){ + customDate = value; + }); + }); } }, child: Container( - width: 154.w, + width: 194.w, alignment: Alignment.center, padding: EdgeInsets.all(8), decoration: BoxDecoration( @@ -223,15 +249,17 @@ class _TradeSummary extends State { margin: EdgeInsets.only(bottom:16.h), child: Row( children: [ - Padding(padding: EdgeInsets.only(right: 20.w), + Expanded(child:Container( + alignment: Alignment.center, child: Text( - "2023年06月01日(今日)", + timeDate(), style: TextStyle( fontSize: 10.sp, fontWeight: MyFontWeight.regular, color: Colors.black, ), - ),), + ), + )), Image.asset( "assets/image/bs_calendar_logo.webp", width:15, @@ -265,6 +293,18 @@ class _TradeSummary extends State { ); } + String timeDate(){ + if(dateIndex == 0){ + return (selectedDate == "" || selectedDate == null) ? "${dayDate}(今日)":"${DateFormat("yyyy年MM月dd日").format(DateTime.parse(selectedDate))}(今日)"; + } + else if(dateIndex == 1){ + return (weekDate == "" || weekDate == null) ? weekDateNum : weekDate;} + else if(dateIndex == 2){ + return (monthlyDate == "" || monthlyDate == null) ? "${monthlyDateNum}(当月)":"${(DateFormat("yyyy年MM月dd日").format(DateTime.parse(monthlyDate)).substring(0,8))}(当月)";} + else if(dateIndex == 3){ + return (customDate == "" || customDate == null) ? "${customDateNum}(今日)" : customDate;} + } + ///经营分析 Widget operateAnalysis(){ return Column( @@ -495,17 +535,4 @@ class _TradeSummary extends State { ); } - showAlertDialog() { - showCupertinoModalPopup( - context: context, - builder: (context) { - return MaterialApp( - title: 'CalendarDatePicker2 Demo', - theme: ThemeData( - primarySwatch: Colors.blue, - ), - localizationsDelegates: GlobalMaterialLocalizations.delegates, - home: MonthlyReportPage(), - );},); - } } diff --git a/lib/main.dart b/lib/main.dart index ae703533..31208844 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -85,6 +85,7 @@ import 'package:huixiang/web/web_turntable_activity.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'business_system/business_page.dart'; +import 'business_system/date_select/custom_page.dart'; import 'business_system/date_select/day_report_page.dart'; import 'business_system/date_select/monthly_report_page.dart'; import 'business_system/date_select/week_report_page.dart'; @@ -501,4 +502,6 @@ Map routers = { WeekReportPage(), '/router/monthly_report_page': (context, {arguments}) => MonthlyReportPage(), + '/router/custom_page': (context, {arguments}) => + CustomPage(), }; diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index 4939dc2e..f86a8946 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -1644,7 +1644,7 @@ class _ApiService implements ApiService { data: _data); final value = BaseData>.fromJson( _result.data, - (json) => (json as List) + (json) => ((json??"") == "")?null:(json as List) .map( (i) => VipBenefitList.fromJson(i as Map)) .toList()); diff --git a/pubspec.yaml b/pubspec.yaml index 8899ea71..d307683e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -113,7 +113,7 @@ dependencies: # 时间选择器 flutter_datetime_picker: ^1.5.1 - syncfusion_flutter_datepicker: ^19.2.44 + syncfusion_flutter_datepicker: ^19.4.38 dev_dependencies: