2026-10-21 03:39:00 -04:00
|
|
|
|
<template>
|
|
|
|
|
|
<div :class="desktop ? 'dgift' : ''">
|
|
|
|
|
|
<div :class="desktop ? 'dgift__container' : ''">
|
|
|
|
|
|
<header v-if="desktop" class="dgift-topbar">
|
|
|
|
|
|
<button type="button" class="dgift-topbar__back" @click="router.back()">
|
|
|
|
|
|
<BasicIcon icon="vuesax-linear:arrow-right-1" size="18" />
|
|
|
|
|
|
<span>بازگشت</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<div class="dgift-topbar__meta">
|
|
|
|
|
|
<p class="dgift-topbar__eyebrow">خرید</p>
|
|
|
|
|
|
<h1 class="dgift-topbar__title">خرید اقساطی مس</h1>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
<MobilePageHeader v-else title="خرید اقساطی مس" show-back />
|
|
|
|
|
|
|
|
|
|
|
|
<a-spin :spinning="loading">
|
|
|
|
|
|
<div :class="desktop ? 'dgift-layout' : 'px-5 mpage-content pb-6 flex flex-col-reverse'">
|
|
|
|
|
|
<section :class="desktop ? 'dgift-surface dgift-form' : 'border-gray-200 border-1 rounded-xl p-4'">
|
|
|
|
|
|
<div v-if="desktop" class="dgift-form__header">
|
|
|
|
|
|
<div class="dgift-form__icon">
|
|
|
|
|
|
<BasicIcon icon="vuesax-linear:calendar" size="28" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h2 class="dgift-form__title">خرید مس قسطی</h2>
|
|
|
|
|
|
<p class="dgift-form__subtitle">طرح را انتخاب کنید و مبلغ خرید را به تومان وارد کنید.</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<template v-else>
|
|
|
|
|
|
<div class="font-bold mb-1">خرید مس قسطی</div>
|
|
|
|
|
|
<p class="text-xs text-gray-500 mb-3">طرح را انتخاب کنید و مبلغ خرید را به تومان وارد کنید.</p>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2 mb-3">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="plan"
|
|
|
|
|
|
:class="{ 'plan--on': plan === 4 }"
|
|
|
|
|
|
@click="plan = 4"
|
|
|
|
|
|
>
|
|
|
|
|
|
<b>اعتبار ۴ قسط</b>
|
|
|
|
|
|
<span>تا {{ money(status?.config.plan4_cap_toman) }} تومان</span>
|
|
|
|
|
|
<span v-if="active">مانده {{ money(status?.plan4_remaining_toman) }} تومان</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="plan"
|
|
|
|
|
|
:class="{ 'plan--on': plan === 12 }"
|
|
|
|
|
|
@click="plan = 12"
|
|
|
|
|
|
>
|
|
|
|
|
|
<b>وام ۱۲ قسط</b>
|
|
|
|
|
|
<span>تا {{ money(status?.config.plan12_cap_toman) }} تومان · یک چک</span>
|
|
|
|
|
|
<span v-if="active">مانده {{ money(status?.plan12_remaining_toman) }} تومان</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<p :class="desktop ? 'dgift-form__hint' : 'text-xs text-gray-500 mb-2'">
|
2026-11-07 12:24:36 +03:30
|
|
|
|
خرید اقساطی با {{ feeShop }}٪ افزایش ({{ feeGateway }}٪ دیجیپی + {{ feeExtra }}٪) محاسبه میشود.
|
2026-10-21 03:39:00 -04:00
|
|
|
|
</p>
|
|
|
|
|
|
<BasicInput
|
|
|
|
|
|
v-model:value="amountText"
|
|
|
|
|
|
place-holder="مبلغ مورد نظر (تومان)"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
type="tel"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<p :class="desktop ? 'dgift-form__hint' : 'text-xs text-gray-500 mt-2'">
|
|
|
|
|
|
{{ gramsPreview || 'بعد از وارد کردن مبلغ، مقدار مس همینجا دیده میشود.' }}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<BasicButton
|
|
|
|
|
|
:class="desktop ? 'dgift-form__submit' : 'w-full py-2 mt-3'"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
:disabled="buying"
|
|
|
|
|
|
@click="buy"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-spin v-if="buying" size="small" />
|
|
|
|
|
|
<span v-else>خرید</span>
|
|
|
|
|
|
</BasicButton>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<aside :class="desktop ? 'dgift-surface dgift-guide' : 'border-gray-200 border-1 rounded-xl p-4 mb-3'">
|
|
|
|
|
|
<h3 :class="desktop ? 'dgift-guide__title' : 'font-bold mb-2'">خرید قسطی با دیجیپی</h3>
|
|
|
|
|
|
<p :class="desktop ? 'dgift-form__hint' : 'text-xs text-gray-500 mb-2'">
|
|
|
|
|
|
احراز هویت در دیجیپی انجام میشود. بعد از تأیید، اعتبار روی همین صفحه مینشیند.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<ol :class="desktop ? 'dgift-guide__steps' : 'installment-steps'">
|
|
|
|
|
|
<li>خرید آنی مس بدون پرداخت نقدی</li>
|
|
|
|
|
|
<li>بدون پیشپرداخت و کاملاً آنلاین</li>
|
|
|
|
|
|
<li>امکان نقد کردن مس خریداریشده</li>
|
|
|
|
|
|
</ol>
|
|
|
|
|
|
<div :class="desktop ? 'dgift-guide__note' : 'text-xs text-gray-500 mt-2'">
|
|
|
|
|
|
<p v-if="status?.status === 'pending'">احراز را تمام کنید. مانده بعد از ثبت پشتیبانی اینجا میآید.</p>
|
|
|
|
|
|
<p v-else-if="active">اعتبار شما فعال است. طرح را انتخاب کنید و خرید را بزنید.</p>
|
|
|
|
|
|
<p v-else>برای شروع، احراز دیجیپی را باز کنید.</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<BasicButton
|
|
|
|
|
|
v-if="!active"
|
|
|
|
|
|
:class="desktop ? 'dgift-form__submit' : 'w-full py-2 mt-3'"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
:disabled="opening"
|
|
|
|
|
|
@click="goDigipay"
|
|
|
|
|
|
>
|
|
|
|
|
|
رفتن به دیجیپی
|
|
|
|
|
|
</BasicButton>
|
|
|
|
|
|
</aside>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-spin>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { computed, onMounted, ref } from 'vue'
|
|
|
|
|
|
import { message } from 'ant-design-vue'
|
|
|
|
|
|
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
|
|
|
|
|
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
|
|
|
|
|
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
|
|
|
|
|
import MobilePageHeader from '@/layouts/components/MobilePageHeader.vue'
|
|
|
|
|
|
import router from '@/router'
|
|
|
|
|
|
import { useSettingsStore } from '@/store/settingsStore'
|
|
|
|
|
|
import {
|
|
|
|
|
|
buyDigipayInstallment,
|
|
|
|
|
|
fetchDigipayInstallment,
|
|
|
|
|
|
startDigipayInstallment,
|
|
|
|
|
|
type DigipayInstallmentStatus
|
|
|
|
|
|
} from '@/api/digipayInstallment'
|
|
|
|
|
|
|
|
|
|
|
|
defineProps<{ desktop?: boolean }>()
|
|
|
|
|
|
|
|
|
|
|
|
const settings = useSettingsStore()
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const opening = ref(false)
|
|
|
|
|
|
const buying = ref(false)
|
|
|
|
|
|
const status = ref<DigipayInstallmentStatus | null>(null)
|
|
|
|
|
|
const plan = ref<4 | 12>(4)
|
|
|
|
|
|
const amountText = ref('')
|
|
|
|
|
|
|
|
|
|
|
|
const active = computed(() => status.value?.status === 'active')
|
|
|
|
|
|
const feeShop = computed(() => status.value?.config.fee_shop_percent ?? 8)
|
|
|
|
|
|
const feeGateway = computed(() => status.value?.config.fee_gateway_percent ?? 5.7)
|
|
|
|
|
|
const feeExtra = computed(() => status.value?.config.fee_extra_percent ?? 2.3)
|
|
|
|
|
|
const amountToman = computed(() => Number(String(amountText.value).replace(/[^\d]/g, '')) || 0)
|
|
|
|
|
|
|
|
|
|
|
|
const gramsPreview = computed(() => {
|
|
|
|
|
|
const price = status.value?.gram_price_rial || 0
|
|
|
|
|
|
if (!price || amountToman.value < 1000) return ''
|
|
|
|
|
|
const grams = (amountToman.value * 10) / price
|
|
|
|
|
|
return `حدود ${grams.toLocaleString('fa-IR', { maximumFractionDigits: 3 })} ${settings.tradeWeightUnit} به کیف مینشیند.`
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
function money(value?: number) {
|
|
|
|
|
|
return Number(value || 0).toLocaleString('fa-IR')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await fetchDigipayInstallment()
|
|
|
|
|
|
status.value = (res as any)?.data ?? res
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function goDigipay() {
|
|
|
|
|
|
opening.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await startDigipayInstallment()
|
|
|
|
|
|
status.value = (res as any)?.data ?? res
|
|
|
|
|
|
const url = status.value?.config.onboarding_url
|
|
|
|
|
|
if (!url) {
|
|
|
|
|
|
message.error('لینک دیجیپی هنوز تنظیم نشده')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
window.open(url, '_blank', 'noopener')
|
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
|
message.error(e?.response?.data?.message || 'شروع احراز انجام نشد')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
opening.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function buy() {
|
|
|
|
|
|
if (!active.value) {
|
|
|
|
|
|
message.warning('اول احراز دیجیپی را تمام کنید تا اعتبارتان ثبت شود')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
buying.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await buyDigipayInstallment(plan.value, amountToman.value)
|
|
|
|
|
|
const data = (res as any)?.data ?? res
|
|
|
|
|
|
message.success(`خرید ثبت شد. ${data.grams} به کیف اضافه شد`)
|
|
|
|
|
|
amountText.value = ''
|
|
|
|
|
|
await load()
|
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
|
message.error(e?.response?.data?.message || 'خرید انجام نشد')
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
buying.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(load)
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.plan {
|
|
|
|
|
|
text-align: right;
|
|
|
|
|
|
border: 1px solid rgba(15, 23, 42, 0.08);
|
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 4px;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: #4b5563;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
.plan b {
|
|
|
|
|
|
color: #111827;
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.plan--on {
|
|
|
|
|
|
border-color: var(--app-primary-color, #093d51);
|
|
|
|
|
|
box-shadow: inset 0 0 0 1px var(--app-primary-color, #093d51);
|
|
|
|
|
|
}
|
|
|
|
|
|
.installment-steps {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding: 0 18px 0 0;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 6px;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: #4b5563;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|