사용하지 않는 파일 정리 전 백업 (Phase 10 완료 후 상태)
This commit is contained in:
@@ -14,10 +14,10 @@ class BranchFormScreen extends StatefulWidget {
|
||||
final String? parentCompanyName; // 수정 모드: 본사명 (표시용)
|
||||
|
||||
const BranchFormScreen({
|
||||
Key? key,
|
||||
super.key,
|
||||
this.branchId,
|
||||
this.parentCompanyName,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
State<BranchFormScreen> createState() => _BranchFormScreenState();
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
import 'package:superport/screens/common/templates/form_layout_template.dart';
|
||||
import 'package:superport/screens/company/controllers/company_form_controller.dart';
|
||||
import 'package:superport/utils/validators.dart';
|
||||
import 'package:superport/utils/phone_utils.dart';
|
||||
import 'package:superport/utils/formatters/korean_phone_formatter.dart';
|
||||
|
||||
/// 회사 등록/수정 화면
|
||||
/// User/Warehouse Location 화면과 동일한 FormFieldWrapper 패턴 사용
|
||||
class CompanyFormScreen extends StatefulWidget {
|
||||
final Map? args;
|
||||
const CompanyFormScreen({Key? key, this.args}) : super(key: key);
|
||||
const CompanyFormScreen({super.key, this.args});
|
||||
|
||||
@override
|
||||
State<CompanyFormScreen> createState() => _CompanyFormScreenState();
|
||||
@@ -25,10 +23,6 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
final TextEditingController _phoneNumberController = TextEditingController();
|
||||
int? companyId;
|
||||
bool isBranch = false;
|
||||
|
||||
// 전화번호 관련 변수
|
||||
String _selectedPhonePrefix = '010';
|
||||
List<String> _phonePrefixes = PhoneUtils.getCommonPhonePrefixes();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -57,8 +51,7 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 전화번호 분리 초기화
|
||||
final fullPhone = _controller.contactPhoneController.text;
|
||||
if (fullPhone.isNotEmpty) {
|
||||
_selectedPhonePrefix = PhoneUtils.extractPhonePrefix(fullPhone, _phonePrefixes);
|
||||
_phoneNumberController.text = PhoneUtils.extractPhoneNumberWithoutPrefix(fullPhone, _phonePrefixes);
|
||||
_phoneNumberController.text = fullPhone; // 통합 필드로 그대로 사용
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
@@ -87,15 +80,26 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
Address.fromFullAddress(_addressController.text)
|
||||
);
|
||||
|
||||
// 전화번호 합치기
|
||||
final fullPhoneNumber = PhoneUtils.getFullPhoneNumber(_selectedPhonePrefix, _phoneNumberController.text);
|
||||
_controller.contactPhoneController.text = fullPhoneNumber;
|
||||
// 전화번호는 이미 포맷팅되어 있으므로 그대로 사용
|
||||
_controller.contactPhoneController.text = _phoneNumberController.text;
|
||||
|
||||
// 로딩 표시
|
||||
showDialog(
|
||||
showShadDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const Center(child: CircularProgressIndicator()),
|
||||
builder: (context) => ShadDialog(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(width: 20),
|
||||
Text('저장 중...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -105,18 +109,18 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
Navigator.pop(context); // 로딩 다이얼로그 닫기
|
||||
|
||||
if (success) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(companyId != null ? '회사 정보가 수정되었습니다.' : '회사가 등록되었습니다.'),
|
||||
backgroundColor: Colors.green,
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast(
|
||||
title: const Text('성공'),
|
||||
description: Text(companyId != null ? '회사 정보가 수정되었습니다.' : '회사가 등록되었습니다.'),
|
||||
),
|
||||
);
|
||||
Navigator.pop(context, true);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('회사 저장에 실패했습니다.'),
|
||||
backgroundColor: Colors.red,
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast.destructive(
|
||||
title: const Text('오류'),
|
||||
description: const Text('회사 저장에 실패했습니다.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -124,10 +128,10 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Navigator.pop(context); // 로딩 다이얼로그 닫기
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('오류가 발생했습니다: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast.destructive(
|
||||
title: const Text('오류'),
|
||||
description: Text('오류가 발생했습니다: $e'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -156,43 +160,86 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CheckboxListTile(
|
||||
title: const Text('고객사'),
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.customer),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.customer, checked ?? false);
|
||||
});
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.customer),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.customer, checked);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('고객사'),
|
||||
],
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('파트너사'),
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.partner),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.partner, checked ?? false);
|
||||
});
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: _controller.selectedCompanyTypes.contains(CompanyType.partner),
|
||||
onChanged: (checked) {
|
||||
setState(() {
|
||||
_controller.toggleCompanyType(CompanyType.partner, checked);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('파트너사'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 부모 회사 선택 (선택사항)
|
||||
FormFieldWrapper(
|
||||
label: "부모 회사",
|
||||
child: ShadSelect<int?>(
|
||||
placeholder: const Text('부모 회사를 선택하세요 (선택사항)'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('없음 (본사)');
|
||||
}
|
||||
final company = _controller.availableParentCompanies.firstWhere(
|
||||
(c) => c.id == value,
|
||||
orElse: () => Company(id: 0, name: '알 수 없음'),
|
||||
);
|
||||
return Text(company.name);
|
||||
},
|
||||
options: [
|
||||
const ShadOption(
|
||||
value: null,
|
||||
child: Text('없음 (본사)'),
|
||||
),
|
||||
..._controller.availableParentCompanies.map((company) {
|
||||
return ShadOption(
|
||||
value: company.id,
|
||||
child: Text(company.name),
|
||||
);
|
||||
}),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_controller.selectedParentCompanyId = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 회사명 (필수)
|
||||
FormFieldWrapper(
|
||||
label: "회사명 *",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.nameController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '회사명을 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('회사명을 입력하세요'),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
if (value.trim().isEmpty) {
|
||||
return '회사명을 입력하세요';
|
||||
}
|
||||
if (value.trim().length < 2) {
|
||||
@@ -200,7 +247,6 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -209,14 +255,10 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 주소 (선택)
|
||||
FormFieldWrapper(
|
||||
label: "주소",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _addressController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '회사 주소를 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('회사 주소를 입력하세요'),
|
||||
maxLines: 2,
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -225,19 +267,15 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자명 (필수)
|
||||
FormFieldWrapper(
|
||||
label: "담당자명 *",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.contactNameController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '담당자명을 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('담당자명을 입력하세요'),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
if (value.trim().isEmpty) {
|
||||
return '담당자명을 입력하세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -246,13 +284,9 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자 직급 (선택)
|
||||
FormFieldWrapper(
|
||||
label: "담당자 직급",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.contactPositionController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '담당자 직급을 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
textInputAction: TextInputAction.next,
|
||||
placeholder: const Text('담당자 직급을 입력하세요'),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -261,72 +295,14 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자 연락처 (필수) - 사용자 폼과 동일한 패턴
|
||||
FormFieldWrapper(
|
||||
label: "담당자 연락처 *",
|
||||
child: Row(
|
||||
children: [
|
||||
// 접두사 드롭다운 (010, 02, 031 등)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: DropdownButton<String>(
|
||||
value: _selectedPhonePrefix,
|
||||
items: _phonePrefixes.map((prefix) {
|
||||
return DropdownMenuItem(
|
||||
value: prefix,
|
||||
child: Text(prefix),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
_selectedPhonePrefix = value;
|
||||
});
|
||||
}
|
||||
},
|
||||
underline: Container(), // 밑줄 제거
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('-', style: TextStyle(fontSize: 16)),
|
||||
const SizedBox(width: 8),
|
||||
// 전화번호 입력 (7-8자리)
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _phoneNumberController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '1234-5678',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
TextInputFormatter.withFunction((oldValue, newValue) {
|
||||
final formatted = PhoneUtils.formatPhoneNumberByPrefix(
|
||||
_selectedPhonePrefix,
|
||||
newValue.text,
|
||||
);
|
||||
return TextEditingValue(
|
||||
text: formatted,
|
||||
selection: TextSelection.collapsed(offset: formatted.length),
|
||||
);
|
||||
}),
|
||||
],
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return '전화번호를 입력하세요';
|
||||
}
|
||||
final digitsOnly = value.replaceAll(RegExp(r'[^\d]'), '');
|
||||
if (digitsOnly.length < 7) {
|
||||
return '전화번호는 7-8자리 숫자를 입력해주세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
child: ShadInputFormField(
|
||||
controller: _phoneNumberController,
|
||||
placeholder: const Text('010-1234-5678'),
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
KoreanPhoneFormatter(), // 한국식 전화번호 자동 포맷팅
|
||||
],
|
||||
validator: PhoneValidator.validate, // 전화번호 유효성 검증
|
||||
),
|
||||
),
|
||||
|
||||
@@ -335,20 +311,16 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 담당자 이메일 (필수)
|
||||
FormFieldWrapper(
|
||||
label: "담당자 이메일 *",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.contactEmailController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'example@company.com',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('example@company.com'),
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
if (value.trim().isEmpty) {
|
||||
return '담당자 이메일을 입력하세요';
|
||||
}
|
||||
return validateEmail(value);
|
||||
},
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -357,30 +329,20 @@ class _CompanyFormScreenState extends State<CompanyFormScreen> {
|
||||
// 비고 (선택)
|
||||
FormFieldWrapper(
|
||||
label: "비고",
|
||||
child: TextFormField(
|
||||
child: ShadInputFormField(
|
||||
controller: _controller.remarkController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '추가 정보나 메모를 입력하세요',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
placeholder: const Text('추가 정보나 메모를 입력하세요'),
|
||||
maxLines: 3,
|
||||
textInputAction: TextInputAction.done,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 저장 버튼
|
||||
ElevatedButton(
|
||||
ShadButton(
|
||||
onPressed: _saveCompany,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: ShadcnTheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
size: ShadButtonSize.lg,
|
||||
width: double.infinity,
|
||||
child: Text(
|
||||
isEditMode ? '수정 완료' : '등록 완료',
|
||||
style: const TextStyle(
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'dart:async';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
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';
|
||||
import 'package:superport/screens/common/widgets/unified_search_bar.dart';
|
||||
import 'package:superport/screens/common/widgets/standard_data_table.dart'
|
||||
as std_table;
|
||||
import 'package:superport/screens/common/widgets/standard_action_bar.dart';
|
||||
import 'package:superport/screens/common/widgets/standard_states.dart';
|
||||
import 'package:superport/screens/common/layouts/base_list_screen.dart';
|
||||
// import 'package:superport/services/mock_data_service.dart'; // Mock 서비스 제거
|
||||
import 'package:superport/screens/company/widgets/company_branch_dialog.dart';
|
||||
import 'package:superport/screens/company/controllers/company_list_controller.dart';
|
||||
import 'package:superport/screens/company/components/company_tree_view.dart';
|
||||
|
||||
/// shadcn/ui 스타일로 재설계된 회사 관리 화면 (통일된 UI 컴포넌트 사용)
|
||||
class CompanyList extends StatefulWidget {
|
||||
@@ -73,127 +70,97 @@ class _CompanyListState extends State<CompanyList> {
|
||||
void _deleteCompany(int id) {
|
||||
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.deleteCompany(id);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(e.toString()),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
builder: (context) => ShadDialog(
|
||||
title: const Text('삭제 확인'),
|
||||
description: const Text('이 회사 정보를 삭제하시겠습니까?'),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.outline(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
try {
|
||||
await _controller.deleteCompany(id);
|
||||
if (mounted) {
|
||||
ShadToaster.of(context).show(
|
||||
const ShadToast(
|
||||
title: Text('성공'),
|
||||
description: Text('회사가 삭제되었습니다.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast.destructive(
|
||||
title: const Text('오류'),
|
||||
description: Text(e.toString()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 지점 다이얼로그 표시
|
||||
void _showBranchDialog(Company mainCompany) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => CompanyBranchDialog(mainCompany: mainCompany),
|
||||
);
|
||||
}
|
||||
|
||||
/// 지점 삭제 처리
|
||||
void _deleteBranch(int companyId, int branchId) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
builder: (context) => ShadDialog(
|
||||
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,
|
||||
),
|
||||
);
|
||||
description: const Text('이 지점 정보를 삭제하시겠습니까?'),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.outline(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
try {
|
||||
await _controller.deleteBranch(companyId, branchId);
|
||||
if (mounted) {
|
||||
ShadToaster.of(context).show(
|
||||
const ShadToast(
|
||||
title: Text('성공'),
|
||||
description: Text('지점이 삭제되었습니다.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ShadToaster.of(context).show(
|
||||
ShadToast.destructive(
|
||||
title: const Text('오류'),
|
||||
description: Text(e.toString()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 회사 유형 배지 생성
|
||||
Widget _buildCompanyTypeChips(List<CompanyType> types) {
|
||||
// 유형이 없으면 기본값 표시
|
||||
if (types.isEmpty) {
|
||||
return Text(
|
||||
'-',
|
||||
style: ShadcnTheme.bodySmall.copyWith(color: ShadcnTheme.muted),
|
||||
);
|
||||
}
|
||||
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 2,
|
||||
children: types.map((type) {
|
||||
ShadcnBadgeVariant variant;
|
||||
String displayText;
|
||||
|
||||
switch (type) {
|
||||
case CompanyType.customer:
|
||||
variant = ShadcnBadgeVariant.companyCustomer; // Orange
|
||||
displayText = '고객사';
|
||||
break;
|
||||
case CompanyType.partner:
|
||||
variant = ShadcnBadgeVariant.companyPartner; // Green
|
||||
displayText = '파트너사';
|
||||
break;
|
||||
default:
|
||||
variant = ShadcnBadgeVariant.secondary;
|
||||
displayText = companyTypeToString(type);
|
||||
}
|
||||
|
||||
return ShadcnBadge(
|
||||
text: displayText,
|
||||
variant: variant,
|
||||
size: ShadcnBadgeSize.small,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 본사/지점 구분 배지 생성
|
||||
Widget _buildCompanyTypeLabel(bool isBranch) {
|
||||
@@ -363,6 +330,174 @@ class _CompanyListState extends State<CompanyList> {
|
||||
return Text(created, style: ShadcnTheme.bodySmall);
|
||||
}
|
||||
}
|
||||
|
||||
/// ShadTable을 사용한 회사 데이터 테이블 빌드
|
||||
Widget _buildCompanyShadTable(List<CompanyItem> items, CompanyListController controller) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: ShadTable(
|
||||
columnCount: 11,
|
||||
rowCount: items.length + 1, // +1 for header
|
||||
header: (context, column) {
|
||||
final headers = [
|
||||
'번호', '회사명', '구분', '주소', '담당자',
|
||||
'연락처', '파트너/고객', '상태', '등록/수정일', '비고', '관리'
|
||||
];
|
||||
return ShadTableCell(
|
||||
child: Text(
|
||||
headers[column],
|
||||
style: theme.textTheme.muted.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
);
|
||||
},
|
||||
builder: (context, vicinity) {
|
||||
final column = vicinity.column;
|
||||
final row = vicinity.row - 1; // -1 because header is row 0
|
||||
|
||||
if (row < 0 || row >= items.length) {
|
||||
return const ShadTableCell(child: SizedBox.shrink());
|
||||
}
|
||||
|
||||
final item = items[row];
|
||||
final index = ((controller.currentPage - 1) * controller.pageSize) + row;
|
||||
|
||||
switch (column) {
|
||||
case 0: // 번호
|
||||
return ShadTableCell(child: Text('${index + 1}', style: theme.textTheme.small));
|
||||
case 1: // 회사명
|
||||
return ShadTableCell(child: _buildDisplayNameText(item));
|
||||
case 2: // 구분
|
||||
return ShadTableCell(child: _buildCompanyTypeLabel(item.isBranch));
|
||||
case 3: // 주소
|
||||
return ShadTableCell(
|
||||
child: Text(
|
||||
item.address.isNotEmpty ? item.address : '-',
|
||||
style: theme.textTheme.small,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
case 4: // 담당자
|
||||
return ShadTableCell(child: _buildContactInfo(item));
|
||||
case 5: // 연락처
|
||||
return ShadTableCell(child: _buildContactDetails(item));
|
||||
case 6: // 파트너/고객
|
||||
return ShadTableCell(child: _buildPartnerCustomerFlags(item));
|
||||
case 7: // 상태
|
||||
return ShadTableCell(child: _buildStatusBadge(item.isActive));
|
||||
case 8: // 등록/수정일
|
||||
return ShadTableCell(child: _buildDateInfo(item));
|
||||
case 9: // 비고
|
||||
return ShadTableCell(
|
||||
child: Text(
|
||||
item.remark ?? '-',
|
||||
style: theme.textTheme.small,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
),
|
||||
);
|
||||
case 10: // 관리
|
||||
return ShadTableCell(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (item.id != null) ...[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit, size: 18),
|
||||
onPressed: () {
|
||||
if (item.isBranch) {
|
||||
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();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete, size: 18),
|
||||
onPressed: () {
|
||||
if (item.isBranch) {
|
||||
_deleteBranch(item.parentCompanyId!, item.id!);
|
||||
} else {
|
||||
_deleteCompany(item.id!);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
default:
|
||||
return const ShadTableCell(child: SizedBox.shrink());
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Tree View 빌드
|
||||
Widget _buildTreeView(BuildContext context, CompanyListController controller) {
|
||||
if (controller.companyHierarchy == null) {
|
||||
return const StandardLoadingState(message: '계층 구조를 불러오는 중...');
|
||||
}
|
||||
|
||||
return CompanyTreeView(
|
||||
hierarchy: controller.companyHierarchy!,
|
||||
expandedNodes: controller.expandedNodes,
|
||||
onToggleExpand: controller.toggleNodeExpansion,
|
||||
onNodeTap: (nodeId) {
|
||||
// 회사 상세 화면으로 이동
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/company/edit',
|
||||
arguments: int.parse(nodeId),
|
||||
);
|
||||
},
|
||||
onEdit: (nodeId) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/company/edit',
|
||||
arguments: int.parse(nodeId),
|
||||
);
|
||||
},
|
||||
onDelete: (nodeId) async {
|
||||
final companyId = int.parse(nodeId);
|
||||
// 삭제 가능 여부 먼저 확인
|
||||
final canDelete = await controller.canDeleteCompany(companyId);
|
||||
if (canDelete) {
|
||||
_deleteCompany(companyId);
|
||||
} else {
|
||||
if (mounted) {
|
||||
ShadToaster.of(context).show(
|
||||
const ShadToast(
|
||||
title: Text('삭제 불가'),
|
||||
description: Text('자식 회사가 있어 삭제할 수 없습니다.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -434,6 +569,16 @@ class _CompanyListState extends State<CompanyList> {
|
||||
),
|
||||
],
|
||||
rightActions: [
|
||||
// Tree View 토글 버튼
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
controller.isTreeView ? Icons.list : Icons.account_tree,
|
||||
color: controller.isTreeView ? ShadcnTheme.primary : null,
|
||||
),
|
||||
tooltip: controller.isTreeView ? '리스트 보기' : '계층 보기',
|
||||
onPressed: () => controller.toggleTreeView(),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 관리자용 비활성 포함 체크박스
|
||||
// TODO: 실제 권한 체크 로직 추가 필요
|
||||
Row(
|
||||
@@ -451,7 +596,7 @@ class _CompanyListState extends State<CompanyList> {
|
||||
statusMessage: controller.searchQuery.isNotEmpty
|
||||
? '"${controller.searchQuery}" 검색 결과'
|
||||
: actualHeadquartersCount > 0
|
||||
? '본사: ${actualHeadquartersCount}개, 지점: ${actualBranchesCount}개 총 ${totalCount}개'
|
||||
? '본사: $actualHeadquartersCount개, 지점: $actualBranchesCount개 총 $totalCount개'
|
||||
: null,
|
||||
),
|
||||
|
||||
@@ -466,9 +611,10 @@ class _CompanyListState extends State<CompanyList> {
|
||||
)
|
||||
: null,
|
||||
|
||||
// 데이터 테이블
|
||||
dataTable:
|
||||
companyItems.isEmpty
|
||||
// 데이터 테이블 또는 Tree View
|
||||
dataTable: controller.isTreeView
|
||||
? _buildTreeView(context, controller)
|
||||
: companyItems.isEmpty
|
||||
? StandardEmptyState(
|
||||
title:
|
||||
controller.searchQuery.isNotEmpty
|
||||
@@ -483,136 +629,7 @@ class _CompanyListState extends State<CompanyList> {
|
||||
)
|
||||
: null,
|
||||
)
|
||||
: std_table.StandardDataTable(
|
||||
columns: [
|
||||
std_table.DataColumn(label: '번호', flex: 1),
|
||||
std_table.DataColumn(label: '회사명', flex: 3),
|
||||
std_table.DataColumn(label: '구분', flex: 1),
|
||||
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: [
|
||||
...companyItems.asMap().entries.map((entry) {
|
||||
final int index = ((controller.currentPage - 1) * controller.pageSize) + entry.key;
|
||||
final CompanyItem item = entry.value;
|
||||
|
||||
return std_table.StandardDataRow(
|
||||
index: index,
|
||||
columns: [
|
||||
std_table.DataColumn(label: '번호', flex: 1),
|
||||
std_table.DataColumn(label: '회사명', flex: 3),
|
||||
std_table.DataColumn(label: '구분', flex: 1),
|
||||
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: [
|
||||
// 번호
|
||||
Text(
|
||||
'${index + 1}',
|
||||
style: ShadcnTheme.bodySmall,
|
||||
),
|
||||
// 회사명 (계층적 표시)
|
||||
_buildDisplayNameText(item),
|
||||
// 구분 (본사/지점 배지)
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: _buildCompanyTypeLabel(item.isBranch),
|
||||
),
|
||||
// 주소
|
||||
Text(
|
||||
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: [
|
||||
std_table.StandardActionButtons(
|
||||
onEdit: item.id != null
|
||||
? () {
|
||||
if (item.isBranch) {
|
||||
// 지점 수정 - 통합 지점 관리 화면으로 이동
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
: _buildCompanyShadTable(companyItems, controller),
|
||||
|
||||
// 페이지네이션 (BaseListController의 goToPage 사용)
|
||||
pagination: Pagination(
|
||||
|
||||
221
lib/screens/company/components/company_tree_view.dart
Normal file
221
lib/screens/company/components/company_tree_view.dart
Normal file
@@ -0,0 +1,221 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/domain/entities/company_hierarchy.dart';
|
||||
import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
|
||||
/// 회사 계층 구조 Tree View 컴포넌트
|
||||
class CompanyTreeView extends StatelessWidget {
|
||||
final CompanyHierarchy hierarchy;
|
||||
final Map<String, bool> expandedNodes;
|
||||
final Function(String) onToggleExpand;
|
||||
final Function(String)? onNodeTap;
|
||||
final Function(String)? onEdit;
|
||||
final Function(String)? onDelete;
|
||||
final String? selectedNodeId;
|
||||
|
||||
const CompanyTreeView({
|
||||
super.key,
|
||||
required this.hierarchy,
|
||||
required this.expandedNodes,
|
||||
required this.onToggleExpand,
|
||||
this.onNodeTap,
|
||||
this.onEdit,
|
||||
this.onDelete,
|
||||
this.selectedNodeId,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.card,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: ShadcnTheme.border),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: hierarchy.children
|
||||
.map((node) => _buildTreeNode(context, node, 0))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTreeNode(BuildContext context, CompanyHierarchy node, int level) {
|
||||
final isExpanded = expandedNodes[node.id] ?? false;
|
||||
final hasChildren = node.children.isNotEmpty;
|
||||
final isSelected = selectedNodeId == node.id;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// 노드 헤더
|
||||
InkWell(
|
||||
onTap: () => onNodeTap?.call(node.id),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? ShadcnTheme.accent.withValues(alpha: 0.1) : null,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: ShadcnTheme.border.withValues(alpha: 0.5),
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16.0 + (level * 24.0),
|
||||
right: 8.0,
|
||||
top: 8.0,
|
||||
bottom: 8.0,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// 확장/축소 버튼
|
||||
if (hasChildren)
|
||||
GestureDetector(
|
||||
onTap: () => onToggleExpand(node.id),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Icon(
|
||||
isExpanded
|
||||
? Icons.keyboard_arrow_down
|
||||
: Icons.keyboard_arrow_right,
|
||||
size: 20,
|
||||
color: ShadcnTheme.muted,
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
const SizedBox(width: 28),
|
||||
|
||||
// 아이콘
|
||||
Icon(
|
||||
level == 0 ? Icons.business : Icons.domain,
|
||||
size: 18,
|
||||
color: level == 0 ? ShadcnTheme.primary : ShadcnTheme.muted,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 회사명
|
||||
Expanded(
|
||||
child: Text(
|
||||
node.name,
|
||||
style: ShadcnTheme.bodyMedium.copyWith(
|
||||
fontWeight: level == 0 ? FontWeight.w600 : FontWeight.normal,
|
||||
color: isSelected ? ShadcnTheme.primary : null,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 자손 수 표시
|
||||
if (node.totalDescendants > 0)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.muted.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'${node.totalDescendants}',
|
||||
style: ShadcnTheme.bodySmall.copyWith(
|
||||
fontSize: 11,
|
||||
color: ShadcnTheme.mutedForeground,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 액션 버튼들
|
||||
if (onEdit != null || onDelete != null) ...[
|
||||
const SizedBox(width: 8),
|
||||
_buildActionButtons(node.id),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 자식 노드들
|
||||
if (hasChildren && isExpanded)
|
||||
...node.children
|
||||
.map((childNode) => _buildTreeNode(context, childNode, level + 1))
|
||||
,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButtons(String nodeId) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (onEdit != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
iconSize: 16,
|
||||
padding: const EdgeInsets.all(4),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
onPressed: () => onEdit!(nodeId),
|
||||
color: ShadcnTheme.muted,
|
||||
tooltip: '수정',
|
||||
),
|
||||
if (onDelete != null)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
iconSize: 16,
|
||||
padding: const EdgeInsets.all(4),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 24,
|
||||
minHeight: 24,
|
||||
),
|
||||
onPressed: () => onDelete!(nodeId),
|
||||
color: ShadcnTheme.destructive,
|
||||
tooltip: '삭제',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 계층 구조 경로 표시 위젯 (Breadcrumb)
|
||||
class CompanyHierarchyPath extends StatelessWidget {
|
||||
final String fullPath;
|
||||
final TextStyle? style;
|
||||
|
||||
const CompanyHierarchyPath({
|
||||
super.key,
|
||||
required this.fullPath,
|
||||
this.style,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pathParts = fullPath.split('/').where((p) => p.isNotEmpty).toList();
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.account_tree,
|
||||
size: 14,
|
||||
color: ShadcnTheme.muted,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
pathParts.join(' > '),
|
||||
style: style ?? ShadcnTheme.bodySmall.copyWith(
|
||||
color: ShadcnTheme.mutedForeground,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
/// - 지점 생성/수정 요청
|
||||
/// - 폼 유효성 검증
|
||||
/// - 수정 모드에서 기존 데이터 로드
|
||||
library;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
@@ -135,7 +136,7 @@ class BranchController extends ChangeNotifier {
|
||||
/// 폼에 지점 데이터 설정 (수정 모드에서만 사용)
|
||||
void _populateFormWithBranchData(Company company) {
|
||||
nameController.text = company.name;
|
||||
addressController.text = company.address?.detailAddress ?? '';
|
||||
addressController.text = company.address.detailAddress ?? '';
|
||||
contactNameController.text = company.contactName ?? '';
|
||||
contactPositionController.text = company.contactPosition ?? '';
|
||||
contactEmailController.text = company.contactEmail ?? '';
|
||||
@@ -273,7 +274,7 @@ class BranchController extends ChangeNotifier {
|
||||
);
|
||||
|
||||
return nameController.text.trim() != _originalBranch!.name ||
|
||||
currentAddress.detailAddress != (_originalBranch!.address?.detailAddress ?? '') ||
|
||||
currentAddress.detailAddress != (_originalBranch!.address.detailAddress ?? '') ||
|
||||
contactNameController.text.trim() != (_originalBranch!.contactName ?? '') ||
|
||||
contactPositionController.text.trim() != (_originalBranch!.contactPosition ?? '') ||
|
||||
currentFullPhone != (_originalBranch!.contactPhone ?? '') ||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
/// - 전화번호 처리
|
||||
/// - 중복 회사명 체크
|
||||
/// - 회사 유형 관리
|
||||
library;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
@@ -15,7 +16,6 @@ import 'package:superport/models/company_model.dart';
|
||||
// import 'package:superport/services/mock_data_service.dart'; // Mock 서비스 제거
|
||||
import 'package:superport/services/company_service.dart';
|
||||
import 'package:superport/core/errors/failures.dart';
|
||||
import 'package:superport/utils/phone_utils.dart';
|
||||
import 'dart:async';
|
||||
import 'branch_form_controller.dart'; // 분리된 지점 컨트롤러 import
|
||||
|
||||
@@ -42,6 +42,10 @@ class CompanyFormController {
|
||||
|
||||
// 회사 유형 선택값 (복수)
|
||||
List<CompanyType> selectedCompanyTypes = [CompanyType.customer];
|
||||
|
||||
// 부모 회사 선택
|
||||
int? selectedParentCompanyId;
|
||||
List<Company> availableParentCompanies = [];
|
||||
|
||||
List<String> companyNames = [];
|
||||
List<String> filteredCompanyNames = [];
|
||||
@@ -96,15 +100,23 @@ class CompanyFormController {
|
||||
List<Company> companies;
|
||||
|
||||
// API만 사용 (PaginatedResponse에서 items 추출)
|
||||
final response = await _companyService.getCompanies();
|
||||
final response = await _companyService.getCompanies(page: 1, perPage: 1000);
|
||||
companies = response.items;
|
||||
|
||||
companyNames = companies.map((c) => c.name).toList();
|
||||
filteredCompanyNames = companyNames;
|
||||
|
||||
// 부모 회사 목록도 설정 (자기 자신은 제외)
|
||||
if (companyId != null) {
|
||||
availableParentCompanies = companies.where((c) => c.id != companyId).toList();
|
||||
} else {
|
||||
availableParentCompanies = companies;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ 회사명 목록 로드 실패: $e');
|
||||
companyNames = [];
|
||||
filteredCompanyNames = [];
|
||||
availableParentCompanies = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,86 +142,81 @@ class CompanyFormController {
|
||||
}
|
||||
|
||||
debugPrint('📝 로드된 회사 정보:');
|
||||
debugPrint(' - ID: ${company?.id}');
|
||||
debugPrint(' - 이름: ${company?.name}');
|
||||
debugPrint(' - 담당자: ${company?.contactName}');
|
||||
debugPrint(' - 연락처: ${company?.contactPhone}');
|
||||
debugPrint(' - 이메일: ${company?.contactEmail}');
|
||||
debugPrint(' - ID: ${company.id}');
|
||||
debugPrint(' - 이름: ${company.name}');
|
||||
debugPrint(' - 담당자: ${company.contactName}');
|
||||
debugPrint(' - 연락처: ${company.contactPhone}');
|
||||
debugPrint(' - 이메일: ${company.contactEmail}');
|
||||
|
||||
if (company != null) {
|
||||
// 폼 필드에 데이터 설정
|
||||
debugPrint('📝 회사명 설정 전: "${nameController.text}"');
|
||||
nameController.text = company.name;
|
||||
debugPrint('📝 회사명 설정 후: "${nameController.text}"');
|
||||
// 폼 필드에 데이터 설정
|
||||
debugPrint('📝 회사명 설정 전: "${nameController.text}"');
|
||||
nameController.text = company.name;
|
||||
debugPrint('📝 회사명 설정 후: "${nameController.text}"');
|
||||
|
||||
companyAddress = company.address;
|
||||
debugPrint('📝 주소 설정: $companyAddress');
|
||||
companyAddress = company.address;
|
||||
debugPrint('📝 주소 설정: $companyAddress');
|
||||
|
||||
contactNameController.text = company.contactName ?? '';
|
||||
debugPrint('📝 담당자명 설정: "${contactNameController.text}"');
|
||||
contactNameController.text = company.contactName ?? '';
|
||||
debugPrint('📝 담당자명 설정: "${contactNameController.text}"');
|
||||
|
||||
contactPositionController.text = company.contactPosition ?? '';
|
||||
debugPrint('📝 직급 설정: "${contactPositionController.text}"');
|
||||
contactPositionController.text = company.contactPosition ?? '';
|
||||
debugPrint('📝 직급 설정: "${contactPositionController.text}"');
|
||||
|
||||
contactEmailController.text = company.contactEmail ?? '';
|
||||
debugPrint('📝 이메일 설정: "${contactEmailController.text}"');
|
||||
contactEmailController.text = company.contactEmail ?? '';
|
||||
debugPrint('📝 이메일 설정: "${contactEmailController.text}"');
|
||||
|
||||
remarkController.text = company.remark ?? '';
|
||||
debugPrint('📝 비고 설정: "${remarkController.text}"');
|
||||
remarkController.text = company.remark ?? '';
|
||||
debugPrint('📝 비고 설정: "${remarkController.text}"');
|
||||
|
||||
// 전화번호 처리
|
||||
if (company.contactPhone != null && company.contactPhone!.isNotEmpty) {
|
||||
selectedPhonePrefix = extractPhonePrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
contactPhoneController.text = extractPhoneNumberWithoutPrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
debugPrint('📝 전화번호 설정: $selectedPhonePrefix-${contactPhoneController.text}');
|
||||
}
|
||||
|
||||
// 회사 유형 설정
|
||||
selectedCompanyTypes = List.from(company.companyTypes);
|
||||
debugPrint('📝 회사 유형 설정: $selectedCompanyTypes');
|
||||
|
||||
// 지점 정보 설정
|
||||
if (company.branches != null && company.branches!.isNotEmpty) {
|
||||
branchControllers.clear();
|
||||
for (final branch in company.branches!) {
|
||||
branchControllers.add(
|
||||
BranchFormController(
|
||||
branch: branch,
|
||||
positions: positions,
|
||||
phonePrefixes: phonePrefixes,
|
||||
),
|
||||
);
|
||||
}
|
||||
debugPrint('📝 지점 설정 완료: ${branchControllers.length}개');
|
||||
}
|
||||
|
||||
debugPrint('📝 폼 필드 설정 완료:');
|
||||
debugPrint(' - 회사명: "${nameController.text}"');
|
||||
debugPrint(' - 담당자: "${contactNameController.text}"');
|
||||
debugPrint(' - 이메일: "${contactEmailController.text}"');
|
||||
debugPrint(' - 전화번호: "$selectedPhonePrefix-${contactPhoneController.text}"');
|
||||
debugPrint(' - 지점 수: ${branchControllers.length}');
|
||||
debugPrint(' - 회사 유형: $selectedCompanyTypes');
|
||||
|
||||
// 강제로 TextEditingController 리스너 트리거
|
||||
nameController.notifyListeners();
|
||||
contactNameController.notifyListeners();
|
||||
contactPositionController.notifyListeners();
|
||||
contactEmailController.notifyListeners();
|
||||
contactPhoneController.notifyListeners();
|
||||
remarkController.notifyListeners();
|
||||
|
||||
debugPrint('✅ 폼 데이터 로드 완료');
|
||||
} else {
|
||||
debugPrint('❌ 회사 정보가 null입니다');
|
||||
// 전화번호 처리
|
||||
if (company.contactPhone != null && company.contactPhone!.isNotEmpty) {
|
||||
selectedPhonePrefix = extractPhonePrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
contactPhoneController.text = extractPhoneNumberWithoutPrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
debugPrint('📝 전화번호 설정: $selectedPhonePrefix-${contactPhoneController.text}');
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
|
||||
// 회사 유형 설정
|
||||
selectedCompanyTypes = List.from(company.companyTypes);
|
||||
debugPrint('📝 회사 유형 설정: $selectedCompanyTypes');
|
||||
|
||||
// 부모 회사 설정
|
||||
selectedParentCompanyId = company.parentCompanyId;
|
||||
debugPrint('📝 부모 회사 설정: $selectedParentCompanyId');
|
||||
|
||||
// 지점 정보 설정
|
||||
if (company.branches != null && company.branches!.isNotEmpty) {
|
||||
branchControllers.clear();
|
||||
for (final branch in company.branches!) {
|
||||
branchControllers.add(
|
||||
BranchFormController(
|
||||
branch: branch,
|
||||
positions: positions,
|
||||
phonePrefixes: phonePrefixes,
|
||||
),
|
||||
);
|
||||
}
|
||||
debugPrint('📝 지점 설정 완료: ${branchControllers.length}개');
|
||||
}
|
||||
|
||||
debugPrint('📝 폼 필드 설정 완료:');
|
||||
debugPrint(' - 회사명: "${nameController.text}"');
|
||||
debugPrint(' - 담당자: "${contactNameController.text}"');
|
||||
debugPrint(' - 이메일: "${contactEmailController.text}"');
|
||||
debugPrint(' - 전화번호: "$selectedPhonePrefix-${contactPhoneController.text}"');
|
||||
debugPrint(' - 지점 수: ${branchControllers.length}');
|
||||
debugPrint(' - 회사 유형: $selectedCompanyTypes');
|
||||
|
||||
// TextEditingController는 text 설정 시 자동으로 리스너 트리거됨
|
||||
// notifyListeners() 직접 호출은 불필요하고 부적절함
|
||||
|
||||
debugPrint('✅ 폼 데이터 로드 완료');
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('❌ 회사 정보 로드 실패: $e');
|
||||
debugPrint('❌ 스택 트레이스: $stackTrace');
|
||||
rethrow;
|
||||
@@ -356,6 +363,7 @@ class CompanyFormController {
|
||||
companyTypes: List.from(selectedCompanyTypes), // 복수 유형 저장
|
||||
isPartner: selectedCompanyTypes.contains(CompanyType.partner),
|
||||
isCustomer: selectedCompanyTypes.contains(CompanyType.customer),
|
||||
parentCompanyId: selectedParentCompanyId, // 부모 회사 ID 추가
|
||||
);
|
||||
|
||||
if (_useApi) {
|
||||
|
||||
@@ -6,17 +6,29 @@ import 'package:superport/services/company_service.dart';
|
||||
import 'package:superport/core/utils/error_handler.dart';
|
||||
import 'package:superport/core/controllers/base_list_controller.dart';
|
||||
import 'package:superport/data/models/common/pagination_params.dart';
|
||||
import 'package:superport/domain/entities/company_hierarchy.dart';
|
||||
import 'package:superport/domain/usecases/company/get_company_hierarchy_usecase.dart';
|
||||
import 'package:superport/domain/usecases/company/update_parent_company_usecase.dart';
|
||||
import 'package:superport/domain/usecases/company/validate_company_deletion_usecase.dart';
|
||||
|
||||
/// 회사 목록 화면의 상태 및 비즈니스 로직을 담당하는 컨트롤러 (리팩토링 버전)
|
||||
/// BaseListController를 상속받아 공통 기능을 재사용
|
||||
/// CompanyItem 모델을 사용하여 회사와 지점을 통합 관리
|
||||
class CompanyListController extends BaseListController<CompanyItem> {
|
||||
late final CompanyService _companyService;
|
||||
late final GetCompanyHierarchyUseCase _getCompanyHierarchyUseCase;
|
||||
late final UpdateParentCompanyUseCase _updateParentCompanyUseCase;
|
||||
late final ValidateCompanyDeletionUseCase _validateCompanyDeletionUseCase;
|
||||
|
||||
// 추가 상태 관리
|
||||
final Set<int> selectedCompanyIds = {};
|
||||
int _actualHeadquartersCount = 0; // 실제 본사 개수 (헤드쿼터 API 기준)
|
||||
|
||||
// 계층 구조 관련
|
||||
CompanyHierarchy? _companyHierarchy;
|
||||
bool _isTreeView = false;
|
||||
final Map<String, bool> _expandedNodes = {};
|
||||
|
||||
// 필터
|
||||
bool? _isActiveFilter;
|
||||
CompanyType? _typeFilter;
|
||||
@@ -34,7 +46,7 @@ class CompanyListController extends BaseListController<CompanyItem> {
|
||||
|
||||
// 호환성을 위한 기존 getter (deprecated, 사용하지 말 것)
|
||||
@deprecated
|
||||
List<Company> get companies => items.where((item) => !item.isBranch).map((item) => item.company!).toList();
|
||||
List<Company> get companies => items.where((item) => !item.isBranch).map((item) => item.company).toList();
|
||||
@deprecated
|
||||
List<Company> get filteredCompanies => companies;
|
||||
bool? get isActiveFilter => _isActiveFilter;
|
||||
@@ -47,9 +59,17 @@ class CompanyListController extends BaseListController<CompanyItem> {
|
||||
loadData(isRefresh: true);
|
||||
}
|
||||
|
||||
// 계층 구조 getter
|
||||
CompanyHierarchy? get companyHierarchy => _companyHierarchy;
|
||||
bool get isTreeView => _isTreeView;
|
||||
Map<String, bool> get expandedNodes => _expandedNodes;
|
||||
|
||||
CompanyListController() {
|
||||
if (GetIt.instance.isRegistered<CompanyService>()) {
|
||||
_companyService = GetIt.instance<CompanyService>();
|
||||
_getCompanyHierarchyUseCase = GetIt.instance<GetCompanyHierarchyUseCase>();
|
||||
_updateParentCompanyUseCase = GetIt.instance<UpdateParentCompanyUseCase>();
|
||||
_validateCompanyDeletionUseCase = GetIt.instance<ValidateCompanyDeletionUseCase>();
|
||||
} else {
|
||||
throw Exception('CompanyService not registered in GetIt');
|
||||
}
|
||||
@@ -326,4 +346,107 @@ class CompanyListController extends BaseListController<CompanyItem> {
|
||||
}
|
||||
clearSelection();
|
||||
}
|
||||
|
||||
// ==================== 계층 구조 관련 메서드 ====================
|
||||
|
||||
/// Tree View 모드 토글
|
||||
void toggleTreeView() {
|
||||
_isTreeView = !_isTreeView;
|
||||
if (_isTreeView) {
|
||||
loadHierarchy();
|
||||
} else {
|
||||
loadData(isRefresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// 계층 구조 로드
|
||||
Future<void> loadHierarchy() async {
|
||||
isLoadingState = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final result = await _getCompanyHierarchyUseCase.call(
|
||||
const GetCompanyHierarchyParams(includeInactive: false),
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
errorState = failure.message;
|
||||
_companyHierarchy = null;
|
||||
},
|
||||
(hierarchy) {
|
||||
_companyHierarchy = hierarchy;
|
||||
errorState = null;
|
||||
// 초기 확장 상태 설정 (루트 노드들만 확장)
|
||||
for (final child in hierarchy.children) {
|
||||
_expandedNodes[child.id] = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
errorState = '계층 구조 로드 중 오류가 발생했습니다: $e';
|
||||
_companyHierarchy = null;
|
||||
}
|
||||
|
||||
isLoadingState = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 노드 확장/축소 토글
|
||||
void toggleNodeExpansion(String nodeId) {
|
||||
_expandedNodes[nodeId] = !(_expandedNodes[nodeId] ?? false);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 부모 회사 변경
|
||||
Future<void> updateParentCompany(int companyId, int? newParentId) async {
|
||||
try {
|
||||
final result = await _updateParentCompanyUseCase.call(
|
||||
UpdateParentCompanyParams(
|
||||
companyId: companyId,
|
||||
newParentId: newParentId,
|
||||
),
|
||||
);
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
errorState = failure.message;
|
||||
notifyListeners();
|
||||
},
|
||||
(_) async {
|
||||
// 성공적으로 업데이트되면 리스트 새로고침
|
||||
if (_isTreeView) {
|
||||
await loadHierarchy();
|
||||
} else {
|
||||
await refresh();
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
errorState = '부모 회사 변경 중 오류가 발생했습니다: $e';
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 회사 삭제 가능 여부 검증
|
||||
Future<bool> canDeleteCompany(int companyId) async {
|
||||
try {
|
||||
final result = await _validateCompanyDeletionUseCase.call(
|
||||
ValidateCompanyDeletionParams(companyId: companyId),
|
||||
);
|
||||
|
||||
return result.fold(
|
||||
(failure) {
|
||||
errorState = failure.message;
|
||||
notifyListeners();
|
||||
return false;
|
||||
},
|
||||
(validationResult) => validationResult.canDelete,
|
||||
);
|
||||
} catch (e) {
|
||||
errorState = '삭제 검증 중 오류가 발생했습니다: $e';
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -425,7 +425,7 @@ class _CompanyBranchDialogState extends State<CompanyBranchDialog> {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.muted.withOpacity(0.1),
|
||||
color: ShadcnTheme.muted.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: ShadcnTheme.border,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
import 'package:superport/screens/common/custom_widgets.dart';
|
||||
import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
import 'package:superport/screens/common/widgets/address_input.dart';
|
||||
import 'package:superport/utils/validators.dart';
|
||||
import 'package:superport/screens/company/widgets/company_name_autocomplete.dart';
|
||||
import 'package:superport/screens/common/widgets/remark_input.dart';
|
||||
|
||||
@@ -23,7 +21,7 @@ class CompanyFormHeader extends StatelessWidget {
|
||||
final TextEditingController remarkController;
|
||||
|
||||
const CompanyFormHeader({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.nameController,
|
||||
required this.nameFocusNode,
|
||||
required this.companyNames,
|
||||
@@ -37,7 +35,7 @@ class CompanyFormHeader extends StatelessWidget {
|
||||
required this.nameLabel,
|
||||
required this.nameHint,
|
||||
required this.remarkController,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:superport/utils/validators.dart';
|
||||
|
||||
class CompanyNameAutocomplete extends StatelessWidget {
|
||||
@@ -14,7 +13,7 @@ class CompanyNameAutocomplete extends StatelessWidget {
|
||||
final String hint;
|
||||
|
||||
const CompanyNameAutocomplete({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.nameController,
|
||||
required this.nameFocusNode,
|
||||
required this.companyNames,
|
||||
@@ -24,7 +23,7 @@ class CompanyNameAutocomplete extends StatelessWidget {
|
||||
required this.onNameSaved,
|
||||
required this.label,
|
||||
required this.hint,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -5,8 +5,7 @@ import 'package:superport/models/company_model.dart';
|
||||
class DuplicateCompanyDialog extends StatelessWidget {
|
||||
final Company company;
|
||||
|
||||
const DuplicateCompanyDialog({Key? key, required this.company})
|
||||
: super(key: key);
|
||||
const DuplicateCompanyDialog({super.key, required this.company});
|
||||
|
||||
static void show(BuildContext context, Company company) {
|
||||
showDialog(
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
class MapDialog extends StatelessWidget {
|
||||
final String address;
|
||||
|
||||
const MapDialog({Key? key, required this.address}) : super(key: key);
|
||||
const MapDialog({super.key, required this.address});
|
||||
|
||||
static void show(BuildContext context, String address) {
|
||||
if (address.trim().isEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user