Fix clients side_two
This commit is contained in:
parent
933ddba195
commit
d7546d79d3
@ -178,28 +178,30 @@ const emit = defineEmits(['closeDealRequisition', 'refreshClients']);
|
|||||||
const selectedClientIds = ref([]);
|
const selectedClientIds = ref([]);
|
||||||
let isUpdating = false;
|
let isUpdating = false;
|
||||||
|
|
||||||
watch(() => props.deal.side_one_clients, (newVal) => {
|
const clientsKey = computed(() => props.side === 'sideOne' ? 'side_one_clients' : 'side_two_clients');
|
||||||
if (isUpdating) return;
|
|
||||||
if (props.side === 'sideOne' && newVal) {
|
|
||||||
selectedClientIds.value = newVal.map(c => c.id);
|
|
||||||
}
|
|
||||||
}, { deep: true });
|
|
||||||
|
|
||||||
watch(() => props.deal.side_two_clients, (newVal) => {
|
// При монтировании — если данные уже загружены, сразу синхронизируем
|
||||||
|
const currentData = props.deal[clientsKey.value];
|
||||||
|
if (currentData && Array.isArray(currentData) && currentData.length > 0) {
|
||||||
|
selectedClientIds.value = currentData.map(c => c.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => props.deal[clientsKey.value], (newVal) => {
|
||||||
if (isUpdating) return;
|
if (isUpdating) return;
|
||||||
if (props.side === 'sideTwo' && newVal) {
|
if (newVal && Array.isArray(newVal)) {
|
||||||
selectedClientIds.value = newVal.map(c => c.id);
|
const newIds = newVal.map(c => c.id);
|
||||||
|
if (newIds.length !== selectedClientIds.value.length || newIds.some((id, i) => id !== selectedClientIds.value[i])) {
|
||||||
|
selectedClientIds.value = newIds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, { deep: true });
|
}, { deep: true });
|
||||||
|
|
||||||
watch(selectedClientIds, (newIds) => {
|
watch(selectedClientIds, (newIds) => {
|
||||||
|
if (isUpdating) return;
|
||||||
isUpdating = true;
|
isUpdating = true;
|
||||||
const selectedClients = props.clientsList.filter(c => newIds.includes(c.id));
|
const selectedClients = props.clientsList.filter(c => newIds.includes(c.id));
|
||||||
if (props.side === 'sideOne') {
|
console.log(`[RequisitionDetails] ${props.side} watch selectedClientIds:`, newIds, '-> writing to deal.${clientsKey.value}');
|
||||||
props.deal.side_one_clients = selectedClients;
|
props.deal[clientsKey.value] = selectedClients;
|
||||||
} else if (props.side === 'sideTwo') {
|
|
||||||
props.deal.side_two_clients = selectedClients;
|
|
||||||
}
|
|
||||||
nextTick(() => { isUpdating = false; });
|
nextTick(() => { isUpdating = false; });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user