feat: require payment method when submitting a preorder

Price depends on cash or check terms, so the customer chooses them before admin pricing.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-15 11:24:52 +03:30
co-authored by Cursor
parent c225a58099
commit 881e6a2c87
10 changed files with 284 additions and 20 deletions
+10
View File
@@ -18,6 +18,8 @@ const {
showFullDialog,
submitting,
submitError,
settlementType,
checkTermMonths,
removeItem,
proceedToCheckout,
proceedAnyway,
@@ -43,6 +45,10 @@ function goToOrdering() {
:remaining-capacity="cartStore.remainingCapacity"
:is-empty="isEmpty"
:submitting="submitting"
:settlement-type="settlementType"
:check-term-months="checkTermMonths"
@update:settlement-type="settlementType = $event"
@update:check-term-months="checkTermMonths = $event"
@back="router.push('/')"
@remove="removeItem"
@checkout="proceedToCheckout"
@@ -59,6 +65,10 @@ function goToOrdering() {
:remaining-capacity="cartStore.remainingCapacity"
:is-empty="isEmpty"
:submitting="submitting"
:settlement-type="settlementType"
:check-term-months="checkTermMonths"
@update:settlement-type="settlementType = $event"
@update:check-term-months="checkTermMonths = $event"
@remove="removeItem"
@checkout="proceedToCheckout"
@select-company="goToOrdering()"
+13 -2
View File
@@ -10,7 +10,8 @@ import IconLightbulb from '@/components/icons/IconLightbulb.vue'
import IconLayoutGrid from '@/components/icons/IconLayoutGrid.vue'
import IconDiamond from '@/components/icons/IconDiamond.vue'
import { formatMeterage, formatNumber } from '@/utils/format'
import type { CartItem } from '@/types'
import type { CartItem, SettlementType } from '@/types'
import PreorderPaymentFields from '@/components/orders/PreorderPaymentFields.vue'
defineProps<{
items: CartItem[]
@@ -27,6 +28,8 @@ defineProps<{
remainingCapacity: number
isEmpty: boolean
submitting?: boolean
settlementType: SettlementType | null
checkTermMonths: number | null
}>()
const emit = defineEmits<{
@@ -34,6 +37,8 @@ const emit = defineEmits<{
checkout: []
selectCompany: []
back: []
'update:settlementType': [value: SettlementType]
'update:checkTermMonths': [value: number]
}>()
const router = useRouter()
@@ -180,6 +185,12 @@ const quickLinks = [
</span>
</div>
</div>
<PreorderPaymentFields
:settlement-type="settlementType"
:check-term-months="checkTermMonths"
@update:settlement-type="emit('update:settlementType', $event)"
@update:check-term-months="emit('update:checkTermMonths', $event)"
/>
<button
type="button"
class="cart-summary-card__cta"
@@ -190,7 +201,7 @@ const quickLinks = [
{{ submitting ? 'در حال ثبت…' : 'ثبت پیش‌سفارش' }}
</button>
<p class="cart-summary-card__note">
پس از ثبت سفارش، مدیریت قیمت‌گذاری می‌کند و فاکتور صادر می‌شود؛ سپس روش تسویه را انتخاب می‌کنید.
روش پرداخت الان ثبت می‌شود. مدیریت بعد از آن قیمت و متراژ را اعلام می‌کند.
</p>
</div>
+13 -2
View File
@@ -4,7 +4,8 @@ import EmptyState from '@/components/ui/EmptyState.vue'
import IconTrash from '@/components/icons/IconTrash.vue'
import IconChevronBack from '@/components/icons/IconChevronBack.vue'
import { formatMeterage, formatNumber } from '@/utils/format'
import type { CartItem } from '@/types'
import type { CartItem, SettlementType } from '@/types'
import PreorderPaymentFields from '@/components/orders/PreorderPaymentFields.vue'
defineProps<{
items: CartItem[]
@@ -21,6 +22,8 @@ defineProps<{
remainingCapacity: number
isEmpty: boolean
submitting?: boolean
settlementType: SettlementType | null
checkTermMonths: number | null
}>()
const emit = defineEmits<{
@@ -28,6 +31,8 @@ const emit = defineEmits<{
remove: [id: string]
checkout: []
selectCompany: []
'update:settlementType': [value: SettlementType]
'update:checkTermMonths': [value: number]
}>()
</script>
@@ -98,8 +103,14 @@ const emit = defineEmits<{
<strong>{{ formatMeterage(remainingCapacity) }}</strong>
</div>
</div>
<PreorderPaymentFields
:settlement-type="settlementType"
:check-term-months="checkTermMonths"
@update:settlement-type="emit('update:settlementType', $event)"
@update:check-term-months="emit('update:checkTermMonths', $event)"
/>
<p class="cart-mobile-page__hint">
پس از ثبت سفارش، کارشناسان قیمت‌گذاری می‌کنند و فاکتور برای شما صادر می‌شود.
پس از ثبت، مدیریت بر اساس همین روش پرداخت قیمت و متراژ را اعلام می‌کند.
</p>
<BaseButton block :loading="submitting" @click="emit('checkout')">ثبت پیش‌سفارش</BaseButton>
</div>
+59 -2
View File
@@ -3,7 +3,8 @@ import { ref, computed, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useMediaQuery } from '@vueuse/core'
import { useOrderStore } from '@/stores/order'
import type { Order } from '@/types'
import type { Order, SettlementType } from '@/types'
import PreorderPaymentFields from '@/components/orders/PreorderPaymentFields.vue'
import BaseButton from '@/components/ui/BaseButton.vue'
import CurrencyInput from '@/components/ui/CurrencyInput.vue'
import PersianDateInput from '@/components/ui/PersianDateInput.vue'
@@ -155,7 +156,37 @@ const trackingFooterLabel = computed(() =>
)
function settlementLabel(type: Order['settlementType']) {
return settlementTypeLabel(type)
const base = settlementTypeLabel(type)
const months = order.value?.checkTermMonths
if ((type === 'check' || type === 'cash_check') && months) {
return `${base} · چک ${months} ماهه`
}
return base
}
const planType = ref<SettlementType | null>(null)
const planMonths = ref<number | null>(null)
const planSaving = ref(false)
async function savePaymentPlan() {
const current = order.value
if (!current || !planType.value) {
formError.value = 'روش پرداخت را انتخاب کنید.'
return
}
if ((planType.value === 'check' || planType.value === 'cash_check') && !planMonths.value) {
formError.value = 'مدت چک را از ۱ تا ۴ ماه انتخاب کنید.'
return
}
planSaving.value = true
formError.value = ''
try {
await orderStore.setPaymentPlan(current.id, planType.value, planMonths.value)
} catch (e) {
formError.value = e instanceof Error ? e.message : 'ثبت روش پرداخت ناموفق بود.'
} finally {
planSaving.value = false
}
}
function showCashTracking(order: Order) {
@@ -314,6 +345,19 @@ async function submitReceipt() {
<p class="desktop-page__subtitle">{{ order.orderNumber }} · {{ order.companyName }}</p>
</header>
<div
v-if="order.status === 'awaiting_review' && !order.settlementType"
class="order-info-card desktop-only"
>
<PreorderPaymentFields
:settlement-type="planType"
:check-term-months="planMonths"
@update:settlement-type="planType = $event"
@update:check-term-months="planMonths = $event"
/>
<BaseButton :loading="planSaving" @click="savePaymentPlan">ثبت روش پرداخت</BaseButton>
</div>
<div class="order-detail-page__body">
<div v-if="!showTracking" class="order-info-card mobile-only">
<div class="order-info-card__head">
@@ -340,6 +384,19 @@ async function submitReceipt() {
</span>
</div>
<div
v-if="order.status === 'awaiting_review' && !order.settlementType"
class="order-info-card__plan"
>
<PreorderPaymentFields
:settlement-type="planType"
:check-term-months="planMonths"
@update:settlement-type="planType = $event"
@update:check-term-months="planMonths = $event"
/>
<BaseButton block :loading="planSaving" @click="savePaymentPlan">ثبت روش پرداخت</BaseButton>
</div>
<div class="order-info-card__row order-info-card__row--last">
<span class="order-info-card__key">مبلغ فاکتور</span>
<strong class="order-info-card__amount">