@@ -1,11 +1,11 @@
< template >
< div class = "bottom-0 fixed top-0" >
< div class = "bottom-0 fixed top-0 -z-10 pointer-events-none " >
< img :src = "img" alt = "" class = " w-inherit "
: style = "{ backgroundRepeat: 'repeat', }"
/ >
< / div >
< a-spin :spinning = "loading" >
< div class = " !h-full overflow-y-scroll" >
< div class = "relative z-0 !h-full overflow-y-scroll" >
< div class = "w-full flex justify-center top-0 py-5" style = "align-self: center" >
< ARadioGroup @change ="changeTab" v -model :value = "activekey" button -style = " solid " >
< ARadioButton class = "cats" value = "همه" > همه < / ARadioButton >
@@ -18,7 +18,7 @@
< / div >
< div class = "mx-5 pb-30 pt-2 grid grid-cols-2 gap-2" style = "color: #1b2b07" >
< div class = "mt-3 gap-2 " :class = "!viewVertical?'col-span-2':''" v-for = "item in items?.filter(i => i.show) " >
< div class = "mt-3 gap-2 " :class = "!viewVertical?'col-span-2':''" v-for = "item in items" :key="item.id " >
< ProductItemVertical v-if = "viewVertical" :ProductItem="item" @click="clickProduct(item)" > < / ProductItemVertical >
< ProductItem v-else class = "col-span-2" :ProductItem = "item" @click ="clickProduct(item)" > < / ProductItem >
< / div >
@@ -63,7 +63,7 @@ import BasicButton from "@/App.vue";
import BasicIcon from "@/components/BasicPacks/BasicIcon.vue" ;
import ProductItemVertical from "@/views/base/products/components/ProductItemVertical.vue" ;
const activekey = ref ( 'آبشد ه ' )
const activekey = ref ( 'هم ه ' )
const showFilter = ref ( )
const selectedProduct = ref < Product > ( )
const viewVertical = ref < boolean > ( 'true' )
@@ -92,11 +92,10 @@ onMounted(async () => {
try {
loading . value = true
items . value = await getProducts ( )
items . value ? . forEach ( ( val , index ) => {
items . value ? . forEach ( ( val ) => {
if ( ! typeItems . value . includes ( val . group _type ) ) {
typeItems . value . push ( val . group _type )
}
// typeItems.value[index] = val.group_type
} )
firstItems . value = items . value
await initPrice ( )
@@ -134,34 +133,43 @@ onUnmounted(() => {
// console.log('okgold')
} )
watch ( lastPrice , async ( ) => {
// console.log(items);
if ( lastPrice . value && items . value ) {
items . value . forEach ( ( val ) => {
// console.log(lastPrice.value)
if ( val . group _type == 'آبشده' ) {
val . price = lastPrice . value ? . price _last
val . sellPrice = lastPrice . value ? . sell
} else {
val . price = parseInt ( val . amount * lastPrice . value ? . price _last )
val . sellPrice = parseInt ( val . amount * lastPrice . value ? . sell )
function applyLivePricesToProducts ( products : Product [ ] | undefined ) {
if ( ! lastPrice . value || ! products ? . length ) {
return
}
// console.log(lastPrice.value?.price_last + "*" + val.amount + ' ' + val.price)
}
} )
// Update firstItems as well
if ( firstItems . value ) {
firstItems . value . forEach ( ( val ) => {
products . forEach ( ( val ) => {
if ( val . group _type == 'آبشده' ) {
val . price = parseInt ( lastPrice . value ? . price _last )
val . sellPrice = parseInt ( lastPrice . value ? . sell )
val . price = parseInt ( String ( lastPrice . value ? . price _last ? ? 0 ) )
val . sellPrice = parseInt ( String ( lastPrice . value ? . sell ? ? 0 ) )
} else {
val . price = parseInt ( val . amount * lastPrice . value ? . price _last )
val . sellPrice = parseInt ( val . amount * lastPrice . value ? . sell )
val . price = parseInt ( String ( val . amount * lastPrice . value ? . price _last ) )
val . sellPrice = parseInt ( String ( val . amount * lastPrice . value ? . sell ) )
}
syncProductShow ( val )
} )
}
/** show از API سرور — بعد از محاسبه قیمت زنده فقط اگر غیرفعال یا قیمت صفر باشد خاموش میشود */
function syncProductShow ( product : Product ) {
if ( ! product . active ) {
product . show = false
return
}
const displayPrice = Number ( product . price ? ? 0 ) + Number ( product . cash _fee _buy ? ? 0 )
if ( displayPrice > 0 ) {
product . show = true
return
}
product . show = Number ( lastPrice . value ? . price _last ? ? 0 ) > 0
}
watch ( lastPrice , ( ) => {
applyLivePricesToProducts ( items . value )
applyLivePricesToProducts ( firstItems . value )
} , { deep : true } )
async function initPrice ( ) {
@@ -172,30 +180,8 @@ async function initPrice() {
loading . value = true
price . value = lastPrice . value
// Update prices for all items
if ( lastPrice . value && items . value ) {
items . value . forEach ( ( val ) => {
if ( val . group _type == 'آبشده' ) {
val . price = parseInt ( lastPrice . value ? . price _last )
val . sellPrice = parseInt ( lastPrice . value ? . sell )
} else {
val . price = parseInt ( val . amount * lastPrice . value ? . price _last )
val . sellPrice = parseInt ( val . amount * lastPrice . value ? . sell )
}
} )
// Update firstItems as well
if ( firstItems . value ) {
firstItems . value . forEach ( ( val ) => {
if ( val . group _type == 'آبشده' ) {
val . price = parseInt ( lastPrice . value ? . price _last )
val . sellPrice = parseInt ( lastPrice . value ? . sell )
} else {
val . price = parseInt ( val . amount * lastPrice . value ? . price _last )
val . sellPrice = parseInt ( val . amount * lastPrice . value ? . sell )
}
} )
}
}
applyLivePricesToProducts ( items . value )
applyLivePricesToProducts ( firstItems . value )
} catch ( e : any ) {
console . log ( e )
// If 401 error, just skip price initialization