2024-04-09 11:44:55 +08:00
|
|
|
import 'package:sk_base_mobile/util/common.util.dart';
|
|
|
|
|
|
|
|
class DeptModel extends TreeNode<DeptModel> {
|
2024-03-28 15:13:27 +08:00
|
|
|
DeptModel({
|
|
|
|
required this.id,
|
|
|
|
required this.createdAt,
|
|
|
|
required this.updatedAt,
|
|
|
|
required this.name,
|
|
|
|
required this.orderNo,
|
2024-04-09 11:44:55 +08:00
|
|
|
this.parent,
|
|
|
|
this.children,
|
2024-03-28 15:13:27 +08:00
|
|
|
});
|
|
|
|
|
2024-04-09 11:44:55 +08:00
|
|
|
final int id;
|
2024-03-28 15:13:27 +08:00
|
|
|
final DateTime? createdAt;
|
|
|
|
final DateTime? updatedAt;
|
2024-04-09 11:44:55 +08:00
|
|
|
final String name;
|
|
|
|
final int orderNo;
|
|
|
|
final DeptModel? parent;
|
|
|
|
List<DeptModel>? children = [];
|
2024-03-28 15:13:27 +08:00
|
|
|
|
|
|
|
factory DeptModel.fromJson(Map<String, dynamic> json) {
|
|
|
|
return DeptModel(
|
2024-04-09 11:44:55 +08:00
|
|
|
id: json["id"] ?? 0,
|
2024-03-28 15:13:27 +08:00
|
|
|
createdAt: DateTime.tryParse(json["createdAt"] ?? ""),
|
|
|
|
updatedAt: DateTime.tryParse(json["updatedAt"] ?? ""),
|
2024-04-09 11:44:55 +08:00
|
|
|
name: json["name"] ?? "",
|
|
|
|
orderNo: json["orderNo"] ?? 0,
|
|
|
|
parent:
|
|
|
|
json["parent"] == null ? null : DeptModel.fromJson(json["parent"]),
|
|
|
|
children: json["children"] == null
|
|
|
|
? []
|
|
|
|
: List<DeptModel>.from(
|
|
|
|
json["children"]!.map((x) => DeptModel.fromJson(x))),
|
2024-03-28 15:13:27 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
"id": id,
|
|
|
|
"createdAt": createdAt?.toIso8601String(),
|
|
|
|
"updatedAt": updatedAt?.toIso8601String(),
|
|
|
|
"name": name,
|
|
|
|
"orderNo": orderNo,
|
2024-04-09 11:44:55 +08:00
|
|
|
"parent": parent?.toJson(),
|
|
|
|
"children": children?.map((x) => x.toJson()).toList(),
|
2024-03-28 15:13:27 +08:00
|
|
|
};
|
|
|
|
}
|