Files
CRM_Montzar/apps/web/src/components/pipeline/PipelineBoard.vue
T

248 lines
5.8 KiB
Vue

<script setup lang="ts">
import { nextTick, ref } from 'vue';
import UiIcon from '@/components/UiIcon.vue';
import PipelineColumn from './PipelineColumn.vue';
import type { PipelineDeal, PipelineStage, PipelineUiCopy } from '@/lib/pipeline-board';
import { DEAL_BOARD_COPY } from '@/lib/pipeline-board';
withDefaults(
defineProps<{
stages: PipelineStage[];
draggingId: string | null;
dropStageId: string | null;
canManage?: boolean;
copy?: PipelineUiCopy;
}>(),
{ copy: () => DEAL_BOARD_COPY },
);
const emit = defineEmits<{
dragStart: [deal: PipelineDeal, event: DragEvent];
dragEnd: [];
dragOver: [stageId: string, event: DragEvent];
drop: [stageId: string, event: DragEvent, index?: number];
addDeal: [stageId: string];
openDeal: [dealId: string];
menuDeal: [dealId: string];
renameStage: [stageId: string, title: string];
deleteStage: [stageId: string];
moveStage: [stageId: string, dir: -1 | 1];
columnDragStart: [stageId: string, event: DragEvent];
columnDragEnd: [];
addStage: [name: string];
loadMore: [stageId: string];
}>();
const adding = ref(false);
const newName = ref('');
const addInput = ref<HTMLInputElement | null>(null);
async function startAdd() {
adding.value = true;
newName.value = '';
await nextTick();
addInput.value?.focus();
}
function cancelAdd() {
adding.value = false;
newName.value = '';
}
function submitAdd() {
const name = newName.value.trim();
if (!name) return;
emit('addStage', name);
adding.value = false;
newName.value = '';
}
</script>
<template>
<div class="board-shell" dir="rtl">
<div class="board">
<PipelineColumn
v-for="(stage, index) in stages"
:key="stage.id"
:stage="stage"
:dragging-id="draggingId"
:drop-active="dropStageId === stage.id"
:can-manage="canManage"
:copy="copy"
:is-first="index === 0"
:is-last="index === stages.length - 1"
@drag-start="(d, e) => emit('dragStart', d, e)"
@drag-end="emit('dragEnd')"
@drag-over="(id, e) => emit('dragOver', id, e)"
@drop="(id, e, index) => emit('drop', id, e, index)"
@add-deal="emit('addDeal', $event)"
@open-deal="emit('openDeal', $event)"
@menu-deal="emit('menuDeal', $event)"
@rename="(id, title) => emit('renameStage', id, title)"
@delete="emit('deleteStage', $event)"
@move="(id, dir) => emit('moveStage', id, dir)"
@column-drag-start="(id, e) => emit('columnDragStart', id, e)"
@column-drag-end="emit('columnDragEnd')"
@load-more="emit('loadMore', $event)"
/>
<section v-if="canManage" class="add-col">
<form v-if="adding" class="add-form" @submit.prevent="submitAdd">
<input
ref="addInput"
v-model="newName"
maxlength="80"
placeholder="نام ستون جدید…"
aria-label="نام ستون جدید"
@keydown.esc.prevent="cancelAdd"
/>
<div class="add-actions">
<button class="ok" type="submit" :disabled="newName.trim().length < 1">
افزودن
</button>
<button class="cancel" type="button" @click="cancelAdd">انصراف</button>
</div>
</form>
<button v-else type="button" class="add-btn" @click="startAdd">
<UiIcon name="plus" :size="18" />
افزودن ستون
</button>
</section>
</div>
</div>
</template>
<style scoped>
.board-shell {
background: #fff;
border: 1px solid var(--line);
border-radius: var(--radius);
padding: var(--pad-modal);
min-width: 0;
}
.board {
display: flex;
flex-direction: row;
gap: 16px;
width: 100%;
min-width: 0;
max-width: 100%;
align-items: stretch;
overflow-x: auto;
overflow-y: hidden;
padding: 0.1rem 0.05rem 0.5rem;
touch-action: pan-x pan-y;
overscroll-behavior-x: contain;
-webkit-overflow-scrolling: touch;
scrollbar-width: thin;
scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent;
}
.board::-webkit-scrollbar {
height: 8px;
}
.board::-webkit-scrollbar-thumb {
background: color-mix(in srgb, var(--muted) 38%, transparent);
border-radius: 999px;
}
.add-col {
flex: 0 0 17.5rem;
min-width: 17.5rem;
min-height: 420px;
display: flex;
align-items: flex-start;
padding-top: 0.15rem;
}
.add-btn {
width: 100%;
min-height: 3.2rem;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.4rem;
border: 1.5px dashed var(--line);
border-radius: var(--radius);
background: #f8fafc;
color: var(--muted);
font: inherit;
font-weight: 700;
cursor: pointer;
}
.add-btn:hover {
border-color: var(--accent);
color: var(--accent-deep, #0f766e);
background: color-mix(in srgb, var(--accent) 6%, #fff);
}
.add-form {
width: 100%;
display: grid;
gap: 0.55rem;
padding: 0.75rem;
border: 1px solid var(--line);
border-radius: var(--radius);
background: #fff;
}
.add-form input {
width: 100%;
min-height: var(--control-h);
padding: 0 0.75rem;
border: 1px solid var(--line);
border-radius: var(--radius);
font: inherit;
}
.add-actions {
display: flex;
gap: 0.4rem;
}
.add-actions .ok,
.add-actions .cancel {
min-height: var(--control-h);
padding: 0 0.85rem;
border-radius: var(--radius);
font: inherit;
font-weight: 700;
cursor: pointer;
}
.add-actions .ok {
border: 0;
background: var(--accent);
color: #fff;
}
.add-actions .ok:disabled {
opacity: 0.5;
cursor: default;
}
.add-actions .cancel {
border: 1px solid var(--line);
background: #fff;
color: var(--ink);
}
@container pipeline (max-width: 720px) {
.board {
scroll-snap-type: x mandatory;
scroll-padding-inline: 0.25rem;
}
.add-col {
flex: 0 0 min(20rem, 86cqi);
width: min(20rem, 86cqi);
min-width: min(20rem, 86cqi);
min-height: 360px;
scroll-snap-align: start;
}
}
</style>