fix bugs of physicalRecieve & login-code-input & odometer-digit
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
/>
|
||||
<div class="pr-cart-row__stock text-xs">
|
||||
<span>مقدار موجودی</span>
|
||||
<span class="font-bold">{{ item.product.wallet.gold }}</span>
|
||||
<span>{{ getProductQuantityUnit(item.product) }}</span>
|
||||
<span class="font-bold">{{ displayGold }}</span>
|
||||
<span>{{ quantityUnit }}</span>
|
||||
<div
|
||||
v-if="getProductUnitWeightLabel(item.product)"
|
||||
class="mt-0.5 text-xs text-gray-500"
|
||||
@@ -26,34 +26,42 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2 flex justify-between items-center gap-2">
|
||||
<div class="shrink-0">تعداد درخواستی:</div>
|
||||
<div class="shrink-0">{{ isCountBased ? 'تعداد درخواستی:' : 'مقدار درخواستی:' }}</div>
|
||||
<div
|
||||
class="flex items-center gap-1 "
|
||||
class="flex items-center gap-1"
|
||||
:class="variant === 'desktop' ? 'dpr-cart-row__input' : 'pr-cart-row__input'"
|
||||
>
|
||||
<BasicInput
|
||||
v-model:value="item.count"
|
||||
:addon-before="getProductQuantityUnit(item.product)"
|
||||
:addon-before="quantityUnit"
|
||||
:addon-bg-color="config.config?.color"
|
||||
addon-text-color="white"
|
||||
type="text"
|
||||
inputmode="numeric"
|
||||
:inputmode="isCountBased ? 'numeric' : 'decimal'"
|
||||
@update:value="onCountInput"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="countError" class="mt-1 text-xs text-red-600">{{ countError }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
||||
import { useConfigStore } from '@/store/configStore'
|
||||
import type { CountPInventory } from '@/models/products'
|
||||
import { getProductDisplayImage } from '@/utils/productAssets'
|
||||
import { getProductQuantityUnit, getProductUnitWeightLabel } from '@/utils/productDealMethod'
|
||||
import {
|
||||
getProductQuantityUnit,
|
||||
getProductUnitWeightLabel,
|
||||
isCountBasedProduct,
|
||||
} from '@/utils/productDealMethod'
|
||||
import { formatGoldAmount, usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { persianToEnglishDigits } from '@/utils/persianDigits'
|
||||
|
||||
interface Props {
|
||||
item: CountPInventory
|
||||
@@ -64,6 +72,10 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
variant: 'mobile',
|
||||
})
|
||||
|
||||
const countError = ref('')
|
||||
const isCountBased = computed(() => isCountBasedProduct(props.item.product))
|
||||
const quantityUnit = computed(() => getProductQuantityUnit(props.item.product))
|
||||
|
||||
const displayImage = computed(() =>
|
||||
getProductDisplayImage({
|
||||
group_type: props.item.product.group_type,
|
||||
@@ -72,8 +84,49 @@ const displayImage = computed(() =>
|
||||
})
|
||||
)
|
||||
|
||||
const displayGold = computed(() => {
|
||||
const gold = Number(props.item.product.wallet?.gold ?? 0)
|
||||
return isCountBased.value ? usePriceWithoutType(gold, false) : formatGoldAmount(gold)
|
||||
})
|
||||
|
||||
const config = useConfigStore()
|
||||
|
||||
function onCountInput(raw: string | number) {
|
||||
countError.value = ''
|
||||
const normalized = persianToEnglishDigits(String(raw ?? '').trim())
|
||||
if (!normalized) {
|
||||
props.item.count = 0 as any
|
||||
return
|
||||
}
|
||||
|
||||
const numeric = Number(normalized)
|
||||
if (!Number.isFinite(numeric)) {
|
||||
countError.value = 'مقدار معتبر وارد کنید'
|
||||
return
|
||||
}
|
||||
|
||||
if (isCountBased.value) {
|
||||
if (numeric % 1 !== 0) {
|
||||
countError.value = 'برای محصول تعدادی فقط عدد صحیح مجاز است'
|
||||
props.item.count = Math.floor(numeric) as any
|
||||
return
|
||||
}
|
||||
props.item.count = Math.floor(numeric) as any
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.item.count,
|
||||
(value) => {
|
||||
if (!isCountBased.value) return
|
||||
const numeric = Number(value)
|
||||
if (Number.isFinite(numeric) && numeric % 1 !== 0) {
|
||||
props.item.count = Math.floor(numeric) as any
|
||||
countError.value = 'برای محصول تعدادی فقط عدد صحیح مجاز است'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
remove: [id: number]
|
||||
}>()
|
||||
|
||||
Reference in New Issue
Block a user