import 'package:flutter/foundation.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 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 toJson() => { // if (id != null) 'id': id, // 'title': title, // 'description': description, // 'startDate': startDate.toIso8601String(), // 'endDate': endDate.toIso8601String(), // }; 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, ); } }