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, this.productNumber, this.productSpecification}); final int? id; final String? productNumber; final String? productSpecification; 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 files; final CompanyModel? company; final DictItemModel? unit; factory ProductModel.fromJson(Map 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"], productNumber: json['productNumber'], productSpecification: json['productSpecification'], unitId: json["unitId"], namePinyin: json["namePinyin"], files: json["files"] == null ? [] : List.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 toJson() => { "id": id, "createdAt": createdAt?.toIso8601String(), "updatedAt": updatedAt?.toIso8601String(), "name": name, "remark": remark, "isDelete": isDelete, "companyId": companyId, "unitId": unitId, 'productNumber': productNumber, 'productSpecification': productSpecification, "namePinyin": namePinyin, "files": files.map((x) => x.toJson()).toList(), "company": company?.toJson(), "unit": unit?.toJson(), }; }