feat: one piece per variant and optional admin rial wage
A customer cart line is a single piece, the home reel opens on tap, and a variant can be saved without a rial wage. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
:aria-label="mode === 'create' ? 'افزودن تنوع جدید' : 'ویرایش تنوع'"
|
:aria-label="mode === 'create' ? 'افزودن تنوع جدید' : 'ویرایش تنوع'"
|
||||||
@keydown="onKeydown"
|
@keydown="onKeydown"
|
||||||
>
|
>
|
||||||
<!-- required: what every weight variant needs -->
|
<!-- weight and percent wage are required; rial wage may be left empty -->
|
||||||
<div class="vre__primary">
|
<div class="vre__primary">
|
||||||
<a-form-item
|
<a-form-item
|
||||||
class="vre__item"
|
class="vre__item"
|
||||||
@@ -51,7 +51,6 @@
|
|||||||
<a-form-item
|
<a-form-item
|
||||||
class="vre__item"
|
class="vre__item"
|
||||||
label="اجرت ریالی"
|
label="اجرت ریالی"
|
||||||
required
|
|
||||||
:validate-status="errors.rial_pay ? 'error' : ''"
|
:validate-status="errors.rial_pay ? 'error' : ''"
|
||||||
:help="errors.rial_pay"
|
:help="errors.rial_pay"
|
||||||
>
|
>
|
||||||
@@ -61,7 +60,7 @@
|
|||||||
:min="0"
|
:min="0"
|
||||||
:step="50000"
|
:step="50000"
|
||||||
addon-after="ریال"
|
addon-after="ریال"
|
||||||
placeholder="نداشت: صفر"
|
placeholder="اختیاری"
|
||||||
:formatter="formatThousands"
|
:formatter="formatThousands"
|
||||||
:parser="parseThousands"
|
:parser="parseThousands"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export function validateVariant(v: VariantRow): VariantErrors {
|
|||||||
else if (Number(v.grams) <= 0) e.grams = 'وزن باید بیشتر از صفر باشد';
|
else if (Number(v.grams) <= 0) e.grams = 'وزن باید بیشتر از صفر باشد';
|
||||||
if (!isBlank(v.qty) && Number(v.qty) < 0) e.qty = 'تعداد منفی نمیشود';
|
if (!isBlank(v.qty) && Number(v.qty) < 0) e.qty = 'تعداد منفی نمیشود';
|
||||||
if (isBlank(v.percentage_pay)) e.percentage_pay = 'اجرت درصدی را وارد کنید';
|
if (isBlank(v.percentage_pay)) e.percentage_pay = 'اجرت درصدی را وارد کنید';
|
||||||
if (isBlank(v.rial_pay)) e.rial_pay = 'اجرت ریالی را وارد کنید؛ اگر ندارد صفر بزنید';
|
if (!isBlank(v.rial_pay) && Number(v.rial_pay) < 0) e.rial_pay = 'اجرت ریالی منفی نمیشود';
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<svg width="12" height="9" viewBox="0 0 12 9" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M6 9C5.91177 5.77359 3.66177 4.75472 0 4.5C3.57353 4.37264 5.91177 3.18396 6 0C6.08824 3.22642 8.38235 4.4151 12 4.5C8.38235 4.75472 6.08824 5.77359 6 9Z" fill="#8D6A46"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 282 B |
@@ -69,6 +69,13 @@ const dragging = ref(false)
|
|||||||
const drag = ref(0)
|
const drag = ref(0)
|
||||||
let startX = 0
|
let startX = 0
|
||||||
let pointerId: number | null = null
|
let pointerId: number | null = null
|
||||||
|
// The cell under the finger at pointerdown. Pointer capture retargets
|
||||||
|
// pointerup (and therefore click) onto the stage, so the card's own click
|
||||||
|
// never runs — a tap has to be resolved from this index instead.
|
||||||
|
let pressedIndex: number | null = null
|
||||||
|
// Set when pointerup already handled the tap, so a click that does arrive
|
||||||
|
// afterwards does not open the product a second time.
|
||||||
|
let tapHandled = false
|
||||||
|
|
||||||
const SWIPE_THRESHOLD = 46
|
const SWIPE_THRESHOLD = 46
|
||||||
|
|
||||||
@@ -153,12 +160,23 @@ function prev() {
|
|||||||
go(index.value - 1)
|
go(index.value - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function indexFromEvent(e: Event): number | null {
|
||||||
|
const target = e.target
|
||||||
|
if (!(target instanceof Element) || !stage.value) return null
|
||||||
|
const cell = target.closest('.reel__cell')
|
||||||
|
if (!cell) return null
|
||||||
|
const i = [...stage.value.querySelectorAll('.reel__cell')].indexOf(cell)
|
||||||
|
return i >= 0 ? i : null
|
||||||
|
}
|
||||||
|
|
||||||
function onDown(e: PointerEvent) {
|
function onDown(e: PointerEvent) {
|
||||||
if (count.value < 2) return
|
if (count.value < 2) return
|
||||||
dragging.value = true
|
dragging.value = true
|
||||||
startX = e.clientX
|
startX = e.clientX
|
||||||
drag.value = 0
|
drag.value = 0
|
||||||
pointerId = e.pointerId
|
pointerId = e.pointerId
|
||||||
|
pressedIndex = indexFromEvent(e)
|
||||||
|
tapHandled = false
|
||||||
;(e.currentTarget as HTMLElement).setPointerCapture?.(e.pointerId)
|
;(e.currentTarget as HTMLElement).setPointerCapture?.(e.pointerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,33 +189,57 @@ function onMove(e: PointerEvent) {
|
|||||||
function onUp(e: PointerEvent) {
|
function onUp(e: PointerEvent) {
|
||||||
if (!dragging.value) return
|
if (!dragging.value) return
|
||||||
const moved = e.clientX - startX
|
const moved = e.clientX - startX
|
||||||
|
const pressed = pressedIndex
|
||||||
dragging.value = false
|
dragging.value = false
|
||||||
drag.value = 0
|
drag.value = 0
|
||||||
pointerId = null
|
pointerId = null
|
||||||
|
pressedIndex = null
|
||||||
|
|
||||||
// RTL: dragging right pushes the stack toward the previous card.
|
// RTL: dragging right pushes the stack toward the previous card.
|
||||||
if (moved > SWIPE_THRESHOLD) prev()
|
if (moved > SWIPE_THRESHOLD) {
|
||||||
else if (moved < -SWIPE_THRESHOLD) next()
|
prev()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (moved < -SWIPE_THRESHOLD) {
|
||||||
|
next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// A tap. Pointer capture delivers this pointerup to the stage, so the
|
||||||
|
// card's click listener never runs; the cell recorded on pointerdown is
|
||||||
|
// what was actually tapped.
|
||||||
|
tapHandled = true
|
||||||
|
activate(pressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A tap on a side card centres it instead of opening it, and a tap that ended
|
// A tap on a side card centres it instead of opening it. The centred card
|
||||||
// a drag does neither.
|
// opens, and the trailing tile goes to the full newest-products list.
|
||||||
function onOpen(i: number, product: ProductSummary) {
|
function activate(i: number | null) {
|
||||||
if (Math.abs(drag.value) > 1) return
|
if (i == null) return
|
||||||
|
const slot = slots.value[i]
|
||||||
|
if (!slot) return
|
||||||
if (i !== index.value) {
|
if (i !== index.value) {
|
||||||
go(i)
|
go(i)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
emit('open', product)
|
if (slot.kind === 'product' && slot.product) emit('open', slot.product)
|
||||||
|
else emit('all')
|
||||||
|
}
|
||||||
|
|
||||||
|
function onOpen(i: number, _product: ProductSummary) {
|
||||||
|
if (tapHandled) {
|
||||||
|
tapHandled = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
activate(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAll(i: number) {
|
function onAll(i: number) {
|
||||||
if (Math.abs(drag.value) > 1) return
|
if (tapHandled) {
|
||||||
if (i !== index.value) {
|
tapHandled = false
|
||||||
go(i)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
emit('all')
|
activate(i)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -82,14 +82,30 @@ function format(v: number) {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The stand-in is the brand mark, not a photo, so it stays a mark in the
|
||||||
|
// middle of the frame instead of filling the slot the piece will occupy.
|
||||||
|
.panel__art img[lazy='loading'],
|
||||||
|
.panel__art img[lazy='error'] {
|
||||||
|
max-width: 62%;
|
||||||
|
max-height: 52%;
|
||||||
|
}
|
||||||
|
|
||||||
// Dark mode: product photos are shot on white, so they sit on a light mat
|
// Dark mode: product photos are shot on white, so they sit on a light mat
|
||||||
// instead of showing as white boxes on a dark card (@photoMat — transparent,
|
// instead of showing as white boxes on a dark card (@photoMat — transparent,
|
||||||
// i.e. no change, in light mode).
|
// i.e. no change, in light mode). The brand mark that stands in while a photo
|
||||||
|
// loads is black line art, so it stays on the card and is drawn light, the
|
||||||
|
// same way the header logo is.
|
||||||
html.theme-dark .panel__art img {
|
html.theme-dark .panel__art img {
|
||||||
background: @photoMat;
|
background: @photoMat;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html.theme-dark .panel__art img[lazy='loading'],
|
||||||
|
html.theme-dark .panel__art img[lazy='error'] {
|
||||||
|
background: transparent;
|
||||||
|
filter: invert(1);
|
||||||
|
}
|
||||||
|
|
||||||
.panel__title {
|
.panel__title {
|
||||||
margin: 14px 0 0;
|
margin: 14px 0 0;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
field existed; that was wrong, and the customer was charged a figure the cart
|
field existed; that was wrong, and the customer was charged a figure the cart
|
||||||
never showed.
|
never showed.
|
||||||
|
|
||||||
All cart behaviour is unchanged: quantity increment/decrement, remove at
|
All cart behaviour for a line: it is one piece, so the row can be removed,
|
||||||
qty 1, and the note affordance that opens the parent's drawer.
|
noted, or moved to buy-later. There is no quantity.
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<article class="ci">
|
<article class="ci">
|
||||||
@@ -32,41 +32,11 @@
|
|||||||
<span v-if="rialWage > 0" class="ci__wage">اجرت ریالی {{ price(rialWage) }} ریال</span>
|
<span v-if="rialWage > 0" class="ci__wage">اجرت ریالی {{ price(rialWage) }} ریال</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p v-if="rialWage > 0 && value.qty > 1" class="ci__rialTotal">
|
|
||||||
جمع اجرت {{ price(rialWage * value.qty) }} ریال
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="ci__row">
|
<div class="ci__row">
|
||||||
<!-- App-wide stepper order rule (also followed by SingleProduct.vue's
|
<button type="button" class="ci__remove" aria-label="حذف" @click="removeLine">
|
||||||
.pd__qty): plus on the visual right, minus (or trash at qty 1) on
|
|
||||||
the visual left. The page is RTL, so a plain flex row lays its
|
|
||||||
DOM-first child on the right — plus has to come FIRST in markup,
|
|
||||||
not last, to land there. Keep both steppers' DOM order in sync if
|
|
||||||
either one changes. -->
|
|
||||||
<div class="ci__qty">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="ci__qtyBtn"
|
|
||||||
aria-label="افزودن"
|
|
||||||
:disabled="!canIncrement"
|
|
||||||
@click="increment"
|
|
||||||
>
|
|
||||||
<Icon icon="vuesax-linear:add" size="16" />
|
|
||||||
</button>
|
|
||||||
<span class="ci__qtyValue">{{ value.qty }}</span>
|
|
||||||
<button
|
|
||||||
v-if="value.qty === 1"
|
|
||||||
type="button"
|
|
||||||
class="ci__qtyBtn ci__qtyBtn--danger"
|
|
||||||
aria-label="حذف"
|
|
||||||
@click="removeLine"
|
|
||||||
>
|
|
||||||
<Icon icon="vuesax-linear:trash" size="16" />
|
<Icon icon="vuesax-linear:trash" size="16" />
|
||||||
|
حذف
|
||||||
</button>
|
</button>
|
||||||
<button v-else type="button" class="ci__qtyBtn" aria-label="کاهش" @click="decrement">
|
|
||||||
<Icon icon="vuesax-linear:minus" size="16" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="button" class="ci__note" @click="emit('note', listIndex)">
|
<button type="button" class="ci__note" @click="emit('note', listIndex)">
|
||||||
<Icon icon="vuesax-linear:note-text" size="15" />
|
<Icon icon="vuesax-linear:note-text" size="15" />
|
||||||
@@ -124,25 +94,6 @@ const listIndex = computed(() =>
|
|||||||
props.mode === 'buyLater' ? buyLater.find_index(props.value) : cart.find_index(props.value),
|
props.mode === 'buyLater' ? buyLater.find_index(props.value) : cart.find_index(props.value),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Active cart: stock ceiling. Buy-later: uncapped (desired qty for later).
|
|
||||||
const maxQty = computed(() => (props.mode === 'cart' ? cart.maxQty(props.value) : null))
|
|
||||||
const canIncrement = computed(() => maxQty.value === null || props.value.qty < maxQty.value)
|
|
||||||
|
|
||||||
const increment = () => {
|
|
||||||
if (!canIncrement.value) return
|
|
||||||
if (props.mode === 'buyLater') {
|
|
||||||
buyLater.updateQty(props.value, props.value.qty + 1)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cart.updateFeild(props.value.qty + 1, listIndex.value, props.value, 'qty')
|
|
||||||
}
|
|
||||||
const decrement = () => {
|
|
||||||
if (props.mode === 'buyLater') {
|
|
||||||
buyLater.updateQty(props.value, props.value.qty - 1)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cart.updateFeild(props.value.qty - 1, listIndex.value, props.value, 'qty')
|
|
||||||
}
|
|
||||||
const removeLine = () => {
|
const removeLine = () => {
|
||||||
if (props.mode === 'buyLater') buyLater.remove(props.value)
|
if (props.mode === 'buyLater') buyLater.remove(props.value)
|
||||||
else cart.remove(props.value)
|
else cart.remove(props.value)
|
||||||
@@ -195,14 +146,27 @@ const wageLabel = computed(() => {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ci__art img[lazy='loading'],
|
||||||
|
.ci__art img[lazy='error'] {
|
||||||
|
width: 64px;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
// Dark mode: product photos are shot on white, so they sit on a light mat
|
// Dark mode: product photos are shot on white, so they sit on a light mat
|
||||||
// instead of showing as white boxes on a dark card (@photoMat — transparent,
|
// instead of showing as white boxes on a dark card (@photoMat — transparent,
|
||||||
// i.e. no change, in light mode).
|
// i.e. no change, in light mode). The brand mark that stands in while a photo
|
||||||
|
// loads is black line art, so it stays on the card and is drawn light.
|
||||||
html.theme-dark .ci__art img {
|
html.theme-dark .ci__art img {
|
||||||
background: @photoMat;
|
background: @photoMat;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html.theme-dark .ci__art img[lazy='loading'],
|
||||||
|
html.theme-dark .ci__art img[lazy='error'] {
|
||||||
|
background: transparent;
|
||||||
|
filter: invert(1);
|
||||||
|
}
|
||||||
|
|
||||||
.ci__artEmpty {
|
.ci__artEmpty {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -247,13 +211,6 @@ html.theme-dark .ci__art img {
|
|||||||
border-inline-start: 1px solid @hairline;
|
border-inline-start: 1px solid @hairline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ci__rialTotal {
|
|
||||||
margin: 5px 0 0;
|
|
||||||
font-size: 11.5px;
|
|
||||||
font-weight: 700;
|
|
||||||
color: @wine;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ci__row {
|
.ci__row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -262,43 +219,24 @@ html.theme-dark .ci__art img {
|
|||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ci__qty {
|
.ci__remove {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 4px;
|
gap: 5px;
|
||||||
padding: 3px;
|
height: 32px;
|
||||||
border-radius: 999px;
|
padding: 0 12px;
|
||||||
background: @hairlineSoft;
|
|
||||||
border: 1px solid @hairline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ci__qtyBtn {
|
|
||||||
width: 27px;
|
|
||||||
height: 27px;
|
|
||||||
border: 0;
|
border: 0;
|
||||||
|
border-radius: 999px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border-radius: 50%;
|
font-family: inherit;
|
||||||
display: grid;
|
font-size: 12px;
|
||||||
place-items: center;
|
|
||||||
color: @inkSoft;
|
|
||||||
background: @canvas;
|
|
||||||
transition: transform 0.15s ease, color 0.15s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ci__qtyBtn--danger {
|
|
||||||
color: @wine;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ci__qtyBtn:active {
|
|
||||||
transform: scale(0.9);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ci__qtyValue {
|
|
||||||
min-width: 22px;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 12.5px;
|
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: @ink;
|
color: @wine;
|
||||||
|
background: @hairlineSoft;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ci__remove:active {
|
||||||
|
transform: scale(0.96);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ci__note {
|
.ci__note {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="oi__figures">
|
<div class="oi__figures">
|
||||||
<span class="oi__figure">
|
<span v-if="value.quantity > 1" class="oi__figure">
|
||||||
{{ value.quantity }}
|
{{ value.quantity }}
|
||||||
<i>عدد</i>
|
<i>عدد</i>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -135,14 +135,30 @@ function wageLabel(v: number) {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The stand-in is the brand mark, not a photo, so it stays a mark in the
|
||||||
|
// middle of the frame instead of filling the slot the piece will occupy.
|
||||||
|
.pc__art img[lazy='loading'],
|
||||||
|
.pc__art img[lazy='error'] {
|
||||||
|
max-width: 62%;
|
||||||
|
max-height: 52%;
|
||||||
|
}
|
||||||
|
|
||||||
// Dark mode: product photos are shot on white, so they sit on a light mat
|
// Dark mode: product photos are shot on white, so they sit on a light mat
|
||||||
// instead of showing as white boxes on a dark card (@photoMat — transparent,
|
// instead of showing as white boxes on a dark card (@photoMat — transparent,
|
||||||
// i.e. no change, in light mode).
|
// i.e. no change, in light mode). The brand mark that stands in while a photo
|
||||||
|
// loads is black line art, so it stays on the card and is drawn light, the
|
||||||
|
// same way the header logo is.
|
||||||
html.theme-dark .pc__art img {
|
html.theme-dark .pc__art img {
|
||||||
background: @photoMat;
|
background: @photoMat;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html.theme-dark .pc__art img[lazy='loading'],
|
||||||
|
html.theme-dark .pc__art img[lazy='error'] {
|
||||||
|
background: transparent;
|
||||||
|
filter: invert(1);
|
||||||
|
}
|
||||||
|
|
||||||
.pc__artEmpty {
|
.pc__artEmpty {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -212,32 +212,7 @@
|
|||||||
|
|
||||||
<!-- ── Action bar ────────────────────────────────────── -->
|
<!-- ── Action bar ────────────────────────────────────── -->
|
||||||
<div class="pd__bar">
|
<div class="pd__bar">
|
||||||
<!-- The reference's left pill. When the piece is not yet in the cart
|
<button v-if="categoryTitle" type="button" class="pd__pill" @click="goCategory">
|
||||||
it deep-links to its category (a real destination); once it is, it
|
|
||||||
becomes the quantity stepper, which has to live somewhere and this
|
|
||||||
is the slot the layout already gives it. -->
|
|
||||||
<!-- Stepper order rule, the same one CartItem.vue follows: plus on
|
|
||||||
the visual right, minus (or trash at qty 1) on the visual left.
|
|
||||||
The page is RTL, so a plain flex row already lays its DOM-first
|
|
||||||
child on the right — plus has to be FIRST in markup, not last, to
|
|
||||||
land there. (FIXED: this used to be minus/trash, value, plus —
|
|
||||||
the reverse of the intended layout, which put plus on the visual
|
|
||||||
left instead of the right.) -->
|
|
||||||
<div v-if="inCart" class="pd__qty">
|
|
||||||
<button type="button" class="pd__qtyBtn" aria-label="افزایش" @click="increment">
|
|
||||||
<Icon icon="vuesax-linear:add" size="15" />
|
|
||||||
</button>
|
|
||||||
<span class="pd__qtyValue">{{ cartQty }}</span>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="pd__qtyBtn"
|
|
||||||
:aria-label="cartQty === 1 ? 'حذف' : 'کاهش'"
|
|
||||||
@click="decrement"
|
|
||||||
>
|
|
||||||
<Icon :icon="cartQty === 1 ? 'vuesax-linear:trash' : 'vuesax-linear:minus'" size="15" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<button v-else-if="categoryTitle" type="button" class="pd__pill" @click="goCategory">
|
|
||||||
<Icon icon="vuesax-linear:category" size="17" />
|
<Icon icon="vuesax-linear:category" size="17" />
|
||||||
<span class="pd__pillText">{{ categoryTitle }}</span>
|
<span class="pd__pillText">{{ categoryTitle }}</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -254,7 +229,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<router-link v-else class="pd__cta" :to="{ name: 'cart' }">
|
<router-link v-else class="pd__cta" :to="{ name: 'cart' }">
|
||||||
<Icon icon="vuesax-linear:bag-2" size="17" />
|
<Icon icon="vuesax-linear:bag-2" size="17" />
|
||||||
مشاهده سبد خرید
|
در سبد خرید
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
@@ -475,7 +450,7 @@ const wageLabel = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const stockLabel = computed(() => {
|
const stockLabel = computed(() => {
|
||||||
if (qty.value > 0) return `${qty.value} عدد موجود`
|
if (qty.value > 0) return 'موجود'
|
||||||
return isPreOrder.value ? 'پیشسفارش' : 'ناموجود'
|
return isPreOrder.value ? 'پیشسفارش' : 'ناموجود'
|
||||||
})
|
})
|
||||||
const stockClass = computed(() => {
|
const stockClass = computed(() => {
|
||||||
@@ -491,27 +466,7 @@ const storeProduct = computed<CartItem>(() => ({
|
|||||||
qty: 1,
|
qty: 1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Quantity control reuses the store's updateFeild(...,'qty') path, the same one
|
|
||||||
// CartItem uses; the store has no dedicated increment/decrement.
|
|
||||||
const inCart = computed(() => cart.isInCart(storeProduct.value))
|
const inCart = computed(() => cart.isInCart(storeProduct.value))
|
||||||
const cartIndex = computed(() => cart.find_index(storeProduct.value))
|
|
||||||
const cartQty = computed(() => (cartIndex.value > -1 ? cart.items[cartIndex.value].qty : 0))
|
|
||||||
|
|
||||||
// Stock ceiling: a pre-order variant may exceed what is on hand, anything else
|
|
||||||
// stops at its qty. The store clamps too — this just keeps the button honest.
|
|
||||||
const cartMaxQty = computed(() => cart.maxQty(storeProduct.value))
|
|
||||||
const canIncrement = computed(() => cartMaxQty.value === null || cartQty.value < cartMaxQty.value)
|
|
||||||
const increment = () => {
|
|
||||||
if (!canIncrement.value) return
|
|
||||||
cart.updateFeild(cartQty.value + 1, cartIndex.value, storeProduct.value, 'qty')
|
|
||||||
}
|
|
||||||
const decrement = () => {
|
|
||||||
if (cartQty.value <= 1) {
|
|
||||||
cart.remove(storeProduct.value)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cart.updateFeild(cartQty.value - 1, cartIndex.value, storeProduct.value, 'qty')
|
|
||||||
}
|
|
||||||
|
|
||||||
const isOrderable = (v: Parameters<typeof isVariantOrderable>[0]) => isVariantOrderable(v)
|
const isOrderable = (v: Parameters<typeof isVariantOrderable>[0]) => isVariantOrderable(v)
|
||||||
|
|
||||||
@@ -1295,40 +1250,6 @@ onBeforeUnmount(() => {
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pd__qty {
|
|
||||||
flex-shrink: 0;
|
|
||||||
height: 48px;
|
|
||||||
padding: 0 6px;
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 4px;
|
|
||||||
border-radius: 999px;
|
|
||||||
border: 1px solid @hairline;
|
|
||||||
background: @canvas;
|
|
||||||
}
|
|
||||||
.pd__qtyBtn {
|
|
||||||
width: 32px;
|
|
||||||
height: 32px;
|
|
||||||
display: grid;
|
|
||||||
place-items: center;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 50%;
|
|
||||||
cursor: pointer;
|
|
||||||
color: @ink;
|
|
||||||
background: @hairlineSoft;
|
|
||||||
transition: transform 0.18s ease;
|
|
||||||
}
|
|
||||||
.pd__qtyBtn:active {
|
|
||||||
transform: scale(0.9);
|
|
||||||
}
|
|
||||||
.pd__qtyValue {
|
|
||||||
min-width: 20px;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 13px;
|
|
||||||
font-weight: 800;
|
|
||||||
color: @ink;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pd__cta {
|
.pd__cta {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { setUnauthorizedHandler } from './api/client';
|
|||||||
import { useSessionStore } from './stores/session';
|
import { useSessionStore } from './stores/session';
|
||||||
import { useAppearanceStore } from './stores/appearanceStore';
|
import { useAppearanceStore } from './stores/appearanceStore';
|
||||||
import Container from './components/ui/Container.vue';
|
import Container from './components/ui/Container.vue';
|
||||||
import Vector from './assets/img/Vector.svg';
|
import brandLogo from './assets/img/brand-logo.svg';
|
||||||
|
|
||||||
// Vant defaults to zh-CN. Every view in this app is Persian (RTL), so any
|
// Vant defaults to zh-CN. Every view in this app is Persian (RTL), so any
|
||||||
// Vant component rendering its own built-in text (PullRefresh's
|
// Vant component rendering its own built-in text (PullRefresh's
|
||||||
@@ -48,12 +48,11 @@ setUnauthorizedHandler(() => {
|
|||||||
void router.replace({ name: 'login' });
|
void router.replace({ name: 'login' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Ported from legacy main.ts:32-46 — Vector.svg is both the while-loading and
|
// While a catalogue photo is still loading, and if it fails, the brand mark
|
||||||
// the on-error placeholder, so a missing/failed image paints the brand mark
|
// stands in the frame. Same file the header and the login screen use.
|
||||||
// instead of collapsing the layout.
|
|
||||||
app.use(VueLazyLoad, {
|
app.use(VueLazyLoad, {
|
||||||
loading: Vector,
|
loading: brandLogo,
|
||||||
error: Vector,
|
error: brandLogo,
|
||||||
});
|
});
|
||||||
app.component('container', Container);
|
app.component('container', Container);
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* (cart never reserved stock; this list also never reserves).
|
* (cart never reserved stock; this list also never reserves).
|
||||||
* - Move here → cart: uses cart.addToCart stock guards; on failure the line
|
* - Move here → cart: uses cart.addToCart stock guards; on failure the line
|
||||||
* stays here so an out-of-stock deferral is not lost.
|
* stays here so an out-of-stock deferral is not lost.
|
||||||
* - Qty/note editable here without stock ceiling (desired qty for later).
|
* - One of each variant. A line is the piece itself; qty stays 1.
|
||||||
* - Survives daily cart expiry and successful order (active cart only clears).
|
* - Survives daily cart expiry and successful order (active cart only clears).
|
||||||
* - Guest: localStorage; logged-in: debounced PUT /cart/buy-later.
|
* - Guest: localStorage; logged-in: debounced PUT /cart/buy-later.
|
||||||
* - Acting-as / logout: list is cleared in memory like the active cart.
|
* - Acting-as / logout: list is cleared in memory like the active cart.
|
||||||
@@ -26,8 +26,8 @@ function loadStored(): CartItem[] {
|
|||||||
const raw = localStorage.getItem(STORAGE_KEY)
|
const raw = localStorage.getItem(STORAGE_KEY)
|
||||||
if (!raw) return []
|
if (!raw) return []
|
||||||
const parsed = JSON.parse(raw)
|
const parsed = JSON.parse(raw)
|
||||||
if (Array.isArray(parsed)) return parsed
|
if (Array.isArray(parsed)) return parsed.map((item) => ({ ...item, qty: 1 }))
|
||||||
return Array.isArray(parsed?.items) ? parsed.items : []
|
return Array.isArray(parsed?.items) ? parsed.items.map((item: CartItem) => ({ ...item, qty: 1 })) : []
|
||||||
} catch {
|
} catch {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ function toServerItems(items: CartItem[]) {
|
|||||||
return items.map((i) => ({
|
return items.map((i) => ({
|
||||||
pid: i.pid,
|
pid: i.pid,
|
||||||
vid: i.vid,
|
vid: i.vid,
|
||||||
qty: i.qty,
|
qty: 1,
|
||||||
note: i.note ?? null,
|
note: i.note ?? null,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ export const useBuyLaterStore = defineStore('buyLater', {
|
|||||||
next.push({
|
next.push({
|
||||||
pid: line.pid,
|
pid: line.pid,
|
||||||
vid: line.vid,
|
vid: line.vid,
|
||||||
qty: Math.max(1, Math.floor(line.qty) || 1),
|
qty: 1,
|
||||||
note: line.note ?? null,
|
note: line.note ?? null,
|
||||||
product: blob,
|
product: blob,
|
||||||
})
|
})
|
||||||
@@ -143,17 +143,16 @@ export const useBuyLaterStore = defineStore('buyLater', {
|
|||||||
return this.items.findIndex((i) => i.pid === item.pid && i.vid === item.vid)
|
return this.items.findIndex((i) => i.pid === item.pid && i.vid === item.vid)
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Upsert a line without any stock check. */
|
/** Upsert a line. A variant already here stays the one piece it is. */
|
||||||
upsert(item: CartItem) {
|
upsert(item: CartItem) {
|
||||||
const qty = Math.max(1, Math.floor(item.qty) || 1)
|
|
||||||
const i = this.find_index(item)
|
const i = this.find_index(item)
|
||||||
if (i === -1) {
|
if (i === -1) {
|
||||||
this.items.push({ ...item, qty })
|
this.items.push({ ...item, qty: 1 })
|
||||||
} else {
|
} else {
|
||||||
this.items[i] = {
|
this.items[i] = {
|
||||||
...this.items[i],
|
...this.items[i],
|
||||||
product: item.product,
|
product: item.product,
|
||||||
qty,
|
qty: 1,
|
||||||
note: item.note ?? this.items[i].note,
|
note: item.note ?? this.items[i].note,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,10 +166,10 @@ export const useBuyLaterStore = defineStore('buyLater', {
|
|||||||
this.writeLocal()
|
this.writeLocal()
|
||||||
},
|
},
|
||||||
|
|
||||||
updateQty(item: Pick<CartItem, 'pid' | 'vid'>, qty: number) {
|
updateQty(item: Pick<CartItem, 'pid' | 'vid'>, _qty: number) {
|
||||||
const i = this.find_index(item)
|
const i = this.find_index(item)
|
||||||
if (i === -1) return
|
if (i === -1) return
|
||||||
this.items[i].qty = Math.max(1, Math.floor(qty) || 1)
|
this.items[i].qty = 1
|
||||||
this.writeLocal()
|
this.writeLocal()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ function loadStored(): StoredCart {
|
|||||||
const parsed = JSON.parse(raw)
|
const parsed = JSON.parse(raw)
|
||||||
// Legacy shape was a bare array.
|
// Legacy shape was a bare array.
|
||||||
if (Array.isArray(parsed)) {
|
if (Array.isArray(parsed)) {
|
||||||
return { items: parsed, touchedAt: null }
|
return { items: oneEach(parsed), touchedAt: null }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
items: Array.isArray(parsed?.items) ? parsed.items : [],
|
items: oneEach(Array.isArray(parsed?.items) ? parsed.items : []),
|
||||||
touchedAt: typeof parsed?.touchedAt === 'string' ? parsed.touchedAt : null,
|
touchedAt: typeof parsed?.touchedAt === 'string' ? parsed.touchedAt : null,
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -48,11 +48,16 @@ function persist(items: CartItem[], touchedAt: string | null) {
|
|||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify({ items, touchedAt }))
|
localStorage.setItem(STORAGE_KEY, JSON.stringify({ items, touchedAt }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A variant is one physical piece, so a line never carries a count above one. */
|
||||||
|
function oneEach(items: CartItem[]): CartItem[] {
|
||||||
|
return items.map((item) => ({ ...item, qty: 1 }))
|
||||||
|
}
|
||||||
|
|
||||||
function toServerItems(items: CartItem[]) {
|
function toServerItems(items: CartItem[]) {
|
||||||
return items.map((i) => ({
|
return items.map((i) => ({
|
||||||
pid: i.pid,
|
pid: i.pid,
|
||||||
vid: i.vid,
|
vid: i.vid,
|
||||||
qty: i.qty,
|
qty: 1,
|
||||||
note: i.note ?? null,
|
note: i.note ?? null,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -172,7 +177,7 @@ export const useCartStore = defineStore('cart', {
|
|||||||
next.push({
|
next.push({
|
||||||
pid: line.pid,
|
pid: line.pid,
|
||||||
vid: line.vid,
|
vid: line.vid,
|
||||||
qty: line.qty,
|
qty: 1,
|
||||||
note: line.note ?? null,
|
note: line.note ?? null,
|
||||||
product,
|
product,
|
||||||
})
|
})
|
||||||
@@ -207,35 +212,16 @@ export const useCartStore = defineStore('cart', {
|
|||||||
if (!((target.qty ?? 0) > 0 || target.isPreOrder)) return false
|
if (!((target.qty ?? 0) > 0 || target.isPreOrder)) return false
|
||||||
|
|
||||||
const index = this.find_index(data)
|
const index = this.find_index(data)
|
||||||
if (index === -1) this.items.push({ ...data, qty: this.capQty(data.qty, target) })
|
if (index === -1) this.items.push({ ...data, qty: 1 })
|
||||||
else {
|
else {
|
||||||
|
// Already in the basket. Refresh the product blob and leave the line
|
||||||
|
// as the one piece it is — a second add must not become two.
|
||||||
this.items[index].product = data.product
|
this.items[index].product = data.product
|
||||||
this.items[index].qty = this.capQty(data.qty, target)
|
this.items[index].qty = 1
|
||||||
}
|
}
|
||||||
this.writeLocal(true)
|
this.writeLocal(true)
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Stock ceiling for a cart line. A pre-order variant is orderable beyond
|
|
||||||
* what is on hand (that is the point of pre-ordering), so it is uncapped;
|
|
||||||
* anything else stops at its on-hand quantity.
|
|
||||||
*/
|
|
||||||
capQty(want: number, variant: { qty?: number; isPreOrder?: boolean }) {
|
|
||||||
const n = Math.max(1, Math.floor(want) || 1)
|
|
||||||
if (variant.isPreOrder) return n
|
|
||||||
const max = variant.qty ?? 0
|
|
||||||
return max > 0 ? Math.min(n, max) : n
|
|
||||||
},
|
|
||||||
|
|
||||||
/** The ceiling for an item already in the cart; null when uncapped. */
|
|
||||||
maxQty(item: Pick<CartItem, 'pid' | 'vid'>) {
|
|
||||||
const i = this.find_index(item)
|
|
||||||
if (i === -1) return null
|
|
||||||
const v = this.variant(this.items[i])
|
|
||||||
if (!v || v.isPreOrder) return null
|
|
||||||
return (v.qty ?? 0) > 0 ? (v.qty as number) : null
|
|
||||||
},
|
|
||||||
remove(item: CartItem) {
|
remove(item: CartItem) {
|
||||||
const index = this.find_index(item)
|
const index = this.find_index(item)
|
||||||
if (index > -1) this.items.splice(index, 1)
|
if (index > -1) this.items.splice(index, 1)
|
||||||
@@ -246,13 +232,8 @@ export const useCartStore = defineStore('cart', {
|
|||||||
updateFeild(value: unknown, index: number | null, item: Pick<CartItem, 'pid' | 'vid'>, field: keyof CartItem) {
|
updateFeild(value: unknown, index: number | null, item: Pick<CartItem, 'pid' | 'vid'>, field: keyof CartItem) {
|
||||||
if (!this.isInCart(item)) return false
|
if (!this.isInCart(item)) return false
|
||||||
const i = index ?? this.find_index(item)
|
const i = index ?? this.find_index(item)
|
||||||
// A quantity change is clamped to what is actually in stock (unless the
|
// A line is one piece. Notes still update; a quantity write cannot.
|
||||||
// variant is pre-orderable), so the ceiling holds no matter which screen
|
if (field === 'qty') value = 1
|
||||||
// drives the stepper.
|
|
||||||
if (field === 'qty') {
|
|
||||||
const v = this.variant(this.items[i])
|
|
||||||
value = v ? this.capQty(Number(value), v) : Math.max(1, Number(value) || 1)
|
|
||||||
}
|
|
||||||
;(this.items[i] as any)[field] = value
|
;(this.items[i] as any)[field] = value
|
||||||
this.writeLocal(true)
|
this.writeLocal(true)
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ const submitOrder = async () => {
|
|||||||
const variant = cart.variant(item)
|
const variant = cart.variant(item)
|
||||||
return {
|
return {
|
||||||
productVariantId: item.vid,
|
productVariantId: item.vid,
|
||||||
quantity: item.qty,
|
quantity: 1,
|
||||||
// Sent for older API builds only: the server prices app orders itself
|
// Sent for older API builds only: the server prices app orders itself
|
||||||
// (MON-08) and ignores this figure.
|
// (MON-08) and ignores this figure.
|
||||||
wagePercent: variant ? parseFloat(variant.defaultWagePercent) : 0,
|
wagePercent: variant ? parseFloat(variant.defaultWagePercent) : 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user