mobile_skt/lib/models/product.model.dart

72 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:sk_base_mobile/models/dict_item.model.dart';
import 'package:sk_base_mobile/models/file.model.dart';
import 'company.model.dart';
class ProductModel {
ProductModel({
required this.id,
required this.createdAt,
required this.updatedAt,
required this.name,
required this.remark,
required this.isDelete,
required this.companyId,
required this.unitId,
required this.namePinyin,
required this.files,
required this.company,
required this.unit,
});
final int? id;
final DateTime? createdAt;
final DateTime? updatedAt;
final String? name;
final String? remark;
final int? isDelete;
final int? companyId;
final int? unitId;
final String? namePinyin;
final List<FileModel> files;
final CompanyModel? company;
final DictItemModel? unit;
factory ProductModel.fromJson(Map<String, dynamic> json) {
return ProductModel(
id: json["id"],
createdAt: DateTime.tryParse(json["createdAt"] ?? ""),
updatedAt: DateTime.tryParse(json["updatedAt"] ?? ""),
name: json["name"],
remark: json["remark"],
isDelete: json["isDelete"],
companyId: json["companyId"],
unitId: json["unitId"],
namePinyin: json["namePinyin"],
files: json["files"] == null
? []
: List<FileModel>.from(
json["files"]!.map((x) => FileModel.fromJson(x))),
company: json["company"] == null
? null
: CompanyModel.fromJson(json["company"]),
unit: json["unit"] == null ? null : DictItemModel.fromJson(json["unit"]),
);
}
Map<String, dynamic> toJson() => {
"id": id,
"createdAt": createdAt?.toIso8601String(),
"updatedAt": updatedAt?.toIso8601String(),
"name": name,
"remark": remark,
"isDelete": isDelete,
"companyId": companyId,
"unitId": unitId,
"namePinyin": namePinyin,
"files": files.map((x) => x?.toJson()).toList(),
"company": company?.toJson(),
"unit": unit?.toJson(),
};
}