merge: bring latest origin/main into dev (keep local UI)
Resolved UI conflicts in favor of local Ant Design screens; kept non-UI changes from main.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import { api } from '@/lib/api';
|
||||
import {
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
formatClockFa,
|
||||
formatJalaliDay,
|
||||
formatJalaliNumeric,
|
||||
toFaDigits,
|
||||
} from '@/lib/jalali';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import UserAvatar from '@/components/UserAvatar.vue';
|
||||
@@ -21,20 +22,42 @@ import type {
|
||||
OrgUserDto,
|
||||
} from '@mento/shared';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { canReassignRecords } from '@/lib/roles';
|
||||
import { canAssignToOthers } from '@/lib/assign-access';
|
||||
import { activityTypeView, typeColorStyle, useActivityTypes } from '@/lib/activity-types';
|
||||
import { brand } from '@mento/shared';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const ACTIVITY_LIST_QUERY = ['board', 'view', 'desk', 'filter', 'stage', 'q', 'typeDefId', 'status', 'assigneeId', 'title', 'customer', 'due'] as const;
|
||||
const NAV_API_QUERY = ['q', 'desk', 'type', 'typeDefId', 'status', 'assigneeId', 'title', 'customer', 'due'] as const;
|
||||
|
||||
function activitiesListLocation() {
|
||||
const query: Record<string, string> = {};
|
||||
for (const key of ACTIVITY_LIST_QUERY) {
|
||||
const value = route.query[key];
|
||||
if (typeof value === 'string' && value) query[key] = value;
|
||||
}
|
||||
return { name: 'activities' as const, query };
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
const back = (window.history.state as { back?: string | null } | null)?.back ?? '';
|
||||
if (back.split('?')[0] === '/activities') {
|
||||
router.back();
|
||||
return;
|
||||
}
|
||||
void router.push(activitiesListLocation());
|
||||
}
|
||||
const auth = useAuthStore();
|
||||
const id = computed(() => (typeof route.params.id === 'string' ? route.params.id : ''));
|
||||
const canReassign = computed(() => canReassignRecords(auth.user?.role));
|
||||
const canReassign = computed(() => canAssignToOthers(auth.user, 'activities'));
|
||||
|
||||
const loading = ref(true);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const activity = ref<ActivityDto | null>(null);
|
||||
const imageUrls = ref<Array<{ id: string; name: string; url: string; kind: 'image' | 'audio' | 'file' }>>([]);
|
||||
const moreOpen = ref(false);
|
||||
const commentOpen = ref(false);
|
||||
const postponeOpen = ref(false);
|
||||
@@ -130,6 +153,7 @@ async function load() {
|
||||
try {
|
||||
const { data } = await api.get<ActivityDto>(`/activities/${id.value}`);
|
||||
activity.value = data;
|
||||
await loadActivityImages(data);
|
||||
assignUserIds.value = data.assignees?.length
|
||||
? data.assignees.map((u) => u.id)
|
||||
: data.assignee?.id
|
||||
@@ -143,6 +167,36 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
function clearImageUrls() {
|
||||
for (const image of imageUrls.value) URL.revokeObjectURL(image.url);
|
||||
imageUrls.value = [];
|
||||
}
|
||||
|
||||
async function loadActivityImages(row: ActivityDto) {
|
||||
clearImageUrls();
|
||||
const next: Array<{ id: string; name: string; url: string; kind: 'image' | 'audio' | 'file' }> = [];
|
||||
for (const image of row.images ?? []) {
|
||||
const mime = image.mimeType.toLowerCase();
|
||||
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
|
||||
try {
|
||||
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
|
||||
responseType: 'blob',
|
||||
});
|
||||
next.push({
|
||||
id: image.id,
|
||||
name: image.fileName,
|
||||
url: URL.createObjectURL(data),
|
||||
kind,
|
||||
});
|
||||
} catch {
|
||||
/* فایل در دسترس نیست */
|
||||
}
|
||||
}
|
||||
imageUrls.value = next;
|
||||
}
|
||||
|
||||
onUnmounted(clearImageUrls);
|
||||
|
||||
async function loadUsers() {
|
||||
if (!canReassign.value) return;
|
||||
try {
|
||||
@@ -217,8 +271,8 @@ async function postponeTo(iso: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function submitComment(text: string) {
|
||||
const body = text.trim();
|
||||
async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
||||
const body = payload.text.trim() || (payload.photoOnly ? 'عکس پیوست شد.' : '');
|
||||
if (!id.value || !activity.value || !body) return;
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
@@ -232,8 +286,9 @@ async function submitComment(text: string) {
|
||||
await api.patch(`/activities/${id.value}`, { description: next });
|
||||
commentOpen.value = false;
|
||||
await load();
|
||||
} catch {
|
||||
} catch (e) {
|
||||
error.value = 'ثبت نظر ناموفق بود.';
|
||||
throw e;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
@@ -250,34 +305,91 @@ async function remove() {
|
||||
}
|
||||
}
|
||||
|
||||
const routinesEnabled = computed(() => {
|
||||
const mods = auth.user?.enabledModules;
|
||||
return !mods || mods.includes('routines');
|
||||
});
|
||||
const converting = ref(false);
|
||||
const navIds = ref<string[]>([]);
|
||||
const deskBrowse = computed(
|
||||
() => route.query.from === 'desk' && typeof route.query.nav === 'string' && route.query.nav.length > 0,
|
||||
);
|
||||
const navIndex = computed(() => navIds.value.indexOf(id.value));
|
||||
const prevNavId = computed(() => (navIndex.value > 0 ? navIds.value[navIndex.value - 1]! : ''));
|
||||
const nextNavId = computed(() =>
|
||||
navIndex.value >= 0 && navIndex.value < navIds.value.length - 1
|
||||
? navIds.value[navIndex.value + 1]!
|
||||
: '',
|
||||
);
|
||||
const showNav = computed(() => deskBrowse.value && navIndex.value >= 0);
|
||||
|
||||
/** پیگیری → Task در «کارهای روتین» (تکراری نمیسازد) */
|
||||
async function convertToTask() {
|
||||
if (!id.value || converting.value) return;
|
||||
converting.value = true;
|
||||
error.value = '';
|
||||
function navStorageKey(token: string) {
|
||||
return `activity-nav:${token}`;
|
||||
}
|
||||
|
||||
function readNavCache(token: string): string[] | null {
|
||||
try {
|
||||
const { data } = await api.post<{ id: string }>(`/routine-tasks/from-activity/${id.value}`);
|
||||
moreOpen.value = false;
|
||||
void router.push({ path: '/routines', query: { task: data.id } });
|
||||
} catch (e) {
|
||||
const msg = (e as { response?: { data?: { message?: string | string[] } } }).response?.data?.message;
|
||||
error.value = Array.isArray(msg) ? msg.join('، ') : (msg ?? 'تبدیل به Task ممکن نشد.');
|
||||
} finally {
|
||||
converting.value = false;
|
||||
const raw = sessionStorage.getItem(navStorageKey(token));
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as { ids?: unknown };
|
||||
if (!Array.isArray(parsed.ids) || parsed.ids.some((item) => typeof item !== 'string')) return null;
|
||||
return parsed.ids as string[];
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
let navSeq = 0;
|
||||
async function loadNav() {
|
||||
const seq = ++navSeq;
|
||||
const token = typeof route.query.nav === 'string' ? route.query.nav : '';
|
||||
const columnMissing =
|
||||
route.query.view === 'board' &&
|
||||
(typeof route.query.stage !== 'string' || !route.query.stage || route.query.stage === 'all');
|
||||
if (!deskBrowse.value || !token || columnMissing) {
|
||||
navIds.value = [];
|
||||
return;
|
||||
}
|
||||
const cached = readNavCache(token);
|
||||
if (cached) {
|
||||
if (seq === navSeq) navIds.value = cached;
|
||||
return;
|
||||
}
|
||||
const params: Record<string, string> = {
|
||||
filter: typeof route.query.filter === 'string' && route.query.filter ? route.query.filter : 'today',
|
||||
};
|
||||
for (const key of NAV_API_QUERY) {
|
||||
const value = route.query[key];
|
||||
if (typeof value === 'string' && value) params[key] = value;
|
||||
}
|
||||
if (typeof route.query.board === 'string' && route.query.board) params.boardId = route.query.board;
|
||||
if (typeof route.query.stage === 'string' && route.query.stage && route.query.stage !== 'all') {
|
||||
params.stageId = route.query.stage;
|
||||
}
|
||||
try {
|
||||
const { data } = await api.get<{ ids: string[] }>('/activities/nav-ids', { params });
|
||||
if (seq !== navSeq) return;
|
||||
const ids = Array.isArray(data.ids) ? data.ids : [];
|
||||
try {
|
||||
sessionStorage.setItem(navStorageKey(token), JSON.stringify({ ids }));
|
||||
} catch {
|
||||
/* حالت خصوصی مرورگر */
|
||||
}
|
||||
navIds.value = ids;
|
||||
} catch {
|
||||
if (seq === navSeq) navIds.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
function goNeighbor(targetId: string) {
|
||||
if (!targetId || targetId === id.value) return;
|
||||
commentOpen.value = false;
|
||||
postponeOpen.value = false;
|
||||
moreOpen.value = false;
|
||||
void router.push({ name: 'activity-detail', params: { id: targetId }, query: route.query });
|
||||
}
|
||||
|
||||
watch(id, () => {
|
||||
commentOpen.value = false;
|
||||
postponeOpen.value = false;
|
||||
void load();
|
||||
});
|
||||
watch(() => route.query.nav, () => void loadNav(), { immediate: true });
|
||||
onMounted(() => {
|
||||
void load();
|
||||
void loadUsers();
|
||||
@@ -288,9 +400,9 @@ onMounted(() => {
|
||||
<template>
|
||||
<section class="page" @click="moreOpen = false">
|
||||
<header class="nav">
|
||||
<RouterLink class="icon-btn back" :to="{ name: 'activities' }" aria-label="بازگشت">
|
||||
<a class="icon-btn back" href="/activities" aria-label="بازگشت" @click.prevent="goBack">
|
||||
<UiIcon name="chevron" :size="18" />
|
||||
</RouterLink>
|
||||
</a>
|
||||
<span class="brand">{{ brand.name }}</span>
|
||||
<div class="more" @click.stop>
|
||||
<button class="icon-btn" type="button" aria-label="منوی بیشتر" @click="moreOpen = !moreOpen">
|
||||
@@ -298,15 +410,21 @@ onMounted(() => {
|
||||
</button>
|
||||
<div v-if="moreOpen && activity" class="menu">
|
||||
<RouterLink :to="{ name: 'activity-edit', params: { id } }">ویرایش</RouterLink>
|
||||
<button v-if="routinesEnabled" type="button" :disabled="converting" @click="convertToTask">
|
||||
تبدیل به Task
|
||||
</button>
|
||||
<button type="button" class="danger" @click="remove">حذف</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<h1>جزئیات فعالیت</h1>
|
||||
<nav v-if="showNav" class="neighbors" aria-label="فعالیتهای همین فهرست">
|
||||
<button type="button" class="neighbor" :disabled="!prevNavId" @click="goNeighbor(prevNavId)">
|
||||
قبلی
|
||||
</button>
|
||||
<span>{{ toFaDigits(navIndex + 1) }} از {{ toFaDigits(navIds.length) }}</span>
|
||||
<button type="button" class="neighbor" :disabled="!nextNavId" @click="goNeighbor(nextNavId)">
|
||||
بعدی
|
||||
</button>
|
||||
</nav>
|
||||
<p v-if="loading" class="muted">در حال بارگذاری…</p>
|
||||
<p v-else-if="error && !activity" class="error">{{ error }}</p>
|
||||
|
||||
@@ -446,9 +564,35 @@ onMounted(() => {
|
||||
</strong>
|
||||
<UiIcon name="chevron" :size="16" :class="{ open: noteOpen }" />
|
||||
</button>
|
||||
<p v-show="noteOpen" :class="{ empty: !activity.description?.trim() }">
|
||||
{{ activity.description?.trim() || 'یادداشتی ثبت نشده.' }}
|
||||
</p>
|
||||
<div v-show="noteOpen">
|
||||
<p v-if="activity.description?.trim()">{{ activity.description.trim() }}</p>
|
||||
<p v-else-if="!imageUrls.length" class="empty">یادداشتی ثبت نشده.</p>
|
||||
<div v-if="imageUrls.some((image) => image.kind === 'image')" class="note-photos">
|
||||
<a
|
||||
v-for="image in imageUrls.filter((item) => item.kind === 'image')"
|
||||
:key="image.id"
|
||||
:href="image.url"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
>
|
||||
<img :src="image.url" :alt="image.name" />
|
||||
</a>
|
||||
</div>
|
||||
<div v-if="imageUrls.some((image) => image.kind === 'audio')" class="note-voices">
|
||||
<audio
|
||||
v-for="image in imageUrls.filter((item) => item.kind === 'audio')"
|
||||
:key="image.id"
|
||||
:src="image.url"
|
||||
controls
|
||||
preload="metadata"
|
||||
/>
|
||||
</div>
|
||||
<ul v-if="imageUrls.some((image) => image.kind === 'file')" class="note-files">
|
||||
<li v-for="image in imageUrls.filter((item) => item.kind === 'file')" :key="image.id">
|
||||
<a :href="image.url" :download="image.name">{{ image.name }}</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
@@ -457,8 +601,8 @@ onMounted(() => {
|
||||
v-if="commentOpen"
|
||||
:activity="activity"
|
||||
:saving="saving"
|
||||
:save="submitComment"
|
||||
@close="commentOpen = false"
|
||||
@submit="submitComment"
|
||||
/>
|
||||
<ActivityPostponeSheet
|
||||
v-if="postponeOpen"
|
||||
@@ -583,6 +727,36 @@ h1 {
|
||||
font-size: 1.35rem;
|
||||
}
|
||||
|
||||
.neighbors {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.neighbors span {
|
||||
color: #64748b;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.neighbor {
|
||||
border: 0;
|
||||
background: #fff;
|
||||
color: #0f766e;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
border-radius: var(--radius);
|
||||
padding: 0.35rem 0.85rem;
|
||||
box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.neighbor:disabled {
|
||||
color: #94a3b8;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.muted,
|
||||
.error {
|
||||
margin: 0;
|
||||
@@ -800,6 +974,48 @@ dd {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.note-photos {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.note-photos a {
|
||||
width: 5.5rem;
|
||||
height: 5.5rem;
|
||||
}
|
||||
|
||||
.note-photos img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 0.6rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.note-voices {
|
||||
display: grid;
|
||||
gap: 0.45rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.note-voices audio {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.note-files {
|
||||
list-style: none;
|
||||
margin: 0.75rem 0 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.note-files a {
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.dock {
|
||||
position: fixed;
|
||||
inset-inline: 0.85rem;
|
||||
|
||||
@@ -64,6 +64,12 @@ const RETENTION_OPTIONS: Array<{ value: DeletionRetention; label: string }> = [
|
||||
const router = useRouter();
|
||||
const auth = useAuthStore();
|
||||
const isOwner = computed(() => auth.user?.role === 'owner');
|
||||
/** ورود و خروج فقط برای مالک و مدیر؛ بقیه با مجوز «لاگ فعالیت» فقط لاگها را میبینند */
|
||||
const visibleTabs = computed(() =>
|
||||
auth.user?.role === 'owner' || auth.user?.role === 'admin'
|
||||
? TABS
|
||||
: TABS.filter((item) => item.key !== 'attendance'),
|
||||
);
|
||||
|
||||
const loading = ref(false);
|
||||
const savingRetention = ref(false);
|
||||
@@ -366,7 +372,7 @@ onMounted(() => {
|
||||
|
||||
<nav class="tabs" aria-label="نوع رویداد">
|
||||
<button
|
||||
v-for="item in TABS"
|
||||
v-for="item in visibleTabs"
|
||||
:key="item.key"
|
||||
type="button"
|
||||
:class="{ on: tab === item.key }"
|
||||
|
||||
@@ -8,6 +8,7 @@ import CustomFieldsSection from '@/components/CustomFieldsSection.vue';
|
||||
import EntityTimeline from '@/components/EntityTimeline.vue';
|
||||
import RelatedTasksPanel from '@/components/routines/RelatedTasksPanel.vue';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import CustomerGroupPicker from '@/components/CustomerGroupPicker.vue';
|
||||
import { formatLocalDateInput, parseLocalInput } from '@/lib/jalali';
|
||||
import {
|
||||
UiButton,
|
||||
@@ -59,6 +60,7 @@ const city = ref('');
|
||||
const postalCode = ref('');
|
||||
const address = ref('');
|
||||
const groupName = ref('');
|
||||
const groupIds = ref<string[]>([]);
|
||||
const registeredAt = ref('');
|
||||
const notes = ref('');
|
||||
const tagsRaw = ref('');
|
||||
@@ -94,6 +96,7 @@ function fill(c: CompanyDto) {
|
||||
postalCode.value = c.postalCode ?? '';
|
||||
address.value = c.address ?? '';
|
||||
groupName.value = c.groupName ?? '';
|
||||
groupIds.value = (c.groups ?? []).map((g) => g.id);
|
||||
registeredAt.value = c.registeredAt ? formatLocalDateInput(new Date(c.registeredAt)) : '';
|
||||
notes.value = c.notes ?? '';
|
||||
tagsRaw.value = (c.tags ?? []).join('، ');
|
||||
@@ -134,6 +137,7 @@ function payload(): CreateCompanyRequest {
|
||||
postalCode: postalCode.value || null,
|
||||
address: address.value || undefined,
|
||||
groupName: groupName.value || null,
|
||||
groupIds: groupIds.value,
|
||||
registeredAt: parseLocalInput(registeredAt.value)?.toISOString() ?? null,
|
||||
notes: notes.value || undefined,
|
||||
tags: parseTags(tagsRaw.value),
|
||||
@@ -254,8 +258,8 @@ onMounted(load);
|
||||
<UiInput id="sourceRef" v-model="sourceRef" placeholder="مثال: 5277" dir="ltr" />
|
||||
</UiField>
|
||||
|
||||
<UiField label="گروه بندی شرکت">
|
||||
<UiInput id="groupName" v-model="groupName" placeholder="مثال: همکار، عمدهفروش" />
|
||||
<UiField label="گروههای شرکت" class="col-span-2">
|
||||
<CustomerGroupPicker v-model="groupIds" />
|
||||
</UiField>
|
||||
|
||||
<UiField label="تاریخ ثبت شرکت">
|
||||
|
||||
@@ -36,6 +36,7 @@ const entityLabels: Record<CustomFieldEntity, string> = {
|
||||
person: 'شخص',
|
||||
company: 'شرکت',
|
||||
deal: 'معامله',
|
||||
note: 'یادداشت',
|
||||
};
|
||||
|
||||
const typeLabels: Record<CustomFieldType, string> = {
|
||||
@@ -126,7 +127,7 @@ onMounted(load);
|
||||
<section class="crm-page narrow">
|
||||
<UiPageHeader
|
||||
title="فیلدهای سفارشی"
|
||||
lead="فیلدهای اختصاصی سازمان را برای شخص، شرکت یا معامله تعریف کنید."
|
||||
lead="فیلدهای اختصاصی سازمان را برای شخص، شرکت، معامله یا یادداشت تعریف کنید."
|
||||
/>
|
||||
|
||||
<form class="crm-form" @submit.prevent="createField">
|
||||
@@ -147,6 +148,7 @@ onMounted(load);
|
||||
<option value="person">شخص</option>
|
||||
<option value="company">شرکت</option>
|
||||
<option value="deal">معامله</option>
|
||||
<option value="note">یادداشت</option>
|
||||
</UiSelect>
|
||||
</UiField>
|
||||
|
||||
@@ -197,6 +199,7 @@ onMounted(load);
|
||||
<option value="person">شخص</option>
|
||||
<option value="company">شرکت</option>
|
||||
<option value="deal">معامله</option>
|
||||
<option value="note">یادداشت</option>
|
||||
</UiSelect>
|
||||
<UiButton variant="ghost" type="button" @click="load">
|
||||
<UiIcon name="refresh" :size="16" />
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
} from '@ant-design/icons-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { canAssignToOthers } from '@/lib/assign-access';
|
||||
import { canUseBehavior } from '@/lib/behavior-access';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import { currencySuffix, formatMoney } from '@/lib/money';
|
||||
@@ -180,6 +181,7 @@ const personSelectOptions = computed(() =>
|
||||
const companySelectOptions = computed(() =>
|
||||
companies.value.map((c) => ({ value: c.id, label: c.name })),
|
||||
);
|
||||
const canAssignOthers = computed(() => canAssignToOthers(auth.user, 'sales'));
|
||||
const ownerSelectOptions = computed(() =>
|
||||
users.value.map((u) => ({ value: u.id, label: u.fullName })),
|
||||
);
|
||||
@@ -772,13 +774,14 @@ onMounted(load);
|
||||
v-model:value="ownerId"
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
:disabled="!canAssignOthers"
|
||||
:options="ownerSelectOptions"
|
||||
placeholder="انتخاب مسئول"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-col v-if="canAssignOthers" :xs="24" :md="12">
|
||||
<a-form-item label="مسئولان مشترک">
|
||||
<UserMultiSelect v-model="selectedAssigneeIds" :users="users" />
|
||||
<a-typography-text type="secondary">علاوه بر مسئول اصلی.</a-typography-text>
|
||||
|
||||
@@ -4,11 +4,16 @@ import { RouterLink, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
Alert as AAlert,
|
||||
Avatar as AAvatar,
|
||||
Button as AButton,
|
||||
Card as ACard,
|
||||
Checkbox as ACheckbox,
|
||||
Dropdown as ADropdown,
|
||||
Empty as AEmpty,
|
||||
Flex as AFlex,
|
||||
Input as AInput,
|
||||
Menu as AMenu,
|
||||
MenuItem as AMenuItem,
|
||||
Modal as AModal,
|
||||
Space as ASpace,
|
||||
Spin as ASpin,
|
||||
Tag as ATag,
|
||||
@@ -18,25 +23,43 @@ import {
|
||||
import {
|
||||
CalendarOutlined,
|
||||
HolderOutlined,
|
||||
MoreOutlined,
|
||||
PhoneOutlined,
|
||||
PlusOutlined,
|
||||
ReloadOutlined,
|
||||
UnorderedListOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
|
||||
import type { LeadBoardColumnDto, LeadDto } from '@mento/shared';
|
||||
import { canManageSettings } from '@/lib/roles';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import type { LeadBoardColumnDto, LeadDto, LeadStageDto } from '@mento/shared';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { token } = theme.useToken();
|
||||
const router = useRouter();
|
||||
const auth = useAuthStore();
|
||||
const canManage = computed(() => canManageSettings(auth.user?.role));
|
||||
|
||||
const GAP = 16;
|
||||
const COL_WIDTH = 280;
|
||||
|
||||
const loading = ref(false);
|
||||
const moving = ref(false);
|
||||
const stageSaving = ref(false);
|
||||
const error = ref('');
|
||||
const stageError = ref('');
|
||||
const columns = ref<LeadBoardColumnDto[]>([]);
|
||||
const stages = ref<LeadStageDto[]>([]);
|
||||
const renameTarget = ref<LeadStageDto | null>(null);
|
||||
const renameName = ref('');
|
||||
const addOpen = ref(false);
|
||||
const addName = ref('');
|
||||
const addConverted = ref(false);
|
||||
const addLost = ref(false);
|
||||
const addUnqualified = ref(false);
|
||||
const deleteTarget = ref<LeadStageDto | null>(null);
|
||||
const moveConfirm = ref<{ stageIds: string[]; message: string } | null>(null);
|
||||
const draggingId = ref<string | null>(null);
|
||||
const dropStageId = ref<string | null>(null);
|
||||
/** بعد از درگ، کلیک باز شدن جزئیات را یک فریم نادیده بگیر */
|
||||
@@ -137,14 +160,6 @@ const cardBodyStyle = computed(() => ({
|
||||
margin: 0,
|
||||
}));
|
||||
|
||||
function leadInitials(lead: LeadDto) {
|
||||
const raw = (lead.contactName || lead.title || '?').trim();
|
||||
const parts = raw.split(/\s+/).filter(Boolean);
|
||||
if (!parts.length) return '؟';
|
||||
if (parts.length === 1) return parts[0]!.slice(0, 1);
|
||||
return `${parts[0]!.slice(0, 1)}${parts[parts.length - 1]!.slice(0, 1)}`;
|
||||
}
|
||||
|
||||
function leadSubtitle(lead: LeadDto) {
|
||||
return [lead.contactName, lead.city].filter(Boolean).join(' · ') || '';
|
||||
}
|
||||
@@ -158,22 +173,288 @@ function formatDate(value: string | null) {
|
||||
}
|
||||
}
|
||||
|
||||
function apiMessage(e: unknown, fallback: string) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] } | undefined)?.message;
|
||||
if (Array.isArray(msg)) return msg[0] ?? fallback;
|
||||
if (typeof msg === 'string' && msg) return msg;
|
||||
if (!e.response) return 'اتصال به API برقرار نشد.';
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function isOpenStage(stage: Pick<LeadStageDto, 'isConverted' | 'isLost' | 'isUnqualified'>) {
|
||||
return !stage.isConverted && !stage.isLost && !stage.isUnqualified;
|
||||
}
|
||||
|
||||
function entryStage(list: LeadStageDto[]) {
|
||||
return list.find(isOpenStage) ?? null;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const { data } = await api.get<LeadBoardColumnDto[]>('/leads/board');
|
||||
columns.value = data;
|
||||
const [board, stageRows] = await Promise.all([
|
||||
api.get<LeadBoardColumnDto[]>('/leads/board'),
|
||||
api.get<LeadStageDto[]>('/leads/stages'),
|
||||
]);
|
||||
columns.value = board.data;
|
||||
stages.value = stageRows.data;
|
||||
} catch (e) {
|
||||
error.value =
|
||||
axios.isAxiosError(e) && !e.response
|
||||
? 'اتصال به API برقرار نشد.'
|
||||
: 'بارگذاری مسیر لیدها ناموفق بود.';
|
||||
error.value = apiMessage(e, 'بارگذاری مسیر لیدها ناموفق بود.');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function visibleIndex(stageId: string) {
|
||||
return stages.value.filter((stage) => stage.showOnBoard).findIndex((stage) => stage.id === stageId);
|
||||
}
|
||||
|
||||
function plannedOrder(stageId: string, dir: -1 | 1) {
|
||||
const visible = stages.value.filter((stage) => stage.showOnBoard);
|
||||
const from = visible.findIndex((stage) => stage.id === stageId);
|
||||
const to = from + dir;
|
||||
if (from < 0 || to < 0 || to >= visible.length) return null;
|
||||
const nextVisible = visible.slice();
|
||||
const [item] = nextVisible.splice(from, 1);
|
||||
if (!item) return null;
|
||||
nextVisible.splice(to, 0, item);
|
||||
const queue = nextVisible.slice();
|
||||
return stages.value.map((stage) => (stage.showOnBoard ? queue.shift()!.id : stage.id));
|
||||
}
|
||||
|
||||
function entryIn(ids: string[]) {
|
||||
const byId = new Map(stages.value.map((stage) => [stage.id, stage]));
|
||||
for (const id of ids) {
|
||||
const stage = byId.get(id);
|
||||
if (stage && isOpenStage(stage)) return stage;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function persistOrder(stageIds: string[]) {
|
||||
stageSaving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
await api.patch('/leads/stages/reorder', { stageIds });
|
||||
moveConfirm.value = null;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiMessage(e, 'جابهجایی ستون ناموفق بود.');
|
||||
} finally {
|
||||
stageSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function requestMove(stageId: string, dir: -1 | 1) {
|
||||
const next = plannedOrder(stageId, dir);
|
||||
if (!next) return;
|
||||
const before = entryStage(stages.value);
|
||||
const after = entryIn(next);
|
||||
if (before && after && before.id !== after.id) {
|
||||
moveConfirm.value = {
|
||||
stageIds: next,
|
||||
message: `با این جابهجایی، لیدهای تازهٔ فرم و ورود از اکسل بهجای «${before.name}» در ستون «${after.name}» ثبت میشوند. لیدهای فعلی سر جایشان میمانند.`,
|
||||
};
|
||||
return;
|
||||
}
|
||||
void persistOrder(next);
|
||||
}
|
||||
|
||||
function nameTaken(name: string, exceptId?: string) {
|
||||
const trimmed = name.trim();
|
||||
return stages.value.some((stage) => stage.id !== exceptId && stage.name === trimmed);
|
||||
}
|
||||
|
||||
function openRename(stage: LeadStageDto) {
|
||||
stageError.value = '';
|
||||
renameName.value = stage.name;
|
||||
renameTarget.value = stage;
|
||||
}
|
||||
|
||||
function openAdd() {
|
||||
stageError.value = '';
|
||||
addName.value = '';
|
||||
addConverted.value = false;
|
||||
addLost.value = false;
|
||||
addUnqualified.value = false;
|
||||
addOpen.value = true;
|
||||
}
|
||||
|
||||
function openDelete(stage: LeadStageDto) {
|
||||
stageError.value = '';
|
||||
deleteTarget.value = stage;
|
||||
}
|
||||
|
||||
function onColumnMenu(stageId: string, key: string) {
|
||||
const stage = stages.value.find((item) => item.id === stageId);
|
||||
if (!stage) return;
|
||||
if (key === 'rename') openRename(stage);
|
||||
else if (key === 'right') requestMove(stageId, -1);
|
||||
else if (key === 'left') requestMove(stageId, 1);
|
||||
else if (key === 'delete') openDelete(stage);
|
||||
}
|
||||
|
||||
const renameNotes = computed(() => {
|
||||
const stage = renameTarget.value;
|
||||
if (!stage) return [];
|
||||
const lines = [
|
||||
'اسم جدید در فهرست لیدها، صفحهٔ جزئیات، فرمساز و فیلتر پیامک هم دیده میشود. لیدهای این ستون سر جایشان میمانند.',
|
||||
];
|
||||
if (entryStage(stages.value)?.id === stage.id) {
|
||||
lines.push('شمارش لیدهای تازه به اسم ستون وابسته نیست و با این تغییر نام بههم نمیریزد.');
|
||||
}
|
||||
if (stage.isConverted) lines.push('علامت تبدیلشده روی همین ستون میماند.');
|
||||
if (stage.isLost) lines.push('علامت از دسترفته روی همین ستون میماند و آمار همان را میشمارد.');
|
||||
if (stage.isUnqualified) lines.push('علامت نامرتبط روی همین ستون میماند.');
|
||||
return lines;
|
||||
});
|
||||
|
||||
const addNotes = computed(() => {
|
||||
const lines = [
|
||||
'ستون در انتهای مسیر اضافه میشود. لیدهای ستونهای دیگر جابهجا نمیشوند.',
|
||||
];
|
||||
const flags = [addConverted.value, addLost.value, addUnqualified.value].filter(Boolean).length;
|
||||
if (flags > 1) {
|
||||
lines.push(
|
||||
'یک ستون را با یک علامت بسازید. اگر تبدیلشده، از دسترفته و نامرتبط با هم باشند، فرم و آمار هر کدام رفتار جدا دارند.',
|
||||
);
|
||||
} else if (!flags) {
|
||||
lines.push('بدون علامت، این ستون مرحلهٔ عادی است و مقصد تبدیل به مشتری یا آمار از دسترفته نمیشود.');
|
||||
}
|
||||
if (addConverted.value && stages.value.some((stage) => stage.isConverted)) {
|
||||
lines.push(
|
||||
'ستون تبدیلشدهٔ دیگری هم هست. تبدیل به مشتری به اولین ستون تبدیلشده در ترتیب مسیر میرود.',
|
||||
);
|
||||
}
|
||||
if (addLost.value && stages.value.some((stage) => stage.isLost)) {
|
||||
lines.push('ستون از دسترفتهٔ دیگری هم هست. آمار، لیدهای هر دو ستون را میشمارد.');
|
||||
}
|
||||
return lines;
|
||||
});
|
||||
|
||||
const deleteInfo = computed(() => {
|
||||
const stage = deleteTarget.value;
|
||||
if (!stage) return { blocked: '', lines: [] as string[] };
|
||||
const total = columns.value.find((col) => col.stage.id === stage.id)?.total ?? stage.leadCount ?? 0;
|
||||
if (total > 0) {
|
||||
return {
|
||||
blocked: `ستون «${stage.name}» ${toFaDigits(total)} لید دارد و حذف نمیشود. اول لیدها را به ستون دیگری ببرید.`,
|
||||
lines: [] as string[],
|
||||
};
|
||||
}
|
||||
const others = stages.value.filter((item) => item.id !== stage.id);
|
||||
const lines = [
|
||||
'این ستون از فهرست لیدها، جزئیات، فرمساز و فیلتر پیامک هم برداشته میشود.',
|
||||
];
|
||||
if (stage.isConverted && !others.some((item) => item.isConverted)) {
|
||||
lines.push(
|
||||
'این تنها ستون تبدیلشده است. بعد از حذف، تبدیل به مشتری هنوز انجام میشود ولی لید به ستون تبدیلشده منتقل نمیشود.',
|
||||
);
|
||||
}
|
||||
if (stage.isLost && !others.some((item) => item.isLost)) {
|
||||
lines.push('این تنها ستون از دسترفته است. بعد از حذف، آمار لیدهای از دسترفته دیگر ستونی برای شمردن ندارد.');
|
||||
}
|
||||
if (stage.isUnqualified && !others.some((item) => item.isUnqualified)) {
|
||||
lines.push('این تنها ستون نامرتبط است. بعد از حذف، مسیر دیگر ستون مشخصی برای لید نامرتبط ندارد.');
|
||||
}
|
||||
if (entryStage(stages.value)?.id === stage.id) {
|
||||
const next = others.find(isOpenStage);
|
||||
lines.push(
|
||||
next
|
||||
? `لیدهای تازهٔ فرم و ورود از اکسل بهجای این ستون در «${next.name}» ثبت میشوند.`
|
||||
: 'ستون باز دیگری نمیماند. لید تازهٔ فرم در اولین ستون باقیمانده ثبت میشود.',
|
||||
);
|
||||
}
|
||||
lines.push('اگر فرمی این ستون را مرحلهٔ اولیه کرده باشد، لید تازه به اولین ستون باز میرود.');
|
||||
return { blocked: '', lines };
|
||||
});
|
||||
|
||||
async function saveRename() {
|
||||
const stage = renameTarget.value;
|
||||
const name = renameName.value.trim();
|
||||
if (!stage || stageSaving.value) return;
|
||||
if (name.length < 1) {
|
||||
stageError.value = 'نام ستون لازم است.';
|
||||
return;
|
||||
}
|
||||
if (name.length > 80) {
|
||||
stageError.value = 'نام ستون حداکثر ۸۰ کاراکتر است.';
|
||||
return;
|
||||
}
|
||||
if (nameTaken(name, stage.id)) {
|
||||
stageError.value = 'ستونی با این نام وجود دارد.';
|
||||
return;
|
||||
}
|
||||
if (name === stage.name) {
|
||||
renameTarget.value = null;
|
||||
return;
|
||||
}
|
||||
stageSaving.value = true;
|
||||
stageError.value = '';
|
||||
try {
|
||||
await api.patch(`/leads/stages/${stage.id}`, { name });
|
||||
renameTarget.value = null;
|
||||
await load();
|
||||
} catch (e) {
|
||||
stageError.value = apiMessage(e, 'تغییر نام ستون ناموفق بود.');
|
||||
} finally {
|
||||
stageSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveAdd() {
|
||||
const name = addName.value.trim();
|
||||
if (stageSaving.value) return;
|
||||
if (!name) {
|
||||
stageError.value = 'نام ستون لازم است.';
|
||||
return;
|
||||
}
|
||||
if (name.length > 80) {
|
||||
stageError.value = 'نام ستون حداکثر ۸۰ کاراکتر است.';
|
||||
return;
|
||||
}
|
||||
if (nameTaken(name)) {
|
||||
stageError.value = 'ستونی با این نام وجود دارد.';
|
||||
return;
|
||||
}
|
||||
stageSaving.value = true;
|
||||
stageError.value = '';
|
||||
try {
|
||||
await api.post('/leads/stages', {
|
||||
name,
|
||||
showOnBoard: true,
|
||||
isConverted: addConverted.value,
|
||||
isLost: addLost.value,
|
||||
isUnqualified: addUnqualified.value,
|
||||
});
|
||||
addOpen.value = false;
|
||||
await load();
|
||||
} catch (e) {
|
||||
stageError.value = apiMessage(e, 'افزودن ستون ناموفق بود.');
|
||||
} finally {
|
||||
stageSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
const stage = deleteTarget.value;
|
||||
if (!stage || deleteInfo.value.blocked || stageSaving.value) return;
|
||||
stageSaving.value = true;
|
||||
stageError.value = '';
|
||||
try {
|
||||
await api.delete(`/leads/stages/${stage.id}`);
|
||||
deleteTarget.value = null;
|
||||
await load();
|
||||
} catch (e) {
|
||||
stageError.value = apiMessage(e, 'حذف ستون ناموفق بود.');
|
||||
} finally {
|
||||
stageSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openLead(lead: LeadDto) {
|
||||
if (suppressCardClick || draggingId.value || moving.value) return;
|
||||
void router.push({ name: 'lead-detail', params: { id: lead.id } });
|
||||
@@ -223,11 +504,16 @@ async function onDrop(stageId: string, event: DragEvent) {
|
||||
|
||||
columns.value = columns.value.map((c) => {
|
||||
if (c.stage.id === fromCol.stage.id) {
|
||||
return { ...c, leads: c.leads.filter((l) => l.id !== leadId) };
|
||||
return {
|
||||
...c,
|
||||
total: Math.max(0, c.total - 1),
|
||||
leads: c.leads.filter((l) => l.id !== leadId),
|
||||
};
|
||||
}
|
||||
if (c.stage.id === stageId) {
|
||||
return {
|
||||
...c,
|
||||
total: c.total + 1,
|
||||
leads: [{ ...lead, stageId, stageName: c.stage.name }, ...c.leads],
|
||||
};
|
||||
}
|
||||
@@ -257,7 +543,7 @@ onMounted(load);
|
||||
مسیر لیدها
|
||||
</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
کشیدن و رها کردن برای تغییر وضعیت
|
||||
کشیدن کارت برای تغییر وضعیت. از منوی هر ستون میتوانید نام، ترتیب و حذف را عوض کنید.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
<a-space :size="GAP">
|
||||
@@ -298,9 +584,14 @@ onMounted(load);
|
||||
|
||||
<a-empty
|
||||
v-if="!loading && !columns.length"
|
||||
description="مرحلهای برای نمایش در مسیر لیدها نیست. در تنظیمات مراحل لید، «نمایش روی مسیر» را فعال کنید."
|
||||
description="مرحلهای برای نمایش در مسیر لیدها نیست."
|
||||
:style="{ margin: 'auto' }"
|
||||
/>
|
||||
>
|
||||
<a-button v-if="canManage" type="primary" @click="openAdd">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
افزودن ستون
|
||||
</a-button>
|
||||
</a-empty>
|
||||
|
||||
<div
|
||||
v-else-if="columns.length"
|
||||
@@ -328,9 +619,31 @@ onMounted(load);
|
||||
/>
|
||||
<a-typography-text strong>{{ col.stage.name }}</a-typography-text>
|
||||
</a-space>
|
||||
<a-typography-text type="secondary">
|
||||
{{ toFaDigits(col.leads.length) }}
|
||||
</a-typography-text>
|
||||
<a-flex align="center" :gap="4">
|
||||
<a-typography-text type="secondary">
|
||||
{{ toFaDigits(col.total) }}
|
||||
</a-typography-text>
|
||||
<a-dropdown v-if="canManage" :trigger="['click']">
|
||||
<a-button type="text" aria-label="منوی ستون" @click.stop>
|
||||
<template #icon><MoreOutlined /></template>
|
||||
</a-button>
|
||||
<template #overlay>
|
||||
<a-menu @click="({ key }) => onColumnMenu(col.stage.id, String(key))">
|
||||
<a-menu-item key="rename">تغییر نام</a-menu-item>
|
||||
<a-menu-item key="right" :disabled="visibleIndex(col.stage.id) <= 0">
|
||||
انتقال به راست
|
||||
</a-menu-item>
|
||||
<a-menu-item
|
||||
key="left"
|
||||
:disabled="visibleIndex(col.stage.id) < 0 || visibleIndex(col.stage.id) >= stages.filter((stage) => stage.showOnBoard).length - 1"
|
||||
>
|
||||
انتقال به چپ
|
||||
</a-menu-item>
|
||||
<a-menu-item key="delete" danger>حذف ستون</a-menu-item>
|
||||
</a-menu>
|
||||
</template>
|
||||
</a-dropdown>
|
||||
</a-flex>
|
||||
</div>
|
||||
|
||||
<div :style="columnBodyStyle">
|
||||
@@ -376,16 +689,6 @@ onMounted(load);
|
||||
>
|
||||
<HolderOutlined />
|
||||
</span>
|
||||
<a-avatar
|
||||
:style="{
|
||||
background: token.colorPrimaryBg,
|
||||
color: token.colorPrimary,
|
||||
flexShrink: 0,
|
||||
fontWeight: 700,
|
||||
}"
|
||||
>
|
||||
{{ leadInitials(lead) }}
|
||||
</a-avatar>
|
||||
<div :style="{ flex: 1, minWidth: 0 }">
|
||||
<a-typography-text
|
||||
strong
|
||||
@@ -501,8 +804,110 @@ onMounted(load);
|
||||
</a-typography-text>
|
||||
</div>
|
||||
</div>
|
||||
<a-flex
|
||||
v-if="canManage"
|
||||
vertical
|
||||
justify="center"
|
||||
align="center"
|
||||
:gap="8"
|
||||
:style="{
|
||||
flex: `0 0 ${COL_WIDTH}px`,
|
||||
width: `${COL_WIDTH}px`,
|
||||
alignSelf: 'stretch',
|
||||
border: `1px dashed ${token.colorBorder}`,
|
||||
borderRadius: `${token.borderRadiusLG}px`,
|
||||
background: token.colorFillAlter,
|
||||
}"
|
||||
>
|
||||
<a-button type="primary" :disabled="stageSaving" @click="openAdd">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
افزودن ستون
|
||||
</a-button>
|
||||
</a-flex>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a-modal
|
||||
:open="!!renameTarget"
|
||||
title="تغییر نام ستون"
|
||||
ok-text="ذخیره"
|
||||
cancel-text="انصراف"
|
||||
:confirm-loading="stageSaving"
|
||||
@ok="saveRename"
|
||||
@cancel="renameTarget = null"
|
||||
>
|
||||
<a-flex vertical :gap="12">
|
||||
<a-alert
|
||||
v-for="line in renameNotes"
|
||||
:key="line"
|
||||
type="info"
|
||||
show-icon
|
||||
:message="line"
|
||||
/>
|
||||
<a-alert v-if="stageError" type="error" show-icon :message="stageError" />
|
||||
<a-input v-model:value="renameName" :maxlength="80" placeholder="نام ستون" @press-enter="saveRename" />
|
||||
</a-flex>
|
||||
</a-modal>
|
||||
|
||||
<a-modal
|
||||
:open="addOpen"
|
||||
title="افزودن ستون"
|
||||
ok-text="افزودن"
|
||||
cancel-text="انصراف"
|
||||
:confirm-loading="stageSaving"
|
||||
@ok="saveAdd"
|
||||
@cancel="addOpen = false"
|
||||
>
|
||||
<a-flex vertical :gap="12">
|
||||
<a-alert
|
||||
v-for="(line, index) in addNotes"
|
||||
:key="index"
|
||||
:type="index === 0 ? 'info' : 'warning'"
|
||||
show-icon
|
||||
:message="line"
|
||||
/>
|
||||
<a-alert v-if="stageError" type="error" show-icon :message="stageError" />
|
||||
<a-input v-model:value="addName" :maxlength="80" placeholder="مثلاً تماس اولیه" @press-enter="saveAdd" />
|
||||
<a-checkbox v-model:checked="addConverted">علامت تبدیلشده</a-checkbox>
|
||||
<a-checkbox v-model:checked="addLost">علامت از دسترفته</a-checkbox>
|
||||
<a-checkbox v-model:checked="addUnqualified">علامت نامرتبط</a-checkbox>
|
||||
</a-flex>
|
||||
</a-modal>
|
||||
|
||||
<a-modal
|
||||
:open="!!deleteTarget"
|
||||
:title="deleteInfo.blocked ? 'حذف ستون ممکن نیست' : 'حذف ستون'"
|
||||
:ok-text="deleteInfo.blocked ? 'متوجه شدم' : 'حذف ستون'"
|
||||
:ok-button-props="deleteInfo.blocked ? undefined : { danger: true }"
|
||||
cancel-text="انصراف"
|
||||
:confirm-loading="stageSaving"
|
||||
@ok="deleteInfo.blocked ? (deleteTarget = null) : confirmDelete()"
|
||||
@cancel="deleteTarget = null"
|
||||
>
|
||||
<a-flex vertical :gap="12">
|
||||
<a-alert v-if="deleteInfo.blocked" type="error" show-icon :message="deleteInfo.blocked" />
|
||||
<a-alert
|
||||
v-for="line in deleteInfo.lines"
|
||||
:key="line"
|
||||
type="warning"
|
||||
show-icon
|
||||
:message="line"
|
||||
/>
|
||||
<a-alert v-if="stageError" type="error" show-icon :message="stageError" />
|
||||
</a-flex>
|
||||
</a-modal>
|
||||
|
||||
<a-modal
|
||||
:open="!!moveConfirm"
|
||||
title="جابهجایی ستون"
|
||||
ok-text="جابهجا شود"
|
||||
cancel-text="انصراف"
|
||||
:confirm-loading="stageSaving"
|
||||
@ok="moveConfirm && persistOrder(moveConfirm.stageIds)"
|
||||
@cancel="moveConfirm = null"
|
||||
>
|
||||
<a-alert v-if="moveConfirm" type="warning" show-icon :message="moveConfirm.message" />
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
Alert as AAlert,
|
||||
Button as AButton,
|
||||
Card as ACard,
|
||||
Checkbox as ACheckbox,
|
||||
Col as ACol,
|
||||
Descriptions as ADescriptions,
|
||||
DescriptionsItem as ADescriptionsItem,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
Empty as AEmpty,
|
||||
Flex as AFlex,
|
||||
Form as AForm,
|
||||
Image as AImage,
|
||||
FormItem as AFormItem,
|
||||
Input as AInput,
|
||||
List as AList,
|
||||
@@ -44,6 +46,7 @@ import {
|
||||
UserAddOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import { isBirthDateAnswer, leadNoteFileIsImage, parseLeadFormNotes } from '@/lib/lead-form-notes';
|
||||
import {
|
||||
formatClockFa,
|
||||
formatJalaliNumeric,
|
||||
@@ -52,7 +55,7 @@ import {
|
||||
toFaDigits,
|
||||
} from '@/lib/jalali';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { canManageSettings } from '@/lib/roles';
|
||||
import { canAssignToOthers } from '@/lib/assign-access';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import RelatedTasksPanel from '@/components/routines/RelatedTasksPanel.vue';
|
||||
import SmsComposeModal from '@/components/SmsComposeModal.vue';
|
||||
@@ -64,8 +67,9 @@ import type {
|
||||
LeadStageDto,
|
||||
OrgUserDto,
|
||||
PaginatedResponse,
|
||||
PersonGender,
|
||||
} from '@mento/shared';
|
||||
import { ACTIVITY_TYPE_LABELS } from '@mento/shared';
|
||||
import { ACTIVITY_TYPE_LABELS, PERSON_GENDERS, PERSON_GENDER_LABELS, splitPersonHonorific } from '@mento/shared';
|
||||
import { canUseBehavior } from '@/lib/behavior-access';
|
||||
import SalesCopilotPanel from '@/components/behavior/SalesCopilotPanel.vue';
|
||||
|
||||
@@ -78,7 +82,7 @@ type LeadDetail = LeadDto & { events: LeadEventDto[] };
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const auth = useAuthStore();
|
||||
const isAdmin = computed(() => canManageSettings(auth.user?.role));
|
||||
const canAssignOthers = computed(() => canAssignToOthers(auth.user, 'leads'));
|
||||
const canBehavior = computed(() => canUseBehavior(auth.user));
|
||||
const copilotOpen = ref(false);
|
||||
|
||||
@@ -111,6 +115,8 @@ let narrowMq: MediaQueryList | null = null;
|
||||
const editForm = ref({
|
||||
title: '',
|
||||
contactName: '',
|
||||
gender: 'none' as PersonGender,
|
||||
showGenderInName: false,
|
||||
mobile: '',
|
||||
phone: '',
|
||||
city: '',
|
||||
@@ -131,6 +137,42 @@ function formatDate(value: string | null | undefined) {
|
||||
}
|
||||
}
|
||||
|
||||
const noteView = computed(() => parseLeadFormNotes(lead.value?.notes));
|
||||
const formBirthDate = computed(
|
||||
() => noteView.value.rows.find((row) => isBirthDateAnswer(row.label) && !row.file)?.text ?? '',
|
||||
);
|
||||
const shownBirthDate = computed(() => {
|
||||
if (lead.value?.birthDate) return formatDate(lead.value.birthDate);
|
||||
return formBirthDate.value || '—';
|
||||
});
|
||||
const answerRows = computed(() =>
|
||||
noteView.value.rows.filter((row) => !isBirthDateAnswer(row.label)),
|
||||
);
|
||||
|
||||
const genderOptions = PERSON_GENDERS.map((key) => ({
|
||||
value: key,
|
||||
label: PERSON_GENDER_LABELS[key],
|
||||
}));
|
||||
|
||||
const genderLabel = computed(() => {
|
||||
const gender = lead.value?.gender;
|
||||
const key = gender === 'male' || gender === 'female' ? gender : 'none';
|
||||
const label = PERSON_GENDER_LABELS[key];
|
||||
return lead.value?.showGenderInName && key !== 'none' ? `${label} · در نام` : label;
|
||||
});
|
||||
|
||||
function bareLeadName(value: string) {
|
||||
const split = splitPersonHonorific(value, '');
|
||||
return [split.firstName, split.lastName].filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
watch(
|
||||
() => editForm.value.gender,
|
||||
(value) => {
|
||||
if (value === 'none') editForm.value.showGenderInName = false;
|
||||
},
|
||||
);
|
||||
|
||||
function apiError(e: unknown, fallback: string) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
@@ -172,9 +214,13 @@ function startEdit() {
|
||||
if (!lead.value) return;
|
||||
editing.value = true;
|
||||
moreOpen.value = false;
|
||||
const gender =
|
||||
lead.value.gender === 'male' || lead.value.gender === 'female' ? lead.value.gender : 'none';
|
||||
editForm.value = {
|
||||
title: lead.value.title,
|
||||
contactName: lead.value.contactName ?? '',
|
||||
title: bareLeadName(lead.value.title),
|
||||
contactName: bareLeadName(lead.value.contactName ?? ''),
|
||||
gender,
|
||||
showGenderInName: !!lead.value.showGenderInName && gender !== 'none',
|
||||
mobile: lead.value.mobile,
|
||||
phone: lead.value.phone ?? '',
|
||||
city: lead.value.city ?? '',
|
||||
@@ -200,6 +246,9 @@ async function saveEdit() {
|
||||
await api.patch(`/leads/${id.value}`, {
|
||||
title: editForm.value.title.trim(),
|
||||
contactName: editForm.value.contactName.trim() || null,
|
||||
gender: editForm.value.gender,
|
||||
showGenderInName:
|
||||
editForm.value.gender !== 'none' && editForm.value.showGenderInName,
|
||||
mobile: editForm.value.mobile.trim(),
|
||||
phone: editForm.value.phone.trim() || null,
|
||||
city: editForm.value.city.trim() || null,
|
||||
@@ -447,7 +496,7 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
<a-col :span="24">
|
||||
<a-flex justify="space-between" align="center" wrap="wrap" :gap="token.marginSM">
|
||||
<a-space :size="12" align="start">
|
||||
<RouterLink :to="{ name: 'leads' }" custom v-slot="{ navigate }">
|
||||
<RouterLink :to="{ name: 'leads-board' }" custom v-slot="{ navigate }">
|
||||
<a-button @click="navigate">
|
||||
<template #icon><ArrowLeftOutlined /></template>
|
||||
</a-button>
|
||||
@@ -539,6 +588,24 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
<a-input v-model:value="editForm.contactName" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="جنسیت">
|
||||
<a-select v-model:value="editForm.gender" :options="genderOptions" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item
|
||||
label="نمایش در نام"
|
||||
extra="مرد «جناب آقای» و زن «سرکار خانم» ابتدای نام مخاطب ذخیره میشود. اگر نام مخاطب خالی باشد روی عنوان مینشیند و با تبدیل به مشتری به تهحساب هم میرود."
|
||||
>
|
||||
<a-checkbox
|
||||
v-model:checked="editForm.showGenderInName"
|
||||
:disabled="editForm.gender === 'none'"
|
||||
>
|
||||
نمایش در نام
|
||||
</a-checkbox>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="8">
|
||||
<a-form-item label="موبایل" required>
|
||||
<a-input
|
||||
@@ -652,6 +719,7 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
<a-descriptions-item label="مالک/مخاطب">
|
||||
{{ lead.contactName || '—' }}
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="جنسیت">{{ genderLabel }}</a-descriptions-item>
|
||||
<a-descriptions-item label="موبایل">
|
||||
<span dir="ltr">{{ lead.mobile }}</span>
|
||||
</a-descriptions-item>
|
||||
@@ -674,7 +742,7 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
{{ lead.assigneeName || '—' }}
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="تاریخ تولد">
|
||||
{{ formatDate(lead.birthDate) }}
|
||||
{{ shownBirthDate }}
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="تاریخ ثبت">
|
||||
{{ formatDate(lead.createdAt) }}
|
||||
@@ -695,8 +763,49 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
>
|
||||
<div v-for="(addr, i) in lead.addresses" :key="i">{{ addr }}</div>
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item v-if="lead.notes" label="یادداشت" :span="2">
|
||||
{{ lead.notes }}
|
||||
<template v-if="noteView.mode === 'answers'">
|
||||
<a-descriptions-item
|
||||
v-for="(row, index) in answerRows"
|
||||
:key="`${row.label}-${index}`"
|
||||
:label="row.label"
|
||||
:span="2"
|
||||
:label-style="{ whiteSpace: 'normal' }"
|
||||
:content-style="{ whiteSpace: 'normal' }"
|
||||
>
|
||||
<a-space v-if="row.file" direction="vertical" :size="4">
|
||||
<a-image
|
||||
v-if="row.file.dataUrl && leadNoteFileIsImage(row.file)"
|
||||
:src="row.file.dataUrl"
|
||||
:alt="row.file.name"
|
||||
:width="160"
|
||||
/>
|
||||
<a-typography-text>{{ row.file.name }}</a-typography-text>
|
||||
</a-space>
|
||||
<a-typography-paragraph
|
||||
v-else
|
||||
:ellipsis="{ rows: 4, expandable: true, symbol: 'بیشتر' }"
|
||||
:content="row.text"
|
||||
style="margin-bottom: 0"
|
||||
/>
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item
|
||||
v-if="noteView.prose"
|
||||
label="یادداشت"
|
||||
:span="2"
|
||||
>
|
||||
<a-typography-paragraph
|
||||
:ellipsis="{ rows: 4, expandable: true, symbol: 'بیشتر' }"
|
||||
:content="noteView.prose"
|
||||
style="margin-bottom: 0"
|
||||
/>
|
||||
</a-descriptions-item>
|
||||
</template>
|
||||
<a-descriptions-item v-else-if="lead.notes" label="یادداشت" :span="2">
|
||||
<a-typography-paragraph
|
||||
:ellipsis="{ rows: 4, expandable: true, symbol: 'بیشتر' }"
|
||||
:content="lead.notes"
|
||||
style="margin-bottom: 0"
|
||||
/>
|
||||
</a-descriptions-item>
|
||||
</a-descriptions>
|
||||
</template>
|
||||
@@ -736,6 +845,16 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
</template>
|
||||
</a-list>
|
||||
<a-empty v-else description="فعالیت مرتبطی نیست." />
|
||||
<RouterLink
|
||||
:to="{ name: 'activity-new', query: { leadId: lead.id } }"
|
||||
custom
|
||||
v-slot="{ navigate }"
|
||||
>
|
||||
<a-button type="dashed" block @click="navigate">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
ایجاد فعالیت
|
||||
</a-button>
|
||||
</RouterLink>
|
||||
|
||||
<a-divider orientation="right">جدول زمانی</a-divider>
|
||||
<a-timeline v-if="lead.events.length">
|
||||
@@ -780,17 +899,6 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
مشاهده همه فعالیتها
|
||||
</a-button>
|
||||
</RouterLink>
|
||||
<RouterLink
|
||||
v-if="narrow"
|
||||
:to="{ name: 'activity-new' }"
|
||||
custom
|
||||
v-slot="{ navigate }"
|
||||
>
|
||||
<a-button type="dashed" block @click="navigate">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
ایجاد فعالیت
|
||||
</a-button>
|
||||
</RouterLink>
|
||||
</template>
|
||||
</a-card>
|
||||
|
||||
@@ -804,7 +912,11 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
|
||||
<a-col :xs="24" :lg="7" :xl="6">
|
||||
<a-affix v-if="!narrow" :offset-top="24">
|
||||
<a-card title="اقدامات سریع" :bordered="false">
|
||||
<a-card
|
||||
title="اقدامات سریع"
|
||||
:bordered="false"
|
||||
:body-style="{ maxHeight: 'calc(100vh - 140px)', overflowY: 'auto' }"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
<a-divider orientation="right">پیامک</a-divider>
|
||||
<a-button
|
||||
@@ -828,7 +940,7 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
اعمال وضعیت
|
||||
</a-button>
|
||||
|
||||
<template v-if="isAdmin">
|
||||
<template v-if="canAssignOthers">
|
||||
<a-divider orientation="right">تخصیص کارشناس</a-divider>
|
||||
<a-form-item label="کارشناس">
|
||||
<a-select
|
||||
@@ -972,7 +1084,7 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
|
||||
</a-form-item>
|
||||
<a-button block :disabled="busy" @click="changeStage">اعمال وضعیت</a-button>
|
||||
|
||||
<template v-if="isAdmin">
|
||||
<template v-if="canAssignOthers">
|
||||
<a-divider orientation="right">تخصیص کارشناس</a-divider>
|
||||
<a-form-item label="کارشناس">
|
||||
<a-select
|
||||
|
||||
@@ -276,7 +276,16 @@ function formatValue(val: unknown): string {
|
||||
if (Array.isArray(val)) return val.join('، ');
|
||||
if (val === true) return 'بله';
|
||||
if (val === false) return 'خیر';
|
||||
return val == null ? '' : String(val);
|
||||
if (val == null) return '';
|
||||
const s = String(val);
|
||||
try {
|
||||
const parsed = JSON.parse(s) as { name?: string; dataUrl?: string };
|
||||
if (parsed?.name && parsed?.dataUrl) return `📎 ${parsed.name}`;
|
||||
} catch {
|
||||
/* not a file payload */
|
||||
}
|
||||
if (s.startsWith('data:')) return '📎 فایل پیوست';
|
||||
return s;
|
||||
}
|
||||
|
||||
function readyIcon(type: LeadFormFieldType | string): IconName {
|
||||
@@ -846,7 +855,7 @@ onMounted(load);
|
||||
{{ u.fullName }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="!assigneeIds.length" class="settings-empty">مسئولی انتخاب نشده؛ لید بدون مسئول ثبت میشود.</p>
|
||||
<p v-if="!assigneeIds.length" class="settings-empty">مسئولی انتخاب نشده. سرنخ جدید مسئولش همان مسئول اولین تماس اتوماسیون میشود؛ اگر تماسی ساخته نشود، مالک سازمان مسئول میماند.</p>
|
||||
</article>
|
||||
|
||||
<article class="settings-card optional">
|
||||
@@ -988,6 +997,7 @@ onMounted(load);
|
||||
<option value="lead.trade">صنف</option>
|
||||
<option value="lead.notes">یادداشت لید</option>
|
||||
<option value="lead.source">منبع لید</option>
|
||||
<option value="lead.gender">جنسیت</option>
|
||||
</optgroup>
|
||||
<optgroup label="شخص">
|
||||
<option value="person.fullName">نام کامل</option>
|
||||
@@ -997,6 +1007,7 @@ onMounted(load);
|
||||
<option value="person.email">ایمیل</option>
|
||||
<option value="person.phone">تلفن</option>
|
||||
<option value="person.position">سمت</option>
|
||||
<option value="person.gender">جنسیت شخص</option>
|
||||
</optgroup>
|
||||
<optgroup label="معامله">
|
||||
<option value="deal.title">عنوان معامله</option>
|
||||
|
||||
@@ -4,11 +4,22 @@ import { useRoute } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import type { PublicLeadFormDto, SubmitLeadFormResponse } from '@mento/shared';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import {
|
||||
FormFileTooLargeError,
|
||||
FORM_FILE_MAX_BYTES,
|
||||
encodeFormFileValue,
|
||||
formFileDisplayName,
|
||||
prepareFormFieldFile,
|
||||
} from '@/lib/form-file-compress';
|
||||
|
||||
const route = useRoute();
|
||||
const loading = ref(true);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const fieldErrors = reactive<Record<string, string>>({});
|
||||
const fileBusy = reactive<Record<string, boolean>>({});
|
||||
const fileInputKey = reactive<Record<string, number>>({});
|
||||
const done = ref(false);
|
||||
const thankYou = ref('');
|
||||
const started = ref(false);
|
||||
@@ -113,6 +124,50 @@ function hasMulti(key: string, option: string) {
|
||||
return (values[key] || '').split(',').map((s) => s.trim()).includes(option);
|
||||
}
|
||||
|
||||
function clearFile(key: string) {
|
||||
values[key] = '';
|
||||
fieldErrors[key] = '';
|
||||
fileInputKey[key] = (fileInputKey[key] ?? 0) + 1;
|
||||
}
|
||||
|
||||
async function onFileChange(key: string, event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
fieldErrors[key] = '';
|
||||
if (!file) {
|
||||
values[key] = '';
|
||||
return;
|
||||
}
|
||||
fileBusy[key] = true;
|
||||
try {
|
||||
const prepared = await prepareFormFieldFile(file);
|
||||
values[key] = encodeFormFileValue(prepared);
|
||||
} catch (e) {
|
||||
values[key] = '';
|
||||
input.value = '';
|
||||
fieldErrors[key] =
|
||||
e instanceof FormFileTooLargeError
|
||||
? e.message
|
||||
: e instanceof Error
|
||||
? e.message
|
||||
: 'آپلود فایل ناموفق بود.';
|
||||
} finally {
|
||||
fileBusy[key] = false;
|
||||
}
|
||||
}
|
||||
|
||||
function validateRequiredFiles(): string | null {
|
||||
if (!form.value) return null;
|
||||
for (const field of form.value.fields) {
|
||||
if (field.fieldType !== 'file' || !field.required) continue;
|
||||
if (!values[field.key]?.trim()) {
|
||||
fieldErrors[field.key] = 'آپلود فایل الزامی است.';
|
||||
return `فیلد «${field.label || 'آپلود فایل'}» را کامل کنید.`;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!form.value) return;
|
||||
if (isPreview) {
|
||||
@@ -120,6 +175,15 @@ async function submit() {
|
||||
done.value = true;
|
||||
return;
|
||||
}
|
||||
const fileErr = validateRequiredFiles();
|
||||
if (fileErr) {
|
||||
error.value = fileErr;
|
||||
return;
|
||||
}
|
||||
if (Object.values(fieldErrors).some(Boolean)) {
|
||||
error.value = 'لطفاً خطاهای فایل را برطرف کنید.';
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
@@ -189,7 +253,7 @@ onBeforeUnmount(() => window.removeEventListener('storage', onStorage));
|
||||
<template v-for="field in form.fields" :key="field.key">
|
||||
<p v-if="field.fieldType === 'heading'" class="heading">{{ field.label }}</p>
|
||||
<label v-else @focusin="onFieldFocus">
|
||||
{{ field.label }}
|
||||
{{ field.fieldType === 'file' ? (field.label || 'آپلود فایل') : field.label }}
|
||||
<span v-if="field.required" class="req">*</span>
|
||||
<textarea
|
||||
v-if="field.fieldType === 'textarea'"
|
||||
@@ -233,11 +297,40 @@ onBeforeUnmount(() => window.removeEventListener('storage', onStorage));
|
||||
★
|
||||
</button>
|
||||
</div>
|
||||
<div v-else-if="field.fieldType === 'date'" class="date-field">
|
||||
<JalaliDateInput
|
||||
v-model="values[field.key]"
|
||||
mode="date"
|
||||
:required="field.required"
|
||||
:placeholder="field.placeholder || 'انتخاب تاریخ شمسی'"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
<div v-else-if="field.fieldType === 'file'" class="file-field">
|
||||
<input
|
||||
:key="fileInputKey[field.key] ?? 0"
|
||||
type="file"
|
||||
:disabled="fileBusy[field.key]"
|
||||
:aria-label="field.label || 'آپلود فایل'"
|
||||
@change="onFileChange(field.key, $event)"
|
||||
/>
|
||||
<small class="file-hint">
|
||||
حداکثر {{ Math.round(FORM_FILE_MAX_BYTES / 1024) }} کیلوبایت پس از فشردهسازی
|
||||
</small>
|
||||
<p v-if="fileBusy[field.key]" class="muted">در حال فشردهسازی…</p>
|
||||
<p v-else-if="values[field.key]" class="file-ok">
|
||||
{{ formFileDisplayName(values[field.key]) }}
|
||||
<button type="button" class="file-clear" @click="clearFile(field.key)">
|
||||
حذف
|
||||
</button>
|
||||
</p>
|
||||
<p v-if="fieldErrors[field.key]" class="error">{{ fieldErrors[field.key] }}</p>
|
||||
</div>
|
||||
<input
|
||||
v-else
|
||||
v-model="values[field.key]"
|
||||
:type="field.fieldType === 'email' ? 'email' : field.fieldType === 'phone' ? 'tel' : field.fieldType === 'date' ? 'date' : field.fieldType === 'number' ? 'number' : field.fieldType === 'file' ? 'text' : 'text'"
|
||||
:placeholder="field.placeholder || (field.fieldType === 'file' ? 'نام فایل یا لینک' : '')"
|
||||
:type="field.fieldType === 'email' ? 'email' : field.fieldType === 'phone' ? 'tel' : field.fieldType === 'number' ? 'number' : 'text'"
|
||||
:placeholder="field.placeholder || ''"
|
||||
:required="field.required"
|
||||
/>
|
||||
</label>
|
||||
@@ -246,7 +339,7 @@ onBeforeUnmount(() => window.removeEventListener('storage', onStorage));
|
||||
<button
|
||||
class="btn"
|
||||
type="submit"
|
||||
:disabled="saving"
|
||||
:disabled="saving || Object.values(fileBusy).some(Boolean)"
|
||||
:style="{ background: form.submitColor || '#14b8a6' }"
|
||||
>
|
||||
<UiIcon v-if="!saving" name="send" :size="16" />
|
||||
@@ -321,6 +414,35 @@ input:focus, textarea:focus, select:focus { outline: none; border-color: #14b8a6
|
||||
.stars button { border: 0; background: none; font-size: 1.5rem; color: #cbd5e1; cursor: pointer; padding: 0; }
|
||||
.stars button.on { color: #eab308; }
|
||||
.heading { margin: 0.2rem 0 0; font-weight: 700; color: #0f172a; }
|
||||
.date-field { min-width: 0; }
|
||||
.date-field :deep(.jdi) { width: 100%; }
|
||||
.file-field { display: grid; gap: 0.35rem; }
|
||||
.file-field input[type='file'] {
|
||||
padding: 0.45rem 0.55rem;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
.file-hint { color: #94a3b8; font-size: 0.75rem; font-weight: 400; }
|
||||
.file-ok {
|
||||
margin: 0;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 500;
|
||||
color: #0f766e;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.file-clear {
|
||||
border: 0;
|
||||
background: #f1f5f9;
|
||||
color: #475569;
|
||||
border-radius: 6px;
|
||||
padding: 0.15rem 0.45rem;
|
||||
font: inherit;
|
||||
font-size: 0.75rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.hp {
|
||||
position: absolute;
|
||||
clip-path: inset(50%);
|
||||
|
||||
@@ -58,6 +58,7 @@ import {
|
||||
} from '@/lib/jalali';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { canManageSettings } from '@/lib/roles';
|
||||
import { canAssignToOthers } from '@/lib/assign-access';
|
||||
import { registerTableColumns, useTableColumns } from '@/lib/tableColumns';
|
||||
import TableColumnsMenu from '@/components/TableColumnsMenu.vue';
|
||||
import ExcelImportFlow from '@/components/ExcelImportFlow.vue';
|
||||
@@ -77,9 +78,10 @@ import type {
|
||||
LeadStageDto,
|
||||
LeadStatsDto,
|
||||
OrgUserDto,
|
||||
PersonGender,
|
||||
PaginatedResponse,
|
||||
} from '@mento/shared';
|
||||
import { brand } from '@mento/shared';
|
||||
import { brand, PERSON_GENDERS, PERSON_GENDER_LABELS, splitPersonHonorific } from '@mento/shared';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText, Paragraph: ATypographyParagraph } =
|
||||
Typography;
|
||||
@@ -146,6 +148,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const auth = useAuthStore();
|
||||
const isAdmin = computed(() => canManageSettings(auth.user?.role));
|
||||
const canAssignOthers = computed(() => canAssignToOthers(auth.user, 'leads'));
|
||||
|
||||
const q = ref(typeof route.query.q === 'string' ? route.query.q : '');
|
||||
const loading = ref(false);
|
||||
@@ -191,6 +194,8 @@ const editingLeadId = ref<string | null>(null);
|
||||
const createForm = ref({
|
||||
title: '',
|
||||
contactName: '',
|
||||
gender: 'none' as PersonGender,
|
||||
showGenderInName: false,
|
||||
mobile: '',
|
||||
city: '',
|
||||
region: '',
|
||||
@@ -656,12 +661,31 @@ const createModalTitle = computed(() =>
|
||||
editingLeadId.value ? 'ویرایش لید' : 'ثبت لید جدید',
|
||||
);
|
||||
|
||||
const genderOptions = PERSON_GENDERS.map((key) => ({
|
||||
value: key,
|
||||
label: PERSON_GENDER_LABELS[key],
|
||||
}));
|
||||
|
||||
function bareLeadName(value: string) {
|
||||
const split = splitPersonHonorific(value, '');
|
||||
return [split.firstName, split.lastName].filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
watch(
|
||||
() => createForm.value.gender,
|
||||
(value) => {
|
||||
if (value === 'none') createForm.value.showGenderInName = false;
|
||||
},
|
||||
);
|
||||
|
||||
function openCreate() {
|
||||
editingLeadId.value = null;
|
||||
createError.value = '';
|
||||
createForm.value = {
|
||||
title: '',
|
||||
contactName: '',
|
||||
gender: 'none',
|
||||
showGenderInName: false,
|
||||
mobile: '',
|
||||
city: '',
|
||||
region: '',
|
||||
@@ -693,8 +717,10 @@ function openEdit(lead: LeadDto) {
|
||||
editingLeadId.value = lead.id;
|
||||
createError.value = '';
|
||||
createForm.value = {
|
||||
title: lead.title,
|
||||
contactName: lead.contactName ?? '',
|
||||
title: bareLeadName(lead.title),
|
||||
contactName: bareLeadName(lead.contactName ?? ''),
|
||||
gender: lead.gender && lead.gender !== 'none' ? lead.gender : 'none',
|
||||
showGenderInName: !!lead.showGenderInName && lead.gender !== 'none',
|
||||
mobile: lead.mobile,
|
||||
city: lead.city ?? '',
|
||||
region: lead.region ?? '',
|
||||
@@ -857,6 +883,8 @@ async function submitCreate() {
|
||||
title: company || person || mobile,
|
||||
mobile,
|
||||
contactName: person || null,
|
||||
gender: createForm.value.gender,
|
||||
showGenderInName: createForm.value.gender !== 'none' && createForm.value.showGenderInName,
|
||||
city: createForm.value.city.trim() || null,
|
||||
region: createForm.value.region.trim() || null,
|
||||
source: createForm.value.source.trim() || null,
|
||||
@@ -1329,7 +1357,7 @@ onBeforeUnmount(() => {
|
||||
<a-typography-text>
|
||||
{{ toFaDigits(selectedIds.length) }} مورد انتخابشده
|
||||
</a-typography-text>
|
||||
<template v-if="isAdmin">
|
||||
<template v-if="canAssignOthers">
|
||||
<a-select
|
||||
v-model:value="assignUserId"
|
||||
placeholder="تخصیص به کارشناس"
|
||||
@@ -1338,6 +1366,8 @@ onBeforeUnmount(() => {
|
||||
:options="users.map((u) => ({ value: u.id, label: u.fullName }))"
|
||||
/>
|
||||
<a-button :disabled="!assignUserId || busy" @click="assignSelected">اعمال تخصیص</a-button>
|
||||
</template>
|
||||
<template v-if="isAdmin">
|
||||
<a-select
|
||||
v-model:value="bulkStageId"
|
||||
placeholder="تغییر وضعیت"
|
||||
@@ -1629,6 +1659,24 @@ onBeforeUnmount(() => {
|
||||
<a-input v-model:value="createForm.contactName" placeholder="مهدی احمدی" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="جنسیت">
|
||||
<a-select v-model:value="createForm.gender" :options="genderOptions" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item
|
||||
label="نمایش در نام"
|
||||
extra="مرد «جناب آقای» و زن «سرکار خانم» ابتدای نام مخاطب ذخیره میشود. اگر نام مخاطب خالی باشد روی عنوان مینشیند و با تبدیل به مشتری به تهحساب هم میرود."
|
||||
>
|
||||
<a-checkbox
|
||||
v-model:checked="createForm.showGenderInName"
|
||||
:disabled="createForm.gender === 'none'"
|
||||
>
|
||||
نمایش در نام
|
||||
</a-checkbox>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="24">
|
||||
<a-form-item label="موبایل">
|
||||
<template #extra>
|
||||
@@ -1711,7 +1759,8 @@ onBeforeUnmount(() => {
|
||||
<a-select
|
||||
v-model:value="createForm.assigneeId"
|
||||
allow-clear
|
||||
placeholder="بدون مسئول"
|
||||
:disabled="!canAssignOthers"
|
||||
:placeholder="canAssignOthers ? 'بدون مسئول' : 'خودتان'"
|
||||
style="width: 100%"
|
||||
:options="users.map((u) => ({ value: u.id, label: u.fullName }))"
|
||||
/>
|
||||
|
||||
@@ -137,7 +137,17 @@ async function submitPasswordLogin() {
|
||||
const result = await auth.login(identifier.value.trim(), password.value);
|
||||
await afterAuth(result);
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'ورود ناموفق بود');
|
||||
const msg = apiError(e, 'ورود ناموفق بود');
|
||||
error.value = msg;
|
||||
// اگر مدیر «ورود با کد» را فعال کرده، مستقیم به تب OTP هدایت کن
|
||||
if (msg.includes('ورود با کد') || msg.includes('رمز عبور برای این حساب غیرفعال')) {
|
||||
const id = identifier.value.trim();
|
||||
if (id && !id.includes('@')) mobile.value = id;
|
||||
mode.value = 'otp';
|
||||
otpStep.value = 'mobile';
|
||||
challenge.value = null;
|
||||
otpCode.value = '';
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
Alert as AAlert,
|
||||
Button as AButton,
|
||||
Card as ACard,
|
||||
Checkbox as ACheckbox,
|
||||
Col as ACol,
|
||||
Divider as ADivider,
|
||||
Flex as AFlex,
|
||||
@@ -34,10 +35,12 @@ import {
|
||||
SearchOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import type { CompanyDto, CreatePersonRequest, PersonDto, PersonMood } from '@mento/shared';
|
||||
import type { CompanyDto, CreatePersonRequest, PersonDto, PersonGender, PersonMood } from '@mento/shared';
|
||||
import { PERSON_GENDER_LABELS, PERSON_GENDERS, splitPersonHonorific } from '@mento/shared';
|
||||
import { PERSON_MOOD_LABELS, PERSON_MOODS } from '@/lib/person-mood';
|
||||
import { formatLocalDateInput, toFaDigits } from '@/lib/jalali';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import { useCustomerGroups } from '@/lib/customer-groups';
|
||||
import {
|
||||
filterPhoneContacts,
|
||||
isContactPickerSupported,
|
||||
@@ -84,6 +87,8 @@ const companies = ref<CompanyDto[]>([]);
|
||||
|
||||
const firstName = ref('');
|
||||
const lastName = ref('');
|
||||
const gender = ref<PersonGender>('none');
|
||||
const showGenderInName = ref(false);
|
||||
const email = ref('');
|
||||
const phone = ref('');
|
||||
const mobile = ref('');
|
||||
@@ -97,7 +102,13 @@ const notes = ref('');
|
||||
const tagsRaw = ref('');
|
||||
const companyId = ref('');
|
||||
const mood = ref<PersonMood>('newcomer');
|
||||
const groupIds = ref<string[]>([]);
|
||||
const customFields = ref<Record<string, unknown>>({});
|
||||
const { groups: customerGroups, loaded: groupsLoaded, load: loadCustomerGroups } =
|
||||
useCustomerGroups();
|
||||
const groupOptions = computed(() =>
|
||||
customerGroups.value.map((g) => ({ value: g.id, label: g.name })),
|
||||
);
|
||||
const loyaltyPoints = ref(0);
|
||||
const loyaltyTierName = ref('');
|
||||
|
||||
@@ -118,6 +129,15 @@ const companyOptions = computed(() => [
|
||||
...companies.value.map((c) => ({ value: c.id, label: c.name })),
|
||||
]);
|
||||
|
||||
const genderOptions = PERSON_GENDERS.map((key) => ({
|
||||
value: key,
|
||||
label: PERSON_GENDER_LABELS[key],
|
||||
}));
|
||||
|
||||
watch(gender, (value) => {
|
||||
if (value === 'none') showGenderInName.value = false;
|
||||
});
|
||||
|
||||
const backTo = computed(() =>
|
||||
isNew.value ? { name: 'contacts' as const } : { name: 'person-detail' as const, params: { id: id.value } },
|
||||
);
|
||||
@@ -242,8 +262,12 @@ function pickFromVcf() {
|
||||
}
|
||||
|
||||
function fill(p: PersonDto) {
|
||||
firstName.value = p.firstName;
|
||||
lastName.value = p.lastName;
|
||||
const bare = splitPersonHonorific(p.firstName, p.lastName);
|
||||
firstName.value = bare.firstName;
|
||||
lastName.value = bare.lastName;
|
||||
gender.value = p.gender && p.gender !== 'none' ? p.gender : (bare.gender ?? 'none');
|
||||
showGenderInName.value =
|
||||
gender.value !== 'none' && (p.showGenderInName || bare.gender != null);
|
||||
email.value = p.email ?? '';
|
||||
phone.value = p.phone ?? '';
|
||||
mobile.value = p.mobile ?? '';
|
||||
@@ -257,6 +281,7 @@ function fill(p: PersonDto) {
|
||||
tagsRaw.value = (p.tags ?? []).join('، ');
|
||||
companyId.value = p.company?.id ?? '';
|
||||
mood.value = p.mood || 'newcomer';
|
||||
groupIds.value = (p.groups ?? []).map((g) => g.id);
|
||||
customFields.value = { ...(p.customFields ?? {}) };
|
||||
loyaltyPoints.value = p.loyaltyPoints ?? 0;
|
||||
loyaltyTierName.value = p.loyaltyTier?.name ?? '';
|
||||
@@ -277,6 +302,7 @@ function removeAddress(index: number) {
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
void loadCustomerGroups().catch(() => undefined);
|
||||
try {
|
||||
const companiesRes = await api.get<{ items: CompanyDto[] }>('/companies', {
|
||||
params: { limit: 100 },
|
||||
@@ -321,6 +347,8 @@ function payload(): CreatePersonRequest {
|
||||
return {
|
||||
firstName: firstName.value,
|
||||
lastName: lastName.value,
|
||||
gender: gender.value,
|
||||
showGenderInName: gender.value !== 'none' && showGenderInName.value,
|
||||
email: email.value || undefined,
|
||||
phone: phone.value || undefined,
|
||||
mobile: mobile.value || undefined,
|
||||
@@ -334,6 +362,7 @@ function payload(): CreatePersonRequest {
|
||||
tags: parseTags(tagsRaw.value),
|
||||
companyId: companyId.value || null,
|
||||
mood: mood.value,
|
||||
groupIds: groupIds.value,
|
||||
customFields: customFields.value,
|
||||
};
|
||||
}
|
||||
@@ -452,6 +481,21 @@ onMounted(load);
|
||||
<a-input v-model:value="lastName" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="جنسیت">
|
||||
<a-select v-model:value="gender" :options="genderOptions" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item
|
||||
label="نمایش در نام"
|
||||
extra="مرد «جناب آقای» و زن «سرکار خانم» ابتدای نام ذخیره میشود و به تهحساب هم همینطور میرود."
|
||||
>
|
||||
<a-checkbox v-model:checked="showGenderInName" :disabled="gender === 'none'">
|
||||
نمایش در نام
|
||||
</a-checkbox>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="موبایل">
|
||||
<a-space-compact block>
|
||||
@@ -559,6 +603,20 @@ onMounted(load);
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="گروهها">
|
||||
<a-select
|
||||
v-model:value="groupIds"
|
||||
mode="multiple"
|
||||
allow-clear
|
||||
option-filter-prop="label"
|
||||
placeholder="بدون گروه"
|
||||
:options="groupOptions"
|
||||
:not-found-content="groupsLoaded ? 'گروهی تعریف نشده' : undefined"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="برچسبها">
|
||||
<a-input
|
||||
|
||||
@@ -47,9 +47,11 @@ import type {
|
||||
QuoteDto,
|
||||
TicketDto,
|
||||
} from '@mento/shared';
|
||||
import { PERSON_GENDER_LABELS } from '@mento/shared';
|
||||
import { PERSON_MOOD_LABELS } from '@/lib/person-mood';
|
||||
import { canUseBehavior } from '@/lib/behavior-access';
|
||||
import DiscBadge from '@/components/behavior/DiscBadge.vue';
|
||||
import CustomerGroupChips from '@/components/CustomerGroupChips.vue';
|
||||
import DiscPanel from '@/components/behavior/DiscPanel.vue';
|
||||
import SalesCopilotPanel from '@/components/behavior/SalesCopilotPanel.vue';
|
||||
|
||||
@@ -83,7 +85,7 @@ const TABS = computed<Array<{ key: TabKey; label: string }>>(() => {
|
||||
{ key: 'tasks', label: 'کارهای مرتبط' },
|
||||
{ key: 'deals', label: 'معاملات' },
|
||||
{ key: 'cards', label: 'کارتها' },
|
||||
{ key: 'assets', label: 'دارایی' },
|
||||
{ key: 'assets', label: 'تهحساب و دارایی' },
|
||||
{ key: 'info', label: 'اطلاعات' },
|
||||
];
|
||||
if (canBehavior.value) {
|
||||
@@ -166,6 +168,11 @@ const registeredAt = computed(() =>
|
||||
const birthDateLabel = computed(() =>
|
||||
person.value?.birthDate ? formatJalaliNumeric(new Date(person.value.birthDate)) : '—',
|
||||
);
|
||||
const genderLabel = computed(() => {
|
||||
const key = person.value?.gender;
|
||||
if (key === 'male' || key === 'female' || key === 'none') return PERSON_GENDER_LABELS[key];
|
||||
return '—';
|
||||
});
|
||||
const externalCode = computed(() => {
|
||||
if (person.value?.sourceRef?.trim()) return person.value.sourceRef.trim();
|
||||
const fields = person.value?.customFields ?? {};
|
||||
@@ -759,6 +766,10 @@ watch(() => route.query.tab, readTab, { immediate: true });
|
||||
</div>
|
||||
|
||||
<dl class="facts-grid">
|
||||
<div class="fact">
|
||||
<dt>گروهها</dt>
|
||||
<dd><CustomerGroupChips :groups="person.groups" empty="—" /></dd>
|
||||
</div>
|
||||
<div class="fact">
|
||||
<dt>شرکت</dt>
|
||||
<dd>{{ person.company?.name || '—' }}</dd>
|
||||
@@ -767,6 +778,10 @@ watch(() => route.query.tab, readTab, { immediate: true });
|
||||
<dt>سمت</dt>
|
||||
<dd>{{ person.position || '—' }}</dd>
|
||||
</div>
|
||||
<div class="fact">
|
||||
<dt>جنسیت</dt>
|
||||
<dd>{{ genderLabel }}</dd>
|
||||
</div>
|
||||
<div class="fact">
|
||||
<dt>تاریخ تولد</dt>
|
||||
<dd>{{ birthDateLabel }}</dd>
|
||||
@@ -809,6 +824,7 @@ watch(() => route.query.tab, readTab, { immediate: true });
|
||||
</h2>
|
||||
<p v-if="subtitle" class="sub">{{ subtitle }}</p>
|
||||
<DiscBadge v-if="canBehavior && person.discReliable" :label="person.discLabel" />
|
||||
<CustomerGroupChips :groups="person.groups" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="contact-rows">
|
||||
@@ -1037,7 +1053,12 @@ watch(() => route.query.tab, readTab, { immediate: true });
|
||||
<div v-show="tab === 'assets'" class="panel assets-panel">
|
||||
<InternalPartyBalance :person-id="id" />
|
||||
<MontifyStoresCard :person-id="id" />
|
||||
<PersonAssetsPanel :person-id="id" @link-changed="onTahesabLinkChanged" />
|
||||
<PersonAssetsPanel
|
||||
:person-id="id"
|
||||
:person-name="fullName"
|
||||
:person-phone="phoneNumber"
|
||||
@link-changed="onTahesabLinkChanged"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="canBehavior && tab === 'disc'" class="panel">
|
||||
@@ -1091,6 +1112,7 @@ watch(() => route.query.tab, readTab, { immediate: true });
|
||||
<div><dt>تلفن</dt><dd>{{ person.phone ? toFaDigits(person.phone) : '—' }}</dd></div>
|
||||
<div><dt>ایمیل</dt><dd>{{ person.email || '—' }}</dd></div>
|
||||
<div><dt>سمت</dt><dd>{{ person.position || '—' }}</dd></div>
|
||||
<div><dt>جنسیت</dt><dd>{{ genderLabel }}</dd></div>
|
||||
<div><dt>منبع ورود</dt><dd>{{ importSourceLabel }}</dd></div>
|
||||
<div><dt>کد مبدأ</dt><dd dir="ltr">{{ externalCode ? toFaDigits(externalCode) : '—' }}</dd></div>
|
||||
<div><dt>نام قبلی</dt><dd>{{ person.previousFullName || '—' }}</dd></div>
|
||||
|
||||
@@ -3,6 +3,8 @@ import { computed, onMounted, ref } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import { canAssignToOthers } from '@/lib/assign-access';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import type { OrgUserDto, ProjectCardDto } from '@mento/shared';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
|
||||
@@ -21,6 +23,8 @@ const emit = defineEmits<{
|
||||
cancel: [];
|
||||
}>();
|
||||
|
||||
const auth = useAuthStore();
|
||||
const canAssignOthers = computed(() => canAssignToOthers(auth.user, 'projects'));
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const id = computed(() => {
|
||||
@@ -231,10 +235,11 @@ onMounted(async () => {
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="card-assignees">مسئولان کارت</label>
|
||||
<select id="card-assignees" v-model="selectedAssigneeIds" multiple class="multi">
|
||||
<select id="card-assignees" v-model="selectedAssigneeIds" multiple class="multi" :disabled="!canAssignOthers">
|
||||
<option v-for="u in users" :key="u.id" :value="u.id">{{ u.fullName }}</option>
|
||||
</select>
|
||||
<small class="hint">با نگه داشتن Ctrl میتوانید چند نفر را انتخاب کنید.</small>
|
||||
<small v-if="canAssignOthers" class="hint">با نگه داشتن Ctrl میتوانید چند نفر را انتخاب کنید.</small>
|
||||
<small v-else class="hint">بدون دسترسی «تخصیص کارت پروژه به دیگران» کارت فقط برای خودتان ثبت میشود.</small>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="card-notes">یادداشت</label>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -496,6 +496,128 @@ async function importBulk() {
|
||||
}
|
||||
}
|
||||
|
||||
/** همهٔ بازههای کد خوانده میشود و گروه تهحساب روی مشتریهای لینکشده نشانده میشود */
|
||||
async function syncGroups() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
if (!sync.connectionId) {
|
||||
error.value = 'ابتدا اتصال را انتخاب کنید.';
|
||||
return;
|
||||
}
|
||||
syncBusy.value = true;
|
||||
importOverlay.open = true;
|
||||
importOverlay.progress = null;
|
||||
const totals = { rows: 0, linked: 0, updated: 0 };
|
||||
try {
|
||||
let page = 1;
|
||||
let emptyStreak = 0;
|
||||
while (emptyStreak < LIST_ALL_EMPTY_STOP) {
|
||||
importOverlay.message = `در حال همگامسازی گروهها… ${toFaDigits(totals.rows)} مشتری بررسی شد · ${toFaDigits(totals.updated)} تغییر`;
|
||||
const { data } = await api.post<{ rows: number; linked: number; updated: number }>(
|
||||
'/integrations/tahesab/sync/groups',
|
||||
{ connectionId: sync.connectionId, page, pageSize: LIST_ALL_CODE_PAGE },
|
||||
{ timeout: 120_000 },
|
||||
);
|
||||
totals.rows += data.rows;
|
||||
totals.linked += data.linked;
|
||||
totals.updated += data.updated;
|
||||
emptyStreak = data.rows ? 0 : emptyStreak + 1;
|
||||
page += 1;
|
||||
}
|
||||
ok.value = `گروهها همگام شد: ${toFaDigits(totals.linked)} مشتری لینکشده بررسی شد · گروه ${toFaDigits(totals.updated)} نفر بهروز شد.`;
|
||||
} catch (e) {
|
||||
error.value = apiErr(e, 'همگامسازی گروهها ناموفق بود');
|
||||
} finally {
|
||||
importOverlay.open = false;
|
||||
syncBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
type ExportItem = {
|
||||
personId: string;
|
||||
name: string;
|
||||
status: 'matched' | 'created' | 'ambiguous' | 'skipped' | 'error';
|
||||
moshtariCode?: number;
|
||||
error?: string;
|
||||
};
|
||||
const EXPORT_CHUNK = 10;
|
||||
const exportIssues = ref<ExportItem[]>([]);
|
||||
|
||||
/** شخصهای لینکنشده: اول تطبیق، بعد ساخت در تهحساب (بدون ساخت تکراری) */
|
||||
async function exportUnlinked() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
exportIssues.value = [];
|
||||
if (!sync.connectionId) {
|
||||
error.value = 'ابتدا اتصال را انتخاب کنید.';
|
||||
return;
|
||||
}
|
||||
syncBusy.value = true;
|
||||
try {
|
||||
const { data: unlinked } = await api.get<{ ids: string[]; total: number }>(
|
||||
'/integrations/tahesab/sync/unlinked-people',
|
||||
{ params: { connectionId: sync.connectionId } },
|
||||
);
|
||||
if (!unlinked.total) {
|
||||
ok.value = 'همهٔ اشخاص به تهحساب لینک هستند.';
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!confirm(
|
||||
`${toFaDigits(unlinked.total)} شخص به تهحساب لینک نیستند.\n` +
|
||||
'برای هر نفر اول با موبایل/نام در تهحساب جستجو میشود: اگر دقیقاً یک نفر پیدا شد فقط لینک میشود، ' +
|
||||
'اگر چند نفر پیدا شد رد میشود تا دستی بررسی کنید، و اگر پیدا نشد در تهحساب ساخته میشود. ادامه؟',
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
importOverlay.open = true;
|
||||
importOverlay.progress = 0;
|
||||
const totals = { matched: 0, created: 0, ambiguous: 0, skipped: 0, failed: 0 };
|
||||
const ids = unlinked.ids;
|
||||
for (let i = 0; i < ids.length; i += EXPORT_CHUNK) {
|
||||
const chunk = ids.slice(i, i + EXPORT_CHUNK);
|
||||
importOverlay.message = `در حال ثبت در تهحساب… ${toFaDigits(Math.min(i + chunk.length, ids.length))} از ${toFaDigits(ids.length)}`;
|
||||
try {
|
||||
const { data } = await api.post<typeof totals & { items: ExportItem[] }>(
|
||||
'/integrations/tahesab/sync/export-people',
|
||||
{ connectionId: sync.connectionId, personIds: chunk },
|
||||
{ timeout: 180_000 },
|
||||
);
|
||||
totals.matched += data.matched;
|
||||
totals.created += data.created;
|
||||
totals.ambiguous += data.ambiguous;
|
||||
totals.skipped += data.skipped;
|
||||
totals.failed += data.failed;
|
||||
exportIssues.value.push(
|
||||
...data.items.filter((it) => it.status === 'ambiguous' || it.status === 'error'),
|
||||
);
|
||||
} catch (e) {
|
||||
totals.failed += chunk.length;
|
||||
exportIssues.value.push(
|
||||
...chunk.map((personId) => ({
|
||||
personId,
|
||||
name: '',
|
||||
status: 'error' as const,
|
||||
error: apiErr(e, 'خطا در ارسال'),
|
||||
})),
|
||||
);
|
||||
}
|
||||
importOverlay.progress = ((i + chunk.length) / ids.length) * 100;
|
||||
}
|
||||
ok.value =
|
||||
`ثبت در تهحساب تمام شد: لینک با مشتری موجود ${toFaDigits(totals.matched)} · ` +
|
||||
`ساختهشده ${toFaDigits(totals.created)} · چند نتیجه (نیاز به بررسی) ${toFaDigits(totals.ambiguous)} · ` +
|
||||
`ناموفق ${toFaDigits(totals.failed)}`;
|
||||
} catch (e) {
|
||||
error.value = apiErr(e, 'ثبت گروهی در تهحساب ناموفق بود');
|
||||
} finally {
|
||||
importOverlay.open = false;
|
||||
importOverlay.progress = null;
|
||||
syncBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function searchProducts() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
@@ -807,6 +929,43 @@ onMounted(load);
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sync-sub-section">
|
||||
<h4 class="sync-subhead">۳) گروهها و ثبت مشتریهای منتکت در تهحساب</h4>
|
||||
<p class="sync-sub-desc">
|
||||
«همگامسازی گروهها» گروه هر مشتری لینکشده را از تهحساب میخواند؛ فقط گروهِ آمده از تهحساب عوض
|
||||
میشود و گروههایی که دستی دادهاید میمانند.
|
||||
«ثبت لینکنشدهها» برای هر شخصی که به تهحساب لینک نیست اول تطبیق (موبایل، بعد نام) را امتحان
|
||||
میکند تا مشتری تکراری ساخته نشود؛ اگر پیدا نشد با گروه، آدرس، کد ملی و تاریخ تولد ساخته میشود.
|
||||
</p>
|
||||
<div class="sync-buttons">
|
||||
<UiButton
|
||||
variant="secondary"
|
||||
:disabled="!sync.connectionId || syncBusy"
|
||||
@click="syncGroups"
|
||||
>
|
||||
همگامسازی گروهها از تهحساب
|
||||
</UiButton>
|
||||
<UiButton :disabled="!sync.connectionId || syncBusy" @click="exportUnlinked">
|
||||
ثبت مشتریهای لینکنشده در تهحساب
|
||||
</UiButton>
|
||||
</div>
|
||||
<div v-if="exportIssues.length" class="export-issues">
|
||||
<p class="sync-sub-desc">
|
||||
این اشخاص ثبت نشدند ({{ toFaDigits(exportIssues.length) }}). از پرونده، بخش «تهحساب و دارایی»
|
||||
دستی لینک یا ثبت کنید:
|
||||
</p>
|
||||
<ul>
|
||||
<li v-for="it in exportIssues" :key="it.personId">
|
||||
<RouterLink :to="{ name: 'person-detail', params: { id: it.personId } }">
|
||||
{{ it.name || 'بدون نام' }}
|
||||
</RouterLink>
|
||||
—
|
||||
{{ it.status === 'ambiguous' ? 'چند مشتری مشابه در تهحساب پیدا شد' : it.error || 'خطا' }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="syncResults.length" class="sync-results-box">
|
||||
<h4 class="sync-results-title">
|
||||
نتایج جستجو ({{ syncVisibleResults.length }}<template v-if="syncOnlyNew"> از {{ syncResults.length }}</template>)
|
||||
@@ -1176,6 +1335,14 @@ onMounted(load);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.export-issues ul {
|
||||
margin: var(--sp-2) 0 0;
|
||||
padding-inline-start: 1.2rem;
|
||||
font-size: var(--fs-xs);
|
||||
max-height: 14rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.sync-table-pagination {
|
||||
margin-top: var(--sp-3);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useEscClose } from '@/lib/modal-stack';
|
||||
import { matchesSearch } from '@/lib/search';
|
||||
import TableColumnsMenu from '@/components/TableColumnsMenu.vue';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
@@ -10,7 +11,9 @@ import { useAuthStore } from '@/stores/auth';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import { UiDropdownMenu, UiModal } from '@/components/ui';
|
||||
import {
|
||||
DATA_ACCESS_SECTIONS,
|
||||
ROLE_PERMISSION_ITEMS,
|
||||
type DataAccessPolicy,
|
||||
type InviteUserRequest,
|
||||
type OrganizationDto,
|
||||
type OrgModuleKey,
|
||||
@@ -29,6 +32,7 @@ import {
|
||||
toFaDigits,
|
||||
} from '@/lib/jalali';
|
||||
import TeamsSettingsPanel from '@/components/TeamsSettingsPanel.vue';
|
||||
import DataAccessPolicyPanel from '@/components/DataAccessPolicyPanel.vue';
|
||||
|
||||
type TabKey = 'users' | 'roles' | 'access' | 'teams';
|
||||
type RoleColor = 'teal' | 'violet' | 'rose' | 'sky' | 'amber' | 'slate' | 'pink';
|
||||
@@ -52,10 +56,18 @@ const router = useRouter();
|
||||
/** مجوزی که ماژولش در سوپرادمین خاموش است در نقشها نشان داده نمیشود. */
|
||||
const PERMISSION_MODULES: Partial<Record<RolePermissionKey, OrgModuleKey[]>> = {
|
||||
customers: ['customers'],
|
||||
assign_customers: ['customers'],
|
||||
leads: ['leads'],
|
||||
assign_leads: ['leads'],
|
||||
sales: ['pipeline'],
|
||||
assign_sales: ['pipeline'],
|
||||
billing: ['invoices', 'quotes'],
|
||||
products: ['products'],
|
||||
activities: ['activities'],
|
||||
assign_activities: ['activities'],
|
||||
assign_routines: ['routines'],
|
||||
assign_projects: ['project_boards'],
|
||||
assign_tickets: ['tickets'],
|
||||
notes: ['notes'],
|
||||
reports: ['reports'],
|
||||
audit: ['audit_logs'],
|
||||
@@ -87,6 +99,8 @@ const orgName = ref('');
|
||||
const businessField = ref('');
|
||||
const orgSaving = ref(false);
|
||||
const accessSaving = ref(false);
|
||||
const roleFormDataAccess = ref<DataAccessPolicy>({});
|
||||
const focusDataAccess = ref<DataAccessPolicy>({});
|
||||
|
||||
const tab = ref<TabKey>('users');
|
||||
const query = ref('');
|
||||
@@ -503,20 +517,74 @@ async function toggleStatus(user: OrgUserDto) {
|
||||
}
|
||||
}
|
||||
|
||||
const LOGIN_OTP_ONLY_TIP =
|
||||
'ورود فقط با کد پیامکی؛ رمز عبور کار نمیکند — حتی اگر از قبل رمز داشته باشد.';
|
||||
|
||||
async function toggleLoginOtpOnly(user: OrgUserDto) {
|
||||
menuUserId.value = null;
|
||||
if (user.role === 'owner') return;
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
const next = !user.loginOtpOnly;
|
||||
await api.patch(`/users/${user.id}/login-otp-only`, { loginOtpOnly: next });
|
||||
ok.value = next
|
||||
? `«${user.fullName}» فقط با کد پیامکی وارد میشود.`
|
||||
: `ورود با رمز برای «${user.fullName}» دوباره فعال شد.`;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'تغییر شیوهٔ ورود ناموفق بود');
|
||||
}
|
||||
}
|
||||
|
||||
const logoutModal = ref<{ user: OrgUserDto; time: string } | null>(null);
|
||||
const logoutSaving = ref(false);
|
||||
|
||||
function openLogoutModal(user: OrgUserDto) {
|
||||
if (!canSetLogoutTime.value || user.role === 'owner') return;
|
||||
logoutModal.value = { user, time: user.logoutTime || '18:00' };
|
||||
}
|
||||
|
||||
async function changeLogoutTime(user: OrgUserDto, raw: string) {
|
||||
if (!canSetLogoutTime.value || user.role === 'owner') return;
|
||||
const next = raw.trim();
|
||||
if (next === (user.logoutTime ?? '')) return;
|
||||
if (next === (user.logoutTime ?? '')) {
|
||||
logoutModal.value = null;
|
||||
return;
|
||||
}
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
logoutSaving.value = true;
|
||||
try {
|
||||
await api.patch(`/users/${user.id}/logout-time`, { logoutTime: next || null });
|
||||
ok.value = next
|
||||
? `ساعت خروج «${user.fullName}» روی ${toFaDigits(next)} تنظیم شد.`
|
||||
: `محدودیت خروج «${user.fullName}» برداشته شد.`;
|
||||
logoutModal.value = null;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'ذخیره ساعت خروج ناموفق بود');
|
||||
} finally {
|
||||
logoutSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleBlockAfterLogout(user: OrgUserDto) {
|
||||
if (!canSetLogoutTime.value || user.role === 'owner' || !user.logoutTime) return;
|
||||
const next = !user.blockLoginAfterLogout;
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
await api.patch(`/users/${user.id}/logout-time`, {
|
||||
logoutTime: user.logoutTime,
|
||||
blockLoginAfterLogout: next,
|
||||
});
|
||||
ok.value = next
|
||||
? `«${user.fullName}» بعد از ساعت ${toFaDigits(user.logoutTime)} دیگر نمیتواند وارد شود.`
|
||||
: `«${user.fullName}» بعد از ساعت خروج هم میتواند وارد شود.`;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'تغییر محدودیت ورود ناموفق بود');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,6 +615,7 @@ function openCreateRole(parentId?: string | null) {
|
||||
roleFormPerms.value = parent
|
||||
? [...parent.permissions]
|
||||
: visibleRolePermissions.value.map((p) => p.key);
|
||||
roleFormDataAccess.value = clonePolicy(parent?.dataAccessPolicy);
|
||||
roleFormOpen.value = true;
|
||||
}
|
||||
|
||||
@@ -566,6 +635,7 @@ function openEditRole() {
|
||||
: 'teal') as RoleColor;
|
||||
roleFormParentId.value = role.systemKey ? '' : (role.parentId ?? '');
|
||||
roleFormPerms.value = [...role.permissions];
|
||||
roleFormDataAccess.value = clonePolicy(role.dataAccessPolicy);
|
||||
roleFormOpen.value = true;
|
||||
}
|
||||
|
||||
@@ -595,12 +665,14 @@ async function submitRoleForm() {
|
||||
description: string;
|
||||
color: RoleColor;
|
||||
permissions: RolePermissionKey[];
|
||||
dataAccessPolicy?: OrgRoleDto['dataAccessPolicy'];
|
||||
parentId?: string | null;
|
||||
} = {
|
||||
name: roleFormName.value.trim(),
|
||||
description: roleFormDesc.value.trim(),
|
||||
color: roleFormColor.value,
|
||||
permissions: roleFormPerms.value,
|
||||
dataAccessPolicy: roleFormDataAccess.value,
|
||||
};
|
||||
if (!editing?.systemKey) {
|
||||
body.parentId = roleFormParentId.value || null;
|
||||
@@ -657,6 +729,50 @@ async function toggleAccess(role: OrgRoleDto, key: RolePermissionKey) {
|
||||
}
|
||||
}
|
||||
|
||||
function clonePolicy(policy?: DataAccessPolicy | null): DataAccessPolicy {
|
||||
const src = policy ?? {};
|
||||
const out: DataAccessPolicy = {};
|
||||
for (const [key, section] of Object.entries(src)) {
|
||||
if (!section) continue;
|
||||
out[key as keyof DataAccessPolicy] = {
|
||||
mode: section.mode,
|
||||
rules: (section.rules ?? []).map((r) => ({ ...r })),
|
||||
};
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function withOpenSections(policy: DataAccessPolicy): DataAccessPolicy {
|
||||
const out = clonePolicy(policy);
|
||||
for (const key of DATA_ACCESS_SECTIONS) {
|
||||
if (!out[key]) out[key] = { mode: 'all', rules: [] };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function syncFocusDataAccess() {
|
||||
focusDataAccess.value = clonePolicy(accessFocusRole.value?.dataAccessPolicy);
|
||||
}
|
||||
|
||||
async function saveFocusDataAccess() {
|
||||
const role = accessFocusRole.value;
|
||||
if (!role || !canEditRoles.value) return;
|
||||
accessSaving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const dataAccessPolicy = withOpenSections(focusDataAccess.value);
|
||||
focusDataAccess.value = dataAccessPolicy;
|
||||
await api.patch(`/org-roles/${role.id}`, { dataAccessPolicy });
|
||||
ok.value = `محدوده داده برای نقش «${role.name}» ذخیره شد.`;
|
||||
await load();
|
||||
syncFocusDataAccess();
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'ذخیره محدوده داده ناموفق بود');
|
||||
} finally {
|
||||
accessSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onDocClick() {
|
||||
menuUserId.value = null;
|
||||
}
|
||||
@@ -692,10 +808,15 @@ watch(
|
||||
if (!list.some((r) => r.id === accessFocusId.value)) {
|
||||
accessFocusId.value = list[0].id;
|
||||
}
|
||||
syncFocusDataAccess();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
watch(accessFocusId, () => {
|
||||
syncFocusDataAccess();
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
syncViewport();
|
||||
window.addEventListener('resize', syncViewport);
|
||||
@@ -826,6 +947,29 @@ onUnmounted(() => {
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div v-if="accessFocusRole" class="data-access-block">
|
||||
<div class="matrix-head">
|
||||
<h3>محدوده داده — {{ accessFocusRole.name }}</h3>
|
||||
<button
|
||||
v-if="canEditRoles"
|
||||
type="button"
|
||||
class="btn primary"
|
||||
:disabled="accessSaving"
|
||||
@click="saveFocusDataAccess"
|
||||
>
|
||||
{{ accessSaving ? 'در حال ذخیره…' : 'ذخیره محدوده' }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="hint">
|
||||
برای هر بخش میتوانید همه را باز بگذارید یا با فیلتر (مالک، گروه، مرحله و…) محدود کنید.
|
||||
</p>
|
||||
<DataAccessPolicyPanel
|
||||
v-model="focusDataAccess"
|
||||
:enabled-permissions="accessFocusRole.permissions"
|
||||
:disabled="!canEditRoles"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -1046,19 +1190,45 @@ onUnmounted(() => {
|
||||
<i />
|
||||
{{ user.isActive === false ? 'غیرفعال' : 'فعال' }}
|
||||
</span>
|
||||
<span
|
||||
v-if="user.loginOtpOnly"
|
||||
class="otp-badge"
|
||||
:title="LOGIN_OTP_ONLY_TIP"
|
||||
>
|
||||
ورود با کد
|
||||
</span>
|
||||
</td>
|
||||
<td class="muted">{{ formatLastLogin(user.lastLoginAt) }}</td>
|
||||
<td v-if="canSetLogoutTime" @click.stop>
|
||||
<span v-if="user.role === 'owner'" class="muted">—</span>
|
||||
<input
|
||||
v-else
|
||||
class="logout-time"
|
||||
type="time"
|
||||
dir="ltr"
|
||||
:value="user.logoutTime || ''"
|
||||
:aria-label="`ساعت خروج ${user.fullName}`"
|
||||
@change="changeLogoutTime(user, ($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
<span v-else class="logout-cell">
|
||||
<button
|
||||
type="button"
|
||||
class="logout-btn"
|
||||
:class="{ set: Boolean(user.logoutTime) }"
|
||||
:aria-label="user.logoutTime ? `ویرایش ساعت خروج ${user.fullName}` : `تعیین ساعت خروج ${user.fullName}`"
|
||||
:title="user.logoutTime ? 'ویرایش ساعت خروج' : 'تعیین ساعت خروج'"
|
||||
@click="openLogoutModal(user)"
|
||||
>
|
||||
<span v-if="user.logoutTime" dir="ltr">{{ toFaDigits(user.logoutTime) }}</span>
|
||||
<UiIcon v-else name="clock" :size="16" />
|
||||
</button>
|
||||
<button
|
||||
v-if="user.logoutTime"
|
||||
type="button"
|
||||
class="block-btn"
|
||||
:class="{ on: user.blockLoginAfterLogout }"
|
||||
:aria-pressed="Boolean(user.blockLoginAfterLogout)"
|
||||
:title="
|
||||
user.blockLoginAfterLogout
|
||||
? 'ورود بعد از ساعت خروج مسدود است — برای آزاد کردن بزنید'
|
||||
: 'ورود بعد از ساعت خروج آزاد است — برای مسدود کردن بزنید'
|
||||
"
|
||||
@click="toggleBlockAfterLogout(user)"
|
||||
>
|
||||
<UiIcon :name="user.blockLoginAfterLogout ? 'check' : 'x'" :size="14" />
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
<td class="ops" @click.stop>
|
||||
<UiDropdownMenu
|
||||
@@ -1078,6 +1248,15 @@ onUnmounted(() => {
|
||||
>
|
||||
ویرایش مشخصات
|
||||
</button>
|
||||
<button
|
||||
v-if="canInvite && user.role !== 'owner'"
|
||||
type="button"
|
||||
:class="{ on: user.loginOtpOnly }"
|
||||
:title="LOGIN_OTP_ONLY_TIP"
|
||||
@click="toggleLoginOtpOnly(user)"
|
||||
>
|
||||
{{ user.loginOtpOnly ? 'لغو ورود با کد' : 'ورود با کد' }}
|
||||
</button>
|
||||
<button type="button" @click="toggleStatus(user)">
|
||||
{{ user.isActive === false ? 'فعال کردن' : 'غیرفعال کردن' }}
|
||||
</button>
|
||||
@@ -1130,6 +1309,16 @@ onUnmounted(() => {
|
||||
>
|
||||
ویرایش
|
||||
</button>
|
||||
<button
|
||||
v-if="canInvite && user.role !== 'owner'"
|
||||
type="button"
|
||||
class="btn ghost"
|
||||
:class="{ 'otp-on': user.loginOtpOnly }"
|
||||
:title="LOGIN_OTP_ONLY_TIP"
|
||||
@click="toggleLoginOtpOnly(user)"
|
||||
>
|
||||
{{ user.loginOtpOnly ? 'لغو ورود با کد' : 'ورود با کد' }}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
<p v-if="!loading && !pagedUsers.length" class="empty">کاربری یافت نشد.</p>
|
||||
@@ -1204,6 +1393,43 @@ onUnmounted(() => {
|
||||
</template>
|
||||
</UiModal>
|
||||
|
||||
<UiModal
|
||||
:open="Boolean(logoutModal)"
|
||||
:title="logoutModal ? `ساعت خروج ${logoutModal.user.fullName}` : 'ساعت خروج'"
|
||||
@close="logoutModal = null"
|
||||
>
|
||||
<form v-if="logoutModal" class="form" @submit.prevent="changeLogoutTime(logoutModal.user, logoutModal.time)">
|
||||
<label>
|
||||
ساعت خروج روزانه
|
||||
<JalaliDateInput v-model="logoutModal.time" mode="time" :clearable="false" />
|
||||
</label>
|
||||
<p class="hint">
|
||||
در این ساعت (به وقت تهران) کاربر خودکار از سامانه خارج میشود. با تیک کنار ساعت میتوانید
|
||||
ورود دوباره تا پایان همان روز را هم ببندید.
|
||||
</p>
|
||||
</form>
|
||||
<template #footer>
|
||||
<button
|
||||
v-if="logoutModal?.user.logoutTime"
|
||||
type="button"
|
||||
class="btn ghost"
|
||||
:disabled="logoutSaving"
|
||||
@click="logoutModal && changeLogoutTime(logoutModal.user, '')"
|
||||
>
|
||||
حذف ساعت خروج
|
||||
</button>
|
||||
<button type="button" class="btn ghost" @click="logoutModal = null">انصراف</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn primary"
|
||||
:disabled="logoutSaving || !logoutModal?.time"
|
||||
@click="logoutModal && changeLogoutTime(logoutModal.user, logoutModal.time)"
|
||||
>
|
||||
{{ logoutSaving ? 'در حال ذخیره…' : 'ذخیره' }}
|
||||
</button>
|
||||
</template>
|
||||
</UiModal>
|
||||
|
||||
<UiModal :open="editOpen" title="ویرایش مشخصات کاربر" @close="editOpen = false">
|
||||
<form class="form" @submit.prevent="submitEditUser">
|
||||
<label>نام و نام خانوادگی<input v-model="editName" required minlength="2" /></label>
|
||||
@@ -1270,6 +1496,14 @@ onUnmounted(() => {
|
||||
{{ perm.label }}
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset class="perm-set">
|
||||
<legend>محدوده داده</legend>
|
||||
<DataAccessPolicyPanel
|
||||
v-model="roleFormDataAccess"
|
||||
:enabled-permissions="roleFormPerms"
|
||||
compact
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
||||
<template #footer>
|
||||
<button type="button" class="btn ghost" @click="roleFormOpen = false">انصراف</button>
|
||||
@@ -1298,6 +1532,20 @@ onUnmounted(() => {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.data-access-block {
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid #eef2f7;
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.data-access-block .hint {
|
||||
color: #64748b;
|
||||
font-size: 0.85rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.page-head {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
@@ -1621,6 +1869,25 @@ tbody tr + tr td {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.otp-badge {
|
||||
display: inline-block;
|
||||
margin-inline-start: 0.4rem;
|
||||
padding: 0.12rem 0.45rem;
|
||||
border-radius: 999px;
|
||||
background: #ecfdf5;
|
||||
color: #0f766e;
|
||||
font-size: 0.72rem;
|
||||
font-weight: 700;
|
||||
vertical-align: middle;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.btn.otp-on {
|
||||
color: #0f766e;
|
||||
border-color: #99f6e4;
|
||||
background: #ecfdf5;
|
||||
}
|
||||
|
||||
.ghost-ico {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
@@ -1874,22 +2141,53 @@ tbody tr + tr td {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.logout-time {
|
||||
width: 7.2rem;
|
||||
min-height: 2rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 10px;
|
||||
padding: 0 0.45rem;
|
||||
font: inherit;
|
||||
background: #fff;
|
||||
box-sizing: border-box;
|
||||
.logout-cell {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
|
||||
.logout-time:disabled {
|
||||
background: #f8fafc;
|
||||
.logout-btn,
|
||||
.block-btn {
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
height: 1.9rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
color: #64748b;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
min-width: 1.9rem;
|
||||
padding: 0 0.4rem;
|
||||
}
|
||||
|
||||
.logout-btn.set {
|
||||
color: #0f172a;
|
||||
font-weight: 700;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.logout-btn:hover,
|
||||
.block-btn:hover {
|
||||
border-color: #0d9488;
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.block-btn {
|
||||
width: 1.9rem;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.block-btn.on {
|
||||
border-color: #99f6e4;
|
||||
background: #f0fdfa;
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.roles-grid,
|
||||
.roles-tree {
|
||||
display: grid;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatJalaliDateTime } from '@/lib/jalali';
|
||||
import { canViewAllRecords } from '@/lib/roles';
|
||||
import { canAssignToOthers } from '@/lib/assign-access';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import {
|
||||
UiBadge,
|
||||
@@ -61,7 +61,7 @@ const faqHints = ref<FaqArticleDto[]>([]);
|
||||
const csatScore = ref<number | null>(null);
|
||||
const csatComment = ref('');
|
||||
|
||||
const canAssignOthers = computed(() => canViewAllRecords(auth.user?.role));
|
||||
const canAssignOthers = computed(() => canAssignToOthers(auth.user, 'tickets'));
|
||||
|
||||
const showCsat = computed(() => {
|
||||
if (!ticket.value || isNew.value) return false;
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import type { CreatePlatformAdminRequest, PlatformAdminDto } from '@mento/shared';
|
||||
import type {
|
||||
CreatePlatformAdminRequest,
|
||||
PlatformAdminDto,
|
||||
PlatformMasterPasswordStatusDto,
|
||||
UpdatePlatformAdminRequest,
|
||||
} from '@mento/shared';
|
||||
import { platformApi } from '@/lib/platform-api';
|
||||
import { formatJalaliNumeric } from '@/lib/jalali';
|
||||
import { usePlatformAuthStore } from '@/stores/platform-auth';
|
||||
@@ -17,6 +22,13 @@ const creating = ref(false);
|
||||
const resetId = ref<string | null>(null);
|
||||
const resetPassword = ref('');
|
||||
const resetting = ref(false);
|
||||
const editId = ref<string | null>(null);
|
||||
const editing = ref(false);
|
||||
const deleteId = ref<string | null>(null);
|
||||
const editForm = reactive({ fullName: '', mobile: '', email: '' });
|
||||
const masterEnabled = ref(false);
|
||||
const masterPassword = ref('');
|
||||
const masterBusy = ref(false);
|
||||
|
||||
const createForm = reactive<CreatePlatformAdminRequest>({
|
||||
fullName: '',
|
||||
@@ -39,6 +51,12 @@ async function load() {
|
||||
try {
|
||||
const { data } = await platformApi.get<PlatformAdminDto[]>('/platform/admins');
|
||||
items.value = data;
|
||||
try {
|
||||
const master = await platformApi.get<PlatformMasterPasswordStatusDto>('/platform/master-password');
|
||||
masterEnabled.value = master.data.enabled;
|
||||
} catch {
|
||||
masterEnabled.value = false;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'بارگذاری ادمینها ناموفق بود');
|
||||
} finally {
|
||||
@@ -46,6 +64,81 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveMasterPassword(clear = false) {
|
||||
masterBusy.value = true;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
const { data } = await platformApi.put<PlatformMasterPasswordStatusDto>(
|
||||
'/platform/master-password',
|
||||
{ password: clear ? null : masterPassword.value },
|
||||
);
|
||||
masterEnabled.value = data.enabled;
|
||||
masterPassword.value = '';
|
||||
success.value = clear ? 'رمز کلی برداشته شد' : 'رمز کلی ذخیره شد';
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'ذخیره رمز کلی ناموفق بود');
|
||||
} finally {
|
||||
masterBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function startEdit(admin: PlatformAdminDto) {
|
||||
editId.value = editId.value === admin.id ? null : admin.id;
|
||||
deleteId.value = null;
|
||||
resetId.value = null;
|
||||
editForm.fullName = admin.fullName;
|
||||
editForm.mobile = admin.mobile || '';
|
||||
editForm.email = admin.email || '';
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
}
|
||||
|
||||
async function submitEdit(id: string) {
|
||||
editing.value = true;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
const body: UpdatePlatformAdminRequest = {
|
||||
fullName: editForm.fullName.trim(),
|
||||
mobile: editForm.mobile.trim(),
|
||||
email: editForm.email.trim() || null,
|
||||
};
|
||||
const { data } = await platformApi.patch<PlatformAdminDto>(`/platform/admins/${id}/profile`, body);
|
||||
items.value = items.value.map((row) => (row.id === id ? data : row));
|
||||
editId.value = null;
|
||||
success.value = 'مشخصات ادمین بهروز شد';
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'ویرایش ادمین ناموفق بود');
|
||||
} finally {
|
||||
editing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function askDelete(id: string) {
|
||||
deleteId.value = deleteId.value === id ? null : id;
|
||||
editId.value = null;
|
||||
resetId.value = null;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
}
|
||||
|
||||
async function submitDelete(id: string) {
|
||||
busyId.value = id;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
await platformApi.delete(`/platform/admins/${id}`);
|
||||
items.value = items.value.filter((row) => row.id !== id);
|
||||
deleteId.value = null;
|
||||
success.value = 'ادمین حذف شد';
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'حذف ادمین ناموفق بود');
|
||||
} finally {
|
||||
busyId.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
function resetCreateForm() {
|
||||
createForm.fullName = '';
|
||||
createForm.mobile = '';
|
||||
@@ -125,12 +218,38 @@ onMounted(() => {
|
||||
<template>
|
||||
<div class="page">
|
||||
<header class="head">
|
||||
<p class="lead">افزودن سوپرادمین با موبایل، فعال/غیرفعال و ریست رمز.</p>
|
||||
<p class="lead">افزودن، ویرایش و حذف سوپرادمین. رمز کلی با موبایل هر کاربر وارد حساب CRM او میشود.</p>
|
||||
<button class="btn" type="button" @click="showCreate = !showCreate">
|
||||
{{ showCreate ? 'بستن فرم' : 'ادمین جدید' }}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<form class="panel" @submit.prevent="saveMasterPassword(false)">
|
||||
<h2>رمز کلی ورود به حساب کاربران</h2>
|
||||
<p class="muted">
|
||||
{{ masterEnabled ? 'رمز کلی فعال است.' : 'رمز کلی تنظیم نشده.' }}
|
||||
با موبایل خود کاربر و این رمز، وارد حساب او در CRM میشوید. ورود با کد و محدودیت ساعت خروج مانع این رمز نیست.
|
||||
</p>
|
||||
<label>
|
||||
<span>رمز جدید (حداقل ۸ کاراکتر)</span>
|
||||
<input v-model="masterPassword" type="password" minlength="8" autocomplete="new-password" />
|
||||
</label>
|
||||
<div class="panel-actions">
|
||||
<button class="btn" type="submit" :disabled="masterBusy || masterPassword.trim().length < 8">
|
||||
{{ masterBusy ? 'در حال ذخیره…' : 'ذخیره رمز کلی' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="masterEnabled"
|
||||
class="btn btn-ghost"
|
||||
type="button"
|
||||
:disabled="masterBusy"
|
||||
@click="saveMasterPassword(true)"
|
||||
>
|
||||
برداشتن رمز
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-else-if="success" class="ok">{{ success }}</p>
|
||||
|
||||
@@ -188,6 +307,9 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-ghost" type="button" @click="startEdit(admin)">
|
||||
ویرایش
|
||||
</button>
|
||||
<button class="btn btn-ghost" type="button" @click="startReset(admin.id)">
|
||||
ریست رمز
|
||||
</button>
|
||||
@@ -199,6 +321,49 @@ onMounted(() => {
|
||||
>
|
||||
{{ admin.isActive ? 'غیرفعال' : 'فعال' }}
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-ghost"
|
||||
type="button"
|
||||
:disabled="admin.id === platform.admin?.id"
|
||||
@click="askDelete(admin.id)"
|
||||
>
|
||||
حذف
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form
|
||||
v-if="editId === admin.id"
|
||||
class="reset-panel"
|
||||
@submit.prevent="submitEdit(admin.id)"
|
||||
>
|
||||
<div class="grid">
|
||||
<label>
|
||||
<span>نام</span>
|
||||
<input v-model="editForm.fullName" required minlength="2" />
|
||||
</label>
|
||||
<label>
|
||||
<span>موبایل</span>
|
||||
<input v-model="editForm.mobile" type="tel" required dir="ltr" />
|
||||
</label>
|
||||
<label>
|
||||
<span>ایمیل (اختیاری)</span>
|
||||
<input v-model="editForm.email" type="email" dir="ltr" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="panel-actions">
|
||||
<button class="btn" type="submit" :disabled="editing">ذخیره</button>
|
||||
<button class="btn btn-ghost" type="button" @click="startEdit(admin)">انصراف</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div v-if="deleteId === admin.id" class="reset-panel">
|
||||
<p class="muted">ادمین «{{ admin.fullName }}» حذف شود؟</p>
|
||||
<div class="panel-actions">
|
||||
<button class="btn" type="button" :disabled="busyId === admin.id" @click="submitDelete(admin.id)">
|
||||
حذف
|
||||
</button>
|
||||
<button class="btn btn-ghost" type="button" @click="askDelete(admin.id)">انصراف</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form
|
||||
@@ -353,6 +518,7 @@ input {
|
||||
display: flex;
|
||||
gap: 0.45rem;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.on,
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import type { BillingAccountDto, BillingPlanCode } from '@mento/shared';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import type { BillingAccountDto, BillingPlanCode, OwnerSeatUsageDto, StorageUsageDto } from '@mento/shared';
|
||||
import {
|
||||
BILLING_PLAN_CODES,
|
||||
BILLING_PLAN_LABELS,
|
||||
BILLING_USER_CAPS,
|
||||
isPermanentBillingPlan,
|
||||
} from '@mento/shared';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import { platformApi } from '@/lib/platform-api';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
billing?: BillingAccountDto | null;
|
||||
busyId: string;
|
||||
userId: string;
|
||||
@@ -16,6 +20,140 @@ defineProps<{
|
||||
const emit = defineEmits<{
|
||||
apply: [planCode: BillingPlanCode];
|
||||
}>();
|
||||
|
||||
const usage = ref<StorageUsageDto | null>(null);
|
||||
const seats = ref<OwnerSeatUsageDto | null>(null);
|
||||
const customUsers = ref('');
|
||||
const seatBusy = ref(false);
|
||||
const seatError = ref('');
|
||||
const quotaGb = ref('');
|
||||
const storageBusy = ref(false);
|
||||
const storageError = ref('');
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
const n = Math.max(0, bytes);
|
||||
const units: Array<[number, string]> = [
|
||||
[1024 ** 3, 'گیگابایت'],
|
||||
[1024 ** 2, 'مگابایت'],
|
||||
[1024, 'کیلوبایت'],
|
||||
];
|
||||
for (const [size, label] of units) {
|
||||
if (n >= size) {
|
||||
const value = n / size;
|
||||
const text = value >= 10 ? value.toFixed(0) : value.toFixed(1);
|
||||
return `${toFaDigits(text)} ${label}`;
|
||||
}
|
||||
}
|
||||
return `${toFaDigits(Math.round(n))} بایت`;
|
||||
}
|
||||
|
||||
function fillQuota(next: StorageUsageDto) {
|
||||
usage.value = next;
|
||||
quotaGb.value =
|
||||
next.quotaBytes == null ? '' : String(Math.round((next.quotaBytes / 1024 ** 3) * 10) / 10);
|
||||
}
|
||||
|
||||
function errorText(err: unknown, fallback: string) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const raw = (err.response?.data as { message?: string | string[] } | undefined)?.message;
|
||||
if (Array.isArray(raw)) return raw.join(' ');
|
||||
if (raw) return raw;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function loadStorage(refresh = false) {
|
||||
storageError.value = '';
|
||||
try {
|
||||
const { data } = await platformApi.get<StorageUsageDto>(
|
||||
`/platform/users/${props.userId}/storage`,
|
||||
{ params: refresh ? { refresh: '1' } : undefined },
|
||||
);
|
||||
fillQuota(data);
|
||||
} catch (err) {
|
||||
storageError.value = errorText(err, 'حجم فایل خوانده نشد');
|
||||
}
|
||||
}
|
||||
|
||||
async function saveQuota(quota: number | null) {
|
||||
storageBusy.value = true;
|
||||
storageError.value = '';
|
||||
try {
|
||||
const { data } = await platformApi.patch<StorageUsageDto>(
|
||||
`/platform/users/${props.userId}/billing/storage`,
|
||||
{ quotaGb: quota },
|
||||
);
|
||||
fillQuota(data);
|
||||
} catch (err) {
|
||||
storageError.value = errorText(err, 'سقف حجم ذخیره نشد');
|
||||
} finally {
|
||||
storageBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function saveTypedQuota() {
|
||||
const raw = quotaGb.value.trim().replace(/,/g, '');
|
||||
if (!raw) {
|
||||
storageError.value = 'سقف را به گیگابایت وارد کنید، یا «بدون سقف» را بزنید';
|
||||
return;
|
||||
}
|
||||
const value = Number(raw);
|
||||
if (!Number.isFinite(value) || value < 0) {
|
||||
storageError.value = 'سقف حجم نامعتبر است';
|
||||
return;
|
||||
}
|
||||
void saveQuota(value);
|
||||
}
|
||||
|
||||
async function loadSeats() {
|
||||
seatError.value = '';
|
||||
try {
|
||||
const { data } = await platformApi.get<OwnerSeatUsageDto>(`/platform/users/${props.userId}/seats`);
|
||||
seats.value = data;
|
||||
customUsers.value =
|
||||
data.maxUsers != null && !(BILLING_USER_CAPS as readonly number[]).includes(data.maxUsers)
|
||||
? String(data.maxUsers)
|
||||
: '';
|
||||
} catch (err) {
|
||||
seatError.value = errorText(err, 'تعداد کاربر خوانده نشد');
|
||||
}
|
||||
}
|
||||
|
||||
async function saveUserCap(maxUsers: number) {
|
||||
seatBusy.value = true;
|
||||
seatError.value = '';
|
||||
try {
|
||||
const { data } = await platformApi.patch<OwnerSeatUsageDto>(
|
||||
`/platform/users/${props.userId}/billing/users`,
|
||||
{ maxUsers },
|
||||
);
|
||||
seats.value = data;
|
||||
customUsers.value =
|
||||
data.maxUsers != null && !(BILLING_USER_CAPS as readonly number[]).includes(data.maxUsers)
|
||||
? String(data.maxUsers)
|
||||
: '';
|
||||
} catch (err) {
|
||||
seatError.value = errorText(err, 'سقف کاربر ذخیره نشد');
|
||||
} finally {
|
||||
seatBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function saveCustomUsers() {
|
||||
const value = Number(customUsers.value.trim());
|
||||
if (!Number.isInteger(value) || value < 21) {
|
||||
seatError.value = 'برای بالای ۲۰ کاربر، عدد توافقی را از ۲۱ به بالا وارد کنید';
|
||||
return;
|
||||
}
|
||||
void saveUserCap(value);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (props.billing) {
|
||||
void loadStorage();
|
||||
void loadSeats();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -40,6 +178,78 @@ const emit = defineEmits<{
|
||||
{{ BILLING_PLAN_LABELS[code] }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="billing" class="storage">
|
||||
<strong>تعداد کاربر</strong>
|
||||
<p v-if="seats" class="muted">
|
||||
فعال {{ toFaDigits(seats.usedUsers) }}
|
||||
<template v-if="seats.maxUsers == null"> · سقف تعیین نشده</template>
|
||||
<template v-else> از {{ toFaDigits(seats.maxUsers) }}</template>
|
||||
</p>
|
||||
<p v-else-if="!seatError" class="muted">در حال خواندن کاربران…</p>
|
||||
<p v-if="seats?.maxUsers != null && seats.usedUsers > seats.maxUsers" class="error">
|
||||
تعداد فعلی از سقف بیشتر است. تا کم شدن کاربران، افزودن کاربر جدید بسته است.
|
||||
</p>
|
||||
<div class="plan-row">
|
||||
<button
|
||||
v-for="cap in BILLING_USER_CAPS"
|
||||
:key="cap"
|
||||
class="btn"
|
||||
:class="{ 'btn-ghost': seats?.maxUsers !== cap }"
|
||||
type="button"
|
||||
:disabled="seatBusy"
|
||||
@click="saveUserCap(cap)"
|
||||
>
|
||||
تا {{ toFaDigits(cap) }} کاربر
|
||||
</button>
|
||||
</div>
|
||||
<label class="quota">
|
||||
بالای ۲۰، توافقی
|
||||
<input v-model="customUsers" type="number" min="21" step="1" inputmode="numeric" />
|
||||
</label>
|
||||
<div class="plan-row">
|
||||
<button class="btn" type="button" :disabled="seatBusy" @click="saveCustomUsers">
|
||||
ذخیره سقف توافقی
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="seatError" class="error">{{ seatError }}</p>
|
||||
</div>
|
||||
<div v-if="billing" class="storage">
|
||||
<strong>حجم فایل</strong>
|
||||
<p v-if="usage" class="muted">
|
||||
مصرف {{ formatBytes(usage.usedBytes) }}
|
||||
<template v-if="usage.quotaBytes == null"> · بدون سقف</template>
|
||||
<template v-else>
|
||||
از {{ formatBytes(usage.quotaBytes) }}
|
||||
· {{ toFaDigits(usage.percent ?? 0) }}٪
|
||||
</template>
|
||||
</p>
|
||||
<p v-else-if="!storageError" class="muted">در حال خواندن مصرف…</p>
|
||||
<ul v-if="usage?.byOrganization?.length" class="orgs">
|
||||
<li v-for="org in usage.byOrganization" :key="org.id">
|
||||
{{ org.name }} · {{ formatBytes(org.usedBytes) }}
|
||||
</li>
|
||||
</ul>
|
||||
<p class="muted">
|
||||
عکس و صوت فعالیت، پیوست یادداشت، لوگو، کاور فرم، تصویر پروفایل، پیوست مالی و فایل گفتگو حساب میشود.
|
||||
متن مشتری، فعالیت و فاکتور حساب نمیشود. فایلهای قدیمی گفتگو که قبلاً روی سرور خارجی رفتهاند داخل این عدد نیستند.
|
||||
</p>
|
||||
<label class="quota">
|
||||
سقف حجم (گیگابایت)
|
||||
<input v-model="quotaGb" type="number" min="0" step="0.5" inputmode="decimal" />
|
||||
</label>
|
||||
<div class="plan-row">
|
||||
<button class="btn" type="button" :disabled="storageBusy" @click="saveTypedQuota">
|
||||
ذخیره سقف
|
||||
</button>
|
||||
<button class="btn btn-ghost" type="button" :disabled="storageBusy" @click="saveQuota(null)">
|
||||
بدون سقف
|
||||
</button>
|
||||
<button class="btn btn-ghost" type="button" :disabled="storageBusy" @click="loadStorage(true)">
|
||||
محاسبه دوباره
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="storageError" class="error">{{ storageError }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -65,4 +275,37 @@ const emit = defineEmits<{
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.storage {
|
||||
display: grid;
|
||||
gap: 0.45rem;
|
||||
padding-top: 0.35rem;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.orgs {
|
||||
margin: 0;
|
||||
padding: 0 1.1rem 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.84rem;
|
||||
}
|
||||
|
||||
.quota {
|
||||
display: grid;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.84rem;
|
||||
}
|
||||
|
||||
.quota input {
|
||||
width: 8rem;
|
||||
padding: 0.4rem 0.55rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin: 0;
|
||||
color: #b91c1c;
|
||||
font-size: 0.84rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import type {
|
||||
ApplyBillingPlanRequest,
|
||||
BillingPlanCode,
|
||||
PlatformOrganizationDto,
|
||||
PlatformOrgMemberDto,
|
||||
} from '@mento/shared';
|
||||
import { BILLING_PLAN_LABELS } from '@mento/shared';
|
||||
import { platformApi } from '@/lib/platform-api';
|
||||
import AdmBillingPanel from './AdmBillingPanel.vue';
|
||||
|
||||
const orgs = ref<PlatformOrganizationDto[]>([]);
|
||||
const orgId = ref('');
|
||||
const owners = ref<PlatformOrgMemberDto[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const success = ref('');
|
||||
const busyId = ref('');
|
||||
|
||||
function apiError(e: unknown, fallback: string) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
return Array.isArray(msg) ? msg.join('، ') : (msg ?? fallback);
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function loadOrgs() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const { data } = await platformApi.get<PlatformOrganizationDto[]>('/platform/organizations');
|
||||
orgs.value = data;
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'بارگذاری محیطها ناموفق بود');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOwners() {
|
||||
owners.value = [];
|
||||
success.value = '';
|
||||
error.value = '';
|
||||
if (!orgId.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const { data } = await platformApi.get<PlatformOrganizationDto>(
|
||||
`/platform/organizations/${orgId.value}`,
|
||||
);
|
||||
owners.value = (data.members ?? []).filter((member) => member.role === 'owner');
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'بارگذاری اشتراک محیط ناموفق بود');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPlan(userId: string, planCode: BillingPlanCode) {
|
||||
busyId.value = `plan-${userId}-${planCode}`;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
const body: ApplyBillingPlanRequest = { planCode };
|
||||
await platformApi.post(`/platform/users/${userId}/billing/apply-plan`, body);
|
||||
await loadOwners();
|
||||
success.value = `پلن «${BILLING_PLAN_LABELS[planCode]}» اعمال شد`;
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'اعمال پلن ناموفق بود');
|
||||
} finally {
|
||||
busyId.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadOrgs();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<p class="lead">پلن، تعداد کاربر و حجم فایل اشتراک را برای محیط انتخابشده تنظیم کنید.</p>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-else-if="success" class="ok">{{ success }}</p>
|
||||
<p v-if="loading && !orgs.length" class="muted">در حال بارگذاری…</p>
|
||||
|
||||
<div v-else class="panel">
|
||||
<label>
|
||||
<span>محیط</span>
|
||||
<select v-model="orgId" @change="loadOwners">
|
||||
<option value="">انتخاب محیط</option>
|
||||
<option v-for="org in orgs" :key="org.id" :value="org.id">
|
||||
{{ org.name }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<p v-if="orgId && loading" class="muted">در حال خواندن اشتراک…</p>
|
||||
<p v-else-if="orgId && !owners.length" class="muted">این محیط مالک فعالی ندارد.</p>
|
||||
<AdmBillingPanel
|
||||
v-for="owner in owners"
|
||||
:key="`${owner.userId}-${owner.billing?.planCode ?? ''}-${owner.billing?.expiresAt ?? ''}`"
|
||||
:user-id="owner.userId"
|
||||
:billing="owner.billing"
|
||||
:busy-id="busyId"
|
||||
@apply="applyPlan(owner.userId, $event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: grid;
|
||||
gap: 0.95rem;
|
||||
max-width: 1080px;
|
||||
}
|
||||
|
||||
.lead,
|
||||
.muted {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin: 0;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.ok {
|
||||
margin: 0;
|
||||
color: var(--success-deep);
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: #fff;
|
||||
border: 1px solid #eef2f7;
|
||||
border-radius: 18px;
|
||||
padding: 1rem;
|
||||
display: grid;
|
||||
gap: 0.85rem;
|
||||
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
|
||||
}
|
||||
|
||||
label {
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
max-width: 24rem;
|
||||
}
|
||||
|
||||
label span {
|
||||
font-size: 0.82rem;
|
||||
color: var(--muted);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
select {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
padding: 0.65rem 0.8rem;
|
||||
font: inherit;
|
||||
background: #fff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,228 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import type {
|
||||
ConversationSettingsDto,
|
||||
PlatformOrganizationDto,
|
||||
UpdateConversationSettingsRequest,
|
||||
} from '@mento/shared';
|
||||
import { platformApi } from '@/lib/platform-api';
|
||||
|
||||
const orgs = ref<PlatformOrganizationDto[]>([]);
|
||||
const orgId = ref('');
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const success = ref('');
|
||||
const apiKeySet = ref(false);
|
||||
const loaded = ref(false);
|
||||
|
||||
const form = reactive({
|
||||
chatHost: '',
|
||||
apiKey: '',
|
||||
uploadUrl: '',
|
||||
downloadUrl: '',
|
||||
});
|
||||
|
||||
function apiError(e: unknown, fallback: string) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
return Array.isArray(msg) ? msg.join('، ') : (msg ?? fallback);
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function loadOrgs() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const { data } = await platformApi.get<PlatformOrganizationDto[]>('/platform/organizations');
|
||||
orgs.value = data;
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'بارگذاری محیطها ناموفق بود');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSettings() {
|
||||
loaded.value = false;
|
||||
success.value = '';
|
||||
error.value = '';
|
||||
form.chatHost = '';
|
||||
form.apiKey = '';
|
||||
form.uploadUrl = '';
|
||||
form.downloadUrl = '';
|
||||
apiKeySet.value = false;
|
||||
if (!orgId.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const { data } = await platformApi.get<ConversationSettingsDto>(
|
||||
`/platform/organizations/${orgId.value}/conversations/settings`,
|
||||
);
|
||||
form.chatHost = data.chatHost;
|
||||
form.uploadUrl = data.uploadUrl;
|
||||
form.downloadUrl = data.downloadUrl;
|
||||
apiKeySet.value = data.apiKeySet;
|
||||
loaded.value = true;
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'بارگذاری تنظیمات گفتگو ناموفق بود');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!orgId.value) return;
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
const payload: UpdateConversationSettingsRequest = {
|
||||
chatHost: form.chatHost.trim(),
|
||||
uploadUrl: form.uploadUrl.trim() || undefined,
|
||||
downloadUrl: form.downloadUrl.trim() || undefined,
|
||||
};
|
||||
if (form.apiKey.trim()) payload.apiKey = form.apiKey.trim();
|
||||
const { data } = await platformApi.patch<ConversationSettingsDto>(
|
||||
`/platform/organizations/${orgId.value}/conversations/settings`,
|
||||
payload,
|
||||
);
|
||||
apiKeySet.value = data.apiKeySet;
|
||||
form.apiKey = '';
|
||||
form.chatHost = data.chatHost;
|
||||
form.uploadUrl = data.uploadUrl;
|
||||
form.downloadUrl = data.downloadUrl;
|
||||
loaded.value = true;
|
||||
success.value = 'تنظیمات گفتگو ذخیره شد';
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'ذخیره تنظیمات گفتگو ناموفق بود');
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadOrgs();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<p class="lead">Host، API Key و آدرس آپلود/دانلود را برای محیط انتخابشده تنظیم کنید.</p>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-else-if="success" class="ok">{{ success }}</p>
|
||||
<p v-if="loading && !orgs.length" class="muted">در حال بارگذاری…</p>
|
||||
|
||||
<form v-else class="panel" @submit.prevent="save">
|
||||
<label>
|
||||
<span>محیط</span>
|
||||
<select v-model="orgId" @change="loadSettings">
|
||||
<option value="">انتخاب محیط</option>
|
||||
<option v-for="org in orgs" :key="org.id" :value="org.id">
|
||||
{{ org.name }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<template v-if="orgId && loaded">
|
||||
<div class="grid">
|
||||
<label>
|
||||
<span>Host سرویس چت</span>
|
||||
<input v-model="form.chatHost" dir="ltr" placeholder="chat.example.ir" autocomplete="off" />
|
||||
</label>
|
||||
<label>
|
||||
<span>{{ apiKeySet ? 'API Key (برای تغییر وارد کنید)' : 'API Key' }}</span>
|
||||
<input v-model="form.apiKey" type="password" dir="ltr" autocomplete="new-password" />
|
||||
</label>
|
||||
<label>
|
||||
<span>آدرس آپلود فایل</span>
|
||||
<input v-model="form.uploadUrl" dir="ltr" placeholder="https://chat.example.ir/upload" />
|
||||
</label>
|
||||
<label>
|
||||
<span>آدرس پایه دانلود فایل</span>
|
||||
<input v-model="form.downloadUrl" dir="ltr" placeholder="https://chat.example.ir/files" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="panel-actions">
|
||||
<button class="btn" type="submit" :disabled="saving">
|
||||
{{ saving ? 'در حال ذخیره…' : 'ذخیره گفتگو' }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else-if="orgId && loading" class="muted">در حال خواندن تنظیمات…</p>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: grid;
|
||||
gap: 0.95rem;
|
||||
max-width: 1080px;
|
||||
}
|
||||
|
||||
.lead,
|
||||
.muted {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin: 0;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.ok {
|
||||
margin: 0;
|
||||
color: var(--success-deep);
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: #fff;
|
||||
border: 1px solid #eef2f7;
|
||||
border-radius: 18px;
|
||||
padding: 1rem;
|
||||
display: grid;
|
||||
gap: 0.85rem;
|
||||
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
label {
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
label span {
|
||||
font-size: 0.82rem;
|
||||
color: var(--muted);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
input,
|
||||
select {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
padding: 0.65rem 0.8rem;
|
||||
font: inherit;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.panel-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,17 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { RouterLink } from 'vue-router';
|
||||
import type { PlatformConversationStatsDto, PlatformStatsDto } from '@mento/shared';
|
||||
import type {
|
||||
PlatformConversationStatsDto,
|
||||
PlatformOrganizationDto,
|
||||
PlatformStatsDto,
|
||||
PlatformUserDto,
|
||||
SubscriptionSummaryDto,
|
||||
} from '@mento/shared';
|
||||
import { BILLING_PLAN_LABELS, USER_ROLE_LABELS } from '@mento/shared';
|
||||
import { platformApi } from '@/lib/platform-api';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import { usePlatformAuthStore } from '@/stores/platform-auth';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
|
||||
type FilterKey = 'organizations' | 'users' | 'memberships' | 'expiring' | 'expired' | 'chat';
|
||||
|
||||
const platform = usePlatformAuthStore();
|
||||
const loading = ref(true);
|
||||
const error = ref('');
|
||||
const listError = ref('');
|
||||
const listLoading = ref(false);
|
||||
const stats = ref<PlatformStatsDto | null>(null);
|
||||
const chatStats = ref<PlatformConversationStatsDto | null>(null);
|
||||
const filter = ref<FilterKey | null>(null);
|
||||
const orgs = ref<PlatformOrganizationDto[] | null>(null);
|
||||
const users = ref<PlatformUserDto[] | null>(null);
|
||||
|
||||
const filterTitle: Record<FilterKey, string> = {
|
||||
organizations: 'محیطها',
|
||||
users: 'کاربران',
|
||||
memberships: 'عضویتها',
|
||||
expiring: 'نزدیک انقضا',
|
||||
expired: 'منقضی',
|
||||
chat: 'گفتگوی پیکربندیشده',
|
||||
};
|
||||
|
||||
async function load() {
|
||||
error.value = '';
|
||||
@@ -30,6 +53,105 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
function isExpiring(sub: SubscriptionSummaryDto | null | undefined) {
|
||||
return Boolean(sub && sub.status === 'active' && sub.daysRemaining > 0 && sub.daysRemaining <= 3);
|
||||
}
|
||||
|
||||
function isExpired(sub: SubscriptionSummaryDto | null | undefined) {
|
||||
if (!sub) return false;
|
||||
return sub.status === 'expired' || (sub.status === 'active' && sub.daysRemaining <= 0);
|
||||
}
|
||||
|
||||
async function ensureLists() {
|
||||
listLoading.value = true;
|
||||
listError.value = '';
|
||||
try {
|
||||
if (!orgs.value) {
|
||||
const { data } = await platformApi.get<PlatformOrganizationDto[]>('/platform/organizations');
|
||||
orgs.value = data;
|
||||
}
|
||||
if (!users.value && (filter.value === 'users' || filter.value === 'memberships')) {
|
||||
const { data } = await platformApi.get<PlatformUserDto[]>('/platform/users');
|
||||
users.value = data;
|
||||
}
|
||||
} catch {
|
||||
listError.value = 'بارگذاری فهرست ناموفق بود';
|
||||
} finally {
|
||||
listLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function billingRows(mode: 'expiring' | 'expired') {
|
||||
const map = new Map<string, { id: string; title: string; orgs: string[]; plan: string; when: string }>();
|
||||
for (const org of orgs.value ?? []) {
|
||||
const sub = org.subscription;
|
||||
const match = mode === 'expiring' ? isExpiring(sub) : isExpired(sub);
|
||||
if (!match || !sub) continue;
|
||||
const key = org.ownerUserId || org.id;
|
||||
const plan = BILLING_PLAN_LABELS[sub.planCode] ?? sub.planCode;
|
||||
const when =
|
||||
mode === 'expiring'
|
||||
? `${toFaDigits(sub.daysRemaining)} روز مانده`
|
||||
: 'نیاز به تمدید';
|
||||
const current = map.get(key);
|
||||
if (current) {
|
||||
current.orgs.push(org.name);
|
||||
continue;
|
||||
}
|
||||
map.set(key, {
|
||||
id: key,
|
||||
title: org.ownerName || org.name,
|
||||
orgs: [org.name],
|
||||
plan,
|
||||
when,
|
||||
});
|
||||
}
|
||||
return [...map.values()].map((row) => ({
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
meta: `${row.orgs.join('، ')} · ${row.plan} · ${row.when}`,
|
||||
}));
|
||||
}
|
||||
|
||||
const rows = computed(() => {
|
||||
if (filter.value === 'organizations') {
|
||||
return (orgs.value ?? []).map((org) => ({
|
||||
id: org.id,
|
||||
title: org.name,
|
||||
meta: org.isActive ? 'فعال' : 'غیرفعال',
|
||||
}));
|
||||
}
|
||||
if (filter.value === 'users') {
|
||||
return (users.value ?? []).map((user) => ({
|
||||
id: user.id,
|
||||
title: user.fullName,
|
||||
meta: `${user.mobile || user.email} · ${user.isActive ? 'فعال' : 'غیرفعال'}`,
|
||||
}));
|
||||
}
|
||||
if (filter.value === 'memberships') {
|
||||
return (users.value ?? []).flatMap((user) =>
|
||||
user.memberships.map((mem) => ({
|
||||
id: mem.membershipId,
|
||||
title: user.fullName,
|
||||
meta: `${mem.organizationName} · ${USER_ROLE_LABELS[mem.role]} · ${mem.isActive ? 'فعال' : 'غیرفعال'}`,
|
||||
})),
|
||||
);
|
||||
}
|
||||
if (filter.value === 'expiring') return billingRows('expiring');
|
||||
if (filter.value === 'expired') return billingRows('expired');
|
||||
if (filter.value === 'chat') {
|
||||
return (orgs.value ?? [])
|
||||
.filter((org) => org.chatConfigured)
|
||||
.map((org) => ({ id: org.id, title: org.name, meta: 'گفتگو پیکربندی شده' }));
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
async function toggleFilter(next: FilterKey) {
|
||||
filter.value = filter.value === next ? null : next;
|
||||
if (filter.value) await ensureLists();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load();
|
||||
});
|
||||
@@ -50,56 +172,100 @@ onMounted(() => {
|
||||
<p v-else-if="loading" class="muted">در حال بارگذاری…</p>
|
||||
|
||||
<div v-else-if="stats" class="kpis">
|
||||
<article class="kpi">
|
||||
<button
|
||||
type="button"
|
||||
class="kpi"
|
||||
:class="{ on: filter === 'organizations' }"
|
||||
@click="toggleFilter('organizations')"
|
||||
>
|
||||
<span class="ico"><UiIcon name="building" :size="18" /></span>
|
||||
<div>
|
||||
<p>محیطها</p>
|
||||
<strong>{{ toFaDigits(stats.organizationCount) }}</strong>
|
||||
<small>{{ toFaDigits(stats.activeOrganizationCount) }} فعال</small>
|
||||
</div>
|
||||
</article>
|
||||
<article class="kpi">
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="kpi"
|
||||
:class="{ on: filter === 'users' }"
|
||||
@click="toggleFilter('users')"
|
||||
>
|
||||
<span class="ico"><UiIcon name="users" :size="18" /></span>
|
||||
<div>
|
||||
<p>کاربران</p>
|
||||
<strong>{{ toFaDigits(stats.userCount) }}</strong>
|
||||
<small>{{ toFaDigits(stats.activeUserCount) }} فعال</small>
|
||||
</div>
|
||||
</article>
|
||||
<article class="kpi">
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="kpi"
|
||||
:class="{ on: filter === 'memberships' }"
|
||||
@click="toggleFilter('memberships')"
|
||||
>
|
||||
<span class="ico"><UiIcon name="layers" :size="18" /></span>
|
||||
<div>
|
||||
<p>عضویتها</p>
|
||||
<strong>{{ toFaDigits(stats.membershipCount) }}</strong>
|
||||
<small>نقش در محیطها</small>
|
||||
</div>
|
||||
</article>
|
||||
<article class="kpi warn">
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="kpi warn"
|
||||
:class="{ on: filter === 'expiring' }"
|
||||
@click="toggleFilter('expiring')"
|
||||
>
|
||||
<span class="ico"><UiIcon name="clock" :size="18" /></span>
|
||||
<div>
|
||||
<p>نزدیک انقضا</p>
|
||||
<strong>{{ toFaDigits(stats.expiringSoonCount ?? 0) }}</strong>
|
||||
<small>کمتر از ۳ روز</small>
|
||||
</div>
|
||||
</article>
|
||||
<article class="kpi danger">
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="kpi danger"
|
||||
:class="{ on: filter === 'expired' }"
|
||||
@click="toggleFilter('expired')"
|
||||
>
|
||||
<span class="ico"><UiIcon name="warning" :size="18" /></span>
|
||||
<div>
|
||||
<p>منقضی</p>
|
||||
<strong>{{ toFaDigits(stats.expiredBillingCount ?? 0) }}</strong>
|
||||
<small>نیاز به تمدید</small>
|
||||
</div>
|
||||
</article>
|
||||
<article v-if="chatStats" class="kpi">
|
||||
</button>
|
||||
<button
|
||||
v-if="chatStats"
|
||||
type="button"
|
||||
class="kpi"
|
||||
:class="{ on: filter === 'chat' }"
|
||||
@click="toggleFilter('chat')"
|
||||
>
|
||||
<span class="ico"><UiIcon name="chat" :size="18" /></span>
|
||||
<div>
|
||||
<p>گفتگو (پیکربندیشده)</p>
|
||||
<strong>{{ toFaDigits(chatStats.organizationsWithChat) }}</strong>
|
||||
<small>{{ toFaDigits(chatStats.totalRoomsTracked) }} room ثبتشده</small>
|
||||
</div>
|
||||
</article>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<section v-if="filter" class="results">
|
||||
<h3>{{ filterTitle[filter] }}</h3>
|
||||
<p v-if="listLoading" class="muted">در حال خواندن…</p>
|
||||
<p v-else-if="listError" class="error">{{ listError }}</p>
|
||||
<p v-else-if="!rows.length" class="muted">موردی نیست.</p>
|
||||
<ul v-else>
|
||||
<li v-for="row in rows" :key="row.id">
|
||||
<strong>{{ row.title }}</strong>
|
||||
<span>{{ row.meta }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="actions">
|
||||
<h3>میانبرها</h3>
|
||||
<div class="shortcuts">
|
||||
@@ -202,6 +368,11 @@ onMounted(() => {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
background: #fff;
|
||||
border: 1px solid #eef2f7;
|
||||
border-radius: 18px;
|
||||
@@ -209,6 +380,11 @@ onMounted(() => {
|
||||
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
|
||||
}
|
||||
|
||||
.kpi.on {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent);
|
||||
}
|
||||
|
||||
.kpi p,
|
||||
.kpi small {
|
||||
margin: 0;
|
||||
@@ -245,6 +421,39 @@ onMounted(() => {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.results {
|
||||
display: grid;
|
||||
gap: 0.55rem;
|
||||
}
|
||||
|
||||
.results h3 {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.results ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
gap: 0.45rem;
|
||||
}
|
||||
|
||||
.results li {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
background: #fff;
|
||||
border: 1px solid #eef2f7;
|
||||
border-radius: 14px;
|
||||
padding: 0.75rem 0.9rem;
|
||||
}
|
||||
|
||||
.results span {
|
||||
color: var(--muted);
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.actions h3 {
|
||||
margin: 0 0 0.65rem;
|
||||
font-size: 0.95rem;
|
||||
|
||||
@@ -2,14 +2,9 @@
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import type {
|
||||
ApplyBillingPlanRequest,
|
||||
BillingPlanCode,
|
||||
ConversationSettingsDto,
|
||||
CreatePlatformOrganizationRequest,
|
||||
OrgModuleKey,
|
||||
PlatformOrganizationDto,
|
||||
PlatformUserDto,
|
||||
UpdateConversationSettingsRequest,
|
||||
UpdatePlatformOrganizationRequest,
|
||||
UserRole,
|
||||
} from '@mento/shared';
|
||||
@@ -25,7 +20,6 @@ import {
|
||||
import { platformApi } from '@/lib/platform-api';
|
||||
import { BUSINESS_FIELDS, BUSINESS_FIELD_LABELS } from '@/lib/business-fields';
|
||||
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
|
||||
import AdmBillingPanel from './AdmBillingPanel.vue';
|
||||
|
||||
const query = ref('');
|
||||
const loading = ref(false);
|
||||
@@ -58,16 +52,6 @@ const editForm = reactive({
|
||||
const moduleDraft = ref<OrgModuleKey[]>([]);
|
||||
const savingModules = ref(false);
|
||||
|
||||
const chatForm = reactive({
|
||||
chatHost: '',
|
||||
apiKey: '',
|
||||
uploadUrl: '',
|
||||
downloadUrl: '',
|
||||
});
|
||||
const chatApiKeySet = ref(false);
|
||||
const savingChat = ref(false);
|
||||
const chatLoadedFor = ref<string | null>(null);
|
||||
|
||||
function fieldLabel(value?: string | null) {
|
||||
if (!value) return '—';
|
||||
return isBusinessField(value) ? BUSINESS_FIELD_LABELS[value] : value;
|
||||
@@ -132,7 +116,6 @@ async function toggleOpen(org: PlatformOrganizationDto) {
|
||||
openId.value = null;
|
||||
detail.value = null;
|
||||
editingId.value = null;
|
||||
chatLoadedFor.value = null;
|
||||
return;
|
||||
}
|
||||
openId.value = org.id;
|
||||
@@ -143,56 +126,11 @@ async function toggleOpen(org: PlatformOrganizationDto) {
|
||||
);
|
||||
detail.value = data;
|
||||
moduleDraft.value = [...(data.enabledModules ?? [])];
|
||||
await loadChatSettings(org.id);
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'بارگذاری اعضا ناموفق بود');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadChatSettings(orgId: string) {
|
||||
try {
|
||||
const { data } = await platformApi.get<ConversationSettingsDto>(
|
||||
`/platform/organizations/${orgId}/conversations/settings`,
|
||||
);
|
||||
chatForm.chatHost = data.chatHost;
|
||||
chatForm.uploadUrl = data.uploadUrl;
|
||||
chatForm.downloadUrl = data.downloadUrl;
|
||||
chatApiKeySet.value = data.apiKeySet;
|
||||
chatForm.apiKey = '';
|
||||
chatLoadedFor.value = orgId;
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'بارگذاری تنظیمات گفتگو ناموفق بود');
|
||||
}
|
||||
}
|
||||
|
||||
async function saveChatSettings(orgId: string) {
|
||||
savingChat.value = true;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
const payload: UpdateConversationSettingsRequest = {
|
||||
chatHost: chatForm.chatHost.trim(),
|
||||
uploadUrl: chatForm.uploadUrl.trim() || undefined,
|
||||
downloadUrl: chatForm.downloadUrl.trim() || undefined,
|
||||
};
|
||||
if (chatForm.apiKey.trim()) payload.apiKey = chatForm.apiKey.trim();
|
||||
const { data } = await platformApi.patch<ConversationSettingsDto>(
|
||||
`/platform/organizations/${orgId}/conversations/settings`,
|
||||
payload,
|
||||
);
|
||||
chatApiKeySet.value = data.apiKeySet;
|
||||
chatForm.apiKey = '';
|
||||
chatForm.chatHost = data.chatHost;
|
||||
chatForm.uploadUrl = data.uploadUrl;
|
||||
chatForm.downloadUrl = data.downloadUrl;
|
||||
success.value = 'تنظیمات گفتگو ذخیره شد';
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'ذخیره تنظیمات گفتگو ناموفق بود');
|
||||
} finally {
|
||||
savingChat.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function startEdit(org: PlatformOrganizationDto) {
|
||||
editingId.value = org.id;
|
||||
editForm.name = org.name;
|
||||
@@ -368,35 +306,6 @@ async function saveModules(orgId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPlan(userId: string, planCode: BillingPlanCode) {
|
||||
busyId.value = `plan-${userId}-${planCode}`;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
const body: ApplyBillingPlanRequest = { planCode };
|
||||
await platformApi.post<PlatformUserDto>(
|
||||
`/platform/users/${userId}/billing/apply-plan`,
|
||||
body,
|
||||
);
|
||||
if (openId.value) {
|
||||
const { data } = await platformApi.get<PlatformOrganizationDto>(
|
||||
`/platform/organizations/${openId.value}`,
|
||||
);
|
||||
detail.value = data;
|
||||
}
|
||||
const { data: list } = await platformApi.get<PlatformOrganizationDto[]>(
|
||||
'/platform/organizations',
|
||||
{ params: query.value.trim() ? { q: query.value.trim() } : undefined },
|
||||
);
|
||||
items.value = list;
|
||||
success.value = `پلن «${BILLING_PLAN_LABELS[planCode]}» اعمال شد`;
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'اعمال پلن ناموفق بود');
|
||||
} finally {
|
||||
busyId.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load();
|
||||
});
|
||||
@@ -599,59 +508,6 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-settings">
|
||||
<div class="modules-head">
|
||||
<strong>تنظیمات گفتگو</strong>
|
||||
<button
|
||||
class="btn"
|
||||
type="button"
|
||||
:disabled="savingChat || chatLoadedFor !== org.id"
|
||||
@click="saveChatSettings(org.id)"
|
||||
>
|
||||
{{ savingChat ? 'ذخیره…' : 'ذخیره گفتگو' }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="chat-hint">
|
||||
Host، API Key و آدرس آپلود/دانلود — فقط از سوپرادمین و برای همین محیط.
|
||||
</p>
|
||||
<div class="chat-grid">
|
||||
<label>
|
||||
<span>Host سرویس چت</span>
|
||||
<input
|
||||
v-model="chatForm.chatHost"
|
||||
dir="ltr"
|
||||
placeholder="chat.example.ir"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>{{ chatApiKeySet ? 'API Key (برای تغییر وارد کنید)' : 'API Key' }}</span>
|
||||
<input
|
||||
v-model="chatForm.apiKey"
|
||||
type="password"
|
||||
dir="ltr"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>آدرس آپلود فایل</span>
|
||||
<input
|
||||
v-model="chatForm.uploadUrl"
|
||||
dir="ltr"
|
||||
placeholder="https://chat.example.ir/upload"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>آدرس پایه دانلود فایل</span>
|
||||
<input
|
||||
v-model="chatForm.downloadUrl"
|
||||
dir="ltr"
|
||||
placeholder="https://chat.example.ir/files"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="!detail?.members?.length" class="muted">عضوی ثبت نشده.</p>
|
||||
<ul v-else>
|
||||
<li v-for="member in detail.members" :key="member.membershipId">
|
||||
@@ -688,13 +544,6 @@ onMounted(() => {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<AdmBillingPanel
|
||||
v-if="member.role === 'owner'"
|
||||
:user-id="member.userId"
|
||||
:billing="member.billing"
|
||||
:busy-id="busyId"
|
||||
@apply="applyPlan(member.userId, $event)"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -933,33 +782,6 @@ label span {
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.chat-settings {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
padding: 0.85rem;
|
||||
border-radius: 12px;
|
||||
background: #f5f3ff;
|
||||
border: 1px solid #e9e5ff;
|
||||
}
|
||||
|
||||
.chat-hint {
|
||||
margin: 0;
|
||||
font-size: 0.82rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.chat-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.chat-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.modules-head,
|
||||
.mod-group-head {
|
||||
display: flex;
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import type {
|
||||
ApplyBillingPlanRequest,
|
||||
BillingPlanCode,
|
||||
PlatformUserDto,
|
||||
UserRole,
|
||||
} from '@mento/shared';
|
||||
import {
|
||||
BILLING_PLAN_LABELS,
|
||||
USER_ROLE_LABELS,
|
||||
USER_ROLES,
|
||||
} from '@mento/shared';
|
||||
import type { PlatformUserDto, UserRole } from '@mento/shared';
|
||||
import { USER_ROLE_LABELS, USER_ROLES } from '@mento/shared';
|
||||
import { platformApi } from '@/lib/platform-api';
|
||||
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
|
||||
import AdmBillingPanel from './AdmBillingPanel.vue';
|
||||
|
||||
const query = ref('');
|
||||
const ownersOnly = ref(false);
|
||||
@@ -135,25 +125,6 @@ async function setMembershipRole(userId: string, membershipId: string, role: Use
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPlan(userId: string, planCode: BillingPlanCode) {
|
||||
busyId.value = `plan-${userId}-${planCode}`;
|
||||
error.value = '';
|
||||
success.value = '';
|
||||
try {
|
||||
const body: ApplyBillingPlanRequest = { planCode };
|
||||
const { data } = await platformApi.post<PlatformUserDto>(
|
||||
`/platform/users/${userId}/billing/apply-plan`,
|
||||
body,
|
||||
);
|
||||
items.value = items.value.map((row) => (row.id === userId ? data : row));
|
||||
success.value = `پلن «${BILLING_PLAN_LABELS[planCode]}» اعمال شد`;
|
||||
} catch (e) {
|
||||
error.value = apiError(e, 'اعمال پلن ناموفق بود');
|
||||
} finally {
|
||||
busyId.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
function setOwnersOnly(value: boolean) {
|
||||
if (ownersOnly.value === value) return;
|
||||
ownersOnly.value = value;
|
||||
@@ -168,7 +139,7 @@ onMounted(() => {
|
||||
<template>
|
||||
<div class="page">
|
||||
<header class="head">
|
||||
<p class="lead">اشتراک مالک، نقش عضویت و ریست رمز.</p>
|
||||
<p class="lead">نقش عضویت و ریست رمز. اشتراک از منوی اشتراک تنظیم میشود.</p>
|
||||
<div class="head-actions">
|
||||
<div class="seg" role="group" aria-label="فیلتر مالکان">
|
||||
<button
|
||||
@@ -264,17 +235,6 @@ onMounted(() => {
|
||||
</form>
|
||||
|
||||
<div v-if="openId === user.id" class="detail">
|
||||
<AdmBillingPanel
|
||||
v-if="user.isBillingOwner"
|
||||
:user-id="user.id"
|
||||
:billing="user.billing"
|
||||
:busy-id="busyId"
|
||||
@apply="applyPlan(user.id, $event)"
|
||||
/>
|
||||
<p v-else class="muted billing-skip">
|
||||
این کاربر عضو زیرمجموعه است و اشتراک جدا ندارد؛ اشتراک روی مالک محیط است.
|
||||
</p>
|
||||
|
||||
<p v-if="!user.memberships.length" class="muted">عضو هیچ محیطی نیست.</p>
|
||||
<ul v-else>
|
||||
<li v-for="mem in user.memberships" :key="mem.membershipId">
|
||||
|
||||
@@ -72,7 +72,9 @@ const f = reactive({
|
||||
const users = computed(() => shell.context.value?.users ?? []);
|
||||
const teams = computed(() => shell.context.value?.teams ?? []);
|
||||
const categories = computed(() => shell.context.value?.categories ?? []);
|
||||
const sources = Object.entries(ROUTINE_TASK_SOURCE_LABELS) as Array<[RoutineTaskSource, string]>;
|
||||
const sources = (['routine', 'manual'] as const).map(
|
||||
(key) => [key, ROUTINE_TASK_SOURCE_LABELS[key]] as [RoutineTaskSource, string],
|
||||
);
|
||||
const statuses = Object.entries(ROUTINE_TASK_STATUS_LABELS) as Array<[RoutineTaskStatus, string]>;
|
||||
|
||||
const userOptions = computed(() => [
|
||||
|
||||
@@ -1,121 +1,203 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import {
|
||||
Alert as AAlert,
|
||||
Button as AButton,
|
||||
Card as ACard,
|
||||
Col as ACol,
|
||||
Divider as ADivider,
|
||||
Empty as AEmpty,
|
||||
Flex as AFlex,
|
||||
Form as AForm,
|
||||
FormItem as AFormItem,
|
||||
Input as AInput,
|
||||
Row as ARow,
|
||||
Space as ASpace,
|
||||
Statistic as AStatistic,
|
||||
Table as ATable,
|
||||
} from 'ant-design-vue';
|
||||
import type { TableColumnsType } from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import type { FinancialAccountDto, FinancialMovementDto } from '@mento/shared';
|
||||
import { UiButton, UiField, UiInput, UiPageHeader } from '@/components/ui';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import { toman } from './treasury-format';
|
||||
import { formatJalaliNumeric } from '@/lib/jalali';
|
||||
import { parseMoneyNumber } from '@/lib/money';
|
||||
import { useTreasuryPageChrome } from './treasuryPageChrome';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const pageChrome = useTreasuryPageChrome();
|
||||
const account = ref<FinancialAccountDto | null>(null);
|
||||
const items = ref<FinancialMovementDto[]>([]);
|
||||
const error = ref('');
|
||||
const stated = ref('');
|
||||
const stated = ref<string | number | null>('');
|
||||
const reason = ref('');
|
||||
const note = ref('');
|
||||
const busy = ref(false);
|
||||
|
||||
const columns: TableColumnsType<FinancialMovementDto> = [
|
||||
{
|
||||
title: 'تاریخ',
|
||||
key: 'occurredAt',
|
||||
customRender: ({ record }) => formatJalaliNumeric(new Date(record.occurredAt)),
|
||||
},
|
||||
{
|
||||
title: 'شرح',
|
||||
key: 'memo',
|
||||
customRender: ({ record }) => record.memo || '—',
|
||||
},
|
||||
{ title: 'نوع', dataIndex: 'kindLabel', key: 'kindLabel' },
|
||||
{
|
||||
title: 'ورودی',
|
||||
key: 'in',
|
||||
customRender: ({ record }) => (record.direction === 'in' ? toman(record.amount) : '—'),
|
||||
},
|
||||
{
|
||||
title: 'خروجی',
|
||||
key: 'out',
|
||||
customRender: ({ record }) => (record.direction === 'out' ? toman(record.amount) : '—'),
|
||||
},
|
||||
{
|
||||
title: 'مانده',
|
||||
key: 'balanceAfter',
|
||||
customRender: ({ record }) => (record.balanceAfter ? toman(record.balanceAfter) : '—'),
|
||||
},
|
||||
];
|
||||
|
||||
async function load() {
|
||||
const { data } = await api.get<{ account: FinancialAccountDto; items: FinancialMovementDto[] }>(
|
||||
`/treasury/accounts/${route.params.id}/ledger`,
|
||||
);
|
||||
account.value = data.account;
|
||||
items.value = data.items;
|
||||
pageChrome?.set({
|
||||
title: data.account.name || 'جزئیات حساب',
|
||||
description: 'گردش قطعی این حساب',
|
||||
});
|
||||
}
|
||||
|
||||
async function reconcile() {
|
||||
error.value = '';
|
||||
note.value = '';
|
||||
busy.value = true;
|
||||
try {
|
||||
const { data } = await api.post<{ difference: string; systemBalance: string }>('/treasury/reconciliations', {
|
||||
accountId: route.params.id,
|
||||
statedBalance: stated.value,
|
||||
});
|
||||
const amount = parseMoneyNumber(String(stated.value ?? ''), 0);
|
||||
const { data } = await api.post<{ difference: string; systemBalance: string }>(
|
||||
'/treasury/reconciliations',
|
||||
{
|
||||
accountId: route.params.id,
|
||||
statedBalance: amount ?? 0,
|
||||
},
|
||||
);
|
||||
note.value = `اختلاف ${toman(data.difference)} نسبت به موجودی سیستم ${toman(data.systemBalance)}. موجودی خودکار عوض نشد.`;
|
||||
} catch {
|
||||
error.value = 'ثبت مغایرت ناموفق بود.';
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function adjust(direction: 'in' | 'out') {
|
||||
error.value = '';
|
||||
busy.value = true;
|
||||
try {
|
||||
const amount = parseMoneyNumber(String(stated.value ?? ''), 0);
|
||||
await api.post('/treasury/adjustments', {
|
||||
accountId: route.params.id,
|
||||
amount: stated.value,
|
||||
amount: amount ?? 0,
|
||||
direction,
|
||||
reason: reason.value,
|
||||
});
|
||||
window.location.reload();
|
||||
await load();
|
||||
note.value = 'اصلاح موجودی ثبت شد.';
|
||||
} catch {
|
||||
error.value = 'اصلاح موجودی ناموفق بود.';
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const { data } = await api.get<{ account: FinancialAccountDto; items: FinancialMovementDto[] }>(
|
||||
`/treasury/accounts/${route.params.id}/ledger`,
|
||||
);
|
||||
account.value = data.account;
|
||||
items.value = data.items;
|
||||
} catch {
|
||||
onMounted(() => {
|
||||
void load().catch(() => {
|
||||
error.value = 'گردش حساب بارگذاری نشد.';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
pageChrome?.clear();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<UiPageHeader :title="account?.name || 'حساب'" description="گردش قطعی این حساب" />
|
||||
<TreasuryNav />
|
||||
<p v-if="error" class="err">{{ error }}</p>
|
||||
<div v-if="account" class="stats">
|
||||
<article><span>موجودی فعلی</span><strong>{{ toman(account.balance) }}</strong></article>
|
||||
<article><span>مانده افتتاحیه</span><strong>{{ toman(account.openingBalance) }}</strong></article>
|
||||
<article><span>ورودی</span><strong>{{ toman(account.periodIn) }}</strong></article>
|
||||
<article><span>خروجی</span><strong>{{ toman(account.periodOut) }}</strong></article>
|
||||
</div>
|
||||
<div v-if="account" class="reconcile">
|
||||
<UiField label="موجودی واقعی"><MoneyInput v-model="stated" :decimals="0" /></UiField>
|
||||
<UiField label="علت اصلاح"><UiInput v-model="reason" /></UiField>
|
||||
<UiButton variant="secondary" @click="reconcile">ثبت مغایرت</UiButton>
|
||||
<UiButton variant="secondary" @click="adjust('in')">اصلاح ورود</UiButton>
|
||||
<UiButton variant="secondary" @click="adjust('out')">اصلاح خروج</UiButton>
|
||||
<p v-if="note" class="note">{{ note }}</p>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>تاریخ</th>
|
||||
<th>شرح</th>
|
||||
<th>نوع</th>
|
||||
<th>ورودی</th>
|
||||
<th>خروجی</th>
|
||||
<th>مانده</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in items" :key="row.id">
|
||||
<td>{{ formatJalaliNumeric(new Date(row.occurredAt)) }}</td>
|
||||
<td>{{ row.memo || '—' }}</td>
|
||||
<td>{{ row.kindLabel }}</td>
|
||||
<td>{{ row.direction === 'in' ? toman(row.amount) : '—' }}</td>
|
||||
<td>{{ row.direction === 'out' ? toman(row.amount) : '—' }}</td>
|
||||
<td>{{ row.balanceAfter ? toman(row.balanceAfter) : '—' }}</td>
|
||||
</tr>
|
||||
<tr v-if="!items.length"><td colspan="6">گردشی ثبت نشده است.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<a-flex vertical :gap="16">
|
||||
<a-space>
|
||||
<a-button type="link" @click="router.push('/finance/accounts')">بازگشت به حسابها</a-button>
|
||||
</a-space>
|
||||
|
||||
<style scoped>
|
||||
.page { display: grid; gap: 1rem; }
|
||||
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.7rem; }
|
||||
.stats article { background: #fff; border: 1px solid #e7eef2; border-radius: 14px; padding: 0.8rem; }
|
||||
.stats span { color: #64748b; display: block; }
|
||||
.table-wrap { overflow: auto; background: #fff; border: 1px solid #e7eef2; border-radius: 16px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { padding: 0.7rem; text-align: right; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
|
||||
.reconcile { display: grid; grid-template-columns: 1fr 1fr auto auto auto; gap: 0.6rem; align-items: end; }
|
||||
.note { grid-column: 1 / -1; color: #0f766e; font-weight: 700; }
|
||||
.err { color: #b91c1c; font-weight: 700; }
|
||||
@media (max-width: 800px) { .reconcile { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
<a-alert v-if="note" type="success" show-icon :message="note" />
|
||||
|
||||
<a-row v-if="account" :gutter="[16, 16]">
|
||||
<a-col :xs="24" :sm="12" :md="6">
|
||||
<a-card :bordered="false">
|
||||
<a-statistic title="موجودی فعلی" :value="toman(account.balance)" />
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="6">
|
||||
<a-card :bordered="false">
|
||||
<a-statistic title="مانده افتتاحیه" :value="toman(account.openingBalance)" />
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="6">
|
||||
<a-card :bordered="false">
|
||||
<a-statistic title="ورودی" :value="toman(account.periodIn)" />
|
||||
</a-card>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="6">
|
||||
<a-card :bordered="false">
|
||||
<a-statistic title="خروجی" :value="toman(account.periodOut)" />
|
||||
</a-card>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-card v-if="account" :bordered="false">
|
||||
<a-divider orientation="right">مغایرت و اصلاح</a-divider>
|
||||
<a-form layout="vertical">
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="موجودی واقعی">
|
||||
<MoneyInput v-model="stated" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="علت اصلاح">
|
||||
<a-input v-model:value="reason" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label=" ">
|
||||
<a-space wrap>
|
||||
<a-button :loading="busy" @click="reconcile">ثبت مغایرت</a-button>
|
||||
<a-button :loading="busy" @click="adjust('in')">اصلاح ورود</a-button>
|
||||
<a-button :loading="busy" @click="adjust('out')">اصلاح خروج</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
|
||||
<a-divider orientation="right">گردش حساب</a-divider>
|
||||
<a-empty v-if="!items.length" description="گردشی ثبت نشده است." />
|
||||
<a-table
|
||||
v-else
|
||||
:columns="columns"
|
||||
:data-source="items"
|
||||
:pagination="false"
|
||||
row-key="id"
|
||||
:scroll="{ x: true }"
|
||||
/>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -20,13 +20,16 @@ import {
|
||||
Statistic as AStatistic,
|
||||
Tag as ATag,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import type { FinancialAccountDto, FinancialAccountType } from '@mento/shared';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import { toman } from './treasury-format';
|
||||
import { parseMoneyNumber } from '@/lib/money';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
const ASelectOption = ASelect.Option;
|
||||
@@ -82,14 +85,19 @@ async function load() {
|
||||
accounts.value = data;
|
||||
}
|
||||
|
||||
function onFinishFailed() {
|
||||
message.warning('لطفاً فیلدهای الزامی را کامل کنید.');
|
||||
}
|
||||
|
||||
async function createAccount() {
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
const openingBalance = parseMoneyNumber(String(form.value.openingBalance ?? ''), 0) ?? 0;
|
||||
await api.post('/treasury/accounts', {
|
||||
...form.value,
|
||||
openingBalance: form.value.openingBalance || 0,
|
||||
openingBalance,
|
||||
openingDate: form.value.openingDate || undefined,
|
||||
});
|
||||
openForm.value = false;
|
||||
@@ -117,11 +125,20 @@ async function sendTransfer() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
const amount = parseMoneyNumber(String(transfer.value.amount ?? ''), 0);
|
||||
if (amount == null || amount <= 0) {
|
||||
error.value = 'مبلغ انتقال معتبر نیست.';
|
||||
return;
|
||||
}
|
||||
await api.post('/treasury/transfers', {
|
||||
...transfer.value,
|
||||
fromAccountId: transfer.value.fromAccountId,
|
||||
toAccountId: transfer.value.toAccountId,
|
||||
amount,
|
||||
memo: transfer.value.memo || undefined,
|
||||
clientKey: crypto.randomUUID(),
|
||||
});
|
||||
transferOpen.value = false;
|
||||
transfer.value = { fromAccountId: '', toAccountId: '', amount: '', memo: '' };
|
||||
ok.value = 'انتقال ثبت شد و در درآمد یا هزینه نیامده است.';
|
||||
await load();
|
||||
} catch (e) {
|
||||
@@ -139,17 +156,7 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a-flex vertical :gap="16">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">صندوق و حسابها</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
موجودی هر حساب از مانده افتتاحیه و گردش قطعی محاسبه میشود.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
<a-alert v-if="ok" type="success" show-icon :message="ok" />
|
||||
|
||||
@@ -192,15 +199,24 @@ onMounted(() => {
|
||||
|
||||
<template v-if="openForm">
|
||||
<a-divider orientation="right">حساب جدید</a-divider>
|
||||
<a-form layout="vertical" @finish="createAccount">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="form"
|
||||
@finish="createAccount"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="نام حساب" name="name">
|
||||
<a-form-item
|
||||
label="نام حساب"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: 'نام حساب الزامی است' }]"
|
||||
>
|
||||
<a-input v-model:value="form.name" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="نوع" name="type">
|
||||
<a-form-item label="نوع" name="type" :rules="[{ required: true }]">
|
||||
<a-select v-model:value="form.type" style="width: 100%">
|
||||
<a-select-option value="cash">صندوق نقدی</a-select-option>
|
||||
<a-select-option value="bank">حساب بانکی</a-select-option>
|
||||
@@ -225,12 +241,12 @@ onMounted(() => {
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="موجودی اولیه" name="openingBalance">
|
||||
<a-input v-model:value="form.openingBalance" />
|
||||
<MoneyInput v-model="form.openingBalance" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="تاریخ شروع" name="openingDate">
|
||||
<a-input v-model:value="form.openingDate" type="date" style="width: 100%" />
|
||||
<JalaliDateInput v-model="form.openingDate" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
@@ -245,12 +261,25 @@ onMounted(() => {
|
||||
|
||||
<template v-if="transferOpen">
|
||||
<a-divider orientation="right">انتقال بین حسابها</a-divider>
|
||||
<a-form layout="vertical" @finish="sendTransfer">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="transfer"
|
||||
@finish="sendTransfer"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="از حساب" name="fromAccountId">
|
||||
<a-select v-model:value="transfer.fromAccountId" style="width: 100%" placeholder="انتخاب">
|
||||
<a-select-option value="">انتخاب</a-select-option>
|
||||
<a-form-item
|
||||
label="از حساب"
|
||||
name="fromAccountId"
|
||||
:rules="[{ required: true, message: 'حساب مبدأ الزامی است' }]"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="transfer.fromAccountId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="انتخاب"
|
||||
>
|
||||
<a-select-option v-for="account in active" :key="account.id" :value="account.id">
|
||||
{{ account.name }}
|
||||
</a-select-option>
|
||||
@@ -258,18 +287,34 @@ onMounted(() => {
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="به حساب" name="toAccountId">
|
||||
<a-select v-model:value="transfer.toAccountId" style="width: 100%" placeholder="انتخاب">
|
||||
<a-select-option value="">انتخاب</a-select-option>
|
||||
<a-select-option v-for="account in active" :key="`to-${account.id}`" :value="account.id">
|
||||
<a-form-item
|
||||
label="به حساب"
|
||||
name="toAccountId"
|
||||
:rules="[{ required: true, message: 'حساب مقصد الزامی است' }]"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="transfer.toAccountId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="انتخاب"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="account in active"
|
||||
:key="`to-${account.id}`"
|
||||
:value="account.id"
|
||||
>
|
||||
{{ account.name }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مبلغ" name="amount">
|
||||
<a-input v-model:value="transfer.amount" />
|
||||
<a-form-item
|
||||
label="مبلغ"
|
||||
name="amount"
|
||||
:rules="[{ required: true, message: 'مبلغ الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="transfer.amount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
@@ -309,6 +354,5 @@ onMounted(() => {
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import {
|
||||
Alert as AAlert,
|
||||
Card as ACard,
|
||||
Empty as AEmpty,
|
||||
Flex as AFlex,
|
||||
List as AList,
|
||||
Typography,
|
||||
} from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import { UiPageHeader } from '@/components/ui';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import { formatJalaliNumeric } from '@/lib/jalali';
|
||||
|
||||
const { Paragraph: ATypographyParagraph } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
|
||||
type Row = {
|
||||
id: string;
|
||||
action: string;
|
||||
@@ -32,26 +42,31 @@ onMounted(async () => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<UiPageHeader title="سوابق تغییرات مالی" description="تسویه سند و نشستن وجه در صندوق، با مقدار ثبتشده." />
|
||||
<TreasuryNav />
|
||||
<p v-if="error" class="err">{{ error }}</p>
|
||||
<p v-if="!error && !rows.length" class="muted">سابقهای نیست.</p>
|
||||
<article v-for="row in rows" :key="row.id">
|
||||
<header>
|
||||
<strong>{{ actionLabel[row.action] ?? row.action }}</strong>
|
||||
<time>{{ formatJalaliNumeric(new Date(row.createdAt)) }}</time>
|
||||
</header>
|
||||
<pre>{{ JSON.stringify(row.after ?? row.before, null, 2) }}</pre>
|
||||
</article>
|
||||
</section>
|
||||
</template>
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
|
||||
<style scoped>
|
||||
.page { display: grid; gap: 0.8rem; }
|
||||
article { background: #fff; border: 1px solid #e7eef2; border-radius: 14px; padding: 0.8rem 1rem; }
|
||||
header { display: flex; justify-content: space-between; gap: 0.75rem; }
|
||||
time, .muted { color: #64748b; }
|
||||
pre { margin: 0.45rem 0 0; white-space: pre-wrap; font: inherit; color: #334155; }
|
||||
.err { color: #b91c1c; font-weight: 700; }
|
||||
</style>
|
||||
<a-card :bordered="false">
|
||||
<a-empty v-if="!error && !rows.length" description="سابقهای نیست." />
|
||||
<a-list v-else item-layout="vertical" :data-source="rows">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item>
|
||||
<a-list-item-meta>
|
||||
<template #title>
|
||||
{{ actionLabel[item.action] ?? item.action }}
|
||||
</template>
|
||||
<template #description>
|
||||
{{ formatJalaliNumeric(new Date(item.createdAt)) }}
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
<a-typography-paragraph
|
||||
:copyable="true"
|
||||
:style="{ marginBottom: 0, whiteSpace: 'pre-wrap', fontFamily: 'inherit' }"
|
||||
>
|
||||
{{ JSON.stringify(item.after ?? item.before, null, 2) }}
|
||||
</a-typography-paragraph>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -16,20 +16,16 @@ import {
|
||||
Row as ARow,
|
||||
Select as ASelect,
|
||||
Tag as ATag,
|
||||
Typography,
|
||||
} from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import type { FinancialCategoryDto } from '@mento/shared';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
const ASelectOption = ASelect.Option;
|
||||
|
||||
const rows = ref<FinancialCategoryDto[]>([]);
|
||||
const name = ref('');
|
||||
const kind = ref<'income' | 'expense'>('expense');
|
||||
const form = ref({ name: '', kind: 'expense' as 'income' | 'expense' });
|
||||
const error = ref('');
|
||||
|
||||
async function load() {
|
||||
@@ -40,8 +36,11 @@ async function load() {
|
||||
async function add() {
|
||||
error.value = '';
|
||||
try {
|
||||
await api.post('/treasury/categories', { name: name.value, kind: kind.value });
|
||||
name.value = '';
|
||||
await api.post('/treasury/categories', {
|
||||
name: form.value.name,
|
||||
kind: form.value.kind,
|
||||
});
|
||||
form.value.name = '';
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = axios.isAxiosError(e)
|
||||
@@ -56,31 +55,25 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a-flex vertical :gap="16">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">دستهبندیهای مالی</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
دستههای پیشفرض با اولین بازدید ساخته میشوند.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-divider orientation="right">افزودن دسته</a-divider>
|
||||
<a-form layout="vertical" @finish="add">
|
||||
<a-form layout="vertical" :model="form" @finish="add">
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="نام" name="name">
|
||||
<a-input v-model:value="name" />
|
||||
<a-form-item
|
||||
label="نام"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: 'نام الزامی است' }]"
|
||||
>
|
||||
<a-input v-model:value="form.name" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="نوع" name="kind">
|
||||
<a-select v-model:value="kind" style="width: 100%">
|
||||
<a-form-item label="نوع" name="kind" :rules="[{ required: true }]">
|
||||
<a-select v-model:value="form.kind" style="width: 100%">
|
||||
<a-select-option value="income">درآمد</a-select-option>
|
||||
<a-select-option value="expense">هزینه</a-select-option>
|
||||
</a-select>
|
||||
@@ -111,6 +104,5 @@ onMounted(() => {
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -16,13 +16,15 @@ import {
|
||||
Row as ARow,
|
||||
Select as ASelect,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import type { FinancialAccountDto, FinancialCategoryDto, FinancialDocumentDto } from '@mento/shared';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import { toman } from './treasury-format';
|
||||
import { parseMoneyNumber } from '@/lib/money';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
const ASelectOption = ASelect.Option;
|
||||
@@ -47,7 +49,6 @@ const form = ref({
|
||||
notes: '',
|
||||
});
|
||||
|
||||
const title = 'پرداختها و هزینهها';
|
||||
const settleLabel = 'مبلغ پرداختشده';
|
||||
const statusLabel: Record<string, string> = {
|
||||
open: 'پرداختنشده',
|
||||
@@ -81,19 +82,29 @@ async function load() {
|
||||
accounts.value = acc.data.filter((row) => row.isActive);
|
||||
}
|
||||
|
||||
function onFinishFailed() {
|
||||
message.warning('لطفاً فیلدهای الزامی را کامل کنید.');
|
||||
}
|
||||
|
||||
async function createDoc() {
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
const amount = parseMoneyNumber(String(form.value.amount ?? ''), 0);
|
||||
if (amount == null || amount <= 0) {
|
||||
error.value = 'مبلغ کل معتبر نیست.';
|
||||
return;
|
||||
}
|
||||
const settleAmount = parseMoneyNumber(String(form.value.settleAmount ?? ''), 0) ?? 0;
|
||||
await api.post('/treasury/documents', {
|
||||
kind,
|
||||
title: form.value.title,
|
||||
amount: form.value.amount,
|
||||
amount,
|
||||
categoryId: form.value.categoryId || null,
|
||||
partyName: form.value.partyName || null,
|
||||
accountId: form.value.accountId || null,
|
||||
settleAmount: form.value.settleAmount || 0,
|
||||
settleAmount,
|
||||
method: form.value.method,
|
||||
reference: form.value.reference || null,
|
||||
notes: form.value.notes || null,
|
||||
@@ -136,43 +147,50 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a-flex vertical :gap="16">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">{{ title }}</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
ثبت سند، موجودی را عوض نمیکند مگر مبلغ دریافت یا پرداخت واقعی وارد شود.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
<a-alert v-if="ok" type="success" show-icon :message="ok" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-divider orientation="right">سند جدید</a-divider>
|
||||
<a-form layout="vertical" @finish="createDoc">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="form"
|
||||
@finish="createDoc"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="عنوان" name="title">
|
||||
<a-form-item
|
||||
label="عنوان"
|
||||
name="title"
|
||||
:rules="[{ required: true, message: 'عنوان الزامی است' }]"
|
||||
>
|
||||
<a-input v-model:value="form.title" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مبلغ کل" name="amount">
|
||||
<a-input v-model:value="form.amount" />
|
||||
<a-form-item
|
||||
label="مبلغ کل"
|
||||
name="amount"
|
||||
:rules="[{ required: true, message: 'مبلغ الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="form.amount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item :label="settleLabel" name="settleAmount">
|
||||
<a-input v-model:value="form.settleAmount" />
|
||||
<MoneyInput v-model="form.settleAmount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="دستهبندی" name="categoryId">
|
||||
<a-select v-model:value="form.categoryId" allow-clear style="width: 100%" placeholder="بدون دسته">
|
||||
<a-select-option value="">بدون دسته</a-select-option>
|
||||
<a-select
|
||||
v-model:value="form.categoryId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="بدون دسته"
|
||||
>
|
||||
<a-select-option v-for="cat in categories" :key="cat.id" :value="cat.id">
|
||||
{{ cat.name }}
|
||||
</a-select-option>
|
||||
@@ -186,8 +204,12 @@ onMounted(() => {
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="حساب" name="accountId">
|
||||
<a-select v-model:value="form.accountId" allow-clear style="width: 100%" placeholder="انتخاب حساب">
|
||||
<a-select-option value="">انتخاب حساب</a-select-option>
|
||||
<a-select
|
||||
v-model:value="form.accountId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="انتخاب حساب"
|
||||
>
|
||||
<a-select-option v-for="account in accounts" :key="account.id" :value="account.id">
|
||||
{{ account.name }}
|
||||
</a-select-option>
|
||||
@@ -256,6 +278,5 @@ onMounted(() => {
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -22,12 +22,12 @@ import {
|
||||
Space as ASpace,
|
||||
Textarea as ATextarea,
|
||||
Typography,
|
||||
message,
|
||||
theme,
|
||||
} from 'ant-design-vue';
|
||||
import type { FormInstance } from 'ant-design-vue';
|
||||
import {
|
||||
ArrowDownOutlined,
|
||||
ArrowLeftOutlined,
|
||||
BankOutlined,
|
||||
CheckOutlined,
|
||||
ClockCircleOutlined,
|
||||
@@ -48,10 +48,11 @@ import type {
|
||||
TreasuryDashboardDto,
|
||||
} from '@mento/shared';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import { toman } from './treasury-format';
|
||||
import { parseMoneyNumber } from '@/lib/money';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
const ASelectOption = ASelect.Option;
|
||||
@@ -91,7 +92,6 @@ function emptyForm() {
|
||||
|
||||
const form = ref(emptyForm());
|
||||
|
||||
const pageTitle = 'دریافتها و درآمدها';
|
||||
const settleLabel = 'مبلغ دریافتشده';
|
||||
const statusLabel: Record<string, string> = {
|
||||
open: 'دریافتنشده',
|
||||
@@ -122,11 +122,15 @@ const formTabOptions = [
|
||||
];
|
||||
|
||||
const remainingAmount = computed(() => {
|
||||
const total = Number(form.value.amount) || 0;
|
||||
const settled = Number(form.value.settleAmount) || 0;
|
||||
const total = parseMoneyNumber(String(form.value.amount ?? ''), 0) ?? 0;
|
||||
const settled = parseMoneyNumber(String(form.value.settleAmount ?? ''), 0) ?? 0;
|
||||
return Math.max(0, total - settled);
|
||||
});
|
||||
|
||||
function onFinishFailed() {
|
||||
message.warning('لطفاً فیلدهای الزامی را کامل کنید.');
|
||||
}
|
||||
|
||||
function apiMessage(e: unknown) {
|
||||
if (!axios.isAxiosError(e)) return 'ذخیره ناموفق بود.';
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
@@ -158,14 +162,20 @@ async function createDoc() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
const amount = parseMoneyNumber(String(form.value.amount ?? ''), 0);
|
||||
if (amount == null || amount <= 0) {
|
||||
error.value = 'مبلغ کل معتبر نیست.';
|
||||
return;
|
||||
}
|
||||
const settleAmount = parseMoneyNumber(String(form.value.settleAmount ?? ''), 0) ?? 0;
|
||||
await api.post('/treasury/documents', {
|
||||
kind,
|
||||
title: form.value.title,
|
||||
amount: form.value.amount,
|
||||
amount,
|
||||
categoryId: form.value.categoryId || null,
|
||||
partyName: form.value.partyName || null,
|
||||
accountId: form.value.accountId || null,
|
||||
settleAmount: form.value.settleAmount || 0,
|
||||
settleAmount,
|
||||
method: form.value.method,
|
||||
reference: form.value.reference || null,
|
||||
notes: form.value.notes || null,
|
||||
@@ -243,18 +253,6 @@ onMounted(() => {
|
||||
<!-- ─── Mobile app experience ─── -->
|
||||
<template v-if="isMobile">
|
||||
<a-flex vertical :gap="token.margin">
|
||||
<div>
|
||||
<a-flex align="center" :gap="token.marginXS">
|
||||
<a-typography-title :level="3" :style="{ margin: 0, flex: 1 }">
|
||||
ثبت دریافت جدید
|
||||
</a-typography-title>
|
||||
<ArrowLeftOutlined :style="{ color: token.colorTextSecondary, fontSize: '18px' }" />
|
||||
</a-flex>
|
||||
<a-typography-text type="secondary">اطلاعات دریافت را وارد کنید</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-row :gutter="[12, 12]">
|
||||
<a-col :span="12">
|
||||
<a-card
|
||||
@@ -418,14 +416,7 @@ onMounted(() => {
|
||||
name="amount"
|
||||
:rules="[{ required: true, message: 'مبلغ کل را وارد کنید' }]"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="form.amount"
|
||||
inputmode="decimal"
|
||||
placeholder="۰"
|
||||
dir="ltr"
|
||||
>
|
||||
<template #prefix><NumberOutlined /></template>
|
||||
</a-input>
|
||||
<MoneyInput v-model="form.amount" :decimals="0" placeholder="۰" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
@@ -434,14 +425,7 @@ onMounted(() => {
|
||||
name="settleAmount"
|
||||
:rules="[{ required: true, message: 'مبلغ دریافتشده را وارد کنید' }]"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="form.settleAmount"
|
||||
inputmode="decimal"
|
||||
placeholder="۰"
|
||||
dir="ltr"
|
||||
>
|
||||
<template #prefix><NumberOutlined /></template>
|
||||
</a-input>
|
||||
<MoneyInput v-model="form.settleAmount" :decimals="0" placeholder="۰" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
@@ -596,35 +580,39 @@ onMounted(() => {
|
||||
<!-- ─── Desktop (unchanged interaction model) ─── -->
|
||||
<template v-else>
|
||||
<a-flex vertical :gap="16">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">{{ pageTitle }}</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
ثبت سند، موجودی را عوض نمیکند مگر مبلغ دریافت یا پرداخت واقعی وارد شود.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
<a-alert v-if="ok" type="success" show-icon :message="ok" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-divider orientation="right">سند جدید</a-divider>
|
||||
<a-form layout="vertical" @finish="createDoc">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="form"
|
||||
@finish="createDoc"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="عنوان" name="title">
|
||||
<a-form-item
|
||||
label="عنوان"
|
||||
name="title"
|
||||
:rules="[{ required: true, message: 'عنوان الزامی است' }]"
|
||||
>
|
||||
<a-input v-model:value="form.title" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مبلغ کل" name="amount">
|
||||
<a-input v-model:value="form.amount" />
|
||||
<a-form-item
|
||||
label="مبلغ کل"
|
||||
name="amount"
|
||||
:rules="[{ required: true, message: 'مبلغ الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="form.amount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item :label="settleLabel" name="settleAmount">
|
||||
<a-input v-model:value="form.settleAmount" />
|
||||
<MoneyInput v-model="form.settleAmount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from 'vue';
|
||||
import { RouterView, useRoute } from 'vue-router';
|
||||
import { Flex as AFlex, Typography, theme } from 'ant-design-vue';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import { provideTreasuryPageChrome } from './treasuryPageChrome';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { token } = theme.useToken();
|
||||
const route = useRoute();
|
||||
const chrome = provideTreasuryPageChrome();
|
||||
|
||||
watch(
|
||||
() => route.fullPath,
|
||||
() => {
|
||||
chrome.clear();
|
||||
const scroller = document.querySelector('main.content');
|
||||
if (scroller instanceof HTMLElement) scroller.scrollTop = 0;
|
||||
},
|
||||
);
|
||||
|
||||
const title = computed(
|
||||
() =>
|
||||
chrome.override.value.title ??
|
||||
(typeof route.meta.treasuryTitle === 'string' ? route.meta.treasuryTitle : 'مدیریت مالی'),
|
||||
);
|
||||
|
||||
const description = computed(
|
||||
() =>
|
||||
chrome.override.value.description ??
|
||||
(typeof route.meta.treasuryDescription === 'string' ? route.meta.treasuryDescription : ''),
|
||||
);
|
||||
|
||||
/** Keep title+subtitle block height stable across tabs (one-line subtitle). */
|
||||
const headerStyle = computed(() => ({
|
||||
minHeight: `${token.value.controlHeightLG + token.value.fontSizeLG + token.value.marginXXS}px`,
|
||||
}));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-flex vertical :gap="token.margin" :style="{ width: '100%' }">
|
||||
<div :style="headerStyle">
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">{{ title }}</a-typography-title>
|
||||
<a-typography-text
|
||||
type="secondary"
|
||||
:ellipsis="description ? { tooltip: description } : false"
|
||||
:style="{ display: 'block', margin: 0 }"
|
||||
>
|
||||
{{ description || '\u00a0' }}
|
||||
</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<RouterView />
|
||||
</a-flex>
|
||||
</template>
|
||||
@@ -16,13 +16,15 @@ import {
|
||||
Row as ARow,
|
||||
Select as ASelect,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import type { FinancialAccountDto, OrgUserDto } from '@mento/shared';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import { toman } from './treasury-format';
|
||||
import { parseMoneyNumber } from '@/lib/money';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
const ASelectOption = ASelect.Option;
|
||||
@@ -41,8 +43,16 @@ const users = ref<OrgUserDto[]>([]);
|
||||
const accounts = ref<FinancialAccountDto[]>([]);
|
||||
const error = ref('');
|
||||
const ok = ref('');
|
||||
const form = ref({ userId: '', period: '', baseAmount: '', benefits: '', bonus: '', deductions: '' });
|
||||
const pay = ref({ id: '', amount: '', accountId: '' });
|
||||
const saving = ref(false);
|
||||
const form = ref({
|
||||
userId: undefined as string | undefined,
|
||||
period: '',
|
||||
baseAmount: '',
|
||||
benefits: '',
|
||||
bonus: '',
|
||||
deductions: '',
|
||||
});
|
||||
const pay = ref({ id: '', amount: '', accountId: undefined as string | undefined });
|
||||
|
||||
function apiMessage(e: unknown) {
|
||||
if (!axios.isAxiosError(e)) return 'عملیات ناموفق بود.';
|
||||
@@ -50,6 +60,10 @@ function apiMessage(e: unknown) {
|
||||
return Array.isArray(msg) ? msg.join('، ') : msg || 'عملیات ناموفق بود.';
|
||||
}
|
||||
|
||||
function onFinishFailed() {
|
||||
message.warning('لطفاً فیلدهای الزامی را کامل کنید.');
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const [payroll, people, acc] = await Promise.all([
|
||||
api.get<PayrollRow[]>('/treasury/payroll'),
|
||||
@@ -63,33 +77,66 @@ async function load() {
|
||||
|
||||
async function createRow() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
saving.value = true;
|
||||
try {
|
||||
await api.post('/treasury/payroll', form.value);
|
||||
const baseAmount = parseMoneyNumber(String(form.value.baseAmount ?? ''), 0) ?? 0;
|
||||
await api.post('/treasury/payroll', {
|
||||
userId: form.value.userId,
|
||||
period: form.value.period,
|
||||
baseAmount,
|
||||
benefits: parseMoneyNumber(String(form.value.benefits ?? ''), 0) ?? 0,
|
||||
bonus: parseMoneyNumber(String(form.value.bonus ?? ''), 0) ?? 0,
|
||||
deductions: parseMoneyNumber(String(form.value.deductions ?? ''), 0) ?? 0,
|
||||
});
|
||||
form.value = {
|
||||
userId: undefined,
|
||||
period: '',
|
||||
baseAmount: '',
|
||||
benefits: '',
|
||||
bonus: '',
|
||||
deductions: '',
|
||||
};
|
||||
ok.value = 'حقوق ثبت شد و تا پرداخت، موجودی حساب تغییر نمیکند.';
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiMessage(e);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function payRow() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
saving.value = true;
|
||||
try {
|
||||
const amount = parseMoneyNumber(String(pay.value.amount ?? ''), 0);
|
||||
if (amount == null || amount <= 0) {
|
||||
error.value = 'مبلغ پرداخت معتبر نیست.';
|
||||
return;
|
||||
}
|
||||
await api.post(`/treasury/payroll/${pay.value.id}/pay`, {
|
||||
amount: pay.value.amount,
|
||||
amount,
|
||||
accountId: pay.value.accountId,
|
||||
clientKey: crypto.randomUUID(),
|
||||
});
|
||||
ok.value = 'پرداخت حقوق از حساب ثبت شد.';
|
||||
pay.value = { id: '', amount: '', accountId: '' };
|
||||
pay.value = { id: '', amount: '', accountId: undefined };
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = apiMessage(e);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function startPay(row: PayrollRow) {
|
||||
pay.value = { id: row.id, amount: row.remaining, accountId: accounts.value[0]?.id || '' };
|
||||
pay.value = {
|
||||
id: row.id,
|
||||
amount: row.remaining,
|
||||
accountId: accounts.value[0]?.id,
|
||||
};
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -100,26 +147,31 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a-flex vertical :gap="16">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">حقوق و دستمزد</a-typography-title>
|
||||
<a-typography-text type="secondary">فقط مالک و مدیر این صفحه را میبینند.</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
<a-alert v-if="ok" type="success" show-icon :message="ok" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-divider orientation="right">ثبت دوره</a-divider>
|
||||
<a-form layout="vertical" @finish="createRow">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="form"
|
||||
@finish="createRow"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="پرسنل" name="userId">
|
||||
<a-select v-model:value="form.userId" style="width: 100%" placeholder="انتخاب">
|
||||
<a-select-option value="">انتخاب</a-select-option>
|
||||
<a-form-item
|
||||
label="پرسنل"
|
||||
name="userId"
|
||||
:rules="[{ required: true, message: 'پرسنل الزامی است' }]"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="form.userId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="انتخاب"
|
||||
>
|
||||
<a-select-option v-for="user in users" :key="user.id" :value="user.id">
|
||||
{{ user.fullName }}
|
||||
</a-select-option>
|
||||
@@ -127,54 +179,84 @@ onMounted(() => {
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="دوره" name="period">
|
||||
<a-form-item
|
||||
label="دوره"
|
||||
name="period"
|
||||
:rules="[{ required: true, message: 'دوره الزامی است' }]"
|
||||
>
|
||||
<a-input v-model:value="form.period" placeholder="۱۴۰۵-۰۷" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="پایه" name="baseAmount">
|
||||
<a-input v-model:value="form.baseAmount" />
|
||||
<a-form-item
|
||||
label="پایه"
|
||||
name="baseAmount"
|
||||
:rules="[{ required: true, message: 'مبلغ پایه الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="form.baseAmount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مزایا" name="benefits">
|
||||
<a-input v-model:value="form.benefits" />
|
||||
<MoneyInput v-model="form.benefits" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="پاداش" name="bonus">
|
||||
<a-input v-model:value="form.bonus" />
|
||||
<MoneyInput v-model="form.bonus" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="کسورات" name="deductions">
|
||||
<a-input v-model:value="form.deductions" />
|
||||
<MoneyInput v-model="form.deductions" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-button type="primary" html-type="submit">ثبت حقوق</a-button>
|
||||
<a-button type="primary" html-type="submit" :loading="saving">ثبت حقوق</a-button>
|
||||
</a-form>
|
||||
|
||||
<template v-if="pay.id">
|
||||
<a-divider orientation="right">پرداخت حقوق</a-divider>
|
||||
<a-form layout="vertical" @finish="payRow">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="pay"
|
||||
@finish="payRow"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مبلغ" name="amount">
|
||||
<a-input v-model:value="pay.amount" />
|
||||
<a-form-item
|
||||
label="مبلغ"
|
||||
name="amount"
|
||||
:rules="[{ required: true, message: 'مبلغ الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="pay.amount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="حساب" name="accountId">
|
||||
<a-select v-model:value="pay.accountId" style="width: 100%">
|
||||
<a-select-option v-for="account in accounts" :key="account.id" :value="account.id">
|
||||
<a-form-item
|
||||
label="حساب"
|
||||
name="accountId"
|
||||
:rules="[{ required: true, message: 'حساب الزامی است' }]"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="pay.accountId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="انتخاب حساب"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="account in accounts"
|
||||
:key="account.id"
|
||||
:value="account.id"
|
||||
>
|
||||
{{ account.name }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-button type="primary" html-type="submit">ثبت پرداخت</a-button>
|
||||
<a-button type="primary" html-type="submit" :loading="saving">ثبت پرداخت</a-button>
|
||||
</a-form>
|
||||
</template>
|
||||
|
||||
@@ -203,6 +285,5 @@ onMounted(() => {
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -19,15 +19,18 @@ import {
|
||||
Table as ATable,
|
||||
Tag as ATag,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import type { TableColumnsType } from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import type { FinancialAccountDto, FinancialReceivableDto } from '@mento/shared';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import { toman } from './treasury-format';
|
||||
import { formatJalaliNumeric } from '@/lib/jalali';
|
||||
import { parseMoneyNumber } from '@/lib/money';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const ASelectOption = ASelect.Option;
|
||||
|
||||
type InstallmentRow = FinancialReceivableDto['installments'][number];
|
||||
@@ -109,19 +112,35 @@ async function downloadExcel() {
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function onFinishFailed() {
|
||||
message.warning('لطفاً فیلدهای الزامی را کامل کنید.');
|
||||
}
|
||||
|
||||
async function createContract() {
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
try {
|
||||
const totalAmount = parseMoneyNumber(String(form.value.totalAmount ?? ''), 0);
|
||||
if (totalAmount == null || totalAmount <= 0) {
|
||||
error.value = 'مبلغ کل معتبر نیست.';
|
||||
return;
|
||||
}
|
||||
const prepaidAmount = parseMoneyNumber(String(form.value.prepaidAmount ?? ''), 0) ?? 0;
|
||||
const installments = custom.value
|
||||
? customLines.value.map((line) => ({
|
||||
amount: parseMoneyNumber(String(line.amount ?? ''), 0) ?? 0,
|
||||
dueDate: line.dueDate,
|
||||
}))
|
||||
: undefined;
|
||||
await api.post('/treasury/receivables', {
|
||||
title: form.value.title,
|
||||
partyName: form.value.partyName || null,
|
||||
totalAmount: form.value.totalAmount,
|
||||
prepaidAmount: form.value.prepaidAmount || 0,
|
||||
totalAmount,
|
||||
prepaidAmount,
|
||||
accountId: form.value.accountId || null,
|
||||
...(custom.value
|
||||
? { installments: customLines.value }
|
||||
? { installments }
|
||||
: {
|
||||
count: Number(form.value.count),
|
||||
interval: form.value.interval,
|
||||
@@ -145,8 +164,13 @@ async function collectInstallment() {
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const amount = parseMoneyNumber(String(collect.value.amount ?? ''), 0);
|
||||
if (amount == null || amount <= 0) {
|
||||
error.value = 'مبلغ دریافت معتبر نیست.';
|
||||
return;
|
||||
}
|
||||
await api.post(`/treasury/installments/${collect.value.installmentId}/collect`, {
|
||||
amount: collect.value.amount,
|
||||
amount,
|
||||
accountId: collect.value.accountId,
|
||||
clientKey: crypto.randomUUID(),
|
||||
});
|
||||
@@ -177,26 +201,25 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a-flex vertical :gap="16">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">اقساط و مطالبات</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
دریافت هر قسط فقط یک بار وارد حساب میشود و مانده همان قسط را کم میکند.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
<a-alert v-if="ok" type="success" show-icon :message="ok" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-divider orientation="right">قرارداد جدید</a-divider>
|
||||
<a-form layout="vertical" @finish="createContract">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="form"
|
||||
@finish="createContract"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="عنوان" name="title">
|
||||
<a-form-item
|
||||
label="عنوان"
|
||||
name="title"
|
||||
:rules="[{ required: true, message: 'عنوان الزامی است' }]"
|
||||
>
|
||||
<a-input v-model:value="form.title" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
@@ -206,19 +229,27 @@ onMounted(() => {
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مبلغ کل" name="totalAmount">
|
||||
<a-input v-model:value="form.totalAmount" />
|
||||
<a-form-item
|
||||
label="مبلغ کل"
|
||||
name="totalAmount"
|
||||
:rules="[{ required: true, message: 'مبلغ کل الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="form.totalAmount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="پیشپرداخت" name="prepaidAmount">
|
||||
<a-input v-model:value="form.prepaidAmount" />
|
||||
<MoneyInput v-model="form.prepaidAmount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="حساب پیشپرداخت" name="accountId">
|
||||
<a-select v-model:value="form.accountId" allow-clear style="width: 100%" placeholder="انتخاب">
|
||||
<a-select-option value="">انتخاب</a-select-option>
|
||||
<a-select
|
||||
v-model:value="form.accountId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="انتخاب"
|
||||
>
|
||||
<a-select-option v-for="account in accounts" :key="account.id" :value="account.id">
|
||||
{{ account.name }}
|
||||
</a-select-option>
|
||||
@@ -240,7 +271,7 @@ onMounted(() => {
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="شروع" name="startDate">
|
||||
<a-input v-model:value="form.startDate" type="date" :disabled="custom" style="width: 100%" />
|
||||
<JalaliDateInput v-model="form.startDate" :disabled="custom" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24">
|
||||
@@ -254,12 +285,12 @@ onMounted(() => {
|
||||
<a-row v-for="(line, index) in customLines" :key="index" :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item :label="`مبلغ قسط ${index + 1}`">
|
||||
<a-input v-model:value="line.amount" />
|
||||
<MoneyInput v-model="line.amount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="سررسید">
|
||||
<a-input v-model:value="line.dueDate" type="date" style="width: 100%" />
|
||||
<JalaliDateInput v-model="line.dueDate" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
@@ -276,17 +307,39 @@ onMounted(() => {
|
||||
|
||||
<template v-if="collect.installmentId">
|
||||
<a-divider orientation="right">دریافت قسط</a-divider>
|
||||
<a-form layout="vertical" @finish="collectInstallment">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="collect"
|
||||
@finish="collectInstallment"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مبلغ" name="amount">
|
||||
<a-input v-model:value="collect.amount" />
|
||||
<a-form-item
|
||||
label="مبلغ"
|
||||
name="amount"
|
||||
:rules="[{ required: true, message: 'مبلغ الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="collect.amount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="حساب مقصد" name="accountId">
|
||||
<a-select v-model:value="collect.accountId" style="width: 100%">
|
||||
<a-select-option v-for="account in accounts" :key="account.id" :value="account.id">
|
||||
<a-form-item
|
||||
label="حساب مقصد"
|
||||
name="accountId"
|
||||
:rules="[{ required: true, message: 'حساب الزامی است' }]"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="collect.accountId"
|
||||
allow-clear
|
||||
style="width: 100%"
|
||||
placeholder="انتخاب حساب"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="account in accounts"
|
||||
:key="account.id"
|
||||
:value="account.id"
|
||||
>
|
||||
{{ account.name }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
@@ -337,6 +390,5 @@ onMounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -16,21 +16,33 @@ import {
|
||||
Row as ARow,
|
||||
Select as ASelect,
|
||||
Typography,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import { toman } from './treasury-format';
|
||||
import { formatJalaliNumeric } from '@/lib/jalali';
|
||||
import { parseMoneyNumber } from '@/lib/money';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
const ASelectOption = ASelect.Option;
|
||||
|
||||
type Row = { id: string; title: string; kind: string; amount: string; interval: string; nextDue: string; isActive: boolean };
|
||||
type Row = {
|
||||
id: string;
|
||||
title: string;
|
||||
kind: string;
|
||||
amount: string;
|
||||
interval: string;
|
||||
nextDue: string;
|
||||
isActive: boolean;
|
||||
};
|
||||
const rows = ref<Row[]>([]);
|
||||
const error = ref('');
|
||||
const ok = ref('');
|
||||
const saving = ref(false);
|
||||
const form = ref({ title: '', kind: 'expense', amount: '', interval: 'monthly', startDate: '' });
|
||||
|
||||
async function load() {
|
||||
@@ -38,16 +50,34 @@ async function load() {
|
||||
rows.value = data;
|
||||
}
|
||||
|
||||
function onFinishFailed() {
|
||||
message.warning('لطفاً فیلدهای الزامی را کامل کنید.');
|
||||
}
|
||||
|
||||
async function createItem() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
saving.value = true;
|
||||
try {
|
||||
await api.post('/treasury/recurring', form.value);
|
||||
const amount = parseMoneyNumber(String(form.value.amount ?? ''), 0);
|
||||
if (amount == null || amount <= 0) {
|
||||
error.value = 'مبلغ معتبر نیست.';
|
||||
return;
|
||||
}
|
||||
await api.post('/treasury/recurring', {
|
||||
...form.value,
|
||||
amount,
|
||||
startDate: form.value.startDate || undefined,
|
||||
});
|
||||
form.value = { title: '', kind: 'expense', amount: '', interval: 'monthly', startDate: '' };
|
||||
ok.value = 'الگو ثبت شد. در سررسید فقط سند باز ساخته میشود.';
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = axios.isAxiosError(e)
|
||||
? String((e.response?.data as { message?: string })?.message ?? 'ثبت ناموفق بود.')
|
||||
: 'ثبت ناموفق بود.';
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,31 +87,30 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a-flex vertical :gap="16">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">درآمد و هزینه تکرارشونده</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
تا تأیید دریافت یا پرداخت، موجودی حساب عوض نمیشود.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-flex vertical :gap="16">
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
<a-alert v-if="ok" type="success" show-icon :message="ok" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
<a-divider orientation="right">الگوی جدید</a-divider>
|
||||
<a-form layout="vertical" @finish="createItem">
|
||||
<a-form
|
||||
layout="vertical"
|
||||
:model="form"
|
||||
@finish="createItem"
|
||||
@finishFailed="onFinishFailed"
|
||||
>
|
||||
<a-row :gutter="[16, 0]">
|
||||
<a-col :xs="24" :md="12">
|
||||
<a-form-item label="عنوان" name="title">
|
||||
<a-form-item
|
||||
label="عنوان"
|
||||
name="title"
|
||||
:rules="[{ required: true, message: 'عنوان الزامی است' }]"
|
||||
>
|
||||
<a-input v-model:value="form.title" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="نوع" name="kind">
|
||||
<a-form-item label="نوع" name="kind" :rules="[{ required: true }]">
|
||||
<a-select v-model:value="form.kind" style="width: 100%">
|
||||
<a-select-option value="expense">هزینه</a-select-option>
|
||||
<a-select-option value="income">درآمد</a-select-option>
|
||||
@@ -89,12 +118,16 @@ onMounted(() => {
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="مبلغ" name="amount">
|
||||
<a-input v-model:value="form.amount" />
|
||||
<a-form-item
|
||||
label="مبلغ"
|
||||
name="amount"
|
||||
:rules="[{ required: true, message: 'مبلغ الزامی است' }]"
|
||||
>
|
||||
<MoneyInput v-model="form.amount" :decimals="0" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="دوره" name="interval">
|
||||
<a-form-item label="دوره" name="interval" :rules="[{ required: true }]">
|
||||
<a-select v-model:value="form.interval" style="width: 100%">
|
||||
<a-select-option value="monthly">ماهانه</a-select-option>
|
||||
<a-select-option value="weekly">هفتگی</a-select-option>
|
||||
@@ -104,11 +137,11 @@ onMounted(() => {
|
||||
</a-col>
|
||||
<a-col :xs="24" :md="8">
|
||||
<a-form-item label="شروع" name="startDate">
|
||||
<a-input v-model:value="form.startDate" type="date" style="width: 100%" />
|
||||
<JalaliDateInput v-model="form.startDate" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-button type="primary" html-type="submit">ثبت الگو</a-button>
|
||||
<a-button type="primary" html-type="submit" :loading="saving">ثبت الگو</a-button>
|
||||
</a-form>
|
||||
|
||||
<a-divider orientation="right">فهرست الگوها</a-divider>
|
||||
@@ -131,6 +164,5 @@ onMounted(() => {
|
||||
</template>
|
||||
</a-list>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -14,10 +14,9 @@ import {
|
||||
import type { TableColumnsType } from 'ant-design-vue';
|
||||
import { DownloadOutlined } from '@ant-design/icons-vue';
|
||||
import { api } from '@/lib/api';
|
||||
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
|
||||
import { toman } from './treasury-format';
|
||||
|
||||
const { Title: ATypographyTitle, Text: ATypographyText } = Typography;
|
||||
const { Text: ATypographyText } = Typography;
|
||||
const AListItem = AList.Item;
|
||||
const AListItemMeta = AList.Item.Meta;
|
||||
|
||||
@@ -100,23 +99,14 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<a-flex vertical :gap="16">
|
||||
<a-flex justify="space-between" align="center" wrap="wrap" :gap="12">
|
||||
<div>
|
||||
<a-typography-title :level="3" :style="{ margin: 0 }">گزارش مالی</a-typography-title>
|
||||
<a-typography-text type="secondary">
|
||||
سود عملیاتی از درآمد و هزینه ثبتشده است، نه از خالص وجه.
|
||||
</a-typography-text>
|
||||
</div>
|
||||
<a-flex vertical :gap="16">
|
||||
<a-flex justify="flex-end">
|
||||
<a-button @click="download">
|
||||
<template #icon><DownloadOutlined /></template>
|
||||
خروجی اکسل
|
||||
</a-button>
|
||||
</a-flex>
|
||||
|
||||
<TreasuryNav />
|
||||
|
||||
<a-alert v-if="error" type="error" show-icon :message="error" />
|
||||
|
||||
<a-card :bordered="false">
|
||||
@@ -179,6 +169,5 @@ onMounted(() => {
|
||||
</a-list>
|
||||
</template>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { inject, provide, ref, type InjectionKey, type Ref } from 'vue';
|
||||
|
||||
export type TreasuryChromeOverride = {
|
||||
title: string | null;
|
||||
description: string | null;
|
||||
};
|
||||
|
||||
type TreasuryChromeApi = {
|
||||
override: Ref<TreasuryChromeOverride>;
|
||||
set: (next: TreasuryChromeOverride) => void;
|
||||
clear: () => void;
|
||||
};
|
||||
|
||||
const KEY: InjectionKey<TreasuryChromeApi> = Symbol('treasuryPageChrome');
|
||||
|
||||
export function provideTreasuryPageChrome(): TreasuryChromeApi {
|
||||
const override = ref<TreasuryChromeOverride>({ title: null, description: null });
|
||||
const api: TreasuryChromeApi = {
|
||||
override,
|
||||
set(next) {
|
||||
override.value = next;
|
||||
},
|
||||
clear() {
|
||||
override.value = { title: null, description: null };
|
||||
},
|
||||
};
|
||||
provide(KEY, api);
|
||||
return api;
|
||||
}
|
||||
|
||||
export function useTreasuryPageChrome(): TreasuryChromeApi | null {
|
||||
return inject(KEY, null);
|
||||
}
|
||||
Reference in New Issue
Block a user