2026-08-03 12:14:12 +02:00
|
|
|
|
<script setup lang="ts">
|
2026-08-09 12:00:18 +03:30
|
|
|
|
import { computed, ref, watch } from 'vue'
|
2026-08-03 12:14:12 +02:00
|
|
|
|
import AdminIcon from '@/components/icons/AdminIcon.vue'
|
|
|
|
|
|
import StatusBadge from '@/components/ui/StatusBadge.vue'
|
2026-08-08 12:44:05 +02:00
|
|
|
|
import { formatCurrency, formatMeterage, formatNumber } from '@/utils/format'
|
2026-08-09 12:00:18 +03:30
|
|
|
|
import { RAW_ORDER_STATUS_LABELS, rawStatusLabel } from '@/utils/orderStatus'
|
|
|
|
|
|
import type { Order, RawOrderStatus } from '@/types'
|
2026-08-03 12:14:12 +02:00
|
|
|
|
|
2026-08-09 12:00:18 +03:30
|
|
|
|
const props = defineProps<{
|
2026-08-03 12:14:12 +02:00
|
|
|
|
order: Order
|
2026-08-09 12:00:18 +03:30
|
|
|
|
settlementLabel: (method?: string | null) => string
|
2026-08-03 12:14:12 +02:00
|
|
|
|
layout?: 'desktop' | 'compact'
|
2026-08-09 12:00:18 +03:30
|
|
|
|
statusSaving?: boolean
|
2026-08-03 12:14:12 +02:00
|
|
|
|
}>()
|
|
|
|
|
|
|
2026-08-09 12:00:18 +03:30
|
|
|
|
const emit = defineEmits<{
|
2026-08-03 12:14:12 +02:00
|
|
|
|
pricing: []
|
|
|
|
|
|
checks: []
|
2026-08-09 12:00:18 +03:30
|
|
|
|
cashReceipt: []
|
|
|
|
|
|
status: [
|
|
|
|
|
|
payload: {
|
|
|
|
|
|
orderId: string
|
|
|
|
|
|
status: RawOrderStatus
|
|
|
|
|
|
note?: string
|
|
|
|
|
|
reason?: string
|
|
|
|
|
|
force?: boolean
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
2026-08-03 12:14:12 +02:00
|
|
|
|
}>()
|
2026-08-09 12:00:18 +03:30
|
|
|
|
|
|
|
|
|
|
const manualMode = ref(false)
|
|
|
|
|
|
const nextStatus = ref<RawOrderStatus | ''>('')
|
|
|
|
|
|
const statusNote = ref('')
|
|
|
|
|
|
|
|
|
|
|
|
const allStatuses = Object.keys(RAW_ORDER_STATUS_LABELS) as RawOrderStatus[]
|
|
|
|
|
|
|
|
|
|
|
|
const transitions = computed(() => props.order.allowedTransitions ?? [])
|
|
|
|
|
|
|
|
|
|
|
|
const statusOptions = computed<RawOrderStatus[]>(() =>
|
|
|
|
|
|
manualMode.value
|
|
|
|
|
|
? allStatuses.filter((s) => s !== props.order.rawStatus)
|
|
|
|
|
|
: [...transitions.value],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const noteRequired = computed(() => manualMode.value)
|
|
|
|
|
|
const canSubmitStatus = computed(
|
|
|
|
|
|
() => !!nextStatus.value && (!noteRequired.value || statusNote.value.trim().length > 0),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
watch([() => props.order.id, manualMode], () => {
|
|
|
|
|
|
nextStatus.value = ''
|
|
|
|
|
|
statusNote.value = ''
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
function submitStatus() {
|
|
|
|
|
|
if (!nextStatus.value || !canSubmitStatus.value) return
|
|
|
|
|
|
const note = statusNote.value.trim() || undefined
|
|
|
|
|
|
emit('status', {
|
|
|
|
|
|
orderId: props.order.id,
|
|
|
|
|
|
status: nextStatus.value,
|
|
|
|
|
|
note,
|
|
|
|
|
|
reason: manualMode.value ? note : undefined,
|
|
|
|
|
|
force: manualMode.value || undefined,
|
|
|
|
|
|
})
|
|
|
|
|
|
nextStatus.value = ''
|
|
|
|
|
|
statusNote.value = ''
|
|
|
|
|
|
}
|
2026-08-03 12:14:12 +02:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div class="order-detail">
|
|
|
|
|
|
<div class="order-detail__id">
|
|
|
|
|
|
<strong>{{ order.orderNumber }}</strong>
|
|
|
|
|
|
<StatusBadge :status="order.status" />
|
2026-08-09 12:00:18 +03:30
|
|
|
|
<span class="order-detail__raw-status">{{ rawStatusLabel(order.rawStatus) }}</span>
|
2026-08-03 12:14:12 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="order-detail__section">
|
|
|
|
|
|
<h3 class="order-detail__section-title">اطلاعات مشتری</h3>
|
|
|
|
|
|
<div class="admin-info-grid">
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<AdminIcon name="building" :size="16" />
|
|
|
|
|
|
<span class="admin-info-row__label">شرکت:</span>
|
|
|
|
|
|
<span class="admin-info-row__value">{{ order.customerName }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<AdminIcon name="phone" :size="16" />
|
|
|
|
|
|
<span class="admin-info-row__label">تلفن:</span>
|
|
|
|
|
|
<span class="admin-info-row__value">{{ order.customerPhone ?? '—' }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<AdminIcon name="id-card" :size="16" />
|
|
|
|
|
|
<span class="admin-info-row__label">شناسه ملی:</span>
|
|
|
|
|
|
<span class="admin-info-row__value">{{ order.customerNationalId ?? '—' }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<AdminIcon name="user" :size="16" />
|
|
|
|
|
|
<span class="admin-info-row__label">نوع مشتری:</span>
|
|
|
|
|
|
<span class="admin-info-row__value">{{ order.customerType ?? '—' }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="order-detail__section">
|
|
|
|
|
|
<h3 class="order-detail__section-title">اطلاعات سفارش</h3>
|
|
|
|
|
|
<div class="admin-info-grid">
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<span class="admin-info-row__label">شرکت:</span>
|
|
|
|
|
|
<span class="admin-info-row__value">{{ order.companyName }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<span class="admin-info-row__label">روش تسویه:</span>
|
|
|
|
|
|
<span class="admin-info-row__value">
|
2026-08-09 12:00:18 +03:30
|
|
|
|
{{ settlementLabel(order.settlementMethod) }}
|
2026-08-03 12:14:12 +02:00
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<span class="admin-info-row__label">متراژ کل:</span>
|
|
|
|
|
|
<span class="admin-info-row__value">{{ formatMeterage(order.meterage) }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="admin-info-row">
|
|
|
|
|
|
<span class="admin-info-row__label">مبلغ کل:</span>
|
2026-08-08 12:44:05 +02:00
|
|
|
|
<span class="admin-info-row__value">
|
|
|
|
|
|
{{ order.totalAmount != null ? formatCurrency(order.totalAmount) : 'پس از قیمتگذاری' }}
|
|
|
|
|
|
</span>
|
2026-08-03 12:14:12 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="order.items?.length" class="order-detail__section">
|
|
|
|
|
|
<h3 class="order-detail__section-title">محصولات سفارش</h3>
|
|
|
|
|
|
<div v-if="layout === 'desktop'" class="admin-table-wrap">
|
|
|
|
|
|
<table class="admin-table admin-table--compact">
|
|
|
|
|
|
<thead>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<th>کالیته</th>
|
|
|
|
|
|
<th>محصول</th>
|
|
|
|
|
|
<th>رنگ / نوع</th>
|
|
|
|
|
|
<th>متراژ</th>
|
|
|
|
|
|
<th>قیمت تأیید شده</th>
|
|
|
|
|
|
<th>مبلغ کل</th>
|
|
|
|
|
|
<th>وضعیت</th>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
|
|
|
<tr v-for="item in order.items" :key="item.id">
|
|
|
|
|
|
<td>{{ item.catalogCode }}</td>
|
|
|
|
|
|
<td>{{ item.productName }}</td>
|
|
|
|
|
|
<td>{{ item.color }}</td>
|
2026-08-08 12:44:05 +02:00
|
|
|
|
<td>{{ formatNumber(item.confirmedMeterage ?? item.requestedMeterage) }}</td>
|
|
|
|
|
|
<td>{{ item.supplyPrice != null ? formatCurrency(item.supplyPrice) : '—' }}</td>
|
|
|
|
|
|
<td>{{ item.totalAmount != null ? formatCurrency(item.totalAmount) : '—' }}</td>
|
2026-08-03 12:14:12 +02:00
|
|
|
|
<td><StatusBadge status="pending_review" /></td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<ul v-else class="order-detail__items">
|
|
|
|
|
|
<li v-for="item in order.items" :key="item.id" class="order-detail__item">
|
|
|
|
|
|
<strong>{{ item.productName }}</strong>
|
|
|
|
|
|
<span>{{ item.catalogCode }} · {{ item.color }}</span>
|
2026-08-08 12:44:05 +02:00
|
|
|
|
<span>{{ formatMeterage(item.confirmedMeterage ?? item.requestedMeterage) }}</span>
|
|
|
|
|
|
<span v-if="item.supplyPrice != null">قیمت: {{ formatCurrency(item.supplyPrice) }}</span>
|
|
|
|
|
|
<span v-if="item.totalAmount != null">مبلغ: {{ formatCurrency(item.totalAmount) }}</span>
|
2026-08-03 12:14:12 +02:00
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-08-09 12:00:18 +03:30
|
|
|
|
<div class="order-detail__section order-detail__status">
|
|
|
|
|
|
<div class="order-detail__status-head">
|
|
|
|
|
|
<h3 class="order-detail__section-title">تغییر وضعیت</h3>
|
|
|
|
|
|
<label class="order-detail__manual">
|
|
|
|
|
|
<input v-model="manualMode" type="checkbox" />
|
|
|
|
|
|
<span>تغییر دستی</span>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<p v-if="manualMode" class="order-detail__status-hint">
|
|
|
|
|
|
این گذر خارج از روال استاندارد است؛ ثبت یادداشت اجباری است و در تاریخچهٔ سفارش ذخیره میشود.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p v-else-if="!statusOptions.length" class="order-detail__status-hint">
|
|
|
|
|
|
در این وضعیت گذر خودکاری وجود ندارد. برای تغییر، حالت دستی را فعال کنید.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<template v-if="statusOptions.length">
|
|
|
|
|
|
<div class="admin-form__field">
|
|
|
|
|
|
<label for="next-status">وضعیت بعدی</label>
|
|
|
|
|
|
<select id="next-status" v-model="nextStatus" class="admin-input">
|
|
|
|
|
|
<option value="">انتخاب کنید…</option>
|
|
|
|
|
|
<option v-for="status in statusOptions" :key="status" :value="status">
|
|
|
|
|
|
{{ rawStatusLabel(status) }}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="admin-form__field">
|
|
|
|
|
|
<label for="status-note">
|
|
|
|
|
|
یادداشت{{ noteRequired ? ' (اجباری)' : ' (اختیاری)' }}
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
id="status-note"
|
|
|
|
|
|
v-model="statusNote"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
class="admin-input"
|
|
|
|
|
|
placeholder="دلیل یا توضیح این تغییر"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="admin-btn admin-btn--primary admin-btn--sm"
|
|
|
|
|
|
:disabled="!canSubmitStatus || statusSaving"
|
|
|
|
|
|
@click="submitStatus"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ statusSaving ? 'در حال ثبت…' : 'ثبت وضعیت' }}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-08-03 12:14:12 +02:00
|
|
|
|
<div class="order-detail__footer">
|
|
|
|
|
|
<button type="button" class="admin-btn admin-btn--primary admin-btn--sm" @click="$emit('pricing')">
|
|
|
|
|
|
قیمتگذاری سفارش
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
v-if="order.settlementMethod === 'check'"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="admin-btn admin-btn--outline admin-btn--sm"
|
|
|
|
|
|
@click="$emit('checks')"
|
|
|
|
|
|
>
|
|
|
|
|
|
مدیریت چکها
|
|
|
|
|
|
</button>
|
2026-08-09 12:00:18 +03:30
|
|
|
|
<button
|
|
|
|
|
|
v-if="order.settlementMethod === 'cash'"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="admin-btn admin-btn--outline admin-btn--sm"
|
|
|
|
|
|
@click="$emit('cashReceipt')"
|
|
|
|
|
|
>
|
|
|
|
|
|
رسید پرداخت این سفارش
|
|
|
|
|
|
</button>
|
2026-08-03 12:14:12 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.order-detail__id {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
font-size: 0.9375rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__section {
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
padding-bottom: 16px;
|
|
|
|
|
|
border-bottom: 1px solid var(--color-border-light);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__section-title {
|
|
|
|
|
|
margin: 0 0 12px;
|
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__items {
|
|
|
|
|
|
list-style: none;
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__item {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 2px;
|
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
|
background: var(--color-border-light);
|
|
|
|
|
|
border-radius: var(--radius-sm);
|
|
|
|
|
|
font-size: 0.8125rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__item strong {
|
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__item span {
|
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-09 12:00:18 +03:30
|
|
|
|
.order-detail__raw-status {
|
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__status-head {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__manual {
|
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 6px;
|
|
|
|
|
|
font-size: 0.8125rem;
|
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__manual input {
|
|
|
|
|
|
width: 15px;
|
|
|
|
|
|
height: 15px;
|
|
|
|
|
|
accent-color: var(--color-primary);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.order-detail__status-hint {
|
|
|
|
|
|
margin: 0 0 12px;
|
|
|
|
|
|
font-size: 0.75rem;
|
|
|
|
|
|
line-height: 1.7;
|
|
|
|
|
|
color: var(--color-text-muted);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-03 12:14:12 +02:00
|
|
|
|
.order-detail__footer {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
margin-top: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|