@@ -1,13 +1,13 @@
< template >
< div class = "bottom-0 fixed top-0" >
< img :src = "img" alt = "" class = "w-inherit" : style = "{ backgroundRepeat: 'repeat' }" / >
< img :src = "img" alt = "" class = "w-inherit" : style = "{ backgroundRepeat: 'repeat' }" / >
< / div >
< a-spin :spinning = "loading" >
< div class = "!h-full overflow-y-scroll" >
< div class = "mx-5 pb-30 pt-5" style = "color: #1b2b07" >
<!-- Product Image -- >
< div class = "bg-gray-100 rounded-lg w-full flex justify-center mb-4" >
< img :src = "getProductImage(product)" class = "max-w-full h-auto" / >
< img :src = "getProductImage(product)" class = "max-w-full h-auto" / >
< / div >
<!-- Product Title -- >
@@ -20,7 +20,7 @@
< div class = "flex-1" >
<!-- Buy Button -- >
< BasicButton
v-if = "product?.show && product?.open_buy"
v-if = "product?.show && product?.open_buy &&(product?.inventory || product?.inventory >0) "
class = "w-full py-3 "
type = "primary"
size = "large"
@@ -34,6 +34,9 @@
< div v-else-if = "!product?.open_buy" class="text-center text-gray-500 py-4" >
خرید این محصول در حال حاضر امکان پذیر نیست
< / div >
< div v-else-if = "!product?.inventory || product?.inventory==0" class="text-center text-gray-500 py-4" >
ناموجود
< / div >
< / div >
@@ -44,30 +47,30 @@
< div v-if = "product?.description" class="mb-6" >
< div class = "text-lg font-semibold mb-2" > توضیحات محصول : < / div >
< div class = "text-base text-gray-700 whitespace-pre-line" > { { product ? . description } } < / div >
<!-- < div class = "text-base text-gray-700 whitespace-pre-line" > شمش طلای نقش برجسته ونوس ۱ گرمی انتخابی ظریف و ارزشمند برای سرمایه گذاری و هدیه است . این شمش از طلای خالص با عیار بالا ساخته شده و نقش برجسته ی الهه ونوس ، نمادی از زیبایی و ظرافت ، جلوه ای هنری و خاص به آن بخشیده است . وزن دقیق ۱ گرم ، ابعاد مناسب و بسته بندی شکیل ، این محصول را به گزینه ای ایده آل برای نگهداری ارزش ، هدیه های خاص و کلکسیون های طلا تبدیل می کند . < / div > -- >
<!-- < div class = "text-base text-gray-700 whitespace-pre-line" > شمش طلای نقش برجسته ونوس ۱ گرمی انتخابی ظریف و ارزشمند برای سرمایه گذاری و هدیه است . این شمش از طلای خالص با عیار بالا ساخته شده و نقش برجسته ی الهه ونوس ، نمادی از زیبایی و ظرافت ، جلوه ای هنری و خاص به آن بخشیده است . وزن دقیق ۱ گرم ، ابعاد مناسب و بسته بندی شکیل ، این محصول را به گزینه ای ایده آل برای نگهداری ارزش ، هدیه های خاص و کلکسیون های طلا تبدیل می کند . < / div > -- >
< / div >
<!-- Similar Products -- >
< div v-if = "product?.similar?.length" class="mt-8" >
< div class = "text-lg font-semibold mb-4" > محصولات مشابه < / div >
< swiper
:slides-per-view = "2.25"
:space-between = "16"
class = "similar-products-swiper"
:slides-per-view = "2.25"
:space-between = "16"
class = "similar-products-swiper"
>
< swiper-slide
v-for = "item in product.similar"
:key = "item.id"
v-for = "item in product.similar"
:key = "item.id"
>
< div
class = "bg-white rounded-lg shadow p-4 cursor-pointer h-full"
@click ="goToProduct(item.id)"
class = "bg-white rounded-lg shadow p-4 cursor-pointer h-full"
@click ="goToProduct(item.id)"
>
<!-- Image -- >
< div class = "bg-gray-100 rounded-md flex justify-center p-4 mb-2" >
< img
:src = "getProductImage(item)"
class = "h-20 object-contain"
:src = "getProductImage(item)"
class = "h-20 object-contain"
/ >
< / div >
@@ -75,11 +78,17 @@
< div class = "text-sm font-semibold mb-1 line-clamp-2" >
{ { item . title } }
< / div >
<!-- Price -- >
< div class = "text-sm text-primary font-bold" >
< div class = "text-sm text-primary font-bold mb-3 " >
{ { usePrice ( ( item . price ? ? 0 ) + ( item . cash _fee _buy ? ? 0 ) ) } }
< / div >
< span
v-if = "item.inventory || item.inventory==0"
class = "text-xs bg-gray-300 text-gray-600 px-1 py-0.5 rounded-md "
>
ناموجود
< / span >
< / div >
< / swiper-slide >
< / swiper >
@@ -101,24 +110,24 @@
< script setup lang = "ts" >
import { onMounted , onUnmounted , ref , computed , watch } from 'vue'
import { useRoute , useRouter } from 'vue-router'
import { useRoute , useRouter } from 'vue-router'
import { getProductById , getProducts } from '@/api/products'
import { loading , getToken } from '@/utils'
import type { Product } from '@/models/products'
import { loading , getToken } from '@/utils'
import type { Product } from '@/models/products'
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
import indexGold from '@/views/base/gold/index.vue'
import DealProduct from '@/views/base/products/components/DealProduct.vue'
import { cloneDeep } from 'lodash'
import { cloneDeep } from 'lodash'
import img from '@/assets/img/user_ly1.svg'
import { message } from 'ant-design-vue'
import { message } from 'ant-design-vue'
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
import { usePrice } from '@/utils/usePrice'
import { usePrice } from '@/utils/usePrice'
import {
getLastPrices ,
lastPrice ,
stopPriceInterval
} from '@/utils/price'
import { Swiper , SwiperSlide } from 'swiper/vue'
import { Swiper , SwiperSlide } from 'swiper/vue'
import 'swiper/swiper-bundle.css'
// Image imports
@@ -143,10 +152,11 @@ watch(
( newId , oldId ) => {
if ( newId && newId !== oldId ) {
loadProduct ( )
window . scrollTo ( { top : 0 , behavior : 'smooth' } )
window . scrollTo ( { top : 0 , behavior : 'smooth' } )
}
}
)
async function loadProduct ( ) {
try {
loading . value = true
@@ -155,7 +165,7 @@ async function loadProduct() {
const foundProduct = products
if ( ! foundProduct ) {
message . error ( 'محصول یافت نشد' )
router . push ( { name : 'buyProduct' } )
router . push ( { name : 'buyProduct' } )
return
}
product . value = foundProduct
@@ -164,7 +174,7 @@ async function loadProduct() {
console . log ( e )
if ( e ? . response ? . status === 401 ) {
message . warning ( 'برای مشاهده محصولات، لطفا ابتدا وارد حساب کاربری خود شوید' )
router . push ( { name : 'login' } )
router . push ( { name : 'login' } )
} else {
message . error ( 'خطا در بارگذاری محصول' )
}
@@ -172,9 +182,10 @@ async function loadProduct() {
loading . value = false
}
}
watch ( lastPrice , async ( ) => {
// console.log(items);
if ( lastPrice . value && product . value . similar ) {
if ( lastPrice . value && product . value . similar ) {
product . value . similar . forEach ( ( val ) => {
// console.log(lastPrice.value)
if ( val . group _type == 'آبشده' ) {
@@ -189,7 +200,7 @@ watch(lastPrice, async () => {
} )
}
} , { deep : true } )
} , { deep : true } )
async function initPrice ( ) {
try {
@@ -215,7 +226,7 @@ function handleBuyClick() {
if ( ! product . value ? . show ) {
return
}
// // Check if user is logged in
// if (!getToken()) {
// message.warning('برای خرید یا فروش محصولات، لطفا ابتدا وارد حساب کاربری خود شوید')
@@ -234,8 +245,9 @@ onMounted(() => {
onUnmounted ( ( ) => {
stopPriceInterval ( )
} )
function goToProduct ( id : number ) {
router . push ( { name : 'productDetail' , params : { id } } )
router . push ( { name : 'productDetail' , params : { id } } )
}
function getProductImage ( product : any ) {
@@ -243,7 +255,7 @@ function getProductImage(product: any) {
if ( product ? . file ? . src ) {
return product . file . src
}
// Fallback to local images based on group_type if file is empty or doesn't exist
const type = product ? . group _type
switch ( type ) {