star-cloud/resources/views/admin/sales/pickup-codes/index.blade.php
sky121113 0332eff9bc [FIX] 修正角色權限顯示邏輯與 UI 組件重構
1. 修正角色編輯頁面、列表頁面與卡片視圖中的權限數量計算邏輯,確保過濾掉無效或隱藏權限。
2. 重構角色權限顯示 UI,將彈窗由不穩定的 Popover 改為基於 Alpine.js x-teleport 的全螢幕置中模窗,解決容器遮擋問題。
3. 抽離並組件化角色清單 (role-list) 與卡片 (role-card) 視圖,提升程式碼複用性。
4. 統一子帳號管理頁面的搜尋與重設按鈕佈局,確保全站視覺一致性。
5. 更新多語系翻譯,修正『租戶』為『客戶』,並新增『全部權限』翻譯項。
6. 完成取貨碼與密碼管理模組的極簡奢華風 UI 遷移。
2026-04-28 16:13:57 +08:00

306 lines
20 KiB
PHP

@extends('layouts.admin')
@section('content')
<div class="space-y-4 pb-20" x-data="{
showCreateModal: false,
selectedMachine: '',
selectedSlot: '',
expiresHours: 24,
slots: [],
loadingSlots: false,
isLoadingTable: false,
async fetchSlots() {
if (!this.selectedMachine) {
this.slots = [];
return;
}
this.loadingSlots = true;
try {
const response = await fetch(`/admin/machines/${this.selectedMachine}/slots-ajax`);
const data = await response.json();
this.slots = data.slots || [];
} catch (error) {
console.error('Error fetching slots:', error);
} finally {
this.loadingSlots = false;
}
},
async fetchPage(url) {
if (!url || this.isLoadingTable) return;
this.isLoadingTable = true;
try {
const res = await fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
const html = await res.text();
const doc = new DOMParser().parseFromString(html, 'text/html');
const newContent = doc.querySelector('#ajax-content-container');
if (newContent) {
document.querySelector('#ajax-content-container').innerHTML = newContent.innerHTML;
window.history.pushState({}, '', url);
if (window.HSStaticMethods?.autoInit) window.HSStaticMethods.autoInit();
}
} catch (e) {
console.error('AJAX Load Failed:', e);
} finally {
this.isLoadingTable = false;
}
}
}">
{{-- Page Header --}}
<x-page-header
:title="__('Pickup Codes')"
:subtitle="__('Generate and manage one-time pickup codes for customers')"
>
<button @click="showCreateModal = true" class="luxury-btn-primary group flex items-center gap-2">
<svg class="w-5 h-5 group-hover:rotate-90 transition-transform duration-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M12 4v16m8-8H4" />
</svg>
<span class="text-sm sm:text-base">{{ __('Generate New Code') }}</span>
</button>
</x-page-header>
{{-- Main Content Card --}}
<div class="luxury-card rounded-3xl p-8 animate-luxury-in relative overflow-hidden">
<x-luxury-spinner show="isLoadingTable" />
<div id="ajax-content-container" :class="{ 'opacity-30 pointer-events-none': isLoadingTable }">
<x-search-bar
:action="route('admin.sales.pickup-codes')"
:value="request('search')"
:placeholder="__('Search by code, machine name or serial...')"
>
<div class="w-full md:w-48">
<select name="status" class="luxury-input w-full text-sm" @change="$el.closest('form').dispatchEvent(new Event('submit', { cancelable: true }))">
<option value="">{{ __('All Status') }}</option>
<option value="active" {{ request('status') === 'active' ? 'selected' : '' }}>{{ __('Active') }}</option>
<option value="used" {{ request('status') === 'used' ? 'selected' : '' }}>{{ __('Used') }}</option>
<option value="expired" {{ request('status') === 'expired' ? 'selected' : '' }}>{{ __('Expired') }}</option>
<option value="cancelled" {{ request('status') === 'cancelled' ? 'selected' : '' }}>{{ __('Cancelled') }}</option>
</select>
</div>
</x-search-bar>
{{-- Table (Desktop) --}}
<div class="hidden xl:block overflow-x-auto">
<table class="w-full text-left border-separate border-spacing-0">
<thead>
<tr class="bg-slate-50/50 dark:bg-slate-900/10">
<th class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800">
{{ __('Code') }}
</th>
<th class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800">
{{ __('Machine / Slot') }}
</th>
<th class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800">
{{ __('Expires At') }}
</th>
<th class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800">
{{ __('Status') }}
</th>
<th class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800 text-right">
{{ __('Actions') }}
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 dark:divide-slate-800/80">
@forelse ($pickupCodes as $code)
<tr class="group hover:bg-slate-50/50 dark:hover:bg-white/[0.02] transition-colors duration-200">
<td class="px-6 py-6 whitespace-nowrap">
<span class="text-lg font-black font-mono text-cyan-600 dark:text-cyan-400 tracking-tighter bg-cyan-50 dark:bg-cyan-500/10 px-3 py-1 rounded-lg border border-cyan-100 dark:border-cyan-500/20 shadow-sm">
{{ $code->code }}
</span>
</td>
<td class="px-6 py-6">
<div class="text-base font-extrabold text-slate-800 dark:text-slate-100 tracking-tight">{{ $code->machine->name }}</div>
<div class="text-xs font-bold text-slate-400 uppercase tracking-widest">{{ __('Slot') }}: {{ $code->slot_no }}</div>
</td>
<td class="px-6 py-6 whitespace-nowrap">
<div class="text-sm font-black text-slate-600 dark:text-slate-300 font-mono tracking-widest">{{ $code->expires_at->format('Y-m-d H:i') }}</div>
<div class="text-xs font-bold text-slate-400 mt-0.5">{{ $code->expires_at->diffForHumans() }}</div>
</td>
<td class="px-6 py-6 whitespace-nowrap">
@php
$displayStatus = $code->status === 'active' && $code->expires_at->isPast() ? 'expired' : $code->status;
@endphp
<x-status-badge :status="$displayStatus" />
</td>
<td class="px-6 py-6 whitespace-nowrap text-right">
<div class="flex items-center justify-end gap-2">
@if($code->status === 'active' && $code->expires_at->isFuture())
<form action="{{ route('admin.sales.pickup-codes.destroy', $code) }}" method="POST" onsubmit="return confirm('{{ __('Are you sure you want to cancel this code?') }}')">
@csrf
@method('DELETE')
<button type="submit" class="p-2 text-rose-500 hover:bg-rose-500/10 rounded-xl transition-all duration-200" title="{{ __('Cancel Code') }}">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</form>
@endif
</div>
</td>
</tr>
@empty
<x-empty-state mode="table" :colspan="5" :message="__('No pickup codes found')" />
@endforelse
</tbody>
</table>
</div>
{{-- Card Grid (Mobile) --}}
<div class="xl:hidden grid grid-cols-1 md:grid-cols-2 gap-6">
@forelse ($pickupCodes as $code)
<div class="luxury-card p-6 rounded-[2rem] border border-slate-100 dark:border-slate-800 bg-white/50 dark:bg-slate-900/50 transition-all duration-300 group">
{{-- Card Header --}}
<div class="flex items-start justify-between gap-4 mb-6">
<div class="flex items-center gap-4 min-w-0">
<div class="w-14 h-14 rounded-2xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center text-slate-400 border border-slate-200 dark:border-slate-700 group-hover:bg-cyan-500 group-hover:text-white transition-all duration-300 overflow-hidden shadow-sm shrink-0">
<svg class="w-7 h-7" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4" />
</svg>
</div>
<div class="min-w-0">
<h3 class="text-base font-extrabold text-slate-800 dark:text-slate-100 truncate hover:text-cyan-600 dark:hover:text-cyan-400 transition-colors tracking-tight">
{{ $code->code }}
</h3>
<p class="text-xs font-mono font-bold text-slate-400 dark:text-slate-500 uppercase tracking-widest truncate">
{{ $code->machine->name }}
</p>
</div>
</div>
@php
$displayStatus = $code->status === 'active' && $code->expires_at->isPast() ? 'expired' : $code->status;
@endphp
<x-status-badge :status="$displayStatus" size="sm" />
</div>
{{-- Info Grid --}}
<div class="grid grid-cols-2 gap-y-4 mb-6 border-y border-slate-100 dark:border-slate-800/50 py-4">
<div>
<p class="text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest mb-1">{{ __('Slot') }}</p>
<p class="text-sm font-bold text-slate-700 dark:text-slate-300">{{ $code->slot_no }}</p>
</div>
<div>
<p class="text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-widest mb-1">{{ __('Expires At') }}</p>
<p class="text-sm font-bold text-slate-700 dark:text-slate-300 font-mono tracking-tighter">{{ $code->expires_at->format('Y-m-d H:i') }}</p>
</div>
</div>
{{-- Action Buttons --}}
<div class="flex items-center gap-3">
@if($code->status === 'active' && $code->expires_at->isFuture())
<form action="{{ route('admin.sales.pickup-codes.destroy', $code) }}" method="POST" class="flex-1" onsubmit="return confirm('{{ __('Are you sure you want to cancel this code?') }}')">
@csrf
@method('DELETE')
<button type="submit" class="w-full flex items-center justify-center gap-2 py-3 rounded-xl bg-slate-50 dark:bg-slate-800 text-slate-500 dark:text-slate-400 font-bold text-xs hover:bg-rose-500 hover:text-white transition-all duration-300 border border-slate-200/50 dark:border-slate-700/50">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
{{ __('Cancel') }}
</button>
</form>
@else
<div class="flex-1 py-3 text-center text-slate-400 text-xs font-bold uppercase tracking-widest bg-slate-50/50 dark:bg-slate-800/30 rounded-xl">
{{ __('No Actions') }}
</div>
@endif
</div>
</div>
@empty
<div class="col-span-full">
<x-empty-state :message="__('No pickup codes found')" />
</div>
@endforelse
</div>
{{-- Pagination --}}
<div class="mt-8 border-t border-slate-100/50 dark:border-slate-800/50 pt-6">
{{ $pickupCodes->links('vendor.pagination.luxury') }}
</div>
</div>
</div>
{{-- Create Modal --}}
<div x-show="showCreateModal"
class="fixed inset-0 z-50 overflow-y-auto"
x-transition:enter="transition ease-out duration-300"
x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100"
x-transition:leave="transition ease-in duration-200"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
x-cloak>
<div class="flex items-center justify-center min-h-screen px-4 pb-20 text-center sm:block sm:p-0">
<div class="fixed inset-0 transition-opacity bg-slate-900/60 backdrop-blur-sm" @click="showCreateModal = false"></div>
<div class="inline-block overflow-hidden text-left align-bottom transition-all transform bg-white dark:bg-slate-900 rounded-[2.5rem] shadow-2xl sm:my-8 sm:align-middle sm:max-w-lg sm:w-full border border-slate-200/50 dark:border-slate-700/50 animate-luxury-in">
<form action="{{ route('admin.sales.pickup-codes.store') }}" method="POST">
@csrf
<div class="p-10">
<div class="flex items-center justify-between mb-8">
<h3 class="text-2xl font-black text-slate-800 dark:text-white tracking-tight font-display">{{ __('Generate Pickup Code') }}</h3>
<button type="button" @click="showCreateModal = false" class="w-10 h-10 flex items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800 text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 transition-colors">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M6 18L18 6M6 6l12 12" /></svg>
</button>
</div>
<div class="space-y-8">
{{-- Machine Selection --}}
<div>
<label class="block text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-[0.2em] mb-3">{{ __('Select Machine') }}</label>
<select name="machine_id" x-model="selectedMachine" @change="fetchSlots()" class="luxury-input w-full py-3" required>
<option value="">{{ __('Please select a machine') }}</option>
@foreach($machines as $machine)
<option value="{{ $machine->id }}">{{ $machine->name }} ({{ $machine->serial_no }})</option>
@endforeach
</select>
</div>
{{-- Slot Selection --}}
<div>
<label class="block text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-[0.2em] mb-3">{{ __('Select Slot') }}</label>
<div class="relative group">
<select name="slot_no" x-model="selectedSlot" class="luxury-input w-full py-3" :disabled="!selectedMachine || loadingSlots" required>
<option value="">{{ __('Select Slot') }}</option>
<template x-for="slot in slots" :key="slot.slot_no">
<option :value="slot.slot_no" x-text="`${slot.slot_no} - ${slot.product_name || 'Empty'}`"></option>
</template>
</select>
<div x-show="loadingSlots" class="absolute right-4 top-3.5">
<svg class="animate-spin h-5 w-5 text-cyan-500" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
</div>
</div>
</div>
{{-- Validity --}}
<div>
<label class="block text-[10px] font-black text-slate-400 dark:text-slate-500 uppercase tracking-[0.2em] mb-3">{{ __('Validity Period (Hours)') }}</label>
<div class="relative">
<input type="number" name="expires_hours" x-model="expiresHours" class="luxury-input w-full py-3 pr-16" min="1" max="720" required>
<div class="absolute right-4 top-3 text-xs font-bold text-slate-400 uppercase tracking-widest">{{ __('Hrs') }}</div>
</div>
<p class="mt-3 text-[10px] text-slate-400 font-bold uppercase tracking-widest flex items-center gap-1.5">
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
{{ __('Max 720 hours (30 days)') }}
</p>
</div>
</div>
</div>
<div class="px-10 py-8 bg-slate-50/50 dark:bg-slate-800/50 flex justify-end gap-4 border-t border-slate-100 dark:border-slate-800">
<button type="button" @click="showCreateModal = false" class="luxury-btn-secondary px-6">
{{ __('Cancel') }}
</button>
<button type="submit" class="luxury-btn-primary px-10" :disabled="!selectedSlot">
{{ __('Generate') }}
</button>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection