feat(ui): desktop piggy/notifications views, support chat fixes, gift card list

This commit is contained in:
2026-09-09 16:57:41 +03:30
parent 5920866a95
commit 0a3a5d7c82
50 changed files with 3242 additions and 1094 deletions
@@ -0,0 +1,118 @@
<template>
<div class="flex flex-col gap-3 mt-4" :class="variant === 'desktop' ? 'dgift-lists' : ''">
<a-spin :spinning="listLoading">
<section class="border border-gray-200 rounded-xl p-3 bg-white">
<h3 class="text-sm font-bold m-0 mb-1">کدهای قابل استفاده</h3>
<p class="text-xs text-gray-500 m-0 mb-2.5">
کارت‌های اختصاصی شما و کدهای عمومی فعال. برای ثبت سریع روی کد بزنید.
</p>
<div v-if="available.length" class="flex flex-col gap-2">
<button
v-for="item in available"
:key="`a-${item.id}`"
type="button"
class="w-full text-right border border-gray-100 rounded-lg p-2.5 bg-gray-50 hover:bg-gray-100 transition-colors"
@click="onAvailableClick(item)"
>
<div class="flex items-start justify-between gap-2">
<div class="min-w-0 flex-1">
<p class="m-0 text-sm font-bold truncate">{{ item.name || kindLabel(item) }}</p>
<p class="m-0 mt-1 text-xs font-mono tracking-wide">{{ item.code }}</p>
<p class="m-0 mt-1 text-xs text-gray-500">{{ amountLabel(item) }}</p>
</div>
<div class="flex flex-col items-end gap-1 shrink-0">
<span class="text-xs px-1.5 py-0.5 rounded bg-blue-50 text-blue-700">{{ scopeLabel(item) }}</span>
<span class="text-xs px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-700">{{ kindLabel(item) }}</span>
</div>
</div>
<p v-if="item.expiry_date" class="m-0 mt-1.5 text-xs text-gray-400">
انقضا: {{ formatDate(item.expiry_date) }}
</p>
</button>
</div>
<p v-else class="text-xs text-gray-400 m-0 py-2">کد قابل استفاده‌ای ندارید.</p>
</section>
<section class="border border-gray-200 rounded-xl p-3 bg-white mt-3">
<h3 class="text-sm font-bold m-0 mb-1">تاریخچه</h3>
<p class="text-xs text-gray-500 m-0 mb-2.5">
کدهایی که قبلاً ثبت یا مصرف کرده‌اید.
</p>
<div v-if="history.length" class="flex flex-col gap-2">
<div
v-for="item in history"
:key="`h-${item.id}`"
class="w-full border border-gray-100 rounded-lg p-2.5 bg-gray-50"
>
<div class="flex items-start justify-between gap-2">
<div class="min-w-0 flex-1">
<p class="m-0 text-sm font-bold truncate">{{ item.name || kindLabel(item) }}</p>
<p class="m-0 mt-1 text-xs font-mono tracking-wide">{{ item.code }}</p>
<p class="m-0 mt-1 text-xs text-gray-500">{{ amountLabel(item) }}</p>
</div>
<div class="flex flex-col items-end gap-1 shrink-0">
<span class="text-xs px-1.5 py-0.5 rounded bg-gray-200 text-gray-700">مصرف‌شده</span>
<span class="text-xs px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-700">{{ kindLabel(item) }}</span>
</div>
</div>
<p v-if="item.used_at" class="m-0 mt-1.5 text-xs text-gray-400">
تاریخ مصرف: {{ formatDate(item.used_at) }}
</p>
</div>
</div>
<p v-else class="text-xs text-gray-400 m-0 py-2">هنوز کدی مصرف نکرده‌اید.</p>
</section>
</a-spin>
</div>
</template>
<script lang="ts" setup>
import { message } from 'ant-design-vue'
import type { CustomerGiftCardItem } from '@/api/giftCard'
import { useGiftCardPageContext } from '../composables/useGiftCardPage'
withDefaults(
defineProps<{
variant?: 'mobile' | 'desktop'
}>(),
{ variant: 'mobile' },
)
const { available, history, listLoading, fillCode } = useGiftCardPageContext()
function onAvailableClick(item: CustomerGiftCardItem) {
fillCode(item.code)
if (item.kind === 'discount') {
message.info('کد تخفیف در فیلد پر شد؛ هنگام خرید در سبد استفاده کنید')
}
}
function kindLabel(item: CustomerGiftCardItem) {
return item.kind === 'discount' ? 'تخفیف' : 'کارت هدیه'
}
function scopeLabel(item: CustomerGiftCardItem) {
return item.scope === 'personal' ? 'اختصاصی' : 'عمومی'
}
function amountLabel(item: CustomerGiftCardItem) {
const amount = Number(item.amount)
if (!Number.isFinite(amount)) return '—'
if (item.unit === 3) {
const percent = amount <= 1 ? amount * 100 : amount
return `${percent.toLocaleString('fa-IR')}٪ تخفیف`
}
if (item.unit === 2) {
return `${amount.toLocaleString('fa-IR')} طلا`
}
return `${amount.toLocaleString('fa-IR')} ریال`
}
function formatDate(value: string) {
try {
return new Date(value).toLocaleDateString('fa-IR')
} catch {
return value
}
}
</script>
@@ -1,6 +1,10 @@
import { computed, inject, provide, ref, type ComputedRef, type InjectionKey, type Ref } from 'vue'
import { computed, inject, onMounted, provide, ref, type ComputedRef, type InjectionKey, type Ref } from 'vue'
import { loading } from '@/utils'
import { registerCodeGiftCard } from '@/api/giftCard'
import {
fetchMyGiftCards,
registerCodeGiftCard,
type CustomerGiftCardItem,
} from '@/api/giftCard'
import { message } from 'ant-design-vue'
export interface GiftCardPageContext {
@@ -8,6 +12,11 @@ export interface GiftCardPageContext {
disableButton: ComputedRef<boolean>
loading: typeof loading
registerGiftCard: () => Promise<void>
available: Ref<CustomerGiftCardItem[]>
history: Ref<CustomerGiftCardItem[]>
listLoading: Ref<boolean>
loadMyGiftCards: () => Promise<void>
fillCode: (code: string) => void
}
export const GIFT_CARD_PAGE_CONTEXT_KEY: InjectionKey<GiftCardPageContext> =
@@ -17,6 +26,9 @@ export function useGiftCardPage() {
const form = ref<{ code: string }>({
code: '',
})
const available = ref<CustomerGiftCardItem[]>([])
const history = ref<CustomerGiftCardItem[]>([])
const listLoading = ref(false)
const disableButton = computed(() => {
if (!loading.value) {
@@ -25,12 +37,42 @@ export function useGiftCardPage() {
return true
})
async function loadMyGiftCards() {
try {
listLoading.value = true
const res = await fetchMyGiftCards()
available.value = res?.available ?? []
history.value = res?.history ?? []
} catch {
available.value = []
history.value = []
} finally {
listLoading.value = false
}
}
function fillCode(code: string) {
form.value.code = code
}
async function registerGiftCard() {
const code = form.value.code.trim()
if (!code) return
const matched =
available.value.find((item) => item.code === code) ||
history.value.find((item) => item.code === code)
if (matched?.kind === 'discount') {
message.info('کد تخفیف را هنگام ثبت سفارش در سبد خرید وارد کنید')
return
}
try {
loading.value = true
await registerCodeGiftCard(form.value.code)
await registerCodeGiftCard(code)
message.success('کد کارت هدیه با موفقیت ثبت شد')
form.value.code = ''
await loadMyGiftCards()
} catch (e: any) {
message.error(e?.response?.data?.message || 'خطا در ثبت کد کارت هدیه')
} finally {
@@ -38,11 +80,20 @@ export function useGiftCardPage() {
}
}
onMounted(() => {
void loadMyGiftCards()
})
const context: GiftCardPageContext = {
form,
disableButton,
loading,
registerGiftCard,
available,
history,
listLoading,
loadMyGiftCards,
fillCode,
}
provide(GIFT_CARD_PAGE_CONTEXT_KEY, context)
@@ -24,6 +24,7 @@
</div>
</div>
<GiftCardForm variant="desktop" />
<GiftCardLists variant="desktop" />
</section>
<aside class="dgift-surface dgift-guide">
@@ -47,4 +48,5 @@
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
import router from '@/router'
import GiftCardForm from '../components/GiftCardForm.vue'
import GiftCardLists from '../components/GiftCardLists.vue'
</script>
@@ -2,12 +2,13 @@
<div>
<MobilePageHeader title="کارت هدیه" show-back />
<div class="px-5 mpage-content pb-2">
<div class="border-gray-200 border-1 rounded-xl p-5 trans h-40 relative">
<div class="border-gray-200 border-1 rounded-xl p-5 trans relative">
<bg_main />
<div class="z-100 relative">
<GiftCardForm variant="mobile" />
</div>
</div>
<GiftCardLists variant="mobile" />
</div>
</div>
</template>
@@ -16,4 +17,5 @@
import Bg_main from '@/components/bg_main.vue'
import MobilePageHeader from '@/layouts/components/MobilePageHeader.vue'
import GiftCardForm from '../components/GiftCardForm.vue'
import GiftCardLists from '../components/GiftCardLists.vue'
</script>