306 lines
12 KiB
Vue
306 lines
12 KiB
Vue
<template>
|
||
<div class="dhome">
|
||
<div class="dhome__container">
|
||
<DesktopHomeTopbar @logout="$emit('logout')" />
|
||
|
||
<HomeSkeleton v-if="loading && !userStore.userInfo" />
|
||
|
||
<template v-else-if="userStore.userInfo">
|
||
<section class="dhome-hero-row">
|
||
<div class="dhome-surface dhome-hero-price">
|
||
<span class="dhome-label">قیمت خرید از کشکول گلد</span>
|
||
<div class="dhome-hero-price__value-row">
|
||
<span
|
||
v-if="percentPriceChanged() !== 0"
|
||
class="dhome-hero-price__delta"
|
||
:class="percentPriceChanged() >= 0 ? 'dhome-hero-price__delta--up' : 'dhome-hero-price__delta--down'"
|
||
>
|
||
<BasicIcon
|
||
:icon="percentPriceChanged() >= 0 ? 'vuesax-linear:arrow-up-2' : 'vuesax-linear:arrow-down-2'"
|
||
size="14"
|
||
/>
|
||
<span class="dhome-hero-price__delta-value">{{ useTowDecimal(percentPriceChanged()) }}%</span>
|
||
</span>
|
||
<Vue3Odometer
|
||
:value="goldVal ?? 0"
|
||
class="dhome-hero-price__odometer o-text"
|
||
/>
|
||
<span class="dhome-hero-price__unit">ریال</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="dhome-surface dhome-price-range">
|
||
<article class="dhome-price-range__item">
|
||
<span class="dhome-price-range__label">بیشترین امروز</span>
|
||
<p class="dhome-price-range__value dhome-price-range__value--high">
|
||
{{ usePriceWithoutType(price?.buy ?? 0) }} ریال
|
||
</p>
|
||
</article>
|
||
<article class="dhome-price-range__item">
|
||
<span class="dhome-price-range__label">کمترین امروز</span>
|
||
<p class="dhome-price-range__value dhome-price-range__value--low">
|
||
{{ usePriceWithoutType(price?.sell ?? 0) }} ریال
|
||
</p>
|
||
</article>
|
||
</div>
|
||
</section>
|
||
|
||
<div class="dhome-default-grid">
|
||
<div class="dhome-default-grid__main">
|
||
<section class="dhome-surface">
|
||
<header class="dhome-section__header">
|
||
<h2 class="dhome-section__title">عملیات</h2>
|
||
</header>
|
||
<div class="dhome-default-actions">
|
||
<button
|
||
v-for="action in mainActions"
|
||
:key="action.name"
|
||
type="button"
|
||
class="dhome-default-action"
|
||
@click="action.handler()"
|
||
>
|
||
<span class="dhome-default-action__icon">
|
||
<BasicIcon :icon="action.icon" size="20" />
|
||
</span>
|
||
<span class="dhome-default-action__label">{{ action.label }}</span>
|
||
</button>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="dhome-surface dhome-chart-banner-combined">
|
||
<div class="dhome-chart-banner-combined__grid">
|
||
<div class="dhome-chart-panel">
|
||
<header class="dhome-section__header dhome-chart-panel__header">
|
||
<h2 class="dhome-section__title">نمودار قیمت</h2>
|
||
</header>
|
||
<div class="dhome-chart-panel__tabs">
|
||
<button
|
||
type="button"
|
||
class="dhome-chart-panel__tab"
|
||
:class="{ 'dhome-chart-panel__tab--active': selection === 'DAILY' }"
|
||
@click="updateData('DAILY')"
|
||
>
|
||
24 ساعت اخیر
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="dhome-chart-panel__tab"
|
||
:class="{ 'dhome-chart-panel__tab--active': selection === 'WEEKLY' }"
|
||
@click="updateData('WEEKLY')"
|
||
>
|
||
هفته گذشته
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="dhome-chart-panel__tab"
|
||
:class="{ 'dhome-chart-panel__tab--active': selection === 'MONTHLY' }"
|
||
@click="updateData('MONTHLY')"
|
||
>
|
||
ماه گذشته
|
||
</button>
|
||
</div>
|
||
<apexchart
|
||
type="area"
|
||
height="280"
|
||
:options="priceChartOptions"
|
||
:series="priceChartSeries"
|
||
/>
|
||
</div>
|
||
<div class="dhome-banner-panel">
|
||
<img :src="bannerImg" alt="" class="dhome-banner-panel__img" />
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<aside class="dhome-default-grid__side">
|
||
<section class="dhome-surface dhome-assets-card">
|
||
<h3 class="dhome-assets-card__title">داراییها</h3>
|
||
<div class="dhome-assets-card__rows">
|
||
<div class="dhome-assets-card__row">
|
||
<span>دارایی طلایی</span>
|
||
<strong>{{ balanceLabel }}</strong>
|
||
</div>
|
||
<div class="dhome-assets-card__row">
|
||
<span>دارایی ریالی</span>
|
||
<strong class="number-ltr">{{ usePriceWithoutType(totalRialDisplay) }} ریال</strong>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section v-if="userStore.userInfo?.referral_id" class="dhome-surface dhome-referral">
|
||
<h3 class="dhome-referral__title">دعوت از دوستان</h3>
|
||
<p class="dhome-referral__code">{{ userStore.userInfo.referral_id }}</p>
|
||
<div class="dhome-referral__actions">
|
||
<button type="button" class="dhome-referral__btn" @click="shareReferral">
|
||
<BasicIcon icon="vuesax-linear:share" size="16" />
|
||
<span>دعوت</span>
|
||
</button>
|
||
<button type="button" class="dhome-referral__btn" @click="copyReferralCode">
|
||
<BasicIcon icon="vuesax-linear:copy" size="16" />
|
||
<span>رونوشت</span>
|
||
</button>
|
||
</div>
|
||
</section>
|
||
</aside>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import Vue3Odometer from 'vue3-odometer'
|
||
import 'odometer/themes/odometer-theme-default.css'
|
||
import router from '@/router'
|
||
import { getAllPrices } from '@/api/home'
|
||
import { loading } from '@/utils'
|
||
import { useUserStore } from '@/store/userStore'
|
||
import { useWalletStore } from '@/store/walletStore'
|
||
import { useSettingsStore } from '@/store/settingsStore'
|
||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||
import { resolveAssetsRialValue } from '@/utils/productAssets'
|
||
import { usePrice, usePriceWithoutType, useTowDecimal, formatGoldAmount } from '@/utils/usePrice'
|
||
import {
|
||
getLastPrices,
|
||
getTradeBuyPrice,
|
||
getUpPrice,
|
||
percentPriceChanged,
|
||
price,
|
||
setIntervalGetAllPrice,
|
||
} from '@/utils/price'
|
||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||
import DesktopHomeTopbar from '@/views/base/home/components/DesktopHomeTopbar.vue'
|
||
import HomeSkeleton from '@/views/base/home/components/HomeSkeleton.vue'
|
||
import bannerImg from '@/assets/img/banner/2.png'
|
||
import { message } from 'ant-design-vue'
|
||
|
||
const emit = defineEmits<{ logout: []; openBalance: [] }>()
|
||
const userStore = useUserStore()
|
||
const walletStore = useWalletStore()
|
||
const settingsStore = useSettingsStore()
|
||
const { assetsSummary, loadWalletAssets } = useWalletAssets()
|
||
|
||
const goldVal = ref<number | undefined>()
|
||
const selection = ref<'DAILY' | 'WEEKLY' | 'MONTHLY'>('DAILY')
|
||
const priceChartSeries = ref([{ name: 'قیمت', data: [] as [number, number][] }])
|
||
const priceChartOptions = ref({
|
||
chart: { toolbar: { show: false }, zoom: { autoScaleYaxis: true } },
|
||
stroke: { width: 2 },
|
||
dataLabels: { enabled: false },
|
||
yaxis: { show: false },
|
||
xaxis: { type: 'datetime', labels: { show: false }, axisBorder: { show: false } },
|
||
colors: ['#a72b77'],
|
||
fill: {
|
||
type: 'gradient',
|
||
gradient: { shadeIntensity: 1, opacityFrom: 0.7, opacityTo: 0.9, stops: [0, 100] },
|
||
},
|
||
tooltip: { x: { format: 'dd/MM/yy HH:mm' } },
|
||
})
|
||
|
||
const countBasedInventory = computed(() =>
|
||
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
|
||
)
|
||
|
||
const primaryMetalTotal = computed(() => assetsSummary.value?.metal_totals?.[0])
|
||
|
||
const balanceLabel = computed(() => {
|
||
const meta = assetsSummary.value?.meta
|
||
if (meta?.has_count_based_products && countBasedInventory.value > 0) {
|
||
return `${countBasedInventory.value} عدد`
|
||
}
|
||
const metal = primaryMetalTotal.value
|
||
if (metal && Number(metal.total_weight) > 0) {
|
||
return `${formatGoldAmount(metal.total_weight)} ${metal.unit}`
|
||
}
|
||
const fallback = walletStore.walletInfo?.gold_sum ?? userStore.userInfo?.wallet?.count_gold ?? 0
|
||
return `${formatGoldAmount(fallback)} گرم`
|
||
})
|
||
|
||
const totalRialDisplay = computed(() =>
|
||
resolveAssetsRialValue(assetsSummary.value, getTradeBuyPrice(price.value) || Number(goldVal.value ?? 0))
|
||
)
|
||
|
||
const mainActions = computed(() => {
|
||
const actions = [
|
||
{ name: 'buySell', icon: 'vuesax-linear:money-receive', label: 'خرید و فروش', handler: () => router.push({ name: 'gold' }) },
|
||
{ name: 'deposit', icon: 'vuesax-linear:card-add', label: 'واریز نقدی', handler: () => router.push({ name: 'wallet', query: { state: 'deposit' } }) },
|
||
{ name: 'balance', icon: 'vuesax-linear:receipt-item', label: 'موجودی', handler: () => emitBalance() },
|
||
{ name: 'fund', icon: 'vuesax-linear:archive-1', label: 'دارایی ها', handler: () => router.push({ name: 'fund' }) },
|
||
]
|
||
if (settingsStore.isSettingTruthy('enable_product_funds')) {
|
||
actions.push({
|
||
name: 'piggy',
|
||
icon: 'vuesax-linear:safe-home',
|
||
label: 'قلک',
|
||
handler: () => router.push({ name: 'piggy' }),
|
||
})
|
||
}
|
||
actions.push({
|
||
name: 'earn',
|
||
icon: 'vuesax-linear:dollar-circle',
|
||
label: 'کسب درآمد',
|
||
handler: () => router.push({ name: 'earnMoney' }),
|
||
})
|
||
return actions
|
||
})
|
||
|
||
function emitBalance() {
|
||
emit('openBalance')
|
||
}
|
||
|
||
async function fetchPrices() {
|
||
try {
|
||
const response = await getAllPrices()
|
||
const data = response?.data?.prices ?? {}
|
||
const selectedData = data[selection.value] ?? []
|
||
priceChartSeries.value[0].data = selectedData.map((item: { timestamp: number; value: number }) => [
|
||
item.timestamp,
|
||
item.value - 1,
|
||
])
|
||
} catch (error) {
|
||
console.error(error)
|
||
}
|
||
}
|
||
|
||
function updateData(timeline: 'DAILY' | 'WEEKLY' | 'MONTHLY') {
|
||
selection.value = timeline
|
||
void fetchPrices()
|
||
}
|
||
|
||
function copyReferralCode() {
|
||
const code = userStore.userInfo?.referral_id
|
||
if (code) {
|
||
navigator.clipboard.writeText(code)
|
||
message.info('کد رونوشت شد')
|
||
}
|
||
}
|
||
|
||
function shareReferral() {
|
||
const text = `⭐️الان طلا بخر؛ آخر ماه سودشو ببر!
|
||
این دعوت نامه از طرف "${userStore.userInfo?.name}" برای شما ارسال شده.
|
||
kh.kashkolgold.ir/login?id=${userStore.userInfo?.referral_id}`
|
||
navigator.share({ title: 'کشکول گلد', text })
|
||
}
|
||
|
||
onMounted(async () => {
|
||
try {
|
||
loading.value = true
|
||
await Promise.all([
|
||
getLastPrices(),
|
||
getUpPrice(),
|
||
setIntervalGetAllPrice(),
|
||
fetchPrices(),
|
||
loadWalletAssets(true),
|
||
userStore.userInfo ? Promise.resolve() : userStore.getMyInfo(),
|
||
])
|
||
goldVal.value = price.value?.price_last
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
})
|
||
</script>
|
||
|
||
<style lang="less" src="./styles/desktop-home.less"></style>
|