마스터 고객/제품/창고 테스트 및 UI 구현
This commit is contained in:
31
lib/core/common/models/paginated_result.dart
Normal file
31
lib/core/common/models/paginated_result.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
/// 공통 페이지네이션 결과 모델
|
||||
///
|
||||
/// - API 응답 형식 `{ "items": [...], "page": 1, "page_size": 20, "total": 40 }`에 대응
|
||||
/// - 리스트 화면에서 페이지 정보와 총 건수를 함께 활용하기 위함
|
||||
class PaginatedResult<T> {
|
||||
PaginatedResult({
|
||||
required this.items,
|
||||
required this.page,
|
||||
required this.pageSize,
|
||||
required this.total,
|
||||
});
|
||||
|
||||
final List<T> items;
|
||||
final int page;
|
||||
final int pageSize;
|
||||
final int total;
|
||||
|
||||
PaginatedResult<T> copyWith({
|
||||
List<T>? items,
|
||||
int? page,
|
||||
int? pageSize,
|
||||
int? total,
|
||||
}) {
|
||||
return PaginatedResult<T>(
|
||||
items: items ?? this.items,
|
||||
page: page ?? this.page,
|
||||
pageSize: pageSize ?? this.pageSize,
|
||||
total: total ?? this.total,
|
||||
);
|
||||
}
|
||||
}
|
||||
160
lib/features/masters/customer/data/dtos/customer_dto.dart
Normal file
160
lib/features/masters/customer/data/dtos/customer_dto.dart
Normal file
@@ -0,0 +1,160 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/customer.dart';
|
||||
|
||||
class CustomerDto {
|
||||
CustomerDto({
|
||||
this.id,
|
||||
required this.customerCode,
|
||||
required this.customerName,
|
||||
this.isPartner = false,
|
||||
this.isGeneral = true,
|
||||
this.email,
|
||||
this.mobileNo,
|
||||
this.zipcode,
|
||||
this.addressDetail,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String customerCode;
|
||||
final String customerName;
|
||||
final bool isPartner;
|
||||
final bool isGeneral;
|
||||
final String? email;
|
||||
final String? mobileNo;
|
||||
final CustomerZipcodeDto? zipcode;
|
||||
final String? addressDetail;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory CustomerDto.fromJson(Map<String, dynamic> json) {
|
||||
return CustomerDto(
|
||||
id: json['id'] as int?,
|
||||
customerCode: json['customer_code'] as String,
|
||||
customerName: json['customer_name'] as String,
|
||||
isPartner: (json['is_partner'] as bool?) ?? false,
|
||||
isGeneral: (json['is_general'] as bool?) ?? true,
|
||||
email: json['email'] as String?,
|
||||
mobileNo: json['mobile_no'] as String?,
|
||||
zipcode: json['zipcode'] is Map<String, dynamic>
|
||||
? CustomerZipcodeDto.fromJson(json['zipcode'] as Map<String, dynamic>)
|
||||
: null,
|
||||
addressDetail: json['address_detail'] as String?,
|
||||
isActive: (json['is_active'] as bool?) ?? true,
|
||||
isDeleted: (json['is_deleted'] as bool?) ?? false,
|
||||
note: json['note'] as String?,
|
||||
createdAt: _parseDate(json['created_at']),
|
||||
updatedAt: _parseDate(json['updated_at']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'customer_code': customerCode,
|
||||
'customer_name': customerName,
|
||||
'is_partner': isPartner,
|
||||
'is_general': isGeneral,
|
||||
'email': email,
|
||||
'mobile_no': mobileNo,
|
||||
'zipcode': zipcode?.toJson(),
|
||||
'address_detail': addressDetail,
|
||||
'is_active': isActive,
|
||||
'is_deleted': isDeleted,
|
||||
'note': note,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
Customer toEntity() => Customer(
|
||||
id: id,
|
||||
customerCode: customerCode,
|
||||
customerName: customerName,
|
||||
isPartner: isPartner,
|
||||
isGeneral: isGeneral,
|
||||
email: email,
|
||||
mobileNo: mobileNo,
|
||||
zipcode: zipcode?.toEntity(),
|
||||
addressDetail: addressDetail,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<Customer> parsePaginated(Map<String, dynamic>? json) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(CustomerDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<Customer>(
|
||||
items: items,
|
||||
page: json?['page'] as int? ?? 1,
|
||||
pageSize: json?['page_size'] as int? ?? items.length,
|
||||
total: json?['total'] as int? ?? items.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomerZipcodeDto {
|
||||
CustomerZipcodeDto({
|
||||
required this.zipcode,
|
||||
this.sido,
|
||||
this.sigungu,
|
||||
this.roadName,
|
||||
});
|
||||
|
||||
final String zipcode;
|
||||
final String? sido;
|
||||
final String? sigungu;
|
||||
final String? roadName;
|
||||
|
||||
factory CustomerZipcodeDto.fromJson(Map<String, dynamic> json) {
|
||||
return CustomerZipcodeDto(
|
||||
zipcode: json['zipcode'] as String,
|
||||
sido: json['sido'] as String?,
|
||||
sigungu: json['sigungu'] as String?,
|
||||
roadName: json['road_name'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'zipcode': zipcode,
|
||||
'sido': sido,
|
||||
'sigungu': sigungu,
|
||||
'road_name': roadName,
|
||||
};
|
||||
}
|
||||
|
||||
CustomerZipcode toEntity() => CustomerZipcode(
|
||||
zipcode: zipcode,
|
||||
sido: sido,
|
||||
sigungu: sigungu,
|
||||
roadName: roadName,
|
||||
);
|
||||
}
|
||||
|
||||
DateTime? _parseDate(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> customerInputToJson(CustomerInput input) {
|
||||
final map = input.toPayload();
|
||||
map.removeWhere((key, value) => value == null);
|
||||
return map;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/api_client.dart';
|
||||
|
||||
import '../../domain/entities/customer.dart';
|
||||
import '../../domain/repositories/customer_repository.dart';
|
||||
import '../dtos/customer_dto.dart';
|
||||
|
||||
class CustomerRepositoryRemote implements CustomerRepository {
|
||||
CustomerRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
static const _basePath = '/customers';
|
||||
|
||||
@override
|
||||
Future<PaginatedResult<Customer>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
bool? isPartner,
|
||||
bool? isGeneral,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (query != null && query.isNotEmpty) 'q': query,
|
||||
if (isPartner != null) 'is_partner': isPartner,
|
||||
if (isGeneral != null) 'is_general': isGeneral,
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return CustomerDto.parsePaginated(response.data ?? const {});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Customer> create(CustomerInput input) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
data: customerInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return CustomerDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Customer> update(int id, CustomerInput input) async {
|
||||
final response = await _api.patch<Map<String, dynamic>>(
|
||||
'$_basePath/$id',
|
||||
data: customerInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return CustomerDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(int id) async {
|
||||
await _api.delete<void>('$_basePath/$id');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Customer> restore(int id) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
'$_basePath/$id/restore',
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return CustomerDto.fromJson(data).toEntity();
|
||||
}
|
||||
}
|
||||
122
lib/features/masters/customer/domain/entities/customer.dart
Normal file
122
lib/features/masters/customer/domain/entities/customer.dart
Normal file
@@ -0,0 +1,122 @@
|
||||
class Customer {
|
||||
Customer({
|
||||
this.id,
|
||||
required this.customerCode,
|
||||
required this.customerName,
|
||||
this.isPartner = false,
|
||||
this.isGeneral = true,
|
||||
this.email,
|
||||
this.mobileNo,
|
||||
this.zipcode,
|
||||
this.addressDetail,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String customerCode;
|
||||
final String customerName;
|
||||
final bool isPartner;
|
||||
final bool isGeneral;
|
||||
final String? email;
|
||||
final String? mobileNo;
|
||||
final CustomerZipcode? zipcode;
|
||||
final String? addressDetail;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
Customer copyWith({
|
||||
int? id,
|
||||
String? customerCode,
|
||||
String? customerName,
|
||||
bool? isPartner,
|
||||
bool? isGeneral,
|
||||
String? email,
|
||||
String? mobileNo,
|
||||
CustomerZipcode? zipcode,
|
||||
String? addressDetail,
|
||||
bool? isActive,
|
||||
bool? isDeleted,
|
||||
String? note,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return Customer(
|
||||
id: id ?? this.id,
|
||||
customerCode: customerCode ?? this.customerCode,
|
||||
customerName: customerName ?? this.customerName,
|
||||
isPartner: isPartner ?? this.isPartner,
|
||||
isGeneral: isGeneral ?? this.isGeneral,
|
||||
email: email ?? this.email,
|
||||
mobileNo: mobileNo ?? this.mobileNo,
|
||||
zipcode: zipcode ?? this.zipcode,
|
||||
addressDetail: addressDetail ?? this.addressDetail,
|
||||
isActive: isActive ?? this.isActive,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
note: note ?? this.note,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomerZipcode {
|
||||
CustomerZipcode({
|
||||
required this.zipcode,
|
||||
this.sido,
|
||||
this.sigungu,
|
||||
this.roadName,
|
||||
});
|
||||
|
||||
final String zipcode;
|
||||
final String? sido;
|
||||
final String? sigungu;
|
||||
final String? roadName;
|
||||
}
|
||||
|
||||
class CustomerInput {
|
||||
CustomerInput({
|
||||
required this.customerCode,
|
||||
required this.customerName,
|
||||
required this.isPartner,
|
||||
required this.isGeneral,
|
||||
this.email,
|
||||
this.mobileNo,
|
||||
this.zipcode,
|
||||
this.addressDetail,
|
||||
this.isActive = true,
|
||||
this.note,
|
||||
});
|
||||
|
||||
final String customerCode;
|
||||
final String customerName;
|
||||
final bool isPartner;
|
||||
final bool isGeneral;
|
||||
final String? email;
|
||||
final String? mobileNo;
|
||||
final String? zipcode;
|
||||
final String? addressDetail;
|
||||
final bool isActive;
|
||||
final String? note;
|
||||
|
||||
Map<String, dynamic> toPayload() {
|
||||
return {
|
||||
'customer_code': customerCode,
|
||||
'customer_name': customerName,
|
||||
'is_partner': isPartner,
|
||||
'is_general': isGeneral,
|
||||
'email': email,
|
||||
'mobile_no': mobileNo,
|
||||
'zipcode': zipcode,
|
||||
'address_detail': addressDetail,
|
||||
'is_active': isActive,
|
||||
'note': note,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../entities/customer.dart';
|
||||
|
||||
abstract class CustomerRepository {
|
||||
Future<PaginatedResult<Customer>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
bool? isPartner,
|
||||
bool? isGeneral,
|
||||
bool? isActive,
|
||||
});
|
||||
|
||||
Future<Customer> create(CustomerInput input);
|
||||
|
||||
Future<Customer> update(int id, CustomerInput input);
|
||||
|
||||
Future<void> delete(int id);
|
||||
|
||||
Future<Customer> restore(int id);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/customer.dart';
|
||||
import '../../domain/repositories/customer_repository.dart';
|
||||
|
||||
enum CustomerTypeFilter { all, partner, general }
|
||||
|
||||
enum CustomerStatusFilter { all, activeOnly, inactiveOnly }
|
||||
|
||||
class CustomerController extends ChangeNotifier {
|
||||
CustomerController({required CustomerRepository repository})
|
||||
: _repository = repository;
|
||||
|
||||
final CustomerRepository _repository;
|
||||
|
||||
PaginatedResult<Customer>? _result;
|
||||
bool _isLoading = false;
|
||||
bool _isSubmitting = false;
|
||||
String _query = '';
|
||||
CustomerTypeFilter _typeFilter = CustomerTypeFilter.all;
|
||||
CustomerStatusFilter _statusFilter = CustomerStatusFilter.all;
|
||||
String? _errorMessage;
|
||||
|
||||
PaginatedResult<Customer>? get result => _result;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
String get query => _query;
|
||||
CustomerTypeFilter get typeFilter => _typeFilter;
|
||||
CustomerStatusFilter get statusFilter => _statusFilter;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> fetch({int page = 1}) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
bool? isPartner;
|
||||
bool? isGeneral;
|
||||
switch (_typeFilter) {
|
||||
case CustomerTypeFilter.all:
|
||||
isPartner = null;
|
||||
isGeneral = null;
|
||||
break;
|
||||
case CustomerTypeFilter.partner:
|
||||
isPartner = true;
|
||||
isGeneral = null;
|
||||
break;
|
||||
case CustomerTypeFilter.general:
|
||||
isPartner = null;
|
||||
isGeneral = true;
|
||||
break;
|
||||
}
|
||||
|
||||
final isActive = switch (_statusFilter) {
|
||||
CustomerStatusFilter.all => null,
|
||||
CustomerStatusFilter.activeOnly => true,
|
||||
CustomerStatusFilter.inactiveOnly => false,
|
||||
};
|
||||
|
||||
final response = await _repository.list(
|
||||
page: page,
|
||||
pageSize: _result?.pageSize ?? 20,
|
||||
query: _query.isEmpty ? null : _query,
|
||||
isPartner: isPartner,
|
||||
isGeneral: isGeneral,
|
||||
isActive: isActive,
|
||||
);
|
||||
_result = response;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuery(String value) {
|
||||
_query = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateTypeFilter(CustomerTypeFilter filter) {
|
||||
_typeFilter = filter;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateStatusFilter(CustomerStatusFilter filter) {
|
||||
_statusFilter = filter;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<Customer?> create(CustomerInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final created = await _repository.create(input);
|
||||
await fetch(page: 1);
|
||||
return created;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Customer?> update(int id, CustomerInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final updated = await _repository.update(id, input);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return updated;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> delete(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
await _repository.delete(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return false;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Customer?> restore(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final restored = await _repository.restore(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return restored;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
void clearError() {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _setSubmitting(bool value) {
|
||||
_isSubmitting = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,927 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/customer.dart';
|
||||
import '../../domain/repositories/customer_repository.dart';
|
||||
import '../controllers/customer_controller.dart';
|
||||
|
||||
class CustomerPage extends StatelessWidget {
|
||||
const CustomerPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SpecPage(
|
||||
title: '회사(고객사) 관리',
|
||||
summary: '고객사 기본 정보와 연락처, 주소를 관리합니다.',
|
||||
sections: [
|
||||
SpecSection(
|
||||
title: '입력 폼',
|
||||
items: [
|
||||
'고객사코드 [Text]',
|
||||
'고객사명 [Text]',
|
||||
'유형 (파트너/일반) [Dropdown]',
|
||||
'이메일 [Text]',
|
||||
'연락처 [Text]',
|
||||
'우편번호 [검색 연동], 상세주소 [Text]',
|
||||
'사용여부 [Switch]',
|
||||
'비고 [Text]',
|
||||
],
|
||||
),
|
||||
SpecSection(
|
||||
title: '수정 폼',
|
||||
items: ['고객사코드 [ReadOnly]', '생성일시 [ReadOnly]'],
|
||||
),
|
||||
SpecSection(
|
||||
title: '테이블 리스트',
|
||||
description: '1행 예시',
|
||||
table: SpecTable(
|
||||
columns: [
|
||||
'번호',
|
||||
'고객사코드',
|
||||
'고객사명',
|
||||
'유형',
|
||||
'이메일',
|
||||
'연락처',
|
||||
'우편번호',
|
||||
'상세주소',
|
||||
'사용여부',
|
||||
'비고',
|
||||
final enabled = Environment.flag('FEATURE_CUSTOMERS_ENABLED');
|
||||
if (!enabled) {
|
||||
return const SpecPage(
|
||||
title: '회사(고객사) 관리',
|
||||
summary: '고객사 기본 정보와 연락처, 주소를 관리합니다.',
|
||||
sections: [
|
||||
SpecSection(
|
||||
title: '입력 폼',
|
||||
items: [
|
||||
'고객사코드 [Text]',
|
||||
'고객사명 [Text]',
|
||||
'유형 (파트너/일반) [Dropdown]',
|
||||
'이메일 [Text]',
|
||||
'연락처 [Text]',
|
||||
'우편번호 [검색 연동], 상세주소 [Text]',
|
||||
'사용여부 [Switch]',
|
||||
'비고 [Text]',
|
||||
],
|
||||
rows: [
|
||||
[
|
||||
'1',
|
||||
'C-001',
|
||||
'슈퍼포트 파트너',
|
||||
'파트너',
|
||||
'partner@superport.com',
|
||||
'02-1234-5678',
|
||||
'04532',
|
||||
'서울시 중구 을지로 100',
|
||||
'Y',
|
||||
'-',
|
||||
),
|
||||
SpecSection(
|
||||
title: '수정 폼',
|
||||
items: ['고객사코드 [ReadOnly]', '생성일시 [ReadOnly]'],
|
||||
),
|
||||
SpecSection(
|
||||
title: '테이블 리스트',
|
||||
description: '1행 예시',
|
||||
table: SpecTable(
|
||||
columns: [
|
||||
'번호',
|
||||
'고객사코드',
|
||||
'고객사명',
|
||||
'유형',
|
||||
'이메일',
|
||||
'연락처',
|
||||
'우편번호',
|
||||
'상세주소',
|
||||
'사용여부',
|
||||
'비고',
|
||||
],
|
||||
rows: [
|
||||
[
|
||||
'1',
|
||||
'C-001',
|
||||
'슈퍼포트 파트너',
|
||||
'파트너',
|
||||
'partner@superport.com',
|
||||
'02-1234-5678',
|
||||
'04532',
|
||||
'서울시 중구 을지로 100',
|
||||
'Y',
|
||||
'-',
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return const _CustomerEnabledPage();
|
||||
}
|
||||
}
|
||||
|
||||
class _CustomerEnabledPage extends StatefulWidget {
|
||||
const _CustomerEnabledPage();
|
||||
|
||||
@override
|
||||
State<_CustomerEnabledPage> createState() => _CustomerEnabledPageState();
|
||||
}
|
||||
|
||||
class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
late final CustomerController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
String? _lastError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = CustomerController(repository: GetIt.I<CustomerRepository>())
|
||||
..addListener(_handleControllerUpdate);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_controller.fetch();
|
||||
});
|
||||
}
|
||||
|
||||
void _handleControllerUpdate() {
|
||||
final error = _controller.errorMessage;
|
||||
if (error != null && error != _lastError && mounted) {
|
||||
_lastError = error;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(error)));
|
||||
_controller.clearError();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.removeListener(_handleControllerUpdate);
|
||||
_controller.dispose();
|
||||
_searchController.dispose();
|
||||
_searchFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) {
|
||||
final result = _controller.result;
|
||||
final customers = result?.items ?? const <Customer>[];
|
||||
final totalCount = result?.total ?? 0;
|
||||
final currentPage = result?.page ?? 1;
|
||||
final totalPages = result == null || result.pageSize == 0
|
||||
? 1
|
||||
: (result.total / result.pageSize).ceil().clamp(1, 9999);
|
||||
final hasNext = result == null
|
||||
? false
|
||||
: (result.page * result.pageSize) < result.total;
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('회사(고객사) 관리', style: theme.textTheme.h2),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'고객사 기본 정보와 연락처, 주소를 관리합니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
ShadButton(
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openCustomerForm(context),
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Text('검색 및 필터', style: theme.textTheme.h3),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 16,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 260,
|
||||
child: ShadInput(
|
||||
controller: _searchController,
|
||||
focusNode: _searchFocus,
|
||||
placeholder: const Text('고객사코드, 고객사명 검색'),
|
||||
leading: const Icon(LucideIcons.search, size: 16),
|
||||
onSubmitted: (_) => _applyFilters(),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: ShadSelect<CustomerTypeFilter>(
|
||||
key: ValueKey(_controller.typeFilter),
|
||||
initialValue: _controller.typeFilter,
|
||||
selectedOptionBuilder: (context, value) =>
|
||||
Text(_typeLabel(value)),
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
_controller.updateTypeFilter(value);
|
||||
},
|
||||
options: CustomerTypeFilter.values
|
||||
.map(
|
||||
(filter) => ShadOption(
|
||||
value: filter,
|
||||
child: Text(_typeLabel(filter)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: ShadSelect<CustomerStatusFilter>(
|
||||
key: ValueKey(_controller.statusFilter),
|
||||
initialValue: _controller.statusFilter,
|
||||
selectedOptionBuilder: (context, value) =>
|
||||
Text(_statusLabel(value)),
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
_controller.updateStatusFilter(value);
|
||||
},
|
||||
options: CustomerStatusFilter.values
|
||||
.map(
|
||||
(filter) => ShadOption(
|
||||
value: filter,
|
||||
child: Text(_statusLabel(filter)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
ShadButton.outline(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: _applyFilters,
|
||||
child: const Text('검색 적용'),
|
||||
),
|
||||
if (_searchController.text.isNotEmpty ||
|
||||
_controller.typeFilter != CustomerTypeFilter.all ||
|
||||
_controller.statusFilter !=
|
||||
CustomerStatusFilter.all)
|
||||
ShadButton.ghost(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: () {
|
||||
_searchController.clear();
|
||||
_searchFocus.requestFocus();
|
||||
_controller.updateQuery('');
|
||||
_controller.updateTypeFilter(
|
||||
CustomerTypeFilter.all,
|
||||
);
|
||||
_controller.updateStatusFilter(
|
||||
CustomerStatusFilter.all,
|
||||
);
|
||||
_controller.fetch(page: 1);
|
||||
},
|
||||
child: const Text('초기화'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('고객사 목록', style: theme.textTheme.h3),
|
||||
Text('$totalCount건', style: theme.textTheme.muted),
|
||||
],
|
||||
),
|
||||
footer: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'페이지 $currentPage / $totalPages',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || currentPage <= 1
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage - 1),
|
||||
child: const Text('이전'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || !hasNext
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage + 1),
|
||||
child: const Text('다음'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _controller.isLoading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(48),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: customers.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Text(
|
||||
'조건에 맞는 고객사가 없습니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
)
|
||||
: _CustomerTable(
|
||||
customers: customers,
|
||||
onEdit: _controller.isSubmitting
|
||||
? null
|
||||
: (customer) => _openCustomerForm(
|
||||
context,
|
||||
customer: customer,
|
||||
),
|
||||
onDelete: _controller.isSubmitting
|
||||
? null
|
||||
: _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreCustomer,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _applyFilters() {
|
||||
_controller.updateQuery(_searchController.text.trim());
|
||||
_controller.fetch(page: 1);
|
||||
}
|
||||
|
||||
String _typeLabel(CustomerTypeFilter filter) {
|
||||
switch (filter) {
|
||||
case CustomerTypeFilter.all:
|
||||
return '전체(파트너/일반)';
|
||||
case CustomerTypeFilter.partner:
|
||||
return '파트너';
|
||||
case CustomerTypeFilter.general:
|
||||
return '일반';
|
||||
}
|
||||
}
|
||||
|
||||
String _statusLabel(CustomerStatusFilter filter) {
|
||||
switch (filter) {
|
||||
case CustomerStatusFilter.all:
|
||||
return '전체(사용/미사용)';
|
||||
case CustomerStatusFilter.activeOnly:
|
||||
return '사용중';
|
||||
case CustomerStatusFilter.inactiveOnly:
|
||||
return '미사용';
|
||||
}
|
||||
}
|
||||
|
||||
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 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 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);
|
||||
|
||||
await showDialog<bool>(
|
||||
context: parentContext,
|
||||
builder: (dialogContext) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
final navigator = Navigator.of(dialogContext);
|
||||
return Dialog(
|
||||
insetPadding: const EdgeInsets.all(24),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 560),
|
||||
child: ShadCard(
|
||||
title: Text(
|
||||
isEdit ? '고객사 수정' : '고객사 등록',
|
||||
style: theme.textTheme.h3,
|
||||
),
|
||||
description: Text(
|
||||
'고객사 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
footer: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (_, isSaving, __) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
onPressed: isSaving ? null : () => navigator.pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final code = codeController.text.trim();
|
||||
final name = nameController.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;
|
||||
|
||||
codeError.value = code.isEmpty
|
||||
? '고객사코드를 입력하세요.'
|
||||
: null;
|
||||
nameError.value = name.isEmpty
|
||||
? '고객사명을 입력하세요.'
|
||||
: null;
|
||||
|
||||
if (!partner && !general) {
|
||||
general = true;
|
||||
generalNotifier.value = true;
|
||||
}
|
||||
|
||||
typeError.value = (!partner && !general)
|
||||
? '파트너/일반 중 하나 이상 선택하세요.'
|
||||
: null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
typeError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = CustomerInput(
|
||||
customerCode: code,
|
||||
customerName: name,
|
||||
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 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 ? '저장' : '등록'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
child: 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),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: partnerNotifier,
|
||||
builder: (_, partner, __) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: generalNotifier,
|
||||
builder: (_, general, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: typeError,
|
||||
builder: (_, errorText, __) {
|
||||
final onChanged = saving.value
|
||||
? null
|
||||
: (bool? value) {
|
||||
if (value == null) return;
|
||||
partnerNotifier.value = value;
|
||||
if (!value && !generalNotifier.value) {
|
||||
typeError.value =
|
||||
'파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
typeError.value = null;
|
||||
}
|
||||
};
|
||||
final onChangedGeneral = saving.value
|
||||
? 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),
|
||||
_FormField(
|
||||
label: '우편번호',
|
||||
child: ShadInput(
|
||||
controller: zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
),
|
||||
),
|
||||
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: saving.value
|
||||
? 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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
emailController.dispose();
|
||||
mobileController.dispose();
|
||||
zipcodeController.dispose();
|
||||
addressController.dispose();
|
||||
noteController.dispose();
|
||||
partnerNotifier.dispose();
|
||||
generalNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
typeError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Customer customer) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('고객사 삭제'),
|
||||
content: Text('"${customer.customerName}" 고객사를 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).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;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).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,
|
||||
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,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
171
lib/features/masters/product/data/dtos/product_dto.dart
Normal file
171
lib/features/masters/product/data/dtos/product_dto.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/product.dart';
|
||||
|
||||
class ProductDto {
|
||||
ProductDto({
|
||||
this.id,
|
||||
required this.productCode,
|
||||
required this.productName,
|
||||
this.vendor,
|
||||
this.uom,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String productCode;
|
||||
final String productName;
|
||||
final ProductVendorDto? vendor;
|
||||
final ProductUomDto? uom;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory ProductDto.fromJson(Map<String, dynamic> json) {
|
||||
return ProductDto(
|
||||
id: json['id'] as int?,
|
||||
productCode: json['product_code'] as String,
|
||||
productName: json['product_name'] as String,
|
||||
vendor: json['vendor'] is Map<String, dynamic>
|
||||
? ProductVendorDto.fromJson(json['vendor'] as Map<String, dynamic>)
|
||||
: null,
|
||||
uom: json['uom'] is Map<String, dynamic>
|
||||
? ProductUomDto.fromJson(json['uom'] as Map<String, dynamic>)
|
||||
: null,
|
||||
isActive: (json['is_active'] as bool?) ?? true,
|
||||
isDeleted: (json['is_deleted'] as bool?) ?? false,
|
||||
note: json['note'] as String?,
|
||||
createdAt: _parseDate(json['created_at']),
|
||||
updatedAt: _parseDate(json['updated_at']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'product_code': productCode,
|
||||
'product_name': productName,
|
||||
'vendor': vendor?.toJson(),
|
||||
'uom': uom?.toJson(),
|
||||
'is_active': isActive,
|
||||
'is_deleted': isDeleted,
|
||||
'note': note,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
Product toEntity() => Product(
|
||||
id: id,
|
||||
productCode: productCode,
|
||||
productName: productName,
|
||||
vendor: vendor?.toEntity(),
|
||||
uom: uom?.toEntity(),
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static ProductDto fromEntity(Product entity) => ProductDto(
|
||||
id: entity.id,
|
||||
productCode: entity.productCode,
|
||||
productName: entity.productName,
|
||||
vendor: entity.vendor == null
|
||||
? null
|
||||
: ProductVendorDto(
|
||||
id: entity.vendor!.id,
|
||||
vendorCode: entity.vendor!.vendorCode,
|
||||
vendorName: entity.vendor!.vendorName,
|
||||
),
|
||||
uom: entity.uom == null
|
||||
? null
|
||||
: ProductUomDto(id: entity.uom!.id, uomName: entity.uom!.uomName),
|
||||
isActive: entity.isActive,
|
||||
isDeleted: entity.isDeleted,
|
||||
note: entity.note,
|
||||
createdAt: entity.createdAt,
|
||||
updatedAt: entity.updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<Product> parsePaginated(Map<String, dynamic>? json) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(ProductDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<Product>(
|
||||
items: items,
|
||||
page: json?['page'] as int? ?? 1,
|
||||
pageSize: json?['page_size'] as int? ?? items.length,
|
||||
total: json?['total'] as int? ?? items.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProductVendorDto {
|
||||
ProductVendorDto({
|
||||
required this.id,
|
||||
required this.vendorCode,
|
||||
required this.vendorName,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final String vendorCode;
|
||||
final String vendorName;
|
||||
|
||||
factory ProductVendorDto.fromJson(Map<String, dynamic> json) {
|
||||
return ProductVendorDto(
|
||||
id: json['id'] as int,
|
||||
vendorCode: json['vendor_code'] as String,
|
||||
vendorName: json['vendor_name'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'id': id, 'vendor_code': vendorCode, 'vendor_name': vendorName};
|
||||
}
|
||||
|
||||
ProductVendor toEntity() =>
|
||||
ProductVendor(id: id, vendorCode: vendorCode, vendorName: vendorName);
|
||||
}
|
||||
|
||||
class ProductUomDto {
|
||||
ProductUomDto({required this.id, required this.uomName});
|
||||
|
||||
final int id;
|
||||
final String uomName;
|
||||
|
||||
factory ProductUomDto.fromJson(Map<String, dynamic> json) {
|
||||
return ProductUomDto(
|
||||
id: json['id'] as int,
|
||||
uomName: json['uom_name'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'id': id, 'uom_name': uomName};
|
||||
}
|
||||
|
||||
ProductUom toEntity() => ProductUom(id: id, uomName: uomName);
|
||||
}
|
||||
|
||||
DateTime? _parseDate(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> productInputToJson(ProductInput input) {
|
||||
final map = input.toPayload();
|
||||
map.removeWhere((key, value) => value == null);
|
||||
return map;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/api_client.dart';
|
||||
|
||||
import '../../domain/entities/product.dart';
|
||||
import '../../domain/repositories/product_repository.dart';
|
||||
import '../dtos/product_dto.dart';
|
||||
|
||||
class ProductRepositoryRemote implements ProductRepository {
|
||||
ProductRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
static const _basePath = '/products';
|
||||
|
||||
@override
|
||||
Future<PaginatedResult<Product>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
int? vendorId,
|
||||
int? uomId,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (query != null && query.isNotEmpty) 'q': query,
|
||||
if (vendorId != null) 'vendor_id': vendorId,
|
||||
if (uomId != null) 'uom_id': uomId,
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
'include': 'vendor,uom',
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return ProductDto.parsePaginated(response.data ?? const {});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Product> create(ProductInput input) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
data: productInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return ProductDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Product> update(int id, ProductInput input) async {
|
||||
final response = await _api.patch<Map<String, dynamic>>(
|
||||
'$_basePath/$id',
|
||||
data: productInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return ProductDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(int id) async {
|
||||
await _api.delete<void>('$_basePath/$id');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Product> restore(int id) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
'$_basePath/$id/restore',
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return ProductDto.fromJson(data).toEntity();
|
||||
}
|
||||
}
|
||||
99
lib/features/masters/product/domain/entities/product.dart
Normal file
99
lib/features/masters/product/domain/entities/product.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
class Product {
|
||||
Product({
|
||||
this.id,
|
||||
required this.productCode,
|
||||
required this.productName,
|
||||
this.vendor,
|
||||
this.uom,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String productCode;
|
||||
final String productName;
|
||||
final ProductVendor? vendor;
|
||||
final ProductUom? uom;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
Product copyWith({
|
||||
int? id,
|
||||
String? productCode,
|
||||
String? productName,
|
||||
ProductVendor? vendor,
|
||||
ProductUom? uom,
|
||||
bool? isActive,
|
||||
bool? isDeleted,
|
||||
String? note,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return Product(
|
||||
id: id ?? this.id,
|
||||
productCode: productCode ?? this.productCode,
|
||||
productName: productName ?? this.productName,
|
||||
vendor: vendor ?? this.vendor,
|
||||
uom: uom ?? this.uom,
|
||||
isActive: isActive ?? this.isActive,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
note: note ?? this.note,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProductVendor {
|
||||
ProductVendor({
|
||||
required this.id,
|
||||
required this.vendorCode,
|
||||
required this.vendorName,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final String vendorCode;
|
||||
final String vendorName;
|
||||
}
|
||||
|
||||
class ProductUom {
|
||||
ProductUom({required this.id, required this.uomName});
|
||||
|
||||
final int id;
|
||||
final String uomName;
|
||||
}
|
||||
|
||||
class ProductInput {
|
||||
ProductInput({
|
||||
required this.productCode,
|
||||
required this.productName,
|
||||
required this.vendorId,
|
||||
required this.uomId,
|
||||
this.isActive = true,
|
||||
this.note,
|
||||
});
|
||||
|
||||
final String productCode;
|
||||
final String productName;
|
||||
final int vendorId;
|
||||
final int uomId;
|
||||
final bool isActive;
|
||||
final String? note;
|
||||
|
||||
Map<String, dynamic> toPayload() {
|
||||
return {
|
||||
'product_code': productCode,
|
||||
'product_name': productName,
|
||||
'vendor_id': vendorId,
|
||||
'uom_id': uomId,
|
||||
'is_active': isActive,
|
||||
'note': note,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../entities/product.dart';
|
||||
|
||||
abstract class ProductRepository {
|
||||
Future<PaginatedResult<Product>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
int? vendorId,
|
||||
int? uomId,
|
||||
bool? isActive,
|
||||
});
|
||||
|
||||
Future<Product> create(ProductInput input);
|
||||
|
||||
Future<Product> update(int id, ProductInput input);
|
||||
|
||||
Future<void> delete(int id);
|
||||
|
||||
Future<Product> restore(int id);
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
import '../../../vendor/domain/repositories/vendor_repository.dart';
|
||||
import '../../../uom/domain/entities/uom.dart';
|
||||
import '../../../uom/domain/repositories/uom_repository.dart';
|
||||
import '../../domain/entities/product.dart';
|
||||
import '../../domain/repositories/product_repository.dart';
|
||||
|
||||
enum ProductStatusFilter { all, activeOnly, inactiveOnly }
|
||||
|
||||
class ProductController extends ChangeNotifier {
|
||||
ProductController({
|
||||
required ProductRepository productRepository,
|
||||
required VendorRepository vendorRepository,
|
||||
required UomRepository uomRepository,
|
||||
}) : _productRepository = productRepository,
|
||||
_vendorRepository = vendorRepository,
|
||||
_uomRepository = uomRepository;
|
||||
|
||||
final ProductRepository _productRepository;
|
||||
final VendorRepository _vendorRepository;
|
||||
final UomRepository _uomRepository;
|
||||
|
||||
PaginatedResult<Product>? _result;
|
||||
bool _isLoading = false;
|
||||
bool _isSubmitting = false;
|
||||
bool _isLoadingLookups = false;
|
||||
String _query = '';
|
||||
int? _vendorFilter;
|
||||
int? _uomFilter;
|
||||
ProductStatusFilter _statusFilter = ProductStatusFilter.all;
|
||||
String? _errorMessage;
|
||||
|
||||
List<Vendor> _vendorOptions = const [];
|
||||
List<Uom> _uomOptions = const [];
|
||||
|
||||
PaginatedResult<Product>? get result => _result;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
bool get isLoadingLookups => _isLoadingLookups;
|
||||
String get query => _query;
|
||||
int? get vendorFilter => _vendorFilter;
|
||||
int? get uomFilter => _uomFilter;
|
||||
ProductStatusFilter get statusFilter => _statusFilter;
|
||||
String? get errorMessage => _errorMessage;
|
||||
List<Vendor> get vendorOptions => _vendorOptions;
|
||||
List<Uom> get uomOptions => _uomOptions;
|
||||
|
||||
Future<void> fetch({int page = 1}) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
final isActive = switch (_statusFilter) {
|
||||
ProductStatusFilter.all => null,
|
||||
ProductStatusFilter.activeOnly => true,
|
||||
ProductStatusFilter.inactiveOnly => false,
|
||||
};
|
||||
final response = await _productRepository.list(
|
||||
page: page,
|
||||
pageSize: _result?.pageSize ?? 20,
|
||||
query: _query.isEmpty ? null : _query,
|
||||
vendorId: _vendorFilter,
|
||||
uomId: _uomFilter,
|
||||
isActive: isActive,
|
||||
);
|
||||
_result = response;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadLookups() async {
|
||||
_isLoadingLookups = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
final vendorResult = await _vendorRepository.list(page: 1, pageSize: 100);
|
||||
final uomResult = await _uomRepository.list(page: 1, pageSize: 100);
|
||||
_vendorOptions = vendorResult.items;
|
||||
_uomOptions = uomResult.items;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
} finally {
|
||||
_isLoadingLookups = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuery(String value) {
|
||||
_query = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateVendorFilter(int? vendorId) {
|
||||
_vendorFilter = vendorId;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateUomFilter(int? uomId) {
|
||||
_uomFilter = uomId;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateStatusFilter(ProductStatusFilter filter) {
|
||||
_statusFilter = filter;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<Product?> create(ProductInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final created = await _productRepository.create(input);
|
||||
await fetch(page: 1);
|
||||
return created;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Product?> update(int id, ProductInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final updated = await _productRepository.update(id, input);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return updated;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> delete(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
await _productRepository.delete(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return false;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Product?> restore(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final restored = await _productRepository.restore(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return restored;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
void clearError() {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _setSubmitting(bool value) {
|
||||
_isSubmitting = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,937 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../../uom/domain/entities/uom.dart';
|
||||
import '../../../uom/domain/repositories/uom_repository.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
import '../../../vendor/domain/repositories/vendor_repository.dart';
|
||||
import '../../domain/entities/product.dart';
|
||||
import '../../domain/repositories/product_repository.dart';
|
||||
import '../controllers/product_controller.dart';
|
||||
|
||||
class ProductPage extends StatelessWidget {
|
||||
const ProductPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SpecPage(
|
||||
title: '장비 모델(제품) 관리',
|
||||
summary: '제품 코드, 제조사, 단위 정보를 유지하여 재고 라인과 연계합니다.',
|
||||
sections: [
|
||||
SpecSection(
|
||||
title: '입력 폼',
|
||||
items: [
|
||||
'제품코드 [Text]',
|
||||
'제품명 [Text]',
|
||||
'제조사 [Dropdown]',
|
||||
'단위 [Dropdown]',
|
||||
'사용여부 [Switch]',
|
||||
'비고 [Text]',
|
||||
],
|
||||
),
|
||||
SpecSection(
|
||||
title: '수정 폼',
|
||||
items: ['제품코드 [ReadOnly]', '생성일시 [ReadOnly]'],
|
||||
),
|
||||
SpecSection(
|
||||
title: '테이블 리스트',
|
||||
description: '1행 예시',
|
||||
table: SpecTable(
|
||||
columns: ['번호', '제품코드', '제품명', '제조사', '단위', '사용여부', '비고', '변경일시'],
|
||||
rows: [
|
||||
[
|
||||
'1',
|
||||
'P-100',
|
||||
'XR-5000',
|
||||
'슈퍼벤더',
|
||||
'EA',
|
||||
'Y',
|
||||
'-',
|
||||
'2024-03-01 10:00',
|
||||
final enabled = Environment.flag('FEATURE_PRODUCTS_ENABLED');
|
||||
if (!enabled) {
|
||||
return const SpecPage(
|
||||
title: '장비 모델(제품) 관리',
|
||||
summary: '제품 코드, 제조사, 단위 정보를 유지하여 재고 라인과 연계합니다.',
|
||||
sections: [
|
||||
SpecSection(
|
||||
title: '입력 폼',
|
||||
items: [
|
||||
'제품코드 [Text]',
|
||||
'제품명 [Text]',
|
||||
'제조사 [Dropdown]',
|
||||
'단위 [Dropdown]',
|
||||
'사용여부 [Switch]',
|
||||
'비고 [Text]',
|
||||
],
|
||||
),
|
||||
SpecSection(
|
||||
title: '수정 폼',
|
||||
items: ['제품코드 [ReadOnly]', '생성일시 [ReadOnly]'],
|
||||
),
|
||||
SpecSection(
|
||||
title: '테이블 리스트',
|
||||
description: '1행 예시',
|
||||
table: SpecTable(
|
||||
columns: ['번호', '제품코드', '제품명', '제조사', '단위', '사용여부', '비고', '변경일시'],
|
||||
rows: [
|
||||
[
|
||||
'1',
|
||||
'P-100',
|
||||
'XR-5000',
|
||||
'슈퍼벤더',
|
||||
'EA',
|
||||
'Y',
|
||||
'-',
|
||||
'2024-03-01 10:00',
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return const _ProductEnabledPage();
|
||||
}
|
||||
}
|
||||
|
||||
class _ProductEnabledPage extends StatefulWidget {
|
||||
const _ProductEnabledPage();
|
||||
|
||||
@override
|
||||
State<_ProductEnabledPage> createState() => _ProductEnabledPageState();
|
||||
}
|
||||
|
||||
class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
late final ProductController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
bool _lookupsLoaded = false;
|
||||
String? _lastError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = ProductController(
|
||||
productRepository: GetIt.I<ProductRepository>(),
|
||||
vendorRepository: GetIt.I<VendorRepository>(),
|
||||
uomRepository: GetIt.I<UomRepository>(),
|
||||
)..addListener(_handleControllerUpdate);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await Future.wait([_controller.loadLookups(), _controller.fetch()]);
|
||||
setState(() {
|
||||
_lookupsLoaded = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _handleControllerUpdate() {
|
||||
final error = _controller.errorMessage;
|
||||
if (error != null && error != _lastError && mounted) {
|
||||
_lastError = error;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(error)));
|
||||
_controller.clearError();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.removeListener(_handleControllerUpdate);
|
||||
_controller.dispose();
|
||||
_searchController.dispose();
|
||||
_searchFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) {
|
||||
final result = _controller.result;
|
||||
final products = result?.items ?? const <Product>[];
|
||||
final totalCount = result?.total ?? 0;
|
||||
final currentPage = result?.page ?? 1;
|
||||
final totalPages = result == null || result.pageSize == 0
|
||||
? 1
|
||||
: (result.total / result.pageSize).ceil().clamp(1, 9999);
|
||||
final hasNext = result == null
|
||||
? false
|
||||
: (result.page * result.pageSize) < result.total;
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('장비 모델(제품) 관리', style: theme.textTheme.h2),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'제품코드, 제조사, 단위 정보를 관리합니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
ShadButton(
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openProductForm(context),
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Text('검색 및 필터', style: theme.textTheme.h3),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 16,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 260,
|
||||
child: ShadInput(
|
||||
controller: _searchController,
|
||||
focusNode: _searchFocus,
|
||||
placeholder: const Text('제품코드, 제품명 검색'),
|
||||
leading: const Icon(LucideIcons.search, size: 16),
|
||||
onSubmitted: (_) => _applyFilters(),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 220,
|
||||
child: ShadSelect<int?>(
|
||||
key: ValueKey(_controller.vendorFilter),
|
||||
initialValue: _controller.vendorFilter,
|
||||
placeholder: const Text('제조사 전체'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('제조사 전체');
|
||||
}
|
||||
final vendor = _controller.vendorOptions
|
||||
.firstWhere(
|
||||
(v) => v.id == value,
|
||||
orElse: () => Vendor(
|
||||
id: value,
|
||||
vendorCode: '',
|
||||
vendorName: '',
|
||||
),
|
||||
);
|
||||
return Text(vendor.vendorName);
|
||||
},
|
||||
onChanged: (value) {
|
||||
_controller.updateVendorFilter(value);
|
||||
},
|
||||
options: [
|
||||
const ShadOption<int?>(
|
||||
value: null,
|
||||
child: Text('제조사 전체'),
|
||||
),
|
||||
..._controller.vendorOptions.map(
|
||||
(vendor) => ShadOption<int?>(
|
||||
value: vendor.id,
|
||||
child: Text(vendor.vendorName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 220,
|
||||
child: ShadSelect<int?>(
|
||||
key: ValueKey(_controller.uomFilter),
|
||||
initialValue: _controller.uomFilter,
|
||||
placeholder: const Text('단위 전체'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('단위 전체');
|
||||
}
|
||||
final uom = _controller.uomOptions.firstWhere(
|
||||
(u) => u.id == value,
|
||||
orElse: () => Uom(id: value, uomName: ''),
|
||||
);
|
||||
return Text(uom.uomName);
|
||||
},
|
||||
onChanged: (value) {
|
||||
_controller.updateUomFilter(value);
|
||||
},
|
||||
options: [
|
||||
const ShadOption<int?>(
|
||||
value: null,
|
||||
child: Text('단위 전체'),
|
||||
),
|
||||
..._controller.uomOptions.map(
|
||||
(uom) => ShadOption<int?>(
|
||||
value: uom.id,
|
||||
child: Text(uom.uomName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: ShadSelect<ProductStatusFilter>(
|
||||
key: ValueKey(_controller.statusFilter),
|
||||
initialValue: _controller.statusFilter,
|
||||
selectedOptionBuilder: (context, filter) =>
|
||||
Text(_statusLabel(filter)),
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
_controller.updateStatusFilter(value);
|
||||
},
|
||||
options: ProductStatusFilter.values
|
||||
.map(
|
||||
(filter) => ShadOption(
|
||||
value: filter,
|
||||
child: Text(_statusLabel(filter)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
ShadButton.outline(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: _applyFilters,
|
||||
child: const Text('검색 적용'),
|
||||
),
|
||||
if (_searchController.text.isNotEmpty ||
|
||||
_controller.vendorFilter != null ||
|
||||
_controller.uomFilter != null ||
|
||||
_controller.statusFilter != ProductStatusFilter.all)
|
||||
ShadButton.ghost(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: () {
|
||||
_searchController.clear();
|
||||
_searchFocus.requestFocus();
|
||||
_controller.updateQuery('');
|
||||
_controller.updateVendorFilter(null);
|
||||
_controller.updateUomFilter(null);
|
||||
_controller.updateStatusFilter(
|
||||
ProductStatusFilter.all,
|
||||
);
|
||||
_controller.fetch(page: 1);
|
||||
},
|
||||
child: const Text('초기화'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('제품 목록', style: theme.textTheme.h3),
|
||||
Text('$totalCount건', style: theme.textTheme.muted),
|
||||
],
|
||||
),
|
||||
footer: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'페이지 $currentPage / $totalPages',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || currentPage <= 1
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage - 1),
|
||||
child: const Text('이전'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || !hasNext
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage + 1),
|
||||
child: const Text('다음'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _controller.isLoading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(48),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: products.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Text(
|
||||
'조건에 맞는 제품이 없습니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
)
|
||||
: _ProductTable(
|
||||
products: products,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
? null
|
||||
: (product) =>
|
||||
_openProductForm(context, product: product),
|
||||
onDelete: _controller.isSubmitting
|
||||
? null
|
||||
: _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreProduct,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _applyFilters() {
|
||||
_controller.updateQuery(_searchController.text.trim());
|
||||
_controller.fetch(page: 1);
|
||||
}
|
||||
|
||||
String _statusLabel(ProductStatusFilter filter) {
|
||||
switch (filter) {
|
||||
case ProductStatusFilter.all:
|
||||
return '전체(사용/미사용)';
|
||||
case ProductStatusFilter.activeOnly:
|
||||
return '사용중';
|
||||
case ProductStatusFilter.inactiveOnly:
|
||||
return '미사용';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openProductForm(
|
||||
BuildContext context, {
|
||||
Product? product,
|
||||
}) async {
|
||||
final existing = product;
|
||||
final isEdit = existing != null;
|
||||
final productId = existing?.id;
|
||||
if (isEdit && productId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_lookupsLoaded) {
|
||||
_showSnack('선택 목록을 불러오는 중입니다. 잠시 후 다시 시도하세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
final parentContext = context;
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existing?.productCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existing?.productName ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(text: existing?.note ?? '');
|
||||
final vendorNotifier = ValueNotifier<int?>(existing?.vendor?.id);
|
||||
final uomNotifier = ValueNotifier<int?>(existing?.uom?.id);
|
||||
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final vendorError = ValueNotifier<String?>(null);
|
||||
final uomError = ValueNotifier<String?>(null);
|
||||
|
||||
await showDialog<bool>(
|
||||
context: parentContext,
|
||||
builder: (dialogContext) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
final navigator = Navigator.of(dialogContext);
|
||||
return Dialog(
|
||||
insetPadding: const EdgeInsets.all(24),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 560),
|
||||
child: ShadCard(
|
||||
title: Text(
|
||||
isEdit ? '제품 수정' : '제품 등록',
|
||||
style: theme.textTheme.h3,
|
||||
),
|
||||
description: Text(
|
||||
'제품 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
footer: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (_, isSaving, __) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
onPressed: isSaving ? null : () => navigator.pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final code = codeController.text.trim();
|
||||
final name = nameController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
final vendorId = vendorNotifier.value;
|
||||
final uomId = uomNotifier.value;
|
||||
|
||||
codeError.value = code.isEmpty
|
||||
? '제품코드를 입력하세요.'
|
||||
: null;
|
||||
nameError.value = name.isEmpty
|
||||
? '제품명을 입력하세요.'
|
||||
: null;
|
||||
vendorError.value = vendorId == null
|
||||
? '제조사를 선택하세요.'
|
||||
: null;
|
||||
uomError.value = uomId == null
|
||||
? '단위를 선택하세요.'
|
||||
: null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
vendorError.value != null ||
|
||||
uomError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = ProductInput(
|
||||
productCode: code,
|
||||
productName: name,
|
||||
vendorId: vendorId!,
|
||||
uomId: uomId!,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(
|
||||
productId!,
|
||||
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 ? '저장' : '등록'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
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),
|
||||
ValueListenableBuilder<int?>(
|
||||
valueListenable: vendorNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: vendorError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '제조사',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int?>(
|
||||
initialValue: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) {
|
||||
vendorNotifier.value = next;
|
||||
vendorError.value = null;
|
||||
},
|
||||
options: _controller.vendorOptions
|
||||
.map(
|
||||
(vendor) => ShadOption<int?>(
|
||||
value: vendor.id,
|
||||
child: Text(vendor.vendorName),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
placeholder: const Text('제조사를 선택하세요'),
|
||||
selectedOptionBuilder: (context, selected) {
|
||||
if (selected == null) {
|
||||
return const Text('제조사를 선택하세요');
|
||||
}
|
||||
final vendor = _controller.vendorOptions
|
||||
.firstWhere(
|
||||
(v) => v.id == selected,
|
||||
orElse: () => Vendor(
|
||||
id: selected,
|
||||
vendorCode: '',
|
||||
vendorName: '',
|
||||
),
|
||||
);
|
||||
return Text(vendor.vendorName);
|
||||
},
|
||||
),
|
||||
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<int?>(
|
||||
valueListenable: uomNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: uomError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '단위',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int?>(
|
||||
initialValue: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) {
|
||||
uomNotifier.value = next;
|
||||
uomError.value = null;
|
||||
},
|
||||
options: _controller.uomOptions
|
||||
.map(
|
||||
(uom) => ShadOption<int?>(
|
||||
value: uom.id,
|
||||
child: Text(uom.uomName),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
placeholder: const Text('단위를 선택하세요'),
|
||||
selectedOptionBuilder: (context, selected) {
|
||||
if (selected == null) {
|
||||
return const Text('단위를 선택하세요');
|
||||
}
|
||||
final uom = _controller.uomOptions
|
||||
.firstWhere(
|
||||
(u) => u.id == selected,
|
||||
orElse: () =>
|
||||
Uom(id: selected, uomName: ''),
|
||||
);
|
||||
return Text(uom.uomName);
|
||||
},
|
||||
),
|
||||
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<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (isEdit) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existing.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existing.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
noteController.dispose();
|
||||
vendorNotifier.dispose();
|
||||
uomNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
vendorError.dispose();
|
||||
uomError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Product product) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('제품 삭제'),
|
||||
content: Text('"${product.productName}" 제품을 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (confirmed == true && product.id != null) {
|
||||
final success = await _controller.delete(product.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('제품을 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreProduct(Product product) async {
|
||||
if (product.id == null) return;
|
||||
final restored = await _controller.restore(product.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('제품을 복구했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
void _showSnack(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) return '-';
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _ProductTable extends StatelessWidget {
|
||||
const _ProductTable({
|
||||
required this.products,
|
||||
required this.dateFormat,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final List<Product> products;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(Product product)? onEdit;
|
||||
final void Function(Product product)? onDelete;
|
||||
final void Function(Product product)? onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final header = [
|
||||
'ID',
|
||||
'제품코드',
|
||||
'제품명',
|
||||
'제조사',
|
||||
'단위',
|
||||
'사용',
|
||||
'삭제',
|
||||
'비고',
|
||||
'변경일시',
|
||||
'동작',
|
||||
].map((text) => ShadTableCell.header(child: Text(text))).toList();
|
||||
|
||||
final rows = products.map((product) {
|
||||
return [
|
||||
product.id?.toString() ?? '-',
|
||||
product.productCode,
|
||||
product.productName,
|
||||
product.vendor?.vendorName ?? '-',
|
||||
product.uom?.uomName ?? '-',
|
||||
product.isActive ? 'Y' : 'N',
|
||||
product.isDeleted ? 'Y' : '-',
|
||||
product.note?.isEmpty ?? true ? '-' : product.note!,
|
||||
product.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.updatedAt!.toLocal()),
|
||||
].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!(product),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
product.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(product),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(product),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (products.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) => index == 9
|
||||
? 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,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
70
lib/features/masters/uom/data/dtos/uom_dto.dart
Normal file
70
lib/features/masters/uom/data/dtos/uom_dto.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/uom.dart';
|
||||
|
||||
class UomDto {
|
||||
UomDto({
|
||||
this.id,
|
||||
required this.uomName,
|
||||
this.isDefault = false,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String uomName;
|
||||
final bool isDefault;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory UomDto.fromJson(Map<String, dynamic> json) {
|
||||
return UomDto(
|
||||
id: json['id'] as int?,
|
||||
uomName: json['uom_name'] as String,
|
||||
isDefault: (json['is_default'] as bool?) ?? false,
|
||||
isActive: (json['is_active'] as bool?) ?? true,
|
||||
isDeleted: (json['is_deleted'] as bool?) ?? false,
|
||||
note: json['note'] as String?,
|
||||
createdAt: _parseDate(json['created_at']),
|
||||
updatedAt: _parseDate(json['updated_at']),
|
||||
);
|
||||
}
|
||||
|
||||
Uom toEntity() => Uom(
|
||||
id: id,
|
||||
uomName: uomName,
|
||||
isDefault: isDefault,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<Uom> parsePaginated(Map<String, dynamic>? json) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(UomDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<Uom>(
|
||||
items: items,
|
||||
page: json?['page'] as int? ?? 1,
|
||||
pageSize: json?['page_size'] as int? ?? items.length,
|
||||
total: json?['total'] as int? ?? items.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
DateTime? _parseDate(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/api_client.dart';
|
||||
|
||||
import '../../domain/entities/uom.dart';
|
||||
import '../../domain/repositories/uom_repository.dart';
|
||||
import '../dtos/uom_dto.dart';
|
||||
|
||||
class UomRepositoryRemote implements UomRepository {
|
||||
UomRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
static const _basePath = '/uoms';
|
||||
|
||||
@override
|
||||
Future<PaginatedResult<Uom>> list({
|
||||
int page = 1,
|
||||
int pageSize = 50,
|
||||
String? query,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (query != null && query.isNotEmpty) 'q': query,
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return UomDto.parsePaginated(response.data ?? const {});
|
||||
}
|
||||
}
|
||||
43
lib/features/masters/uom/domain/entities/uom.dart
Normal file
43
lib/features/masters/uom/domain/entities/uom.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
class Uom {
|
||||
Uom({
|
||||
this.id,
|
||||
required this.uomName,
|
||||
this.isDefault = false,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String uomName;
|
||||
final bool isDefault;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
Uom copyWith({
|
||||
int? id,
|
||||
String? uomName,
|
||||
bool? isDefault,
|
||||
bool? isActive,
|
||||
bool? isDeleted,
|
||||
String? note,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return Uom(
|
||||
id: id ?? this.id,
|
||||
uomName: uomName ?? this.uomName,
|
||||
isDefault: isDefault ?? this.isDefault,
|
||||
isActive: isActive ?? this.isActive,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
note: note ?? this.note,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../entities/uom.dart';
|
||||
|
||||
/// 단위(UOM) 조회 리포지토리
|
||||
abstract class UomRepository {
|
||||
Future<PaginatedResult<Uom>> list({
|
||||
int page = 1,
|
||||
int pageSize = 50,
|
||||
String? query,
|
||||
bool? isActive,
|
||||
});
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/vendor.dart';
|
||||
|
||||
/// 벤더 DTO (JSON 직렬화/역직렬화)
|
||||
@@ -49,26 +51,40 @@ class VendorDto {
|
||||
}
|
||||
|
||||
Vendor toEntity() => Vendor(
|
||||
id: id,
|
||||
vendorCode: vendorCode,
|
||||
vendorName: vendorName,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
id: id,
|
||||
vendorCode: vendorCode,
|
||||
vendorName: vendorName,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static VendorDto fromEntity(Vendor entity) => VendorDto(
|
||||
id: entity.id,
|
||||
vendorCode: entity.vendorCode,
|
||||
vendorName: entity.vendorName,
|
||||
isActive: entity.isActive,
|
||||
isDeleted: entity.isDeleted,
|
||||
note: entity.note,
|
||||
createdAt: entity.createdAt,
|
||||
updatedAt: entity.updatedAt,
|
||||
);
|
||||
id: entity.id,
|
||||
vendorCode: entity.vendorCode,
|
||||
vendorName: entity.vendorName,
|
||||
isActive: entity.isActive,
|
||||
isDeleted: entity.isDeleted,
|
||||
note: entity.note,
|
||||
createdAt: entity.createdAt,
|
||||
updatedAt: entity.updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<Vendor> parsePaginated(Map<String, dynamic>? json) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(VendorDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<Vendor>(
|
||||
items: items,
|
||||
page: json?['page'] as int? ?? 1,
|
||||
pageSize: json?['page_size'] as int? ?? items.length,
|
||||
total: json?['total'] as int? ?? items.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
DateTime? _parseDate(Object? value) {
|
||||
@@ -78,3 +94,8 @@ DateTime? _parseDate(Object? value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> vendorInputToJson(VendorInput input) {
|
||||
final map = input.toPayload();
|
||||
map.removeWhere((key, value) => value == null);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/api_client.dart';
|
||||
|
||||
import '../../domain/entities/vendor.dart';
|
||||
import '../../domain/repositories/vendor_repository.dart';
|
||||
import '../dtos/vendor_dto.dart';
|
||||
import '../../../../../core/network/api_client.dart';
|
||||
|
||||
/// 원격 구현체: 공통 ApiClient(Dio) 사용
|
||||
class VendorRepositoryRemote implements VendorRepository {
|
||||
@@ -14,57 +16,60 @@ class VendorRepositoryRemote implements VendorRepository {
|
||||
static const _basePath = '/vendors'; // TODO: 백엔드 경로 확정 시 수정
|
||||
|
||||
@override
|
||||
Future<List<Vendor>> list({
|
||||
Future<PaginatedResult<Vendor>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
bool includeInactive = true,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
final response = await _api.get<List<dynamic>>(
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (query != null && query.isNotEmpty) 'q': query,
|
||||
if (includeInactive) 'include': 'inactive',
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = response.data ?? [];
|
||||
return data
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map((e) => VendorDto.fromJson(e).toEntity())
|
||||
.toList();
|
||||
final map = response.data ?? const <String, dynamic>{};
|
||||
return VendorDto.parsePaginated(map);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Vendor> create(Vendor vendor) async {
|
||||
final dto = VendorDto.fromEntity(vendor);
|
||||
Future<Vendor> create(VendorInput input) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
data: dto.toJson(),
|
||||
data: vendorInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return VendorDto.fromJson(response.data ?? {}).toEntity();
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return VendorDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Vendor> update(Vendor vendor) async {
|
||||
if (vendor.id == null) {
|
||||
throw ArgumentError('id가 없는 엔티티는 수정할 수 없습니다.');
|
||||
}
|
||||
final dto = VendorDto.fromEntity(vendor);
|
||||
Future<Vendor> update(int id, VendorInput input) async {
|
||||
final response = await _api.patch<Map<String, dynamic>>(
|
||||
'$_basePath/${vendor.id}',
|
||||
data: dto.toJson(),
|
||||
'$_basePath/$id',
|
||||
data: vendorInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return VendorDto.fromJson(response.data ?? {}).toEntity();
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return VendorDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(int id) async {
|
||||
await _api.delete<void>('$_basePath/$id');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Vendor> restore(int id) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
'$_basePath/$id/restore',
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return VendorDto.fromJson(data).toEntity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,3 +59,28 @@ class Vendor {
|
||||
}
|
||||
}
|
||||
|
||||
/// 벤더 신규/수정 입력 모델
|
||||
///
|
||||
/// - code는 생성 시 필수, 수정 시 읽기 전용이지만 API 전송을 위해 포함
|
||||
class VendorInput {
|
||||
VendorInput({
|
||||
required this.vendorCode,
|
||||
required this.vendorName,
|
||||
this.isActive = true,
|
||||
this.note,
|
||||
});
|
||||
|
||||
final String vendorCode;
|
||||
final String vendorName;
|
||||
final bool isActive;
|
||||
final String? note;
|
||||
|
||||
Map<String, dynamic> toPayload() {
|
||||
return {
|
||||
'vendor_code': vendorCode,
|
||||
'vendor_name': vendorName,
|
||||
'is_active': isActive,
|
||||
'note': note,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../entities/vendor.dart';
|
||||
|
||||
/// 벤더 리포지토리 인터페이스
|
||||
@@ -8,20 +10,22 @@ abstract class VendorRepository {
|
||||
/// 벤더 목록 조회
|
||||
///
|
||||
/// - 표준 쿼리 파라미터: page, page_size, q, include
|
||||
Future<List<Vendor>> list({
|
||||
Future<PaginatedResult<Vendor>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
bool includeInactive = true,
|
||||
bool? isActive,
|
||||
});
|
||||
|
||||
/// 벤더 생성
|
||||
Future<Vendor> create(Vendor vendor);
|
||||
Future<Vendor> create(VendorInput input);
|
||||
|
||||
/// 벤더 수정 (부분 업데이트 포함)
|
||||
Future<Vendor> update(Vendor vendor);
|
||||
Future<Vendor> update(int id, VendorInput input);
|
||||
|
||||
/// 벤더 소프트 삭제
|
||||
Future<void> delete(int id);
|
||||
}
|
||||
|
||||
/// 벤더 복구 (소프트 삭제 해제)
|
||||
Future<Vendor> restore(int id);
|
||||
}
|
||||
|
||||
142
lib/features/masters/vendor/presentation/controllers/vendor_controller.dart
vendored
Normal file
142
lib/features/masters/vendor/presentation/controllers/vendor_controller.dart
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/vendor.dart';
|
||||
import '../../domain/repositories/vendor_repository.dart';
|
||||
|
||||
enum VendorStatusFilter { all, activeOnly, inactiveOnly }
|
||||
|
||||
/// 벤더 화면 상태 컨트롤러
|
||||
///
|
||||
/// - 목록/검색/필터/페이지 상태를 관리한다.
|
||||
/// - 생성/수정/삭제/복구 요청을 래핑하여 UI에 알린다.
|
||||
class VendorController extends ChangeNotifier {
|
||||
VendorController({required VendorRepository repository})
|
||||
: _repository = repository;
|
||||
|
||||
final VendorRepository _repository;
|
||||
|
||||
PaginatedResult<Vendor>? _result;
|
||||
bool _isLoading = false;
|
||||
bool _isSubmitting = false;
|
||||
String _query = '';
|
||||
VendorStatusFilter _statusFilter = VendorStatusFilter.all;
|
||||
String? _errorMessage;
|
||||
|
||||
PaginatedResult<Vendor>? get result => _result;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
String get query => _query;
|
||||
VendorStatusFilter get statusFilter => _statusFilter;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
/// 목록 갱신
|
||||
Future<void> fetch({int page = 1}) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
final isActive = switch (_statusFilter) {
|
||||
VendorStatusFilter.all => null,
|
||||
VendorStatusFilter.activeOnly => true,
|
||||
VendorStatusFilter.inactiveOnly => false,
|
||||
};
|
||||
final response = await _repository.list(
|
||||
page: page,
|
||||
pageSize: _result?.pageSize ?? 20,
|
||||
query: _query.isEmpty ? null : _query,
|
||||
isActive: isActive,
|
||||
);
|
||||
_result = response;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuery(String value) {
|
||||
_query = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateStatusFilter(VendorStatusFilter filter) {
|
||||
_statusFilter = filter;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 신규 등록
|
||||
Future<Vendor?> create(VendorInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final vendor = await _repository.create(input);
|
||||
await fetch(page: 1);
|
||||
return vendor;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// 수정
|
||||
Future<Vendor?> update(int id, VendorInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final vendor = await _repository.update(id, input);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return vendor;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// 삭제 (소프트)
|
||||
Future<bool> delete(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
await _repository.delete(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return false;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// 복구
|
||||
Future<Vendor?> restore(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final vendor = await _repository.restore(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return vendor;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
void clearError() {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _setSubmitting(bool value) {
|
||||
_isSubmitting = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
import '../../../vendor/domain/repositories/vendor_repository.dart';
|
||||
import '../controllers/vendor_controller.dart';
|
||||
|
||||
class VendorPage extends StatelessWidget {
|
||||
const VendorPage({super.key});
|
||||
@@ -65,111 +66,630 @@ class _VendorEnabledPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
final _repo = GetIt.I<VendorRepository>();
|
||||
final _loading = ValueNotifier(false);
|
||||
final _vendors = ValueNotifier<List<Vendor>>([]);
|
||||
late final VendorController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
String? _lastError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = VendorController(repository: GetIt.I<VendorRepository>());
|
||||
_controller.addListener(_onControllerChanged);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _controller.fetch());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_loading.dispose();
|
||||
_vendors.dispose();
|
||||
_controller.removeListener(_onControllerChanged);
|
||||
_controller.dispose();
|
||||
_searchController.dispose();
|
||||
_searchFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
_loading.value = true;
|
||||
try {
|
||||
final list = await _repo.list(page: 1, pageSize: 50);
|
||||
_vendors.value = list;
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('벤더 조회 실패: $e')),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
_loading.value = false;
|
||||
void _onControllerChanged() {
|
||||
final error = _controller.errorMessage;
|
||||
if (error != null && error != _lastError && mounted) {
|
||||
_lastError = error;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(error)));
|
||||
_controller.clearError();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) {
|
||||
final result = _controller.result;
|
||||
final vendors = result?.items ?? const <Vendor>[];
|
||||
final totalCount = result?.total ?? 0;
|
||||
final currentPage = result?.page ?? 1;
|
||||
final totalPages = result == null || result.pageSize == 0
|
||||
? 1
|
||||
: (result.total / result.pageSize).ceil().clamp(1, 9999);
|
||||
final hasNext = result == null
|
||||
? false
|
||||
: (result.page * result.pageSize) < result.total;
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('제조사(벤더) 관리', style: theme.textTheme.h2),
|
||||
const SizedBox(height: 6),
|
||||
Text('벤더코드, 명칭, 사용여부 관리', style: theme.textTheme.muted),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: _loading,
|
||||
builder: (_, loading, __) {
|
||||
return ShadButton(
|
||||
onPressed: loading ? null : _load,
|
||||
child: Text(loading ? '로딩 중...' : '데이터 조회'),
|
||||
);
|
||||
},
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('제조사(벤더) 관리', style: theme.textTheme.h2),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'벤더코드, 명칭, 사용여부, 삭제 상태를 관리합니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
ShadButton(
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openVendorForm(context),
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Text('검색 및 필터', style: theme.textTheme.h3),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 16,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 280,
|
||||
child: ShadInput(
|
||||
controller: _searchController,
|
||||
focusNode: _searchFocusNode,
|
||||
placeholder: const Text('벤더코드, 벤더명 검색'),
|
||||
leading: const Icon(LucideIcons.search, size: 16),
|
||||
onSubmitted: (_) => _applyFilters(),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 220,
|
||||
child: ShadSelect<VendorStatusFilter>(
|
||||
key: ValueKey(_controller.statusFilter),
|
||||
initialValue: _controller.statusFilter,
|
||||
selectedOptionBuilder: (context, value) =>
|
||||
Text(_statusLabel(value)),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
_controller.updateStatusFilter(value);
|
||||
_controller.fetch(page: 1);
|
||||
}
|
||||
},
|
||||
options: VendorStatusFilter.values
|
||||
.map(
|
||||
(filter) => ShadOption(
|
||||
value: filter,
|
||||
child: Text(_statusLabel(filter)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
ShadButton.outline(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: _applyFilters,
|
||||
child: const Text('검색 적용'),
|
||||
),
|
||||
if (_searchController.text.isNotEmpty ||
|
||||
_controller.statusFilter != VendorStatusFilter.all)
|
||||
ShadButton.ghost(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: () {
|
||||
_searchController.clear();
|
||||
_searchFocusNode.requestFocus();
|
||||
_controller.updateQuery('');
|
||||
_controller.updateStatusFilter(
|
||||
VendorStatusFilter.all,
|
||||
);
|
||||
_controller.fetch(page: 1);
|
||||
},
|
||||
child: const Text('초기화'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('벤더 목록', style: theme.textTheme.h3),
|
||||
Text('$totalCount건', style: theme.textTheme.muted),
|
||||
],
|
||||
),
|
||||
footer: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'페이지 $currentPage / $totalPages',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || currentPage <= 1
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage - 1),
|
||||
child: const Text('이전'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || !hasNext
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage + 1),
|
||||
child: const Text('다음'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _controller.isLoading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(48),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: vendors.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Text(
|
||||
'조건에 맞는 벤더가 없습니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
)
|
||||
: _VendorTable(
|
||||
vendors: vendors,
|
||||
onEdit: _controller.isSubmitting
|
||||
? null
|
||||
: (vendor) =>
|
||||
_openVendorForm(context, vendor: vendor),
|
||||
onDelete: _controller.isSubmitting
|
||||
? null
|
||||
: _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreVendor,
|
||||
dateFormat: _dateFormat,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ShadCard(
|
||||
title: Text('벤더 목록', style: theme.textTheme.h3),
|
||||
child: ValueListenableBuilder<List<Vendor>>(
|
||||
valueListenable: _vendors,
|
||||
builder: (_, vendors, __) {
|
||||
if (vendors.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text('데이터가 없습니다. 상단의 "데이터 조회"를 눌러주세요.',
|
||||
style: theme.textTheme.muted),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _applyFilters() {
|
||||
_controller.updateQuery(_searchController.text.trim());
|
||||
_controller.fetch(page: 1);
|
||||
}
|
||||
|
||||
String _statusLabel(VendorStatusFilter filter) {
|
||||
switch (filter) {
|
||||
case VendorStatusFilter.all:
|
||||
return '전체(사용/미사용)';
|
||||
case VendorStatusFilter.activeOnly:
|
||||
return '사용중';
|
||||
case VendorStatusFilter.inactiveOnly:
|
||||
return '미사용';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openVendorForm(BuildContext context, {Vendor? vendor}) async {
|
||||
final existingVendor = vendor;
|
||||
final isEdit = existingVendor != null;
|
||||
final vendorId = existingVendor?.id;
|
||||
if (isEdit && vendorId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existingVendor?.vendorCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existingVendor?.vendorName ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingVendor?.note ?? '',
|
||||
);
|
||||
final isActiveNotifier = ValueNotifier<bool>(
|
||||
existingVendor?.isActive ?? true,
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
final navigator = Navigator.of(dialogContext);
|
||||
return Dialog(
|
||||
insetPadding: const EdgeInsets.all(24),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: ShadCard(
|
||||
title: Text(
|
||||
isEdit ? '벤더 수정' : '벤더 등록',
|
||||
style: theme.textTheme.h3,
|
||||
),
|
||||
description: Text(
|
||||
'벤더 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
footer: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (_, isSaving, __) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
onPressed: isSaving ? null : () => navigator.pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final code = codeController.text.trim();
|
||||
final name = nameController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
|
||||
codeError.value = code.isEmpty
|
||||
? '벤더코드를 입력하세요.'
|
||||
: null;
|
||||
nameError.value = name.isEmpty
|
||||
? '벤더명을 입력하세요.'
|
||||
: null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = VendorInput(
|
||||
vendorCode: code,
|
||||
vendorName: name,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(vendorId!, 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 ? '저장' : '등록'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return SizedBox(
|
||||
height: 56.0 * (vendors.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: const [
|
||||
'ID',
|
||||
'벤더코드',
|
||||
'벤더명',
|
||||
'사용',
|
||||
'비고',
|
||||
'변경일시',
|
||||
].map((h) => ShadTableCell.header(child: Text(h))).toList(),
|
||||
children: vendors
|
||||
.map(
|
||||
(v) => [
|
||||
'${v.id ?? '-'}',
|
||||
v.vendorCode,
|
||||
v.vendorName,
|
||||
v.isActive ? 'Y' : 'N',
|
||||
v.note ?? '-',
|
||||
v.updatedAt?.toIso8601String() ?? '-',
|
||||
].map((c) => ShadTableCell(child: Text(c))).toList(),
|
||||
)
|
||||
.toList(),
|
||||
columnSpanExtent: (index) => const FixedTableSpanExtent(160),
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
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),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (isEdit) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existingVendor.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingVendor.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
noteController.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Vendor vendor) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('벤더 삭제'),
|
||||
content: Text('"${vendor.vendorName}" 벤더를 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (confirmed == true && vendor.id != null) {
|
||||
final success = await _controller.delete(vendor.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('벤더를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreVendor(Vendor vendor) async {
|
||||
if (vendor.id == null) return;
|
||||
final restored = await _controller.restore(vendor.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('벤더를 복구했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
void _showSnack(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _VendorTable extends StatelessWidget {
|
||||
const _VendorTable({
|
||||
required this.vendors,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.dateFormat,
|
||||
});
|
||||
|
||||
final List<Vendor> vendors;
|
||||
final void Function(Vendor vendor)? onEdit;
|
||||
final void Function(Vendor vendor)? onDelete;
|
||||
final void Function(Vendor vendor)? onRestore;
|
||||
final DateFormat dateFormat;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final header = [
|
||||
'ID',
|
||||
'벤더코드',
|
||||
'벤더명',
|
||||
'사용',
|
||||
'삭제',
|
||||
'비고',
|
||||
'변경일시',
|
||||
'동작',
|
||||
].map((text) => ShadTableCell.header(child: Text(text))).toList();
|
||||
|
||||
final rows = vendors.map((vendor) {
|
||||
return [
|
||||
vendor.id?.toString() ?? '-',
|
||||
vendor.vendorCode,
|
||||
vendor.vendorName,
|
||||
vendor.isActive ? 'Y' : 'N',
|
||||
vendor.isDeleted ? 'Y' : '-',
|
||||
vendor.note?.isEmpty ?? true ? '-' : vendor.note!,
|
||||
vendor.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.updatedAt!.toLocal()),
|
||||
].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!(vendor),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
vendor.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(vendor),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(vendor),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (vendors.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) => index == 7
|
||||
? 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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
142
lib/features/masters/warehouse/data/dtos/warehouse_dto.dart
Normal file
142
lib/features/masters/warehouse/data/dtos/warehouse_dto.dart
Normal file
@@ -0,0 +1,142 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/warehouse.dart';
|
||||
|
||||
class WarehouseDto {
|
||||
WarehouseDto({
|
||||
this.id,
|
||||
required this.warehouseCode,
|
||||
required this.warehouseName,
|
||||
this.zipcode,
|
||||
this.addressDetail,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String warehouseCode;
|
||||
final String warehouseName;
|
||||
final WarehouseZipcodeDto? zipcode;
|
||||
final String? addressDetail;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory WarehouseDto.fromJson(Map<String, dynamic> json) {
|
||||
return WarehouseDto(
|
||||
id: json['id'] as int?,
|
||||
warehouseCode: json['warehouse_code'] as String,
|
||||
warehouseName: json['warehouse_name'] as String,
|
||||
zipcode: json['zipcode'] is Map<String, dynamic>
|
||||
? WarehouseZipcodeDto.fromJson(
|
||||
json['zipcode'] as Map<String, dynamic>,
|
||||
)
|
||||
: null,
|
||||
addressDetail: json['address_detail'] as String?,
|
||||
isActive: (json['is_active'] as bool?) ?? true,
|
||||
isDeleted: (json['is_deleted'] as bool?) ?? false,
|
||||
note: json['note'] as String?,
|
||||
createdAt: _parseDate(json['created_at']),
|
||||
updatedAt: _parseDate(json['updated_at']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'warehouse_code': warehouseCode,
|
||||
'warehouse_name': warehouseName,
|
||||
'zipcode': zipcode?.toJson(),
|
||||
'address_detail': addressDetail,
|
||||
'is_active': isActive,
|
||||
'is_deleted': isDeleted,
|
||||
'note': note,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
Warehouse toEntity() => Warehouse(
|
||||
id: id,
|
||||
warehouseCode: warehouseCode,
|
||||
warehouseName: warehouseName,
|
||||
zipcode: zipcode?.toEntity(),
|
||||
addressDetail: addressDetail,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<Warehouse> parsePaginated(Map<String, dynamic>? json) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(WarehouseDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<Warehouse>(
|
||||
items: items,
|
||||
page: json?['page'] as int? ?? 1,
|
||||
pageSize: json?['page_size'] as int? ?? items.length,
|
||||
total: json?['total'] as int? ?? items.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WarehouseZipcodeDto {
|
||||
WarehouseZipcodeDto({
|
||||
required this.zipcode,
|
||||
this.sido,
|
||||
this.sigungu,
|
||||
this.roadName,
|
||||
});
|
||||
|
||||
final String zipcode;
|
||||
final String? sido;
|
||||
final String? sigungu;
|
||||
final String? roadName;
|
||||
|
||||
factory WarehouseZipcodeDto.fromJson(Map<String, dynamic> json) {
|
||||
return WarehouseZipcodeDto(
|
||||
zipcode: json['zipcode'] as String,
|
||||
sido: json['sido'] as String?,
|
||||
sigungu: json['sigungu'] as String?,
|
||||
roadName: json['road_name'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'zipcode': zipcode,
|
||||
'sido': sido,
|
||||
'sigungu': sigungu,
|
||||
'road_name': roadName,
|
||||
};
|
||||
}
|
||||
|
||||
WarehouseZipcode toEntity() => WarehouseZipcode(
|
||||
zipcode: zipcode,
|
||||
sido: sido,
|
||||
sigungu: sigungu,
|
||||
roadName: roadName,
|
||||
);
|
||||
}
|
||||
|
||||
DateTime? _parseDate(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> warehouseInputToJson(WarehouseInput input) {
|
||||
final map = input.toPayload();
|
||||
map.removeWhere((key, value) => value == null);
|
||||
return map;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/api_client.dart';
|
||||
|
||||
import '../../domain/entities/warehouse.dart';
|
||||
import '../../domain/repositories/warehouse_repository.dart';
|
||||
import '../dtos/warehouse_dto.dart';
|
||||
|
||||
class WarehouseRepositoryRemote implements WarehouseRepository {
|
||||
WarehouseRepositoryRemote({required ApiClient apiClient}) : _api = apiClient;
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
static const _basePath = '/warehouses';
|
||||
|
||||
@override
|
||||
Future<PaginatedResult<Warehouse>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (query != null && query.isNotEmpty) 'q': query,
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return WarehouseDto.parsePaginated(response.data ?? const {});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Warehouse> create(WarehouseInput input) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
data: warehouseInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return WarehouseDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Warehouse> update(int id, WarehouseInput input) async {
|
||||
final response = await _api.patch<Map<String, dynamic>>(
|
||||
'$_basePath/$id',
|
||||
data: warehouseInputToJson(input),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return WarehouseDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(int id) async {
|
||||
await _api.delete<void>('$_basePath/$id');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Warehouse> restore(int id) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
'$_basePath/$id/restore',
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return WarehouseDto.fromJson(data).toEntity();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
class Warehouse {
|
||||
Warehouse({
|
||||
this.id,
|
||||
required this.warehouseCode,
|
||||
required this.warehouseName,
|
||||
this.zipcode,
|
||||
this.addressDetail,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final String warehouseCode;
|
||||
final String warehouseName;
|
||||
final WarehouseZipcode? zipcode;
|
||||
final String? addressDetail;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
Warehouse copyWith({
|
||||
int? id,
|
||||
String? warehouseCode,
|
||||
String? warehouseName,
|
||||
WarehouseZipcode? zipcode,
|
||||
String? addressDetail,
|
||||
bool? isActive,
|
||||
bool? isDeleted,
|
||||
String? note,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return Warehouse(
|
||||
id: id ?? this.id,
|
||||
warehouseCode: warehouseCode ?? this.warehouseCode,
|
||||
warehouseName: warehouseName ?? this.warehouseName,
|
||||
zipcode: zipcode ?? this.zipcode,
|
||||
addressDetail: addressDetail ?? this.addressDetail,
|
||||
isActive: isActive ?? this.isActive,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
note: note ?? this.note,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WarehouseZipcode {
|
||||
WarehouseZipcode({
|
||||
required this.zipcode,
|
||||
this.sido,
|
||||
this.sigungu,
|
||||
this.roadName,
|
||||
});
|
||||
|
||||
final String zipcode;
|
||||
final String? sido;
|
||||
final String? sigungu;
|
||||
final String? roadName;
|
||||
}
|
||||
|
||||
class WarehouseInput {
|
||||
WarehouseInput({
|
||||
required this.warehouseCode,
|
||||
required this.warehouseName,
|
||||
this.zipcode,
|
||||
this.addressDetail,
|
||||
this.isActive = true,
|
||||
this.note,
|
||||
});
|
||||
|
||||
final String warehouseCode;
|
||||
final String warehouseName;
|
||||
final String? zipcode;
|
||||
final String? addressDetail;
|
||||
final bool isActive;
|
||||
final String? note;
|
||||
|
||||
Map<String, dynamic> toPayload() {
|
||||
return {
|
||||
'warehouse_code': warehouseCode,
|
||||
'warehouse_name': warehouseName,
|
||||
'zipcode': zipcode,
|
||||
'address_detail': addressDetail,
|
||||
'is_active': isActive,
|
||||
'note': note,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../entities/warehouse.dart';
|
||||
|
||||
abstract class WarehouseRepository {
|
||||
Future<PaginatedResult<Warehouse>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
String? query,
|
||||
bool? isActive,
|
||||
});
|
||||
|
||||
Future<Warehouse> create(WarehouseInput input);
|
||||
|
||||
Future<Warehouse> update(int id, WarehouseInput input);
|
||||
|
||||
Future<void> delete(int id);
|
||||
|
||||
Future<Warehouse> restore(int id);
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/warehouse.dart';
|
||||
import '../../domain/repositories/warehouse_repository.dart';
|
||||
|
||||
enum WarehouseStatusFilter { all, activeOnly, inactiveOnly }
|
||||
|
||||
class WarehouseController extends ChangeNotifier {
|
||||
WarehouseController({required WarehouseRepository repository})
|
||||
: _repository = repository;
|
||||
|
||||
final WarehouseRepository _repository;
|
||||
|
||||
PaginatedResult<Warehouse>? _result;
|
||||
bool _isLoading = false;
|
||||
bool _isSubmitting = false;
|
||||
String _query = '';
|
||||
WarehouseStatusFilter _statusFilter = WarehouseStatusFilter.all;
|
||||
String? _errorMessage;
|
||||
|
||||
PaginatedResult<Warehouse>? get result => _result;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
String get query => _query;
|
||||
WarehouseStatusFilter get statusFilter => _statusFilter;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> fetch({int page = 1}) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
final isActive = switch (_statusFilter) {
|
||||
WarehouseStatusFilter.all => null,
|
||||
WarehouseStatusFilter.activeOnly => true,
|
||||
WarehouseStatusFilter.inactiveOnly => false,
|
||||
};
|
||||
final response = await _repository.list(
|
||||
page: page,
|
||||
pageSize: _result?.pageSize ?? 20,
|
||||
query: _query.isEmpty ? null : _query,
|
||||
isActive: isActive,
|
||||
);
|
||||
_result = response;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuery(String value) {
|
||||
_query = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateStatusFilter(WarehouseStatusFilter filter) {
|
||||
_statusFilter = filter;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<Warehouse?> create(WarehouseInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final created = await _repository.create(input);
|
||||
await fetch(page: 1);
|
||||
return created;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Warehouse?> update(int id, WarehouseInput input) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final updated = await _repository.update(id, input);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return updated;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> delete(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
await _repository.delete(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return false;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Warehouse?> restore(int id) async {
|
||||
_setSubmitting(true);
|
||||
try {
|
||||
final restored = await _repository.restore(id);
|
||||
await fetch(page: _result?.page ?? 1);
|
||||
return restored;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
} finally {
|
||||
_setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
void clearError() {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _setSubmitting(bool value) {
|
||||
_isSubmitting = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,759 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/warehouse.dart';
|
||||
import '../../domain/repositories/warehouse_repository.dart';
|
||||
import '../controllers/warehouse_controller.dart';
|
||||
|
||||
class WarehousePage extends StatelessWidget {
|
||||
const WarehousePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SpecPage(
|
||||
title: '입고지(창고) 관리',
|
||||
summary: '창고 주소와 사용 여부를 구성합니다.',
|
||||
sections: [
|
||||
SpecSection(
|
||||
title: '입력 폼',
|
||||
items: [
|
||||
'창고코드 [Text]',
|
||||
'창고명 [Text]',
|
||||
'우편번호 [검색 연동]',
|
||||
'상세주소 [Text]',
|
||||
'사용여부 [Switch]',
|
||||
'비고 [Text]',
|
||||
],
|
||||
),
|
||||
SpecSection(
|
||||
title: '수정 폼',
|
||||
items: ['창고코드 [ReadOnly]', '생성일시 [ReadOnly]'],
|
||||
),
|
||||
SpecSection(
|
||||
title: '테이블 리스트',
|
||||
description: '1행 예시',
|
||||
table: SpecTable(
|
||||
columns: [
|
||||
'번호',
|
||||
'창고코드',
|
||||
'창고명',
|
||||
'우편번호',
|
||||
'상세주소',
|
||||
'사용여부',
|
||||
'비고',
|
||||
'변경일시',
|
||||
final enabled = Environment.flag('FEATURE_WAREHOUSES_ENABLED');
|
||||
if (!enabled) {
|
||||
return const SpecPage(
|
||||
title: '입고지(창고) 관리',
|
||||
summary: '창고 코드, 주소, 사용여부를 관리합니다.',
|
||||
sections: [
|
||||
SpecSection(
|
||||
title: '입력 폼',
|
||||
items: [
|
||||
'창고코드 [Text]',
|
||||
'창고명 [Text]',
|
||||
'우편번호 [Text+검색]',
|
||||
'상세주소 [Text]',
|
||||
'사용여부 [Switch]',
|
||||
'비고 [Text]',
|
||||
],
|
||||
rows: [
|
||||
[
|
||||
'1',
|
||||
'WH-01',
|
||||
'서울 1창고',
|
||||
'04532',
|
||||
'서울시 중구 을지로 100',
|
||||
'Y',
|
||||
'-',
|
||||
'2024-03-01 10:00',
|
||||
),
|
||||
SpecSection(
|
||||
title: '수정 폼',
|
||||
items: ['창고코드 [ReadOnly]', '생성일시 [ReadOnly]'],
|
||||
),
|
||||
SpecSection(
|
||||
title: '테이블 리스트',
|
||||
description: '1행 예시',
|
||||
table: SpecTable(
|
||||
columns: [
|
||||
'번호',
|
||||
'창고코드',
|
||||
'창고명',
|
||||
'우편번호',
|
||||
'상세주소',
|
||||
'사용여부',
|
||||
'비고',
|
||||
'변경일시',
|
||||
],
|
||||
rows: [
|
||||
[
|
||||
'1',
|
||||
'WH-001',
|
||||
'서울 1창고',
|
||||
'06000',
|
||||
'강남대로 123',
|
||||
'Y',
|
||||
'-',
|
||||
'2024-03-01 10:00',
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return const _WarehouseEnabledPage();
|
||||
}
|
||||
}
|
||||
|
||||
class _WarehouseEnabledPage extends StatefulWidget {
|
||||
const _WarehouseEnabledPage();
|
||||
|
||||
@override
|
||||
State<_WarehouseEnabledPage> createState() => _WarehouseEnabledPageState();
|
||||
}
|
||||
|
||||
class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
|
||||
late final WarehouseController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
String? _lastError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = WarehouseController(
|
||||
repository: GetIt.I<WarehouseRepository>(),
|
||||
)..addListener(_handleControllerUpdate);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_controller.fetch();
|
||||
});
|
||||
}
|
||||
|
||||
void _handleControllerUpdate() {
|
||||
final error = _controller.errorMessage;
|
||||
if (error != null && error != _lastError && mounted) {
|
||||
_lastError = error;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(error)));
|
||||
_controller.clearError();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.removeListener(_handleControllerUpdate);
|
||||
_controller.dispose();
|
||||
_searchController.dispose();
|
||||
_searchFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) {
|
||||
final result = _controller.result;
|
||||
final warehouses = result?.items ?? const <Warehouse>[];
|
||||
final totalCount = result?.total ?? 0;
|
||||
final currentPage = result?.page ?? 1;
|
||||
final totalPages = result == null || result.pageSize == 0
|
||||
? 1
|
||||
: (result.total / result.pageSize).ceil().clamp(1, 9999);
|
||||
final hasNext = result == null
|
||||
? false
|
||||
: (result.page * result.pageSize) < result.total;
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('입고지(창고) 관리', style: theme.textTheme.h2),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'창고 코드, 주소, 사용여부를 관리합니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
ShadButton(
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openWarehouseForm(context),
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Text('검색 및 필터', style: theme.textTheme.h3),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 16,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 260,
|
||||
child: ShadInput(
|
||||
controller: _searchController,
|
||||
focusNode: _searchFocus,
|
||||
placeholder: const Text('창고코드, 창고명 검색'),
|
||||
leading: const Icon(LucideIcons.search, size: 16),
|
||||
onSubmitted: (_) => _applyFilters(),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: ShadSelect<WarehouseStatusFilter>(
|
||||
key: ValueKey(_controller.statusFilter),
|
||||
initialValue: _controller.statusFilter,
|
||||
selectedOptionBuilder: (context, filter) =>
|
||||
Text(_statusLabel(filter)),
|
||||
onChanged: (value) {
|
||||
if (value == null) return;
|
||||
_controller.updateStatusFilter(value);
|
||||
},
|
||||
options: WarehouseStatusFilter.values
|
||||
.map(
|
||||
(filter) => ShadOption(
|
||||
value: filter,
|
||||
child: Text(_statusLabel(filter)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
ShadButton.outline(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: _applyFilters,
|
||||
child: const Text('검색 적용'),
|
||||
),
|
||||
if (_searchController.text.isNotEmpty ||
|
||||
_controller.statusFilter !=
|
||||
WarehouseStatusFilter.all)
|
||||
ShadButton.ghost(
|
||||
onPressed: _controller.isLoading
|
||||
? null
|
||||
: () {
|
||||
_searchController.clear();
|
||||
_searchFocus.requestFocus();
|
||||
_controller.updateQuery('');
|
||||
_controller.updateStatusFilter(
|
||||
WarehouseStatusFilter.all,
|
||||
);
|
||||
_controller.fetch(page: 1);
|
||||
},
|
||||
child: const Text('초기화'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ShadCard(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('창고 목록', style: theme.textTheme.h3),
|
||||
Text('$totalCount건', style: theme.textTheme.muted),
|
||||
],
|
||||
),
|
||||
footer: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'페이지 $currentPage / $totalPages',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || currentPage <= 1
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage - 1),
|
||||
child: const Text('이전'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: _controller.isLoading || !hasNext
|
||||
? null
|
||||
: () => _controller.fetch(page: currentPage + 1),
|
||||
child: const Text('다음'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _controller.isLoading
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(48),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: warehouses.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Text(
|
||||
'조건에 맞는 창고가 없습니다.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
)
|
||||
: _WarehouseTable(
|
||||
warehouses: warehouses,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
? null
|
||||
: (warehouse) => _openWarehouseForm(
|
||||
context,
|
||||
warehouse: warehouse,
|
||||
),
|
||||
onDelete: _controller.isSubmitting
|
||||
? null
|
||||
: _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreWarehouse,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _applyFilters() {
|
||||
_controller.updateQuery(_searchController.text.trim());
|
||||
_controller.fetch(page: 1);
|
||||
}
|
||||
|
||||
String _statusLabel(WarehouseStatusFilter filter) {
|
||||
switch (filter) {
|
||||
case WarehouseStatusFilter.all:
|
||||
return '전체(사용/미사용)';
|
||||
case WarehouseStatusFilter.activeOnly:
|
||||
return '사용중';
|
||||
case WarehouseStatusFilter.inactiveOnly:
|
||||
return '미사용';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openWarehouseForm(
|
||||
BuildContext context, {
|
||||
Warehouse? warehouse,
|
||||
}) async {
|
||||
final existing = warehouse;
|
||||
final isEdit = existing != null;
|
||||
final warehouseId = existing?.id;
|
||||
if (isEdit && warehouseId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existing?.warehouseCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existing?.warehouseName ?? '',
|
||||
);
|
||||
final zipcodeController = TextEditingController(
|
||||
text: existing?.zipcode?.zipcode ?? '',
|
||||
);
|
||||
final addressController = TextEditingController(
|
||||
text: existing?.addressDetail ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(text: existing?.note ?? '');
|
||||
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
final navigator = Navigator.of(dialogContext);
|
||||
return Dialog(
|
||||
insetPadding: const EdgeInsets.all(24),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 540),
|
||||
child: ShadCard(
|
||||
title: Text(
|
||||
isEdit ? '창고 수정' : '창고 등록',
|
||||
style: theme.textTheme.h3,
|
||||
),
|
||||
description: Text(
|
||||
'창고 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
footer: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (_, isSaving, __) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
onPressed: isSaving ? null : () => navigator.pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final code = codeController.text.trim();
|
||||
final name = nameController.text.trim();
|
||||
final zipcode = zipcodeController.text.trim();
|
||||
final address = addressController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
|
||||
codeError.value = code.isEmpty
|
||||
? '창고코드를 입력하세요.'
|
||||
: null;
|
||||
nameError.value = name.isEmpty
|
||||
? '창고명을 입력하세요.'
|
||||
: null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = WarehouseInput(
|
||||
warehouseCode: code,
|
||||
warehouseName: name,
|
||||
zipcode: zipcode.isEmpty ? null : zipcode,
|
||||
addressDetail: address.isEmpty
|
||||
? null
|
||||
: address,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(
|
||||
warehouseId!,
|
||||
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 ? '저장' : '등록'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
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: zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
),
|
||||
),
|
||||
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: saving.value
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (isEdit) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existing.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existing.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (!mounted) {
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
zipcodeController.dispose();
|
||||
addressController.dispose();
|
||||
noteController.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
zipcodeController.dispose();
|
||||
addressController.dispose();
|
||||
noteController.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Warehouse warehouse) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('창고 삭제'),
|
||||
content: Text('"${warehouse.warehouseName}" 창고를 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (confirmed == true && warehouse.id != null) {
|
||||
final success = await _controller.delete(warehouse.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('창고를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreWarehouse(Warehouse warehouse) async {
|
||||
if (warehouse.id == null) return;
|
||||
final restored = await _controller.restore(warehouse.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('창고를 복구했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
void _showSnack(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) return '-';
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _WarehouseTable extends StatelessWidget {
|
||||
const _WarehouseTable({
|
||||
required this.warehouses,
|
||||
required this.dateFormat,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final List<Warehouse> warehouses;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(Warehouse warehouse)? onEdit;
|
||||
final void Function(Warehouse warehouse)? onDelete;
|
||||
final void Function(Warehouse warehouse)? onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final header = [
|
||||
'ID',
|
||||
'창고코드',
|
||||
'창고명',
|
||||
'우편번호',
|
||||
'상세주소',
|
||||
'사용',
|
||||
'삭제',
|
||||
'비고',
|
||||
'변경일시',
|
||||
'동작',
|
||||
].map((text) => ShadTableCell.header(child: Text(text))).toList();
|
||||
|
||||
final rows = warehouses.map((warehouse) {
|
||||
return [
|
||||
warehouse.id?.toString() ?? '-',
|
||||
warehouse.warehouseCode,
|
||||
warehouse.warehouseName,
|
||||
warehouse.zipcode?.zipcode ?? '-',
|
||||
warehouse.addressDetail?.isEmpty ?? true
|
||||
? '-'
|
||||
: warehouse.addressDetail!,
|
||||
warehouse.isActive ? 'Y' : 'N',
|
||||
warehouse.isDeleted ? 'Y' : '-',
|
||||
warehouse.note?.isEmpty ?? true ? '-' : warehouse.note!,
|
||||
warehouse.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(warehouse.updatedAt!.toLocal()),
|
||||
].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!(warehouse),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
warehouse.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(warehouse),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(warehouse),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (warehouses.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) => index == 9
|
||||
? 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,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,16 @@ import 'package:get_it/get_it.dart';
|
||||
|
||||
import 'core/network/api_client.dart';
|
||||
import 'core/network/interceptors/auth_interceptor.dart';
|
||||
import 'features/masters/customer/data/repositories/customer_repository_remote.dart';
|
||||
import 'features/masters/customer/domain/repositories/customer_repository.dart';
|
||||
import 'features/masters/product/data/repositories/product_repository_remote.dart';
|
||||
import 'features/masters/product/domain/repositories/product_repository.dart';
|
||||
import 'features/masters/vendor/data/repositories/vendor_repository_remote.dart';
|
||||
import 'features/masters/vendor/domain/repositories/vendor_repository.dart';
|
||||
import 'features/masters/warehouse/data/repositories/warehouse_repository_remote.dart';
|
||||
import 'features/masters/warehouse/domain/repositories/warehouse_repository.dart';
|
||||
import 'features/masters/uom/data/repositories/uom_repository_remote.dart';
|
||||
import 'features/masters/uom/domain/repositories/uom_repository.dart';
|
||||
|
||||
/// 전역 DI 컨테이너
|
||||
final GetIt sl = GetIt.instance;
|
||||
@@ -39,4 +47,20 @@ Future<void> initInjection({required String baseUrl, Duration? connectTimeout, D
|
||||
sl.registerLazySingleton<VendorRepository>(
|
||||
() => VendorRepositoryRemote(apiClient: sl<ApiClient>()),
|
||||
);
|
||||
|
||||
sl.registerLazySingleton<ProductRepository>(
|
||||
() => ProductRepositoryRemote(apiClient: sl<ApiClient>()),
|
||||
);
|
||||
|
||||
sl.registerLazySingleton<WarehouseRepository>(
|
||||
() => WarehouseRepositoryRemote(apiClient: sl<ApiClient>()),
|
||||
);
|
||||
|
||||
sl.registerLazySingleton<UomRepository>(
|
||||
() => UomRepositoryRemote(apiClient: sl<ApiClient>()),
|
||||
);
|
||||
|
||||
sl.registerLazySingleton<CustomerRepository>(
|
||||
() => CustomerRepositoryRemote(apiClient: sl<ApiClient>()),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user