Simplify order detail layout
This commit is contained in:
9
app/composables/useOrderDetailPresentation.ts
Normal file
9
app/composables/useOrderDetailPresentation.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export function orderLineStateText(totalPrice?: number | null) {
|
||||||
|
return totalPrice == null
|
||||||
|
? 'Цена уточняется менеджером'
|
||||||
|
: 'Цена согласована менеджером';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function orderDeliveryStateText(deliveryTerms?: string | null) {
|
||||||
|
return deliveryTerms?.trim() || 'Доставка уточняется менеджером';
|
||||||
|
}
|
||||||
@@ -5,9 +5,12 @@ import {
|
|||||||
CompleteOrderDocument,
|
CompleteOrderDocument,
|
||||||
ManagerFinalizeOrderDocument,
|
ManagerFinalizeOrderDocument,
|
||||||
ManagerOrdersDocument,
|
ManagerOrdersDocument,
|
||||||
ManagerSetOrderOfferDocument,
|
|
||||||
StartOrderWorkDocument,
|
StartOrderWorkDocument,
|
||||||
} from '~/composables/graphql/generated';
|
} from '~/composables/graphql/generated';
|
||||||
|
import {
|
||||||
|
orderDeliveryStateText,
|
||||||
|
orderLineStateText,
|
||||||
|
} from '~/composables/useOrderDetailPresentation';
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
middleware: ['manager-only'],
|
middleware: ['manager-only'],
|
||||||
@@ -18,7 +21,6 @@ const orderId = computed(() => String(route.params.id || ''));
|
|||||||
|
|
||||||
const ordersQuery = useQuery(ManagerOrdersDocument, { status: null });
|
const ordersQuery = useQuery(ManagerOrdersDocument, { status: null });
|
||||||
|
|
||||||
const setOfferMutation = useMutation(ManagerSetOrderOfferDocument);
|
|
||||||
const finalizeMutation = useMutation(ManagerFinalizeOrderDocument);
|
const finalizeMutation = useMutation(ManagerFinalizeOrderDocument);
|
||||||
const blockMutation = useMutation(BlockOrderDocument);
|
const blockMutation = useMutation(BlockOrderDocument);
|
||||||
const startWorkMutation = useMutation(StartOrderWorkDocument);
|
const startWorkMutation = useMutation(StartOrderWorkDocument);
|
||||||
@@ -28,43 +30,10 @@ const currentOrder = computed(() =>
|
|||||||
(ordersQuery.result.value?.managerOrders ?? []).find((item) => item.id === orderId.value),
|
(ordersQuery.result.value?.managerOrders ?? []).find((item) => item.id === orderId.value),
|
||||||
);
|
);
|
||||||
|
|
||||||
const offerForm = reactive({
|
|
||||||
deliveryTerms: '',
|
|
||||||
deliveryFee: 0,
|
|
||||||
totalPrice: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
watchEffect(() => {
|
|
||||||
if (!currentOrder.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
offerForm.deliveryTerms = currentOrder.value.deliveryTerms || 'Доставка 3-5 дней';
|
|
||||||
offerForm.deliveryFee = Number(currentOrder.value.deliveryFee ?? 1000);
|
|
||||||
offerForm.totalPrice = Number(currentOrder.value.totalPrice ?? 12500);
|
|
||||||
});
|
|
||||||
|
|
||||||
async function refetchOrder() {
|
async function refetchOrder() {
|
||||||
await ordersQuery.refetch({ status: null });
|
await ordersQuery.refetch({ status: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function publishOffer() {
|
|
||||||
if (!currentOrder.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await setOfferMutation.mutate({
|
|
||||||
input: {
|
|
||||||
orderId: currentOrder.value.id,
|
|
||||||
deliveryTerms: offerForm.deliveryTerms,
|
|
||||||
deliveryFee: Number(offerForm.deliveryFee),
|
|
||||||
totalPrice: Number(offerForm.totalPrice),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await refetchOrder();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function approveOrder() {
|
async function approveOrder() {
|
||||||
if (!currentOrder.value) {
|
if (!currentOrder.value) {
|
||||||
return;
|
return;
|
||||||
@@ -134,49 +103,38 @@ async function completeOrder() {
|
|||||||
<h1 class="manager-title">{{ currentOrder.code }}</h1>
|
<h1 class="manager-title">{{ currentOrder.code }}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid gap-4 lg:grid-cols-[1.1fr_0.9fr]">
|
<div class="space-y-4">
|
||||||
<div class="space-y-4">
|
<OrdersOrderStatusTimelineCard
|
||||||
<OrdersOrderStatusTimelineCard
|
:status="currentOrder.status"
|
||||||
:status="currentOrder.status"
|
:created-at="currentOrder.createdAt"
|
||||||
:created-at="currentOrder.createdAt"
|
/>
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="surface-card rounded-3xl p-5">
|
<div class="surface-card rounded-3xl p-5">
|
||||||
<h2 class="text-xl font-bold text-[#123824]">Состав заказа</h2>
|
<h2 class="text-xl font-bold text-[#123824]">Состав заказа</h2>
|
||||||
<ul class="mt-4 space-y-3">
|
<ul class="mt-4 space-y-3">
|
||||||
<li v-for="item in currentOrder.items" :key="item.id" class="manager-mini-card text-sm text-[#123824]">
|
<li v-for="item in currentOrder.items" :key="item.id" class="manager-mini-card space-y-2">
|
||||||
{{ item.productName }} × {{ item.quantity }}
|
<p class="text-sm font-semibold text-[#123824]">{{ item.productName }} × {{ item.quantity }}</p>
|
||||||
</li>
|
<p class="text-sm text-[#5c7b69]">{{ orderLineStateText(currentOrder.totalPrice) }}</p>
|
||||||
</ul>
|
</li>
|
||||||
</div>
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="surface-card rounded-3xl p-5">
|
<div class="surface-card rounded-3xl p-5">
|
||||||
<h2 class="text-xl font-bold text-[#123824]">Доставка</h2>
|
<h2 class="text-xl font-bold text-[#123824]">Доставка</h2>
|
||||||
<div class="mt-4 grid gap-3 md:grid-cols-2">
|
<div class="mt-4 space-y-3">
|
||||||
<div class="manager-mini-card text-sm text-[#123824]">
|
<div class="manager-mini-card text-sm text-[#123824]">
|
||||||
Адрес: {{ currentOrder.deliveryAddress || 'не выбран' }}
|
Адрес: {{ currentOrder.deliveryAddress || 'Адрес пока не указан' }}
|
||||||
</div>
|
</div>
|
||||||
<div class="manager-mini-card text-sm text-[#123824]">
|
<div class="manager-mini-card text-sm text-[#123824]">
|
||||||
Условия: {{ currentOrder.deliveryTerms || 'еще не указаны' }}
|
{{ orderDeliveryStateText(currentOrder.deliveryTerms) }}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-4">
|
<div class="surface-card rounded-3xl p-5">
|
||||||
<div class="surface-card rounded-3xl p-5">
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||||
<h2 class="text-xl font-bold text-[#123824]">Оффер</h2>
|
<h2 class="text-xl font-bold text-[#123824]">Действия менеджера</h2>
|
||||||
<div class="mt-4 space-y-3">
|
<div class="flex flex-wrap gap-2">
|
||||||
<input v-model="offerForm.deliveryTerms" class="input manager-field w-full" placeholder="Условия доставки">
|
|
||||||
<input v-model="offerForm.deliveryFee" type="number" class="input manager-field w-full" placeholder="Стоимость доставки">
|
|
||||||
<input v-model="offerForm.totalPrice" type="number" class="input manager-field w-full" placeholder="Итоговая стоимость">
|
|
||||||
<button class="btn btn-primary border-0" @click="publishOffer">Публиковать оффер</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="surface-card rounded-3xl p-5">
|
|
||||||
<h2 class="text-xl font-bold text-[#123824]">Действия</h2>
|
|
||||||
<div class="mt-4 flex flex-wrap gap-2">
|
|
||||||
<button class="btn btn-success btn-sm border-0" @click="approveOrder">Подтвердить</button>
|
<button class="btn btn-success btn-sm border-0" @click="approveOrder">Подтвердить</button>
|
||||||
<button class="btn btn-error btn-sm border-0" @click="rejectOrder">Отклонить</button>
|
<button class="btn btn-error btn-sm border-0" @click="rejectOrder">Отклонить</button>
|
||||||
<button class="btn btn-warning btn-sm border-0" @click="blockOrder">Заблокировать</button>
|
<button class="btn btn-warning btn-sm border-0" @click="blockOrder">Заблокировать</button>
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import {
|
|||||||
MyOrdersDocument,
|
MyOrdersDocument,
|
||||||
type MyOrdersQuery,
|
type MyOrdersQuery,
|
||||||
} from '~/composables/graphql/generated';
|
} from '~/composables/graphql/generated';
|
||||||
|
import {
|
||||||
|
orderDeliveryStateText,
|
||||||
|
orderLineStateText,
|
||||||
|
} from '~/composables/useOrderDetailPresentation';
|
||||||
|
|
||||||
type OrderItem = MyOrdersQuery['myOrders'][number];
|
type OrderItem = MyOrdersQuery['myOrders'][number];
|
||||||
|
|
||||||
@@ -46,21 +50,22 @@ const currentOrder = computed<OrderItem | null>(() =>
|
|||||||
<li
|
<li
|
||||||
v-for="item in currentOrder.items"
|
v-for="item in currentOrder.items"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
class="manager-mini-card text-sm text-[#123824]"
|
class="manager-mini-card space-y-2"
|
||||||
>
|
>
|
||||||
{{ item.productName }} × {{ item.quantity }}
|
<p class="text-sm font-semibold text-[#123824]">{{ item.productName }} × {{ item.quantity }}</p>
|
||||||
|
<p class="text-sm text-[#5c7b69]">{{ orderLineStateText(currentOrder.totalPrice) }}</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="surface-card rounded-3xl p-5">
|
<div class="surface-card rounded-3xl p-5">
|
||||||
<h2 class="text-xl font-bold text-[#123824]">Доставка</h2>
|
<h2 class="text-xl font-bold text-[#123824]">Доставка</h2>
|
||||||
<div class="mt-4 grid gap-3 md:grid-cols-2">
|
<div class="mt-4 space-y-3">
|
||||||
<div class="manager-mini-card text-sm text-[#123824]">
|
<div class="manager-mini-card text-sm text-[#123824]">
|
||||||
Адрес: {{ currentOrder.deliveryAddress || 'не выбран' }}
|
Адрес: {{ currentOrder.deliveryAddress || 'Адрес пока не указан' }}
|
||||||
</div>
|
</div>
|
||||||
<div class="manager-mini-card text-sm text-[#123824]">
|
<div class="manager-mini-card text-sm text-[#123824]">
|
||||||
Условия: {{ currentOrder.deliveryTerms || 'еще не указаны' }}
|
{{ orderDeliveryStateText(currentOrder.deliveryTerms) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user