41 lines
1.4 KiB
Dart
41 lines
1.4 KiB
Dart
// 功能描述:用户收货地址模型,列表脱敏展示、编辑使用本人完整数据。
|
||
// 版本:1.0.0。
|
||
class ShippingAddress {
|
||
const ShippingAddress({
|
||
this.identity = '',
|
||
required this.address,
|
||
required this.contactName,
|
||
required this.contactPhone,
|
||
this.longitude = '',
|
||
this.latitude = '',
|
||
this.isDefault = false,
|
||
});
|
||
final String identity, address, contactName, contactPhone, longitude, latitude;
|
||
final bool isDefault;
|
||
|
||
/// 从兼容地址响应读取字段;历史空联系人在编辑时要求补齐。
|
||
factory ShippingAddress.fromJson(Map<String, Object?> json) => ShippingAddress(
|
||
identity: json['identity'] as String? ?? '',
|
||
address: json['address'] as String? ?? '',
|
||
contactName: json['contact_name'] as String? ?? '',
|
||
contactPhone: json['contact_phone'] as String? ?? '',
|
||
longitude: json['longitude'] as String? ?? '',
|
||
latitude: json['latitude'] as String? ?? '',
|
||
isDefault: json['is_default'] == true,
|
||
);
|
||
|
||
String get maskedPhone => contactPhone.length == 11
|
||
? '${contactPhone.substring(0, 3)}****${contactPhone.substring(7)}'
|
||
: contactPhone;
|
||
|
||
/// 保存地址的完整字段;不接收内部账户编号。
|
||
Map<String, Object?> toJson() => {
|
||
'address': address,
|
||
'contact_name': contactName,
|
||
'contact_phone': contactPhone,
|
||
'longitude': longitude,
|
||
'latitude': latitude,
|
||
'is_default': isDefault,
|
||
};
|
||
}
|