feat: enhance product datatable with bulk delete functionality and refined category/price columns.

This commit is contained in:
pbao9
2026-02-13 14:59:10 +07:00
parent 549e434627
commit 78b87c10fe
8 changed files with 381 additions and 270 deletions
@@ -1,6 +1,34 @@
<div class="d-flex gap-2">
<x-button-crm type="button" variant="outline-primary" size="sm" route="products.edit" :params="['id' => $row->id]"
icon="pencil">Chỉnh sửa</x-button-crm>
<x-button-crm type="button" variant="outline-danger" size="sm" route="products.destroy" :params="['id' => $row->id]"
icon="trash">Xóa</x-button-crm>
</div>
<div class="dt-action-dropdown dropdown">
<button class="btn btn-sm btn-light border d-flex align-items-center gap-1" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i data-lucide="more-vertical" width="14" height="14"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<a class="dropdown-item" href="{{ route('products.edit', ['id' => $row->id]) }}">
<i data-lucide="pencil" width="14" height="14"></i>
Edit
</a>
</li>
<li>
<form action="{{ route('products.duplicate', ['id' => $row->id]) }}" method="POST" class="d-inline">
@csrf
<button type="submit" class="dropdown-item">
<i data-lucide="copy" width="14" height="14"></i>
Duplicate
</button>
</form>
</li>
<li><hr class="dropdown-divider"></li>
<li>
<form action="{{ route('products.destroy', ['id' => $row->id]) }}" method="POST" class="d-inline"
onsubmit="return confirm('Are you sure you want to delete this product?')">
@csrf
@method('DELETE')
<button type="submit" class="dropdown-item text-danger">
<i data-lucide="trash-2" width="14" height="14"></i>
Delete
</button>
</form>
</li>
</ul>
</div>
@@ -0,0 +1,18 @@
@php
$type = \App\Enums\Product\ProductTypeEnums::tryFrom($row->product_type);
$categoryName = $row->category?->name;
@endphp
<div class="d-flex flex-column gap-1 small">
@if($categoryName)
<div class="d-flex align-items-center gap-1">
<i data-lucide="folder" width="13" height="13" class="text-warning"></i>
<span>{{ $categoryName }}</span>
</div>
@endif
@if($type)
<div>
<span class="badge bg-light text-dark border" style="font-size: 0.7rem;">{{ $type->label() }}</span>
</div>
@endif
</div>
@@ -0,0 +1,17 @@
@php
$pricing = $row->pricings->where('is_active', 1)->sortBy('price')->first();
@endphp
@if($pricing)
<div class="d-flex flex-column small">
@if($pricing->price_sale && $pricing->price_sale < $pricing->price)
<span class="text-decoration-line-through text-muted">{{ number_format($pricing->price) }}</span>
<span class="fw-semibold text-success">{{ number_format($pricing->price_sale) }}</span>
@else
<span class="fw-semibold">{{ number_format($pricing->price) }}</span>
@endif
<span class="text-muted" style="font-size: 0.75rem;">/ {{ $pricing->billing_cycle ?? 'monthly' }}</span>
</div>
@else
<span class="text-muted">-</span>
@endif
@@ -7,48 +7,51 @@
@section('breadcrumb')
@php
$breadcrumbItems = [
['label' => 'Product'],
['label' => 'Product / Services'],
['label' => 'Product List', 'active' => true],
];
$breadcrumbItems = [
['label' => 'Product'],
['label' => 'Product / Services'],
['label' => 'Product List', 'active' => true],
];
@endphp
<x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection
@section('tab')
@php
$tabs = [
[
'label' => 'Product',
'route' => 'products.index',
'icon' => 'server',
],
[
'label' => 'Product Group',
'route' => 'products.group.index',
'icon' => 'server',
],
];
$tabs = [
[
'label' => 'Product',
'route' => 'products.index',
'icon' => 'server',
],
[
'label' => 'Product Group',
'route' => 'products.group.index',
'icon' => 'server',
],
];
@endphp
<x-admin-tab :items="$tabs" />
@endsection
@section('content')
@if (auth()->guard('admins')->user()->can('manager product'))
<div class="card card-primary card-outline">
<div class="card-header d-flex justify-content-end gap-2">
<div class="card card-primary card-outline rounded-4 shadow-none">
<div class="card-header d-flex justify-content-end gap-2 rounded-top-4">
@include('administrator.pages.block.product.btn')
</div>
<div class="card-body">
<x-datatable id="productTable" ajax="{{ route('products.datatable') }}" :columns="[
['key' => 'name', 'label' => 'Product Name'],
['key' => 'category_name', 'label' => 'Category'],
['key' => 'product_type_label', 'label' => 'Type'],
['key' => 'specs', 'label' => 'Specifications'],
['key' => 'status', 'label' => 'Status'],
['key' => 'action', 'label' => 'Action'],
]" />
<div class="card-body p-0">
@php
$productColumns = [
['key' => 'checkbox', 'label' => '<input type="checkbox" class="form-check-input" id="dt-master-checkbox">', 'orderable' => false, 'searchable' => false, 'className' => 'text-center'],
['key' => 'name', 'label' => 'Product Name'],
['key' => 'category', 'label' => 'Category / Type', 'searchable' => false],
['key' => 'price', 'label' => 'Price', 'orderable' => false, 'searchable' => false],
['key' => 'specs', 'label' => 'Specifications', 'orderable' => false, 'searchable' => false],
['key' => 'status', 'label' => 'Status', 'searchable' => false],
['key' => 'action', 'label' => '', 'orderable' => false, 'searchable' => false, 'className' => 'text-center'],
];
@endphp
<x-datatable id="productTable" ajax="{{ route('products.datatable') }}" :columns="$productColumns" />
</div>
</div>
@else
<div class="alert alert-danger alert-dismissible">