fix bug of products selector
This commit is contained in:
@@ -22,8 +22,11 @@ export function getProductsCatalog(force = false): Promise<Product[]> {
|
||||
|
||||
catalogPromise = getProducts()
|
||||
.then((products) => {
|
||||
catalogProducts.value = products ?? []
|
||||
syncProductTradingHoursFromProducts(catalogProducts.value)
|
||||
// وقتی فروشگاه بسته است API گاهی [] برمیگرداند — کاتالوگ قبلی را پاک نکن
|
||||
if (Array.isArray(products) && products.length > 0) {
|
||||
catalogProducts.value = products
|
||||
syncProductTradingHoursFromProducts(catalogProducts.value)
|
||||
}
|
||||
return catalogProducts.value
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
@@ -64,6 +64,8 @@ function applyProductsList(products: Product[]) {
|
||||
if (products.length) {
|
||||
productsCloseTime.value = products[0].auto_close_at
|
||||
productsOpenTime.value = products[0].auto_open_at
|
||||
// همسان نگه داشتن کاتالوگ مشترک با لیست صفحه محصولات
|
||||
getProductsCatalogRef().value = products
|
||||
}
|
||||
|
||||
productsFirstItems.value = products
|
||||
|
||||
@@ -13,16 +13,10 @@
|
||||
:class="mobileLayout ? 'boursecu-transactions__filter-select' : undefined"
|
||||
placeholder="محصول"
|
||||
size="large"
|
||||
:options="productOptions"
|
||||
:get-popup-container="popupContainer"
|
||||
@change="applyInlineFilters"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="option in productOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
/>
|
||||
</div>
|
||||
|
||||
<a-select
|
||||
@@ -89,4 +83,8 @@ const {
|
||||
statusOptions,
|
||||
applyInlineFilters,
|
||||
} = useTransactionsPageContext()
|
||||
|
||||
function popupContainer() {
|
||||
return document.body
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -2,6 +2,10 @@ import { computed, inject, onActivated, onMounted, provide, ref, type ComponentP
|
||||
import { useIntersectionObserver } from '@vueuse/core'
|
||||
import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
|
||||
import { getProductsCatalog, getProductsCatalogRef } from '@/composables/useProductsCatalog'
|
||||
import {
|
||||
initProductsPageData,
|
||||
productsFirstItems,
|
||||
} from '@/views/base/products/composables/useProductsPageData'
|
||||
import { loading, loadingMore } from '@/utils'
|
||||
import {
|
||||
BOURSECU_TRANSACTION_TABS,
|
||||
@@ -81,14 +85,19 @@ export function useTransactionsPageProvider() {
|
||||
|
||||
const statusOptions = computed(() => getBoursecuStatusOptionsForTab(activeTab.value))
|
||||
|
||||
const productOptions = computed(() =>
|
||||
getProductsCatalogRef().value
|
||||
.filter((product) => product.active && product.show)
|
||||
.map((product) => ({
|
||||
value: product.id,
|
||||
label: product.title,
|
||||
})),
|
||||
)
|
||||
// بدون فیلتر active/show: برای تاریخچه معاملات همه محصولات کاتالوگ لازم است.
|
||||
// اگر کاتالوگ خالی بود (مثلاً بعد از پاسخ خالی API هنگام بسته بودن فروشگاه)،
|
||||
// از کش صفحه محصولات استفاده میکنیم.
|
||||
const productOptions = computed(() => {
|
||||
const catalog = getProductsCatalogRef().value
|
||||
const source =
|
||||
catalog.length > 0 ? catalog : (productsFirstItems.value ?? [])
|
||||
|
||||
return source.map((product) => ({
|
||||
value: product.id,
|
||||
label: product.title,
|
||||
}))
|
||||
})
|
||||
|
||||
const showProductFilter = computed(
|
||||
() => boursecuTabSupportsProductFilter(activeTab.value),
|
||||
@@ -178,6 +187,16 @@ export function useTransactionsPageProvider() {
|
||||
|
||||
onMounted(async () => {
|
||||
await getProductsCatalog()
|
||||
|
||||
// اگر کاتالوگ خالی است، از مسیر صفحه محصولات دوباره پر کن
|
||||
if (!getProductsCatalogRef().value.length) {
|
||||
await initProductsPageData(true)
|
||||
}
|
||||
|
||||
if (!getProductsCatalogRef().value.length && productsFirstItems.value?.length) {
|
||||
getProductsCatalogRef().value = productsFirstItems.value
|
||||
}
|
||||
|
||||
await initTransactionsPageData()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user