some trigger handled
This commit is contained in:
@@ -67,7 +67,7 @@
|
||||
size="large" type="text" inputmode="numeric" @onchange="handleGoldValueChange" />
|
||||
</a-form-item>
|
||||
<a-form-item v-else name="goldValue"
|
||||
:rules="[justNumber3(props?.ProductItem?.sellPrice, productNum ,false)]">
|
||||
:rules="[justNumber3(props?.ProductItem?.sellPrice, productNum.value ,false)]">
|
||||
<BasicInput v-model:value="form.goldValue" addon-before="تعداد" addon-bg-color="#000000FF"
|
||||
addon-text-color="white"
|
||||
place-holder="تعداد"
|
||||
@@ -104,8 +104,7 @@
|
||||
{{ cashWalletBalanceText }}
|
||||
</div>
|
||||
<div class="font-bold text-xs" v-else>
|
||||
<div>{{ `موجودی محصول: ${getInventoryById(props?.ProductItem?.id)} ${getProductQuantityUnit(props?.ProductItem)}` }}</div>
|
||||
<div v-if="isMetalReceiveDeal" class="mt-1">{{ sellMetalWalletBalanceText }}</div>
|
||||
<div>{{ productWalletBalanceText }}</div>
|
||||
</div>
|
||||
</Transition>
|
||||
<Transition mode="out-in" name="fade">
|
||||
@@ -296,6 +295,8 @@ import {
|
||||
productMaxOrderCash,
|
||||
productMinOrderCash
|
||||
} from '@/utils/productOrderLimit'
|
||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||
import { formatProductWalletBalanceText, getProductInventoryQuantity } from '@/utils/productAssets'
|
||||
|
||||
const typeDeal = computed(() => getProductDealMethodOptions(props?.ProductItem?.group_type, isBuy.value))
|
||||
|
||||
@@ -329,16 +330,28 @@ const goldWalletBalanceText = computed(() =>
|
||||
formatGoldWalletBalanceText(walletStore?.walletInfo?.gold ?? 0, productGroupType.value)
|
||||
)
|
||||
|
||||
const productWalletBalance = computed(() =>
|
||||
getProductInventoryQuantity(
|
||||
assetsSummary.value?.inventory_cards ?? [],
|
||||
props?.ProductItem?.id,
|
||||
walletStore?.walletInfo?.gold
|
||||
)
|
||||
)
|
||||
|
||||
const productWalletBalanceText = computed(() =>
|
||||
formatProductWalletBalanceText(
|
||||
props?.ProductItem,
|
||||
assetsSummary.value?.inventory_cards ?? [],
|
||||
walletStore?.walletInfo?.gold
|
||||
)
|
||||
)
|
||||
|
||||
const buyMetalWalletBalanceText = computed(() =>
|
||||
form.value.method === 'katod'
|
||||
? formatMainMetalWalletBalanceText(walletStore?.walletInfo?.gold ?? 0)
|
||||
: goldWalletBalanceText.value
|
||||
)
|
||||
|
||||
const sellMetalWalletBalanceText = computed(() =>
|
||||
formatMainMetalWalletBalanceText(walletStore?.walletInfo?.gold ?? 0)
|
||||
)
|
||||
|
||||
const cashWalletBalanceText = computed(() =>
|
||||
formatCashWalletBalanceText(
|
||||
usePriceWithoutType(walletStore?.walletInfo?.cash ?? 0),
|
||||
@@ -347,6 +360,7 @@ const cashWalletBalanceText = computed(() =>
|
||||
)
|
||||
const infoVisible = ref(false)
|
||||
const walletStore = useWalletStore()
|
||||
const { assetsSummary, loadWalletAssets } = useWalletAssets()
|
||||
const userStore = useUserStore()
|
||||
const confirmAction = ref<boolean>(false)
|
||||
const noCompleteVisible = ref<boolean>(false)
|
||||
@@ -525,6 +539,7 @@ async function initSellTable() {
|
||||
// }
|
||||
|
||||
onMounted(async () => {
|
||||
void loadWalletAssets()
|
||||
switch (router.currentRoute.value.query.state) {
|
||||
case 'sell':
|
||||
isBuy.value = false
|
||||
@@ -581,15 +596,7 @@ onMounted(() => {
|
||||
noCompleteVisible.value = true
|
||||
}
|
||||
})
|
||||
const productNum = ref<number>(0)
|
||||
const getInventoryById = (id: number) => {
|
||||
|
||||
userStore?.productWallet?.forEach((val) => {
|
||||
if (val.product_id == id)
|
||||
productNum.value = val.gold
|
||||
})
|
||||
return productNum.value ?? 0
|
||||
}
|
||||
const productNum = computed(() => productWalletBalance.value)
|
||||
|
||||
/*function percentChange(val: number) {
|
||||
if (val !== 0)
|
||||
@@ -802,6 +809,7 @@ async function ok() {
|
||||
emit('ordered')
|
||||
await userStore.getMyInfo()
|
||||
await walletStore.getMyWallet()
|
||||
await loadWalletAssets(true)
|
||||
await fundStore.getMyFund()
|
||||
message.success('سفارش شما با موفقیت انجام شد')
|
||||
await router.push({ name: 'transactions' })
|
||||
|
||||
@@ -89,13 +89,7 @@ import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import router from '@/router'
|
||||
import ProductItem from '@/views/base/products/components/ProductItem.vue'
|
||||
import { getProducts } from '@/api/products'
|
||||
import {
|
||||
getLastPrices,
|
||||
lastPrice,
|
||||
stopPriceInterval
|
||||
} from '@/utils/price'
|
||||
import { loading } from '@/utils'
|
||||
import { Price } from '@/models/home'
|
||||
import type { Product } from '@/models/products'
|
||||
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
||||
import indexGold from '@/views/base/gold/index.vue'
|
||||
@@ -162,9 +156,57 @@ function changeTab() {
|
||||
}
|
||||
|
||||
const firstItems = ref<Product[]>()
|
||||
const price = ref<Price>()
|
||||
const items = ref<Product[]>()
|
||||
const typeItems = ref([])
|
||||
let productListInterval: ReturnType<typeof setInterval> | undefined
|
||||
|
||||
/**
|
||||
* رفرش بیصدای لیست محصولات (هر ۱۰ ثانیه تا وقتی در این صفحهایم).
|
||||
* آپدیت درجا انجام میشود تا لیست re-render کامل نشود و نپرد؛
|
||||
* فقط اگر محصولی اضافه/حذف شده باشد ساختار لیست عوض میشود.
|
||||
*/
|
||||
async function refreshProducts() {
|
||||
try {
|
||||
const fresh = await getProducts()
|
||||
if (!fresh?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
fresh.forEach((val) => {
|
||||
if (!typeItems.value.includes(val.group_type)) {
|
||||
typeItems.value.push(val.group_type)
|
||||
}
|
||||
})
|
||||
|
||||
const freshById = new Map(fresh.map((p) => [p.id, p]))
|
||||
const current = firstItems.value
|
||||
|
||||
if (!current?.length) {
|
||||
firstItems.value = fresh
|
||||
changeTab()
|
||||
return
|
||||
}
|
||||
|
||||
// آپدیت فیلدهای محصولات موجود روی همان آبجکتها (items همین رفرنسها را دارد)
|
||||
current.forEach((item) => {
|
||||
const updated = freshById.get(item.id)
|
||||
if (updated) {
|
||||
Object.assign(item, updated)
|
||||
}
|
||||
})
|
||||
|
||||
const currentIds = new Set(current.map((p) => p.id))
|
||||
const hasAdded = fresh.some((p) => !currentIds.has(p.id))
|
||||
const hasRemoved = current.some((p) => !freshById.has(p.id))
|
||||
if (hasAdded || hasRemoved) {
|
||||
firstItems.value = fresh
|
||||
changeTab()
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
@@ -182,9 +224,9 @@ onMounted(async () => {
|
||||
// typeItems.value[index] = val.group_type
|
||||
})
|
||||
firstItems.value = items.value
|
||||
await Promise.all([initPrice(), loadServiceFeeFromSettings()])
|
||||
// await setIntervalGetLastPrice()
|
||||
// console.log('run product')
|
||||
await loadServiceFeeFromSettings()
|
||||
// فقط لیست محصولات هر ۱۰ ثانیه — last فقط در صفحه اصلی poll میشود
|
||||
productListInterval = setInterval(refreshProducts, 10000)
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
@@ -205,10 +247,10 @@ onMounted(async () => {
|
||||
}
|
||||
})
|
||||
onUnmounted(() => {
|
||||
stopPriceInterval()
|
||||
// console.log('stop product')
|
||||
|
||||
// console.log('okgold')
|
||||
if (productListInterval) {
|
||||
clearInterval(productListInterval)
|
||||
productListInterval = undefined
|
||||
}
|
||||
})
|
||||
// watch(lastPrice, async () => {
|
||||
// // console.log(items);
|
||||
@@ -226,19 +268,6 @@ onUnmounted(() => {
|
||||
//
|
||||
// })
|
||||
// })
|
||||
|
||||
async function initPrice() {
|
||||
try {
|
||||
// chartLoading.value = true
|
||||
await getLastPrices()
|
||||
loading.value = true
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
// chartLoading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
|
||||
Reference in New Issue
Block a user