Fix clients side_one
This commit is contained in:
parent
101a778b5d
commit
933ddba195
@ -43,7 +43,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
||||
<RequisitionDetails v-if="selectedRequisitionSideOne" :deal="deal" :requisition="selectedRequisitionSideOne" :clientsList="clientsList" side="sideOne" @closeDealRequisition="handleCloseDealRequisition" />
|
||||
<RequisitionDetails v-if="selectedRequisitionSideOne" :deal="deal" :requisition="selectedRequisitionSideOne" :clientsList="clientsList" side="sideOne" @closeDealRequisition="handleCloseDealRequisition" @refreshClients="refreshClientsList" />
|
||||
</div>
|
||||
|
||||
<div class="form__item flex flex-col gap-1 w-full" v-if="selectedRequisitionSideOne && (selectedRequisitionSideOne.type?.heir || selectedRequisitionSideOne.type_id) === 2">
|
||||
@ -105,7 +105,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
||||
<RequisitionDetails v-if="selectedRequisitionSideTwo" :deal="deal" :requisition="selectedRequisitionSideTwo" :clientsList="clientsList" side="sideTwo" @closeDealRequisition="handleCloseDealRequisition" />
|
||||
<RequisitionDetails v-if="selectedRequisitionSideTwo" :deal="deal" :requisition="selectedRequisitionSideTwo" :clientsList="clientsList" side="sideTwo" @closeDealRequisition="handleCloseDealRequisition" @refreshClients="refreshClientsList" />
|
||||
</div>
|
||||
|
||||
<!-- Селект объекта скрыт, объект подтягивается из заявки
|
||||
@ -1250,6 +1250,21 @@ const handleCloseDealRequisition = (side) => {
|
||||
}
|
||||
};
|
||||
|
||||
const refreshClientsList = async () => {
|
||||
console.log('[DealModal] refreshClientsList — обновляем clientsList');
|
||||
try {
|
||||
const clientsRes = await fetchClientsListData('/clients?fields=short&no_pagination=1');
|
||||
if (clientsRes?.data?.data) {
|
||||
console.log('[DealModal] clientsList обновлён, количество:', clientsRes.data.data.length);
|
||||
clientsList.value = clientsRes.data.data;
|
||||
} else {
|
||||
console.warn('[DealModal] clientsRes:', clientsRes);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[DealModal] refreshClientsList error:', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Закрытие ObjectDetails
|
||||
const handleCloseDealObject = (side) => {
|
||||
if (side === 'sideOne') {
|
||||
|
||||
@ -128,7 +128,7 @@
|
||||
</MultiSelect>
|
||||
</div>
|
||||
<div class="ml-2">
|
||||
<a href="javascript:{}" class="add_client_new" style="border: none;">
|
||||
<a href="javascript:{}" class="add_client_new" style="border: none;" @click="onAddClientClick">
|
||||
<img src="@/shared/assets/icons/plus-green.svg" alt="Добавить клиента" class="w-6 h-6">
|
||||
</a>
|
||||
</div>
|
||||
@ -147,7 +147,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, onMounted, watch } from 'vue';
|
||||
import { computed, ref, onMounted, watch, nextTick } from 'vue';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import ru from 'dayjs/locale/ru';
|
||||
@ -173,25 +173,34 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['closeDealRequisition']); // Добавляем событие для закрытия
|
||||
const emit = defineEmits(['closeDealRequisition', 'refreshClients']);
|
||||
|
||||
const selectedClientIds = ref([]);
|
||||
let isUpdating = false;
|
||||
|
||||
onMounted(() => {
|
||||
if (props.side === 'sideOne' && props.deal.side_one_clients) {
|
||||
selectedClientIds.value = props.deal.side_one_clients.map(c => c.id);
|
||||
} else if (props.side === 'sideTwo' && props.deal.side_two_clients) {
|
||||
selectedClientIds.value = props.deal.side_two_clients.map(c => c.id);
|
||||
watch(() => props.deal.side_one_clients, (newVal) => {
|
||||
if (isUpdating) return;
|
||||
if (props.side === 'sideOne' && newVal) {
|
||||
selectedClientIds.value = newVal.map(c => c.id);
|
||||
}
|
||||
});
|
||||
}, { deep: true });
|
||||
|
||||
watch(() => props.deal.side_two_clients, (newVal) => {
|
||||
if (isUpdating) return;
|
||||
if (props.side === 'sideTwo' && newVal) {
|
||||
selectedClientIds.value = newVal.map(c => c.id);
|
||||
}
|
||||
}, { deep: true });
|
||||
|
||||
watch(selectedClientIds, (newIds) => {
|
||||
isUpdating = true;
|
||||
const selectedClients = props.clientsList.filter(c => newIds.includes(c.id));
|
||||
if (props.side === 'sideOne') {
|
||||
props.deal.side_one_clients = selectedClients;
|
||||
} else if (props.side === 'sideTwo') {
|
||||
props.deal.side_two_clients = selectedClients;
|
||||
}
|
||||
nextTick(() => { isUpdating = false; });
|
||||
});
|
||||
|
||||
// // Выбранные клиенты
|
||||
@ -246,6 +255,17 @@ const openHistoryClient = (clientId) => {
|
||||
}
|
||||
};
|
||||
|
||||
const onAddClientClick = () => {
|
||||
console.log('[RequisitionDetails] onAddClientClick — registruem listener deal:clientCreated');
|
||||
window.addEventListener('deal:clientCreated', function handler(e) {
|
||||
console.log('[RequisitionDetails] deal:clientCreated poluchen:', e.detail);
|
||||
window.removeEventListener('deal:clientCreated', handler);
|
||||
console.log('[RequisitionDetails] listener udalen, emit refreshClients');
|
||||
emit('refreshClients');
|
||||
});
|
||||
console.log('[RequisitionDetails] listener zaregistrirovan');
|
||||
};
|
||||
|
||||
|
||||
// Переменные для шагов
|
||||
const steps = ref([]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user