Split desktop and mobile layouts with shared page data so APIs fetch once per context.

Add layout shells, desktop views, module-level page caches, and UI fixes for auth, home, wallet, transactions, address, and related pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-14 10:08:46 +03:30
co-authored by Cursor
parent 4404b4cb92
commit a5e458ed25
234 changed files with 18425 additions and 5503 deletions
@@ -0,0 +1,101 @@
<template>
<a-form
ref="formRef"
:model="address"
:class="variant === 'desktop' ? 'daddr-form' : '!mt-5'"
name="address-form"
>
<div :class="variant === 'desktop' ? 'daddr-form__fields' : 'flex flex-col items-center'">
<div
v-if="variant !== 'desktop'"
class="font-bold text-lg mb-2"
>
آدرس
</div>
<div
:class="variant === 'desktop'
? 'daddr-form__grid'
: 'flex flex-col gap-4 pb-20 w-full h-60vh overflow-y-scroll'"
>
<a-form-item label="استان" name="province" :rules="[required()]">
<BasicSelect
v-model:value="address.province"
:items="provinceList"
value-name="title"
key-name="title"
:size="variant === 'desktop' ? 'large' : undefined"
@change="changeProvince"
/>
</a-form-item>
<a-form-item label="شهر" name="city" :rules="[required()]">
<BasicSelect
v-model:value="address.city"
:disabled="!cityList"
value-name="title"
:items="cityList"
key-name="title"
:size="variant === 'desktop' ? 'large' : undefined"
/>
</a-form-item>
<a-form-item label="کد پستی" name="zip" :rules="[required()]">
<BasicInput
v-model:value="address.zip"
placeholder="کد پستی را وارد نمایید"
:size="variant === 'desktop' ? 'large' : undefined"
/>
</a-form-item>
<a-form-item label="تلفن تماس" name="phone" :rules="[required()]">
<BasicInput
v-model:value="address.phone"
placeholder="تلفن تماس را وارد نمایید"
:size="variant === 'desktop' ? 'large' : undefined"
/>
</a-form-item>
<a-form-item
label="آدرس کامل"
name="address"
:rules="[required()]"
:class="variant === 'desktop' ? 'daddr-form__address-item' : ''"
>
<BasicTextArea
v-model:value="address.address"
placeholder="آدرس کامل را وارد نمایید"
/>
</a-form-item>
<BasicButton
:class="variant === 'desktop' ? 'daddr-form__submit' : '!text-white px-3 pb-4rem'"
type="primary"
@click="handleOk"
>
{{ editId ? 'ویرایش آدرس' : 'ثبت آدرس' }}
</BasicButton>
</div>
</div>
</a-form>
</template>
<script lang="ts" setup>
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
import BasicTextArea from '@/components/BasicPacks/BasicTextArea.vue'
import { required } from '@/utils/inputRules'
import { useAddressPageContext } from '../composables/useAddressPage'
withDefaults(
defineProps<{
variant?: 'mobile' | 'desktop'
}>(),
{ variant: 'mobile' },
)
const {
address,
formRef,
editId,
provinceList,
cityList,
changeProvince,
handleOk,
} = useAddressPageContext()
</script>
@@ -0,0 +1,94 @@
<template>
<div class="address-mobile-item shadow mb-2 p-2 rounded-lg w-full">
<div class="flex justify-between">
<div>
<div class="font-semibold text-base mb-2">{{ item.address }}</div>
</div>
</div>
<div class="flex flex-col gap-2 mt-2">
<BasicInfoItem is-line title="استان" :value="item.province" />
<BasicInfoItem is-line title="شهر" :value="item.city" />
<BasicInfoItem is-line title="کد پستی" :value="item.zip" />
<BasicInfoItem is-line title="شماره تلفن" :value="item.phone" />
</div>
<a-divider class="!my-3" />
<div class="flex justify-between mt-1">
<div class="mb-2">{{ formatAddressDate(item.created_at) }}</div>
<div class="flex gap-2">
<BasicIcon
color="red"
icon="vuesax-linear:trash"
class="p-1"
@click.stop="deleteConfirmVisible = true"
/>
<BasicIcon
color="green"
icon="vuesax-linear:edit"
class="p-1"
@click.stop="emits('edit', item)"
/>
</div>
</div>
<DialogVant
v-model:show="deleteConfirmVisible"
teleport="body"
:close-on-click-overlay="false"
:time-out="-1"
>
<template #title>
<div class="flex flex-col items-center">
<div class="p-5 text-sm">آیا از حذف آدرس اطمینان دارید؟</div>
</div>
</template>
<template #button>
<div class="text-center text-red flex items-center justify-center" @click="deleteItem">
<a-spin :spinning="deleteLoading" size="small">تایید</a-spin>
</div>
<div class="text-center" @click="deleteConfirmVisible = false">انصراف</div>
</template>
</DialogVant>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { toJalali } from '@/utils/useDateTime'
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import BasicInfoItem from '@/components/BasicPacks/BasicInfoItem.vue'
import DialogVant from '@/components/DialogVant.vue'
import type { Address } from '@/models/address'
import { deleteAddress } from '@/api/address'
const deleteLoading = ref(false)
const deleteConfirmVisible = ref(false)
const props = defineProps<{
item: Address
}>()
const emits = defineEmits<{
edit: [item: Address]
refresh: []
}>()
function formatAddressDate(dateTime?: string) {
if (!dateTime) return ''
const formatted = toJalali(dateTime)
return formatted.includes('Invalid') ? '' : formatted
}
async function deleteItem() {
try {
deleteLoading.value = true
await deleteAddress(props.item.id!)
deleteConfirmVisible.value = false
emits('refresh')
} catch (e) {
console.log(e)
} finally {
deleteLoading.value = false
}
}
</script>
+113 -108
View File
@@ -1,112 +1,155 @@
<template>
<div @click="infoVisible = true" class="shadow mb-2 p-2 rounded-lg">
<div v-if="variant === 'desktop'" class="daddr-card">
<p class="daddr-card__address">{{ item.address }}</p>
<div class="daddr-card__meta">
<div class="daddr-card__row">
<span class="daddr-card__label">استان:</span>
<span class="daddr-card__value">{{ item.province }}</span>
</div>
<div class="daddr-card__row">
<span class="daddr-card__label">شهر:</span>
<span class="daddr-card__value">{{ item.city }}</span>
</div>
<div class="daddr-card__row">
<span class="daddr-card__label">کد پستی:</span>
<span class="daddr-card__value">{{ item.zip }}</span>
</div>
<div class="daddr-card__row">
<span class="daddr-card__label">شماره تلفن:</span>
<span class="daddr-card__value">{{ item.phone }}</span>
</div>
</div>
<div class="daddr-card__actions">
<button
type="button"
class="daddr-card__icon-btn daddr-card__icon-btn--edit"
@click.stop="emits('edit', item)"
>
<BasicIcon color="green" icon="vuesax-linear:edit" size="18" />
</button>
<button
type="button"
class="daddr-card__icon-btn daddr-card__icon-btn--danger"
@click.stop="deleteConfirmVisible = true"
>
<BasicIcon color="red" icon="vuesax-linear:trash" size="18" />
</button>
</div>
<div class="daddr-card__footer">
<span class="daddr-card__date">{{ formatAddressDate(item.created_at) }}</span>
</div>
<DialogVant
v-model:show="deleteConfirmVisible"
:close-on-click-overlay="false"
:time-out="-1"
teleport="body"
>
<template #title>
<div class="flex flex-col items-center">
<div class="p-5 text-sm">آیا از حذف آدرس اطمینان دارید؟</div>
</div>
</template>
<template #button>
<div class="text-center text-red flex items-center justify-center" @click="deleteItem">
<a-spin :spinning="deleteLoading" size="small">تایید</a-spin>
</div>
<div class="text-center" @click="deleteConfirmVisible = false">انصراف</div>
</template>
</DialogVant>
</div>
<div v-else class="shadow mb-2 p-2 rounded-lg">
<div class="flex justify-between">
<div>
<div class="font-semibold text-base mb-2">{{item.address }}</div>
<div class="font-semibold text-base mb-2">{{ item.address }}</div>
</div>
</div>
<div class="flex flex-col gap-2 mt-2">
<BasicInfoItem is-line title="استان" :value="item.province"/>
<BasicInfoItem is-line title="شهر" :value="item.city"/>
<BasicInfoItem is-line title="کد پستی" :value="item.zip"/>
<BasicInfoItem is-line title="شماره تلفن" :value="item.phone"/>
<BasicInfoItem is-line title="استان" :value="item.province" />
<BasicInfoItem is-line title="شهر" :value="item.city" />
<BasicInfoItem is-line title="کد پستی" :value="item.zip" />
<BasicInfoItem is-line title="شماره تلفن" :value="item.phone" />
</div>
<a-divider class="!my-3" />
<div class="flex justify-between mt-1">
<div class="mb-2">{{toJalali(item.created_at)}}</div>
<div class="flex gap-2 ">
<BasicIcon color="red" icon="vuesax-linear:trash" @click.stop="deleteConfirmVisible = true" class="p-1"/>
<BasicIcon color="green" icon="vuesax-linear:edit" @click.stop="emits('edit',item)" class="p-1"/>
<div class="mb-2">{{ formatAddressDate(item.created_at) }}</div>
<div class="flex gap-2">
<BasicIcon
color="red"
icon="vuesax-linear:trash"
class="p-1"
@click.stop="deleteConfirmVisible = true"
/>
<BasicIcon
color="green"
icon="vuesax-linear:edit"
class="p-1"
@click.stop="emits('edit', item)"
/>
</div>
</div>
</div>
<!-- <teleport to="app">-->
<DialogVant v-model:show="deleteConfirmVisible" teleport="body" :closeOnClickOverlay="false" :timeOut="-1">
<!-- <template v-slot:img>
<img :src="registerDelayImage" alt="" class="opacity-80">
</template>-->
<template v-slot:title>
<DialogVant
v-model:show="deleteConfirmVisible"
teleport="body"
:close-on-click-overlay="false"
:time-out="-1"
>
<template #title>
<div class="flex flex-col items-center">
<div class="p-5 text-sm">
آیا از حذف آدرس اطمینان دارید؟
</div>
<div class="p-5 text-sm">آیا از حذف آدرس اطمینان دارید؟</div>
</div>
</template>
<template v-slot:button>
<template #button>
<div class="text-center text-red flex items-center justify-center" @click="deleteItem">
<a-spin :spinning="deleteLoading" size="small">
تایید
</a-spin>
</div>
<div class="text-center" @click="deleteConfirmVisible = false">
انصراف
<a-spin :spinning="deleteLoading" size="small">تایید</a-spin>
</div>
<div class="text-center" @click="deleteConfirmVisible = false">انصراف</div>
</template>
</DialogVant>
<!-- </teleport>-->
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'
import { toJalali } from '../../../../utils/useDateTime'
import { ref } from 'vue'
import { toJalali } from '@/utils/useDateTime'
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import BasicInfoItem from '@/components/BasicPacks/BasicInfoItem.vue'
import DialogVant from '@/components/DialogVant.vue'
import { updatePriceTrigger } from '@/api/triggerPrice'
import { loading } from '@/utils'
import type { Address } from '@/models/address'
import { deleteAddress } from '@/api/address'
const infoVisible = ref<boolean>(false)
const isActive = ref<boolean>(false)
const deleteLoading = ref(false)
const deleteConfirmVisible = ref(false)
interface Prop {
item: Address
}
function changeActive(val: boolean) {
console.log(val)
try {
loading.value = true
updatePriceTrigger(props?.item.id, {is_active: val})
} catch (e) {
console.log(e)
isActive.value = !isActive.value
} finally {
loading.value = false
}
}
const props = withDefaults(
defineProps<{
item: Address
variant?: 'mobile' | 'desktop'
}>(),
{ variant: 'mobile' },
)
function returnPriceCondition(val: string) {
switch (val) {
case '==': return 'مساوی'
case '<': return 'کوچکتر'
// case '==': return 'مساوی'
}
/* if (val === '=='){
return 'مساوی'
} else if (val === '<'){
return 'کوچکتر'
}*/
const emits = defineEmits<{
edit: [item: Address]
refresh: []
}>()
function formatAddressDate(dateTime?: string) {
if (!dateTime) return ''
const formatted = toJalali(dateTime)
return formatted.includes('Invalid') ? '' : formatted
}
async function deleteItem() {
try {
deleteLoading.value = true
await deleteAddress(props.item.id)
await deleteAddress(props.item.id!)
deleteConfirmVisible.value = false
emits('refresh')
} catch (e) {
@@ -115,42 +158,4 @@ async function deleteItem() {
deleteLoading.value = false
}
}
function returnAction(val: string) {
switch (val) {
case 'sms': return 'پیامک'
case 'email': return 'ایمیل'
case 'notify': return 'نوتیفیکیشن'
// case '==': return 'مساوی'
}
/* if (val === '=='){
return 'مساوی'
} else if (val === '<'){
return 'کوچکتر'
}*/
}
const props = withDefaults(defineProps<Prop>(), {})
const emits = defineEmits(['edit','refresh'])
/*const title = computed(() => {
if (isUp.value) {
if (isGold.value) {
return 'واریز ریالی'
} else {
return 'خرید طلا'
}
} else {
if (isGold.value) {
return 'برداشت ریالی'
} else {
return 'فروش طلا'
}
}
})*/
</script>
<style scoped>
</style>
@@ -0,0 +1,145 @@
import { inject, onMounted, provide, ref, type InjectionKey, type Ref } from 'vue'
import { cloneDeep } from 'lodash'
import { type FormInstance, message } from 'ant-design-vue'
import { createAddress, getCity, updateAddress } from '@/api/address'
import type { Address } from '@/models/address'
import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
import { loading, loadingMore } from '@/utils'
import { isBazretalaProject } from '@/utils/config'
import {
addressItems,
addressProvinceList,
initAddressPageData,
refreshAddressItems,
} from './useAddressPageData'
export interface AddressPageContext {
provinceList: typeof addressProvinceList
cityList: Ref<any[] | undefined>
items: typeof addressItems
addAddressVisible: Ref<boolean>
editId: Ref<number | undefined>
address: Ref<Address>
formRef: Ref<FormInstance | undefined>
loading: typeof loading
loadingMore: typeof loadingMore
isBazretalaProject: typeof isBazretalaProject
resetFields: () => void
openAdd: () => void
openEdit: (val: Address) => void
handleOk: (e?: MouseEvent) => void
initItems: () => Promise<void>
changeProvince: (obj: { id: number }) => Promise<void>
}
export const ADDRESS_PAGE_CONTEXT_KEY: InjectionKey<AddressPageContext> =
Symbol('addressPageContext')
const emptyAddress = (): Address => ({
city: '',
province: '',
phone: '',
address: '',
zip: '',
default_address: false,
})
export function useAddressPage() {
const isDesktop = useDesktopBreakpoint()
const cityList = ref<any[]>()
const addAddressVisible = ref(false)
const editId = ref<number | undefined>(undefined)
const formRef = ref<FormInstance>()
const address = ref<Address>(emptyAddress())
function resetFields() {
editId.value = undefined
address.value = emptyAddress()
cityList.value = undefined
}
function openAdd() {
resetFields()
editId.value = undefined
addAddressVisible.value = !isDesktop.value
}
async function openEdit(val: Address) {
address.value = cloneDeep(val)
editId.value = address.value.id
if (address.value.province) {
const province = addressProvinceList.value.find((item) => item.title === address.value.province)
if (province?.id) {
cityList.value = await getCity(province.id)
}
}
addAddressVisible.value = true
}
const handleOk = (_e?: MouseEvent) => {
formRef.value?.validate().then(async () => {
if (editId.value) {
await updateAddress(editId.value, address.value)
} else {
await createAddress(address.value)
}
await initItems()
addAddressVisible.value = false
message.success('آدرس با موفقیت ثبت شد')
resetFields()
}).catch((error) => {
console.log('error', error)
})
}
async function initItems() {
await refreshAddressItems()
}
const changeProvince = async (obj: { id: number }) => {
try {
loading.value = true
cityList.value = undefined
address.value.city = undefined
cityList.value = await getCity(obj.id)
} catch (e) {
message.error('خطا در دریافت شهرها')
} finally {
loading.value = false
}
}
onMounted(async () => {
await initAddressPageData()
})
const context: AddressPageContext = {
provinceList: addressProvinceList,
cityList,
items: addressItems,
addAddressVisible,
editId,
address,
formRef,
loading,
loadingMore,
isBazretalaProject,
resetFields,
openAdd,
openEdit,
handleOk,
initItems,
changeProvince,
}
provide(ADDRESS_PAGE_CONTEXT_KEY, context)
return context
}
export function useAddressPageContext() {
const context = inject(ADDRESS_PAGE_CONTEXT_KEY)
if (!context) {
throw new Error('useAddressPageContext must be used within a page that calls useAddressPage()')
}
return context
}
@@ -0,0 +1,82 @@
import { ref } from 'vue'
import { getProvince, tableAddress } from '@/api/address'
import type { Address } from '@/models/address'
import { loading, loadingMore } from '@/utils'
import { runOnceAsync, resetOnceAsyncByPrefix } from '@/composables/useOnceAsync'
/**
* Shared address page datasets — mobile and desktop views read this module state only.
*/
let initPromise: Promise<void> | null = null
const initialized = ref(false)
export const addressItems = ref<Address[]>([])
export const addressProvinceList = ref<any[]>([])
export function isAddressPageDataInitialized() {
return initialized.value
}
export async function refreshAddressItems() {
try {
loading.value = true
const data = await tableAddress({ page: 0, limit: 150 })
addressItems.value = data.rows
} catch (error) {
console.error('Address list refresh error:', error)
} finally {
loading.value = false
loadingMore.value = false
}
}
async function loadAddressItems() {
const data = await tableAddress({ page: 0, limit: 150 })
addressItems.value = data.rows
}
async function loadProvinces() {
addressProvinceList.value = await getProvince()
}
export async function initAddressPageData(force = false) {
if (!force && initialized.value) {
return
}
if (!force && initPromise) {
return initPromise
}
initPromise = (async () => {
try {
if (force) {
resetAddressPageData()
}
loading.value = true
await Promise.all([
runOnceAsync('address:items', () => loadAddressItems(), force),
runOnceAsync('address:provinces', () => loadProvinces(), force),
])
initialized.value = true
} catch (error) {
console.error('Address page initialization error:', error)
} finally {
loading.value = false
initPromise = null
}
})()
return initPromise
}
export function resetAddressPageData() {
initialized.value = false
initPromise = null
resetOnceAsyncByPrefix('address:')
addressItems.value = []
addressProvinceList.value = []
}
@@ -0,0 +1,86 @@
<template>
<div class="daddr">
<div class="daddr__container">
<header class="daddr-topbar">
<p class="daddr-topbar__eyebrow">حساب کاربری</p>
<h1 class="daddr-topbar__title">آدرس‌ها</h1>
<p class="daddr-topbar__subtitle">آدرس‌های تحویل سفارش خود را مدیریت کنید</p>
</header>
<div
v-if="isBazretalaProject()"
class="daddr-notice"
>
جهت تحویل فیزیکی محصول در تهران و قم ازطریق معرف اقدام فرمائید یا با شماره امورمالی و حسابداری 09925202099 درارتباط باشید.
</div>
<div class="daddr-grid">
<section class="daddr-surface daddr-form">
<div class="daddr-form__header">
<h2 class="daddr-form__title">{{ editId ? 'ویرایش آدرس' : 'ثبت آدرس جدید' }}</h2>
<button
v-if="editId"
type="button"
class="daddr-form__reset"
@click="openAdd()"
>
آدرس جدید
</button>
</div>
<AddressForm variant="desktop" />
</section>
<section class="daddr-surface daddr-list">
<div class="daddr-list__header">
<h3 class="daddr-list__title">آدرس‌های ثبت‌شده</h3>
<span class="daddr-list__count">{{ items.length }} مورد</span>
</div>
<div v-if="loading" class="daddr-list__skeletons">
<TransactionSkeleton v-for="i in 6" :key="i" class="mt-1" />
</div>
<div v-else-if="items.length" class="daddr-list__items">
<list-anim>
<Item
v-for="item in items"
:key="`desktop-${item.id}`"
:item="item"
variant="desktop"
@edit="openEdit"
@refresh="initItems"
/>
</list-anim>
</div>
<div v-else class="daddr-empty">
<BasicIcon icon="vuesax-linear:location" size="36" />
<p>هنوز آدرسی ثبت نشده است.</p>
<button type="button" class="daddr-empty__btn" @click="openAdd()">
افزودن اولین آدرس
</button>
</div>
</section>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import ListAnim from '@/components/ListAnim.vue'
import TransactionSkeleton from '@/components/TransactionSkeleton.vue'
import AddressForm from '../components/AddressForm.vue'
import Item from '../components/Item.vue'
import { useAddressPageContext } from '../composables/useAddressPage'
const {
items,
loading,
editId,
isBazretalaProject,
openAdd,
openEdit,
initItems,
} = useAddressPageContext()
</script>
@@ -0,0 +1,307 @@
/* Premium desktop address page — scoped to desktop shell only */
html.app-layout--desktop {
.daddr {
min-height: 100%;
background: #f6f7f9;
color: #111827;
}
.daddr__container {
max-width: 1180px;
margin: 0 auto;
padding: 28px 36px 40px;
}
.daddr-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;
}
}
.daddr-notice {
margin-bottom: 20px;
padding: 14px 16px;
border-radius: 12px;
border: 1px solid rgba(59, 130, 246, 0.15);
background: rgba(59, 130, 246, 0.06);
color: @App-primary-color;
font-size: 13px;
line-height: 1.8;
text-align: justify;
}
.daddr-grid {
display: grid;
grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
gap: 20px;
align-items: start;
}
.daddr-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);
}
.daddr-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;
}
}
&__fields {
width: 100%;
}
&__grid {
display: flex;
flex-direction: column;
gap: 4px;
}
&__address-item {
margin-bottom: 8px !important;
}
&__submit {
width: 100%;
margin-top: 8px;
}
}
.daddr-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;
}
}
.daddr-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);
}
&__address {
grid-column: 1 / -1;
font-size: 16px;
font-weight: 700;
color: #111827;
margin: 0;
line-height: 1.5;
}
&__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;
}
}
.daddr-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) {
.daddr-grid {
grid-template-columns: 1fr;
}
}
}
+29 -246
View File
@@ -1,257 +1,40 @@
<template>
<div>
<div class="bg-white py-3 px-3 text-primary font-bold drop-shadow wrap-fix flex z-10">
<div @click="router.back()">
<BasicIcon icon="vuesax-linear:arrow-right-1" />
</div>
<div class="mr-2">آدرس ها</div>
</div>
<div>
<img :src="img" alt="" class="mt-2 w-full absolute bottom-0" />
</div>
<!-- <a-spin :spinning="loading">-->
<div ref="el" :class="loading? 'h-screen': ''" class="px-3 pt-16 pb-2 overflow-y-scroll"
style="max-height: calc(100vh - 50px)">
<div
v-if="isBazretalaProject()"
class="text-justify text-sm text-primary mb-4 px-1 leading-7"
>
جهت تحویل فیزیکی محصول در تهران و قم ازطریق معرف اقدام فرمائید یا با شماره امورمالی و حسابداری 09925202099 درارتباط باشید.
</div>
<list-anim v-if="!loading" class="pb-[calc(var(--app-bottom-chrome-height)+var(--app-add-card-height)+1rem)]">
<Item v-for="item in items" :key="item.id" :item="item" @edit="openEdit" @refresh="initItems" />
<!-- <TransactionSkeleton v-if="loadingMore" class="mt-1 mb-8" />-->
</list-anim>
<div v-if="loading">
<TransactionSkeleton v-for="i in 13" :key="i" class="mt-1" />
</div>
</div>
<!-- </a-spin>-->
<BasicActionSheet v-model:show="addAddressVisible" class="h-80vh" >
<a-form ref="formRef" :model="address" class="!mt-5" name="basic"
@finish="ok()">
<div class="flex flex-col items-center">
<div class="font-bold text-lg mb-2">آدرس</div>
<div class="flex flex-col gap-4 pb-20 w-full h-60vh overflow-y-scroll">
<a-form-item label="استان" name="province" :rules="[required()]">
<BasicSelect
v-model:value="address.province"
:items="provinceList"
@change="changeProvince"
valueName="title"
keyName="title"
/>
</a-form-item>
<a-form-item label="شهر" name="city" :rules="[required()]">
<BasicSelect
:disabled="!cityList"
v-model:value="address.city"
valueName="title"
:items="cityList"
keyName="title"
/>
</a-form-item>
<a-form-item
label="کد پستی" name="zip" :rules="[required()]">
<BasicInput placeholder="کد پستی را وارد نمایید" v-model:value="address.zip" />
</a-form-item>
<a-form-item
label="تلفن تماس" name="phone" :rules="[required()]"
>
<BasicInput placeholder="تلفن تماس را وارد نمایید" v-model:value="address.phone" />
</a-form-item>
<!-- <FormItem label="کد پستی" name="">
<Input placeholder="کد پستی را وارد نمایید" />
</FormItem>-->
<a-form-item
label="آدرس کامل"
name="address"
:rules="[required()]"
>
<BasicTextArea placeholder="آدرس کامل را وارد نمایید" v-model:value="address.address" />
</a-form-item>
<!-- <div class=" w-full pb-5 !text-white flex justify-center items-center">-->
<BasicButton class=" !text-white px-3 pb-4rem" type="primary" @click="handleOk">ثبت آدرس
</BasicButton>
</div>
<!-- </div>-->
</div>
</a-form>
<div v-if="!isDesktop">
<MobileAddressView />
<BasicActionSheet v-model:show="addAddressVisible" class="h-80vh">
<AddressForm />
</BasicActionSheet>
<!-- <div class="bg-primary w-3rem h-3rem flex items-center justify-center rounded-lg fixed bottom-12vh left-8vw"
@click="openAdd()">
<BasicIcon icon="vuesax-linear:add" color="white" />
</div>-->
<Teleport to="body">
<div
v-if="!addAddressVisible"
class="add-address app-dock-add-bar"
@click="openAdd()"
>
<div>افزودن آدرس جدید</div>
<BasicIcon icon="vuesax-linear:add" />
</div>
</Teleport>
</div>
<template v-else>
<DesktopAddressView />
<BasicModal
v-model:visible="addAddressVisible"
:title="editId ? 'ویرایش آدرس' : 'ثبت آدرس جدید'"
width="520px"
destroy-on-close
custom-footer
>
<AddressForm variant="desktop" />
<template #footer>
<div></div>
</template>
</BasicModal>
</template>
</template>
<script lang="ts" setup>
import { createPriceTrigger, getPriceTriggers, updatePriceTrigger } from '@/api/triggerPrice'
const radioStyle = reactive({
display: '',
height: '30px',
lineHeight: '30px'
})
import type { SelectItem } from '@/models/SelectItem'
// import Item from "./components/Item.vue";
/*import {lengthValidation, required} from "@/utils/inputRules";
import {loading} from "@/utils";
import BasicButton from "@/components/BasicPacks/BasicButton.vue";
import BasicActionSheet from "@/components/BasicPacks/BasicActionSheet.vue";
import BasicInput from "@/components/BasicPacks/BasicInput.vue";*/
import { onMounted, reactive, ref } from 'vue'
import type { TableEngineInput, TableOutput } from '@/models/table'
import { loading, loadingMore } from '@/utils'
// import {getOrders} from "@/api/order";
import { getTransactionTable } from '@/api/transaction'
import type { Transaction } from '@/models/transaction'
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
import BaseDatePicker from '@/components/BasicPacks/BaseDatePicker/src/BaseDatePicker.vue'
import { useInfiniteScroll, useScroll } from '@vueuse/core'
import ListAnim from '@/components/ListAnim.vue'
import TransactionSkeleton from '@/components/TransactionSkeleton.vue'
import { DotLottieVue } from '@lottiefiles/dotlottie-vue'
import { mobileValidation, required } from '@/utils/inputRules'
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
import type { User } from '@/models/login'
import { type FormInstance, message } from 'ant-design-vue'
import type { PriceTrigger } from '@/models/PriceTrigger'
import BasicSelect from '@/components/BasicPacks/BasicSelect.vue'
import Item from './components/Item.vue'
import { cloneDeep } from 'lodash'
import router from '@/router'
import type { Address } from '@/models/address'
import { createAddress, getCity, getProvince, tableAddress, updateAddress } from '@/api/address'
import BasicTextArea from '@/components/BasicPacks/BasicTextArea.vue'
import img from "@/assets/img/user_ly1.svg";
import { isBazretalaProject } from '@/utils/config'
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
import { useAddressPage } from './composables/useAddressPage'
import AddressForm from './components/AddressForm.vue'
import DesktopAddressView from './desktop/DesktopAddressView.vue'
import MobileAddressView from './mobile/MobileAddressView.vue'
const provinceList = ref<any[]>([])
const cityList = ref<any[]>()
const items = ref<PriceTrigger[]>([])
const addAddressVisible = ref<boolean>(false)
const editId = ref<number | undefined>(undefined)
const el = ref()
const address = ref<Address>({
city: '',
province: '',
phone: '',
address: '',
zip: '',
default_address: false
})
const formRef = ref<FormInstance>()
onMounted(async () => {
await initItems()
provinceList.value = await getProvince()
})
function resetFields() {
editId.value = undefined
address.value = {
city: '',
province: '',
phone: '',
address: '',
zip: '',
default_address: false
}
}
function openAdd() {
resetFields()
editId.value = undefined
addAddressVisible.value = true
}
const handleOk = (e: MouseEvent) => {
formRef.value?.validate().then(async () => {
editId.value ? await updateAddress(editId.value, address.value) : await createAddress(address.value)
await initItems()
addAddressVisible.value = false
message.success('آدرس با موفقیت ثبت شد')
resetFields()
})
.catch((error) => {
console.log('error', error)
})
}
async function initItems() {
try {
items.value = []
const data = await tableAddress({ page: 0, limit: 150 })
items.value = data.rows
// console.log(items.value)
} catch (e) {
console.log(e)
} finally {
loading.value = false
loadingMore.value = false
}
}
const changeProvince = async (obj: any) => {
try {
loading.value = true
cityList.value = undefined
address.value.city = undefined
cityList.value = await getCity(obj.id)
} catch (e) {
message.error('خطا در دریافت شهرها')
} finally {
loading.value = false
}
}
function openEdit(val: PriceTrigger) {
address.value = cloneDeep(val)
editId.value = address.value.id
addAddressVisible.value = true
}
async function ok() {
formRef.value?.validateFields().then(async () => {
try {
loading.value = true
editId.value ? await updatePriceTrigger(editId.value, address.value) : await createPriceTrigger(address.value)
message.success('آدرس با موفقیت ایجاد شد')
await initItems()
addAddressVisible.value = false
//
} catch (e) {
console.log(e)
} finally {
loading.value = false
}
})
}
const isDesktop = useDesktopBreakpoint()
const { addAddressVisible, editId } = useAddressPage()
</script>
<style scoped>
</style>
@@ -0,0 +1,72 @@
<template>
<div>
<div class="bg-white py-3 px-3 text-primary font-bold drop-shadow wrap-fix flex z-10">
<div @click="router.back()">
<BasicIcon icon="vuesax-linear:arrow-right-1" />
</div>
<div class="mr-2">آدرس ها</div>
</div>
<div>
<img :src="img" alt="" class="mt-2 w-full absolute bottom-0" />
</div>
<div
:class="loading ? 'h-screen' : ''"
class="px-3 pt-16 pb-2 overflow-y-scroll"
style="max-height: calc(100vh - 50px)"
>
<div
v-if="isBazretalaProject()"
class="text-justify text-sm text-primary mb-4 px-1 leading-7"
>
جهت تحویل فیزیکی محصول در تهران و قم ازطریق معرف اقدام فرمائید یا با شماره امورمالی و حسابداری 09925202099 درارتباط باشید.
</div>
<div
v-if="!loading"
class="pb-[calc(var(--app-bottom-chrome-height)+var(--app-add-card-height)+1rem)]"
>
<Item
v-for="item in items"
:key="item.id"
:item="item"
@edit="openEdit"
@refresh="initItems"
/>
</div>
<div v-if="loading">
<TransactionSkeleton v-for="i in 13" :key="i" class="mt-1" />
</div>
</div>
<Teleport to="body">
<div
v-if="!addAddressVisible"
class="add-address app-dock-add-bar"
@click="openAdd()"
>
<div>افزودن آدرس جدید</div>
<BasicIcon icon="vuesax-linear:add" />
</div>
</Teleport>
</div>
</template>
<script lang="ts" setup>
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import TransactionSkeleton from '@/components/TransactionSkeleton.vue'
import img from '@/assets/img/user_ly1.svg'
import router from '@/router'
import Item from '../components/Item.vue'
import { useAddressPageContext } from '../composables/useAddressPage'
const {
items,
loading,
addAddressVisible,
isBazretalaProject,
openAdd,
openEdit,
initItems,
} = useAddressPageContext()
</script>