From 3a3a55287b0abdac1b632b26b6dd457f864ad36c Mon Sep 17 00:00:00 2001 From: MojtabaSoumi Date: Wed, 1 Jul 2026 18:18:46 +0330 Subject: [PATCH] 1405/04/10-fix bugs --- src/layouts/components/MobilePageHeader.vue | 35 +++ .../composables/useMobileScrollReset.ts | 125 ++++++++ src/layouts/styles/mobile-page-common.less | 208 +++++++++++++ src/views/base/home/components/AppHeader.vue | 208 +++++++++++++ .../PhysicalReceiveAddressPicker.vue | 50 ++++ .../components/PhysicalReceiveCartRow.vue | 108 +++++++ .../composables/useNewPhysicalRequestPage.ts | 170 +++++++++++ .../composables/usePhysicalReceiveList.ts | 37 +++ .../composables/usePhysicalReceiveShell.ts | 23 ++ .../desktop/DesktopNewRequestView.vue | 126 ++++++++ .../mobile/MobileNewRequestView.vue | 165 +++++++++++ .../mobile/MobilePhysicalReceiveChrome.vue | 15 + .../mobile/MobileRequestListView.vue | 29 ++ .../components/PriceTriggerForm.vue | 63 ++++ .../composables/usePriceTriggerPage.ts | 135 +++++++++ .../desktop/DesktopPriceTriggerView.vue | 78 +++++ .../desktop/styles/desktop-price-trigger.less | 273 ++++++++++++++++++ .../mobile/MobilePriceTriggerView.vue | 52 ++++ .../products/mobile/MobileProductsView.vue | 153 ++++++++++ 19 files changed, 2053 insertions(+) create mode 100644 src/layouts/components/MobilePageHeader.vue create mode 100644 src/layouts/composables/useMobileScrollReset.ts create mode 100644 src/layouts/styles/mobile-page-common.less create mode 100644 src/views/base/home/components/AppHeader.vue create mode 100644 src/views/base/physicalReceive/components/PhysicalReceiveAddressPicker.vue create mode 100644 src/views/base/physicalReceive/components/PhysicalReceiveCartRow.vue create mode 100644 src/views/base/physicalReceive/composables/useNewPhysicalRequestPage.ts create mode 100644 src/views/base/physicalReceive/composables/usePhysicalReceiveList.ts create mode 100644 src/views/base/physicalReceive/composables/usePhysicalReceiveShell.ts create mode 100644 src/views/base/physicalReceive/desktop/DesktopNewRequestView.vue create mode 100644 src/views/base/physicalReceive/mobile/MobileNewRequestView.vue create mode 100644 src/views/base/physicalReceive/mobile/MobilePhysicalReceiveChrome.vue create mode 100644 src/views/base/physicalReceive/mobile/MobileRequestListView.vue create mode 100644 src/views/base/priceTrigger/components/PriceTriggerForm.vue create mode 100644 src/views/base/priceTrigger/composables/usePriceTriggerPage.ts create mode 100644 src/views/base/priceTrigger/desktop/DesktopPriceTriggerView.vue create mode 100644 src/views/base/priceTrigger/desktop/styles/desktop-price-trigger.less create mode 100644 src/views/base/priceTrigger/mobile/MobilePriceTriggerView.vue create mode 100644 src/views/base/products/mobile/MobileProductsView.vue diff --git a/src/layouts/components/MobilePageHeader.vue b/src/layouts/components/MobilePageHeader.vue new file mode 100644 index 0000000..fbc9c6e --- /dev/null +++ b/src/layouts/components/MobilePageHeader.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/layouts/composables/useMobileScrollReset.ts b/src/layouts/composables/useMobileScrollReset.ts new file mode 100644 index 0000000..aed17b6 --- /dev/null +++ b/src/layouts/composables/useMobileScrollReset.ts @@ -0,0 +1,125 @@ +import { nextTick } from 'vue' +import router from '@/router' + +let recoveryTimers: ReturnType[] = [] + +function clearRecoveryTimers() { + recoveryTimers.forEach(clearTimeout) + recoveryTimers = [] +} + +function blurFocusedField() { + const active = document.activeElement + if (active instanceof HTMLElement && active !== document.body) { + active.blur() + } +} + +function clearBodyScrollLock() { + document.body.classList.remove('van-overflow-hidden') + document.body.style.removeProperty('position') + document.body.style.removeProperty('top') + document.body.style.removeProperty('left') + document.body.style.removeProperty('right') + document.body.style.removeProperty('width') + document.body.style.removeProperty('height') + document.body.style.removeProperty('min-height') + document.body.style.removeProperty('overflow') + document.body.style.removeProperty('transform') + document.documentElement.style.removeProperty('overflow') + document.documentElement.style.removeProperty('height') + document.documentElement.style.removeProperty('transform') + + const appRoot = document.getElementById('app') + if (appRoot) { + appRoot.style.removeProperty('position') + appRoot.style.removeProperty('top') + appRoot.style.removeProperty('height') + appRoot.style.removeProperty('min-height') + appRoot.style.removeProperty('overflow') + appRoot.style.removeProperty('transform') + } +} + +function resetAllScrollPositions() { + window.scrollTo(0, 0) + document.documentElement.scrollTop = 0 + document.body.scrollTop = 0 + + document + .querySelectorAll('.main-with-bottom-chrome-inner, .login-page, .login-page-root') + .forEach((node) => { + if (node instanceof HTMLElement) { + node.scrollTop = 0 + } + }) +} + +function kickViewportReflow() { + window.dispatchEvent(new Event('resize')) + + if (window.visualViewport) { + window.scrollTo(0, 0) + } +} + +function runViewportRecovery() { + clearBodyScrollLock() + resetAllScrollPositions() + kickViewportReflow() +} + +function scheduleViewportRecovery() { + clearRecoveryTimers() + runViewportRecovery() + + nextTick(() => { + requestAnimationFrame(() => { + runViewportRecovery() + + for (const delay of [50, 150, 300, 500]) { + recoveryTimers.push(window.setTimeout(runViewportRecovery, delay)) + } + }) + }) +} + +/** Reset scroll offsets after navigation — fixes iOS safe-area drift. */ +export function resetMobileAppScroll() { + runViewportRecovery() + + nextTick(() => { + requestAnimationFrame(runViewportRecovery) + }) +} + +export async function dismissMobileKeyboard() { + blurFocusedField() + await new Promise((resolve) => window.setTimeout(resolve, 120)) +} + +export async function prepareMobileViewportForAppShell() { + blurFocusedField() + resetAllScrollPositions() + await dismissMobileKeyboard() +} + +/** Full recovery after auth — runs after home shell is mounted. */ +export function recoverMobileViewportAfterAuth() { + scheduleViewportRecovery() +} + +export const resetMobileAppScrollAfterLogin = recoverMobileViewportAfterAuth + +export async function completeLoginNavigation() { + await prepareMobileViewportForAppShell() + await router.push({ name: 'buyProduct' }) + await router.isReady() + recoverMobileViewportAfterAuth() +} + +export function initMobileScrollRestoration() { + if (typeof history !== 'undefined' && 'scrollRestoration' in history) { + history.scrollRestoration = 'manual' + } +} diff --git a/src/layouts/styles/mobile-page-common.less b/src/layouts/styles/mobile-page-common.less new file mode 100644 index 0000000..6d315df --- /dev/null +++ b/src/layouts/styles/mobile-page-common.less @@ -0,0 +1,208 @@ +/* Shared mobile page chrome (inner pages — not home .app-header) */ + +:root { + --mpage-header-bar: 2.75rem; + --mpage-header-offset: calc(4rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); + --mpage-subheader-offset: calc(var(--mpage-header-bar) + var(--app-safe-top, env(safe-area-inset-top, 0px))); + --mpage-content-with-subheader: calc(6.5rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); + --mpage-scroll-max-height: calc(100dvh - 50px - var(--app-safe-top, env(safe-area-inset-top, 0px))); + --mobile-info-support-block: calc(5rem + var(--app-safe-bottom, env(safe-area-inset-bottom, 0px))); +} + +/* Fixed top bar: background fills under status bar; content sits below safe area */ +.mobile-top-chrome { + top: 0; + box-sizing: border-box; + padding-top: calc(0.75rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); +} + +.mobile-top-chrome.h-12, +.mobile-top-chrome.min-h-12 { + height: auto; + min-height: calc(3rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); +} + +.mpage-header { + display: flex; + align-items: center; + gap: 0.5rem; + top: 0; + box-sizing: border-box; + padding: 0.75rem; + padding-top: calc(0.75rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); + background: #fff; + color: @primary-color; + font-size: 1rem; + font-weight: 700; + line-height: 1.5; + box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08); + z-index: 1999; + + &__back { + display: inline-flex; + align-items: center; + justify-content: center; + border: none; + background: transparent; + padding: 0; + color: inherit; + cursor: pointer; + font-family: inherit; + } + + &__title { + flex: 1; + min-width: 0; + } + + &__trailing { + display: inline-flex; + align-items: center; + flex-shrink: 0; + } +} + +.mpage-subheader { + top: var(--mpage-subheader-offset); + z-index: 1999; + padding: 0.75rem; + background: #fff; + color: @primary-color; + font-weight: 700; +} + +.mpage-content { + padding-top: var(--mpage-header-offset); +} + +.mpage-content--with-subheader { + padding-top: var(--mpage-content-with-subheader); +} + +.mpage-scroll { + overflow-y: auto; + max-height: var(--mpage-scroll-max-height); +} + +.mobile-page-body--pt10 { + padding-top: calc(2.5rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); +} + +.mobile-page-body--pt15 { + padding-top: calc(3.75rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); +} + +.mobile-page-body--pt20 { + padding-top: calc(5rem + var(--app-safe-top, env(safe-area-inset-top, 0px))); +} + +/* Info pages (about, educate): fixed shell, scroll inside content box only */ +.mobile-info-page { + position: relative; + display: flex; + flex-direction: column; + height: 100%; + min-height: 0; + max-height: 100%; + overflow: hidden; +} + +.mobile-info-page__header { + z-index: 1999; +} + +/* Decorative page background — fixed to viewport, never scrolls on iOS */ +.mobile-page-bg, +.mobile-info-page__bg { + pointer-events: none; + position: fixed; + z-index: 0; + top: 0; + left: 0; + right: 0; + bottom: var(--app-bottom-chrome-height, 80px); + overflow: hidden; + max-width: 100vw; + box-sizing: border-box; + + img { + position: absolute; + bottom: 0; + left: 0; + width: 100%; + height: auto; + } +} + +.mobile-page-bg--no-nav, +.mobile-info-page__bg { + bottom: var(--app-credit-footer-offset, 0px); +} + +.mobile-page-bg--cover { + background-size: cover; + background-position: center; + background-repeat: no-repeat; +} + +html:not(.app-layout--desktop) { + @media screen and (min-width: 426px) and (max-width: 767.98px) { + .mobile-page-bg, + .mobile-info-page__bg { + width: 426px; + max-width: 426px; + left: 50%; + right: auto; + transform: translateX(-50%); + } + } +} + +.mobile-info-page__main { + position: relative; + z-index: 1; + flex: 1 1 0; + min-height: 0; + display: flex; + flex-direction: column; + overflow: hidden; + padding-top: calc(var(--mpage-header-offset) + 1rem); + padding-right: 2.5rem; + padding-left: 2.5rem; + padding-bottom: calc( + var(--mobile-info-support-block, 5rem) + var(--app-credit-footer-offset, 0px) + 1.25rem + ); + pointer-events: none; + + > * { + pointer-events: auto; + } +} + +.mobile-info-page__support { + bottom: var(--app-credit-footer-offset, 0px); + box-sizing: border-box; + padding: 1rem 2.5rem; + padding-bottom: calc(1rem + var(--app-safe-bottom, env(safe-area-inset-bottom, 0px))); + background: #fff; + box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.06); + z-index: 1998; +} + +.mobile-content-box { + display: flex; + flex-direction: column; + flex: 1 1 0; + min-height: 0; + overflow: hidden; + margin-bottom: 0.75rem; +} + +.mobile-content-box__scroll { + flex: 1 1 0; + min-height: 0; + overflow-y: auto; + overflow-x: hidden; + -webkit-overflow-scrolling: touch; + overscroll-behavior-y: contain; +} diff --git a/src/views/base/home/components/AppHeader.vue b/src/views/base/home/components/AppHeader.vue new file mode 100644 index 0000000..f9df656 --- /dev/null +++ b/src/views/base/home/components/AppHeader.vue @@ -0,0 +1,208 @@ + + + + + diff --git a/src/views/base/physicalReceive/components/PhysicalReceiveAddressPicker.vue b/src/views/base/physicalReceive/components/PhysicalReceiveAddressPicker.vue new file mode 100644 index 0000000..a29b811 --- /dev/null +++ b/src/views/base/physicalReceive/components/PhysicalReceiveAddressPicker.vue @@ -0,0 +1,50 @@ + + + diff --git a/src/views/base/physicalReceive/components/PhysicalReceiveCartRow.vue b/src/views/base/physicalReceive/components/PhysicalReceiveCartRow.vue new file mode 100644 index 0000000..0962341 --- /dev/null +++ b/src/views/base/physicalReceive/components/PhysicalReceiveCartRow.vue @@ -0,0 +1,108 @@ + + + + + diff --git a/src/views/base/physicalReceive/composables/useNewPhysicalRequestPage.ts b/src/views/base/physicalReceive/composables/useNewPhysicalRequestPage.ts new file mode 100644 index 0000000..949d54c --- /dev/null +++ b/src/views/base/physicalReceive/composables/useNewPhysicalRequestPage.ts @@ -0,0 +1,170 @@ +import { inject, nextTick, onMounted, provide, ref, type InjectionKey, type Ref } from 'vue' +import { cloneDeep } from 'lodash' +import { message } from 'ant-design-vue' +import router from '@/router' +import { getProductInventory } from '@/api/products' +import { physicalReceiveApi } from '@/api/physicalreceive' +import { tableAddress } from '@/api/address' +import type { CountPInventory, PInventory } from '@/models/products' +import type { Address } from '@/models/address' +import { loading } from '@/utils' +import { usePhysicalReceiveShellContext } from './usePhysicalReceiveShell' + +export interface NewPhysicalRequestContext { + isDesktop: Ref + items: Ref + selectedProduct: Ref + selectedProducts: Ref + address: Ref + selectedAddressID: Ref + showAddress: Ref + addAddressVisible: Ref + handleAdd: () => void + handleRemove: (id: number) => void + handelFirstSubmit: () => Promise + handelsubmit: () => Promise + handleAddress: () => void +} + +export const NEW_PHYSICAL_REQUEST_KEY: InjectionKey = + Symbol('newPhysicalRequest') + +export function useNewPhysicalRequestPage() { + const { isDesktop } = usePhysicalReceiveShellContext() + + const items = ref() + const baseItems = ref() + const selectedAddressID = ref() + const selectedProduct = ref() + const productsByWalletId = ref>([]) + const address = ref() + const selectedProducts = ref([]) + const showAddress = ref(false) + const addAddressVisible = ref(false) + + function handleAdd() { + const product = items.value?.find((x) => x.id === selectedProduct.value) + if (!product) return + + selectedProducts.value.push({ + count: 0, + product, + }) + items.value?.splice(items.value.findIndex((x) => x.id === selectedProduct.value), 1) + selectedProduct.value = undefined + } + + function handleAddress() { + getAddress() + addAddressVisible.value = false + showAddress.value = true + } + + function handleRemove(id: number) { + const findItem = baseItems.value?.find((x) => x.id === id) + if (findItem) { + items.value?.push(findItem) + } + selectedProducts.value.splice( + selectedProducts.value.findIndex((x) => x.product.id === id), + 1, + ) + } + + async function initProductWallet() { + try { + loading.value = true + const inventory = (await getProductInventory()).rows.filter( + (x) => x.title !== 'آبشده نقدی' && x.wallet?.gold && x.wallet.gold > 0, + ) + items.value = inventory + baseItems.value = cloneDeep(inventory) + } catch (e) { + console.log(e) + } finally { + loading.value = false + } + } + + async function handelFirstSubmit() { + try { + const zeroAmount = selectedProducts.value.map((item) => item.count <= 0) + if (zeroAmount.includes(true)) { + message.error('لطفاً تعداد درخواستی محصول را وارد کنید.') + } else { + showAddress.value = true + } + } catch (e) { + console.log(e) + } + } + + async function handelsubmit() { + if (!selectedAddressID.value) { + message.error('لطفاً آدرس را انتخاب کنید.') + return + } + + try { + loading.value = true + productsByWalletId.value = selectedProducts.value.map((val) => ({ + wallet_id: val.product.wallet.id, + value: val.count, + })) + await physicalReceiveApi({ + address_id: selectedAddressID.value, + wallets: productsByWalletId.value, + }) + + showAddress.value = false + selectedAddressID.value = undefined + selectedProducts.value = [] + await nextTick() + + message.success('درخواست شما با موفقیت ارسال شد') + await initProductWallet() + await router.push({ name: 'list' }) + } catch (e) { + console.log(e) + } finally { + loading.value = false + } + } + + async function getAddress() { + const { rows } = await tableAddress({ page: 0, limit: 150 }) + address.value = rows + } + + onMounted(async () => { + await initProductWallet() + await getAddress() + }) + + const context: NewPhysicalRequestContext = { + isDesktop, + items, + selectedProduct, + selectedProducts, + address, + selectedAddressID, + showAddress, + addAddressVisible, + handleAdd, + handleRemove, + handelFirstSubmit, + handelsubmit, + handleAddress, + } + + provide(NEW_PHYSICAL_REQUEST_KEY, context) + return context +} + +export function useNewPhysicalRequestContext() { + const context = inject(NEW_PHYSICAL_REQUEST_KEY) + if (!context) { + throw new Error('useNewPhysicalRequestContext must be used within useNewPhysicalRequestPage') + } + return context +} diff --git a/src/views/base/physicalReceive/composables/usePhysicalReceiveList.ts b/src/views/base/physicalReceive/composables/usePhysicalReceiveList.ts new file mode 100644 index 0000000..23fa974 --- /dev/null +++ b/src/views/base/physicalReceive/composables/usePhysicalReceiveList.ts @@ -0,0 +1,37 @@ +import { inject, onMounted, provide, ref, type InjectionKey, type Ref } from 'vue' +import { getPhysicalReceiveList } from '@/api/physicalreceive' +import type { Physicalreceive } from '@/models/physicalreceive' +import router from '@/router' + +export interface PhysicalReceiveListContext { + requestItems: Ref + openAdd: () => void +} + +export const PHYSICAL_RECEIVE_LIST_KEY: InjectionKey = + Symbol('physicalReceiveList') + +export function usePhysicalReceiveList() { + const requestItems = ref([]) + + function openAdd() { + router.push({ name: 'new' }) + } + + onMounted(async () => { + const { rows } = await getPhysicalReceiveList() + requestItems.value = rows + }) + + const context: PhysicalReceiveListContext = { requestItems, openAdd } + provide(PHYSICAL_RECEIVE_LIST_KEY, context) + return context +} + +export function usePhysicalReceiveListContext() { + const context = inject(PHYSICAL_RECEIVE_LIST_KEY) + if (!context) { + throw new Error('usePhysicalReceiveListContext must be used within usePhysicalReceiveList') + } + return context +} diff --git a/src/views/base/physicalReceive/composables/usePhysicalReceiveShell.ts b/src/views/base/physicalReceive/composables/usePhysicalReceiveShell.ts new file mode 100644 index 0000000..9ff147f --- /dev/null +++ b/src/views/base/physicalReceive/composables/usePhysicalReceiveShell.ts @@ -0,0 +1,23 @@ +import { inject, provide, type InjectionKey } from 'vue' +import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout' + +export interface PhysicalReceiveShellContext { + isDesktop: ReturnType +} + +export const PHYSICAL_RECEIVE_SHELL_KEY: InjectionKey = + Symbol('physicalReceiveShell') + +export function usePhysicalReceiveShell() { + const isDesktop = useDesktopBreakpoint() + provide(PHYSICAL_RECEIVE_SHELL_KEY, { isDesktop }) + return { isDesktop } +} + +export function usePhysicalReceiveShellContext() { + const context = inject(PHYSICAL_RECEIVE_SHELL_KEY) + if (!context) { + throw new Error('usePhysicalReceiveShellContext must be used within physical receive shell') + } + return context +} diff --git a/src/views/base/physicalReceive/desktop/DesktopNewRequestView.vue b/src/views/base/physicalReceive/desktop/DesktopNewRequestView.vue new file mode 100644 index 0000000..19a5db5 --- /dev/null +++ b/src/views/base/physicalReceive/desktop/DesktopNewRequestView.vue @@ -0,0 +1,126 @@ + + + + + diff --git a/src/views/base/physicalReceive/mobile/MobileNewRequestView.vue b/src/views/base/physicalReceive/mobile/MobileNewRequestView.vue new file mode 100644 index 0000000..ff4d208 --- /dev/null +++ b/src/views/base/physicalReceive/mobile/MobileNewRequestView.vue @@ -0,0 +1,165 @@ + + + + + diff --git a/src/views/base/physicalReceive/mobile/MobilePhysicalReceiveChrome.vue b/src/views/base/physicalReceive/mobile/MobilePhysicalReceiveChrome.vue new file mode 100644 index 0000000..8e3f5c0 --- /dev/null +++ b/src/views/base/physicalReceive/mobile/MobilePhysicalReceiveChrome.vue @@ -0,0 +1,15 @@ + + + diff --git a/src/views/base/physicalReceive/mobile/MobileRequestListView.vue b/src/views/base/physicalReceive/mobile/MobileRequestListView.vue new file mode 100644 index 0000000..12bf48e --- /dev/null +++ b/src/views/base/physicalReceive/mobile/MobileRequestListView.vue @@ -0,0 +1,29 @@ + + + diff --git a/src/views/base/priceTrigger/components/PriceTriggerForm.vue b/src/views/base/priceTrigger/components/PriceTriggerForm.vue new file mode 100644 index 0000000..5042b3d --- /dev/null +++ b/src/views/base/priceTrigger/components/PriceTriggerForm.vue @@ -0,0 +1,63 @@ + + + diff --git a/src/views/base/priceTrigger/composables/usePriceTriggerPage.ts b/src/views/base/priceTrigger/composables/usePriceTriggerPage.ts new file mode 100644 index 0000000..3252d5e --- /dev/null +++ b/src/views/base/priceTrigger/composables/usePriceTriggerPage.ts @@ -0,0 +1,135 @@ +import { inject, onMounted, provide, reactive, ref, type InjectionKey, type Ref } from 'vue' +import { cloneDeep } from 'lodash' +import { type FormInstance, message } from 'ant-design-vue' +import { createPriceTrigger, getPriceTriggers, updatePriceTrigger } from '@/api/triggerPrice' +import type { SelectItem } from '@/models/SelectItem' +import type { PriceTrigger } from '@/models/PriceTrigger' +import { loading } from '@/utils' + +export interface PriceTriggerPageContext { + items: Ref + addTriggerVisible: Ref + editId: Ref + form: Ref + formRef: Ref + loading: typeof loading + radioStyle: ReturnType> + typeItems: SelectItem[] + resetFields: () => void + openAdd: () => void + openEdit: (val: PriceTrigger) => void + initItems: () => Promise + ok: () => Promise +} + +export const PRICE_TRIGGER_PAGE_CONTEXT_KEY: InjectionKey = + Symbol('priceTriggerPageContext') + +export function usePriceTriggerPage() { + const items = ref([]) + const addTriggerVisible = ref(false) + const editId = ref(undefined) + const formRef = ref() + + const radioStyle = reactive({ + display: '', + height: '30px', + lineHeight: '30px', + }) + + const form = ref({ + price_condition: '', + is_active: true, + action: '', + target_price: '', + }) + + const typeItems: SelectItem[] = [ + { value: 'بزرگتر', key: '>' }, + { value: 'کوچکتر', key: '<' }, + { value: 'مساوی', key: '==' }, + ] + + function resetFields() { + form.value = { + price_condition: '', + is_active: true, + action: '', + target_price: '', + } + } + + function openAdd() { + resetFields() + editId.value = undefined + addTriggerVisible.value = true + } + + function openEdit(val: PriceTrigger) { + form.value = cloneDeep(val) + editId.value = form.value.id + addTriggerVisible.value = true + } + + async function initItems() { + try { + items.value = [] + items.value = await getPriceTriggers() + } catch (e) { + console.log(e) + } finally { + loading.value = false + } + } + + async function ok() { + await formRef.value?.validateFields().then(async () => { + try { + loading.value = true + if (editId.value) { + await updatePriceTrigger(editId.value, form.value) + } else { + await createPriceTrigger(form.value) + } + message.success('هشدار با موفقیت ایجاد شد') + await initItems() + addTriggerVisible.value = false + } catch (e) { + console.log(e) + } finally { + loading.value = false + } + }) + } + + onMounted(() => { + initItems() + }) + + const context: PriceTriggerPageContext = { + items, + addTriggerVisible, + editId, + form, + formRef, + loading, + radioStyle, + typeItems, + resetFields, + openAdd, + openEdit, + initItems, + ok, + } + + provide(PRICE_TRIGGER_PAGE_CONTEXT_KEY, context) + return context +} + +export function usePriceTriggerPageContext() { + const context = inject(PRICE_TRIGGER_PAGE_CONTEXT_KEY) + if (!context) { + throw new Error('usePriceTriggerPageContext must be used within a page that calls usePriceTriggerPage()') + } + return context +} diff --git a/src/views/base/priceTrigger/desktop/DesktopPriceTriggerView.vue b/src/views/base/priceTrigger/desktop/DesktopPriceTriggerView.vue new file mode 100644 index 0000000..06eaaab --- /dev/null +++ b/src/views/base/priceTrigger/desktop/DesktopPriceTriggerView.vue @@ -0,0 +1,78 @@ + + + diff --git a/src/views/base/priceTrigger/desktop/styles/desktop-price-trigger.less b/src/views/base/priceTrigger/desktop/styles/desktop-price-trigger.less new file mode 100644 index 0000000..3faf1a5 --- /dev/null +++ b/src/views/base/priceTrigger/desktop/styles/desktop-price-trigger.less @@ -0,0 +1,273 @@ +/* Premium desktop price trigger page */ + +.dptr { + min-height: 100%; + background: #f6f7f9; + color: #111827; +} + +.dptr__container { + max-width: 1180px; + margin: 0 auto; + padding: 28px 36px 40px; +} + +.dptr-topbar { + margin-bottom: 24px; + padding-bottom: 24px; + border-bottom: 1px solid rgba(15, 23, 42, 0.06); + + &__eyebrow { + font-size: 12px; + font-weight: 500; + color: #9ca3af; + margin: 0 0 4px; + } + + &__title { + font-size: 26px; + font-weight: 600; + letter-spacing: -0.03em; + color: #111827; + margin: 0 0 6px; + line-height: 1.2; + } + + &__subtitle { + font-size: 14px; + color: #6b7280; + margin: 0; + max-width: 520px; + line-height: 1.6; + } +} + +.dptr-grid { + display: grid; + grid-template-columns: minmax(0, 380px) minmax(0, 1fr); + gap: 20px; + align-items: start; +} + +.dptr-surface { + background: #fff; + border: 1px solid rgba(15, 23, 42, 0.06); + border-radius: 16px; + box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); +} + +.dptr-form { + padding: 24px; + + &__header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + margin-bottom: 20px; + } + + &__title { + font-size: 16px; + font-weight: 600; + color: #111827; + margin: 0; + } + + &__reset { + border: 1px solid #e5e7eb; + border-radius: 8px; + background: #fff; + color: #6b7280; + font-size: 12px; + font-weight: 600; + font-family: inherit; + padding: 6px 10px; + cursor: pointer; + transition: border-color 0.15s ease, color 0.15s ease; + + &:hover { + border-color: @App-primary-color; + color: @App-primary-color; + } + } +} + +.dptr-list { + display: flex; + flex-direction: column; + min-height: 420px; + + &__header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + padding: 20px 24px 0; + } + + &__title { + font-size: 16px; + font-weight: 600; + color: #111827; + margin: 0; + } + + &__count { + font-size: 12px; + font-weight: 600; + color: #6b7280; + background: #f3f4f6; + border-radius: 999px; + padding: 4px 10px; + } + + &__items { + padding: 16px 24px 24px; + display: flex; + flex-direction: column; + gap: 10px; + } + + &__skeletons { + padding: 16px 24px 24px; + } +} + +.dptr-card { + display: grid; + grid-template-columns: minmax(0, 1fr) auto; + gap: 12px 16px; + padding: 16px 18px; + border: 1px solid #eef0f3; + border-radius: 12px; + background: #fafbfc; + transition: border-color 0.15s ease, box-shadow 0.15s ease; + + &:hover { + border-color: #dbe0e6; + box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04); + } + + &__price { + grid-column: 1 / -1; + font-size: 18px; + font-weight: 700; + color: #111827; + margin: 0; + } + + &__meta { + display: flex; + flex-direction: column; + gap: 6px; + min-width: 0; + } + + &__row { + display: flex; + align-items: center; + gap: 8px; + font-size: 13px; + color: #6b7280; + } + + &__label { + color: #9ca3af; + flex-shrink: 0; + } + + &__value { + color: #374151; + font-weight: 600; + } + + &__actions { + display: flex; + align-items: flex-start; + gap: 4px; + } + + &__icon-btn { + display: inline-flex; + align-items: center; + justify-content: center; + width: 34px; + height: 34px; + border: 1px solid #e5e7eb; + border-radius: 10px; + background: #fff; + cursor: pointer; + transition: border-color 0.15s ease, background 0.15s ease; + + &:hover { + background: #f9fafb; + } + + &--danger:hover { + border-color: #fecaca; + background: #fef2f2; + } + + &--edit:hover { + border-color: #bbf7d0; + background: #f0fdf4; + } + } + + &__footer { + grid-column: 1 / -1; + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + padding-top: 10px; + border-top: 1px solid #eef0f3; + } + + &__date { + font-size: 12px; + color: #9ca3af; + } +} + +.dptr-empty { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 12px; + padding: 48px 24px; + color: #6b7280; + text-align: center; + + p { + margin: 0; + font-size: 14px; + } + + &__btn { + margin-top: 4px; + border: none; + border-radius: 10px; + background: @App-primary-color; + color: #fff; + font-size: 13px; + font-weight: 600; + font-family: inherit; + padding: 10px 16px; + cursor: pointer; + transition: opacity 0.15s ease; + + &:hover { + opacity: 0.92; + } + } +} + +@media (max-width: 1023.98px) { + .dptr-grid { + grid-template-columns: 1fr; + } +} diff --git a/src/views/base/priceTrigger/mobile/MobilePriceTriggerView.vue b/src/views/base/priceTrigger/mobile/MobilePriceTriggerView.vue new file mode 100644 index 0000000..9bc20ff --- /dev/null +++ b/src/views/base/priceTrigger/mobile/MobilePriceTriggerView.vue @@ -0,0 +1,52 @@ + + + diff --git a/src/views/base/products/mobile/MobileProductsView.vue b/src/views/base/products/mobile/MobileProductsView.vue new file mode 100644 index 0000000..af3f8d5 --- /dev/null +++ b/src/views/base/products/mobile/MobileProductsView.vue @@ -0,0 +1,153 @@ + + + + + + +