edit business owner
This commit is contained in:
+6
-1
@@ -22,6 +22,7 @@ export type Business = {
|
|||||||
slug: string;
|
slug: string;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
address?: string | null;
|
address?: string | null;
|
||||||
|
contactPhone?: string | null;
|
||||||
phone?: string | null;
|
phone?: string | null;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
categoryId: string;
|
categoryId: string;
|
||||||
@@ -39,6 +40,7 @@ export type UpdateBusinessPayload = {
|
|||||||
subtitle?: string | null;
|
subtitle?: string | null;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
address?: string | null;
|
address?: string | null;
|
||||||
|
contactPhone?: string | null;
|
||||||
phone?: string | null;
|
phone?: string | null;
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
concurrentCapacity?: number;
|
concurrentCapacity?: number;
|
||||||
@@ -122,14 +124,17 @@ export type CreateBusinessRegistrationPayload = {
|
|||||||
phone?: string;
|
phone?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type BusinessServiceRequestStatus = 'pending' | 'approved' | 'rejected';
|
||||||
|
|
||||||
export type BusinessServiceRequest = {
|
export type BusinessServiceRequest = {
|
||||||
id: string;
|
id: string;
|
||||||
businessId: string;
|
businessId: string;
|
||||||
status: string;
|
status: BusinessServiceRequestStatus;
|
||||||
title: string;
|
title: string;
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
price: string;
|
price: string;
|
||||||
durationMinutes?: number | null;
|
durationMinutes?: number | null;
|
||||||
|
adminNote?: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -289,8 +289,10 @@ const classStepRequired = computed(
|
|||||||
() => Boolean(props.business.serviceClassesEnabled) && serviceClasses.value.length > 0,
|
() => Boolean(props.business.serviceClassesEnabled) && serviceClasses.value.length > 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const classesEnabled = computed(() => Boolean(props.business.serviceClassesEnabled));
|
||||||
|
|
||||||
const perClass = computed(
|
const perClass = computed(
|
||||||
() => Boolean(props.business.serviceClassesEnabled) && Boolean(selectedClassId.value),
|
() => classesEnabled.value && Boolean(selectedClassId.value),
|
||||||
);
|
);
|
||||||
|
|
||||||
const selectedServices = computed(() =>
|
const selectedServices = computed(() =>
|
||||||
@@ -347,7 +349,7 @@ const summaryItems = computed(() =>
|
|||||||
),
|
),
|
||||||
durationLabel: serviceDurationLabel(
|
durationLabel: serviceDurationLabel(
|
||||||
service,
|
service,
|
||||||
perClass.value,
|
classesEnabled.value,
|
||||||
serviceClasses.value,
|
serviceClasses.value,
|
||||||
selectedClassId.value || undefined,
|
selectedClassId.value || undefined,
|
||||||
),
|
),
|
||||||
@@ -440,7 +442,7 @@ const canProceed = computed(() => {
|
|||||||
function durationFor(service: BusinessService) {
|
function durationFor(service: BusinessService) {
|
||||||
return serviceDurationLabel(
|
return serviceDurationLabel(
|
||||||
service,
|
service,
|
||||||
perClass.value,
|
classesEnabled.value,
|
||||||
serviceClasses.value,
|
serviceClasses.value,
|
||||||
selectedClassId.value || undefined,
|
selectedClassId.value || undefined,
|
||||||
);
|
);
|
||||||
@@ -449,7 +451,7 @@ function durationFor(service: BusinessService) {
|
|||||||
function priceFor(service: BusinessService) {
|
function priceFor(service: BusinessService) {
|
||||||
return servicePriceLabel(
|
return servicePriceLabel(
|
||||||
service,
|
service,
|
||||||
perClass.value,
|
classesEnabled.value,
|
||||||
serviceClasses.value,
|
serviceClasses.value,
|
||||||
selectedClassId.value || undefined,
|
selectedClassId.value || undefined,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ import { ApiError } from '@/api/client';
|
|||||||
import type { Business, BusinessCategory } from '@/api/types';
|
import type { Business, BusinessCategory } from '@/api/types';
|
||||||
import HomeBusinessList from '@/components/home/HomeBusinessList.vue';
|
import HomeBusinessList from '@/components/home/HomeBusinessList.vue';
|
||||||
import HomeSearchAndFilter from '@/components/home/HomeSearchAndFilter.vue';
|
import HomeSearchAndFilter from '@/components/home/HomeSearchAndFilter.vue';
|
||||||
|
import { useOwnedBusiness } from '@/composables/useOwnedBusiness';
|
||||||
|
import { useAuthStore } from '@/stores/auth';
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -41,6 +43,9 @@ const props = withDefaults(
|
|||||||
{ listVariant: 'compact' },
|
{ listVariant: 'compact' },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const auth = useAuthStore();
|
||||||
|
const { ensureLoaded, isOwnBusiness } = useOwnedBusiness();
|
||||||
|
|
||||||
const categories = ref<BusinessCategory[]>([]);
|
const categories = ref<BusinessCategory[]>([]);
|
||||||
const businesses = ref<Business[]>([]);
|
const businesses = ref<Business[]>([]);
|
||||||
const selectedCategoryId = ref<string | null>(null);
|
const selectedCategoryId = ref<string | null>(null);
|
||||||
@@ -58,10 +63,16 @@ const showSearch = computed(() => businesses.value.length > 1);
|
|||||||
|
|
||||||
const filteredBusinesses = computed(() => {
|
const filteredBusinesses = computed(() => {
|
||||||
const q = searchQuery.value.trim().toLowerCase();
|
const q = searchQuery.value.trim().toLowerCase();
|
||||||
if (!q) {
|
let items = businesses.value;
|
||||||
return businesses.value;
|
|
||||||
|
if (auth.isBusinessOwner) {
|
||||||
|
items = items.filter((business) => !isOwnBusiness(business.id));
|
||||||
}
|
}
|
||||||
return businesses.value.filter((b) => {
|
|
||||||
|
if (!q) {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
return items.filter((b) => {
|
||||||
const haystack = [b.title, b.description, b.address]
|
const haystack = [b.title, b.description, b.address]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' ')
|
.join(' ')
|
||||||
@@ -107,6 +118,10 @@ watch(selectedCategoryId, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
if (auth.isLoggedIn) {
|
||||||
|
await auth.loadUser();
|
||||||
|
await ensureLoaded();
|
||||||
|
}
|
||||||
await loadCategories();
|
await loadCategories();
|
||||||
await loadBusinesses();
|
await loadBusinesses();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-wrap items-center gap-3">
|
<div class="flex flex-wrap items-center gap-3">
|
||||||
<button
|
<button
|
||||||
|
v-if="props.showBookButton"
|
||||||
type="button"
|
type="button"
|
||||||
class="inline-flex items-center gap-2 rounded-lg bg-brand-600 px-6 py-3 text-[15px] font-semibold text-white shadow-sm transition hover:bg-brand-700"
|
class="inline-flex items-center gap-2 rounded-lg bg-brand-600 px-6 py-3 text-[15px] font-semibold text-white shadow-sm transition hover:bg-brand-700"
|
||||||
@click="emit('book')"
|
@click="emit('book')"
|
||||||
@@ -99,6 +100,13 @@ import { useTenantStore } from '@/stores/tenant';
|
|||||||
import type { AppIconName } from '@/types/icons';
|
import type { AppIconName } from '@/types/icons';
|
||||||
import { businessCoverUrl } from '@/utils/media';
|
import { businessCoverUrl } from '@/utils/media';
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
showBookButton?: boolean;
|
||||||
|
}>(),
|
||||||
|
{ showBookButton: true },
|
||||||
|
);
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
book: [];
|
book: [];
|
||||||
browse: [];
|
browse: [];
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<RouterLink
|
<component
|
||||||
:to="to"
|
:is="linkEnabled ? RouterLink : 'div'"
|
||||||
class="flex min-w-0 flex-1 flex-col rounded-xl border bg-white px-4 py-5 text-center shadow-[0_2px_12px_rgba(15,23,42,0.06)] transition hover:-translate-y-0.5 hover:shadow-md dark:bg-surface"
|
:to="linkEnabled ? to : undefined"
|
||||||
:class="
|
class="flex min-w-0 flex-1 flex-col rounded-xl border border-slate-100 bg-white px-4 py-5 text-center shadow-[0_2px_12px_rgba(15,23,42,0.06)] transition dark:border-border dark:bg-surface hover:-translate-y-0.5 hover:border-brand-600 hover:shadow-md hover:ring-1 hover:ring-brand-600/25 focus-visible:border-brand-600 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-brand-600/25 active:border-brand-600 active:ring-1 active:ring-brand-600/25"
|
||||||
featured
|
|
||||||
? 'border-brand-600 ring-1 ring-brand-600/25'
|
|
||||||
: 'border-slate-100 dark:border-border'
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<div class="mb-3 flex justify-center text-slate-400 dark:text-muted">
|
<div class="mb-3 flex justify-center text-slate-400 dark:text-muted">
|
||||||
<AppIcon :name="icon" size="lg" />
|
<AppIcon :name="icon" size="lg" />
|
||||||
@@ -26,22 +22,26 @@
|
|||||||
<p v-if="durationLabel" class="mt-3 text-xs text-landing-muted dark:text-muted">
|
<p v-if="durationLabel" class="mt-3 text-xs text-landing-muted dark:text-muted">
|
||||||
مدت زمان: {{ durationLabel }}
|
مدت زمان: {{ durationLabel }}
|
||||||
</p>
|
</p>
|
||||||
</RouterLink>
|
</component>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { RouterLink } from 'vue-router';
|
||||||
import AppIcon from '@/components/ui/AppIcon.vue';
|
import AppIcon from '@/components/ui/AppIcon.vue';
|
||||||
import type { AppIconName } from '@/types/icons';
|
import type { AppIconName } from '@/types/icons';
|
||||||
|
|
||||||
defineProps<{
|
withDefaults(
|
||||||
to:
|
defineProps<{
|
||||||
| string
|
to:
|
||||||
| { name: string; params?: Record<string, string>; hash?: string }
|
| string
|
||||||
| { path: string; hash?: string };
|
| { name: string; params?: Record<string, string>; hash?: string }
|
||||||
title: string;
|
| { path: string; hash?: string };
|
||||||
description?: string | null;
|
title: string;
|
||||||
durationLabel?: string | null;
|
description?: string | null;
|
||||||
icon: AppIconName;
|
durationLabel?: string | null;
|
||||||
featured?: boolean;
|
icon: AppIconName;
|
||||||
}>();
|
linkEnabled?: boolean;
|
||||||
|
}>(),
|
||||||
|
{ linkEnabled: true },
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -29,14 +29,14 @@
|
|||||||
:class="gridClass"
|
:class="gridClass"
|
||||||
>
|
>
|
||||||
<HomeServiceCard
|
<HomeServiceCard
|
||||||
v-for="(item, index) in items"
|
v-for="item in items"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:to="serviceLink(item)"
|
:to="serviceLink(item)"
|
||||||
:title="item.title"
|
:title="item.title"
|
||||||
:description="item.description"
|
:description="item.description"
|
||||||
:duration-label="item.durationLabel"
|
:duration-label="item.durationLabel"
|
||||||
:icon="item.icon"
|
:icon="item.icon"
|
||||||
:featured="index === featuredIndex"
|
:link-enabled="props.bookingEnabled"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -50,11 +50,15 @@ import HomeServiceCard from '@/components/home/HomeServiceCard.vue';
|
|||||||
import ServiceGridSkeleton from '@/components/ui/ServiceGridSkeleton.vue';
|
import ServiceGridSkeleton from '@/components/ui/ServiceGridSkeleton.vue';
|
||||||
import type { LandingServiceItem } from '@/types/landing';
|
import type { LandingServiceItem } from '@/types/landing';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = withDefaults(
|
||||||
items: LandingServiceItem[];
|
defineProps<{
|
||||||
loading: boolean;
|
items: LandingServiceItem[];
|
||||||
error: string;
|
loading: boolean;
|
||||||
}>();
|
error: string;
|
||||||
|
bookingEnabled?: boolean;
|
||||||
|
}>(),
|
||||||
|
{ bookingEnabled: true },
|
||||||
|
);
|
||||||
|
|
||||||
const gridClass = computed(() => {
|
const gridClass = computed(() => {
|
||||||
const count = props.items.length;
|
const count = props.items.length;
|
||||||
@@ -64,13 +68,8 @@ const gridClass = computed(() => {
|
|||||||
return 'lg:grid-cols-2';
|
return 'lg:grid-cols-2';
|
||||||
});
|
});
|
||||||
|
|
||||||
const featuredIndex = computed(() => {
|
|
||||||
const len = props.items.length;
|
|
||||||
if (!len) return 0;
|
|
||||||
return Math.min(2, len - 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
function serviceLink(item: LandingServiceItem) {
|
function serviceLink(item: LandingServiceItem) {
|
||||||
|
if (!props.bookingEnabled) return '#services';
|
||||||
return {
|
return {
|
||||||
name: 'app-business-detail',
|
name: 'app-business-detail',
|
||||||
params: { id: item.businessId },
|
params: { id: item.businessId },
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<DesktopSiteLayout content-width="full">
|
<DesktopSiteLayout content-width="full">
|
||||||
<HomeHeroSection @book="goToBooking" @browse="scrollToServices" />
|
<HomeHeroSection
|
||||||
|
:show-book-button="props.bookingEnabled"
|
||||||
|
@book="goToBooking"
|
||||||
|
@browse="scrollToServices"
|
||||||
|
/>
|
||||||
|
|
||||||
<HomeServicesSection
|
<HomeServicesSection
|
||||||
:items="services"
|
:items="services"
|
||||||
:loading="loadingServices"
|
:loading="loadingServices"
|
||||||
:error="servicesError"
|
:error="servicesError"
|
||||||
|
:booking-enabled="props.bookingEnabled"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<HomeFeatureBar />
|
<HomeFeatureBar />
|
||||||
@@ -22,11 +27,15 @@ import DesktopSiteLayout from '@/layouts/DesktopSiteLayout.vue';
|
|||||||
import { useTenantStore } from '@/stores/tenant';
|
import { useTenantStore } from '@/stores/tenant';
|
||||||
import type { LandingServiceItem } from '@/types/landing';
|
import type { LandingServiceItem } from '@/types/landing';
|
||||||
|
|
||||||
defineProps<{
|
const props = withDefaults(
|
||||||
services: LandingServiceItem[];
|
defineProps<{
|
||||||
loadingServices: boolean;
|
services: LandingServiceItem[];
|
||||||
servicesError: string;
|
loadingServices: boolean;
|
||||||
}>();
|
servicesError: string;
|
||||||
|
bookingEnabled?: boolean;
|
||||||
|
}>(),
|
||||||
|
{ bookingEnabled: true },
|
||||||
|
);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const tenant = useTenantStore();
|
const tenant = useTenantStore();
|
||||||
@@ -38,6 +47,11 @@ function scrollToServices() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function goToBooking() {
|
function goToBooking() {
|
||||||
|
if (!props.bookingEnabled) {
|
||||||
|
void router.push({ name: 'app-owner' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const id = singleBusinessId.value;
|
const id = singleBusinessId.value;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
scrollToServices();
|
scrollToServices();
|
||||||
|
|||||||
@@ -34,6 +34,10 @@
|
|||||||
<section id="contact" class="scroll-mt-28">
|
<section id="contact" class="scroll-mt-28">
|
||||||
<h3 class="mb-4 text-sm font-bold text-landing-ink dark:text-text">تماس با ما</h3>
|
<h3 class="mb-4 text-sm font-bold text-landing-ink dark:text-text">تماس با ما</h3>
|
||||||
<ul class="space-y-3 text-sm text-landing-muted dark:text-muted">
|
<ul class="space-y-3 text-sm text-landing-muted dark:text-muted">
|
||||||
|
<li v-if="address" class="flex items-start gap-2">
|
||||||
|
<AppIcon name="map-pin" size="sm" class="mt-0.5 shrink-0 text-brand-600" />
|
||||||
|
{{ address }}
|
||||||
|
</li>
|
||||||
<li v-if="contactPhone" class="flex items-center gap-2" dir="ltr">
|
<li v-if="contactPhone" class="flex items-center gap-2" dir="ltr">
|
||||||
<AppIcon name="phone" size="sm" class="shrink-0 text-brand-600" />
|
<AppIcon name="phone" size="sm" class="shrink-0 text-brand-600" />
|
||||||
{{ contactPhone }}
|
{{ contactPhone }}
|
||||||
@@ -42,10 +46,6 @@
|
|||||||
<AppIcon name="phone" size="sm" class="shrink-0 text-brand-600" />
|
<AppIcon name="phone" size="sm" class="shrink-0 text-brand-600" />
|
||||||
{{ contactMobile }}
|
{{ contactMobile }}
|
||||||
</li>
|
</li>
|
||||||
<li v-if="address" class="flex items-start gap-2">
|
|
||||||
<AppIcon name="map-pin" size="sm" class="mt-0.5 shrink-0 text-brand-600" />
|
|
||||||
{{ address }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { computed } from 'vue';
|
|||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import type { AppIconName } from '@/types/icons';
|
import type { AppIconName } from '@/types/icons';
|
||||||
import { useAuthStore } from '@/stores/auth';
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import { useProfileModalStore } from '@/stores/profile-modal';
|
|
||||||
import { useTenantStore } from '@/stores/tenant';
|
import { useTenantStore } from '@/stores/tenant';
|
||||||
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
|
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
|
||||||
|
|
||||||
@@ -19,7 +18,6 @@ export type AppNavItem = {
|
|||||||
export function useAppNav() {
|
export function useAppNav() {
|
||||||
const auth = useAuthStore();
|
const auth = useAuthStore();
|
||||||
const tenant = useTenantStore();
|
const tenant = useTenantStore();
|
||||||
const profileModal = useProfileModalStore();
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -68,13 +66,6 @@ export function useAppNav() {
|
|||||||
icon: 'clipboard-list',
|
icon: 'clipboard-list',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push({
|
|
||||||
key: 'profile',
|
|
||||||
name: 'app-profile',
|
|
||||||
label: 'پروفایل',
|
|
||||||
icon: 'user',
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
items.push({
|
items.push({
|
||||||
key: 'register',
|
key: 'register',
|
||||||
@@ -118,9 +109,6 @@ export function useAppNav() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function isNavActive(item: AppNavItem): boolean {
|
function isNavActive(item: AppNavItem): boolean {
|
||||||
if (item.key === 'profile') {
|
|
||||||
return profileModal.isOpen;
|
|
||||||
}
|
|
||||||
if (item.hash) {
|
if (item.hash) {
|
||||||
return route.name === item.name && route.hash === item.hash;
|
return route.name === item.name && route.hash === item.hash;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { computed, ref } from 'vue';
|
||||||
|
import { fetchMyBusinesses } from '@/api/businesses';
|
||||||
|
import { useAuthStore } from '@/stores/auth';
|
||||||
|
|
||||||
|
const ownedBusinessIds = ref<Set<string>>(new Set());
|
||||||
|
const loaded = ref(false);
|
||||||
|
let loadPromise: Promise<void> | null = null;
|
||||||
|
|
||||||
|
export function useOwnedBusiness() {
|
||||||
|
const auth = useAuthStore();
|
||||||
|
|
||||||
|
async function ensureLoaded() {
|
||||||
|
if (!auth.isBusinessOwner) {
|
||||||
|
ownedBusinessIds.value = new Set();
|
||||||
|
loaded.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (loaded.value) return;
|
||||||
|
if (loadPromise) {
|
||||||
|
await loadPromise;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadPromise = (async () => {
|
||||||
|
try {
|
||||||
|
const businesses = await fetchMyBusinesses();
|
||||||
|
ownedBusinessIds.value = new Set(businesses.map((item) => item.id));
|
||||||
|
} catch {
|
||||||
|
ownedBusinessIds.value = new Set();
|
||||||
|
} finally {
|
||||||
|
loaded.value = true;
|
||||||
|
loadPromise = null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
await loadPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isOwnBusiness(businessId: string | null | undefined): boolean {
|
||||||
|
if (!businessId || !auth.isBusinessOwner) return false;
|
||||||
|
return ownedBusinessIds.value.has(businessId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ownsAnyBusiness = computed(() => ownedBusinessIds.value.size > 0);
|
||||||
|
|
||||||
|
return {
|
||||||
|
loaded,
|
||||||
|
ownsAnyBusiness,
|
||||||
|
ensureLoaded,
|
||||||
|
isOwnBusiness,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -23,12 +23,8 @@
|
|||||||
>
|
>
|
||||||
<div class="grid gap-1" :class="mobileNavGridClass">
|
<div class="grid gap-1" :class="mobileNavGridClass">
|
||||||
<template v-for="item in mobileNavItems" :key="`mobile-${item.key}`">
|
<template v-for="item in mobileNavItems" :key="`mobile-${item.key}`">
|
||||||
<ProfileDropdown
|
|
||||||
v-if="item.key === 'profile'"
|
|
||||||
variant="bottom-nav"
|
|
||||||
/>
|
|
||||||
<RouterLink
|
<RouterLink
|
||||||
v-else-if="item.to && !item.onClick"
|
v-if="item.to && !item.onClick"
|
||||||
:to="item.hash ? { path: item.to, hash: item.hash.replace('#', '') } : item.to"
|
:to="item.hash ? { path: item.to, hash: item.hash.replace('#', '') } : item.to"
|
||||||
class="flex flex-col items-center rounded-xl px-2 py-2 text-xs transition"
|
class="flex flex-col items-center rounded-xl px-2 py-2 text-xs transition"
|
||||||
:class="navLinkClass(item)"
|
:class="navLinkClass(item)"
|
||||||
@@ -58,7 +54,6 @@ import AppShell from '@/components/shell/AppShell.vue';
|
|||||||
import AppIcon from '@/components/ui/AppIcon.vue';
|
import AppIcon from '@/components/ui/AppIcon.vue';
|
||||||
import AppLogo from '@/components/brand/AppLogo.vue';
|
import AppLogo from '@/components/brand/AppLogo.vue';
|
||||||
import ThemeToggle from '@/components/ui/ThemeToggle.vue';
|
import ThemeToggle from '@/components/ui/ThemeToggle.vue';
|
||||||
import ProfileDropdown from '@/components/profile/ProfileDropdown.vue';
|
|
||||||
import AuthHeaderAction from '@/components/shell/AuthHeaderAction.vue';
|
import AuthHeaderAction from '@/components/shell/AuthHeaderAction.vue';
|
||||||
import { useAppNav } from '@/composables/useAppNav';
|
import { useAppNav } from '@/composables/useAppNav';
|
||||||
import { useTenantStore } from '@/stores/tenant';
|
import { useTenantStore } from '@/stores/tenant';
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import { useAuthStore } from '@/stores/auth';
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import { useProfileModalStore } from '@/stores/profile-modal';
|
import { useProfileModalStore } from '@/stores/profile-modal';
|
||||||
|
import { useOwnedBusiness } from '@/composables/useOwnedBusiness';
|
||||||
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
|
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
@@ -79,6 +80,14 @@ router.beforeEach(async (to) => {
|
|||||||
return auth.isBusinessOwner ? { name: 'app-owner' } : { name: 'app-home' };
|
return auth.isBusinessOwner ? { name: 'app-owner' } : { name: 'app-home' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (to.name === 'app-business-detail' && auth.isBusinessOwner) {
|
||||||
|
const { ensureLoaded, isOwnBusiness } = useOwnedBusiness();
|
||||||
|
await ensureLoaded();
|
||||||
|
if (isOwnBusiness(String(to.params.id))) {
|
||||||
|
return { name: 'app-owner' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (to.meta.guest && auth.isLoggedIn) {
|
if (to.meta.guest && auth.isLoggedIn) {
|
||||||
return { name: 'app-home' };
|
return { name: 'app-home' };
|
||||||
}
|
}
|
||||||
|
|||||||
+192
-42
@@ -1,67 +1,220 @@
|
|||||||
import type { BusinessService, BusinessServiceClass } from '@/api/types';
|
import type { BusinessService, BusinessServiceClass } from '@/api/types';
|
||||||
import { formatPriceToman } from '@/utils/format';
|
import { formatDuration, formatPriceToman } from '@/utils/format';
|
||||||
|
|
||||||
|
export function activeServiceClasses(classes: BusinessServiceClass[]): BusinessServiceClass[] {
|
||||||
|
return [...classes]
|
||||||
|
.filter((item) => item.isActive)
|
||||||
|
.sort((a, b) => a.sortOrder - b.sortOrder || a.title.localeCompare(b.title, 'fa'));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usesServiceClasses(
|
||||||
|
classesEnabled: boolean,
|
||||||
|
classes: BusinessServiceClass[],
|
||||||
|
): boolean {
|
||||||
|
return classesEnabled && activeServiceClasses(classes).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
export function getClassPriceForService(
|
export function getClassPriceForService(
|
||||||
service: BusinessService,
|
service: BusinessService,
|
||||||
classId: string,
|
classId: string,
|
||||||
) {
|
) {
|
||||||
return service.classPrices?.find((item) => item.classId === classId && item.isActive);
|
return service.classPrices?.find(
|
||||||
|
(item) => item.classId === classId && item.isActive,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveServiceMinutes(
|
export function serviceHasActiveClassPrices(
|
||||||
service: BusinessService,
|
service: BusinessService,
|
||||||
perClass: boolean,
|
classes: BusinessServiceClass[],
|
||||||
classId?: string,
|
): boolean {
|
||||||
): number | null {
|
const activeIds = new Set(activeServiceClasses(classes).map((item) => item.id));
|
||||||
if (perClass && classId) {
|
return (service.classPrices ?? []).some(
|
||||||
const classPrice = getClassPriceForService(service, classId);
|
(item) => item.isActive && activeIds.has(item.classId),
|
||||||
if (classPrice?.durationMinutes != null) return classPrice.durationMinutes;
|
);
|
||||||
}
|
|
||||||
if (service.durationMinutes != null) return service.durationMinutes;
|
|
||||||
return service.serviceTemplate?.defaultDurationMinutes ?? null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isServiceBookableForClass(
|
||||||
|
service: BusinessService,
|
||||||
|
classId: string,
|
||||||
|
): boolean {
|
||||||
|
return service.isActive && !!getClassPriceForService(service, classId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isServiceBookable(
|
||||||
|
service: BusinessService,
|
||||||
|
classesEnabled: boolean,
|
||||||
|
classes: BusinessServiceClass[],
|
||||||
|
): boolean {
|
||||||
|
if (!service.isActive) return false;
|
||||||
|
if (!usesServiceClasses(classesEnabled, classes)) return true;
|
||||||
|
return serviceHasActiveClassPrices(service, classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function servicePriceLabel(
|
||||||
|
service: BusinessService,
|
||||||
|
classesEnabled: boolean,
|
||||||
|
classes: BusinessServiceClass[],
|
||||||
|
classId?: string | null,
|
||||||
|
): string {
|
||||||
|
if (classId) {
|
||||||
|
const price = resolvedServicePrice(service, classId);
|
||||||
|
return price ? `${formatPriceToman(price)} تومان` : 'قیمت تعیین نشده';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usesServiceClasses(classesEnabled, classes)) {
|
||||||
|
return `${formatPriceToman(service.price)} تومان`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeClasses = activeServiceClasses(classes);
|
||||||
|
const prices = activeClasses
|
||||||
|
.map((item) => getClassPriceForService(service, item.id))
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((item) => Number.parseFloat(item!.price));
|
||||||
|
|
||||||
|
if (!prices.length) return 'قیمت تعیین نشده';
|
||||||
|
const min = Math.min(...prices);
|
||||||
|
const max = Math.max(...prices);
|
||||||
|
if (min === max) {
|
||||||
|
return `${formatPriceToman(String(min))} تومان`;
|
||||||
|
}
|
||||||
|
return `از ${formatPriceToman(String(min))} تومان`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serviceDurationLabel(
|
||||||
|
service: BusinessService,
|
||||||
|
classesEnabled: boolean,
|
||||||
|
classes: BusinessServiceClass[],
|
||||||
|
classId?: string | null,
|
||||||
|
): string {
|
||||||
|
if (classId) {
|
||||||
|
const classPrice = getClassPriceForService(service, classId);
|
||||||
|
return formatDuration(
|
||||||
|
classPrice?.durationMinutes ?? service.durationMinutes,
|
||||||
|
service.serviceTemplate?.defaultDurationMinutes ?? undefined,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usesServiceClasses(classesEnabled, classes)) {
|
||||||
|
return formatDuration(
|
||||||
|
service.durationMinutes,
|
||||||
|
service.serviceTemplate?.defaultDurationMinutes ?? undefined,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeClasses = activeServiceClasses(classes);
|
||||||
|
const durations = activeClasses
|
||||||
|
.map((item) => getClassPriceForService(service, item.id))
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((item) =>
|
||||||
|
item!.durationMinutes ?? service.durationMinutes ?? service.serviceTemplate?.defaultDurationMinutes,
|
||||||
|
)
|
||||||
|
.filter((value): value is number => value != null && value > 0);
|
||||||
|
|
||||||
|
if (!durations.length) {
|
||||||
|
return formatDuration(
|
||||||
|
service.durationMinutes,
|
||||||
|
service.serviceTemplate?.defaultDurationMinutes ?? undefined,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const min = Math.min(...durations);
|
||||||
|
const max = Math.max(...durations);
|
||||||
|
if (min === max) return `${min} دقیقه`;
|
||||||
|
return `${min}–${max} دقیقه`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolvedServicePrice(
|
||||||
|
service: BusinessService,
|
||||||
|
classId: string,
|
||||||
|
): string | null {
|
||||||
|
const classPrice = getClassPriceForService(service, classId);
|
||||||
|
return classPrice?.price ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveServiceDurationMinutes(
|
||||||
|
service: BusinessService,
|
||||||
|
classesEnabled: boolean,
|
||||||
|
classes: BusinessServiceClass[],
|
||||||
|
classId?: string | null,
|
||||||
|
): number {
|
||||||
|
if (classId) {
|
||||||
|
const classPrice = getClassPriceForService(service, classId);
|
||||||
|
const fromClass =
|
||||||
|
classPrice?.durationMinutes ?? service.durationMinutes ?? service.serviceTemplate?.defaultDurationMinutes;
|
||||||
|
if (fromClass != null && fromClass > 0) return fromClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usesServiceClasses(classesEnabled, classes) && classId) {
|
||||||
|
const classPrice = getClassPriceForService(service, classId);
|
||||||
|
const value =
|
||||||
|
classPrice?.durationMinutes ??
|
||||||
|
service.durationMinutes ??
|
||||||
|
service.serviceTemplate?.defaultDurationMinutes;
|
||||||
|
if (value != null && value > 0) return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallback =
|
||||||
|
service.durationMinutes ?? service.serviceTemplate?.defaultDurationMinutes;
|
||||||
|
return fallback != null && fallback > 0 ? fallback : 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function totalDurationForServices(
|
||||||
|
services: BusinessService[],
|
||||||
|
classesEnabled: boolean,
|
||||||
|
classes: BusinessServiceClass[],
|
||||||
|
classId?: string | null,
|
||||||
|
): number {
|
||||||
|
return services.reduce(
|
||||||
|
(sum, service) =>
|
||||||
|
sum + resolveServiceDurationMinutes(service, classesEnabled, classes, classId),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function totalPriceForServices(
|
||||||
|
services: BusinessService[],
|
||||||
|
classesEnabled: boolean,
|
||||||
|
classes: BusinessServiceClass[],
|
||||||
|
classId?: string | null,
|
||||||
|
): number | null {
|
||||||
|
if (usesServiceClasses(classesEnabled, classes)) {
|
||||||
|
if (!classId) return null;
|
||||||
|
let total = 0;
|
||||||
|
for (const service of services) {
|
||||||
|
const price = resolvedServicePrice(service, classId);
|
||||||
|
if (!price) return null;
|
||||||
|
total += Number.parseFloat(price);
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
return services.reduce((sum, service) => sum + Number.parseFloat(service.price), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Booking flow helpers — `perClass` means class-based pricing is active for the selection. */
|
||||||
export function resolveServicePrice(
|
export function resolveServicePrice(
|
||||||
service: BusinessService,
|
service: BusinessService,
|
||||||
perClass: boolean,
|
perClass: boolean,
|
||||||
classId?: string,
|
classId?: string,
|
||||||
): string {
|
): string {
|
||||||
if (perClass && classId) {
|
if (perClass && classId) {
|
||||||
const classPrice = getClassPriceForService(service, classId);
|
return resolvedServicePrice(service, classId) ?? service.price;
|
||||||
if (classPrice) return classPrice.price;
|
|
||||||
}
|
}
|
||||||
return service.price;
|
return service.price;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function servicePriceLabel(
|
|
||||||
service: BusinessService,
|
|
||||||
perClass: boolean,
|
|
||||||
_classes: BusinessServiceClass[],
|
|
||||||
classId?: string,
|
|
||||||
): string {
|
|
||||||
return `${formatPriceToman(resolveServicePrice(service, perClass, classId))} تومان`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function serviceDurationLabel(
|
|
||||||
service: BusinessService,
|
|
||||||
perClass: boolean,
|
|
||||||
_classes: BusinessServiceClass[],
|
|
||||||
classId?: string,
|
|
||||||
): string {
|
|
||||||
const minutes = resolveServiceMinutes(service, perClass, classId);
|
|
||||||
if (minutes == null) return '—';
|
|
||||||
return `${minutes} دقیقه`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sumServicesPrice(
|
export function sumServicesPrice(
|
||||||
services: BusinessService[],
|
services: BusinessService[],
|
||||||
perClass: boolean,
|
perClass: boolean,
|
||||||
classId?: string,
|
classId?: string,
|
||||||
): number {
|
): number {
|
||||||
return services.reduce((total, service) => {
|
if (perClass && classId) {
|
||||||
const price = Number.parseFloat(resolveServicePrice(service, perClass, classId));
|
return (
|
||||||
return total + (Number.isFinite(price) ? price : 0);
|
totalPriceForServices(services, true, [], classId) ??
|
||||||
}, 0);
|
services.reduce((sum, service) => sum + Number.parseFloat(service.price), 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return services.reduce((sum, service) => sum + Number.parseFloat(service.price), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sumServicesDurationMinutes(
|
export function sumServicesDurationMinutes(
|
||||||
@@ -69,8 +222,5 @@ export function sumServicesDurationMinutes(
|
|||||||
perClass: boolean,
|
perClass: boolean,
|
||||||
classId?: string,
|
classId?: string,
|
||||||
): number {
|
): number {
|
||||||
return services.reduce((total, service) => {
|
return totalDurationForServices(services, perClass, [], classId);
|
||||||
const minutes = resolveServiceMinutes(service, perClass, classId);
|
|
||||||
return total + (minutes ?? 0);
|
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,21 @@
|
|||||||
این کسبوکار فعلاً غیرفعال است.
|
این کسبوکار فعلاً غیرفعال است.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else-if="isOwnBusinessView"
|
||||||
|
class="rounded-2xl border border-border bg-surface-2 p-6 text-center"
|
||||||
|
>
|
||||||
|
<p class="text-sm text-muted">
|
||||||
|
شما صاحب این کسبوکار هستید و نمیتوانید برای خودتان نوبت رزرو کنید.
|
||||||
|
</p>
|
||||||
|
<RouterLink
|
||||||
|
:to="{ name: 'app-owner' }"
|
||||||
|
class="mt-4 inline-flex items-center justify-center rounded-xl bg-brand-600 px-5 py-3 text-sm font-semibold text-white"
|
||||||
|
>
|
||||||
|
ورود به پنل مدیریت
|
||||||
|
</RouterLink>
|
||||||
|
</div>
|
||||||
|
|
||||||
<DesktopBookingFlow
|
<DesktopBookingFlow
|
||||||
v-else
|
v-else
|
||||||
:business="business"
|
:business="business"
|
||||||
@@ -32,7 +47,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { computed, onMounted, ref } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||||
import { fetchBusinessServices } from '@/api/business-services';
|
import { fetchBusinessServices } from '@/api/business-services';
|
||||||
import { fetchBusiness } from '@/api/businesses';
|
import { fetchBusiness } from '@/api/businesses';
|
||||||
import { ApiError } from '@/api/client';
|
import { ApiError } from '@/api/client';
|
||||||
@@ -40,10 +55,12 @@ import type { Business, BusinessService } from '@/api/types';
|
|||||||
import DesktopBookingFlow from '@/components/booking/DesktopBookingFlow.vue';
|
import DesktopBookingFlow from '@/components/booking/DesktopBookingFlow.vue';
|
||||||
import DetailPageSkeleton from '@/components/ui/DetailPageSkeleton.vue';
|
import DetailPageSkeleton from '@/components/ui/DetailPageSkeleton.vue';
|
||||||
import ResponsiveAppLayout from '@/layouts/ResponsiveAppLayout.vue';
|
import ResponsiveAppLayout from '@/layouts/ResponsiveAppLayout.vue';
|
||||||
|
import { useOwnedBusiness } from '@/composables/useOwnedBusiness';
|
||||||
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
|
import { loginRouteWithRedirect } from '@/utils/auth-redirect';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { ensureLoaded, isOwnBusiness } = useOwnedBusiness();
|
||||||
|
|
||||||
const business = ref<Business | null>(null);
|
const business = ref<Business | null>(null);
|
||||||
const services = ref<BusinessService[]>([]);
|
const services = ref<BusinessService[]>([]);
|
||||||
@@ -54,6 +71,10 @@ const servicesError = ref('');
|
|||||||
|
|
||||||
const homeRoute = computed(() => ({ name: 'app-home' }));
|
const homeRoute = computed(() => ({ name: 'app-home' }));
|
||||||
|
|
||||||
|
const isOwnBusinessView = computed(() =>
|
||||||
|
business.value ? isOwnBusiness(business.value.id) : false,
|
||||||
|
);
|
||||||
|
|
||||||
async function loadBusiness() {
|
async function loadBusiness() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
error.value = '';
|
error.value = '';
|
||||||
@@ -84,7 +105,10 @@ function goToLoginForBooking() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
await ensureLoaded();
|
||||||
await loadBusiness();
|
await loadBusiness();
|
||||||
await loadServices();
|
if (!isOwnBusinessView.value) {
|
||||||
|
await loadServices();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -4,14 +4,20 @@
|
|||||||
:services="landingServices"
|
:services="landingServices"
|
||||||
:loading-services="loadingLandingServices"
|
:loading-services="loadingLandingServices"
|
||||||
:services-error="landingServicesError"
|
:services-error="landingServicesError"
|
||||||
|
:booking-enabled="canBookSingleBusiness"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<WebAppLayout v-else-if="showMobileLanding">
|
<WebAppLayout v-else-if="showMobileLanding">
|
||||||
<HomeHeroSection @book="goToBooking" @browse="scrollToServices" />
|
<HomeHeroSection
|
||||||
|
:show-book-button="canBookSingleBusiness"
|
||||||
|
@book="goToBooking"
|
||||||
|
@browse="scrollToServices"
|
||||||
|
/>
|
||||||
<HomeServicesSection
|
<HomeServicesSection
|
||||||
:items="landingServices"
|
:items="landingServices"
|
||||||
:loading="loadingLandingServices"
|
:loading="loadingLandingServices"
|
||||||
:error="landingServicesError"
|
:error="landingServicesError"
|
||||||
|
:booking-enabled="canBookSingleBusiness"
|
||||||
/>
|
/>
|
||||||
<HomeFeatureBar />
|
<HomeFeatureBar />
|
||||||
</WebAppLayout>
|
</WebAppLayout>
|
||||||
@@ -43,13 +49,17 @@ import DesktopDiscoveryPage from '@/components/landing/DesktopDiscoveryPage.vue'
|
|||||||
import DesktopLandingPage from '@/components/landing/DesktopLandingPage.vue';
|
import DesktopLandingPage from '@/components/landing/DesktopLandingPage.vue';
|
||||||
import BusinessCardSkeleton from '@/components/ui/BusinessCardSkeleton.vue';
|
import BusinessCardSkeleton from '@/components/ui/BusinessCardSkeleton.vue';
|
||||||
import WebAppLayout from '@/layouts/WebAppLayout.vue';
|
import WebAppLayout from '@/layouts/WebAppLayout.vue';
|
||||||
|
import { useOwnedBusiness } from '@/composables/useOwnedBusiness';
|
||||||
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import { useTenantStore } from '@/stores/tenant';
|
import { useTenantStore } from '@/stores/tenant';
|
||||||
import type { LandingServiceItem } from '@/types/landing';
|
import type { LandingServiceItem } from '@/types/landing';
|
||||||
import { fetchLandingServices } from '@/utils/landing-services';
|
import { fetchLandingServices } from '@/utils/landing-services';
|
||||||
|
|
||||||
const isDesktop = useMediaQuery('(min-width: 1024px)');
|
const isDesktop = useMediaQuery('(min-width: 1024px)');
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const auth = useAuthStore();
|
||||||
const tenant = useTenantStore();
|
const tenant = useTenantStore();
|
||||||
|
const { ensureLoaded, isOwnBusiness } = useOwnedBusiness();
|
||||||
|
|
||||||
const landingServices = ref<LandingServiceItem[]>([]);
|
const landingServices = ref<LandingServiceItem[]>([]);
|
||||||
const loadingLandingServices = ref(false);
|
const loadingLandingServices = ref(false);
|
||||||
@@ -67,6 +77,12 @@ const showSingleBusinessLanding = computed(
|
|||||||
() => showDesktopLanding.value || showMobileLanding.value,
|
() => showDesktopLanding.value || showMobileLanding.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const canBookSingleBusiness = computed(() => {
|
||||||
|
const businessId = tenant.singleBusinessId;
|
||||||
|
if (!businessId) return true;
|
||||||
|
return !isOwnBusiness(businessId);
|
||||||
|
});
|
||||||
|
|
||||||
async function loadLandingServices() {
|
async function loadLandingServices() {
|
||||||
if (!tenant.singleBusinessId) return;
|
if (!tenant.singleBusinessId) return;
|
||||||
|
|
||||||
@@ -87,6 +103,11 @@ function scrollToServices() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function goToBooking() {
|
function goToBooking() {
|
||||||
|
if (!canBookSingleBusiness.value) {
|
||||||
|
void router.push({ name: 'app-owner' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const id = tenant.singleBusinessId;
|
const id = tenant.singleBusinessId;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
scrollToServices();
|
scrollToServices();
|
||||||
@@ -106,6 +127,11 @@ watch(showSingleBusinessLanding, (show) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
if (auth.isLoggedIn) {
|
||||||
|
await auth.loadUser();
|
||||||
|
await ensureLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
await tenant.bootstrap();
|
await tenant.bootstrap();
|
||||||
|
|
||||||
if (showSingleBusinessLanding.value) {
|
if (showSingleBusinessLanding.value) {
|
||||||
|
|||||||
+819
-58
@@ -3,128 +3,889 @@
|
|||||||
<h1 class="mb-1 text-xl font-bold text-text">مدیریت کسبوکار</h1>
|
<h1 class="mb-1 text-xl font-bold text-text">مدیریت کسبوکار</h1>
|
||||||
<p class="mb-6 text-sm text-muted">تنظیمات کسبوکار، خدمات و ساعات کاری</p>
|
<p class="mb-6 text-sm text-muted">تنظیمات کسبوکار، خدمات و ساعات کاری</p>
|
||||||
|
|
||||||
<FormPageSkeleton v-if="loading" />
|
|
||||||
|
|
||||||
<p
|
<p
|
||||||
v-else-if="error"
|
v-if="error"
|
||||||
class="rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-400"
|
class="mb-4 rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600"
|
||||||
>
|
>
|
||||||
{{ error }}
|
{{ error }}
|
||||||
</p>
|
</p>
|
||||||
|
<p
|
||||||
|
v-if="message"
|
||||||
|
class="mb-4 rounded-xl border border-brand-500/40 bg-brand-500/10 px-4 py-3 text-sm text-brand-700 dark:text-brand-500"
|
||||||
|
>
|
||||||
|
{{ message }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<FormPageSkeleton v-if="loading" />
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else-if="!business"
|
||||||
|
class="rounded-2xl border border-dashed border-border p-6 text-center text-sm text-muted"
|
||||||
|
>
|
||||||
|
کسبوکاری به حساب شما وصل نیست.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="mx-auto max-w-3xl space-y-8">
|
||||||
|
<form class="space-y-4" @submit.prevent="onSave">
|
||||||
|
<h2 class="text-base font-semibold text-text">اطلاعات کسبوکار</h2>
|
||||||
|
|
||||||
|
<dl class="space-y-3 rounded-2xl border border-border bg-surface-2 p-4">
|
||||||
|
<div class="flex items-center justify-between gap-4">
|
||||||
|
<dt class="shrink-0 text-xs text-muted">دسته</dt>
|
||||||
|
<dd class="font-medium text-text">{{ business.category?.title ?? '—' }}</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-4">
|
||||||
|
<dt class="shrink-0 text-xs text-muted">وضعیت</dt>
|
||||||
|
<dd>
|
||||||
|
<span
|
||||||
|
class="inline-block rounded-lg px-2 py-0.5 text-xs"
|
||||||
|
:class="business.isActive ? 'bg-green-500/15 text-green-700' : 'bg-amber-500/15 text-amber-700'"
|
||||||
|
>
|
||||||
|
{{ business.isActive ? 'فعال' : 'غیرفعال' }}
|
||||||
|
</span>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
|
||||||
<div v-else-if="business" class="mx-auto max-w-3xl space-y-6">
|
|
||||||
<form class="space-y-4 rounded-2xl border border-border bg-surface-2 p-4" @submit.prevent="saveBusiness">
|
|
||||||
<AppInput id="ownerTitle" v-model="form.title" label="نام کسبوکار" required />
|
<AppInput id="ownerTitle" v-model="form.title" label="نام کسبوکار" required />
|
||||||
<AppInput id="ownerSubtitle" v-model="form.subtitle" label="زیرعنوان" />
|
<AppInput id="ownerSubtitle" v-model="form.subtitle" label="زیرعنوان" />
|
||||||
<AppTextarea id="ownerDescription" v-model="form.description" label="توضیحات" />
|
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label for="ownerDesc" class="block text-sm font-medium text-muted">توضیحات</label>
|
||||||
|
<textarea
|
||||||
|
id="ownerDesc"
|
||||||
|
v-model="form.description"
|
||||||
|
rows="3"
|
||||||
|
class="w-full rounded-xl border border-border bg-surface-2 px-4 py-3 text-text outline-none focus:border-brand-500 focus:ring-2 focus:ring-brand-500/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AppInput
|
||||||
|
id="ownerPhone"
|
||||||
|
v-model="form.contactPhone"
|
||||||
|
label="تلفن"
|
||||||
|
type="tel"
|
||||||
|
inputmode="tel"
|
||||||
|
ltr
|
||||||
|
/>
|
||||||
<AppInput id="ownerAddress" v-model="form.address" label="آدرس" />
|
<AppInput id="ownerAddress" v-model="form.address" label="آدرس" />
|
||||||
<AppInput id="ownerPhone" v-model="form.phone" label="تلفن" ltr />
|
|
||||||
<p v-if="saveMessage" class="text-sm text-brand-700 dark:text-brand-500">{{ saveMessage }}</p>
|
<AppButton type="submit" :loading="saving">ذخیره تغییرات</AppButton>
|
||||||
<AppButton type="submit" :loading="saving">ذخیره اطلاعات</AppButton>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<ServiceClassManager
|
<section class="border-t border-border pt-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-full items-center justify-between gap-3 rounded-2xl border border-border bg-surface-2 px-4 py-3 text-start transition hover:border-brand-500/30"
|
||||||
|
:aria-expanded="bookingExpanded"
|
||||||
|
@click="bookingExpanded = !bookingExpanded"
|
||||||
|
>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<AppIcon name="calendar" size="sm" class="text-brand-600 dark:text-brand-500" />
|
||||||
|
<h2 class="text-base font-semibold text-text">تنظیمات نوبتدهی</h2>
|
||||||
|
</div>
|
||||||
|
<p v-if="!bookingExpanded" class="mt-1 truncate text-xs text-muted">
|
||||||
|
{{ bookingSummary }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<AppIcon
|
||||||
|
:name="bookingExpanded ? 'chevron-up' : 'chevron-down'"
|
||||||
|
size="sm"
|
||||||
|
class="shrink-0 text-muted"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div v-show="bookingExpanded" class="mt-3 space-y-4">
|
||||||
|
<AppInput
|
||||||
|
id="ownerConcurrentCapacity"
|
||||||
|
v-model="bookingForm.concurrentCapacity"
|
||||||
|
label="پذیرش همزمان"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
ltr
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<p class="-mt-2 text-xs text-muted">
|
||||||
|
حداکثر تعداد مشتری که همزمان میتوانید پذیرش کنید. مثلاً ۳ یعنی هر ساعت تا ۳ رزرو همپوشان.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<AppInput
|
||||||
|
id="ownerSlotStep"
|
||||||
|
v-model="bookingForm.slotStepMinutes"
|
||||||
|
label="گام نوبتدهی (دقیقه)"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
ltr
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<p class="-mt-2 text-xs text-muted">
|
||||||
|
فاصله بین ساعتهای قابل رزرو. مثلاً ۳۰ یعنی ۱۰:۰۰، ۱۰:۳۰، ۱۱:۰۰ و …
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<AppButton :loading="savingBooking" @click="onSaveBookingSettings">
|
||||||
|
ذخیره تنظیمات نوبتدهی
|
||||||
|
</AppButton>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<BusinessAvailabilityEditor
|
||||||
|
v-if="business"
|
||||||
:business-id="business.id"
|
:business-id="business.id"
|
||||||
:enabled="serviceClassesEnabled"
|
|
||||||
@update:enabled="setServiceClassesEnabled"
|
|
||||||
/>
|
/>
|
||||||
<BusinessAvailabilityEditor :business-id="business.id" />
|
|
||||||
|
<ServiceClassManager
|
||||||
|
v-if="business"
|
||||||
|
:business-id="business.id"
|
||||||
|
:enabled="business.serviceClassesEnabled === true"
|
||||||
|
@updated="onServiceClassesUpdated"
|
||||||
|
@update:enabled="onServiceClassesEnabledChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<section class="border-t border-border pt-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-full items-center justify-between gap-3 rounded-2xl border border-border bg-surface-2 px-4 py-3 text-start transition hover:border-brand-500/30"
|
||||||
|
:aria-expanded="servicesExpanded"
|
||||||
|
@click="servicesExpanded = !servicesExpanded"
|
||||||
|
>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<AppIcon name="clipboard-list" size="sm" class="text-brand-600 dark:text-brand-500" />
|
||||||
|
<h2 class="text-base font-semibold text-text">خدمات و قیمتها</h2>
|
||||||
|
</div>
|
||||||
|
<p v-if="!servicesExpanded" class="mt-1 truncate text-xs text-muted">
|
||||||
|
{{ servicesSummary }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<AppIcon
|
||||||
|
:name="servicesExpanded ? 'chevron-up' : 'chevron-down'"
|
||||||
|
size="sm"
|
||||||
|
class="shrink-0 text-muted"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div v-show="servicesExpanded" class="mt-3 space-y-4">
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
خدماتی که اینجا ثبت میکنید در صفحه کسبوکار برای مشتریان و مقایسه نمایش داده میشود.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ListCardSkeleton v-if="loadingServices" :count="3" />
|
||||||
|
|
||||||
|
<ul v-else-if="services.length" class="space-y-2">
|
||||||
|
<li
|
||||||
|
v-for="svc in services"
|
||||||
|
:key="svc.id"
|
||||||
|
class="rounded-xl border border-border bg-surface-2 p-3"
|
||||||
|
>
|
||||||
|
<div class="flex items-start justify-between gap-2">
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<p class="font-medium text-text">
|
||||||
|
{{ svc.serviceTemplate?.title ?? 'خدمت' }}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
v-if="svc.serviceTemplate?.description"
|
||||||
|
class="mt-0.5 text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ svc.serviceTemplate.description }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex shrink-0 items-center gap-1">
|
||||||
|
<label class="flex items-center gap-1 text-xs text-muted">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
:checked="svc.isActive"
|
||||||
|
@change="onToggleActive(svc)"
|
||||||
|
/>
|
||||||
|
فعال
|
||||||
|
</label>
|
||||||
|
<template v-if="editingId !== svc.id">
|
||||||
|
<AppIconButton icon="pencil" label="ویرایش خدمت" @click="startEdit(svc)" />
|
||||||
|
<AppIconButton icon="trash" label="حذف خدمت" variant="danger" @click="onDelete(svc)" />
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="editingId === svc.id" class="mt-3 space-y-2">
|
||||||
|
<template v-if="hasServiceClasses">
|
||||||
|
<p class="text-sm font-medium text-text">قیمت بر اساس کلاس</p>
|
||||||
|
<div
|
||||||
|
v-for="cls in activeClasses"
|
||||||
|
:key="cls.id"
|
||||||
|
class="space-y-2 rounded-xl border border-border bg-surface px-3 py-3"
|
||||||
|
>
|
||||||
|
<p class="text-sm font-medium text-text">{{ cls.title }}</p>
|
||||||
|
<PriceInput
|
||||||
|
:id="`edit-class-price-${svc.id}-${cls.id}`"
|
||||||
|
v-model="editClassPrices[cls.id].price"
|
||||||
|
label="قیمت (تومان)"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<AppInput
|
||||||
|
:id="`edit-class-duration-${svc.id}-${cls.id}`"
|
||||||
|
v-model="editClassPrices[cls.id].durationMinutes"
|
||||||
|
label="مدت (دقیقه — اختیاری)"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
ltr
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<PriceInput
|
||||||
|
id="editPrice"
|
||||||
|
v-model="editForm.price"
|
||||||
|
label="قیمت (تومان)"
|
||||||
|
/>
|
||||||
|
<AppInput
|
||||||
|
id="editDuration"
|
||||||
|
v-model="editForm.durationMinutes"
|
||||||
|
label="مدت (دقیقه)"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
ltr
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<AppButton class="!w-auto flex-1" :loading="savingService" @click="onSaveEdit(svc)">
|
||||||
|
ذخیره
|
||||||
|
</AppButton>
|
||||||
|
<AppButton variant="ghost" class="!w-auto px-4" @click="cancelEdit">
|
||||||
|
انصراف
|
||||||
|
</AppButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="mt-2 space-y-2 text-sm text-muted">
|
||||||
|
<template v-if="hasServiceClasses">
|
||||||
|
<div
|
||||||
|
v-for="cls in activeClasses"
|
||||||
|
:key="cls.id"
|
||||||
|
class="flex flex-wrap items-center gap-2"
|
||||||
|
>
|
||||||
|
<span class="font-medium text-text">{{ cls.title }}:</span>
|
||||||
|
<span>{{ servicePriceLabel(svc, true, serviceClasses, cls.id) }}</span>
|
||||||
|
<template v-if="getClassPriceForService(svc, cls.id)">
|
||||||
|
<span>·</span>
|
||||||
|
<span>{{ serviceDurationLabel(svc, true, serviceClasses, cls.id) }}</span>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div v-else class="flex flex-wrap items-center gap-2">
|
||||||
|
<span>{{ formatPriceToman(svc.price) }} تومان</span>
|
||||||
|
<span>·</span>
|
||||||
|
<span>{{ serviceDurationLabel(svc, false, serviceClasses) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p v-else class="text-sm text-muted">هنوز خدمتی ثبت نشده است.</p>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="!loadingServices && templates.length === 0"
|
||||||
|
class="rounded-xl border border-dashed border-border bg-surface-2 p-4 text-sm text-muted"
|
||||||
|
>
|
||||||
|
برای دسته «{{ business.category?.title }}» هنوز نوع خدمتی تعریف نشده. از مدیر سیستم
|
||||||
|
بخواهید قالب خدمت اضافه کند.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
v-else-if="availableTemplates.length"
|
||||||
|
class="space-y-3 rounded-2xl border border-border bg-surface-2 p-4"
|
||||||
|
@submit.prevent="onAddService"
|
||||||
|
>
|
||||||
|
<p class="text-sm font-medium text-text">افزودن خدمت</p>
|
||||||
|
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label for="svcTemplate" class="block text-sm font-medium text-muted">نوع خدمت</label>
|
||||||
|
<select
|
||||||
|
id="svcTemplate"
|
||||||
|
v-model="serviceForm.serviceTemplateId"
|
||||||
|
required
|
||||||
|
class="w-full rounded-xl border border-border bg-surface px-4 py-3 text-text outline-none focus:border-brand-500"
|
||||||
|
>
|
||||||
|
<option value="" disabled>انتخاب کنید</option>
|
||||||
|
<option v-for="tpl in availableTemplates" :key="tpl.id" :value="tpl.id">
|
||||||
|
{{ tpl.title }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<PriceInput
|
||||||
|
v-if="!hasServiceClasses"
|
||||||
|
id="svcPrice"
|
||||||
|
v-model="serviceForm.price"
|
||||||
|
label="قیمت (تومان)"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<AppInput
|
||||||
|
v-if="!hasServiceClasses"
|
||||||
|
id="svcDuration"
|
||||||
|
v-model="serviceForm.durationMinutes"
|
||||||
|
label="مدت (دقیقه — اختیاری)"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
ltr
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div v-if="hasServiceClasses" class="space-y-2">
|
||||||
|
<p class="text-sm font-medium text-text">قیمت بر اساس کلاس</p>
|
||||||
|
<div
|
||||||
|
v-for="cls in activeClasses"
|
||||||
|
:key="cls.id"
|
||||||
|
class="space-y-2 rounded-xl border border-border bg-surface px-3 py-3"
|
||||||
|
>
|
||||||
|
<p class="text-sm font-medium text-text">{{ cls.title }}</p>
|
||||||
|
<PriceInput
|
||||||
|
:id="`add-class-price-${cls.id}`"
|
||||||
|
v-model="classPriceForm[cls.id].price"
|
||||||
|
label="قیمت (تومان)"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<AppInput
|
||||||
|
:id="`add-class-duration-${cls.id}`"
|
||||||
|
v-model="classPriceForm[cls.id].durationMinutes"
|
||||||
|
label="مدت (دقیقه — اختیاری)"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
ltr
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AppButton type="submit" :loading="addingService">افزودن</AppButton>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p
|
||||||
|
v-else-if="!loadingServices && templates.length && !availableTemplates.length"
|
||||||
|
class="text-sm text-muted"
|
||||||
|
>
|
||||||
|
همهٔ انواع خدمت این دسته را اضافه کردهاید.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<section class="space-y-3 rounded-2xl border border-dashed border-brand-500/40 bg-brand-500/5 p-4">
|
||||||
|
<h3 class="text-sm font-semibold text-text">خدمت سفارشی (خارج از لیست ادمین)</h3>
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
اگر خدمتی در لیست بالا نیست، اینجا پیشنهاد دهید. پس از تأیید مدیر، به خدمات کسبوکار شما
|
||||||
|
اضافه میشود.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul v-if="serviceRequests.length" class="space-y-2">
|
||||||
|
<li
|
||||||
|
v-for="req in serviceRequests"
|
||||||
|
:key="req.id"
|
||||||
|
class="rounded-xl border border-border bg-surface-2 px-3 py-2 text-sm"
|
||||||
|
>
|
||||||
|
<p class="font-medium text-text">{{ req.title }}</p>
|
||||||
|
<p class="mt-0.5 text-xs text-muted">
|
||||||
|
{{ formatPriceToman(req.price) }} تومان
|
||||||
|
<span v-if="req.durationMinutes"> · {{ req.durationMinutes }} دقیقه</span>
|
||||||
|
</p>
|
||||||
|
<span
|
||||||
|
class="mt-1 inline-block rounded-lg px-2 py-0.5 text-xs"
|
||||||
|
:class="requestStatusClass(req.status)"
|
||||||
|
>
|
||||||
|
{{ requestStatusLabel(req.status) }}
|
||||||
|
</span>
|
||||||
|
<p v-if="req.adminNote" class="mt-1 text-xs text-red-600">{{ req.adminNote }}</p>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<form class="space-y-3" @submit.prevent="onAddCustomService">
|
||||||
|
<AppInput id="customTitle" v-model="customForm.title" label="نام خدمت" required />
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label for="customDesc" class="block text-sm font-medium text-muted">توضیح (اختیاری)</label>
|
||||||
|
<textarea
|
||||||
|
id="customDesc"
|
||||||
|
v-model="customForm.description"
|
||||||
|
rows="2"
|
||||||
|
class="w-full rounded-xl border border-border bg-surface-2 px-4 py-3 text-text outline-none focus:border-brand-500 focus:ring-2 focus:ring-brand-500/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<PriceInput id="customPrice" v-model="customForm.price" label="قیمت پیشنهادی (تومان)" required />
|
||||||
|
<AppInput
|
||||||
|
id="customDuration"
|
||||||
|
v-model="customForm.durationMinutes"
|
||||||
|
label="مدت (دقیقه — اختیاری)"
|
||||||
|
type="number"
|
||||||
|
inputmode="numeric"
|
||||||
|
ltr
|
||||||
|
/>
|
||||||
|
<AppButton type="submit" :loading="addingCustom">ارسال برای تأیید</AppButton>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</ResponsiveAppLayout>
|
</ResponsiveAppLayout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from 'vue';
|
import { computed, onMounted, ref } from 'vue';
|
||||||
import { fetchMyBusinesses, updateBusiness } from '@/api/businesses';
|
import { fetchMyBusinesses, updateBusiness } from '@/api/businesses';
|
||||||
|
import {
|
||||||
|
createServiceRequest,
|
||||||
|
fetchMyServiceRequests,
|
||||||
|
} from '@/api/business-service-requests';
|
||||||
|
import {
|
||||||
|
createBusinessService,
|
||||||
|
deleteBusinessService,
|
||||||
|
fetchBusinessServices,
|
||||||
|
setBusinessServiceClassPrices,
|
||||||
|
updateBusinessService,
|
||||||
|
type ClassPriceItem,
|
||||||
|
} from '@/api/business-services';
|
||||||
|
import { fetchServiceTemplates } from '@/api/service-templates';
|
||||||
|
import type {
|
||||||
|
Business,
|
||||||
|
BusinessService,
|
||||||
|
BusinessServiceClass,
|
||||||
|
BusinessServiceRequest,
|
||||||
|
BusinessServiceRequestStatus,
|
||||||
|
} from '@/api/types';
|
||||||
import { ApiError } from '@/api/client';
|
import { ApiError } from '@/api/client';
|
||||||
import type { Business } from '@/api/types';
|
|
||||||
import BusinessAvailabilityEditor from '@/components/owner/BusinessAvailabilityEditor.vue';
|
import BusinessAvailabilityEditor from '@/components/owner/BusinessAvailabilityEditor.vue';
|
||||||
import ServiceClassManager from '@/components/owner/ServiceClassManager.vue';
|
import ServiceClassManager from '@/components/owner/ServiceClassManager.vue';
|
||||||
import AppButton from '@/components/ui/AppButton.vue';
|
|
||||||
import AppInput from '@/components/ui/AppInput.vue';
|
|
||||||
import AppTextarea from '@/components/ui/AppTextarea.vue';
|
|
||||||
import FormPageSkeleton from '@/components/ui/FormPageSkeleton.vue';
|
import FormPageSkeleton from '@/components/ui/FormPageSkeleton.vue';
|
||||||
|
import ListCardSkeleton from '@/components/ui/ListCardSkeleton.vue';
|
||||||
|
import AppButton from '@/components/ui/AppButton.vue';
|
||||||
|
import AppIcon from '@/components/ui/AppIcon.vue';
|
||||||
|
import AppIconButton from '@/components/ui/AppIconButton.vue';
|
||||||
|
import AppInput from '@/components/ui/AppInput.vue';
|
||||||
|
import PriceInput from '@/components/ui/PriceInput.vue';
|
||||||
import ResponsiveAppLayout from '@/layouts/ResponsiveAppLayout.vue';
|
import ResponsiveAppLayout from '@/layouts/ResponsiveAppLayout.vue';
|
||||||
import { useTenantStore } from '@/stores/tenant';
|
import { useTenantStore } from '@/stores/tenant';
|
||||||
|
import {
|
||||||
|
formatPriceInputDisplay,
|
||||||
|
formatPriceToman,
|
||||||
|
parseOptionalMinutes,
|
||||||
|
parsePriceInput,
|
||||||
|
} from '@/utils/format';
|
||||||
|
import {
|
||||||
|
activeServiceClasses,
|
||||||
|
getClassPriceForService,
|
||||||
|
serviceDurationLabel,
|
||||||
|
servicePriceLabel,
|
||||||
|
} from '@/utils/service-pricing';
|
||||||
|
|
||||||
const tenant = useTenantStore();
|
const tenant = useTenantStore();
|
||||||
const business = ref<Business | null>(null);
|
const business = ref<Business | null>(null);
|
||||||
|
const services = ref<BusinessService[]>([]);
|
||||||
|
const serviceClasses = ref<BusinessServiceClass[]>([]);
|
||||||
|
const templates = ref<Awaited<ReturnType<typeof fetchServiceTemplates>>>([]);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
|
const loadingServices = ref(false);
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
|
const savingBooking = ref(false);
|
||||||
|
const savingService = ref(false);
|
||||||
|
const addingService = ref(false);
|
||||||
|
const addingCustom = ref(false);
|
||||||
|
const serviceRequests = ref<BusinessServiceRequest[]>([]);
|
||||||
const error = ref('');
|
const error = ref('');
|
||||||
const saveMessage = ref('');
|
const message = ref('');
|
||||||
const serviceClassesEnabled = ref(false);
|
const editingId = ref<string | null>(null);
|
||||||
|
const servicesExpanded = ref(false);
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
title: '',
|
title: '',
|
||||||
subtitle: '',
|
subtitle: '',
|
||||||
description: '',
|
description: '',
|
||||||
|
contactPhone: '',
|
||||||
address: '',
|
address: '',
|
||||||
phone: '',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function loadBusiness() {
|
const bookingForm = ref({
|
||||||
loading.value = true;
|
concurrentCapacity: '1',
|
||||||
error.value = '';
|
slotStepMinutes: '30',
|
||||||
try {
|
});
|
||||||
const items = await fetchMyBusinesses();
|
|
||||||
business.value = items[0] ?? null;
|
const bookingExpanded = ref(false);
|
||||||
if (!business.value) {
|
|
||||||
error.value = 'کسبوکاری برای مدیریت یافت نشد.';
|
const serviceForm = ref({
|
||||||
return;
|
serviceTemplateId: '',
|
||||||
}
|
price: '',
|
||||||
form.value = {
|
durationMinutes: '',
|
||||||
title: business.value.title,
|
});
|
||||||
subtitle: business.value.subtitle ?? '',
|
|
||||||
description: business.value.description ?? '',
|
const editForm = ref({
|
||||||
address: business.value.address ?? '',
|
price: '',
|
||||||
phone: business.value.phone ?? '',
|
durationMinutes: '',
|
||||||
};
|
});
|
||||||
serviceClassesEnabled.value = business.value.serviceClassesEnabled ?? false;
|
|
||||||
} catch (e) {
|
const classPriceForm = ref<Record<string, { price: string; durationMinutes: string }>>({});
|
||||||
error.value = e instanceof ApiError ? e.message : 'بارگذاری کسبوکار ناموفق بود.';
|
const editClassPrices = ref<Record<string, { price: string; durationMinutes: string }>>({});
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
const customForm = ref({
|
||||||
|
title: '',
|
||||||
|
description: '',
|
||||||
|
price: '',
|
||||||
|
durationMinutes: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const availableTemplates = computed(() => {
|
||||||
|
const used = new Set(services.value.map((s) => s.serviceTemplateId));
|
||||||
|
return templates.value.filter((t) => !used.has(t.id));
|
||||||
|
});
|
||||||
|
|
||||||
|
const activeClasses = computed(() => activeServiceClasses(serviceClasses.value));
|
||||||
|
const hasServiceClasses = computed(
|
||||||
|
() => business.value?.serviceClassesEnabled === true && activeClasses.value.length > 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
const servicesSummary = computed(() => {
|
||||||
|
if (loadingServices.value) return '…';
|
||||||
|
const count = services.value.length;
|
||||||
|
if (count === 0) return 'هنوز خدمتی ثبت نشده';
|
||||||
|
const activeCount = services.value.filter((s) => s.isActive).length;
|
||||||
|
return `${count} خدمت · ${activeCount} فعال`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const bookingSummary = computed(
|
||||||
|
() =>
|
||||||
|
`${bookingForm.value.concurrentCapacity} همزمان · گام ${bookingForm.value.slotStepMinutes} دقیقه`,
|
||||||
|
);
|
||||||
|
|
||||||
|
function emptyClassPriceForm() {
|
||||||
|
const result: Record<string, { price: string; durationMinutes: string }> = {};
|
||||||
|
for (const cls of activeClasses.value) {
|
||||||
|
result[cls.id] = { price: '', durationMinutes: '' };
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setServiceClassesEnabled(value: boolean) {
|
function buildClassPricesPayload(
|
||||||
|
form: Record<string, { price: string; durationMinutes: string }>,
|
||||||
|
): ClassPriceItem[] | null {
|
||||||
|
const prices: ClassPriceItem[] = [];
|
||||||
|
for (const cls of activeClasses.value) {
|
||||||
|
const row = form[cls.id];
|
||||||
|
const price = parsePriceInput(row?.price ?? '');
|
||||||
|
if (price === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const duration = parseOptionalMinutes(row?.durationMinutes ?? '');
|
||||||
|
if (duration === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
prices.push({
|
||||||
|
classId: cls.id,
|
||||||
|
price,
|
||||||
|
durationMinutes: duration && duration > 0 ? duration : null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return prices;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onServiceClassesUpdated(classes: BusinessServiceClass[]) {
|
||||||
|
serviceClasses.value = classes;
|
||||||
|
classPriceForm.value = emptyClassPriceForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onServiceClassesEnabledChange(value: boolean) {
|
||||||
if (!business.value) return;
|
if (!business.value) return;
|
||||||
const previous = serviceClassesEnabled.value;
|
error.value = '';
|
||||||
serviceClassesEnabled.value = value;
|
message.value = '';
|
||||||
try {
|
try {
|
||||||
business.value = await updateBusiness(business.value.id, {
|
business.value = await updateBusiness(business.value.id, {
|
||||||
serviceClassesEnabled: value,
|
serviceClassesEnabled: value,
|
||||||
});
|
});
|
||||||
tenant.syncSingleBusiness(business.value);
|
tenant.syncSingleBusiness(business.value);
|
||||||
|
if (!value) {
|
||||||
|
serviceClasses.value = [];
|
||||||
|
classPriceForm.value = {};
|
||||||
|
}
|
||||||
|
message.value = value
|
||||||
|
? 'کلاسبندی فعال شد. کلاسهای خود را تعریف کنید.'
|
||||||
|
: 'کلاسبندی غیرفعال شد. قیمتگذاری به حالت عادی برمیگردد.';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
serviceClassesEnabled.value = previous;
|
error.value = e instanceof ApiError ? e.message : 'تغییر وضعیت کلاسبندی ناموفق بود';
|
||||||
error.value =
|
|
||||||
e instanceof ApiError ? e.message : 'ذخیره وضعیت کلاسبندی ناموفق بود.';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveBusiness() {
|
async function loadServicesAndTemplates() {
|
||||||
|
if (!business.value) return;
|
||||||
|
loadingServices.value = true;
|
||||||
|
try {
|
||||||
|
const [svcList, tplList, reqs] = await Promise.all([
|
||||||
|
fetchBusinessServices(business.value.id),
|
||||||
|
fetchServiceTemplates(business.value.categoryId),
|
||||||
|
fetchMyServiceRequests(),
|
||||||
|
]);
|
||||||
|
services.value = svcList;
|
||||||
|
templates.value = tplList;
|
||||||
|
serviceRequests.value = reqs;
|
||||||
|
if (availableTemplates.value[0] && !serviceForm.value.serviceTemplateId) {
|
||||||
|
serviceForm.value.serviceTemplateId = availableTemplates.value[0].id;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'خطا در بارگذاری خدمات';
|
||||||
|
} finally {
|
||||||
|
loadingServices.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
loading.value = true;
|
||||||
|
error.value = '';
|
||||||
|
try {
|
||||||
|
const list = await fetchMyBusinesses();
|
||||||
|
business.value = list[0] ?? null;
|
||||||
|
if (business.value) {
|
||||||
|
form.value = {
|
||||||
|
title: business.value.title,
|
||||||
|
subtitle: business.value.subtitle ?? '',
|
||||||
|
description: business.value.description ?? '',
|
||||||
|
contactPhone: business.value.contactPhone ?? business.value.phone ?? '',
|
||||||
|
address: business.value.address ?? '',
|
||||||
|
};
|
||||||
|
bookingForm.value = {
|
||||||
|
concurrentCapacity: String(business.value.concurrentCapacity ?? 1),
|
||||||
|
slotStepMinutes: String(business.value.slotStepMinutes ?? 30),
|
||||||
|
};
|
||||||
|
await loadServicesAndTemplates();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'خطا در بارگذاری';
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function onSave() {
|
||||||
if (!business.value) return;
|
if (!business.value) return;
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
saveMessage.value = '';
|
error.value = '';
|
||||||
|
message.value = '';
|
||||||
try {
|
try {
|
||||||
business.value = await updateBusiness(business.value.id, {
|
business.value = await updateBusiness(business.value.id, {
|
||||||
title: form.value.title.trim(),
|
title: form.value.title.trim(),
|
||||||
subtitle: form.value.subtitle.trim() || null,
|
subtitle: form.value.subtitle.trim() || null,
|
||||||
description: form.value.description.trim() || null,
|
description: form.value.description.trim() || null,
|
||||||
|
contactPhone: form.value.contactPhone.trim() || null,
|
||||||
address: form.value.address.trim() || null,
|
address: form.value.address.trim() || null,
|
||||||
phone: form.value.phone.trim() || null,
|
|
||||||
});
|
});
|
||||||
tenant.syncSingleBusiness(business.value);
|
tenant.syncSingleBusiness(business.value);
|
||||||
saveMessage.value = 'تغییرات ذخیره شد.';
|
message.value = 'اطلاعات ذخیره شد.';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.value = e instanceof ApiError ? e.message : 'ذخیره ناموفق بود.';
|
error.value = e instanceof ApiError ? e.message : 'خطا در ذخیره';
|
||||||
} finally {
|
} finally {
|
||||||
saving.value = false;
|
saving.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
async function onSaveBookingSettings() {
|
||||||
void loadBusiness();
|
if (!business.value) return;
|
||||||
});
|
const concurrentCapacity = Number.parseInt(bookingForm.value.concurrentCapacity, 10);
|
||||||
|
if (!Number.isFinite(concurrentCapacity) || concurrentCapacity < 1 || concurrentCapacity > 20) {
|
||||||
|
error.value = 'پذیرش همزمان باید عددی بین ۱ تا ۲۰ باشد.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const slotStepMinutes = Number.parseInt(bookingForm.value.slotStepMinutes, 10);
|
||||||
|
if (!Number.isFinite(slotStepMinutes) || slotStepMinutes < 5 || slotStepMinutes > 120) {
|
||||||
|
error.value = 'گام نوبتدهی باید عددی بین ۵ تا ۱۲۰ دقیقه باشد.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
savingBooking.value = true;
|
||||||
|
error.value = '';
|
||||||
|
message.value = '';
|
||||||
|
try {
|
||||||
|
business.value = await updateBusiness(business.value.id, {
|
||||||
|
concurrentCapacity,
|
||||||
|
slotStepMinutes,
|
||||||
|
});
|
||||||
|
tenant.syncSingleBusiness(business.value);
|
||||||
|
message.value = 'تنظیمات نوبتدهی ذخیره شد.';
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'خطا در ذخیره';
|
||||||
|
} finally {
|
||||||
|
savingBooking.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onAddService() {
|
||||||
|
if (!business.value || !serviceForm.value.serviceTemplateId) return;
|
||||||
|
|
||||||
|
let price = 0;
|
||||||
|
let duration: number | null | undefined;
|
||||||
|
let classPrices: ClassPriceItem[] | null = null;
|
||||||
|
|
||||||
|
if (hasServiceClasses.value) {
|
||||||
|
classPrices = buildClassPricesPayload(classPriceForm.value);
|
||||||
|
if (!classPrices?.length) {
|
||||||
|
error.value = 'قیمت همه کلاسها را وارد کنید.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
price = Math.min(...classPrices.map((item) => item.price));
|
||||||
|
} else {
|
||||||
|
const parsedPrice = parsePriceInput(serviceForm.value.price);
|
||||||
|
if (parsedPrice === null) {
|
||||||
|
error.value = 'قیمت معتبر نیست.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
price = parsedPrice;
|
||||||
|
duration = parseOptionalMinutes(serviceForm.value.durationMinutes);
|
||||||
|
if (duration === null) {
|
||||||
|
error.value = 'مدت زمان معتبر نیست.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addingService.value = true;
|
||||||
|
error.value = '';
|
||||||
|
message.value = '';
|
||||||
|
try {
|
||||||
|
const created = await createBusinessService({
|
||||||
|
businessId: business.value.id,
|
||||||
|
serviceTemplateId: serviceForm.value.serviceTemplateId,
|
||||||
|
price,
|
||||||
|
durationMinutes: duration && duration > 0 ? duration : undefined,
|
||||||
|
});
|
||||||
|
if (classPrices?.length) {
|
||||||
|
await setBusinessServiceClassPrices(created.id, classPrices);
|
||||||
|
}
|
||||||
|
serviceForm.value = { serviceTemplateId: '', price: '', durationMinutes: '' };
|
||||||
|
classPriceForm.value = emptyClassPriceForm();
|
||||||
|
await loadServicesAndTemplates();
|
||||||
|
if (availableTemplates.value[0]) {
|
||||||
|
serviceForm.value.serviceTemplateId = availableTemplates.value[0].id;
|
||||||
|
}
|
||||||
|
message.value = 'خدمت اضافه شد.';
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'خطا در افزودن خدمت';
|
||||||
|
} finally {
|
||||||
|
addingService.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestStatusLabel(status: BusinessServiceRequestStatus): string {
|
||||||
|
const map: Record<BusinessServiceRequestStatus, string> = {
|
||||||
|
pending: 'در انتظار تأیید',
|
||||||
|
approved: 'تأیید و اضافه شد',
|
||||||
|
rejected: 'رد شده',
|
||||||
|
};
|
||||||
|
return map[status];
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestStatusClass(status: BusinessServiceRequestStatus): string {
|
||||||
|
if (status === 'approved') return 'bg-green-500/15 text-green-700';
|
||||||
|
if (status === 'rejected') return 'bg-red-500/15 text-red-600';
|
||||||
|
return 'bg-amber-500/15 text-amber-700';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onAddCustomService() {
|
||||||
|
const title = customForm.value.title.trim();
|
||||||
|
const price = parsePriceInput(customForm.value.price);
|
||||||
|
const duration = parseOptionalMinutes(customForm.value.durationMinutes);
|
||||||
|
if (!title || price === null) {
|
||||||
|
error.value = 'نام و قیمت معتبر را وارد کنید.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (duration === null) {
|
||||||
|
error.value = 'مدت زمان معتبر نیست.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addingCustom.value = true;
|
||||||
|
error.value = '';
|
||||||
|
message.value = '';
|
||||||
|
try {
|
||||||
|
await createServiceRequest({
|
||||||
|
businessId: business.value!.id,
|
||||||
|
title,
|
||||||
|
description: customForm.value.description.trim() || undefined,
|
||||||
|
price,
|
||||||
|
durationMinutes: duration && duration > 0 ? duration : undefined,
|
||||||
|
});
|
||||||
|
customForm.value = { title: '', description: '', price: '', durationMinutes: '' };
|
||||||
|
await loadServicesAndTemplates();
|
||||||
|
message.value = 'درخواست ارسال شد. پس از تأیید مدیر در لیست خدمات نمایش داده میشود.';
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'ارسال درخواست ناموفق بود';
|
||||||
|
} finally {
|
||||||
|
addingCustom.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEdit(svc: BusinessService) {
|
||||||
|
editingId.value = svc.id;
|
||||||
|
editForm.value = {
|
||||||
|
price: formatPriceInputDisplay(Math.round(Number.parseFloat(svc.price))),
|
||||||
|
durationMinutes: svc.durationMinutes != null ? String(svc.durationMinutes) : '',
|
||||||
|
};
|
||||||
|
const form = emptyClassPriceForm();
|
||||||
|
for (const classPrice of svc.classPrices ?? []) {
|
||||||
|
if (form[classPrice.classId]) {
|
||||||
|
form[classPrice.classId] = {
|
||||||
|
price: formatPriceInputDisplay(Math.round(Number.parseFloat(classPrice.price))),
|
||||||
|
durationMinutes:
|
||||||
|
classPrice.durationMinutes != null ? String(classPrice.durationMinutes) : '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editClassPrices.value = form;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelEdit() {
|
||||||
|
editingId.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onSaveEdit(svc: BusinessService) {
|
||||||
|
savingService.value = true;
|
||||||
|
error.value = '';
|
||||||
|
try {
|
||||||
|
if (hasServiceClasses.value) {
|
||||||
|
const classPrices = buildClassPricesPayload(editClassPrices.value);
|
||||||
|
if (!classPrices?.length) {
|
||||||
|
error.value = 'قیمت همه کلاسها را وارد کنید.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await setBusinessServiceClassPrices(svc.id, classPrices);
|
||||||
|
} else {
|
||||||
|
const price = parsePriceInput(editForm.value.price);
|
||||||
|
if (price === null) {
|
||||||
|
error.value = 'قیمت معتبر نیست.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const duration = parseOptionalMinutes(editForm.value.durationMinutes);
|
||||||
|
if (duration === null) {
|
||||||
|
error.value = 'مدت زمان معتبر نیست.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await updateBusinessService(svc.id, {
|
||||||
|
price,
|
||||||
|
durationMinutes: duration ?? null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
editingId.value = null;
|
||||||
|
await loadServicesAndTemplates();
|
||||||
|
message.value = 'خدمت بهروزرسانی شد.';
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'خطا در ویرایش';
|
||||||
|
} finally {
|
||||||
|
savingService.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onToggleActive(svc: BusinessService) {
|
||||||
|
error.value = '';
|
||||||
|
try {
|
||||||
|
await updateBusinessService(svc.id, { isActive: !svc.isActive });
|
||||||
|
await loadServicesAndTemplates();
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'خطا در تغییر وضعیت';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onDelete(svc: BusinessService) {
|
||||||
|
const title = svc.serviceTemplate?.title ?? 'این خدمت';
|
||||||
|
if (!confirm(`«${title}» حذف شود؟`)) return;
|
||||||
|
error.value = '';
|
||||||
|
try {
|
||||||
|
await deleteBusinessService(svc.id);
|
||||||
|
await loadServicesAndTemplates();
|
||||||
|
message.value = 'خدمت حذف شد.';
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof ApiError ? e.message : 'خطا در حذف';
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user