add structure
This commit is contained in:
123
lib/vo/product.dart
Normal file
123
lib/vo/product.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
|
||||
import '../util.dart';
|
||||
|
||||
class Product {
|
||||
String accountID;
|
||||
String id;
|
||||
String name;
|
||||
int price;
|
||||
int color;
|
||||
String action;
|
||||
int quantity;
|
||||
int displayOrder;
|
||||
Map<String, int> priceHistory;
|
||||
bool isDisable;
|
||||
|
||||
// used for buyer registration
|
||||
int dailySale;
|
||||
int storageCapacity;
|
||||
int dailyQuota;
|
||||
|
||||
int oldPirce;
|
||||
|
||||
//used for do item
|
||||
String storageID;
|
||||
String storageName;
|
||||
|
||||
String get getname => this.name;
|
||||
int get getprice => this.price;
|
||||
List<ProductPrice> get getPrices => this
|
||||
.priceHistory
|
||||
.entries
|
||||
.map((k) => ProductPrice(
|
||||
name: name,
|
||||
price: k.value,
|
||||
date: DateUtil.toLocal(DateTime.parse(k.key)),
|
||||
displayOrder: displayOrder))
|
||||
.toList();
|
||||
|
||||
Product(
|
||||
{this.accountID,
|
||||
this.id,
|
||||
this.name,
|
||||
this.price,
|
||||
this.color,
|
||||
this.action,
|
||||
this.priceHistory,
|
||||
this.dailySale,
|
||||
this.storageCapacity,
|
||||
this.dailyQuota,
|
||||
this.quantity,
|
||||
this.oldPirce,
|
||||
this.displayOrder,
|
||||
this.storageID,
|
||||
this.storageName,
|
||||
this.isDisable});
|
||||
|
||||
factory Product.clone(Product p) {
|
||||
return Product(
|
||||
accountID: p.accountID,
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
price: p.price,
|
||||
color: p.color,
|
||||
displayOrder: p.displayOrder,
|
||||
action: p.action,
|
||||
isDisable: p.isDisable);
|
||||
}
|
||||
|
||||
factory Product.fromJson(Map<String, dynamic> json) {
|
||||
return Product(
|
||||
name: json['name'],
|
||||
price: int.parse(json['price']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'account_id': accountID,
|
||||
'id': id,
|
||||
'name': name,
|
||||
'price': price,
|
||||
'color': color,
|
||||
'display_order': displayOrder,
|
||||
'action': action,
|
||||
'disable': isDisable
|
||||
};
|
||||
}
|
||||
|
||||
factory Product.fromMap(Map<String, dynamic> map, String id) {
|
||||
return Product(
|
||||
id: id,
|
||||
name: map['name'] ?? map['product_name'],
|
||||
price: map['price'],
|
||||
color: map['color'],
|
||||
quantity: map['quantity'],
|
||||
displayOrder: map['display_order'],
|
||||
priceHistory: map['price_history']?.cast<String, int>(),
|
||||
storageID: map['storage_id'],
|
||||
storageName: map['storage_name'],
|
||||
isDisable: map['disable']);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'User{name: $name, price: $price,storageID:$storageID,storageName:$storageName,isDisable:$isDisable}';
|
||||
}
|
||||
}
|
||||
|
||||
class ProductPrice {
|
||||
DateTime date;
|
||||
int price;
|
||||
String name;
|
||||
int displayOrder;
|
||||
ProductPrice({this.date, this.price, this.name, this.displayOrder});
|
||||
|
||||
int compareTo(ProductPrice other) {
|
||||
int r = other.date.compareTo(this.date);
|
||||
if (r == 0) {
|
||||
return this.displayOrder.compareTo(other.displayOrder);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user