@@ -177,6 +229,8 @@
کسبوکار
{{ business.title }}
+
کلاس
+
{{ selectedClass.title }}
{{ svc.serviceTemplate?.title ?? 'خدمت' }}
{{
- requiresServiceClass && bookingForm.serviceClassId
- ? `${formatPriceToman(resolvedServicePrice(svc, bookingForm.serviceClassId) ?? svc.price)} تومان`
+ requiresServiceClass && selectedClassId
+ ? `${formatPriceToman(resolvedServicePrice(svc, selectedClassId) ?? svc.price)} تومان`
: `${formatPriceToman(svc.price)} تومان`
}}
@@ -199,43 +253,13 @@
{{ totalDurationLabel }}
-
-
- کلاس خودرو / دسته
-
-
- انتخاب کنید
-
- {{ cls.title }}
-
-
-
-
-
- ابتدا کلاس خودرو را انتخاب کنید.
-
@@ -276,8 +300,8 @@ import { useAuthStore } from '@/stores/auth';
import { formatPriceToman } from '@/utils/format';
import {
activeServiceClasses,
- getClassPriceForService,
isServiceBookable,
+ isServiceBookableForClass,
resolvedServicePrice,
serviceDurationLabel,
servicePriceLabel,
@@ -299,11 +323,11 @@ const error = ref('');
const servicesError = ref('');
const bookingOpen = ref(false);
+const selectedClassId = ref('');
const selectedServiceIds = ref([]);
const bookingSaving = ref(false);
const bookingError = ref('');
const bookingForm = ref({
- serviceClassId: '',
scheduledAt: '',
note: '',
});
@@ -321,8 +345,28 @@ const bookableServices = computed(() =>
),
);
+const displayedServices = computed(() => {
+ if (!requiresServiceClass.value) {
+ return bookableServices.value;
+ }
+ if (!selectedClassId.value) {
+ return [];
+ }
+ return bookableServices.value.filter((svc) =>
+ isServiceBookableForClass(svc, selectedClassId.value),
+ );
+});
+
+const selectedClass = computed(() =>
+ activeClasses.value.find((cls) => cls.id === selectedClassId.value) ?? null,
+);
+
+const canProceedToBooking = computed(
+ () => !requiresServiceClass.value || !!selectedClassId.value,
+);
+
const selectedServices = computed(() =>
- bookableServices.value.filter((svc) => selectedServiceIds.value.includes(svc.id)),
+ displayedServices.value.filter((svc) => selectedServiceIds.value.includes(svc.id)),
);
const totalDurationLabel = computed(() => {
@@ -330,21 +374,18 @@ const totalDurationLabel = computed(() => {
selectedServices.value,
classesEnabled.value,
serviceClasses.value,
- bookingForm.value.serviceClassId || null,
+ selectedClassId.value || null,
);
return `${minutes} دقیقه`;
});
const bookingPriceLabel = computed(() => {
if (!selectedServices.value.length) return '—';
- if (requiresServiceClass.value && !bookingForm.value.serviceClassId) {
- return 'کلاس را انتخاب کنید';
- }
const total = totalPriceForServices(
selectedServices.value,
classesEnabled.value,
serviceClasses.value,
- bookingForm.value.serviceClassId || null,
+ selectedClassId.value || null,
);
return total != null ? `${formatPriceToman(String(total))} تومان` : '—';
});
@@ -363,7 +404,18 @@ function isServiceSelected(id: string): boolean {
return selectedServiceIds.value.includes(id);
}
+function selectClass(classId: string) {
+ if (selectedClassId.value === classId) {
+ return;
+ }
+ selectedClassId.value = classId;
+ selectedServiceIds.value = [];
+}
+
function toggleService(id: string) {
+ if (requiresServiceClass.value && !selectedClassId.value) {
+ return;
+ }
if (isServiceSelected(id)) {
selectedServiceIds.value = selectedServiceIds.value.filter((item) => item !== id);
} else {
@@ -372,9 +424,8 @@ function toggleService(id: string) {
}
function openBooking() {
- if (!auth.user || !selectedServices.value.length) return;
+ if (!auth.user || !selectedServices.value.length || !canProceedToBooking.value) return;
bookingForm.value = {
- serviceClassId: '',
scheduledAt: '',
note: '',
};
@@ -442,7 +493,7 @@ async function onSubmitBooking() {
bookingError.value = 'لطفاً یک ساعت از لیست انتخاب کنید.';
return;
}
- if (requiresServiceClass.value && !bookingForm.value.serviceClassId) {
+ if (requiresServiceClass.value && !selectedClassId.value) {
bookingError.value = 'لطفاً کلاس خودرو را انتخاب کنید.';
return;
}
@@ -456,11 +507,12 @@ async function onSubmitBooking() {
items: selectedServices.value.map((svc) => ({
businessServiceId: svc.id,
})),
- serviceClassId: bookingForm.value.serviceClassId || null,
+ serviceClassId: selectedClassId.value || null,
scheduledAt: scheduled.toISOString(),
note: bookingForm.value.note.trim() || null,
});
selectedServiceIds.value = [];
+ selectedClassId.value = '';
closeBooking();
router.push({ name: 'app-bookings' });
} catch (e) {