Files
kartoteka/resources/js/Pages/Home/ArchiveHistoryModal/Index.vue
2025-12-12 17:10:05 +09:00

190 lines
5.9 KiB
Vue

<script setup>
import { NModal, NDataTable, NSpace, NFlex, NButton, NForm, NFormItem, NInput, NDatePicker, NDivider, NSwitch, NTag } from 'naive-ui'
import ArchiveHistoryMoveModal from '../ArchiveHistoryMoveModal/Index.vue'
import {computed, ref, watch} from "vue";
import {useMedicalHistoryFilter} from "../../../Composables/useMedicalHistoryFilter.js";
const open = defineModel('open')
const props = defineProps({
patientId: {
type: Number,
}
})
const {filtersRef} = useMedicalHistoryFilter()
const loading = ref(true)
const patient = ref({})
const showArchiveHistoryModal = ref(false)
const selectedArchiveHistoryId = ref(null)
const selectedArchiveHistoryType = ref(null)
const isCreateNewArchiveHistoryModal = ref(false)
const archiveInfo = ref({
id: props.patientId,
num: null,
post_in: null,
status: null
})
const emits = defineEmits(['historyUpdated'])
const onResetData = () => {
archiveInfo.value = {
id: props.patientId,
num: null,
post_in: null,
status: null
}
}
const patientData = ref({
...patient.value.info
})
const loadPatientData = async () => {
if (!props.patientId) return
loading.value = true
try {
axios.get(`/api/si/patients/${props.patientId}?view_type=${filtersRef.value.view_type}`).then(res => {
patient.value = res.data
patientData.value = res.data.info
archiveInfo.value = res.data.archiveInfo ?? {
historyable_type: res.data.historyable_type,
id: props.patientId,
num: null,
post_in: null,
status: null,
}
})
} catch (error) {
// message.error('Ошибка при загрузке данных пациента')
console.error(error)
} finally {
loading.value = false
}
}
const onShowArchiveHistoryModal = (id) => {
if (id === null) {
isCreateNewArchiveHistoryModal.value = true
selectedArchiveHistoryId.value = props.patientId
} else {
isCreateNewArchiveHistoryModal.value = false
selectedArchiveHistoryId.value = id
}
selectedArchiveHistoryType.value = archiveInfo.value.historyable_type
showArchiveHistoryModal.value = true
}
const columns = [
{
title: 'Выдача',
key: 'issue_at',
width: 100
},
{
title: 'Возврат',
key: 'return_at',
width: 100
},
{
title: 'Организация',
key: 'org',
width: 220
},
{
title: 'ФИО',
key: 'employee_name',
width: 180
},
{
title: 'Должность',
key: 'employee_post',
width: 120
},
]
const rowProps = (row) => ({
onDblclick: () => {
onShowArchiveHistoryModal(row.id)
}
})
const onUpdateHistory = (updatedData) => {
loadPatientData()
}
const hasCreateNew = computed(() => archiveInfo.value === null)
const onSubmit = async () => {
try {
await axios.post(`/api/archive/histories/info/${props.patientId}`, archiveInfo.value).then(res => {
// onCloseWithoutSave()
emits('historyUpdated', {
type: hasCreateNew.value ? 'created' : 'updated',
data: res.data,
patientId: props.patientId
})
})
} catch (error) {
console.error(error)
} finally {
loading.value = false
}
}
// Наблюдаем за изменением patientId
watch(() => props.patientId, (newId) => {
if (newId) {
loadPatientData()
}
}, { immediate: true })
</script>
<template>
<NModal v-model:show="open" preset="card" class="max-w-4xl" closable @close="open = false">
<template #header>
{{ patient.info?.medcardnum }} {{ patient.info?.family }} {{ patient.info?.name }} {{ patient.info?.ot }}
</template>
<NSpace vertical>
<NFlex inline justify="space-between" align="center" :wrap="false">
<NForm inline :show-feedback="false">
<NFormItem label="Статус карты">
<NTag :type="archiveInfo.status?.variant ?? 'error'" :bordered="false" round>
{{ archiveInfo.status?.text ?? 'Нет в архиве' }}
</NTag>
</NFormItem>
<NFormItem label="№ в архиве">
<NInput v-model:value="archiveInfo.num" />
</NFormItem>
<NFormItem label="Дата поступления карты в архив">
<NDatePicker v-model:value="archiveInfo.post_in" format="dd.MM.yyyy" />
</NFormItem>
</NForm>
</NFlex>
<NButton @click="onShowArchiveHistoryModal(null)" :disabled="!patientData.can_be_issued">
Добавить
</NButton>
<NDataTable :row-props="rowProps" min-height="420px" max-height="420px" :columns="columns" :data="patient?.journal" />
</NSpace>
<template #action>
<NFlex justify="end" align="center">
<NSpace align="center" :size="0">
<NButton secondary>
Закрыть без сохранения
</NButton>
<NDivider vertical />
<NButton secondary type="primary" @click="onSubmit">
Сохранить
</NButton>
</NSpace>
</NFlex>
</template>
</NModal>
<ArchiveHistoryMoveModal @history-updated="onUpdateHistory" @close-without-save="selectedArchiveHistoryId = null" :is-create-new="isCreateNewArchiveHistoryModal" v-model:open="showArchiveHistoryModal" :active-history-type="selectedArchiveHistoryType" :archive-history-id="selectedArchiveHistoryId" />
</template>
<style scoped>
</style>