feat(dialog): 상세 팝업 SuperportDetailDialog 통합
- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화 - 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환 - SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거 - 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지 - detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
@@ -0,0 +1,845 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../../util/postal_search/presentation/models/postal_search_result.dart';
|
||||
import '../../../../util/postal_search/presentation/widgets/postal_search_dialog.dart';
|
||||
import '../../domain/entities/customer.dart';
|
||||
|
||||
/// 고객 상세 다이얼로그에서 발생 가능한 액션 종류이다.
|
||||
enum CustomerDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 고객 상세 다이얼로그가 반환하는 결과 모델이다.
|
||||
class CustomerDetailDialogResult {
|
||||
const CustomerDetailDialogResult({
|
||||
required this.action,
|
||||
required this.message,
|
||||
this.customer,
|
||||
});
|
||||
|
||||
final CustomerDetailDialogAction action;
|
||||
final String message;
|
||||
|
||||
/// 갱신된 고객 엔터티. 삭제 동작의 경우 null일 수 있다.
|
||||
final Customer? customer;
|
||||
}
|
||||
|
||||
typedef CustomerCreateCallback =
|
||||
Future<Customer?> Function(CustomerInput input);
|
||||
typedef CustomerUpdateCallback =
|
||||
Future<Customer?> Function(int id, CustomerInput input);
|
||||
typedef CustomerDeleteCallback = Future<bool> Function(int id);
|
||||
typedef CustomerRestoreCallback = Future<Customer?> Function(int id);
|
||||
|
||||
/// 고객 상세 다이얼로그를 노출한다.
|
||||
Future<CustomerDetailDialogResult?> showCustomerDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Customer? customer,
|
||||
required CustomerCreateCallback onCreate,
|
||||
required CustomerUpdateCallback onUpdate,
|
||||
required CustomerDeleteCallback onDelete,
|
||||
required CustomerRestoreCallback onRestore,
|
||||
}) {
|
||||
final metadata = customer == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: customer.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '고객사 코드',
|
||||
value: customer.customerCode,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '유형',
|
||||
value: _resolveType(customer),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '담당자',
|
||||
value: customer.contactName?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.contactName!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '연락처',
|
||||
value: customer.mobileNo?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.mobileNo!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '이메일',
|
||||
value: customer.email?.isEmpty ?? true ? '-' : customer.email!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 상태',
|
||||
value: customer.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: customer.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '우편번호',
|
||||
value: customer.zipcode?.zipcode ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '주소',
|
||||
value: _resolveAddress(customer),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: customer.note?.isEmpty ?? true ? '-' : customer.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: customer.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(customer.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '수정일시',
|
||||
value: customer.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(customer.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<CustomerDetailDialogResult>(
|
||||
context: context,
|
||||
title: customer == null ? '고객사 등록' : '고객사 상세',
|
||||
description: customer == null
|
||||
? '새로운 고객사 정보를 입력하세요.'
|
||||
: '고객사 기본 정보와 연락처·주소를 확인하고 관리합니다.',
|
||||
sections: [
|
||||
_CustomerEditSection(
|
||||
id: customer == null
|
||||
? _CustomerDetailSections.create
|
||||
: _CustomerDetailSections.edit,
|
||||
label: customer == null ? '등록' : '수정',
|
||||
customer: customer,
|
||||
onSubmit: (input) async {
|
||||
if (customer == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.created,
|
||||
message: '고객사를 등록했습니다.',
|
||||
customer: created,
|
||||
);
|
||||
}
|
||||
final updated = await onUpdate(customer.id!, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.updated,
|
||||
message: '고객사를 수정했습니다.',
|
||||
customer: updated,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (customer != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: customer.isDeleted
|
||||
? _CustomerDetailSections.restore
|
||||
: _CustomerDetailSections.delete,
|
||||
label: customer.isDeleted ? '복구' : '삭제',
|
||||
icon: customer.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (_) => _CustomerDangerSection(
|
||||
customer: customer,
|
||||
onDelete: () async {
|
||||
final success = await onDelete(customer.id!);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return const CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.deleted,
|
||||
message: '고객사를 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final restored = await onRestore(customer.id!);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.restored,
|
||||
message: '고객사를 복구했습니다.',
|
||||
customer: restored,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
summary: customer == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
customer.customerName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'코드 ${customer.customerCode}',
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: customer == null
|
||||
? const []
|
||||
: [
|
||||
if (customer.isPartner && customer.isGeneral)
|
||||
const ShadBadge(child: Text('파트너/일반'))
|
||||
else if (customer.isPartner)
|
||||
const ShadBadge(child: Text('파트너'))
|
||||
else if (customer.isGeneral)
|
||||
const ShadBadge(child: Text('일반')),
|
||||
if (customer.isActive)
|
||||
const ShadBadge.outline(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.destructive(child: Text('미사용')),
|
||||
if (customer.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
emptyPlaceholder: const Text('표시할 고객사 정보가 없습니다.'),
|
||||
initialSectionId: customer == null
|
||||
? _CustomerDetailSections.create
|
||||
: _CustomerDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 다이얼로그 섹션 식별자 상수 모음이다.
|
||||
class _CustomerDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const create = 'create';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
}
|
||||
|
||||
/// 키-값 형태의 행을 표현하는 내부 모델이다.
|
||||
|
||||
/// 고객 등록/수정 폼 섹션 정의이다.
|
||||
class _CustomerEditSection extends SuperportDetailDialogSection {
|
||||
_CustomerEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required this.customer,
|
||||
required this.onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) =>
|
||||
_CustomerForm(customer: customer, onSubmit: onSubmit),
|
||||
);
|
||||
|
||||
final Customer? customer;
|
||||
final Future<CustomerDetailDialogResult?> Function(CustomerInput input)
|
||||
onSubmit;
|
||||
}
|
||||
|
||||
/// 삭제/복구 단계를 안내하는 위험 섹션이다.
|
||||
class _CustomerDangerSection extends StatelessWidget {
|
||||
const _CustomerDangerSection({
|
||||
required this.customer,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Customer customer;
|
||||
final Future<CustomerDetailDialogResult?> Function() onDelete;
|
||||
final Future<CustomerDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = customer.isDeleted;
|
||||
final description = isDeleted
|
||||
? '고객사를 복구하면 다시 목록에 노출되고 사용중 상태로 전환됩니다.'
|
||||
: '고객사를 삭제하면 목록에서 숨겨지고 관련 데이터는 보존됩니다.';
|
||||
final actionLabel = isDeleted ? '복구' : '삭제';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(actionLabel),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(actionLabel),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 고객 입력 폼을 관리하는 상태ful 위젯이다.
|
||||
class _CustomerForm extends StatefulWidget {
|
||||
const _CustomerForm({required this.customer, required this.onSubmit});
|
||||
|
||||
final Customer? customer;
|
||||
final Future<CustomerDetailDialogResult?> Function(CustomerInput input)
|
||||
onSubmit;
|
||||
|
||||
@override
|
||||
State<_CustomerForm> createState() => _CustomerFormState();
|
||||
}
|
||||
|
||||
class _CustomerFormState extends State<_CustomerForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _contactController;
|
||||
late final TextEditingController _emailController;
|
||||
late final TextEditingController _mobileController;
|
||||
late final TextEditingController _zipcodeController;
|
||||
late final TextEditingController _addressController;
|
||||
late final TextEditingController _noteController;
|
||||
late bool _isPartner;
|
||||
late bool _isGeneral;
|
||||
late bool _isActive;
|
||||
PostalSearchResult? _selectedPostal;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _typeError;
|
||||
String? _zipcodeError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
bool _isApplyingPostalSelection = false;
|
||||
|
||||
bool get _isEdit => widget.customer != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final existing = widget.customer;
|
||||
_codeController = TextEditingController(text: existing?.customerCode ?? '');
|
||||
_nameController = TextEditingController(text: existing?.customerName ?? '');
|
||||
_contactController = TextEditingController(
|
||||
text: existing?.contactName ?? '',
|
||||
);
|
||||
_emailController = TextEditingController(text: existing?.email ?? '');
|
||||
_mobileController = TextEditingController(text: existing?.mobileNo ?? '');
|
||||
_zipcodeController = TextEditingController(
|
||||
text: existing?.zipcode?.zipcode ?? '',
|
||||
);
|
||||
_addressController = TextEditingController(
|
||||
text: existing?.addressDetail ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: existing?.note ?? '');
|
||||
|
||||
final zipcode = existing?.zipcode;
|
||||
_selectedPostal = zipcode == null
|
||||
? null
|
||||
: PostalSearchResult(
|
||||
zipcode: zipcode.zipcode,
|
||||
sido: zipcode.sido,
|
||||
sigungu: zipcode.sigungu,
|
||||
roadName: zipcode.roadName,
|
||||
);
|
||||
|
||||
_isPartner = existing?.isPartner ?? false;
|
||||
_isGeneral = existing?.isGeneral ?? true;
|
||||
_isActive = existing?.isActive ?? true;
|
||||
|
||||
_zipcodeController.addListener(_handleZipcodeChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_contactController.dispose();
|
||||
_emailController.dispose();
|
||||
_mobileController.dispose();
|
||||
_zipcodeController.removeListener(_handleZipcodeChanged);
|
||||
_zipcodeController.dispose();
|
||||
_addressController.dispose();
|
||||
_noteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final destructiveColor = theme.colorScheme.destructive;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_CustomerFormField(
|
||||
label: '고객사코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '고객사명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '담당자',
|
||||
child: ShadInput(controller: _contactController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '유형',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: _isPartner,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_isPartner = value;
|
||||
if (!_isPartner && !_isGeneral) {
|
||||
_typeError = '파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
_typeError = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('파트너'),
|
||||
const SizedBox(width: 24),
|
||||
ShadCheckbox(
|
||||
value: _isGeneral,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_isGeneral = value;
|
||||
if (!_isPartner && !_isGeneral) {
|
||||
_typeError = '파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
_typeError = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('일반'),
|
||||
],
|
||||
),
|
||||
if (_typeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_typeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '이메일',
|
||||
child: ShadInput(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '연락처',
|
||||
child: ShadInput(
|
||||
controller: _mobileController,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '우편번호',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ShadInput(
|
||||
controller: _zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
onPressed: _isSubmitting ? null : _openPostalSearch,
|
||||
child: const Text('검색'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_selectedPostal == null
|
||||
? '검색 버튼을 눌러 주소를 선택하세요.'
|
||||
: _selectedPostal!.fullAddress.isEmpty
|
||||
? '선택한 우편번호에 주소 정보가 없습니다.'
|
||||
: _selectedPostal!.fullAddress,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: _selectedPostal == null
|
||||
? theme.colorScheme.mutedForeground
|
||||
: theme.textTheme.small.color,
|
||||
),
|
||||
),
|
||||
if (_zipcodeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_zipcodeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '상세주소',
|
||||
child: ShadInput(
|
||||
controller: _addressController,
|
||||
placeholder: const Text('상세주소 입력'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: _isActive,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) {
|
||||
setState(() {
|
||||
_isActive = next;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_isActive ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 200,
|
||||
),
|
||||
),
|
||||
if (widget.customer != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(widget.customer!.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(widget.customer!.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(color: destructiveColor),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openPostalSearch() async {
|
||||
final keyword = _zipcodeController.text.trim();
|
||||
final result = await showPostalSearchDialog(
|
||||
context,
|
||||
initialKeyword: keyword.isEmpty ? null : keyword,
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
_isApplyingPostalSelection = true;
|
||||
_zipcodeController
|
||||
..text = result.zipcode
|
||||
..selection = TextSelection.collapsed(offset: result.zipcode.length);
|
||||
_isApplyingPostalSelection = false;
|
||||
setState(() {
|
||||
_selectedPostal = result;
|
||||
if (result.fullAddress.isNotEmpty) {
|
||||
_addressController
|
||||
..text = result.fullAddress
|
||||
..selection = TextSelection.collapsed(
|
||||
offset: _addressController.text.length,
|
||||
);
|
||||
}
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
|
||||
void _handleZipcodeChanged() {
|
||||
if (_isApplyingPostalSelection) {
|
||||
return;
|
||||
}
|
||||
final text = _zipcodeController.text.trim();
|
||||
if (text.isEmpty) {
|
||||
if (_selectedPostal != null) {
|
||||
setState(() {
|
||||
_selectedPostal = null;
|
||||
});
|
||||
}
|
||||
if (_zipcodeError != null) {
|
||||
setState(() {
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_selectedPostal != null && _selectedPostal!.zipcode != text) {
|
||||
setState(() {
|
||||
_selectedPostal = null;
|
||||
});
|
||||
}
|
||||
if (_zipcodeError != null) {
|
||||
setState(() {
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
final contact = _contactController.text.trim();
|
||||
final email = _emailController.text.trim();
|
||||
final mobile = _mobileController.text.trim();
|
||||
final zipcode = _zipcodeController.text.trim();
|
||||
final address = _addressController.text.trim();
|
||||
final note = _noteController.text.trim();
|
||||
|
||||
if (!_isPartner && !_isGeneral) {
|
||||
setState(() {
|
||||
_isGeneral = true;
|
||||
});
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '고객사코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '고객사명을 입력하세요.' : null;
|
||||
_typeError = (!_isPartner && !_isGeneral)
|
||||
? '파트너/일반 중 하나 이상 선택하세요.'
|
||||
: null;
|
||||
_zipcodeError = zipcode.isNotEmpty && _selectedPostal == null
|
||||
? '우편번호 검색으로 주소를 선택하세요.'
|
||||
: null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null ||
|
||||
_nameError != null ||
|
||||
_typeError != null ||
|
||||
_zipcodeError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final input = CustomerInput(
|
||||
customerCode: code,
|
||||
customerName: name,
|
||||
contactName: contact.isEmpty ? null : contact,
|
||||
isPartner: _isPartner,
|
||||
isGeneral: _isGeneral,
|
||||
email: email.isEmpty ? null : email,
|
||||
mobileNo: mobile.isEmpty ? null : mobile,
|
||||
zipcode: zipcode.isEmpty ? null : zipcode,
|
||||
addressDetail: address.isEmpty ? null : address,
|
||||
isActive: _isActive,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return value.toLocal().toIso8601String();
|
||||
}
|
||||
}
|
||||
|
||||
/// 고객 폼 필드의 레이블·컨텐츠 배치를 담당한다.
|
||||
class _CustomerFormField extends StatelessWidget {
|
||||
const _CustomerFormField({required this.label, required this.child});
|
||||
|
||||
final String label;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: theme.textTheme.small),
|
||||
const SizedBox(height: 6),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _resolveType(Customer customer) {
|
||||
if (customer.isPartner && customer.isGeneral) {
|
||||
return '파트너/일반';
|
||||
}
|
||||
if (customer.isPartner) {
|
||||
return '파트너';
|
||||
}
|
||||
if (customer.isGeneral) {
|
||||
return '일반';
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
|
||||
String _resolveAddress(Customer customer) {
|
||||
final zipcode = customer.zipcode;
|
||||
final detail = customer.addressDetail;
|
||||
if (zipcode == null && (detail == null || detail.isEmpty)) {
|
||||
return '-';
|
||||
}
|
||||
final buffer = StringBuffer();
|
||||
if (zipcode != null) {
|
||||
buffer.write(zipcode.zipcode);
|
||||
final components = [
|
||||
zipcode.sido,
|
||||
zipcode.sigungu,
|
||||
zipcode.roadName,
|
||||
].whereType<String>().where((value) => value.isNotEmpty);
|
||||
if (components.isNotEmpty) {
|
||||
buffer.write(' (${components.join(' ')})');
|
||||
}
|
||||
}
|
||||
if (detail != null && detail.isNotEmpty) {
|
||||
if (buffer.isNotEmpty) {
|
||||
buffer.write('\n');
|
||||
}
|
||||
buffer.write(detail);
|
||||
}
|
||||
return buffer.isEmpty ? '-' : buffer.toString();
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import 'package:superport_v2/core/constants/app_sections.dart';
|
||||
import 'package:superport_v2/widgets/app_layout.dart';
|
||||
import 'package:superport_v2/widgets/components/filter_bar.dart';
|
||||
import 'package:superport_v2/widgets/components/superport_dialog.dart';
|
||||
import 'package:superport_v2/widgets/components/superport_pagination_controls.dart';
|
||||
import 'package:superport_v2/features/util/postal_search/presentation/models/postal_search_result.dart';
|
||||
import 'package:superport_v2/features/util/postal_search/presentation/widgets/postal_search_dialog.dart';
|
||||
import 'package:superport_v2/widgets/components/superport_table.dart';
|
||||
import 'package:superport_v2/widgets/components/responsive_section.dart';
|
||||
|
||||
import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/customer.dart';
|
||||
import '../../domain/repositories/customer_repository.dart';
|
||||
import '../dialogs/customer_detail_dialog.dart';
|
||||
import '../controllers/customer_controller.dart';
|
||||
|
||||
/// 고객 관리 화면. 기능 플래그에 따라 사양 페이지를 보여주거나 실제 목록을 노출한다.
|
||||
@@ -89,6 +89,84 @@ class CustomerPage extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _CustomerTable extends StatelessWidget {
|
||||
const _CustomerTable({required this.customers, required this.onCustomerTap});
|
||||
|
||||
final List<Customer> customers;
|
||||
final void Function(Customer customer)? onCustomerTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final columns = const [
|
||||
Text('ID'),
|
||||
Text('고객사코드'),
|
||||
Text('고객사명'),
|
||||
Text('담당자'),
|
||||
Text('유형'),
|
||||
Text('이메일'),
|
||||
Text('연락처'),
|
||||
Text('우편번호'),
|
||||
Text('상세주소'),
|
||||
Text('사용'),
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
];
|
||||
|
||||
String resolveType(Customer customer) {
|
||||
if (customer.isPartner && customer.isGeneral) {
|
||||
return '파트너/일반';
|
||||
}
|
||||
if (customer.isPartner) return '파트너';
|
||||
if (customer.isGeneral) return '일반';
|
||||
return '-';
|
||||
}
|
||||
|
||||
final rows = customers
|
||||
.map(
|
||||
(customer) => <Widget>[
|
||||
Text(customer.id?.toString() ?? '-'),
|
||||
Text(customer.customerCode),
|
||||
Text(customer.customerName),
|
||||
Text(
|
||||
customer.contactName?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.contactName!,
|
||||
),
|
||||
Text(resolveType(customer)),
|
||||
Text(customer.email?.isEmpty ?? true ? '-' : customer.email!),
|
||||
Text(customer.mobileNo?.isEmpty ?? true ? '-' : customer.mobileNo!),
|
||||
Text(customer.zipcode?.zipcode ?? '-'),
|
||||
Text(
|
||||
customer.addressDetail?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.addressDetail!,
|
||||
),
|
||||
Text(customer.isActive ? 'Y' : 'N'),
|
||||
Text(customer.isDeleted ? 'Y' : '-'),
|
||||
Text(customer.note?.isEmpty ?? true ? '-' : customer.note!),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 56.0 * (customers.length + 1),
|
||||
onRowTap: onCustomerTap == null
|
||||
? null
|
||||
: (index) => onCustomerTap!(customers[index]),
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
2 => const FixedTableSpanExtent(180),
|
||||
5 => const FixedTableSpanExtent(200),
|
||||
8 => const FixedTableSpanExtent(220),
|
||||
11 => const FixedTableSpanExtent(200),
|
||||
_ => const FixedTableSpanExtent(140),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 고객 관리 기능이 활성화된 경우 사용하는 실제 화면 위젯.
|
||||
class _CustomerEnabledPage extends StatefulWidget {
|
||||
const _CustomerEnabledPage({required this.routeUri});
|
||||
@@ -104,6 +182,7 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
late final CustomerController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
|
||||
String? _lastError;
|
||||
String? _lastAppliedRoute;
|
||||
|
||||
@@ -211,7 +290,7 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openCustomerForm(context),
|
||||
: _openCustomerCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -346,14 +425,9 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
)
|
||||
: _CustomerTable(
|
||||
customers: customers,
|
||||
onEdit: _controller.isSubmitting
|
||||
onCustomerTap: _controller.isSubmitting
|
||||
? null
|
||||
: (customer) =>
|
||||
_openCustomerForm(context, customer: customer),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreCustomer,
|
||||
: _openCustomerDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -475,6 +549,40 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openCustomerCreateDialog() async {
|
||||
final result = await showCustomerDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openCustomerDetailDialog(Customer customer) async {
|
||||
final customerId = customer.id;
|
||||
if (customerId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
final result = await showCustomerDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
customer: customer,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
String _typeLabel(CustomerTypeFilter filter) {
|
||||
switch (filter) {
|
||||
case CustomerTypeFilter.all:
|
||||
@@ -497,546 +605,6 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openCustomerForm(
|
||||
BuildContext context, {
|
||||
Customer? customer,
|
||||
}) async {
|
||||
final existing = customer;
|
||||
final isEdit = existing != null;
|
||||
final customerId = existing?.id;
|
||||
if (isEdit && customerId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final parentContext = context;
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existing?.customerCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existing?.customerName ?? '',
|
||||
);
|
||||
final contactController = TextEditingController(
|
||||
text: existing?.contactName ?? '',
|
||||
);
|
||||
final emailController = TextEditingController(text: existing?.email ?? '');
|
||||
final mobileController = TextEditingController(
|
||||
text: existing?.mobileNo ?? '',
|
||||
);
|
||||
final zipcodeController = TextEditingController(
|
||||
text: existing?.zipcode?.zipcode ?? '',
|
||||
);
|
||||
final addressController = TextEditingController(
|
||||
text: existing?.addressDetail ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(text: existing?.note ?? '');
|
||||
final existingZipcode = existing?.zipcode;
|
||||
final selectedPostalNotifier = ValueNotifier<PostalSearchResult?>(
|
||||
existingZipcode == null
|
||||
? null
|
||||
: PostalSearchResult(
|
||||
zipcode: existingZipcode.zipcode,
|
||||
sido: existingZipcode.sido,
|
||||
sigungu: existingZipcode.sigungu,
|
||||
roadName: existingZipcode.roadName,
|
||||
),
|
||||
);
|
||||
final partnerNotifier = ValueNotifier<bool>(existing?.isPartner ?? false);
|
||||
final generalNotifier = ValueNotifier<bool>(existing?.isGeneral ?? true);
|
||||
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final typeError = ValueNotifier<String?>(null);
|
||||
final zipcodeError = ValueNotifier<String?>(null);
|
||||
|
||||
var isApplyingPostalSelection = false;
|
||||
|
||||
void handleZipcodeChange() {
|
||||
if (isApplyingPostalSelection) {
|
||||
return;
|
||||
}
|
||||
final text = zipcodeController.text.trim();
|
||||
final selection = selectedPostalNotifier.value;
|
||||
if (text.isEmpty) {
|
||||
if (selection != null) {
|
||||
selectedPostalNotifier.value = null;
|
||||
}
|
||||
zipcodeError.value = null;
|
||||
return;
|
||||
}
|
||||
if (selection != null && selection.zipcode != text) {
|
||||
selectedPostalNotifier.value = null;
|
||||
}
|
||||
if (zipcodeError.value != null) {
|
||||
zipcodeError.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
void handlePostalSelectionChange() {
|
||||
if (selectedPostalNotifier.value != null) {
|
||||
zipcodeError.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
zipcodeController.addListener(handleZipcodeChange);
|
||||
selectedPostalNotifier.addListener(handlePostalSelectionChange);
|
||||
|
||||
Future<void> openPostalSearch(BuildContext dialogContext) async {
|
||||
final keyword = zipcodeController.text.trim();
|
||||
final result = await showPostalSearchDialog(
|
||||
dialogContext,
|
||||
initialKeyword: keyword.isEmpty ? null : keyword,
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
isApplyingPostalSelection = true;
|
||||
zipcodeController
|
||||
..text = result.zipcode
|
||||
..selection = TextSelection.collapsed(offset: result.zipcode.length);
|
||||
isApplyingPostalSelection = false;
|
||||
selectedPostalNotifier.value = result;
|
||||
if (result.fullAddress.isNotEmpty) {
|
||||
addressController
|
||||
..text = result.fullAddress
|
||||
..selection = TextSelection.collapsed(
|
||||
offset: addressController.text.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
context: parentContext,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '고객사 수정' : '고객사 등록',
|
||||
description: '고객사 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
primaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (context, isSaving, _) {
|
||||
return ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final code = codeController.text.trim();
|
||||
final name = nameController.text.trim();
|
||||
final contact = contactController.text.trim();
|
||||
final email = emailController.text.trim();
|
||||
final mobile = mobileController.text.trim();
|
||||
final zipcode = zipcodeController.text.trim();
|
||||
final address = addressController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
final partner = partnerNotifier.value;
|
||||
var general = generalNotifier.value;
|
||||
final selectedPostal = selectedPostalNotifier.value;
|
||||
|
||||
codeError.value = code.isEmpty ? '고객사코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '고객사명을 입력하세요.' : null;
|
||||
zipcodeError.value =
|
||||
zipcode.isNotEmpty && selectedPostal == null
|
||||
? '우편번호 검색으로 주소를 선택하세요.'
|
||||
: null;
|
||||
|
||||
if (!partner && !general) {
|
||||
general = true;
|
||||
generalNotifier.value = true;
|
||||
}
|
||||
|
||||
typeError.value = (!partner && !general)
|
||||
? '파트너/일반 중 하나 이상 선택하세요.'
|
||||
: null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
zipcodeError.value != null ||
|
||||
typeError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = CustomerInput(
|
||||
customerCode: code,
|
||||
customerName: name,
|
||||
contactName: contact.isEmpty ? null : contact,
|
||||
isPartner: partner,
|
||||
isGeneral: general,
|
||||
email: email.isEmpty ? null : email,
|
||||
mobileNo: mobile.isEmpty ? null : mobile,
|
||||
zipcode: zipcode.isEmpty ? null : zipcode,
|
||||
addressDetail: address.isEmpty ? null : address,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(customerId!, input)
|
||||
: await _controller.create(input);
|
||||
saving.value = false;
|
||||
if (response != null) {
|
||||
if (!navigator.mounted) {
|
||||
return;
|
||||
}
|
||||
if (mounted) {
|
||||
_showSnack(isEdit ? '고객사를 수정했습니다.' : '고객사를 등록했습니다.');
|
||||
}
|
||||
navigator.pop(true);
|
||||
}
|
||||
},
|
||||
child: Text(isEdit ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
secondaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (context, isSaving, _) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(context, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (context, isSaving, _) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final materialTheme = Theme.of(context);
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: codeError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '고객사코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: codeController,
|
||||
readOnly: isEdit,
|
||||
onChanged: (_) {
|
||||
if (codeController.text.trim().isNotEmpty) {
|
||||
codeError.value = null;
|
||||
}
|
||||
},
|
||||
),
|
||||
if (errorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
errorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: nameError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '고객사명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: nameController,
|
||||
onChanged: (_) {
|
||||
if (nameController.text.trim().isNotEmpty) {
|
||||
nameError.value = null;
|
||||
}
|
||||
},
|
||||
),
|
||||
if (errorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
errorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '담당자',
|
||||
child: ShadInput(controller: contactController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: partnerNotifier,
|
||||
builder: (_, partner, __) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: generalNotifier,
|
||||
builder: (_, general, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: typeError,
|
||||
builder: (_, errorText, __) {
|
||||
final onChanged = isSaving
|
||||
? null
|
||||
: (bool? value) {
|
||||
if (value == null) return;
|
||||
partnerNotifier.value = value;
|
||||
if (!value && !generalNotifier.value) {
|
||||
typeError.value =
|
||||
'파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
typeError.value = null;
|
||||
}
|
||||
};
|
||||
final onChangedGeneral = isSaving
|
||||
? null
|
||||
: (bool? value) {
|
||||
if (value == null) return;
|
||||
generalNotifier.value = value;
|
||||
if (!value && !partnerNotifier.value) {
|
||||
typeError.value =
|
||||
'파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
typeError.value = null;
|
||||
}
|
||||
};
|
||||
return _FormField(
|
||||
label: '유형',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: partner,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('파트너'),
|
||||
const SizedBox(width: 24),
|
||||
ShadCheckbox(
|
||||
value: general,
|
||||
onChanged: onChangedGeneral,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('일반'),
|
||||
],
|
||||
),
|
||||
if (errorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
errorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color:
|
||||
materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '이메일',
|
||||
child: ShadInput(
|
||||
controller: emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '연락처',
|
||||
child: ShadInput(
|
||||
controller: mobileController,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: zipcodeError,
|
||||
builder: (_, zipcodeErrorText, __) {
|
||||
return _FormField(
|
||||
label: '우편번호',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ShadInput(
|
||||
controller: zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => openPostalSearch(context),
|
||||
child: const Text('검색'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ValueListenableBuilder<PostalSearchResult?>(
|
||||
valueListenable: selectedPostalNotifier,
|
||||
builder: (_, selection, __) {
|
||||
if (selection == null) {
|
||||
return Text(
|
||||
'검색 버튼을 눌러 주소를 선택하세요.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
);
|
||||
}
|
||||
final fullAddress = selection.fullAddress;
|
||||
return Text(
|
||||
fullAddress.isEmpty
|
||||
? '선택한 우편번호에 주소 정보가 없습니다.'
|
||||
: fullAddress,
|
||||
style: theme.textTheme.small,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (zipcodeErrorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
zipcodeErrorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '상세주소',
|
||||
child: ShadInput(
|
||||
controller: addressController,
|
||||
placeholder: const Text('상세주소 입력'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: isSaving
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (existing != null) ..._buildAuditInfo(existing, theme),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
zipcodeController.removeListener(handleZipcodeChange);
|
||||
selectedPostalNotifier.removeListener(handlePostalSelectionChange);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
contactController.dispose();
|
||||
emailController.dispose();
|
||||
mobileController.dispose();
|
||||
zipcodeController.dispose();
|
||||
addressController.dispose();
|
||||
noteController.dispose();
|
||||
selectedPostalNotifier.dispose();
|
||||
partnerNotifier.dispose();
|
||||
generalNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
typeError.dispose();
|
||||
zipcodeError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Customer customer) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '고객사 삭제',
|
||||
description: '"${customer.customerName}" 고객사를 삭제하시겠습니까?',
|
||||
actions: [
|
||||
ShadButton.ghost(
|
||||
onPressed: () =>
|
||||
Navigator.of(context, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
ShadButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context, rootNavigator: true).pop(true),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && customer.id != null) {
|
||||
final success = await _controller.delete(customer.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('고객사를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreCustomer(Customer customer) async {
|
||||
if (customer.id == null) return;
|
||||
final restored = await _controller.restore(customer.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('고객사를 복구했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
void _showSnack(String message) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -1047,143 +615,4 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) return '-';
|
||||
return value.toLocal().toIso8601String();
|
||||
}
|
||||
|
||||
List<Widget> _buildAuditInfo(Customer customer, ShadThemeData theme) {
|
||||
return [
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(customer.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(customer.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class _CustomerTable extends StatelessWidget {
|
||||
const _CustomerTable({
|
||||
required this.customers,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final List<Customer> customers;
|
||||
final void Function(Customer customer)? onEdit;
|
||||
final void Function(Customer customer)? onDelete;
|
||||
final void Function(Customer customer)? onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final header = [
|
||||
'ID',
|
||||
'고객사코드',
|
||||
'고객사명',
|
||||
'담당자',
|
||||
'유형',
|
||||
'이메일',
|
||||
'연락처',
|
||||
'우편번호',
|
||||
'상세주소',
|
||||
'사용',
|
||||
'삭제',
|
||||
'비고',
|
||||
'동작',
|
||||
].map((text) => ShadTableCell.header(child: Text(text))).toList();
|
||||
|
||||
String resolveType(Customer customer) {
|
||||
if (customer.isPartner && customer.isGeneral) {
|
||||
return '파트너/일반';
|
||||
}
|
||||
if (customer.isPartner) return '파트너';
|
||||
if (customer.isGeneral) return '일반';
|
||||
return '-';
|
||||
}
|
||||
|
||||
final rows = customers.map((customer) {
|
||||
return [
|
||||
customer.id?.toString() ?? '-',
|
||||
customer.customerCode,
|
||||
customer.customerName,
|
||||
customer.contactName?.isEmpty ?? true ? '-' : customer.contactName!,
|
||||
resolveType(customer),
|
||||
customer.email?.isEmpty ?? true ? '-' : customer.email!,
|
||||
customer.mobileNo?.isEmpty ?? true ? '-' : customer.mobileNo!,
|
||||
customer.zipcode?.zipcode ?? '-',
|
||||
customer.addressDetail?.isEmpty ?? true ? '-' : customer.addressDetail!,
|
||||
customer.isActive ? 'Y' : 'N',
|
||||
customer.isDeleted ? 'Y' : '-',
|
||||
customer.note?.isEmpty ?? true ? '-' : customer.note!,
|
||||
].map((text) => ShadTableCell(child: Text(text))).toList()..add(
|
||||
ShadTableCell(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(customer),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
customer.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(customer),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(customer),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (customers.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) => index == 11
|
||||
? const FixedTableSpanExtent(160)
|
||||
: const FixedTableSpanExtent(140),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FormField extends StatelessWidget {
|
||||
const _FormField({required this.label, required this.child});
|
||||
|
||||
final String label;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: theme.textTheme.small),
|
||||
const SizedBox(height: 6),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user