limit added

This commit is contained in:
2026-06-06 22:41:42 +03:30
parent 183fd09289
commit a984710c0a
5 changed files with 127 additions and 6 deletions
+1
View File
@@ -8,6 +8,7 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
AButton: typeof import('ant-design-vue/es')['Button']
AConfigProvider: typeof import('ant-design-vue/es')['ConfigProvider']
ADivider: typeof import('ant-design-vue/es')['Divider']
AForm: typeof import('ant-design-vue/es')['Form']
AFormItem: typeof import('ant-design-vue/es')['FormItem']
+3
View File
@@ -19,6 +19,9 @@ export interface Product {
percent_fee_sell: number | undefined
cash_fee_buy: number | undefined
cash_fee_sell: number | undefined
order_limit_enabled?: boolean
min_order_cash?: number | null
max_order_cash?: number | null
direct_price: number | undefined
reading_method: any
created_at: any
+72
View File
@@ -0,0 +1,72 @@
import type { Product } from '@/models/products'
import { usePriceWithoutType } from '@/utils/usePrice'
type LimitProduct = Pick<Product, 'order_limit_enabled' | 'min_order_cash' | 'max_order_cash'> | null | undefined
export function productOrderLimitEnabled(product?: LimitProduct): boolean {
if (!product?.order_limit_enabled) return false
return product.min_order_cash != null || product.max_order_cash != null
}
export function productMinOrderCash(product?: LimitProduct, isBuy = true, defaultBuyMin = 500_000): number {
if (productOrderLimitEnabled(product) && product?.min_order_cash != null) {
return Number(product.min_order_cash)
}
return isBuy ? defaultBuyMin : 0
}
export function productMaxOrderCash(product?: LimitProduct): number | undefined {
if (productOrderLimitEnabled(product) && product?.max_order_cash != null) {
return Number(product.max_order_cash)
}
return undefined
}
export function productCashValidationMessage(
product: LimitProduct,
goldCash: number | string | undefined,
isBuy: boolean,
formatPrice: (value: number) => string = usePriceWithoutType
): string {
if (goldCash === '' || goldCash === undefined) return ''
const cash = Number(goldCash ?? 0)
const min = productMinOrderCash(product, isBuy)
const max = productMaxOrderCash(product)
if (max != null && cash > max) {
return `حداکثر مبلغ این محصول ${formatPrice(max)} ریال است`
}
if (min > 0 && cash < min) {
if (productOrderLimitEnabled(product) && product?.min_order_cash != null) {
return `حداقل مبلغ این محصول ${formatPrice(min)} ریال است`
}
return `حداقل مبلغ طلا جهت ${isBuy ? 'خرید' : 'فروش'} ${formatPrice(min)} ریال می باشد.`
}
return ''
}
export function validateProductOrderLimitForm(form: {
order_limit_enabled?: boolean
min_order_cash?: number | string | null
max_order_cash?: number | string | null
}): string | null {
if (!form.order_limit_enabled) return null
const min = form.min_order_cash
const max = form.max_order_cash
const hasMin = min != null && min !== ''
const hasMax = max != null && max !== ''
if (!hasMin && !hasMax) {
return 'با فعال بودن محدودیت مبلغ سفارش، حداقل یکی از حداقل یا حداکثر مبلغ باید وارد شود'
}
if (hasMin && hasMax && Number(min) > Number(max)) {
return 'حداقل مبلغ نمی‌تواند بیشتر از حداکثر باشد'
}
return null
}
+29 -4
View File
@@ -58,6 +58,9 @@
place-holder="مقدار طلا"
size="large" type="text" inputmode="decimal" @onchange="calculateCash" />
</a-form-item>
<div v-if="cashValidationMessage" class="text-red-700 text-xs font-bold mt-2">
{{ cashValidationMessage }}
</div>
<!-- {{walletStore?.walletInfo?.gold}}-->
<Transition mode="out-in" name="fade">
<div v-if="!isBuy" class="font-bold text-xs">
@@ -119,9 +122,9 @@
({{ walletStore?.walletInfo?.gold }}گرم) می باشد.
</div>
<!-- <div>{{form?.goldValue? true: false}}</div>-->
<div v-if="isBuy? ((form?.goldValue || form.goldValue === 0)? form?.goldCash < 500000: false) : false"
<div v-if="isBuy ? (form?.goldCash > walletStore?.walletInfo?.cash) : false"
class="text-red-700 text-xs font-bold mt-2">
حداقل مقدار طلا جهت خرید 500,000 ریال می باشد.
موجودی کیف پول ناکافی می باشد.
</div>
</a-form-item>
<div class=" w-full bottom-18 px-6 rounded-xl py-1 border-1 bg-white">
@@ -236,6 +239,11 @@ import { calcFeeInGrams, loadServiceFeeFromSettings } from '@/utils/serviceFee'
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
import { useSettingsStore } from '@/store/settingsStore'
import { storeToRefs } from 'pinia'
import {
productCashValidationMessage,
productMaxOrderCash,
productMinOrderCash
} from '@/utils/productOrderLimit'
const infoVisible = ref(false)
const walletStore = useWalletStore()
@@ -293,13 +301,25 @@ const payablePrice = computed(() =>
isBuy.value ? finalPrice.value + feeInRial.value : finalPrice.value - feeInRial.value
)
const minOrderCash = computed(() => productMinOrderCash(props.ProductItem, isBuy.value))
const maxOrderCash = computed(() => productMaxOrderCash(props.ProductItem))
const cashValidationMessage = computed(() =>
productCashValidationMessage(props.ProductItem, form.value?.goldCash, isBuy.value, usePriceWithoutType)
)
const disableTransaction = computed(() =>
loading.value ||
form.value?.goldValue === undefined ||
form.value?.goldValue === '' ||
form.value?.goldCash === '' ||
form.value?.goldCash === undefined ||
(isBuy.value ? (form.value?.goldCash ?? 0) < 500000 : (form.value?.goldValue ?? 0) < 0.001) ||
(isBuy.value
? (form.value?.goldCash ?? 0) < minOrderCash.value
: (productMinOrderCash(props.ProductItem, false) > 0 || productMaxOrderCash(props.ProductItem) != null
? ((form.value?.goldCash ?? 0) < minOrderCash.value || (maxOrderCash.value != null && (form.value?.goldCash ?? 0) > maxOrderCash.value))
: (form.value?.goldValue ?? 0) < 0.001)) ||
(maxOrderCash.value != null && (form.value?.goldCash ?? 0) > maxOrderCash.value) ||
cashValidationMessage.value !== '' ||
(!isBuy.value && form.value.goldValue > walletStore?.walletInfo?.gold) ||
!lastPrice.value ||
(isBuy.value ? getTradeBuyPrice(lastPrice.value) <= 0 : getTradeSellPrice(lastPrice.value) <= 0))
@@ -592,6 +612,10 @@ async function initPrice() {
}
function okConfirm() {
if (cashValidationMessage.value) {
message.warning(cashValidationMessage.value)
return
}
confirmAction.value = true
}
@@ -602,7 +626,8 @@ async function ok() {
await createOrder({
direction: isBuy.value ? 1 : 2,
price: isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value),
amount: form.value.goldValue ?? 0
amount: form.value.goldValue ?? 0,
abshode_id: props.ProductItem?.id,
})
await walletStore.getMyWallet()
await router.push({ name: 'transactions' })
@@ -79,6 +79,10 @@
<div>{{ usePrice(form.goldCash ?? 0) }}</div>
</div>
<div v-if="cashValidationMessage" class="text-red-700 text-xs font-bold mt-2">
{{ cashValidationMessage }}
</div>
<div v-if="shouldShowProductTotalWeight(props?.ProductItem)" class="flex justify-between">
<div>وزن کل</div>
<div>{{ totalWeightDisplay }}</div>
@@ -276,6 +280,11 @@ import {
isCountBasedProduct,
shouldShowProductTotalWeight,
} from '@/utils/productDealMethod'
import {
productCashValidationMessage,
productMaxOrderCash,
productMinOrderCash
} from '@/utils/productOrderLimit'
const typeDeal = computed(() => getProductDealMethodOptions(props?.ProductItem?.group_type))
@@ -377,14 +386,25 @@ const sellPagination = ref<TableEngineInput>({
const finalPrice = computed(() => (form.value?.goldValue * (isBuy.value ? props.ProductItem?.price ?? 0 : props.ProductItem?.sellPrice ?? 0)))
const payablePrice = computed(() => finalPrice.value)
const minOrderCash = computed(() => productMinOrderCash(props.ProductItem, isBuy.value))
const maxOrderCash = computed(() => productMaxOrderCash(props.ProductItem))
const cashValidationMessage = computed(() =>
productCashValidationMessage(props.ProductItem, form.value?.goldCash, isBuy.value, usePriceWithoutType)
)
const disableTransaction = computed(() =>
loading.value ||
form.value?.goldValue === undefined ||
form.value?.goldValue === '' ||
form.value?.goldCash === '' ||
form.value?.goldCash === undefined ||
(isBuy.value ? (form.value?.goldCash ?? 0) < 500000 : (form.value?.goldValue ?? 0) < 0.001) ||
// (!isBuy.value && form.value.goldValue > walletStore?.walletInfo?.gold) ||
(isBuy.value
? (form.value?.goldCash ?? 0) < minOrderCash.value
: (productMinOrderCash(props.ProductItem, false) > 0 || productMaxOrderCash(props.ProductItem) != null
? ((form.value?.goldCash ?? 0) < minOrderCash.value || (maxOrderCash.value != null && (form.value?.goldCash ?? 0) > maxOrderCash.value))
: (form.value?.goldValue ?? 0) < 0.001)) ||
(maxOrderCash.value != null && (form.value?.goldCash ?? 0) > maxOrderCash.value) ||
cashValidationMessage.value !== '' ||
!lastPrice.value ||
(isBuy.value ? getTradeBuyPrice(lastPrice.value) <= 0 : getTradeSellPrice(lastPrice.value) <= 0))