188 lines
5.4 KiB
Vue
188 lines
5.4 KiB
Vue
<script setup lang="ts">
|
||||
|
|
import { computed, onMounted, ref } from 'vue';
|
|||
|
|
import { useRoute, useRouter } from 'vue-router';
|
|||
|
|
import type { GamificationReportDto } from '@mento/shared';
|
|||
|
|
import UiIcon from '@/components/UiIcon.vue';
|
|||
|
|
import { useAuthStore } from '@/stores/auth';
|
|||
|
|
import { api } from '@/lib/api';
|
|||
|
|
import AdminRules from '@/components/gamification/admin/AdminRules.vue';
|
|||
|
|
import AdminApprovals from '@/components/gamification/admin/AdminApprovals.vue';
|
|||
|
|
import AdminRewards from '@/components/gamification/admin/AdminRewards.vue';
|
|||
|
|
import AdminAchievements from '@/components/gamification/admin/AdminAchievements.vue';
|
|||
|
|
import AdminAdjust from '@/components/gamification/admin/AdminAdjust.vue';
|
|||
|
|
import AdminSettings from '@/components/gamification/admin/AdminSettings.vue';
|
|||
|
|
import AdminReports from '@/components/gamification/admin/AdminReports.vue';
|
|||
|
|
import { toFaDigits } from '@/lib/jalali';
|
|||
|
|
|
|||
|
|
type Tab = 'rules' | 'redemptions' | 'rewards' | 'badges' | 'adjust' | 'settings' | 'reports';
|
|||
|
|
const TABS: Array<{
|
|||
|
|
value: Tab;
|
|||
|
|
label: string;
|
|||
|
|
icon: 'sliders' | 'check' | 'gift' | 'medal' | 'edit' | 'settings' | 'chart';
|
|||
|
|
}> = [
|
|||
|
|
{ value: 'rules', label: 'قوانین امتیاز', icon: 'sliders' },
|
|||
|
|
{ value: 'redemptions', label: 'تأییدها', icon: 'check' },
|
|||
|
|
{ value: 'rewards', label: 'فروشگاه پاداش', icon: 'gift' },
|
|||
|
|
{ value: 'badges', label: 'نشانها و بونوسها', icon: 'medal' },
|
|||
|
|
{ value: 'adjust', label: 'تنظیم دستی', icon: 'edit' },
|
|||
|
|
{ value: 'reports', label: 'گزارش و ROI', icon: 'chart' },
|
|||
|
|
{ value: 'settings', label: 'تنظیمات', icon: 'settings' },
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
const route = useRoute();
|
|||
|
|
const router = useRouter();
|
|||
|
|
const auth = useAuthStore();
|
|||
|
|
|
|||
|
|
const isAdmin = computed(() => auth.user?.role === 'owner' || auth.user?.role === 'admin');
|
|||
|
|
const pendingCount = ref(0);
|
|||
|
|
|
|||
|
|
const tab = computed<Tab>(() => {
|
|||
|
|
const t = route.query.tab;
|
|||
|
|
return TABS.some((x) => x.value === t) ? (t as Tab) : 'rules';
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
function setTab(next: Tab) {
|
|||
|
|
void router.replace({ query: { ...route.query, tab: next === 'rules' ? undefined : next } });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function loadPending() {
|
|||
|
|
try {
|
|||
|
|
const { data } = await api.get<GamificationReportDto>('/admin/gamification/reports', {
|
|||
|
|
params: { period: 'today' },
|
|||
|
|
});
|
|||
|
|
pendingCount.value = data.totals.pendingApprovals + data.totals.pendingRedemptions;
|
|||
|
|
} catch {
|
|||
|
|
pendingCount.value = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function onChanged() {
|
|||
|
|
void loadPending();
|
|||
|
|
window.dispatchEvent(new CustomEvent('gamification:updated'));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
onMounted(() => {
|
|||
|
|
if (isAdmin.value) void loadPending();
|
|||
|
|
});
|
|||
|
|
</script>
|
|||
|
|
|
|||
|
|
<template>
|
|||
|
|
<section class="crm-page gadmin">
|
|||
|
|
<header class="head">
|
|||
|
|
<RouterLink to="/club" class="back"><UiIcon name="chevron-right" :size="16" /> باشگاه امتیازات</RouterLink>
|
|||
|
|
<h1>مدیریت باشگاه امتیازات</h1>
|
|||
|
|
<p>قوانین امتیازدهی، پاداشها، نشانها و درخواستها را از اینجا مدیریت کنید.</p>
|
|||
|
|
</header>
|
|||
|
|
|
|||
|
|
<p v-if="!isAdmin" class="denied">این بخش فقط برای مالک و مدیران سازمان در دسترس است.</p>
|
|||
|
|
|
|||
|
|
<template v-else>
|
|||
|
|
<nav class="tabs" aria-label="بخشهای مدیریت باشگاه">
|
|||
|
|
<button
|
|||
|
|
v-for="t in TABS"
|
|||
|
|
:key="t.value"
|
|||
|
|
type="button"
|
|||
|
|
class="tab"
|
|||
|
|
:class="{ on: tab === t.value }"
|
|||
|
|
@click="setTab(t.value)"
|
|||
|
|
>
|
|||
|
|
<UiIcon :name="t.icon" :size="15" />
|
|||
|
|
<span>{{ t.label }}</span>
|
|||
|
|
<em v-if="t.value === 'redemptions' && pendingCount">{{ toFaDigits(pendingCount) }}</em>
|
|||
|
|
</button>
|
|||
|
|
</nav>
|
|||
|
|
|
|||
|
|
<AdminRules v-if="tab === 'rules'" />
|
|||
|
|
<AdminApprovals v-else-if="tab === 'redemptions'" @changed="onChanged" />
|
|||
|
|
<AdminRewards v-else-if="tab === 'rewards'" />
|
|||
|
|
<AdminAchievements v-else-if="tab === 'badges'" />
|
|||
|
|
<AdminAdjust v-else-if="tab === 'adjust'" @changed="onChanged" />
|
|||
|
|
<AdminReports v-else-if="tab === 'reports'" />
|
|||
|
|
<AdminSettings v-else-if="tab === 'settings'" @changed="onChanged" />
|
|||
|
|
</template>
|
|||
|
|
</section>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<style scoped>
|
|||
|
|
.gadmin {
|
|||
|
|
gap: var(--sp-4);
|
|||
|
|
grid-template-columns: minmax(0, 1fr);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.head {
|
|||
|
|
display: grid;
|
|||
|
|
gap: 4px;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.back {
|
|||
|
|
display: inline-flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: 4px;
|
|||
|
|
color: var(--accent-deep);
|
|||
|
|
font-size: var(--fs-sm);
|
|||
|
|
text-decoration: none;
|
|||
|
|
width: fit-content;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.head h1 {
|
|||
|
|
margin: 0;
|
|||
|
|
font-size: var(--fs-xl);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.head p {
|
|||
|
|
margin: 0;
|
|||
|
|
color: var(--muted);
|
|||
|
|
font-size: var(--fs-sm);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.denied {
|
|||
|
|
padding: var(--sp-4);
|
|||
|
|
border-radius: var(--radius);
|
|||
|
|
background: var(--warning-soft);
|
|||
|
|
color: var(--warning-deep);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.tabs {
|
|||
|
|
display: flex;
|
|||
|
|
gap: 4px;
|
|||
|
|
overflow-x: auto;
|
|||
|
|
padding-bottom: 2px;
|
|||
|
|
border-bottom: 1px solid var(--line);
|
|||
|
|
scrollbar-width: thin;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.tab {
|
|||
|
|
display: inline-flex;
|
|||
|
|
align-items: center;
|
|||
|
|
gap: 6px;
|
|||
|
|
padding: 9px 12px;
|
|||
|
|
border: 0;
|
|||
|
|
border-bottom: 2px solid transparent;
|
|||
|
|
background: transparent;
|
|||
|
|
color: var(--muted);
|
|||
|
|
font: inherit;
|
|||
|
|
font-size: var(--fs-sm);
|
|||
|
|
font-weight: 600;
|
|||
|
|
white-space: nowrap;
|
|||
|
|
cursor: pointer;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.tab.on {
|
|||
|
|
color: var(--accent-deep);
|
|||
|
|
border-bottom-color: var(--accent);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.tab em {
|
|||
|
|
font-style: normal;
|
|||
|
|
font-size: 0.68rem;
|
|||
|
|
min-width: 18px;
|
|||
|
|
height: 18px;
|
|||
|
|
padding: 0 5px;
|
|||
|
|
border-radius: 999px;
|
|||
|
|
display: grid;
|
|||
|
|
place-items: center;
|
|||
|
|
background: var(--danger);
|
|||
|
|
color: #fff;
|
|||
|
|
}
|
|||
|
|
</style>
|