| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import 'package:flutter/foundation.dart';
- import 'package:intl/intl.dart';
- // 待办
- @immutable
- class ChallengeModel {
- final int? id;
- final int actionType; // 1-愿景 2-战略目标 3-挑战目标 4-待办目标
- final String title;
- final String description;
- final String cover;
- final int sort;
- final int status; // 1-正常 2-进行中 3-已完成 4-失败放弃
- final int difficulty; // 1-简单 2-正常 3-困难 4-地狱
- final String remark;
- final DateTime? startDate;
- final DateTime? endDate;
- final DateTime? finishDate;
- final DateTime? planFinishDate;
- final int parentId;
- const ChallengeModel({
- required this.id,
- required this.actionType,
- required this.title,
- required this.description,
- required this.cover,
- required this.sort,
- required this.status,
- required this.difficulty,
- required this.remark,
- required this.startDate,
- required this.endDate,
- required this.finishDate,
- required this.parentId,
- required this.planFinishDate,
- });
- factory ChallengeModel.fromJson(Map<String, dynamic> json) {
- return ChallengeModel(
- id: json['id'] as int?,
- title: json['title'] as String,
- description: json['description'] as String,
- startDate: DateTime.parse(json['start_date'] as String),
- endDate: DateTime.parse(json['end_date'] as String),
- cover: json['cover'] as String,
- sort: json['sort'] as int,
- status: json['status'] as int,
- remark: json['remark'] as String,
- finishDate: DateTime.parse(json['finish_date'] as String),
- parentId: json['parent_id'] as int,
- actionType: 0,
- difficulty: 0,
- planFinishDate: DateTime.parse(json['end_date'] as String),
- );
- }
- /// 转换为JSON
- Map<String, dynamic> toJson() => {
- if (id != null) 'id': id,
- 'title': title,
- 'description': description,
- };
- ChallengeModel copyWith({
- int? id,
- int? actionType,
- String? title,
- String? description,
- int? status,
- int? sort,
- String? cover,
- String? remark,
- int? difficulty,
- DateTime? startDate,
- DateTime? endDate,
- DateTime? finishDate,
- DateTime? planFinishDate,
- int? parentId,
- }) {
- return ChallengeModel(
- id: id ?? this.id,
- actionType: actionType ?? this.actionType,
- title: title ?? this.title,
- description: description ?? this.description,
- startDate: startDate ?? this.startDate,
- endDate: endDate ?? this.endDate,
- cover: cover ?? this.cover,
- sort: sort ?? this.sort,
- status: status ?? this.status,
- remark: remark ?? this.remark,
- finishDate: finishDate ?? this.finishDate,
- planFinishDate: planFinishDate ?? this.planFinishDate,
- parentId: parentId ?? this.parentId,
- difficulty: difficulty ?? this.difficulty,
- );
- }
- }
- // 挑战类的 form 表单,用于绑定等
- class ChallengeFormModel {
- int? id;
- int actionType; // 1-愿景 2-战略目标 3-挑战目标 4-待办目标
- String title;
- String description;
- String cover;
- int sort;
- int status; // 1-正常 2-进行中 3-已完成 4-失败放弃
- int difficulty; // 1-简单 2-正常 3-困难 4-地狱
- String remark;
- DateTime? startDate;
- DateTime? endDate;
- DateTime? finishDate;
- DateTime? planFinishDate;
- int parentId;
- ChallengeFormModel({
- this.id,
- this.actionType = 0,
- this.title = '',
- this.description = '',
- this.cover = '',
- this.sort = 100,
- this.status = 0,
- this.difficulty = 0,
- this.remark = '',
- this.startDate,
- this.endDate,
- this.finishDate,
- this.planFinishDate,
- this.parentId = 0
- });
- // 转换为Map方便打印
- Map<String, dynamic> toMap() {
- return {
- 'id': id,
- 'actionType': actionType ,
- 'title': title,
- 'description': description,
- 'cover': cover,
- 'sort': sort,
- 'status': status,
- 'difficulty': difficulty,
- 'remark': remark,
- 'startDate': startDate != null ? DateFormat('yyyy-MM-dd').format(startDate!) : null,
- 'endDate': endDate != null ? DateFormat('yyyy-MM-dd').format(endDate!) : null,
- 'finishDate': finishDate != null ? DateFormat('yyyy-MM-dd').format(finishDate!) : null,
- 'planFinishDate': planFinishDate != null ? DateFormat('yyyy-MM-dd').format(planFinishDate!) : null,
- 'parentId': parentId,
- };
- }
- // 添加转换方法
- factory ChallengeFormModel.fromChallenge(ChallengeModel challenge) {
- return ChallengeFormModel(
- id: challenge.id,
- actionType: challenge.actionType,
- title: challenge.title,
- description: challenge.description,
- cover: challenge.cover,
- sort: challenge.sort,
- status: challenge.status,
- difficulty: challenge.difficulty,
- remark: challenge.remark,
- startDate: challenge.startDate,
- endDate: challenge.endDate,
- finishDate: challenge.finishDate,
- planFinishDate: challenge.planFinishDate,
- parentId: challenge.parentId,
- );
- }
- ChallengeModel toChallenge() {
- return ChallengeModel(
- id: id,
- actionType: actionType,
- title: title,
- description: description,
- cover: cover,
- sort: sort,
- status: status,
- difficulty: difficulty,
- remark: remark,
- startDate: startDate,
- endDate: endDate,
- finishDate: finishDate,
- planFinishDate: planFinishDate,
- parentId: parentId,
- );
- }
- }
|