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