chooseVisitTimeContent_state.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'package:shared/utils/date_time_utils.dart';
  2. import 'package:widgets/load_state_layout.dart';
  3. import 'visitTimeType.dart';
  4. class ChooseVisitTimeContentState{
  5. // 当前所选中的所有时间段集合
  6. List<VisitTimeContentItem> get allSelectedTimeList => visitTimeList.where((item) => item.isChecked??false).toList()??[];
  7. // extraTotalCost 总预约费用
  8. double get extraTotalCost {
  9. if(extraCostList?.isNotEmpty == true){
  10. return extraCostList?.fold(0.0, (previousValue, current) => previousValue! + current??0.0)??0.0;
  11. }else {
  12. return 0.0;
  13. }
  14. }
  15. //页面 LoadView 状态的展示
  16. LoadState loadingState;
  17. String? errorMessage;
  18. // 是否可多选
  19. bool? isMultiSelect;
  20. List<VisitTimeContentItem> visitTimeList = [];
  21. List<double>? extraCostList = []; // 预约费用(节假日/加急/夜间 费用的集合)
  22. String currentDate = DateTimeUtils.formatDate(DateTime.now(), format: "yyyy-MM-dd");
  23. ChooseVisitTimeContentState({
  24. this.loadingState = LoadState.State_Loading,
  25. this.errorMessage,
  26. this.isMultiSelect = false,
  27. required this.currentDate,
  28. this.extraCostList,
  29. List<VisitTimeContentItem>? visitTimeList,
  30. }) {
  31. this.visitTimeList = visitTimeList ?? [];
  32. }
  33. ChooseVisitTimeContentState copyWith({
  34. LoadState? loadingState,
  35. String? errorMessage,
  36. bool? isMultiSelect,
  37. List<VisitTimeContentItem>? visitTimeList,
  38. List<double>? extraCostList,
  39. String? currentDate,
  40. }) {
  41. return ChooseVisitTimeContentState(
  42. loadingState: loadingState ?? this.loadingState,
  43. errorMessage: errorMessage ?? this.errorMessage,
  44. isMultiSelect: isMultiSelect ?? this.isMultiSelect,
  45. visitTimeList: visitTimeList ?? this.visitTimeList,
  46. extraCostList: extraCostList ?? this.extraCostList,
  47. currentDate: currentDate ?? this.currentDate,
  48. );
  49. }
  50. }
  51. class VisitTimeContentItem{
  52. int? id;
  53. String? timeText;
  54. String? time;
  55. bool? urgent;
  56. bool? holiday;
  57. bool? night;
  58. bool? isChecked;
  59. bool? enable;
  60. VisitTimeContentItem({
  61. this.id,
  62. this.timeText,
  63. this.time,
  64. this.urgent,
  65. this.holiday,
  66. this.night,
  67. this.isChecked = false,
  68. this.enable = false,
  69. });
  70. VisitTimeContentItem copyWith({
  71. String? name,
  72. int? id,
  73. Map<String, dynamic>? type,
  74. bool? isChecked,
  75. bool? enable,
  76. }){
  77. return VisitTimeContentItem(
  78. id: id??this.id,
  79. timeText: timeText??this.timeText,
  80. time: time??this.time,
  81. urgent: urgent??this.urgent,
  82. holiday: holiday??this.holiday,
  83. night: night??this.night,
  84. isChecked: isChecked??this.isChecked,
  85. enable: enable??this.enable,
  86. );
  87. }
  88. }