138 lines
3.9 KiB
Vue
138 lines
3.9 KiB
Vue
<script setup lang="ts">
|
|||
|
|
import { computed } from 'vue';
|
||
|
|
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||
|
|
import { UiButton, UiField, UiModal, UiTextarea } from '@/components/ui';
|
||
|
|
import type { RoutineTaskActions } from '@/lib/useRoutineTaskActions';
|
||
|
|
|
||
|
|
const props = defineProps<{ actions: RoutineTaskActions }>();
|
||
|
|
|
||
|
|
const modal = computed(() => props.actions.modal);
|
||
|
|
|
||
|
|
const title = computed(() => {
|
||
|
|
switch (modal.value.kind) {
|
||
|
|
case 'complete':
|
||
|
|
return modal.value.task?.status === 'completed' ? 'گزارش نتیجه' : 'ثبت انجام کار';
|
||
|
|
case 'skip':
|
||
|
|
return 'رد کردن کار';
|
||
|
|
case 'reschedule':
|
||
|
|
return 'تغییر زمان کار';
|
||
|
|
case 'cancel':
|
||
|
|
return 'لغو کار';
|
||
|
|
default:
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
const noteRequired = computed(() => {
|
||
|
|
const t = modal.value.task;
|
||
|
|
if (!t) return false;
|
||
|
|
if (modal.value.kind === 'complete') return t.rules.reportRequired;
|
||
|
|
if (modal.value.kind === 'skip') return t.rules.skipReasonRequired;
|
||
|
|
return false;
|
||
|
|
});
|
||
|
|
|
||
|
|
const noteLabel = computed(() => {
|
||
|
|
if (modal.value.kind === 'complete') return 'نتیجه / گزارش';
|
||
|
|
if (modal.value.kind === 'skip') return 'دلیل رد کردن';
|
||
|
|
return 'توضیح (اختیاری)';
|
||
|
|
});
|
||
|
|
|
||
|
|
const placeholder = computed(() => {
|
||
|
|
if (modal.value.kind === 'complete') return 'مثلاً: با مشتری تماس گرفته شد و قرار جلسه برای فردا تنظیم شد.';
|
||
|
|
if (modal.value.kind === 'skip') return 'چرا این کار امروز انجام نمیشود؟';
|
||
|
|
return '';
|
||
|
|
});
|
||
|
|
|
||
|
|
const submitLabel = computed(() => {
|
||
|
|
switch (modal.value.kind) {
|
||
|
|
case 'complete':
|
||
|
|
return modal.value.task?.status === 'completed' ? 'ذخیره گزارش' : 'انجام شد';
|
||
|
|
case 'skip':
|
||
|
|
return 'رد کردن';
|
||
|
|
case 'reschedule':
|
||
|
|
return 'ذخیره زمان جدید';
|
||
|
|
case 'cancel':
|
||
|
|
return 'لغو کار';
|
||
|
|
default:
|
||
|
|
return 'ذخیره';
|
||
|
|
}
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<template>
|
||
|
|
<UiModal :open="!!modal.kind" :title="title" nest @close="actions.close()">
|
||
|
|
<form class="rt-modal" @submit.prevent="actions.submit()">
|
||
|
|
<p v-if="modal.task" class="task-name">{{ modal.task.title }}</p>
|
||
|
|
|
||
|
|
<template v-if="modal.kind === 'reschedule'">
|
||
|
|
<div class="when">
|
||
|
|
<UiField label="تاریخ" required>
|
||
|
|
<JalaliDateInput v-model="modal.date" mode="date" required :clearable="false" />
|
||
|
|
</UiField>
|
||
|
|
<UiField label="ساعت" hint="خالی = تا پایان روز">
|
||
|
|
<JalaliDateInput v-model="modal.time" mode="time" />
|
||
|
|
</UiField>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<UiField v-else :label="noteLabel" :required="noteRequired">
|
||
|
|
<UiTextarea v-model="modal.note" :rows="4" :placeholder="placeholder" :maxlength="2000" />
|
||
|
|
</UiField>
|
||
|
|
|
||
|
|
<p v-if="modal.kind === 'cancel'" class="hint">
|
||
|
|
کار لغو شده در محاسبه درصد انجام حساب نمیشود.
|
||
|
|
</p>
|
||
|
|
<p v-if="modal.error" class="error">{{ modal.error }}</p>
|
||
|
|
</form>
|
||
|
|
|
||
|
|
<template #footer>
|
||
|
|
<UiButton
|
||
|
|
:variant="modal.kind === 'cancel' ? 'danger' : modal.kind === 'complete' ? 'success' : 'primary'"
|
||
|
|
:loading="modal.saving"
|
||
|
|
@click="actions.submit()"
|
||
|
|
>
|
||
|
|
{{ submitLabel }}
|
||
|
|
</UiButton>
|
||
|
|
<UiButton variant="ghost" @click="actions.close()">انصراف</UiButton>
|
||
|
|
</template>
|
||
|
|
</UiModal>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<style scoped>
|
||
|
|
.rt-modal {
|
||
|
|
display: grid;
|
||
|
|
gap: var(--sp-4);
|
||
|
|
}
|
||
|
|
|
||
|
|
.task-name {
|
||
|
|
margin: 0;
|
||
|
|
padding: var(--sp-2) var(--sp-3);
|
||
|
|
border-radius: var(--radius);
|
||
|
|
background: var(--surface-subtle);
|
||
|
|
font-weight: var(--fw-semibold);
|
||
|
|
color: var(--ink);
|
||
|
|
}
|
||
|
|
|
||
|
|
.when {
|
||
|
|
display: grid;
|
||
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||
|
|
gap: var(--sp-3);
|
||
|
|
}
|
||
|
|
|
||
|
|
.hint {
|
||
|
|
margin: 0;
|
||
|
|
font-size: var(--fs-xs);
|
||
|
|
color: var(--muted);
|
||
|
|
}
|
||
|
|
|
||
|
|
.error {
|
||
|
|
margin: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
@media (max-width: 600px) {
|
||
|
|
.when {
|
||
|
|
grid-template-columns: 1fr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</style>
|