feat:영업권 수정 페이지 첨부 이미지 삭제 기능 추가

This commit is contained in:
pro
2026-01-28 10:21:03 +09:00
parent 1642aa249a
commit e5b054ea0a
4 changed files with 110 additions and 11 deletions

View File

@@ -213,4 +213,32 @@ public function checkBusinessNumber(Request $request)
return response()->json($result);
}
/**
* 첨부 이미지 삭제 (AJAX)
*/
public function deleteAttachment(Request $request, int $id)
{
$prospect = TenantProspect::findOrFail($id);
// 이미 전환된 경우 수정 불가
if ($prospect->isConverted()) {
return response()->json(['success' => false, 'message' => '전환된 영업권은 수정할 수 없습니다.'], 403);
}
$type = $request->get('type');
$allowedTypes = ['business_card', 'id_card', 'bankbook'];
if (!in_array($type, $allowedTypes)) {
return response()->json(['success' => false, 'message' => '잘못된 요청입니다.'], 400);
}
$result = $this->service->deleteAttachment($prospect, $type);
if ($result) {
return response()->json(['success' => true, 'message' => '이미지가 삭제되었습니다.']);
}
return response()->json(['success' => false, 'message' => '삭제할 이미지가 없습니다.'], 404);
}
}

View File

@@ -270,12 +270,25 @@ private function uploadBusinessCard(UploadedFile $file, int $userId): string
*/
public function deleteBusinessCard(TenantProspect $prospect): bool
{
if ($prospect->business_card_path && Storage::disk('tenant')->exists($prospect->business_card_path)) {
Storage::disk('tenant')->delete($prospect->business_card_path);
$prospect->update(['business_card_path' => null]);
return true;
return $this->deleteAttachment($prospect, 'business_card');
}
/**
* 첨부파일 삭제
*/
public function deleteAttachment(TenantProspect $prospect, string $type): bool
{
$pathField = $type . '_path';
if (!$prospect->$pathField) {
return false;
}
return false;
if (Storage::disk('tenant')->exists($prospect->$pathField)) {
Storage::disk('tenant')->delete($prospect->$pathField);
}
$prospect->update([$pathField => null]);
return true;
}
}

View File

@@ -76,8 +76,17 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">명함 이미지</label>
@if($prospect->hasBusinessCard())
<div class="mb-2 p-2 bg-gray-50 rounded-lg">
<img src="{{ $prospect->business_card_url }}" alt="현재 명함" class="max-h-32 rounded">
<div class="mb-2 p-2 bg-gray-50 rounded-lg" id="business_card_preview">
<div class="flex items-start gap-3">
<img src="{{ $prospect->business_card_url }}" alt="현재 명함" class="max-h-32 rounded">
<button type="button" onclick="deleteAttachment('business_card')"
class="text-red-500 hover:text-red-700 text-sm flex items-center gap-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
삭제
</button>
</div>
<p class="text-xs text-gray-500 mt-1"> 이미지를 업로드하면 기존 이미지가 교체됩니다</p>
</div>
@endif
@@ -93,8 +102,17 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">신분증 사본</label>
@if($prospect->hasIdCard())
<div class="mb-2 p-2 bg-gray-50 rounded-lg">
<img src="{{ $prospect->id_card_url }}" alt="현재 신분증" class="max-h-32 rounded">
<div class="mb-2 p-2 bg-gray-50 rounded-lg" id="id_card_preview">
<div class="flex items-start gap-3">
<img src="{{ $prospect->id_card_url }}" alt="현재 신분증" class="max-h-32 rounded">
<button type="button" onclick="deleteAttachment('id_card')"
class="text-red-500 hover:text-red-700 text-sm flex items-center gap-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
삭제
</button>
</div>
<p class="text-xs text-gray-500 mt-1"> 이미지를 업로드하면 기존 이미지가 교체됩니다</p>
</div>
@endif
@@ -105,8 +123,17 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">통장 사본</label>
@if($prospect->hasBankbook())
<div class="mb-2 p-2 bg-gray-50 rounded-lg">
<img src="{{ $prospect->bankbook_url }}" alt="현재 통장사본" class="max-h-32 rounded">
<div class="mb-2 p-2 bg-gray-50 rounded-lg" id="bankbook_preview">
<div class="flex items-start gap-3">
<img src="{{ $prospect->bankbook_url }}" alt="현재 통장사본" class="max-h-32 rounded">
<button type="button" onclick="deleteAttachment('bankbook')"
class="text-red-500 hover:text-red-700 text-sm flex items-center gap-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
삭제
</button>
</div>
<p class="text-xs text-gray-500 mt-1"> 이미지를 업로드하면 기존 이미지가 교체됩니다</p>
</div>
@endif
@@ -154,4 +181,34 @@ class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition"
</div>
</form>
</div>
@push('scripts')
<script>
function deleteAttachment(type) {
if (!confirm('이미지를 삭제하시겠습니까?')) {
return;
}
fetch('{{ route("sales.prospects.delete-attachment", $prospect->id) }}?type=' + type, {
method: 'DELETE',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json',
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById(type + '_preview').remove();
} else {
alert(data.message || '삭제에 실패했습니다.');
}
})
.catch(error => {
console.error('Error:', error);
alert('삭제 중 오류가 발생했습니다.');
});
}
</script>
@endpush
@endsection

View File

@@ -821,6 +821,7 @@
Route::resource('prospects', \App\Http\Controllers\Sales\TenantProspectController::class);
Route::post('prospects/{id}/convert', [\App\Http\Controllers\Sales\TenantProspectController::class, 'convert'])->name('prospects.convert');
Route::post('prospects/check-business-number', [\App\Http\Controllers\Sales\TenantProspectController::class, 'checkBusinessNumber'])->name('prospects.check-business-number');
Route::delete('prospects/{id}/attachment', [\App\Http\Controllers\Sales\TenantProspectController::class, 'deleteAttachment'])->name('prospects.delete-attachment');
// 영업 실적 관리
Route::resource('records', \App\Http\Controllers\Sales\SalesRecordController::class);