This commit is contained in:
Viet An
2026-04-13 21:58:04 +07:00
parent 631527225e
commit 0011c3ced9
25 changed files with 1956 additions and 686 deletions

View File

@@ -1,75 +1,61 @@
<script setup>
const props = defineProps({
id: Number,
code: String,
employee: Number,
employee__name: String,
customer: Number,
customer__name: String,
customer__phone: String,
total: String,
status: Number,
status__name: String,
status__color: String,
payment_status: Number,
payment_status__name: String,
payment_status__color: String,
delivery_status: Number,
delivery_status__name: String,
delivery_status__color: String,
order__products: Array,
create_time: String
order: Object,
selected: Boolean
});
const { $dayjs, $shortenCurrency } = useNuxtApp();
const emit = defineEmits(['selectOrder', 'unselect'])
</script>
<template>
<tr>
<tr
:class="['is-clickable', selected && 'is-selected']"
@click="selected ? emit('unselect') : emit('selectOrder', order.id) "
>
<td>
<div>
<p class="fs-15 font-semibold">{{ code }}</p>
<p class="fs-13 has-text-grey">{{ employee__name }}</p>
<p class="fs-15 font-semibold">{{ order.code }}</p>
<p class="has-text-grey">{{ order.employee__name }}</p>
</div>
</td>
<td>
<div>
<p>{{ customer__name }}</p>
<div class="is-flex is-gap-0.5 is-align-items-center mt-1 fs-13 has-text-grey">
<p>{{ order.customer__name }}</p>
<div class="is-flex is-gap-0.5 is-align-items-center mt-1 has-text-grey">
<Icon name="material-symbols:call-outline-rounded"
:size="15"
/>
<span class="fs-12">{{ customer__phone }}</span>
<span class="fs-12">{{ order.customer__phone }}</span>
</div>
</div>
</td>
<td class="has-text-right">
<div>
<p class="font-semibold">{{ $shortenCurrency(total) }}</p>
<p class="fs-13 has-text-grey">{{ order__products.length }} SP</p>
<p class="fs-14 font-semibold">{{ $shortenCurrency(order.total) }}</p>
<p class="has-text-grey">{{ order.order__products.length }} SP</p>
</div>
</td>
<td class="has-text-centered">
<span :class="[
'tag rounded-full',
`has-background-${status__color}-80 has-text-${status__color}-25`
`has-background-${order.status__color}-80 has-text-${order.status__color}-25`
]">
{{ status__name }}
{{ order.status__name }}
</span>
</td>
<td>
<p :class="`has-text-${payment_status__color}-40`">{{ payment_status__name }}</p>
<p :class="`has-text-${order.payment_status__color}-40`">{{ order.payment_status__name }}</p>
</td>
<td>
<p :class="`has-text-${delivery_status__color}-40`">{{ delivery_status__name }}</p>
<p :class="`has-text-${order.delivery_status__color}-40`">{{ order.delivery_status__name }}</p>
</td>
<td>
<div>
<div class="is-flex is-gap-0.5">
<Icon :size="18" name="material-symbols:calendar-month-outline-rounded" />
<span class="fs-13">{{ $dayjs(create_time).format('L') }}</span>
<span>{{ $dayjs(order.create_time).format('L') }}</span>
</div>
<p class="has-text-grey fs-12">{{ $dayjs(create_time).format('HH:mm') }}</p>
<p class="has-text-grey fs-12">{{ $dayjs(order.create_time).format('HH:mm') }}</p>
</div>
</td>
<td>
@@ -78,6 +64,10 @@ const { $dayjs, $shortenCurrency } = useNuxtApp();
</tr>
</template>
<style scoped>
tr.is-selected {
--bulma-table-row-active-background-color: var(--bulma-primary-95);
color: unset;
}
td {
vertical-align: middle;
--bulma-table-cell-padding: 0.75em;

View File

@@ -1,5 +1,9 @@
<script setup>
import OrderRow from '@/components/orders/OrderRow.vue';
import SelectedOrder from '@/components/orders/SelectedOrder.vue';
import { pull } from 'es-toolkit';
const { $dayjs } = useNuxtApp();
const orders = [
{
@@ -62,7 +66,7 @@ const orders = [
status__color: 'blue',
payment_status: 2,
payment_status__name: 'Một phần',
payment_status__color: 'orange',
payment_status__color: 'yellow',
delivery_status: 2,
delivery_status__name: 'Sẵn sàng',
delivery_status__color: 'blue',
@@ -186,46 +190,408 @@ const orders = [
],
create_time: '2026-04-04T23:21:11.587660+07:00'
},
{
id: 5,
code: 'SO005',
employee: 5,
employee__name: 'Hoàng Văn E',
customer: 7,
customer__name: 'Đỗ Văn G',
customer__phone: '0945781113',
total: '9400000.00',
status: 2,
status__name: 'Đã xác nhận',
status__color: 'blue',
payment_status: 1,
payment_status__name: 'Chưa thanh toán',
payment_status__color: 'red',
delivery_status: 1,
delivery_status__name: 'Chờ xử lý',
delivery_status__color: 'grey',
order__products: [
{
id: 12,
name: 'Kem mắt chống lão hóa',
unit_price: '550000.00',
quantity: 10,
discount: null,
total: '5500000.00'
},
{
id: 13,
name: 'Serum Vitamin C 30ml',
unit_price: '450000.00',
quantity: 8,
discount: 0.05,
total: '3420000.00'
},
{
id: 14,
name: 'Gel rửa mặt làm sạch sâu',
unit_price: '140000.00',
quantity: 5,
discount: 0.15,
total: '595000.00'
},
],
create_time: '2026-04-07T11:21:46.587660+07:00'
},
{
id: 6,
code: 'SO006',
employee: 1,
employee__name: 'Trần Thị B',
customer: 8,
customer__name: 'Bùi Thị H',
customer__phone: '0933184392',
total: '4200000.00',
status: 1,
status__name: 'Nháp',
status__color: 'yellow',
payment_status: 1,
payment_status__name: 'Chưa thanh toán',
payment_status__color: 'red',
delivery_status: 1,
delivery_status__name: 'Chờ xử lý',
delivery_status__color: 'grey',
order__products: [
{
id: 15,
name: 'Toner cân bằng da 200ml',
unit_price: '180000.00',
quantity: 15,
discount: null,
total: '2700000.00'
},
{
id: 16,
name: 'Mặt nạ collagen 10 miếng',
unit_price: '320000.00',
quantity: 5,
discount: 0.05,
total: '1520000.00'
},
],
create_time: '2026-04-07T13:17:36.587660+07:00'
},
{
id: 7,
code: 'SO007',
employee: 5,
employee__name: 'Hoàng Văn E',
customer: 9,
customer__name: 'Ngô Văn I',
customer__phone: '0978335172',
total: '15600000.00',
status: 3,
status__name: 'Đang giao',
status__color: 'orange',
payment_status: 3,
payment_status__name: 'Đã thanh toán',
payment_status__color: 'green',
delivery_status: 2,
delivery_status__name: 'Hoàn thành',
delivery_status__color: 'green',
order__products: [
{
id: 17,
name: 'Kem chống nắng SPF 50+',
unit_price: '280000.00',
quantity: 30,
discount: 0.1,
total: '7560000.00'
},
{
id: 18,
name: 'Phấn nền BB cream',
unit_price: '220000.00',
quantity: 25,
discount: 0.05,
total: '5225000.00'
},
{
id: 19,
name: 'Kem dưỡng ẩm ban đêm',
unit_price: '380000.00',
quantity: 8,
discount: 0.05,
total: '2880000.00'
},
],
create_time: '2026-06-04T09:30:12.587660+07:00'
},
{
id: 8,
code: 'SO008',
employee: 1,
employee__name: 'Trần Thị B',
customer: 11,
customer__name: 'Đinh Thị K',
customer__phone: '0922104853',
total: '7900000.00',
status: 2,
status__name: 'Đã xác nhận',
status__color: 'blue',
payment_status: 2,
payment_status__name: 'Một phần',
payment_status__color: 'yellow',
delivery_status: 2,
delivery_status__name: 'Sẵn sàng',
delivery_status__color: 'blue',
order__products: [
{
id: 20,
name: 'Nước tẩy trang 3 trong 1',
unit_price: '195000.00',
quantity: 20,
discount: 0.05,
total: '3705000.00'
},
{
id: 21,
name: 'Sữa rửa mặt trà xanh 150ml',
unit_price: '150000.00',
quantity: 18,
discount: null,
total: '2700000.00'
},
{
id: 22,
name: 'Dầu gội thảo mộc 500ml',
unit_price: '120000.00',
quantity: 13,
discount: 0.05,
total: '1482000.00'
},
],
create_time: '2026-04-06T16:01:22.587660+07:00'
},
];
const statuses = [
{
id: 1,
name: 'Nháp',
color: 'yellow',
},
{
id: 2,
name: 'Đã xác nhận',
color: 'blue',
},
{
id: 3,
name: 'Đang giao',
color: 'orange',
},
{
id: 4,
name: 'Hoàn thành',
color: 'green',
},
];
const paymentStatuses = [
{
id: 1,
name: 'Chưa thanh toán',
color: 'red',
},
{
id: 2,
name: 'Một phần',
color: 'yellow',
},
{
id: 3,
name: 'Đã thanh toán',
color: 'green',
}
];
const employees = [
{
id: 1,
name: 'Trần Thị B',
},
{
id: 5,
name: 'Hoàng Văn E',
},
]
const input = ref();
const dateRange = ref({
from: null,
to: null,
});
const selectedStatuses = ref([]);
const selectedPaymentStatus = ref();
const selectedEmployee = ref();
const filteredOrders = computed(() => {
const filteredByInput = orders.filter(order => {
if (!input.value) return true;
const values = Object.values(order);
const strValues = values.filter(v => typeof v === 'string');
return strValues.some(str => str.toLowerCase().includes(input.value.toLowerCase()));
});
const filteredByStatuses = filteredByInput.filter(order => {
if (selectedStatuses.value.length === 0) return true;
return selectedStatuses.value.includes(order.status);
});
const filteredByPaymentStatuses = filteredByStatuses.filter(order => {
if (!selectedPaymentStatus.value) return true;
return order.payment_status === selectedPaymentStatus.value;
});
const filteredByEmployees = filteredByPaymentStatuses.filter(order => {
if (!selectedEmployee.value) return true;
return order.employee === selectedEmployee.value;
});
const filteredByDates = filteredByEmployees.filter(order => {
if (!dateRange.value) return true;
const from = $dayjs(dateRange.value.from || 0);
const to = $dayjs(dateRange.value.to || undefined);
const createTime = $dayjs(order.create_time);
return createTime.isSameOrAfter(from) && createTime.isSameOrBefore(to);
})
return filteredByDates;
});
const selectedOrder = ref(null);
watch(filteredOrders, () => {
selectedOrder.value = null;
});
function toggleStatus(id) {
if (selectedStatuses.value.includes(id)) {
selectedStatuses.value = pull(selectedStatuses.value, [id])
} else {
selectedStatuses.value.push(id);
}
}
</script>
<template>
<div>
<div class="card">
<div class="card-content"></div>
</div>
<div class="card">
<div class="card-content p-0">
<p class="p-5 fs-17 font-semibold is-flex is-align-items-center is-gap-1">
<Icon name="material-symbols:list-alt-outline-rounded" :size="22" />
<span>Danh sách đơn hàng ({{ orders.length }})</span>
</p>
<table class="table is-fullwidth is-hoverable fs-14">
<thead>
<tr>
<th>Đơn hàng</th>
<th>Khách hàng</th>
<th class="has-text-right">Tổng tiền</th>
<th class="has-text-centered">Trạng thái</th>
<th>Thanh toán</th>
<th>Giao hàng</th>
<th>Ngày tạo</th>
<th>Thao tác</th>
</tr>
</thead>
<tbody>
<OrderRow
v-for="order in orders"
:key="order.id"
v-bind="order"
<div class="card-content">
<div class="is-flex is-gap-2 is-align-items-center">
<div class="field m-0">
<p class="control has-icons-left">
<input v-model="input" class="input" type="text" placeholder="Tìm kiếm mã đơn, khách hàng..." />
<span class="icon is-small is-left">
<Icon name="material-symbols:search-rounded" :size="24" />
</span>
</p>
</div>
<div class="is-flex is-gap-1 is-align-items-center">
<!-- Date pickers -->
<Datepicker v-bind="{
record: dateRange,
attr: 'from',
maxdate: new Date(),
onDate: (e) => dateRange.from = e
}" />
<span></span>
<Datepicker v-bind="{
record: dateRange,
attr: 'to',
maxdate: new Date(),
onDate: (e) => dateRange.to = e
}" />
</div>
<div class="select">
<select v-model="selectedPaymentStatus">
<option :value="undefined">Phương thức thanh toán</option>
<option
v-for="paymentStatus in paymentStatuses"
:key="paymentStatus.id"
:value="paymentStatus.id"
>
{{ paymentStatus.name }}
</option>
</select>
</div>
<div class="select">
<select v-model="selectedEmployee">
<option :value="undefined">Nhân viên</option>
<option
v-for="employee in employees"
:key="employee.id"
:value="employee.id"
>
{{ employee.name }}
</option>
</select>
</div>
</div>
<div class="is-flex is-gap-1 mt-3">
<button
v-for="status in statuses"
:key="status.id"
:class="[
'tag fs-13 is-rounded',
selectedStatuses.includes(status.id) && `has-background-${status.color}-80`
]"
@click="toggleStatus(status.id)"
>
{{ status.name }}
<Icon
v-if="selectedStatuses.includes(status.id)"
name="material-symbols:check-rounded"
:size="18"
class="ml-1"
/>
</tbody>
</table>
</button>
</div>
</div>
</div>
<div class="fixed-grid has-3-cols">
<div class="grid">
<div :class="['cell', selectedOrder ? 'is-col-span-2' : 'is-col-span-3']">
<div class="card">
<div class="card-content p-0">
<p class="p-5 fs-17 font-semibold is-flex is-align-items-center is-gap-1">
<Icon name="material-symbols:list-alt-outline-rounded" :size="22" />
<span>Danh sách đơn hàng ({{ filteredOrders.length }})</span>
</p>
<table class="table is-fullwidth is-hoverable fs-13">
<thead>
<tr>
<th class="font-semibold">Đơn hàng</th>
<th class="font-semibold">Khách hàng</th>
<th class="font-semibold has-text-right">Tổng tiền</th>
<th class="font-semibold has-text-centered">Trạng thái</th>
<th class="font-semibold">Thanh toán</th>
<th class="font-semibold">Giao hàng</th>
<th class="font-semibold">Ngày tạo</th>
<th class="font-semibold">Thao tác</th>
</tr>
</thead>
<tbody>
<OrderRow
v-for="order in filteredOrders"
:key="order.id"
v-bind="{ order, selected: order.id === selectedOrder?.id }"
@selectOrder="(id) => {
selectedOrder = filteredOrders.find(order => order.id === id);
}"
@unselect="selectedOrder = null"
/>
</tbody>
</table>
</div>
</div>
</div>
<SelectedOrder :order="selectedOrder" @unselect="selectedOrder = null" />
</div>
</div>
</div>
</template>
<style scoped>
th {
font-weight: 600;
}
</style>

View File

@@ -0,0 +1,105 @@
<script setup>
const props = defineProps({
order: Object
});
const { $dayjs, $numtoString } = useNuxtApp();
const emit = defineEmits(['unselect']);
</script>
<template>
<div v-if="order" class="cell relative fs-14">
<div class="card">
<button
@click="emit('unselect')"
class="button is-white rounded-full has-text-grey absolute size-8 is-flex is-justify-content-center is-align-items-center"
style="right: 0.5rem; top: 0.5rem;"
>
<span class="icon">
<Icon name="material-symbols:close-rounded" :size="22" />
</span>
</button>
<div class="card-content">
<div>
<div class="is-flex is-gap-2 is-align-items-center">
<span class="fs-17 font-bold">{{ order.code }}</span>
<span :class="[
'tag rounded-full',
`has-background-${order.status__color}-80 has-text-${order.status__color}-25`
]">
{{ order.status__name }}
</span>
</div>
<div class="is-flex is-gap-0.5 is-flex-direction-column mt-2">
<div class="is-flex is-gap-1 is-align-items-center">
<Icon name="material-symbols:person-outline-rounded" :size="18" />
<p>{{ order.customer__name }}</p>
</div>
<div class="is-flex is-gap-1 is-align-items-center">
<Icon name="material-symbols:call-outline-rounded" :size="18" />
<p>{{ order.customer__phone }}</p>
</div>
<div class="is-flex is-gap-1 is-align-items-center">
<Icon name="material-symbols:calendar-today-outline-rounded" :size="18" />
<p>{{ $dayjs(order.create_time).format('LL') }}</p>
</div>
</div>
<div class="p-4 has-background-primary-95 rounded-lg mt-6">
<p>Tổng giá trị đơn hàng</p>
<p class="font-bold fs-28">{{ $numtoString(order.total, { hasUnit: true }) }}</p>
</div>
</div>
<hr class="m-0" />
<div class="buttons m-0">
<button class="button fs-14 is-flex-grow-1 is-primary">Xác nhận đơn</button>
<button class="button fs-14 is-flex-grow-1">Ghi thanh toán</button>
</div>
<hr class="m-0" />
<div class="tabs is-toggle fs-13">
<ul>
<li class="is-active">
<a>
<span>Chi tiết đơn</span>
</a>
</li>
<li>
<a>
<span>Giao hàng</span>
</a>
</li>
<li>
<a>
<span>Hoá đơn</span>
</a>
</li>
<li>
<a>
<span>Thanh toán</span>
</a>
</li>
<li>
<a>
<span>Lịch sử</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.card-content {
padding: 0; /* 1.5rem */
> div {
padding: var(--bulma-card-content-padding);
}
}
.tabs {
--bulma-tabs-toggle-link-active-background-color: var(--bulma-link-90);
--bulma-tabs-toggle-link-active-border-color: var(--bulma-link-90);
--bulma-tabs-toggle-link-active-color: var(--bulma-link-40);
}
</style>