2026-05-18 20:18:28 +03:30
|
|
|
|
<template>
|
|
|
|
|
|
<WebAppLayout>
|
|
|
|
|
|
<h1 class="mb-4 text-xl font-bold text-text">مدیریت کسبوکار</h1>
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
|
|
|
|
|
<p
|
|
|
|
|
|
v-if="error"
|
|
|
|
|
|
class="mb-4 rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ error }}
|
|
|
|
|
|
</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>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="loading" class="text-sm text-muted">در حال بارگذاری…</div>
|
|
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
<div
|
|
|
|
|
|
v-else-if="!business"
|
|
|
|
|
|
class="rounded-2xl border border-dashed border-border p-6 text-center text-sm text-muted"
|
|
|
|
|
|
>
|
2026-05-23 18:13:25 +03:30
|
|
|
|
کسبوکاری به حساب شما وصل نیست.
|
2026-05-18 20:18:28 +03:30
|
|
|
|
</div>
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
<div v-else class="space-y-8">
|
|
|
|
|
|
<form class="space-y-4" @submit.prevent="onSave">
|
|
|
|
|
|
<h2 class="text-base font-semibold text-text">اطلاعات کسبوکار</h2>
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
<div class="rounded-2xl border border-border bg-surface-2 p-4">
|
|
|
|
|
|
<p class="text-xs text-muted">دسته</p>
|
|
|
|
|
|
<p class="mt-0.5 font-medium text-text">{{ business.category?.title ?? '—' }}</p>
|
|
|
|
|
|
<span
|
|
|
|
|
|
class="mt-2 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>
|
|
|
|
|
|
</div>
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
<AppInput id="ownerTitle" v-model="form.title" label="نام کسبوکار" required />
|
|
|
|
|
|
|
|
|
|
|
|
<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
|
2026-05-23 18:13:25 +03:30
|
|
|
|
/>
|
2026-05-24 11:34:52 +03:30
|
|
|
|
<AppInput id="ownerAddress" v-model="form.address" label="آدرس" />
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
<AppButton type="submit" :loading="saving">ذخیره تغییرات</AppButton>
|
|
|
|
|
|
</form>
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
2026-05-25 19:13:28 +03:30
|
|
|
|
<BusinessAvailabilityEditor
|
|
|
|
|
|
v-if="business"
|
|
|
|
|
|
:business-id="business.id"
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
<section class="space-y-4 border-t border-border pt-6">
|
|
|
|
|
|
<h2 class="text-base font-semibold text-text">خدمات و قیمتها</h2>
|
|
|
|
|
|
<p class="text-xs text-muted">
|
|
|
|
|
|
خدماتی که اینجا ثبت میکنید در صفحه کسبوکار برای مشتریان و مقایسه نمایش داده میشود.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="loadingServices" class="text-sm text-muted">در حال بارگذاری خدمات…</div>
|
|
|
|
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
<label class="flex shrink-0 items-center gap-1 text-xs text-muted">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
:checked="svc.isActive"
|
|
|
|
|
|
@change="onToggleActive(svc)"
|
|
|
|
|
|
/>
|
|
|
|
|
|
فعال
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="editingId === svc.id" class="mt-3 space-y-2">
|
2026-05-25 21:38:17 +03:30
|
|
|
|
<PriceInput
|
2026-05-24 11:34:52 +03:30
|
|
|
|
id="editPrice"
|
|
|
|
|
|
v-model="editForm.price"
|
|
|
|
|
|
label="قیمت (تومان)"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<AppInput
|
|
|
|
|
|
id="editDuration"
|
|
|
|
|
|
v-model="editForm.durationMinutes"
|
|
|
|
|
|
label="مدت (دقیقه)"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
|
ltr
|
|
|
|
|
|
/>
|
|
|
|
|
|
<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 flex flex-wrap items-center gap-2 text-sm text-muted">
|
|
|
|
|
|
<span>{{ formatPriceToman(svc.price) }} تومان</span>
|
|
|
|
|
|
<span>·</span>
|
|
|
|
|
|
<span>{{
|
|
|
|
|
|
formatDuration(
|
|
|
|
|
|
svc.durationMinutes,
|
|
|
|
|
|
svc.serviceTemplate?.defaultDurationMinutes,
|
|
|
|
|
|
)
|
|
|
|
|
|
}}</span>
|
|
|
|
|
|
<AppButton variant="ghost" class="!w-auto px-2 text-xs" @click="startEdit(svc)">
|
|
|
|
|
|
ویرایش
|
|
|
|
|
|
</AppButton>
|
|
|
|
|
|
<AppButton variant="danger" class="!w-auto px-2 text-xs" @click="onDelete(svc)">
|
|
|
|
|
|
حذف
|
|
|
|
|
|
</AppButton>
|
|
|
|
|
|
</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>
|
|
|
|
|
|
|
2026-05-25 21:38:17 +03:30
|
|
|
|
<PriceInput
|
2026-05-24 11:34:52 +03:30
|
|
|
|
id="svcPrice"
|
|
|
|
|
|
v-model="serviceForm.price"
|
|
|
|
|
|
label="قیمت (تومان)"
|
|
|
|
|
|
required
|
|
|
|
|
|
/>
|
|
|
|
|
|
<AppInput
|
|
|
|
|
|
id="svcDuration"
|
|
|
|
|
|
v-model="serviceForm.durationMinutes"
|
|
|
|
|
|
label="مدت (دقیقه — اختیاری)"
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
|
ltr
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<AppButton type="submit" :loading="addingService">افزودن</AppButton>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|
<p
|
|
|
|
|
|
v-else-if="!loadingServices && templates.length && !availableTemplates.length"
|
|
|
|
|
|
class="text-sm text-muted"
|
|
|
|
|
|
>
|
|
|
|
|
|
همهٔ انواع خدمت این دسته را اضافه کردهاید.
|
|
|
|
|
|
</p>
|
2026-05-25 21:38:17 +03:30
|
|
|
|
|
|
|
|
|
|
<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>
|
2026-05-24 11:34:52 +03:30
|
|
|
|
</section>
|
|
|
|
|
|
</div>
|
2026-05-18 20:18:28 +03:30
|
|
|
|
</WebAppLayout>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-05-24 11:34:52 +03:30
|
|
|
|
import { computed, onMounted, ref } from 'vue';
|
2026-05-23 18:13:25 +03:30
|
|
|
|
import { fetchMyBusinesses, updateBusiness } from '@/api/businesses';
|
2026-05-25 21:38:17 +03:30
|
|
|
|
import {
|
|
|
|
|
|
createServiceRequest,
|
|
|
|
|
|
fetchMyServiceRequests,
|
|
|
|
|
|
} from '@/api/business-service-requests';
|
2026-05-24 11:34:52 +03:30
|
|
|
|
import {
|
|
|
|
|
|
createBusinessService,
|
|
|
|
|
|
deleteBusinessService,
|
|
|
|
|
|
fetchBusinessServices,
|
|
|
|
|
|
updateBusinessService,
|
|
|
|
|
|
} from '@/api/business-services';
|
|
|
|
|
|
import { fetchServiceTemplates } from '@/api/service-templates';
|
2026-05-25 21:38:17 +03:30
|
|
|
|
import type {
|
|
|
|
|
|
Business,
|
|
|
|
|
|
BusinessService,
|
|
|
|
|
|
BusinessServiceRequest,
|
|
|
|
|
|
BusinessServiceRequestStatus,
|
|
|
|
|
|
} from '@/api/types';
|
2026-05-23 18:13:25 +03:30
|
|
|
|
import { ApiError } from '@/api/client';
|
2026-05-25 19:13:28 +03:30
|
|
|
|
import BusinessAvailabilityEditor from '@/components/owner/BusinessAvailabilityEditor.vue';
|
2026-05-23 18:13:25 +03:30
|
|
|
|
import AppButton from '@/components/ui/AppButton.vue';
|
|
|
|
|
|
import AppInput from '@/components/ui/AppInput.vue';
|
2026-05-25 21:38:17 +03:30
|
|
|
|
import PriceInput from '@/components/ui/PriceInput.vue';
|
2026-05-18 20:18:28 +03:30
|
|
|
|
import WebAppLayout from '@/layouts/WebAppLayout.vue';
|
2026-05-25 19:13:28 +03:30
|
|
|
|
import {
|
|
|
|
|
|
formatDuration,
|
2026-05-25 21:38:17 +03:30
|
|
|
|
formatPriceInputDisplay,
|
2026-05-25 19:13:28 +03:30
|
|
|
|
formatPriceToman,
|
|
|
|
|
|
parseOptionalMinutes,
|
|
|
|
|
|
parsePriceInput,
|
|
|
|
|
|
} from '@/utils/format';
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
|
|
|
|
|
const business = ref<Business | null>(null);
|
2026-05-24 11:34:52 +03:30
|
|
|
|
const services = ref<BusinessService[]>([]);
|
|
|
|
|
|
const templates = ref<Awaited<ReturnType<typeof fetchServiceTemplates>>>([]);
|
2026-05-23 18:13:25 +03:30
|
|
|
|
const loading = ref(true);
|
2026-05-24 11:34:52 +03:30
|
|
|
|
const loadingServices = ref(false);
|
2026-05-23 18:13:25 +03:30
|
|
|
|
const saving = ref(false);
|
2026-05-24 11:34:52 +03:30
|
|
|
|
const savingService = ref(false);
|
|
|
|
|
|
const addingService = ref(false);
|
2026-05-25 21:38:17 +03:30
|
|
|
|
const addingCustom = ref(false);
|
|
|
|
|
|
const serviceRequests = ref<BusinessServiceRequest[]>([]);
|
2026-05-23 18:13:25 +03:30
|
|
|
|
const error = ref('');
|
|
|
|
|
|
const message = ref('');
|
2026-05-24 11:34:52 +03:30
|
|
|
|
const editingId = ref<string | null>(null);
|
2026-05-23 18:13:25 +03:30
|
|
|
|
|
|
|
|
|
|
const form = ref({
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
description: '',
|
|
|
|
|
|
contactPhone: '',
|
|
|
|
|
|
address: '',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
const serviceForm = ref({
|
|
|
|
|
|
serviceTemplateId: '',
|
|
|
|
|
|
price: '',
|
|
|
|
|
|
durationMinutes: '',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const editForm = ref({
|
|
|
|
|
|
price: '',
|
|
|
|
|
|
durationMinutes: '',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-25 21:38:17 +03:30
|
|
|
|
const customForm = ref({
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
description: '',
|
|
|
|
|
|
price: '',
|
|
|
|
|
|
durationMinutes: '',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
const availableTemplates = computed(() => {
|
|
|
|
|
|
const used = new Set(services.value.map((s) => s.serviceTemplateId));
|
|
|
|
|
|
return templates.value.filter((t) => !used.has(t.id));
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
async function loadServicesAndTemplates() {
|
|
|
|
|
|
if (!business.value) return;
|
|
|
|
|
|
loadingServices.value = true;
|
|
|
|
|
|
try {
|
2026-05-25 21:38:17 +03:30
|
|
|
|
const [svcList, tplList, reqs] = await Promise.all([
|
2026-05-24 11:34:52 +03:30
|
|
|
|
fetchBusinessServices(business.value.id),
|
|
|
|
|
|
fetchServiceTemplates(business.value.categoryId),
|
2026-05-25 21:38:17 +03:30
|
|
|
|
fetchMyServiceRequests(),
|
2026-05-24 11:34:52 +03:30
|
|
|
|
]);
|
|
|
|
|
|
services.value = svcList;
|
|
|
|
|
|
templates.value = tplList;
|
2026-05-25 21:38:17 +03:30
|
|
|
|
serviceRequests.value = reqs;
|
2026-05-24 11:34:52 +03:30
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 18:13:25 +03:30
|
|
|
|
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,
|
|
|
|
|
|
description: business.value.description ?? '',
|
|
|
|
|
|
contactPhone: business.value.contactPhone ?? '',
|
|
|
|
|
|
address: business.value.address ?? '',
|
|
|
|
|
|
};
|
2026-05-24 11:34:52 +03:30
|
|
|
|
await loadServicesAndTemplates();
|
2026-05-23 18:13:25 +03:30
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
error.value = e instanceof ApiError ? e.message : 'خطا در بارگذاری';
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
async function onSave() {
|
|
|
|
|
|
if (!business.value) return;
|
|
|
|
|
|
saving.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
message.value = '';
|
|
|
|
|
|
try {
|
|
|
|
|
|
business.value = await updateBusiness(business.value.id, {
|
|
|
|
|
|
title: form.value.title.trim(),
|
|
|
|
|
|
description: form.value.description.trim() || null,
|
|
|
|
|
|
contactPhone: form.value.contactPhone.trim() || null,
|
|
|
|
|
|
address: form.value.address.trim() || null,
|
|
|
|
|
|
});
|
2026-05-24 11:34:52 +03:30
|
|
|
|
message.value = 'اطلاعات ذخیره شد.';
|
2026-05-23 18:13:25 +03:30
|
|
|
|
} catch (e) {
|
|
|
|
|
|
error.value = e instanceof ApiError ? e.message : 'خطا در ذخیره';
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
saving.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-24 11:34:52 +03:30
|
|
|
|
|
|
|
|
|
|
async function onAddService() {
|
|
|
|
|
|
if (!business.value || !serviceForm.value.serviceTemplateId) return;
|
2026-05-25 19:13:28 +03:30
|
|
|
|
const price = parsePriceInput(serviceForm.value.price);
|
2026-05-24 11:34:52 +03:30
|
|
|
|
if (price === null) {
|
|
|
|
|
|
error.value = 'قیمت معتبر نیست.';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-05-25 19:13:28 +03:30
|
|
|
|
const duration = parseOptionalMinutes(serviceForm.value.durationMinutes);
|
|
|
|
|
|
if (duration === null) {
|
|
|
|
|
|
error.value = 'مدت زمان معتبر نیست.';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-05-24 11:34:52 +03:30
|
|
|
|
addingService.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
message.value = '';
|
|
|
|
|
|
try {
|
|
|
|
|
|
await createBusinessService({
|
|
|
|
|
|
businessId: business.value.id,
|
|
|
|
|
|
serviceTemplateId: serviceForm.value.serviceTemplateId,
|
|
|
|
|
|
price,
|
|
|
|
|
|
durationMinutes: duration && duration > 0 ? duration : undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
serviceForm.value = { serviceTemplateId: '', price: '', durationMinutes: '' };
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-25 21:38:17 +03:30
|
|
|
|
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({
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-24 11:34:52 +03:30
|
|
|
|
function startEdit(svc: BusinessService) {
|
|
|
|
|
|
editingId.value = svc.id;
|
|
|
|
|
|
editForm.value = {
|
2026-05-25 21:38:17 +03:30
|
|
|
|
price: formatPriceInputDisplay(Math.round(Number.parseFloat(svc.price))),
|
2026-05-24 11:34:52 +03:30
|
|
|
|
durationMinutes: svc.durationMinutes != null ? String(svc.durationMinutes) : '',
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cancelEdit() {
|
|
|
|
|
|
editingId.value = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function onSaveEdit(svc: BusinessService) {
|
2026-05-25 19:13:28 +03:30
|
|
|
|
const price = parsePriceInput(editForm.value.price);
|
2026-05-24 11:34:52 +03:30
|
|
|
|
if (price === null) {
|
|
|
|
|
|
error.value = 'قیمت معتبر نیست.';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-05-25 19:13:28 +03:30
|
|
|
|
const duration = parseOptionalMinutes(editForm.value.durationMinutes);
|
|
|
|
|
|
if (duration === null) {
|
|
|
|
|
|
error.value = 'مدت زمان معتبر نیست.';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-05-24 11:34:52 +03:30
|
|
|
|
savingService.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
try {
|
|
|
|
|
|
await updateBusinessService(svc.id, {
|
|
|
|
|
|
price,
|
2026-05-25 19:13:28 +03:30
|
|
|
|
durationMinutes: duration ?? null,
|
2026-05-24 11:34:52 +03:30
|
|
|
|
});
|
|
|
|
|
|
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 : 'خطا در حذف';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-18 20:18:28 +03:30
|
|
|
|
</script>
|