refactor: 회사 폼 UI 개선 및 코드 정리
- 담당자 연락처 필드를 드롭다운 + 입력 방식으로 분리 - 사용자 폼과 동일한 전화번호 UI 패턴 적용 - 미사용 위젯 파일 4개 정리 (branch_card, contact_info_* 등) - 파일명 통일성 확보 (branch_edit_screen → branch_form, company_form_simplified → company_form) - 네이밍 일관성 개선으로 유지보수성 향상
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
||||
import 'dart:async';
|
||||
import 'package:superport/core/constants/app_constants.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/models/company_item_model.dart';
|
||||
import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
import 'package:superport/screens/common/components/shadcn_components.dart';
|
||||
import 'package:superport/screens/common/widgets/pagination.dart';
|
||||
@@ -104,18 +105,38 @@ class _CompanyListState extends State<CompanyList> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Branch 객체를 Company 객체로 변환
|
||||
Company _convertBranchToCompany(Branch branch) {
|
||||
return Company(
|
||||
id: branch.id,
|
||||
name: branch.name,
|
||||
address: branch.address,
|
||||
contactName: branch.contactName,
|
||||
contactPosition: branch.contactPosition,
|
||||
contactPhone: branch.contactPhone,
|
||||
contactEmail: branch.contactEmail,
|
||||
companyTypes: [],
|
||||
remark: branch.remark,
|
||||
/// 지점 삭제 처리
|
||||
void _deleteBranch(int companyId, int branchId) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('지점 삭제 확인'),
|
||||
content: const Text('이 지점 정보를 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
try {
|
||||
await _controller.deleteBranch(companyId, branchId);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(e.toString()),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -177,23 +198,161 @@ class _CompanyListState extends State<CompanyList> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 회사 이름 표시 (지점인 경우 본사명 포함)
|
||||
Widget _buildCompanyNameText(
|
||||
Company company,
|
||||
bool isBranch, {
|
||||
String? mainCompanyName,
|
||||
}) {
|
||||
if (isBranch && mainCompanyName != null) {
|
||||
/// CompanyItem의 계층적 이름 표시
|
||||
Widget _buildDisplayNameText(CompanyItem item) {
|
||||
if (item.isBranch) {
|
||||
return Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(text: '$mainCompanyName > ', style: ShadcnTheme.bodyMuted),
|
||||
TextSpan(text: company.name, style: ShadcnTheme.bodyMedium),
|
||||
TextSpan(text: '${item.parentCompanyName} > ', style: ShadcnTheme.bodyMuted),
|
||||
TextSpan(text: item.name, style: ShadcnTheme.bodyMedium),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Text(company.name, style: ShadcnTheme.bodyMedium);
|
||||
return Text(item.name, style: ShadcnTheme.bodyMedium);
|
||||
}
|
||||
}
|
||||
|
||||
/// 활성 상태 배지 생성
|
||||
Widget _buildStatusBadge(bool isActive) {
|
||||
return ShadcnBadge(
|
||||
text: isActive ? '활성' : '비활성',
|
||||
variant: isActive
|
||||
? ShadcnBadgeVariant.success
|
||||
: ShadcnBadgeVariant.secondary,
|
||||
size: ShadcnBadgeSize.small,
|
||||
);
|
||||
}
|
||||
|
||||
/// 날짜 포맷팅
|
||||
String _formatDate(DateTime? date) {
|
||||
if (date == null) return '-';
|
||||
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
/// 담당자 정보 통합 표시 (이름 + 직책)
|
||||
Widget _buildContactInfo(CompanyItem item) {
|
||||
final name = item.contactName ?? '-';
|
||||
final position = item.contactPosition;
|
||||
|
||||
if (position != null && position.isNotEmpty) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
style: ShadcnTheme.bodySmall.copyWith(fontWeight: FontWeight.w500),
|
||||
),
|
||||
Text(
|
||||
position,
|
||||
style: ShadcnTheme.bodySmall.copyWith(
|
||||
color: ShadcnTheme.muted,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Text(name, style: ShadcnTheme.bodySmall);
|
||||
}
|
||||
}
|
||||
|
||||
/// 연락처 정보 통합 표시 (전화 + 이메일)
|
||||
Widget _buildContactDetails(CompanyItem item) {
|
||||
final phone = item.contactPhone ?? '-';
|
||||
final email = item.contactEmail;
|
||||
|
||||
if (email != null && email.isNotEmpty) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
phone,
|
||||
style: ShadcnTheme.bodySmall,
|
||||
),
|
||||
Text(
|
||||
email,
|
||||
style: ShadcnTheme.bodySmall.copyWith(
|
||||
color: ShadcnTheme.muted,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Text(phone, style: ShadcnTheme.bodySmall);
|
||||
}
|
||||
}
|
||||
|
||||
/// 파트너/고객 플래그 표시
|
||||
Widget _buildPartnerCustomerFlags(CompanyItem item) {
|
||||
if (item.isBranch) {
|
||||
return Text('-', style: ShadcnTheme.bodySmall);
|
||||
}
|
||||
|
||||
final flags = <Widget>[];
|
||||
|
||||
if (item.isPartner) {
|
||||
flags.add(ShadcnBadge(
|
||||
text: '파트너',
|
||||
variant: ShadcnBadgeVariant.companyPartner,
|
||||
size: ShadcnBadgeSize.small,
|
||||
));
|
||||
}
|
||||
|
||||
if (item.isCustomer) {
|
||||
flags.add(ShadcnBadge(
|
||||
text: '고객',
|
||||
variant: ShadcnBadgeVariant.companyCustomer,
|
||||
size: ShadcnBadgeSize.small,
|
||||
));
|
||||
}
|
||||
|
||||
if (flags.isEmpty) {
|
||||
return Text('-', style: ShadcnTheme.bodySmall);
|
||||
}
|
||||
|
||||
return Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 2,
|
||||
children: flags,
|
||||
);
|
||||
}
|
||||
|
||||
/// 등록일/수정일 표시
|
||||
Widget _buildDateInfo(CompanyItem item) {
|
||||
final createdAt = item.createdAt;
|
||||
final updatedAt = item.updatedAt;
|
||||
|
||||
if (createdAt == null) {
|
||||
return Text('-', style: ShadcnTheme.bodySmall);
|
||||
}
|
||||
|
||||
final created = _formatDate(createdAt);
|
||||
|
||||
if (updatedAt != null && updatedAt != createdAt) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'등록: $created',
|
||||
style: ShadcnTheme.bodySmall,
|
||||
),
|
||||
Text(
|
||||
'수정: ${_formatDate(updatedAt)}',
|
||||
style: ShadcnTheme.bodySmall.copyWith(
|
||||
color: ShadcnTheme.muted,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Text(created, style: ShadcnTheme.bodySmall);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,38 +362,18 @@ class _CompanyListState extends State<CompanyList> {
|
||||
value: _controller,
|
||||
child: Consumer<CompanyListController>(
|
||||
builder: (context, controller, child) {
|
||||
// 본사와 지점 구분하기 위한 데이터 준비
|
||||
final List<Map<String, dynamic>> displayCompanies = [];
|
||||
for (final company in controller.filteredCompanies) {
|
||||
displayCompanies.add({
|
||||
'company': company,
|
||||
'isBranch': false,
|
||||
'mainCompanyName': null,
|
||||
});
|
||||
if (company.branches != null) {
|
||||
for (final branch in company.branches!) {
|
||||
displayCompanies.add({
|
||||
'branch': branch,
|
||||
'companyId': company.id,
|
||||
'isBranch': true,
|
||||
'mainCompanyName': company.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Controller가 이미 페이지크된 데이터를 제공
|
||||
final List<Map<String, dynamic>> pagedCompanies = displayCompanies;
|
||||
final int totalCount = controller.total; // 실제 전체 개수 사용
|
||||
// CompanyItem 데이터 직접 사용 (복잡한 변환 로직 제거)
|
||||
final companyItems = controller.companyItems;
|
||||
final int totalCount = controller.total;
|
||||
|
||||
print('🔍 [VIEW DEBUG] 페이지네이션 상태');
|
||||
print(' • Controller items: ${controller.companies.length}개');
|
||||
print('🔍 [VIEW DEBUG] CompanyItem 페이지네이션 상태');
|
||||
print(' • CompanyItem items: ${controller.companyItems.length}개');
|
||||
print(' • 전체 개수: ${controller.total}개');
|
||||
print(' • 현재 페이지: ${controller.currentPage}');
|
||||
print(' • 페이지 크기: ${controller.pageSize}');
|
||||
|
||||
// 로딩 상태
|
||||
if (controller.isLoading && controller.companies.isEmpty) {
|
||||
if (controller.isLoading && controller.companyItems.isEmpty) {
|
||||
return const StandardLoadingState(message: '회사 데이터를 불러오는 중...');
|
||||
}
|
||||
|
||||
@@ -306,7 +445,7 @@ class _CompanyListState extends State<CompanyList> {
|
||||
|
||||
// 데이터 테이블
|
||||
dataTable:
|
||||
displayCompanies.isEmpty
|
||||
companyItems.isEmpty
|
||||
? StandardEmptyState(
|
||||
title:
|
||||
controller.searchQuery.isNotEmpty
|
||||
@@ -326,23 +465,19 @@ class _CompanyListState extends State<CompanyList> {
|
||||
std_table.DataColumn(label: '번호', flex: 1),
|
||||
std_table.DataColumn(label: '회사명', flex: 3),
|
||||
std_table.DataColumn(label: '구분', flex: 1),
|
||||
std_table.DataColumn(label: '유형', flex: 2),
|
||||
std_table.DataColumn(label: '연락처', flex: 2),
|
||||
std_table.DataColumn(label: '주소', flex: 3),
|
||||
std_table.DataColumn(label: '담당자', flex: 2),
|
||||
std_table.DataColumn(label: '연락처', flex: 3),
|
||||
std_table.DataColumn(label: '파트너/고객', flex: 2),
|
||||
std_table.DataColumn(label: '상태', flex: 1),
|
||||
std_table.DataColumn(label: '등록/수정일', flex: 2),
|
||||
std_table.DataColumn(label: '비고', flex: 2),
|
||||
std_table.DataColumn(label: '관리', flex: 2),
|
||||
],
|
||||
rows: [
|
||||
...pagedCompanies.asMap().entries.map((entry) {
|
||||
...companyItems.asMap().entries.map((entry) {
|
||||
final int index = ((controller.currentPage - 1) * controller.pageSize) + entry.key;
|
||||
final companyData = entry.value;
|
||||
final bool isBranch = companyData['isBranch'] as bool;
|
||||
final Company company =
|
||||
isBranch
|
||||
? _convertBranchToCompany(
|
||||
companyData['branch'] as Branch,
|
||||
)
|
||||
: companyData['company'] as Company;
|
||||
final String? mainCompanyName =
|
||||
companyData['mainCompanyName'] as String?;
|
||||
final CompanyItem item = entry.value;
|
||||
|
||||
return std_table.StandardDataRow(
|
||||
index: index,
|
||||
@@ -350,8 +485,13 @@ class _CompanyListState extends State<CompanyList> {
|
||||
std_table.DataColumn(label: '번호', flex: 1),
|
||||
std_table.DataColumn(label: '회사명', flex: 3),
|
||||
std_table.DataColumn(label: '구분', flex: 1),
|
||||
std_table.DataColumn(label: '유형', flex: 2),
|
||||
std_table.DataColumn(label: '연락처', flex: 2),
|
||||
std_table.DataColumn(label: '주소', flex: 3),
|
||||
std_table.DataColumn(label: '담당자', flex: 2),
|
||||
std_table.DataColumn(label: '연락처', flex: 3),
|
||||
std_table.DataColumn(label: '파트너/고객', flex: 2),
|
||||
std_table.DataColumn(label: '상태', flex: 1),
|
||||
std_table.DataColumn(label: '등록/수정일', flex: 2),
|
||||
std_table.DataColumn(label: '비고', flex: 2),
|
||||
std_table.DataColumn(label: '관리', flex: 2),
|
||||
],
|
||||
cells: [
|
||||
@@ -360,82 +500,89 @@ class _CompanyListState extends State<CompanyList> {
|
||||
'${index + 1}',
|
||||
style: ShadcnTheme.bodySmall,
|
||||
),
|
||||
// 회사명
|
||||
_buildCompanyNameText(
|
||||
company,
|
||||
isBranch,
|
||||
mainCompanyName: mainCompanyName,
|
||||
),
|
||||
// 구분
|
||||
// 회사명 (계층적 표시)
|
||||
_buildDisplayNameText(item),
|
||||
// 구분 (본사/지점 배지)
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: _buildCompanyTypeLabel(isBranch),
|
||||
child: _buildCompanyTypeLabel(item.isBranch),
|
||||
),
|
||||
// 유형
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: _buildCompanyTypeChips(company.companyTypes),
|
||||
),
|
||||
// 연락처
|
||||
// 주소
|
||||
Text(
|
||||
company.contactPhone ?? '-',
|
||||
item.address.isNotEmpty ? item.address : '-',
|
||||
style: ShadcnTheme.bodySmall,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
// 관리
|
||||
// 담당자 (이름 + 직책)
|
||||
_buildContactInfo(item),
|
||||
// 연락처 (전화 + 이메일)
|
||||
_buildContactDetails(item),
|
||||
// 파트너/고객 플래그
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: _buildPartnerCustomerFlags(item),
|
||||
),
|
||||
// 상태
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: _buildStatusBadge(item.isActive),
|
||||
),
|
||||
// 등록/수정일
|
||||
_buildDateInfo(item),
|
||||
// 비고
|
||||
Text(
|
||||
item.remark ?? '-',
|
||||
style: ShadcnTheme.bodySmall,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
),
|
||||
// 관리 (액션 버튼들)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (!isBranch &&
|
||||
company.branches != null &&
|
||||
company.branches!.isNotEmpty) ...[
|
||||
ShadcnButton(
|
||||
text: '지점',
|
||||
onPressed:
|
||||
() => _showBranchDialog(company),
|
||||
variant: ShadcnButtonVariant.ghost,
|
||||
size: ShadcnButtonSize.small,
|
||||
),
|
||||
const SizedBox(width: ShadcnTheme.spacing1),
|
||||
],
|
||||
std_table.StandardActionButtons(
|
||||
onEdit:
|
||||
company.id != null
|
||||
? () {
|
||||
if (isBranch) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/company/edit',
|
||||
arguments: {
|
||||
'companyId':
|
||||
companyData['companyId'],
|
||||
'isBranch': true,
|
||||
'mainCompanyName':
|
||||
mainCompanyName,
|
||||
'branchId': company.id,
|
||||
},
|
||||
).then((result) {
|
||||
if (result == true)
|
||||
controller.refresh();
|
||||
});
|
||||
} else {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/company/edit',
|
||||
arguments: {
|
||||
'companyId': company.id,
|
||||
'isBranch': false,
|
||||
},
|
||||
).then((result) {
|
||||
if (result == true)
|
||||
controller.refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
: null,
|
||||
onDelete:
|
||||
(!isBranch && company.id != null)
|
||||
? () => _deleteCompany(company.id!)
|
||||
: null,
|
||||
onEdit: item.id != null
|
||||
? () {
|
||||
if (item.isBranch) {
|
||||
// 지점 수정 - 별도 화면으로 이동 (Phase 3에서 구현)
|
||||
// TODO: Phase 3에서 별도 지점 수정 화면 구현
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/company/branch/edit',
|
||||
arguments: {
|
||||
'companyId': item.parentCompanyId,
|
||||
'branchId': item.id,
|
||||
'parentCompanyName': item.parentCompanyName,
|
||||
},
|
||||
).then((result) {
|
||||
if (result == true) controller.refresh();
|
||||
});
|
||||
} else {
|
||||
// 본사 수정
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/company/edit',
|
||||
arguments: {
|
||||
'companyId': item.id,
|
||||
'isBranch': false,
|
||||
},
|
||||
).then((result) {
|
||||
if (result == true) controller.refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
: null,
|
||||
onDelete: item.id != null
|
||||
? () {
|
||||
if (item.isBranch) {
|
||||
// 지점 삭제
|
||||
_deleteBranch(item.parentCompanyId!, item.id!);
|
||||
} else {
|
||||
// 본사 삭제
|
||||
_deleteCompany(item.id!);
|
||||
}
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user