widthdraw and deposit

This commit is contained in:
2026-06-09 21:04:22 +03:30
parent 95516ee2d8
commit 689c51c27d
26 changed files with 1228 additions and 522 deletions
+37 -29
View File
@@ -6,11 +6,11 @@
<div class="flex justify-evenly w-full px-2 h-11 items-center bg-gray-50 relative rounded ">
<div :class="isBuy?'text-tertiary':'text-gray-400'" class="w-full text-center z-2"
@click.stop="setIsBuy(true) ">
خرید {{ meltedGoldLabel }} {{ props?.ProductItem?.title }}
خرید {{ tradeProductLabel }}
</div>
<div :class="!isBuy?'text-tertiary':'text-gray-400'" class="w-full text-center z-2"
@click.stop="setIsBuy(false) ">
فروش {{ meltedGoldLabel }} {{ props?.ProductItem?.title }}
فروش {{ tradeProductLabel }}
</div>
<!-- <div ref="bganim" class="absolute bg-white h-8 w-1/2 rounded-lg " :style="`transform: translateX(${isbuy? '0':'-100%'}); left: ${isbuy? '0':'100%'}`"></div>-->
<div ref="bganim" :style="useStyle()"
@@ -53,9 +53,9 @@
type="price" @onchange="calculateGold" />
</a-form-item>
<a-form-item :rules="[justNumber()]">
<BasicInput v-model:value="form.goldValue" addon-before="گرم" :addon-bg-color="useConfigStore().config.color"
<BasicInput v-model:value="form.goldValue" :addon-before="weightUnit" :addon-bg-color="useConfigStore().config.color"
addon-text-color="white"
place-holder="مقدار طلا"
:place-holder="amountFieldLabel"
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">
@@ -133,7 +133,7 @@
<div class="flex gap-2 items-center">
<div class="">{{ feeInGrams }}</div>
<div>
گرم
{{ weightUnit }}
</div>
</div>
</div>
@@ -157,13 +157,13 @@
<div>وزن:</div>
<div class="flex items-center">
<div class="font-bold">{{ form.goldValue }}</div>
<div class="text-xs mr-1">گرم</div>
<div class="text-xs mr-1">{{ weightUnit }}</div>
</div>
</div>
<div class="flex justify-between mt-3">
<div>مظنه:</div>
<div class="flex items-center">
<div class="font-bold">{{ usePriceWithoutType(isBuy ? getTradeBuyPrice(lastPrice) : getTradeSellPrice(lastPrice)) }}</div>
<div class="font-bold">{{ usePriceWithoutType(Math.round(goldPriceValue)) }}</div>
<div class="text-xs mr-1">ریال</div>
</div>
</div>
@@ -171,7 +171,7 @@
<div>کارمزد:</div>
<div class="flex items-center gap-2">
<div class="font-bold text-xl">{{ feeInGrams }}</div>
<div class="text-xs mr-1">گرم</div>
<div class="text-xs mr-1">{{ weightUnit }}</div>
</div>
</div>
<div >(معادل {{ equivalentPrice }} ریال)</div>
@@ -236,7 +236,8 @@ import type { Product } from '@/models/products'
import { useFundUserStore } from '@/store/fundStore'
import {useConfigStore} from "@/store/configStore";
import { calcFeeInGrams, loadServiceFeeFromSettings } from '@/utils/serviceFee'
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
import { formatCashWalletBalanceText, formatGoldWalletBalanceText, getWeightUnit } from '@/utils/productDealMethod'
import { isMeltedTradeGroup } from '@/utils/productCategories'
import { useSettingsStore } from '@/store/settingsStore'
import { storeToRefs } from 'pinia'
import {
@@ -250,6 +251,7 @@ const walletStore = useWalletStore()
const userStore = useUserStore()
const settingsStore = useSettingsStore()
const { meltedGoldLabel } = storeToRefs(settingsStore)
const weightUnit = computed(() => getWeightUnit())
const fundStore = useFundUserStore()
const confirmAction = ref<boolean>(false)
const noCompleteVisible = ref<boolean>(false)
@@ -267,6 +269,12 @@ interface Prop {
const props = withDefaults(defineProps<Prop>(), {})
const isBuy = ref<boolean>(true)
const tradeProductLabel = computed(() => {
const title = props.ProductItem?.title?.trim()
return title || meltedGoldLabel.value
})
const amountFieldLabel = computed(() => `مقدار ${tradeProductLabel.value}`)
const buyPagination = ref<TableEngineInput>({
filters: [{
field: 'type',
@@ -288,8 +296,8 @@ const sellPagination = ref<TableEngineInput>({
const unitPrice = computed(() => {
const product = props.ProductItem
if (product?.group_type === 'آبشده') {
return isBuy.value ? getProductBuyPrice(product) : getProductSellPrice(product)
if (isMeltedTradeGroup(product?.group_type)) {
return isBuy.value ? getProductBuyPrice(product!) : getProductSellPrice(product!)
}
return isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value)
})
@@ -307,6 +315,11 @@ const cashValidationMessage = computed(() =>
productCashValidationMessage(props.ProductItem, form.value?.goldCash, isBuy.value, usePriceWithoutType)
)
const priceUnavailable = computed(() => {
const unit = unitPrice.value
return !unit || Number.isNaN(unit) || unit <= 0
})
const disableTransaction = computed(() =>
loading.value ||
form.value?.goldValue === undefined ||
@@ -321,8 +334,7 @@ const disableTransaction = computed(() =>
(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))
priceUnavailable.value)
function refreshTable() {
sellItems.value = []
@@ -498,7 +510,8 @@ const limitedPrice = computed(() => {
})
function syncFormWithLatestPrice() {
if (!lastPrice.value) return
const unit = unitPrice.value
if (!unit || Number.isNaN(unit)) return
const goldValue = form.value.goldValue
if (goldValue !== undefined && goldValue !== null && goldValue !== '' && !isNaN(Number(goldValue))) {
@@ -513,7 +526,7 @@ function syncFormWithLatestPrice() {
}
watch(
() => [getTradeBuyPrice(lastPrice.value), getTradeSellPrice(lastPrice.value), isBuy.value],
() => [unitPrice.value, isBuy.value, props.ProductItem?.id],
() => {
syncFormWithLatestPrice()
}
@@ -521,20 +534,20 @@ watch(
function calculateCash(val: number) {
priceErrorVisible.value = false
if (!lastPrice.value) return
const unit = unitPrice.value
if (!unit || Number.isNaN(unit)) return
const unit = isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value)
form.value.goldCash = val ? parseFloat((val * unit).toFixed(0)) : undefined
}
function calculateGold(val: number) {
if (!lastPrice.value) return
const unit = unitPrice.value
if (!unit || Number.isNaN(unit)) return
const unit = isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value)
if (isBuy.value) {
if (val) {
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / unit)))
priceErrorVisible.value = parseInt(finalPrice.value) > 0
priceErrorVisible.value = parseInt(String(finalPrice.value)) > 0
} else if (val.toString() === '') {
form.value.goldValue = undefined
priceErrorVisible.value = false
@@ -544,7 +557,7 @@ function calculateGold(val: number) {
}
} else if (val) {
form.value.goldValue = toFixedDownThreeChar(parseFloat(String(val / unit)))
priceErrorVisible.value = parseInt(finalPrice.value) > 0
priceErrorVisible.value = parseInt(String(finalPrice.value)) > 0
} else if (val.toString() === '') {
form.value.goldValue = undefined
priceErrorVisible.value = false
@@ -590,12 +603,7 @@ const formatter = (value: number) => {
const price = computed((): Price => <Price>lastPrice.value ?? 0)
const goldPriceValue = computed(() => {
if (!lastPrice.value?.price) return 0
return isBuy.value
? getTradeBuyPrice(lastPrice.value)
: getTradeSellPrice(lastPrice.value)
})
const goldPriceValue = computed(() => unitPrice.value)
async function initPrice() {
try {
@@ -625,10 +633,11 @@ async function ok() {
infoVisible.value = true
await createOrder({
direction: isBuy.value ? 1 : 2,
price: isBuy.value ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value),
price: Math.round(unitPrice.value),
amount: form.value.goldValue ?? 0,
abshode_id: props.ProductItem?.id,
})
confirmAction.value = false
await walletStore.getMyWallet()
await router.push({ name: 'transactions' })
form.value = {
@@ -636,7 +645,6 @@ async function ok() {
goldCash: undefined,
percentWallet: undefined
}
// refreshTable()
message.success('سفارش شما با موفقیت انجام شد')
await fundStore.getMyFund()
} catch (e) {