You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

143 lines
4.9 KiB

// 数据模型类 - 根据真实API返回格式调整
import 'user_info_data.dart';
class MarriageData {
final String miId;
final String userId;
final String profilePhoto;
final String nickName;
final bool isRealNameCertified;
final String birthYear;
final String birthDate;
final int age;
final int provinceCode;
final String provinceName;
final int cityCode;
final String cityName;
final int districtCode;
final String districtName;
final String describeInfo;
final String createTime;
final int genderCode;
final int visitCount;
final List<PhotoItem> photoList;
final bool isLive; // 是否为直播类型
final bool liveStreaming; // 是否为直播类型
final String? isLiveChannelId;
// 为了兼容UI展示,添加一些计算属性
String get name => nickName;
String get avatar => profilePhoto.trim().replaceAll('`', ''); // 移除照片URL中的反引号
String get city => cityName;
String get description => describeInfo;
List<String> get images => photoList.map((photo) => photo.photoUrl.trim().replaceAll('`', '')).toList();
MarriageData({
required this.miId,
required this.userId,
required this.profilePhoto,
required this.nickName,
required this.isRealNameCertified,
required this.birthYear,
required this.birthDate,
required this.age,
required this.provinceCode,
required this.provinceName,
required this.cityCode,
required this.cityName,
required this.districtCode,
required this.districtName,
required this.describeInfo,
required this.createTime,
required this.photoList,
required this.genderCode,
required this.visitCount,
this.isLive = false,
this.liveStreaming = false,
this.isLiveChannelId = null,
});
factory MarriageData.fromJson(Map<String, dynamic> json) {
return MarriageData(
miId: json['miId'] ?? '',
userId: json['userId'] ?? '',
profilePhoto: json['profilePhoto'] ?? '',
nickName: json['nickName'] ?? '',
isRealNameCertified: json['isRealNameCertified'] ?? false,
birthYear: json['birthYear'] ?? '',
birthDate: json['birthDate'] ?? '',
age: json['age'] ?? 0,
provinceCode: json['provinceCode'] ?? 0,
provinceName: json['provinceName'] ?? '',
cityCode: json['cityCode'] ?? 0,
cityName: json['cityName'] ?? '',
districtCode: json['districtCode'] ?? 0,
districtName: json['districtName'] ?? '',
describeInfo: json['describeInfo'] ?? '',
createTime: json['createTime'] ?? '',
genderCode: json['genderCode'] ?? 0,
visitCount: json['visitCount'] ?? 0,
photoList: (json['photoList'] as List<dynamic>?)?.map((e) => PhotoItem.fromJson(e as Map<String, dynamic>)).toList() ?? [],
isLive: json['isLive'] ?? json['liveStatus'] ?? false, // 支持isLive或liveStatus字段
liveStreaming: json['liveStreaming'] ?? json['liveStreaming'] ?? false, // 支持isLive或liveStatus字段
isLiveChannelId: json['isLiveChannelId'], // 支持isLive或liveStatus字段
);
}
/// 从 UserInfoData 转换为 MarriageData
factory MarriageData.fromUserInfoData(UserInfoData userInfo) {
return MarriageData(
miId: userInfo.miId ?? '',
userId: userInfo.userId ?? '',
profilePhoto: userInfo.profilePhoto ?? '',
nickName: userInfo.nickName ?? '',
isRealNameCertified: userInfo.identityCard != null && userInfo.identityCard!.isNotEmpty,
birthYear: userInfo.birthYear ?? '',
birthDate: userInfo.birthDate ?? '',
age: userInfo.age?.toInt() ?? 0,
provinceCode: userInfo.provinceCode?.toInt() ?? 0,
provinceName: userInfo.provinceName ?? '',
cityCode: userInfo.cityCode?.toInt() ?? 0,
cityName: userInfo.cityName ?? '',
districtCode: userInfo.districtCode?.toInt() ?? 0,
districtName: userInfo.districtName ?? '',
describeInfo: userInfo.describeInfo ?? '',
createTime: userInfo.createTime ?? '',
genderCode: userInfo.genderCode?.toInt() ?? 0,
visitCount: userInfo.visitCount?.toInt() ?? 0,
photoList: (userInfo.photoList ?? []).map((photo) => PhotoItem(
photoUrl: photo.photoUrl ?? '',
auditStatus: photo.auditStatus,
id: photo.id ?? '',
miId: photo.miId ?? 0,
)).toList(),
isLive: false, // 从UserInfoData转换时默认为false
liveStreaming: false, // 从UserInfoData转换时默认为false
isLiveChannelId: null, // 从UserInfoData转换时默认为false
);
}
}
// 照片项数据模型
class PhotoItem {
final String photoUrl;
final String? id;
final num? miId;
final dynamic auditStatus;
PhotoItem({
required this.photoUrl,
this.id,
this.miId,
this.auditStatus,
});
factory PhotoItem.fromJson(Map<String, dynamic> json) {
return PhotoItem(
photoUrl: json['photoUrl'] ?? '',
auditStatus: json['auditStatus'],
id: json['id'],
miId: json['miId'],
);
}
}