refactor: 회사 폼 UI 개선 및 코드 정리
- 담당자 연락처 필드를 드롭다운 + 입력 방식으로 분리 - 사용자 폼과 동일한 전화번호 UI 패턴 적용 - 미사용 위젯 파일 4개 정리 (branch_card, contact_info_* 등) - 파일명 통일성 확보 (branch_edit_screen → branch_form, company_form_simplified → company_form) - 네이밍 일관성 개선으로 유지보수성 향상
This commit is contained in:
223
lib/models/company_item_model.dart
Normal file
223
lib/models/company_item_model.dart
Normal file
@@ -0,0 +1,223 @@
|
||||
import 'package:superport/models/company_model.dart';
|
||||
|
||||
/// Company와 Branch를 통합 관리하기 위한 래퍼 모델
|
||||
/// 리스트에서 본사와 지점을 동일한 구조로 표시하기 위해 사용
|
||||
class CompanyItem {
|
||||
final bool isBranch;
|
||||
final Company? company; // 본사인 경우에만 값 존재
|
||||
final Branch? branch; // 지점인 경우에만 값 존재
|
||||
final String? parentCompanyName; // 지점인 경우 본사명
|
||||
final int? parentCompanyId; // 지점인 경우 본사 ID
|
||||
|
||||
CompanyItem({
|
||||
required this.isBranch,
|
||||
this.company,
|
||||
this.branch,
|
||||
this.parentCompanyName,
|
||||
this.parentCompanyId,
|
||||
}) : assert(
|
||||
(isBranch && branch != null && parentCompanyName != null) ||
|
||||
(!isBranch && company != null),
|
||||
'CompanyItem must have either company (for headquarters) or branch+parentCompanyName (for branch)'
|
||||
);
|
||||
|
||||
/// 본사 생성자
|
||||
CompanyItem.headquarters(Company company)
|
||||
: isBranch = false,
|
||||
company = company,
|
||||
branch = null,
|
||||
parentCompanyName = null,
|
||||
parentCompanyId = null;
|
||||
|
||||
/// 지점 생성자
|
||||
CompanyItem.branch(Branch branch, String parentCompanyName, int parentCompanyId)
|
||||
: isBranch = true,
|
||||
company = null,
|
||||
branch = branch,
|
||||
parentCompanyName = parentCompanyName,
|
||||
parentCompanyId = parentCompanyId;
|
||||
|
||||
/// 표시용 이름 (계층적 구조)
|
||||
String get displayName {
|
||||
if (isBranch) {
|
||||
return '$parentCompanyName > ${branch!.name}';
|
||||
} else {
|
||||
return company!.name;
|
||||
}
|
||||
}
|
||||
|
||||
/// 실제 이름 (본사명 또는 지점명)
|
||||
String get name {
|
||||
return isBranch ? branch!.name : company!.name;
|
||||
}
|
||||
|
||||
/// ID (본사 ID 또는 지점 ID)
|
||||
int? get id {
|
||||
return isBranch ? branch!.id : company!.id;
|
||||
}
|
||||
|
||||
/// 주소
|
||||
String get address {
|
||||
if (isBranch) {
|
||||
return branch!.address.toString();
|
||||
} else {
|
||||
return company!.address.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// 담당자명
|
||||
String? get contactName {
|
||||
if (isBranch) {
|
||||
return branch!.contactName;
|
||||
} else {
|
||||
return company!.contactName;
|
||||
}
|
||||
}
|
||||
|
||||
/// 담당자 직급 (지점은 null)
|
||||
String? get contactPosition {
|
||||
if (isBranch) {
|
||||
return null; // 지점은 직급 정보 없음
|
||||
} else {
|
||||
return company!.contactPosition;
|
||||
}
|
||||
}
|
||||
|
||||
/// 연락처
|
||||
String? get contactPhone {
|
||||
if (isBranch) {
|
||||
return branch!.contactPhone;
|
||||
} else {
|
||||
return company!.contactPhone;
|
||||
}
|
||||
}
|
||||
|
||||
/// 이메일 (지점은 null)
|
||||
String? get contactEmail {
|
||||
if (isBranch) {
|
||||
return null; // 지점은 이메일 정보 없음
|
||||
} else {
|
||||
return company!.contactEmail;
|
||||
}
|
||||
}
|
||||
|
||||
/// 회사 유형 (본사만, 지점은 빈 리스트)
|
||||
List<CompanyType> get companyTypes {
|
||||
if (isBranch) {
|
||||
return []; // 지점은 회사 유형 없음
|
||||
} else {
|
||||
return company!.companyTypes;
|
||||
}
|
||||
}
|
||||
|
||||
/// 비고
|
||||
String? get remark {
|
||||
if (isBranch) {
|
||||
return branch!.remark;
|
||||
} else {
|
||||
return company!.remark;
|
||||
}
|
||||
}
|
||||
|
||||
/// 생성일
|
||||
DateTime? get createdAt {
|
||||
if (isBranch) {
|
||||
return null; // 지점은 생성일 정보 없음
|
||||
} else {
|
||||
return company!.createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
/// 수정일
|
||||
DateTime? get updatedAt {
|
||||
if (isBranch) {
|
||||
return null; // 지점은 수정일 정보 없음
|
||||
} else {
|
||||
return company!.updatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
/// 활성 상태
|
||||
bool get isActive {
|
||||
if (isBranch) {
|
||||
return true; // 지점은 기본적으로 활성
|
||||
} else {
|
||||
return company!.isActive;
|
||||
}
|
||||
}
|
||||
|
||||
/// 파트너사 플래그
|
||||
bool get isPartner {
|
||||
if (isBranch) {
|
||||
return false; // 지점은 파트너 플래그 없음
|
||||
} else {
|
||||
return company!.isPartner;
|
||||
}
|
||||
}
|
||||
|
||||
/// 고객사 플래그
|
||||
bool get isCustomer {
|
||||
if (isBranch) {
|
||||
return false; // 지점은 고객 플래그 없음
|
||||
} else {
|
||||
return company!.isCustomer;
|
||||
}
|
||||
}
|
||||
|
||||
/// JSON 직렬화
|
||||
Map<String, dynamic> toJson() {
|
||||
if (isBranch) {
|
||||
return {
|
||||
'isBranch': true,
|
||||
'branch': branch!.toJson(),
|
||||
'parentCompanyName': parentCompanyName,
|
||||
'parentCompanyId': parentCompanyId,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'isBranch': false,
|
||||
'company': company!.toJson(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// JSON 역직렬화
|
||||
factory CompanyItem.fromJson(Map<String, dynamic> json) {
|
||||
final isBranch = json['isBranch'] as bool;
|
||||
|
||||
if (isBranch) {
|
||||
return CompanyItem.branch(
|
||||
Branch.fromJson(json['branch']),
|
||||
json['parentCompanyName'] as String,
|
||||
json['parentCompanyId'] as int,
|
||||
);
|
||||
} else {
|
||||
return CompanyItem.headquarters(
|
||||
Company.fromJson(json['company']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is CompanyItem &&
|
||||
other.isBranch == isBranch &&
|
||||
other.id == id;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(isBranch, id);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
if (isBranch) {
|
||||
return 'CompanyItem.branch(${branch!.name} of $parentCompanyName)';
|
||||
} else {
|
||||
return 'CompanyItem.headquarters(${company!.name})';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user