Automate role and filter req after load modal
This commit is contained in:
parent
5839d8e1be
commit
686f70f5a5
@ -22,7 +22,7 @@
|
|||||||
<label>Укажите сторону 1:</label>
|
<label>Укажите сторону 1:</label>
|
||||||
<Select
|
<Select
|
||||||
v-model="deal.side_one"
|
v-model="deal.side_one"
|
||||||
:options="deal_sides_list"
|
:options="selectedRequisitionSideOne ? sideOneOptions : fullSidesList"
|
||||||
:class="{ 'p-invalid': errors.side_one }"
|
:class="{ 'p-invalid': errors.side_one }"
|
||||||
>
|
>
|
||||||
<template #dropdownicon>
|
<template #dropdownicon>
|
||||||
@ -32,20 +32,13 @@
|
|||||||
<small v-if="errors.side_one" class="p-error">{{ errorMessages.side_one }}</small>
|
<small v-if="errors.side_one" class="p-error">{{ errorMessages.side_one }}</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
||||||
<label>Выберите заявку:</label>
|
<label>Заявка стороны 1:</label>
|
||||||
<Select
|
<InputText
|
||||||
v-model="selectedRequisitionSideOneId"
|
v-if="selectedRequisitionSideOne"
|
||||||
:options="requisitionsList"
|
:value="selectedRequisitionSideOne.name"
|
||||||
optionLabel="name"
|
disabled
|
||||||
optionValue="id"
|
class="w-full bg-gray-100"
|
||||||
placeholder="Выберите заявку"
|
/>
|
||||||
:filter="true"
|
|
||||||
:virtualScrollerOptions="{ itemSize: 40 }"
|
|
||||||
>
|
|
||||||
<template #dropdownicon>
|
|
||||||
<DropdownIcon />
|
|
||||||
</template>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
||||||
@ -78,7 +71,7 @@
|
|||||||
<label for="side2">Укажите сторону 2:</label>
|
<label for="side2">Укажите сторону 2:</label>
|
||||||
<Select
|
<Select
|
||||||
v-model="deal.side_two"
|
v-model="deal.side_two"
|
||||||
:options="deal_sides_list"
|
:options="sideTwoOptions"
|
||||||
:class="{ 'p-invalid': errors.side_two }"
|
:class="{ 'p-invalid': errors.side_two }"
|
||||||
>
|
>
|
||||||
<template #dropdownicon>
|
<template #dropdownicon>
|
||||||
@ -88,7 +81,7 @@
|
|||||||
<small v-if="errors.side_two" class="p-error">{{ errorMessages.side_two }}</small>
|
<small v-if="errors.side_two" class="p-error">{{ errorMessages.side_two }}</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
<div class="form__item flex flex-col gap-1 w-full mb-3">
|
||||||
<label>Выберите заявку:</label>
|
<label>Заявка стороны 2:</label>
|
||||||
<Select
|
<Select
|
||||||
v-model="selectedRequisitionSideTwoId"
|
v-model="selectedRequisitionSideTwoId"
|
||||||
:options="requisitionsList"
|
:options="requisitionsList"
|
||||||
@ -410,11 +403,11 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import MyButton from "@/shared/UI/MyButton.vue";
|
import MyButton from "@/shared/UI/MyButton.vue";
|
||||||
import {ref, onMounted, watch, inject, toRaw, markRaw} from "vue";
|
import {computed, inject, onMounted, ref, watch} from "vue";
|
||||||
import { useLaravelApi } from '@/composables/useLaravelApi';
|
import {useLaravelApi} from '@/composables/useLaravelApi';
|
||||||
//import useDeal from '@/composables/useDeal';
|
//import useDeal from '@/composables/useDeal';
|
||||||
import { useToast } from "primevue/usetoast";
|
import {useToast} from "primevue/usetoast";
|
||||||
import { useDialog } from 'primevue/usedialog';
|
import {useDialog} from 'primevue/usedialog';
|
||||||
import ConfirmDialog from 'primevue/confirmdialog';
|
import ConfirmDialog from 'primevue/confirmdialog';
|
||||||
import Toast from "primevue/toast";
|
import Toast from "primevue/toast";
|
||||||
import InputText from "primevue/inputtext";
|
import InputText from "primevue/inputtext";
|
||||||
@ -455,6 +448,8 @@ const newDealReqId = dialogRef.value.data?.newDealReqId;
|
|||||||
let dealId = null;
|
let dealId = null;
|
||||||
const isEditing = ref(false);
|
const isEditing = ref(false);
|
||||||
|
|
||||||
|
const isSideOneLoaded = ref(false);
|
||||||
|
|
||||||
const { data: dealData, fetchData: fetchDealData } = useLaravelApi();
|
const { data: dealData, fetchData: fetchDealData } = useLaravelApi();
|
||||||
const { data: employeesData, fetchData: fetchEmployeesData } = useLaravelApi();
|
const { data: employeesData, fetchData: fetchEmployeesData } = useLaravelApi();
|
||||||
const { data: requisitionsListData, fetchData: fetchRequisitionsListData } = useLaravelApi();
|
const { data: requisitionsListData, fetchData: fetchRequisitionsListData } = useLaravelApi();
|
||||||
@ -563,8 +558,10 @@ watch(() => newDealReqId, async (newVal) => {
|
|||||||
|
|
||||||
selectedRequisitionSideOneId.value = Number(newVal);
|
selectedRequisitionSideOneId.value = Number(newVal);
|
||||||
|
|
||||||
//ToDo роль
|
deal.value.side_one = getSideByRequisitionType(reqData.type_id, reqData.type_name);
|
||||||
//deal.value.side_one = 'Продавец';
|
|
||||||
|
isSideOneLoaded.value = true;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка загрузки заявки:', error);
|
console.error('Ошибка загрузки заявки:', error);
|
||||||
showError('Не удалось загрузить заявку');
|
showError('Не удалось загрузить заявку');
|
||||||
@ -823,12 +820,23 @@ onMounted(async () => {
|
|||||||
|
|
||||||
const reqList = requisitions.data?.data?.map(item => ({
|
const reqList = requisitions.data?.data?.map(item => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.name || `Заявка ${item.id}`
|
name: item.name || `Заявка ${item.id}`,
|
||||||
|
type_id: item.type_id
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
requisitionsList.value = reqList;
|
|
||||||
originalRequisitionsList.value = reqList;
|
originalRequisitionsList.value = reqList;
|
||||||
|
|
||||||
|
if (isSideOneLoaded) {
|
||||||
|
const sideOneTypeId = selectedRequisitionSideOne.value.type?.heir || selectedRequisitionSideOne.value.type_id;
|
||||||
|
if (sideOneTypeId === 2) {
|
||||||
|
requisitionsList.value = reqList.filter(req => req.type_id !== 2);
|
||||||
|
} else {
|
||||||
|
requisitionsList.value = reqList.filter(req => req.type_id === 2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
requisitionsList.value = reqList;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка загрузки:', error);
|
console.error('Ошибка загрузки:', error);
|
||||||
showError('Не удалось загрузить данные');
|
showError('Не удалось загрузить данные');
|
||||||
@ -859,7 +867,14 @@ watch(selectedRequisitionSideOneId, async (newId) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Получение деталей выбранной заявки 2 стороны
|
// Получение деталей выбранной заявки 2 стороны
|
||||||
watch(selectedRequisitionSideTwoId, async (newId) => {
|
watch(selectedRequisitionSideTwoId, async (newId, oldId) => {
|
||||||
|
|
||||||
|
if (oldId && newId !== oldId) {
|
||||||
|
selectedObjectSideTwoId.value = null;
|
||||||
|
selectedObjectSideTwo.value = null;
|
||||||
|
deal.value.side_two_object_id = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (newId) {
|
if (newId) {
|
||||||
await fetchRequisitionSideTwoDetails(`/requisitions/${newId}`);
|
await fetchRequisitionSideTwoDetails(`/requisitions/${newId}`);
|
||||||
if (requisitionSideTwoDetails.value) {
|
if (requisitionSideTwoDetails.value) {
|
||||||
@ -874,7 +889,6 @@ watch(selectedRequisitionSideTwoId, async (newId) => {
|
|||||||
deal.value.side_two_client_main = null;
|
deal.value.side_two_client_main = null;
|
||||||
}
|
}
|
||||||
console.log('Загружены основной клиент стороны 2:', deal.value.side_two_client_main);
|
console.log('Загружены основной клиент стороны 2:', deal.value.side_two_client_main);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
selectedRequisitionSideTwo.value = null;
|
selectedRequisitionSideTwo.value = null;
|
||||||
}
|
}
|
||||||
@ -1256,6 +1270,44 @@ const saveDeal = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSideByRequisitionType = (typeId) => {
|
||||||
|
if (typeId === 2) {
|
||||||
|
return 'Продавец';
|
||||||
|
}
|
||||||
|
return 'Покупатель';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Список сторон в зависимости от типа заявки
|
||||||
|
const sideOneOptions = computed(() => {
|
||||||
|
if (!selectedRequisitionSideOne.value) return [];
|
||||||
|
const typeId = selectedRequisitionSideOne.value.type_id;
|
||||||
|
if (typeId === 2) {
|
||||||
|
return ['Продавец', 'Арендодатель', 'Застройщик'];
|
||||||
|
}
|
||||||
|
return ['Покупатель', 'Арендатор'];
|
||||||
|
});
|
||||||
|
|
||||||
|
const sideTwoOptions = computed(() => {
|
||||||
|
const sideOne = deal.value.side_one;
|
||||||
|
|
||||||
|
if (!sideOne) return [];
|
||||||
|
|
||||||
|
// Если сторона 1 - продавец/арендодатель/застройщик
|
||||||
|
if (sideOne === 'Продавец' || sideOne === 'Арендодатель' || sideOne === 'Застройщик') {
|
||||||
|
return ['Покупатель', 'Арендатор'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если сторона 1 - покупатель/арендатор
|
||||||
|
if (sideOne === 'Покупатель' || sideOne === 'Арендатор') {
|
||||||
|
return ['Продавец', 'Арендодатель', 'Застройщик'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Полный список для случаев, когда заявка не выбрана
|
||||||
|
const fullSidesList = ['Покупатель', 'Продавец', 'Арендодатель', 'Арендатор', 'Застройщик'];
|
||||||
|
|
||||||
|
|
||||||
// Локальное состояние
|
// Локальное состояние
|
||||||
const isOpen = ref(props.isOpen);
|
const isOpen = ref(props.isOpen);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user