feat: 統一採購單與操作紀錄 UI、增強各模組操作紀錄功能
- 統一採購單篩選列與表單樣式 (移除舊元件、標準化 Input) - 增強操作紀錄功能 (加入篩選、快照、詳細異動比對) - 統一刪除確認視窗與按鈕樣式 - 修復庫存編輯頁面樣式 - 實作採購單品項異動紀錄 - 實作角色分配異動紀錄 - 擴充供應商與倉庫模組紀錄
This commit is contained in:
@@ -4,9 +4,13 @@ import { Head, router } from '@inertiajs/react';
|
||||
import { PageProps } from '@/types/global';
|
||||
import Pagination from '@/Components/shared/Pagination';
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import { FileText } from 'lucide-react';
|
||||
import { FileText, Search, RotateCcw, Calendar } from 'lucide-react';
|
||||
import LogTable, { Activity } from '@/Components/ActivityLog/LogTable';
|
||||
import ActivityDetailDialog from '@/Components/ActivityLog/ActivityDetailDialog';
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import { Input } from '@/Components/ui/input';
|
||||
import { Label } from '@/Components/ui/label';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/Components/ui/select";
|
||||
|
||||
interface PaginationLinks {
|
||||
url: string | null;
|
||||
@@ -27,14 +31,62 @@ interface Props extends PageProps {
|
||||
per_page?: string;
|
||||
sort_by?: string;
|
||||
sort_order?: 'asc' | 'desc';
|
||||
search?: string;
|
||||
date_start?: string;
|
||||
date_end?: string;
|
||||
event?: string;
|
||||
subject_type?: string;
|
||||
causer_id?: string;
|
||||
};
|
||||
subject_types: { label: string; value: string }[];
|
||||
users: { label: string; value: string }[];
|
||||
}
|
||||
|
||||
export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
export default function ActivityLogIndex({ activities, filters, subject_types, users }: Props) {
|
||||
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
|
||||
const [selectedActivity, setSelectedActivity] = useState<Activity | null>(null);
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
|
||||
// Filter States
|
||||
const [search, setSearch] = useState(filters.search || '');
|
||||
const [dateStart, setDateStart] = useState(filters.date_start || '');
|
||||
const [dateEnd, setDateEnd] = useState(filters.date_end || '');
|
||||
const [event, setEvent] = useState(filters.event || 'all');
|
||||
const [subjectType, setSubjectType] = useState(filters.subject_type || 'all');
|
||||
const [causer, setCauser] = useState(filters.causer_id || 'all');
|
||||
|
||||
const handleFilter = () => {
|
||||
router.get(
|
||||
route('activity-logs.index'),
|
||||
{
|
||||
...filters,
|
||||
search: search,
|
||||
date_start: dateStart,
|
||||
date_end: dateEnd,
|
||||
event: event === 'all' ? undefined : event,
|
||||
subject_type: subjectType === 'all' ? undefined : subjectType,
|
||||
causer_id: causer === 'all' ? undefined : causer,
|
||||
page: 1 // Reset to first page on filter
|
||||
},
|
||||
{ preserveState: true, replace: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setSearch('');
|
||||
setDateStart('');
|
||||
setDateEnd('');
|
||||
setEvent('all');
|
||||
setSubjectType('all');
|
||||
setCauser('all');
|
||||
|
||||
router.get(
|
||||
route('activity-logs.index'),
|
||||
{ per_page: perPage, sort_by: filters.sort_by, sort_order: filters.sort_order },
|
||||
{ preserveState: true, replace: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleViewDetail = (activity: Activity) => {
|
||||
setSelectedActivity(activity);
|
||||
setDetailOpen(true);
|
||||
@@ -91,6 +143,118 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 篩選區塊 */}
|
||||
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4">
|
||||
{/* 關鍵字搜尋 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">關鍵字搜尋</Label>
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
placeholder="搜尋描述、內容..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="pl-9"
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 操作人員 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">操作人員</Label>
|
||||
<SearchableSelect
|
||||
value={causer}
|
||||
onValueChange={setCauser}
|
||||
options={[
|
||||
{ label: "所有人員", value: "all" },
|
||||
...users
|
||||
]}
|
||||
placeholder="選擇操作人員"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 事件類型 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">事件類型</Label>
|
||||
<Select value={event} onValueChange={setEvent}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="選擇事件類型" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">所有事件</SelectItem>
|
||||
<SelectItem value="created">新增 (Created)</SelectItem>
|
||||
<SelectItem value="updated">更新 (Updated)</SelectItem>
|
||||
<SelectItem value="deleted">刪除 (Deleted)</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 操作對象 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">操作對象</Label>
|
||||
<SearchableSelect
|
||||
value={subjectType}
|
||||
onValueChange={setSubjectType}
|
||||
options={[
|
||||
{ label: "所有對象", value: "all" },
|
||||
...subject_types
|
||||
]}
|
||||
placeholder="選擇操作對象"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 日期範圍 - 開始 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">開始日期</Label>
|
||||
<div className="relative">
|
||||
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
type="date"
|
||||
value={dateStart}
|
||||
onChange={(e) => setDateStart(e.target.value)}
|
||||
className="pl-9 block w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 日期範圍 - 結束 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">結束日期</Label>
|
||||
<div className="relative">
|
||||
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
type="date"
|
||||
value={dateEnd}
|
||||
onChange={(e) => setDateEnd(e.target.value)}
|
||||
className="pl-9 block w-full text-left"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleReset}
|
||||
className="flex items-center gap-2 button-outlined-primary"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
重置條件
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleFilter}
|
||||
className="flex items-center gap-2 button-filled-primary"
|
||||
>
|
||||
<Search className="h-4 w-4" />
|
||||
查詢紀錄
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<LogTable
|
||||
activities={activities.data}
|
||||
sortField={filters.sort_by}
|
||||
@@ -100,7 +264,7 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
from={activities.from}
|
||||
/>
|
||||
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
@@ -112,12 +276,14 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[80px] h-8"
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<Pagination links={activities.links} />
|
||||
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
|
||||
<Pagination links={activities.links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
TableRow,
|
||||
} from "@/Components/ui/table";
|
||||
import { format } from 'date-fns';
|
||||
import { toast } from 'sonner';
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
@@ -23,6 +22,16 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/Components/ui/dialog";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
@@ -50,11 +59,23 @@ interface Props {
|
||||
|
||||
export default function RoleIndex({ roles, filters = {} }: Props) {
|
||||
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [deleteName, setDeleteName] = useState<string>('');
|
||||
const [modelOpen, setModelOpen] = useState(false);
|
||||
|
||||
const handleDelete = (id: number, name: string) => {
|
||||
if (confirm(`確定要刪除角色「${name}」嗎?此操作無法復原。`)) {
|
||||
router.delete(route('roles.destroy', id), {
|
||||
onSuccess: () => toast.success('角色已刪除'),
|
||||
const confirmDelete = (id: number, name: string) => {
|
||||
setDeleteId(id);
|
||||
setDeleteName(name);
|
||||
setModelOpen(true);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
router.delete(route('roles.destroy', deleteId), {
|
||||
onSuccess: () => {
|
||||
setModelOpen(false);
|
||||
},
|
||||
onFinish: () => setModelOpen(false),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -212,7 +233,7 @@ export default function RoleIndex({ roles, filters = {} }: Props) {
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
disabled={role.users_count > 0}
|
||||
onClick={() => handleDelete(role.id, role.display_name)}
|
||||
onClick={() => confirmDelete(role.id, role.display_name)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -274,6 +295,23 @@ export default function RoleIndex({ roles, filters = {} }: Props) {
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<AlertDialog open={modelOpen} onOpenChange={setModelOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確定要刪除此角色嗎?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
您即將刪除角色「{deleteName}」。此操作無法復原,請確認是否繼續。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} className="button-filled-error">
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,11 +12,20 @@ import {
|
||||
TableRow,
|
||||
} from "@/Components/ui/table";
|
||||
import { format } from 'date-fns';
|
||||
import { toast } from 'sonner';
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
import { cn } from "@/lib/utils";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
|
||||
interface Role {
|
||||
id: number;
|
||||
@@ -54,12 +63,23 @@ interface Props {
|
||||
|
||||
export default function UserIndex({ users, filters }: Props) {
|
||||
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [deleteName, setDeleteName] = useState<string>('');
|
||||
const [modelOpen, setModelOpen] = useState(false);
|
||||
|
||||
const handleDelete = (id: number, name: string) => {
|
||||
if (confirm(`確定要刪除使用者「${name}」嗎?此操作無法復原。`)) {
|
||||
router.delete(route('users.destroy', id), {
|
||||
onSuccess: () => toast.success('使用者已刪除'),
|
||||
onError: () => toast.error('刪除失敗,請檢查權限'),
|
||||
const confirmDelete = (id: number, name: string) => {
|
||||
setDeleteId(id);
|
||||
setDeleteName(name);
|
||||
setModelOpen(true);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
router.delete(route('users.destroy', deleteId), {
|
||||
onSuccess: () => {
|
||||
setModelOpen(false);
|
||||
},
|
||||
onFinish: () => setModelOpen(false),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -229,7 +249,7 @@ export default function UserIndex({ users, filters }: Props) {
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={() => handleDelete(user.id, user.name)}
|
||||
onClick={() => confirmDelete(user.id, user.name)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -243,7 +263,7 @@ export default function UserIndex({ users, filters }: Props) {
|
||||
</div>
|
||||
|
||||
{/* 分頁元件 - 統一樣式 */}
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
@@ -255,14 +275,33 @@ export default function UserIndex({ users, filters }: Props) {
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[80px] h-8"
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<Pagination links={users.links} />
|
||||
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
|
||||
<Pagination links={users.links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
|
||||
<AlertDialog open={modelOpen} onOpenChange={setModelOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確定要刪除此使用者嗎?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
您即將刪除使用者「{deleteName}」。此操作無法復原,請確認是否繼續。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} className="button-filled-error">
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</AuthenticatedLayout >
|
||||
);
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
/>
|
||||
|
||||
{/* 分頁元件 */}
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
@@ -272,12 +272,14 @@ export default function ProductManagement({ products, categories, units, filters
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[80px] h-8"
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<Pagination links={products.links} />
|
||||
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
|
||||
<Pagination links={products.links} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ProductDialog
|
||||
|
||||
@@ -244,7 +244,7 @@ export default function CreatePurchaseOrder({
|
||||
value={expectedDate || ""}
|
||||
onChange={(e) => setExpectedDate(e.target.value)}
|
||||
min={getTodayDate()}
|
||||
className="h-12 border-gray-200"
|
||||
className="block w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -267,7 +267,7 @@ export default function CreatePurchaseOrder({
|
||||
value={notes || ""}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
placeholder="備註這筆採購單的特殊需求..."
|
||||
className="min-h-[100px] border-gray-200"
|
||||
className="min-h-[100px]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -293,7 +293,7 @@ export default function CreatePurchaseOrder({
|
||||
onChange={(e) => setInvoiceNumber(e.target.value)}
|
||||
placeholder="AB-12345678"
|
||||
maxLength={11}
|
||||
className="h-12 border-gray-200"
|
||||
className="block w-full"
|
||||
/>
|
||||
<p className="text-xs text-gray-500">格式:2 碼英文 + 分隔線 + 8 碼數字</p>
|
||||
</div>
|
||||
@@ -306,7 +306,7 @@ export default function CreatePurchaseOrder({
|
||||
type="date"
|
||||
value={invoiceDate}
|
||||
onChange={(e) => setInvoiceDate(e.target.value)}
|
||||
className="h-12 border-gray-200"
|
||||
className="block w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -321,7 +321,7 @@ export default function CreatePurchaseOrder({
|
||||
placeholder="0"
|
||||
min="0"
|
||||
step="0.01"
|
||||
className="h-12 border-gray-200"
|
||||
className="block w-full"
|
||||
/>
|
||||
{invoiceAmount && totalAmount > 0 && parseFloat(invoiceAmount) !== totalAmount && (
|
||||
<p className="text-xs text-amber-600">
|
||||
|
||||
@@ -2,20 +2,26 @@
|
||||
* 採購單管理主頁面
|
||||
*/
|
||||
|
||||
import { useState, useCallback } from "react";
|
||||
import { Plus, ShoppingCart } from 'lucide-react';
|
||||
import { useState, useEffect } from "react";
|
||||
import { Plus, ShoppingCart, Search, RotateCcw, Calendar } from 'lucide-react';
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, router } from "@inertiajs/react";
|
||||
import PurchaseOrderTable from "@/Components/PurchaseOrder/PurchaseOrderTable";
|
||||
import { PurchaseOrderFilters } from "@/Components/PurchaseOrder/PurchaseOrderFilters";
|
||||
import { type DateRange } from "@/Components/PurchaseOrder/DateFilter";
|
||||
import type { PurchaseOrder } from "@/types/purchase-order";
|
||||
import { debounce } from "lodash";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { getBreadcrumbs } from "@/utils/breadcrumb";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import { Input } from "@/Components/ui/input";
|
||||
import { Label } from "@/Components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/Components/ui/select";
|
||||
|
||||
interface Props {
|
||||
orders: {
|
||||
@@ -29,6 +35,8 @@ interface Props {
|
||||
search?: string;
|
||||
status?: string;
|
||||
warehouse_id?: string;
|
||||
date_start?: string;
|
||||
date_end?: string;
|
||||
sort_field?: string;
|
||||
sort_direction?: string;
|
||||
per_page?: string;
|
||||
@@ -37,74 +45,70 @@ interface Props {
|
||||
}
|
||||
|
||||
export default function PurchaseOrderIndex({ orders, filters, warehouses }: Props) {
|
||||
const [searchQuery, setSearchQuery] = useState(filters.search || "");
|
||||
const [statusFilter, setStatusFilter] = useState<string>(filters.status || "all");
|
||||
const [requesterFilter, setRequesterFilter] = useState<string>(filters.warehouse_id || "all");
|
||||
// 篩選狀態
|
||||
const [search, setSearch] = useState(filters.search || "");
|
||||
const [status, setStatus] = useState<string>(filters.status || "all");
|
||||
const [warehouseId, setWarehouseId] = useState<string>(filters.warehouse_id || "all");
|
||||
const [dateStart, setDateStart] = useState(filters.date_start || "");
|
||||
const [dateEnd, setDateEnd] = useState(filters.date_end || "");
|
||||
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
|
||||
const [dateRange, setDateRange] = useState<DateRange | null>(null);
|
||||
|
||||
const handleFilterChange = (newFilters: any) => {
|
||||
router.get("/purchase-orders", {
|
||||
...filters,
|
||||
...newFilters,
|
||||
page: 1,
|
||||
}, {
|
||||
preserveState: true,
|
||||
replace: true,
|
||||
});
|
||||
// 同步 URL 參數到 State (雖有初始值,但若由外部連結進入可確保同步)
|
||||
useEffect(() => {
|
||||
setSearch(filters.search || "");
|
||||
setStatus(filters.status || "all");
|
||||
setWarehouseId(filters.warehouse_id || "all");
|
||||
setDateStart(filters.date_start || "");
|
||||
setDateEnd(filters.date_end || "");
|
||||
setPerPage(filters.per_page || "10");
|
||||
}, [filters]);
|
||||
|
||||
const handleFilter = () => {
|
||||
router.get(
|
||||
route('purchase-orders.index'),
|
||||
{
|
||||
search,
|
||||
status: status === 'all' ? undefined : status,
|
||||
warehouse_id: warehouseId === 'all' ? undefined : warehouseId,
|
||||
date_start: dateStart,
|
||||
date_end: dateEnd,
|
||||
per_page: perPage,
|
||||
sort_field: filters.sort_field,
|
||||
sort_direction: filters.sort_direction,
|
||||
},
|
||||
{ preserveState: true, replace: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleSearch = useCallback(
|
||||
debounce((value: string) => {
|
||||
handleFilterChange({ search: value });
|
||||
}, 500),
|
||||
[filters]
|
||||
);
|
||||
const handleReset = () => {
|
||||
setSearch("");
|
||||
setStatus("all");
|
||||
setWarehouseId("all");
|
||||
setDateStart("");
|
||||
setDateEnd("");
|
||||
|
||||
const onSearchChange = (value: string) => {
|
||||
setSearchQuery(value);
|
||||
handleSearch(value);
|
||||
};
|
||||
|
||||
const onStatusChange = (value: string) => {
|
||||
setStatusFilter(value);
|
||||
handleFilterChange({ status: value });
|
||||
};
|
||||
|
||||
const onWarehouseChange = (value: string) => {
|
||||
setRequesterFilter(value);
|
||||
handleFilterChange({ warehouse_id: value });
|
||||
};
|
||||
|
||||
const handleClearFilters = () => {
|
||||
setSearchQuery("");
|
||||
setStatusFilter("all");
|
||||
setRequesterFilter("all");
|
||||
setDateRange(null);
|
||||
router.get("/purchase-orders");
|
||||
};
|
||||
|
||||
const hasActiveFilters = searchQuery !== "" || statusFilter !== "all" || requesterFilter !== "all" || dateRange !== null;
|
||||
|
||||
const handleNavigateToCreateOrder = () => {
|
||||
router.get("/purchase-orders/create");
|
||||
router.get(route('purchase-orders.index'));
|
||||
};
|
||||
|
||||
const handlePerPageChange = (value: string) => {
|
||||
setPerPage(value);
|
||||
router.get("/purchase-orders", {
|
||||
...filters,
|
||||
per_page: value,
|
||||
page: 1,
|
||||
}, {
|
||||
preserveState: false,
|
||||
replace: true,
|
||||
});
|
||||
router.get(
|
||||
route("purchase-orders.index"),
|
||||
{
|
||||
...filters,
|
||||
per_page: value,
|
||||
},
|
||||
{ preserveState: false, replace: true, preserveScroll: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleNavigateToCreateOrder = () => {
|
||||
router.get(route('purchase-orders.create'));
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout breadcrumbs={getBreadcrumbs("purchaseOrders")}>
|
||||
<Head title="採購管理 - 管理採購單" />
|
||||
<Head title="採購單管理" />
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
@@ -129,20 +133,105 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-6">
|
||||
<PurchaseOrderFilters
|
||||
searchQuery={searchQuery}
|
||||
statusFilter={statusFilter}
|
||||
requesterFilter={requesterFilter}
|
||||
warehouses={warehouses}
|
||||
onSearchChange={onSearchChange}
|
||||
onStatusChange={onStatusChange}
|
||||
onRequesterChange={onWarehouseChange}
|
||||
onClearFilters={handleClearFilters}
|
||||
hasActiveFilters={hasActiveFilters}
|
||||
dateRange={dateRange}
|
||||
onDateRangeChange={setDateRange}
|
||||
/>
|
||||
{/* 篩選區塊 */}
|
||||
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4">
|
||||
{/* 關鍵字搜尋 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">關鍵字搜尋</Label>
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
placeholder="搜尋採購單號、廠商..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
className="pl-9"
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 狀態篩選 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">訂單狀態</Label>
|
||||
<Select value={status} onValueChange={setStatus}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="選擇狀態" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">全部狀態</SelectItem>
|
||||
<SelectItem value="draft">草稿</SelectItem>
|
||||
<SelectItem value="pending">待審核</SelectItem>
|
||||
<SelectItem value="processing">處理中</SelectItem>
|
||||
<SelectItem value="shipping">運送中</SelectItem>
|
||||
<SelectItem value="confirming">待確認</SelectItem>
|
||||
<SelectItem value="completed">已完成</SelectItem>
|
||||
<SelectItem value="cancelled">已取消</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 倉庫篩選 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">入庫倉庫</Label>
|
||||
<SearchableSelect
|
||||
value={warehouseId}
|
||||
onValueChange={setWarehouseId}
|
||||
options={[
|
||||
{ label: "全部倉庫", value: "all" },
|
||||
...warehouses.map(w => ({ label: w.name, value: String(w.id) }))
|
||||
]}
|
||||
placeholder="選擇倉庫"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 日期範圍 - 開始 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">開始日期</Label>
|
||||
<div className="relative">
|
||||
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
type="date"
|
||||
value={dateStart}
|
||||
onChange={(e) => setDateStart(e.target.value)}
|
||||
className="pl-9 block w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 日期範圍 - 結束 */}
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-gray-500">結束日期</Label>
|
||||
<div className="relative">
|
||||
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
type="date"
|
||||
value={dateEnd}
|
||||
onChange={(e) => setDateEnd(e.target.value)}
|
||||
className="pl-9 block w-full text-left"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleReset}
|
||||
className="flex items-center gap-2 button-outlined-primary"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
重置條件
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleFilter}
|
||||
className="flex items-center gap-2 button-filled-primary"
|
||||
>
|
||||
<Search className="h-4 w-4" />
|
||||
查詢紀錄
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<PurchaseOrderTable
|
||||
@@ -150,7 +239,7 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
|
||||
/>
|
||||
|
||||
{/* 分頁元件 - 統一樣式 */}
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
@@ -162,12 +251,14 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[80px] h-8"
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<Pagination links={orders.links} />
|
||||
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
|
||||
<Pagination links={orders.links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
|
||||
8
resources/js/Pages/Vendor/Index.tsx
vendored
8
resources/js/Pages/Vendor/Index.tsx
vendored
@@ -202,7 +202,7 @@ export default function VendorManagement({ vendors, filters }: PageProps) {
|
||||
/>
|
||||
|
||||
{/* 分頁元件 - 統一樣式 */}
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
@@ -214,12 +214,14 @@ export default function VendorManagement({ vendors, filters }: PageProps) {
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[80px] h-8"
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<Pagination links={vendors.links} />
|
||||
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
|
||||
<Pagination links={vendors.links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
|
||||
@@ -146,7 +146,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
|
||||
value={data.batchNumber}
|
||||
onChange={(e) => setData("batchNumber", e.target.value)}
|
||||
placeholder="例:FL20251101"
|
||||
className="button-outlined-primary"
|
||||
className="border-gray-300"
|
||||
// 目前後端可能尚未支援儲存,但依需求顯示
|
||||
/>
|
||||
</div>
|
||||
@@ -172,7 +172,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
|
||||
setData("quantity", parseFloat(e.target.value) || 0)
|
||||
}
|
||||
placeholder="0"
|
||||
className={`button-outlined-primary ${errors.quantity ? "border-red-500" : ""}`}
|
||||
className={`border-gray-300 ${errors.quantity ? "border-red-500" : ""}`}
|
||||
/>
|
||||
{errors.quantity && <p className="text-xs text-red-500">{errors.quantity}</p>}
|
||||
<p className="text-sm text-gray-500">
|
||||
@@ -194,7 +194,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
|
||||
type="date"
|
||||
value={data.expiryDate}
|
||||
onChange={(e) => setData("expiryDate", e.target.value)}
|
||||
className="button-outlined-primary"
|
||||
className="border-gray-300"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -207,7 +207,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
|
||||
onChange={(e) =>
|
||||
setData("lastInboundDate", e.target.value)
|
||||
}
|
||||
className="button-outlined-primary"
|
||||
className="border-gray-300"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -220,7 +220,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
|
||||
onChange={(e) =>
|
||||
setData("lastOutboundDate", e.target.value)
|
||||
}
|
||||
className="button-outlined-primary"
|
||||
className="border-gray-300"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user