| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import 'outing_log_comment.dart';
- class OutingLogModel {
- final String id;
- final String visitNo;
- final String salespersonId;
- final String salespersonName;
- final String deptId;
- final String deptName;
- final String customerId;
- final String customerName;
- final String contactId;
- final String contactName;
- final String contactPhone;
- final double? checkInLongitude;
- final double? checkInLatitude;
- final double gpsAccuracy;
- final String checkInAddress;
- final String visitSummary;
- final String nextPlan;
- final List<String> visitPhotos;
- final String status;
- final List<OutingLogComment> comments;
- final DateTime? lastViewedTime;
- final DateTime createTime;
- final DateTime updateTime;
- const OutingLogModel({
- required this.id,
- required this.visitNo,
- this.salespersonId = '',
- this.salespersonName = '',
- this.deptId = '',
- this.deptName = '',
- this.customerId = '',
- required this.customerName,
- this.contactId = '',
- this.contactName = '',
- this.contactPhone = '',
- this.checkInLongitude,
- this.checkInLatitude,
- this.gpsAccuracy = 15.0,
- this.checkInAddress = '',
- required this.visitSummary,
- this.nextPlan = '',
- this.visitPhotos = const [],
- this.status = 'completed',
- this.comments = const [],
- this.lastViewedTime,
- required this.createTime,
- required this.updateTime,
- });
- bool get hasNewComment {
- if (comments.isEmpty) return false;
- if (lastViewedTime == null) return true;
- return comments.any((c) => c.createTime.isAfter(lastViewedTime!));
- }
- bool get isDraft => status == 'draft';
- bool get isCompleted => status == 'completed';
- String get statusLabel => isDraft ? '草稿' : '已完成';
- String get statusCode => status;
- factory OutingLogModel.fromJson(Map<String, dynamic> json) {
- return OutingLogModel(
- id: json['id'] as String,
- visitNo: json['visitNo'] as String? ?? '',
- salespersonId: json['salespersonId'] as String? ?? '',
- salespersonName: json['salespersonName'] as String? ?? '',
- deptId: json['deptId'] as String? ?? '',
- deptName: json['deptName'] as String? ?? '',
- customerId: json['customerId'] as String? ?? '',
- customerName: json['customerName'] as String? ?? '',
- contactId: json['contactId'] as String? ?? '',
- contactName: json['contactName'] as String? ?? '',
- contactPhone: json['contactPhone'] as String? ?? '',
- checkInLongitude: (json['checkInLongitude'] as num?)?.toDouble(),
- checkInLatitude: (json['checkInLatitude'] as num?)?.toDouble(),
- gpsAccuracy: (json['gpsAccuracy'] as num?)?.toDouble() ?? 15.0,
- checkInAddress: json['checkInAddress'] as String? ?? '',
- visitSummary: json['visitSummary'] as String? ?? '',
- nextPlan: json['nextPlan'] as String? ?? '',
- visitPhotos: (json['visitPhotos'] as List<dynamic>?)
- ?.map((e) => e as String)
- .toList() ??
- [],
- status: json['status'] as String? ?? 'completed',
- comments: (json['comments'] as List<dynamic>?)
- ?.map(
- (e) =>
- OutingLogComment.fromJson(e as Map<String, dynamic>),
- )
- .toList() ??
- [],
- lastViewedTime: json['lastViewedTime'] != null
- ? DateTime.parse(json['lastViewedTime'] as String)
- : null,
- createTime: DateTime.parse(json['createTime'] as String),
- updateTime: DateTime.parse(json['updateTime'] as String),
- );
- }
- Map<String, dynamic> toJson() => {
- 'id': id,
- 'visitNo': visitNo,
- 'salespersonId': salespersonId,
- 'salespersonName': salespersonName,
- 'deptId': deptId,
- 'deptName': deptName,
- 'customerId': customerId,
- 'customerName': customerName,
- 'contactId': contactId,
- 'contactName': contactName,
- 'contactPhone': contactPhone,
- 'checkInLongitude': checkInLongitude,
- 'checkInLatitude': checkInLatitude,
- 'gpsAccuracy': gpsAccuracy,
- 'checkInAddress': checkInAddress,
- 'visitSummary': visitSummary,
- 'nextPlan': nextPlan,
- 'visitPhotos': visitPhotos,
- 'status': status,
- 'comments': comments.map((c) => c.toJson()).toList(),
- 'lastViewedTime': lastViewedTime?.toIso8601String(),
- 'createTime': createTime.toIso8601String(),
- 'updateTime': updateTime.toIso8601String(),
- };
- }
|