|
|
|
@@ -44,7 +44,7 @@
|
|
|
|
|
حداقل مبلغ اولیه برای ثبت سفارش {{ usePriceWithoutType(limitedPrice.value as number ?? 0) }} ریال می باشد.
|
|
|
|
|
</div>
|
|
|
|
|
<!-- </a-spin>-->
|
|
|
|
|
<a-form ref="refInput" :model="form" class="!mt-5" name="basic" @finish="okConfirm()">
|
|
|
|
|
<a-form ref="refInput" :model="form" class="!mt-5" name="basic" @finish="okConfirm()" @finishFailed="(errorInfo) => { console.log('Form submit failed:', errorInfo); console.log('Error fields details:', JSON.stringify(errorInfo.errorFields, null, 2)); if (errorInfo.errorFields && errorInfo.errorFields.length > 0) { const firstError = errorInfo.errorFields[0]; console.log('First error field:', firstError.name, 'errors:', firstError.errors); message.error(firstError.errors?.[0] || 'لطفا تمام فیلدها را به درستی پر کنید') } }">
|
|
|
|
|
<div class="border-gray-200 border-1 rounded-xl p-5 relative">
|
|
|
|
|
<bg_main />
|
|
|
|
|
<div class="z-100 relative">
|
|
|
|
@@ -60,7 +60,7 @@
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
|
|
|
|
<a-form-item v-if="isBuy" name="goldValue"
|
|
|
|
|
:rules="[justNumber2(props?.ProductItem?.price , form.method , props?.ProductItem?.amount, true)]">
|
|
|
|
|
:rules="[justNumber2(props?.ProductItem?.price , form.method , props?.ProductItem?.amount, true, form.gateway)]">
|
|
|
|
|
<BasicInput v-model:value="form.goldValue" addon-before="تعداد" addon-bg-color="#521620"
|
|
|
|
|
addon-text-color="white"
|
|
|
|
|
place-holder="تعداد"
|
|
|
|
@@ -104,6 +104,16 @@
|
|
|
|
|
</Transition>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<a-form-item-rest v-if="isBuy && form.method === 'cash'">
|
|
|
|
|
<div class="mt-4 w-full px-6 rounded-xl py-1 border-1 bg-white">
|
|
|
|
|
<div class="flex justify-between items-center">
|
|
|
|
|
<div>استفاده از درگاه:</div>
|
|
|
|
|
<div class="flex gap-2 items-center">
|
|
|
|
|
<a-switch v-model:checked="form.gateway" size="small" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</a-form-item-rest>
|
|
|
|
|
<GoldLoading v-model:show="infoVisible" title="" />
|
|
|
|
|
<a-form-item>
|
|
|
|
|
<BasicButton
|
|
|
|
@@ -112,6 +122,7 @@
|
|
|
|
|
class=" w-full py-2 mt-5"
|
|
|
|
|
html-type="submit"
|
|
|
|
|
type="primary"
|
|
|
|
|
@click="() => console.log('Button clicked, disabled:', disableTransaction, 'walletStore:', !!walletStore)"
|
|
|
|
|
>
|
|
|
|
|
<div>
|
|
|
|
|
<a-spin v-if="loading" size="small" />
|
|
|
|
@@ -221,25 +232,24 @@
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
<BasicButton class="mb-20 mt-5 w-full" type="primary" @click="ok(); confirmAction= false">ثبت نهایی</BasicButton>
|
|
|
|
|
<BasicButton class="mb-20 mt-5 w-full" type="primary" @click="() => { ok(); confirmAction = false }">ثبت نهایی</BasicButton>
|
|
|
|
|
</BasicActionSheet>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
|
|
|
|
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
|
|
|
import { computed, onMounted, ref, watch } from 'vue'
|
|
|
|
|
import img1 from '@/assets/img/home_ly2.svg'
|
|
|
|
|
import {useFormat, usePrice, usePriceWithoutType, useTowDecimal} from '@/utils/usePrice'
|
|
|
|
|
import {useFormat, usePrice, usePriceWithoutType} from '@/utils/usePrice'
|
|
|
|
|
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
|
|
|
|
import type { Gold } from '@/models/gold'
|
|
|
|
|
import { loading, loadingMore, toFixedDownThreeChar } from '@/utils'
|
|
|
|
|
import { loading, loadingMore } from '@/utils'
|
|
|
|
|
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
|
|
|
|
import router from '@/router'
|
|
|
|
|
import { useWalletStore } from '@/store/walletStore'
|
|
|
|
|
import { createOrder } from '@/api/order'
|
|
|
|
|
import { FormInstance, message } from 'ant-design-vue'
|
|
|
|
|
import type { Price } from '@/models/home'
|
|
|
|
|
// import {getLastPrice} from '@/api/home'
|
|
|
|
|
import Icon from '@/components/BasicPacks/BasicIcon.vue'
|
|
|
|
|
import { useUserStore } from '@/store/userStore'
|
|
|
|
|
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
|
|
|
@@ -250,15 +260,14 @@ import GoldLoading from '@/components/GoldLoading.vue'
|
|
|
|
|
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
|
|
|
|
import type { Transaction } from '@/models/transaction'
|
|
|
|
|
import type { TableEngineInput, TableOutput } from '@/models/table'
|
|
|
|
|
import { useInfiniteScroll } from '@vueuse/core'
|
|
|
|
|
import { getTransactionTable } from '@/api/transaction'
|
|
|
|
|
import { getLastPrices, lastPrice, setIntervalGetAllPrice, stopPriceInterval } from '@/utils/price'
|
|
|
|
|
import { getLastPrices, lastPrice } from '@/utils/price'
|
|
|
|
|
import { Product } from '@/models/products'
|
|
|
|
|
import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
|
|
|
|
|
import { SelectItem } from '@/models/SelectItem'
|
|
|
|
|
import Bg_main from '@/components/bg_main.vue'
|
|
|
|
|
import { useFundUserStore } from '@/store/fundStore'
|
|
|
|
|
// import Bg_main from "@/components/bg_main.vue";
|
|
|
|
|
|
|
|
|
|
const typeDeal: SelectItem[] = [
|
|
|
|
|
{
|
|
|
|
|
value: 'نقدی',
|
|
|
|
@@ -324,15 +333,30 @@ const finalPrice = computed(() => (form.value?.goldValue * (isBuy.value ? props.
|
|
|
|
|
// const payablePrice = computed(() => finalPrice.value + finalPrice.value * 0.007)
|
|
|
|
|
const payablePrice = computed(() => finalPrice.value)
|
|
|
|
|
|
|
|
|
|
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) ||
|
|
|
|
|
price.value?.buy === undefined)
|
|
|
|
|
const disableTransaction = computed(() => {
|
|
|
|
|
// If gateway is enabled, skip wallet balance checks
|
|
|
|
|
if (isBuy.value && form.value?.gateway) {
|
|
|
|
|
return (
|
|
|
|
|
loading.value ||
|
|
|
|
|
form.value?.goldValue === undefined ||
|
|
|
|
|
form.value?.goldValue === '' ||
|
|
|
|
|
form.value?.goldCash === '' ||
|
|
|
|
|
form.value?.goldCash === undefined ||
|
|
|
|
|
price.value?.buy === undefined
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
// Normal validation when gateway is disabled
|
|
|
|
|
return (
|
|
|
|
|
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) ||
|
|
|
|
|
price.value?.buy === undefined
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function refreshTable() {
|
|
|
|
|
sellItems.value = []
|
|
|
|
@@ -442,8 +466,10 @@ const form = ref<Gold>({
|
|
|
|
|
goldValue: undefined,
|
|
|
|
|
percentWallet: undefined,
|
|
|
|
|
method: 'cash',
|
|
|
|
|
goldVazn:undefined
|
|
|
|
|
goldVazn:undefined,
|
|
|
|
|
gateway: false
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const allowedAsciiCodeFloat = [46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]
|
|
|
|
|
// const allowedAsciiCodeInt = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57]
|
|
|
|
|
watch(form.value, () => {
|
|
|
|
@@ -454,8 +480,26 @@ watch(form.value, () => {
|
|
|
|
|
calculateCash(form.value.goldValue)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Re-validate when gateway changes
|
|
|
|
|
watch(() => form.value.gateway, () => {
|
|
|
|
|
if (isBuy.value && form.value.goldValue) {
|
|
|
|
|
// Clear validation errors and re-validate
|
|
|
|
|
refInput.value?.clearValidate('goldValue')
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
refInput.value?.validateFields(['goldValue']).catch(() => {
|
|
|
|
|
// Ignore validation errors, just trigger re-validation
|
|
|
|
|
})
|
|
|
|
|
}, 100)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Reset gateway when method changes to non-cash
|
|
|
|
|
watch(() => form.value.method, (newMethod) => {
|
|
|
|
|
if (newMethod !== 'cash' && form.value.gateway) {
|
|
|
|
|
form.value.gateway = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
@@ -508,7 +552,6 @@ const limitedPrice = computed(() => {
|
|
|
|
|
|
|
|
|
|
function calculateCash(val: number) {
|
|
|
|
|
priceErrorVisible.value = false
|
|
|
|
|
|
|
|
|
|
// console.log(val)
|
|
|
|
|
if (price.value) {
|
|
|
|
|
form.value.goldVazn = parseFloat((val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy)))/lastPrice.value?.buy).toFixed(1)
|
|
|
|
@@ -520,7 +563,6 @@ console.log(val,props?.ProductItem?.price,props?.ProductItem?.cash_fee_buy,lastP
|
|
|
|
|
else {
|
|
|
|
|
form.value.goldCash = 0
|
|
|
|
|
form.value.goldVazn = 0
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
@@ -581,7 +623,6 @@ function useStyle() {
|
|
|
|
|
else return ' right: 98%; transform: translate(100%, 0);'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setIsBuy(val: boolean) {
|
|
|
|
|
isBuy.value = val
|
|
|
|
|
form.value.goldValue = undefined
|
|
|
|
@@ -602,13 +643,7 @@ const formatter = (value: number) => {
|
|
|
|
|
return `${value}%`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const price = computed((): Price => <Price>lastPrice.value ?? 0)
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
// await initPrice()
|
|
|
|
|
// await setIntervalGetPrice()
|
|
|
|
|
// console.log('okkkkkkkkgold')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
async function initPrice() {
|
|
|
|
|
try {
|
|
|
|
@@ -627,36 +662,68 @@ async function initPrice() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// onMounted(() => {
|
|
|
|
|
// initPrice()
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
function okConfirm() {
|
|
|
|
|
confirmAction.value = true
|
|
|
|
|
refInput.value?.validateFields()
|
|
|
|
|
async function okConfirm() {
|
|
|
|
|
try {
|
|
|
|
|
console.log('okConfirm called, form values:', form.value)
|
|
|
|
|
console.log('disableTransaction:', disableTransaction.value)
|
|
|
|
|
await refInput.value?.validateFields()
|
|
|
|
|
console.log('Validation passed, showing confirmation action sheet')
|
|
|
|
|
// If validation passes, show confirmation action sheet
|
|
|
|
|
confirmAction.value = true
|
|
|
|
|
console.log('confirmAction set to:', confirmAction.value)
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// Validation failed, don't show action sheet
|
|
|
|
|
console.error('Validation failed:', error)
|
|
|
|
|
message.error('لطفا تمام فیلدها را به درستی پر کنید')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function ok() {
|
|
|
|
|
console.log('ok() function called')
|
|
|
|
|
try {
|
|
|
|
|
loading.value = true
|
|
|
|
|
infoVisible.value = true
|
|
|
|
|
await createOrder({
|
|
|
|
|
const data = await createOrder({
|
|
|
|
|
direction: isBuy.value ? 1 : 2,
|
|
|
|
|
price: isBuy.value ? price.value?.buy : price.value?.sell,
|
|
|
|
|
amount: form.value.goldValue ?? 0,
|
|
|
|
|
gateway: form.value.gateway,
|
|
|
|
|
product_id: props.ProductItem.id,
|
|
|
|
|
method: form.value.method,
|
|
|
|
|
number: form.value.goldValue ?? 0
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// console.log('Order response:', data) // Debug log
|
|
|
|
|
// Check if response has returnUrl (for gateway payment)
|
|
|
|
|
|
|
|
|
|
let returnUrl = null
|
|
|
|
|
if (Array.isArray(data)) {
|
|
|
|
|
const itemWithReturnUrl = data.find(item => item?.returnUrl)
|
|
|
|
|
returnUrl = itemWithReturnUrl?.returnUrl
|
|
|
|
|
} else if (data?.returnUrl) {
|
|
|
|
|
returnUrl = data.returnUrl
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('Return URL:', returnUrl) // Debug log
|
|
|
|
|
|
|
|
|
|
// If returnUrl exists, redirect to gateway and stop execution
|
|
|
|
|
if (returnUrl) {
|
|
|
|
|
window.location.href = returnUrl
|
|
|
|
|
return // Stop execution here
|
|
|
|
|
}
|
|
|
|
|
// If no gateway, continue with normal flow
|
|
|
|
|
await walletStore.getMyWallet()
|
|
|
|
|
await router.push({ name: 'transactions' })
|
|
|
|
|
form.value = {
|
|
|
|
|
goldValue: undefined,
|
|
|
|
|
goldCash: undefined,
|
|
|
|
|
percentWallet: undefined,
|
|
|
|
|
method: 'cash'
|
|
|
|
|
method: 'cash',
|
|
|
|
|
gateway: false
|
|
|
|
|
}
|
|
|
|
|
// refreshTable()
|
|
|
|
|
await fundStore.getMyFund()
|
|
|
|
|
message.success('سفارش شما با موفقیت انجام شد')
|
|
|
|
|
await fundStore.getMyFund()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// console.log(e)
|
|
|
|
|
// await initPrice()
|
|
|
|
@@ -706,7 +773,6 @@ async function ok() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.animate.right {
|
|
|
|
|
right: 0;
|
|
|
|
|
}
|
|
|
|
|