challenge_model.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'package:flutter/foundation.dart';
  2. // 待办
  3. @immutable
  4. class ChallengeModel {
  5. final int? id;
  6. final int actionType; // 1-愿景 2-战略目标 3-挑战目标 4-待办目标
  7. final String title;
  8. final String description;
  9. final String cover;
  10. final int sort;
  11. final int status; // 1-正常 2-进行中 3-已完成 4-失败放弃
  12. final int difficulty; // 1-简单 2-正常 3-困难 4-地狱
  13. final String remark;
  14. final DateTime? startDate;
  15. final DateTime? endDate;
  16. final DateTime? finishDate;
  17. final DateTime? planFinishDate;
  18. final int parentId;
  19. const ChallengeModel({
  20. required this.id,
  21. required this.actionType,
  22. required this.title,
  23. required this.description,
  24. required this.cover,
  25. required this.sort,
  26. required this.status,
  27. required this.difficulty,
  28. required this.remark,
  29. required this.startDate,
  30. required this.endDate,
  31. required this.finishDate,
  32. required this.parentId,
  33. required this.planFinishDate,
  34. });
  35. factory ChallengeModel.fromJson(Map<String, dynamic> json) {
  36. return ChallengeModel(
  37. id: json['id'] as int?,
  38. title: json['title'] as String,
  39. description: json['description'] as String,
  40. startDate: DateTime.parse(json['start_date'] as String),
  41. endDate: DateTime.parse(json['end_date'] as String),
  42. cover: json['cover'] as String,
  43. sort: json['sort'] as int,
  44. status: json['status'] as int,
  45. remark: json['remark'] as String,
  46. finishDate: DateTime.parse(json['finish_date'] as String),
  47. parentId: json['parent_id'] as int,
  48. actionType: 0,
  49. difficulty: 0,
  50. planFinishDate: DateTime.parse(json['end_date'] as String),
  51. );
  52. }
  53. /// 转换为JSON
  54. // Map<String, dynamic> toJson() => {
  55. // if (id != null) 'id': id,
  56. // 'title': title,
  57. // 'description': description,
  58. // 'startDate': startDate.toIso8601String(),
  59. // 'endDate': endDate.toIso8601String(),
  60. // };
  61. ChallengeModel copyWith({
  62. int? id,
  63. int? actionType,
  64. String? title,
  65. String? description,
  66. int? status,
  67. int? sort,
  68. String? cover,
  69. String? remark,
  70. int? difficulty,
  71. DateTime? startDate,
  72. DateTime? endDate,
  73. DateTime? finishDate,
  74. DateTime? planFinishDate,
  75. int? parentId,
  76. }) {
  77. return ChallengeModel(
  78. id: id ?? this.id,
  79. actionType: actionType ?? this.actionType,
  80. title: title ?? this.title,
  81. description: description ?? this.description,
  82. startDate: startDate ?? this.startDate,
  83. endDate: endDate ?? this.endDate,
  84. cover: cover ?? this.cover,
  85. sort: sort ?? this.sort,
  86. status: status ?? this.status,
  87. remark: remark ?? this.remark,
  88. finishDate: finishDate ?? this.finishDate,
  89. planFinishDate: planFinishDate ?? this.planFinishDate,
  90. parentId: parentId ?? this.parentId,
  91. difficulty: difficulty ?? this.difficulty,
  92. );
  93. }
  94. }