feat: port QA/money fixes from tehran_taj (atomic document confirm, validated inputs, expert customer edit/toggle/weights, made-to-order, grid sort/customer column)

Order-revision workflow kept as is: the direct admin line-edit routes were not ported.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
saeed
2026-10-29 18:43:22 +03:30
co-authored by Claude Sonnet 5.5
parent 756ecef6db
commit 3eaecde876
65 changed files with 3810 additions and 216 deletions
+74
View File
@@ -373,6 +373,15 @@ export interface ExpertCustomer {
phone: string | null;
store_name: string | null;
pasazh_name: string | null;
/** What «ویرایش مشتری» opens with. */
fname: string;
lname: string;
address: string | null;
zone: string | null;
city_id: string | null;
national_code: string | null;
/** Gregorian YYYY-MM-DD, or null. */
birth_date: string | null;
gram_level: string;
remain: string;
rial_remain: string;
@@ -380,6 +389,47 @@ export interface ExpertCustomer {
createdAt: string;
}
/** The contact details an expert may change on one of their customers — never the percent or credit. */
export interface ExpertCustomerEdit {
fname: string;
lname: string;
mobile?: string;
phone?: string | null;
address?: string | null;
store_name?: string | null;
pasazh_name?: string | null;
national_code?: string | null;
birth_date?: string | null;
}
/** One «سفارش ساخت» request as the customer sees it. */
export interface PreOrderRow {
id: string;
status: string;
/** The reference's label: ثبت سفارش، تایید ادمین، تایید کارگاه، … */
sts_str_fa: string;
/** 1–5 on the tracker; 0 = cancelled. */
step: number;
color: string | null;
size: string | null;
color_mina: string | null;
color_stone: string | null;
sum: number;
description: string | null;
image: string | null;
createdAt: string;
}
export interface PreOrderInput {
color: string;
size?: string;
color_mina?: string;
color_stone?: string;
sum: number;
file_id?: string | null;
description?: string;
}
/** One row of "سفارش مشتریان". */
export interface ExpertChildOrder {
id: string;
@@ -653,6 +703,30 @@ export const api = {
'/expert/child-orders',
{ method: 'POST', body: JSON.stringify({ page, search: search ?? null }) },
),
/**
* The expert's real weight for each piece of an order in their hands, and
* optionally «ثبت نهایی» (hand it to the customer). Only raw weights travel:
* the making charge, the totals and the debt are the server's to compute.
* Mirrors legacy PUT /order/child/{id}.
*/
/** Switch one of the expert's customers off or on (legacy customer/toggle-active). */
toggleExpertCustomer: (customerId: string) =>
request<{ id: string; active: number }>(`/expert/customers/${encodeURIComponent(customerId)}/toggle-active`, { method: 'POST' }),
/** Correct a customer's contact details (legacy customer/update). */
updateExpertCustomer: (customerId: string, body: ExpertCustomerEdit) =>
request<{ id: string; name: string; mobile: string }>(`/expert/customers/${encodeURIComponent(customerId)}`, {
method: 'PUT',
body: JSON.stringify(body),
}),
// ── «سفارش ساخت» (legacy create-custom-order / get-custom-orders) ──
createPreOrder: (body: PreOrderInput) =>
request<PreOrderRow>('/customer/me/pre-orders', { method: 'POST', body: JSON.stringify(body) }),
getMyPreOrders: () => request<{ rows: PreOrderRow[] }>('/customer/me/pre-orders'),
adjustExpertChildOrder: (orderId: string, items: { id: string; rash_weight: number }[], finalSubmit: boolean) =>
request<{ id: string; status: string }>(`/expert/child-orders/${encodeURIComponent(orderId)}`, {
method: 'PUT',
body: JSON.stringify({ items, final_submit: finalSubmit }),
}),
// ── complete_profile ─────────────────────────────────────────────────
// Ports POST /major/complete (henza_server Major/CustomerController::complete)
+4
View File
@@ -45,6 +45,10 @@ export const router = createRouter({
},
{ path: '/profile', name: 'profileData', component: () => import('../views/user/ProfileView.vue'), meta: { requiresAuth: true } },
{ path: '/favorites', name: 'favoritesList', component: () => import('../views/user/FavoritesView.vue'), meta: { requiresAuth: true } },
// «سفارش ساخت» — ask for a piece to be made, and follow the request.
// Reference paths and names kept (henza_pwa router/index.ts:113-128).
{ path: '/makeOrder', name: 'makeOrderList', component: () => import('../views/user/MakeOrderView.vue'), meta: { requiresAuth: true } },
{ path: '/makeOrder_status', name: 'makeOrderStatus', component: () => import('../views/user/MakeOrderStatusView.vue'), meta: { requiresAuth: true } },
// Theme + reduced motion. Device preferences, so no requiresAuth.
{ path: '/settings/appearance', name: 'appearanceSettings', component: () => import('../views/user/AppearanceView.vue') },
// D21 — the sales expert's two screens. Reference paths and names kept
+14
View File
@@ -85,6 +85,9 @@
{{ cart.total() }}
<i>گرم</i>
</span>
<span v-if="cart.totalRial() > 0" class="cart__totalRial">
+ اجرت ریالی {{ price(cart.totalRial()) }} <i>ریال</i>
</span>
</div>
<button type="button" class="cart__submit" @click="cartData.notify = true">ثبت نهایی سفارش</button>
</div>
@@ -157,6 +160,7 @@ import PageBar from '../components/ui/PageBar.vue'
import Spinner from '../components/Spinner.vue'
import DialogVant from '../components/DialogVant.vue'
import CartItem from '../components/product/CartItem.vue'
import { price } from '../utils/filters'
import { useCartStore, type CartItem as CartItemType } from '../stores/cartStore'
import { useSessionStore } from '../stores/session'
import { useReveal } from '../composables/useReveal'
@@ -390,6 +394,16 @@ onMounted(async () => {
font-weight: 800;
color: @ink;
}
.cart__totalRial {
font-size: 11.5px;
font-weight: 700;
color: @inkSoft;
}
.cart__totalRial i {
font-style: normal;
font-weight: 600;
color: @inkFaint;
}
.cart__totalValue i {
font-style: normal;
font-size: 11px;
@@ -16,11 +16,15 @@
returns orders at that status (`where('sts', 5)`, ApiMobileController:766)
- the card is tappable, as the reference's was (:29)
Deliberately NOT ported: the reference's edit-order drawer behind that tap
(toEditOrder -> PUT /order/child/{id}) recalculated an order's weights and
prices from values the CLIENT sent. Bringing that across during a delivery
would put a money path in the app with no server-side recomputation; the tap
opens a read-only summary instead. Recorded in D21/DELIVERY.md.
The reference's edit-order drawer behind that tap (toEditOrder ->
PUT /order/child/{id}) is back, in a form that keeps the reason it was held
back: it used to recalculate an order's weights and prices from values the
CLIENT sent. Here the expert enters ONLY the real raw weight of each piece;
the server applies the making charge the order was placed at, recomputes the
totals and the customer's debt, and refuses anyone but the expert the order
belongs to (OrdersService.expertAdjust). The figures shown under each field
are a preview of that formula, not what is saved. «ثبت نهایی» hands the order
to the customer.
Scope is the server's: every row belongs to a customer this expert referred.
No id travels from the client.
@@ -133,6 +137,37 @@
<dd>تحویل مسئول فروش</dd>
</div>
</dl>
<!-- The real weight of each piece. Only the raw weight is sent; the making
charge, totals and debt are worked out by the server, and the figure
shown under each field is a preview of that. -->
<h3 v-if="drafts.length" class="cho__editTitle">وزن واقعی هر عدد (گرم)</h3>
<div v-for="d in drafts" :key="d.id" class="cho__line">
<div class="cho__lineHead">
<span class="cho__lineName">{{ d.title }}</span>
<span class="cho__lineQty" dir="rtl"><bdi>{{ d.qty }}</bdi> عدد · اجرت <bdi>{{ d.netPercent }}٪</bdi></span>
</div>
<InputNumber v-model:value="d.weight" class="cho__input" :min="0.001" :step="0.01" :precision="3" size="large" />
<div class="cho__lineSum" dir="ltr">
{{ grams(preview(d)) }} g
<span class="cho__muted">({{ d.qty }} × {{ grams(unitPreview(d)) }})</span>
</div>
</div>
<div v-if="drafts.length" class="cho__previewTotal">
<span>جمع وزن پس از ثبت</span>
<b dir="ltr">{{ grams(previewTotal) }} گرم</b>
</div>
<p v-if="saveError" class="cho__error">{{ saveError }}</p>
<div v-if="drafts.length" class="cho__actions">
<button type="button" class="cho__save" :disabled="saving" @click="save(false)">ثبت تغییرات</button>
<button type="button" class="cho__final" :disabled="saving" @click="confirmFinal = true">ثبت نهایی</button>
</div>
<p v-if="confirmFinal" class="cho__confirm">
آیا مطمئن به ثبت نهایی هستید؟ پس از آن سفارش تحویل مشتری می‌شود.
<button type="button" class="cho__final" :disabled="saving" @click="save(true)">بله، ثبت نهایی</button>
<button type="button" class="cho__link" @click="confirmFinal = false">بی‌خیال</button>
</p>
<button type="button" class="cho__close" @click="detailOpen = false">بستن</button>
</div>
</Drawer>
@@ -140,8 +175,8 @@
</template>
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue'
import { Drawer } from 'ant-design-vue'
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { Drawer, InputNumber } from 'ant-design-vue'
import AppPullRefresh from '../../components/ui/AppPullRefresh.vue'
import Icon from '../../components/icon/Icon.vue'
import PageBar from '../../components/ui/PageBar.vue'
@@ -212,11 +247,67 @@ async function onRefresh() {
}
}
/** One line of the order as the expert edits it: the raw weight is the only input. */
interface Draft {
id: string
title: string
qty: number
/** The percent the order was placed at (charge − promotion), kept as it is. */
netPercent: number
weight: number | undefined
}
const drafts = ref<Draft[]>([])
const saving = ref(false)
const saveError = ref('')
const confirmFinal = ref(false)
function openDetail(item: ExpertChildOrder) {
active.value = item
drafts.value = (item.items ?? []).map((i) => ({
id: i.id,
title: [i.productVariant?.product?.title, i.productVariant?.title].filter(Boolean).join(' — ') || 'محصول',
qty: i.quantity,
netPercent: Number(i.wagePercentSnapshot) - Number(i.discountPercentSnapshot),
weight: Number(i.rashWeightGramsSnapshot),
}))
saveError.value = ''
confirmFinal.value = false
detailOpen.value = true
}
/** rash × (1 + net/100) — the server's own formula, shown so the effect is visible before saving. */
const unitPreview = (d: Draft) => (d.weight ?? 0) * (1 + d.netPercent / 100)
const preview = (d: Draft) => unitPreview(d) * d.qty
const previewTotal = computed(() => drafts.value.reduce((s, d) => s + preview(d), 0))
async function save(finalSubmit: boolean) {
if (!active.value || saving.value) return
if (drafts.value.some((d) => !d.weight || d.weight <= 0)) {
saveError.value = 'وزن هر عدد باید بیشتر از صفر باشد.'
return
}
saving.value = true
saveError.value = ''
try {
await api.adjustExpertChildOrder(
active.value.id,
drafts.value.map((d) => ({ id: d.id, rash_weight: d.weight as number })),
finalSubmit,
)
detailOpen.value = false
await reload()
} catch (e) {
// The server's Persian reason (not found, wrong status, accounting busy, …) is in the body.
const text = e instanceof Error ? e.message : ''
const m = text.match(/"message":"([^"]+)"/)
saveError.value = m ? m[1] : 'ثبت تغییرات انجام نشد؛ دوباره تلاش کنید.'
} finally {
saving.value = false
confirmFinal.value = false
}
}
// Infinite scroll, the reference's behaviour (useInfiniteScroll at :216/:330).
const sentinel = ref<HTMLElement | null>(null)
let observer: IntersectionObserver | null = null
@@ -402,6 +493,109 @@ onBeforeUnmount(() => observer?.disconnect())
font-weight: 600;
}
.cho__editTitle {
margin: 18px 0 6px;
font-size: 13px;
font-weight: 800;
color: @ink;
}
.cho__line {
padding: 12px 0;
border-bottom: 1px solid @hairline;
}
.cho__lineHead {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
font-size: 12.5px;
}
.cho__lineName {
font-weight: 700;
color: @ink;
}
.cho__lineQty {
color: @inkFaint;
white-space: nowrap;
}
.cho__input {
width: 100%;
}
.cho__lineSum {
margin-top: 6px;
font-size: 12px;
font-weight: 700;
color: @inkSoft;
}
.cho__previewTotal {
display: flex;
justify-content: space-between;
padding: 14px 0 4px;
font-size: 13px;
}
.cho__error {
margin: 10px 0 0;
font-size: 12.5px;
color: #c0392b;
}
.cho__actions {
display: flex;
gap: 10px;
margin-top: 14px;
}
.cho__save,
.cho__final {
flex: 1;
padding: 12px;
border: 1px solid @wine;
border-radius: 14px;
background: transparent;
color: @wine;
font-family: inherit;
font-size: 13.5px;
font-weight: 700;
cursor: pointer;
}
.cho__final {
background: @wine;
color: #fff;
}
.cho__save:disabled,
.cho__final:disabled {
opacity: 0.5;
cursor: default;
}
.cho__confirm {
display: flex;
flex-direction: column;
gap: 8px;
margin: 12px 0 0;
font-size: 12.5px;
color: @inkSoft;
}
.cho__link {
border: none;
background: transparent;
color: @inkFaint;
font-family: inherit;
font-size: 12.5px;
cursor: pointer;
}
.cho__close {
margin-top: 18px;
width: 100%;
@@ -22,10 +22,11 @@
expert keeps their own token and the client names the customer in a header,
which the server re-authorises on every request.
Still deliberately NOT ported (D21):
- The activate/deactivate toggle and the edit button, which posted to
`/customer/toggle-active` and the customer form. Those are admin-panel
operations here. The state is shown, read-only.
The activate/deactivate toggle and the edit button (the reference's
`/customer/toggle-active` and `/customer/update`) are back, scoped the way
the reference's update was and its toggle was not: the server only lets an
expert touch THEIR OWN customers, and the edit covers contact details only —
never the percent, the credit limit, the kind or the account switches.
Scope is the server's: `referredByAgentId` = this expert, from the token.
-->
@@ -129,14 +130,56 @@
<button type="button" class="cch__enter" :disabled="entering" @click="enterAccount(active)">
{{ entering ? 'در حال ورود…' : 'ورود به حساب این مشتری' }}
</button>
<div class="cch__actions">
<button type="button" class="cch__act" @click="startEdit(active)">ویرایش اطلاعات</button>
<button
type="button"
class="cch__act"
:class="{ 'is-danger': active.active === 1 }"
:disabled="toggling"
@click="confirmToggle = true"
>
{{ active.active === 1 ? 'غیرفعال کردن' : 'فعال کردن' }}
</button>
</div>
<p v-if="confirmToggle" class="cch__confirm">
{{ active.active === 1 ? 'کاربر غیرفعال شود؟' : 'کاربر فعال شود؟' }}
<button type="button" class="cch__act is-danger" :disabled="toggling" @click="toggleActive(active)">بله</button>
<button type="button" class="cch__link" @click="confirmToggle = false">بی‌خیال</button>
</p>
<button type="button" class="cch__close" @click="detailOpen = false">بستن</button>
</div>
</Drawer>
<!-- «ویرایش مشتری»: contact details only. -->
<Drawer v-model:visible="editOpen" placement="bottom" height="auto" :closable="false" :body-style="{ padding: '0' }">
<form class="cch__detail" @submit.prevent="saveEdit">
<h2 class="cch__detailTitle">ویرایش اطلاعات مشتری</h2>
<label class="cch__field"><span>نام</span><input v-model.trim="edit.fname" type="text" maxlength="100" /></label>
<label class="cch__field"><span>نام خانوادگی</span><input v-model.trim="edit.lname" type="text" maxlength="100" /></label>
<label class="cch__field">
<span>موبایل</span>
<input v-model.trim="edit.mobile" type="tel" dir="ltr" maxlength="11" inputmode="numeric" />
</label>
<label class="cch__field"><span>تلفن ثابت</span><input v-model.trim="edit.phone" type="tel" dir="ltr" maxlength="30" /></label>
<label class="cch__field"><span>نام فروشگاه</span><input v-model.trim="edit.store_name" type="text" maxlength="150" /></label>
<label class="cch__field"><span>نام پاساژ</span><input v-model.trim="edit.pasazh_name" type="text" maxlength="150" /></label>
<label class="cch__field">
<span>کد ملی</span>
<input v-model.trim="edit.national_code" type="text" dir="ltr" maxlength="10" inputmode="numeric" />
</label>
<label class="cch__field"><span>تاریخ تولد</span><input v-model="edit.birth_date" type="date" dir="ltr" /></label>
<label class="cch__field"><span>آدرس</span><textarea v-model.trim="edit.address" rows="2" maxlength="500" /></label>
<p v-if="editError" class="cch__error">{{ editError }}</p>
<button type="submit" class="cch__enter" :disabled="saving">{{ saving ? 'در حال ثبت…' : 'ثبت تغییرات' }}</button>
<button type="button" class="cch__close" @click="editOpen = false">بستن</button>
</form>
</Drawer>
</div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { onMounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { Drawer } from 'ant-design-vue'
import AppPullRefresh from '../../components/ui/AppPullRefresh.vue'
@@ -228,6 +271,91 @@ async function enterAccount(item: ExpertCustomer) {
}
}
// ── «فعال/غیرفعال کردن» and «ویرایش» (reference customer/toggle-active, customer/update)
const toggling = ref(false)
const confirmToggle = ref(false)
async function toggleActive(item: ExpertCustomer) {
toggling.value = true
try {
const res = await api.toggleExpertCustomer(item.id)
item.active = res.active
const row = rows.value.find((r) => r.id === item.id)
if (row) row.active = res.active
toast.success(res.active === 1 ? 'کاربر فعال شد' : 'کاربر غیرفعال شد')
} catch {
toast.error('تغییر وضعیت انجام نشد؛ دوباره تلاش کنید.')
} finally {
toggling.value = false
confirmToggle.value = false
}
}
const editOpen = ref(false)
const saving = ref(false)
const editError = ref('')
const edit = reactive({
id: '',
fname: '',
lname: '',
mobile: '',
phone: '',
store_name: '',
pasazh_name: '',
national_code: '',
birth_date: '',
address: '',
})
function startEdit(item: ExpertCustomer) {
Object.assign(edit, {
id: item.id,
fname: item.fname ?? '',
lname: item.lname ?? '',
mobile: item.mobile ?? '',
phone: item.phone ?? '',
store_name: item.store_name ?? '',
pasazh_name: item.pasazh_name ?? '',
national_code: item.national_code ?? '',
birth_date: item.birth_date ?? '',
address: item.address ?? '',
})
editError.value = ''
detailOpen.value = false
editOpen.value = true
}
async function saveEdit() {
if (!edit.fname || !edit.lname) {
editError.value = 'نام و نام خانوادگی الزامی است.'
return
}
saving.value = true
editError.value = ''
try {
await api.updateExpertCustomer(edit.id, {
fname: edit.fname,
lname: edit.lname,
mobile: edit.mobile || undefined,
phone: edit.phone,
store_name: edit.store_name,
pasazh_name: edit.pasazh_name,
national_code: edit.national_code,
birth_date: edit.birth_date,
address: edit.address,
})
editOpen.value = false
toast.success('اطلاعات مشتری ثبت شد')
await load()
} catch (e) {
// The server's Persian reason (duplicate mobile, bad date, …) is in the body.
const m = (e instanceof Error ? e.message : '').match(/"message":"([^"]+)"/)
editError.value = m ? m[1] : 'ثبت تغییرات انجام نشد؛ دوباره تلاش کنید.'
} finally {
saving.value = false
}
}
onMounted(load)
</script>
@@ -392,6 +520,80 @@ onMounted(load)
}
/* Secondary now that "enter the account" is the primary action here. */
.cch__actions {
display: flex;
gap: 10px;
margin-top: 10px;
}
.cch__act {
flex: 1;
padding: 12px;
border: 1px solid @wine;
border-radius: 14px;
background: transparent;
color: @wine;
font-family: inherit;
font-size: 13.5px;
font-weight: 700;
cursor: pointer;
&.is-danger {
border-color: @red;
color: @red;
}
&:disabled {
opacity: 0.5;
cursor: default;
}
}
.cch__confirm {
display: flex;
align-items: center;
gap: 10px;
margin: 12px 0 0;
font-size: 13px;
color: @inkSoft;
}
.cch__link {
border: none;
background: transparent;
color: @inkFaint;
font-family: inherit;
font-size: 12.5px;
cursor: pointer;
}
.cch__field {
display: flex;
flex-direction: column;
gap: 5px;
padding: 8px 0;
font-size: 12.5px;
color: @inkSoft;
}
.cch__field input,
.cch__field textarea {
width: 100%;
padding: 10px 12px;
border: 1px solid @hairline;
border-radius: 12px;
background: transparent;
color: @ink;
font-family: inherit;
font-size: 14px;
}
.cch__error {
margin: 8px 0 0;
font-size: 12.5px;
color: @red;
}
.cch__close {
margin-top: 10px;
width: 100%;
@@ -198,6 +198,14 @@
<div class="text-center text-danger" @click="data.loginNotify = false">بیخیال</div>
</template>
</DialogVant>
<!-- «سفارش ساخت»: place a request, or see the ones already placed. -->
<Drawer v-model:visible="makeOrderChoice" placement="bottom" height="auto" :closable="false" :body-style="{ padding: '0' }">
<div class="dash__choice">
<button type="button" class="dash__choiceBtn" @click="chooseMakeOrder('makeOrderList')">ثبت سفارش</button>
<button type="button" class="dash__choiceBtn is-quiet" @click="chooseMakeOrder('makeOrderStatus')">مشاهده سفارش</button>
</div>
</Drawer>
</div>
</template>
@@ -205,6 +213,7 @@
import { brand } from '../../brand'
import { computed, onActivated, onMounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { Drawer } from 'ant-design-vue'
import AppPullRefresh from '../../components/ui/AppPullRefresh.vue'
import Icon from '../../components/icon/Icon.vue'
import SectionHead from '../../components/home/SectionHead.vue'
@@ -257,6 +266,8 @@ const BASE_TILES = [
// gated on hasMCode() (Dashboard.vue:179, :449). The target has no mcode, so
// every signed-in customer sees it and the server scopes it to their token.
{ id: 6, icon: 'vuesax-linear:chart-2', title: 'گزارش', tone: 'slate', disabled: false },
// «سفارش ساخت» (reference makeOrder): ask for a piece to be made.
{ id: 8, icon: 'vuesax-linear:3d-cube-scan', title: 'سفارش ساخت', tone: 'rose', disabled: false },
]
/**
@@ -297,6 +308,15 @@ function goToDetails(id: number) {
if (id === 4) router.push({ name: 'ChildOrder' })
if (id === 5) router.push({ name: 'customerChoice' })
if (id === 6) router.push({ name: 'report' })
if (id === 8) makeOrderChoice.value = true
}
// «سفارش ساخت»: the reference opened a two-button dialog — place a request, or
// see the ones already placed.
const makeOrderChoice = ref(false)
function chooseMakeOrder(name: 'makeOrderList' | 'makeOrderStatus') {
makeOrderChoice.value = false
router.push({ name })
}
async function logOut() {
@@ -756,4 +776,28 @@ onMounted(async () => {
color: @inkFaint;
opacity: 0.7;
}
.dash__choice {
display: flex;
flex-direction: column;
gap: 10px;
padding: 20px 16px 24px;
}
.dash__choiceBtn {
padding: 15px;
border: 1px solid @wine;
border-radius: 14px;
background: @wine;
color: #fff;
font-family: inherit;
font-size: 15px;
font-weight: 700;
cursor: pointer;
}
.dash__choiceBtn.is-quiet {
background: transparent;
color: @wine;
}
</style>
@@ -0,0 +1,237 @@
<!--
"وضعیت سفارش" — where each «سفارش ساخت» request stands.
Ported from henza_pwa/src/views/user/src/components/makeOrderStatus.vue
(route /makeOrder_status, name makeOrderStatus), restyled into this app's
design language.
Kept from the reference:
- the header title "وضعیت سفارش"
- one card per request, newest first, with the five-step tracker
ثبت سفارش → تایید ادمین → تایید کارگاه → ارسال → تحویل شده
- the facts it listed: رنگ محصول، سایز محصول، رنگ مینا، رنگ سنگ، تعداد، وضعیت،
تاریخ ثبت، ساعت ثبت, and the photo
Deliberately NOT ported: the «تایید سفارش» / «ارسال سفارش» buttons the reference
showed to workshop-type users. Both posted the same `sts: 2` and the server
checked neither who asked nor whose request it was. Moving a request along is
the admin screen's job («سفارشات ساختنی»).
-->
<template>
<div class="mks">
<PageBar title="وضعیت سفارش" back-to="userPage::hasSubRoute" />
<Spinner :spinning="loading && !rows.length" tip="درحال دریافت اطلاعات">
<AppPullRefresh v-model="refreshing" @refresh="onRefresh">
<container class="mks__body">
<article v-for="item in rows" :key="item.id" class="mks__card">
<ol v-if="item.step > 0" class="mks__track" :aria-label="item.sts_str_fa">
<li
v-for="(label, i) in STEPS"
:key="label"
:class="{ 'is-done': item.step > i + 1, 'is-now': item.step === i + 1 }"
>
<i aria-hidden="true" />
<span>{{ label }}</span>
</li>
</ol>
<p v-else class="mks__cancelled">این سفارش لغو شده است.</p>
<dl class="mks__facts">
<div><dt>رنگ محصول</dt><dd>{{ item.color || '—' }}</dd></div>
<div><dt>سایز محصول</dt><dd>{{ item.size || '—' }}</dd></div>
<div><dt>رنگ مینا</dt><dd>{{ item.color_mina || '—' }}</dd></div>
<div><dt>رنگ سنگ</dt><dd>{{ item.color_stone || '—' }}</dd></div>
<div><dt>تعداد</dt><dd>{{ item.sum }}</dd></div>
<div><dt>وضعیت</dt><dd>{{ item.sts_str_fa }}</dd></div>
<div><dt>تاریخ ثبت</dt><dd dir="ltr">{{ jdate(item.createdAt) }}</dd></div>
<div><dt>ساعت ثبت</dt><dd dir="ltr">{{ timeOf(item.createdAt) }}</dd></div>
</dl>
<p v-if="item.description" class="mks__note">{{ item.description }}</p>
<img v-if="item.image" class="mks__photo" :src="item.image" alt="" />
</article>
<section v-if="!rows.length && !loading && !failed" class="mks__empty">
<Icon icon="vuesax-linear:box" size="26" />
<p>هنوز سفارش ساختی ثبت نکرده‌اید.</p>
<button type="button" class="mks__cta" @click="router.push({ name: 'makeOrderList' })">ثبت سفارش</button>
</section>
<section v-if="failed" class="mks__empty">
<Icon icon="vuesax-linear:danger" size="26" />
<p>دریافت اطلاعات با خطا روبه‌رو شد.</p>
<button type="button" class="mks__cta" @click="load">تلاش دوباره</button>
</section>
</container>
</AppPullRefresh>
</Spinner>
</div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import AppPullRefresh from '../../components/ui/AppPullRefresh.vue'
import Icon from '../../components/icon/Icon.vue'
import PageBar from '../../components/ui/PageBar.vue'
import Spinner from '../../components/Spinner.vue'
import { jdate } from '../../utils/filters'
import { api, type PreOrderRow } from '../../api/client'
const router = useRouter()
const STEPS = ['ثبت سفارش', 'تایید ادمین', 'تایید کارگاه', 'ارسال', 'تحویل شده']
const rows = ref<PreOrderRow[]>([])
const loading = ref(false)
const refreshing = ref(false)
const failed = ref(false)
/** HH:mm in Tehran time, as the reference showed the hour of registration. */
function timeOf(iso: string): string {
return new Date(iso).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', timeZone: 'Asia/Tehran' })
}
async function load() {
loading.value = true
failed.value = false
try {
rows.value = (await api.getMyPreOrders()).rows
} catch {
failed.value = true
} finally {
loading.value = false
}
}
async function onRefresh() {
try {
await load()
} finally {
refreshing.value = false
}
}
onMounted(load)
</script>
<style scoped lang="less">
.mks__body {
padding-top: 84px;
padding-bottom: 90px;
}
.mks__card {
padding: 18px 2px;
border-bottom: 1px solid @hairline;
}
.mks__track {
display: flex;
justify-content: space-between;
gap: 4px;
margin: 0 0 16px;
padding: 0;
list-style: none;
}
.mks__track li {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
text-align: center;
font-size: 10.5px;
color: @inkFaint;
}
.mks__track i {
display: block;
width: 100%;
height: 3px;
border-radius: 999px;
background: @hairline;
}
.mks__track li.is-done {
color: @inkSoft;
}
.mks__track li.is-done i {
background: @wine;
}
.mks__track li.is-now {
color: @wine;
font-weight: 800;
}
.mks__track li.is-now i {
background: @wine;
opacity: 0.55;
}
.mks__cancelled {
margin: 0 0 12px;
font-size: 12.5px;
font-weight: 700;
color: @red;
}
.mks__facts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 14px;
margin: 0;
}
.mks__facts div {
display: flex;
gap: 6px;
font-size: 12.5px;
}
.mks__facts dt {
color: @inkFaint;
}
.mks__facts dd {
margin: 0;
font-weight: 700;
color: @ink;
}
.mks__note {
margin: 12px 0 0;
font-size: 12.5px;
color: @inkSoft;
}
.mks__photo {
display: block;
width: 100%;
max-height: 260px;
margin-top: 12px;
border-radius: 14px;
object-fit: cover;
}
.mks__empty {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
padding: 48px 0;
color: @inkFaint;
text-align: center;
}
.mks__cta {
padding: 11px 22px;
border: none;
border-radius: 999px;
background: @wine;
color: #fff;
font-family: inherit;
font-size: 13.5px;
font-weight: 700;
cursor: pointer;
}
</style>
@@ -0,0 +1,197 @@
<!--
"سفارش ساخت" — ask for a piece to be made.
Ported from henza_pwa/src/views/user/src/components/makeOrder.vue (route
/makeOrder, name makeOrderList), restyled into this app's design language.
Kept from the reference:
- the header title "سفارش ساخت"
- the photo of the piece first, then the questions: رنگ محصول، سایز محصول،
رنگ مینا، رنگ سنگ، تعداد، توضیحات (the last one optional)
- every field but the description required, with the reference's own messages
- POST create-custom-order -> customer/me/pre-orders here; the customer is the
token's, nothing about WHO is sent
The reference then sent the customer home; this goes to «وضعیت سفارش» so the
request just placed is the first thing seen.
-->
<template>
<div class="mko">
<PageBar title="سفارش ساخت" back-to="userPage::hasSubRoute" />
<Spinner :spinning="submitting" tip="در حال ثبت اطلاعات">
<container class="mko__body">
<form class="mko__form" novalidate @submit.prevent="submit">
<SingleImageUploader
upload-text="بارگذاری عکس سفارش"
purpose="preorder-design"
@done="(id: string) => (form.file_id = id)"
/>
<p class="mko__lead">لطفا به سوالات زیر پاسخ دهید</p>
<label class="mko__field">
<span>رنگ محصول</span>
<input v-model.trim="form.color" type="text" maxlength="100" />
</label>
<label class="mko__field">
<span>سایز محصول</span>
<input v-model.trim="form.size" type="text" maxlength="100" />
</label>
<label class="mko__field">
<span>رنگ مینا</span>
<input v-model.trim="form.color_mina" type="text" maxlength="100" />
</label>
<label class="mko__field">
<span>رنگ سنگ</span>
<input v-model.trim="form.color_stone" type="text" maxlength="100" />
</label>
<label class="mko__field">
<span>تعداد</span>
<input v-model.number="form.sum" type="number" inputmode="numeric" min="1" step="1" />
</label>
<label class="mko__field">
<span>توضیحات</span>
<textarea v-model.trim="form.description" rows="3" maxlength="1000" />
</label>
<p v-if="error" class="mko__error">{{ error }}</p>
<button type="submit" class="mko__submit" :disabled="submitting">ارسال اطلاعات</button>
</form>
</container>
</Spinner>
</div>
</template>
<script setup lang="ts">
import { reactive, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { toast } from '../../composables/useToast'
import PageBar from '../../components/ui/PageBar.vue'
import Spinner from '../../components/Spinner.vue'
import SingleImageUploader from '../../components/upload/SingleImageUploader.vue'
import { api } from '../../api/client'
const router = useRouter()
const form = reactive({
file_id: null as string | null,
color: '',
size: '',
color_mina: '',
color_stone: '',
sum: 1,
description: '',
})
const submitting = ref(false)
const error = ref<string | null>(null)
/** A message about a missing field must not outlive the fix (e.g. the photo being uploaded). */
watch(form, () => (error.value = null))
/** The reference's required-field messages, in the order it asked. */
function firstMissing(): string | null {
if (!form.file_id) return 'لطفا تصویر سفارش را آپلود کنید'
if (!form.color) return 'لطفا رنگ محصول را وارد کنید'
if (!form.size) return 'لطفا سایز محصول را وارد کنید'
if (!form.color_mina) return 'لطفا رنگ مینا را وارد کنید'
if (!form.color_stone) return 'لطفا رنگ سنگ را وارد کنید'
if (!Number.isInteger(form.sum) || form.sum < 1) return 'لطفا تعداد را وارد کنید'
return null
}
async function submit() {
error.value = firstMissing()
if (error.value) return
submitting.value = true
try {
await api.createPreOrder({
color: form.color,
size: form.size,
color_mina: form.color_mina,
color_stone: form.color_stone,
sum: form.sum,
file_id: form.file_id,
description: form.description || undefined,
})
toast.success('سفارش با موفقیت ثبت شد')
router.replace({ name: 'makeOrderStatus' })
} catch {
error.value = 'خطا در ثبت سفارش'
} finally {
submitting.value = false
}
}
</script>
<style scoped lang="less">
.mko__body {
padding-top: 84px;
padding-bottom: 110px;
}
.mko__form {
display: flex;
flex-direction: column;
}
.mko__lead {
margin: 18px 2px 4px;
font-size: 13px;
font-weight: 700;
color: @inkMuted;
}
.mko__field {
display: flex;
flex-direction: column;
gap: 6px;
padding: 12px 0;
border-bottom: 1px solid @hairline;
font-size: 12.5px;
color: @inkSoft;
}
.mko__field input,
.mko__field textarea {
width: 100%;
padding: 11px 12px;
border: 1px solid @hairline;
border-radius: 12px;
background: transparent;
color: @ink;
font-family: inherit;
font-size: 14px;
}
.mko__error {
margin: 12px 2px 0;
font-size: 12.5px;
color: @red;
}
.mko__submit {
position: fixed;
left: 16px;
right: 16px;
bottom: 20px;
z-index: 20;
max-width: 736px;
margin: 0 auto;
padding: 15px;
border: none;
border-radius: 999px;
background: @wine;
color: #fff;
font-family: inherit;
font-size: 15px;
font-weight: 700;
cursor: pointer;
}
.mko__submit:disabled {
opacity: 0.6;
cursor: progress;
}
</style>
+5 -1
View File
@@ -122,6 +122,10 @@
<dt>وزن سفارش</dt>
<dd>{{ parseFloat(viewData.item.totalGoldWeightGrams).toFixed(2) }} گرم</dd>
</div>
<div v-if="parseFloat(viewData.item.flatRialCharge) > 0" class="detail__spec">
<dt>اجرت ریالی</dt>
<dd>{{ price(Math.round(parseFloat(viewData.item.flatRialCharge))) }} ریال</dd>
</div>
<div class="detail__spec">
<dt>تاریخ سفارش</dt>
<dd>{{ jdate(viewData.item.createdAt) }}</dd>
@@ -230,7 +234,7 @@ import {
orderStatusIcon,
orderStatusLabel,
} from '../../utils/orderStatus'
import { jdate, jtimelineWhen } from '../../utils/filters'
import { jdate, jtimelineWhen, price } from '../../utils/filters'
import { useSessionStore } from '../../stores/session'
import { api, type OrderDetail } from '../../api/client'
import { useQueryCache, KEYS } from '../../stores/queryCache'