feat(sep): add selected prop to ListPatient and enhance radio selection handling in select-radio component
This commit is contained in:
No files matched your search
@@ -11,6 +11,7 @@ import { config } from './list-cfg.patient'
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
data: PatientData[]
|
data: PatientData[]
|
||||||
|
selected?: string
|
||||||
paginationMeta?: PaginationMeta
|
paginationMeta?: PaginationMeta
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ function handlePageChange(page: number) {
|
|||||||
<PubMyUiDataTable
|
<PubMyUiDataTable
|
||||||
v-bind="config"
|
v-bind="config"
|
||||||
:rows="props.data"
|
:rows="props.data"
|
||||||
|
:selected="props.selected"
|
||||||
/>
|
/>
|
||||||
<PaginationView
|
<PaginationView
|
||||||
v-if="paginationMeta"
|
v-if="paginationMeta"
|
||||||
|
|||||||
@@ -1,26 +1,34 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, type Ref } from 'vue'
|
||||||
// Components
|
// Components
|
||||||
import { RadioGroup, RadioGroupItem } from '~/components/pub/ui/radio-group'
|
import { RadioGroup, RadioGroupItem } from '~/components/pub/ui/radio-group'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
rec: { id: string; name: string; menu: string }
|
rec: { id: string; name: string; menu: string }
|
||||||
|
selected?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
// No emits needed - using provide/inject
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const record = props.rec || {}
|
const record = props.rec || {}
|
||||||
const recId = inject<Ref<number>>('rec_select_id')!
|
const recId = inject('rec_select_id') as Ref<number>
|
||||||
const recMenu = inject<Ref<string>>('rec_select_menu')!
|
const recMenu = inject('rec_select_menu') as Ref<string>
|
||||||
const selected = ref<string>('')
|
const selected = computed(() => recId.value === Number(record.id) ? record.id : '')
|
||||||
|
|
||||||
|
function handleSelection(value: string) {
|
||||||
|
if (value === record.id) {
|
||||||
|
recId.value = Number(record.id) || 0
|
||||||
|
recMenu.value = record.menu || ''
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
:model-value="selected"
|
:model-value="selected"
|
||||||
@update:model-value="
|
@update:model-value="handleSelection"
|
||||||
() => {
|
|
||||||
recId = Number(record.id) || 0
|
|
||||||
recMenu = record.menu || ''
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<RadioGroupItem
|
<RadioGroupItem
|
||||||
:id="record.id"
|
:id="record.id"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref, provide, watch, computed } from 'vue'
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import {
|
import {
|
||||||
@@ -38,17 +38,46 @@ const emit = defineEmits<{
|
|||||||
const search = ref('')
|
const search = ref('')
|
||||||
const debouncedSearch = refDebounced(search, 500) // 500ms debounce
|
const debouncedSearch = refDebounced(search, 500) // 500ms debounce
|
||||||
|
|
||||||
|
// Provide for radio selection - use selected prop directly
|
||||||
|
const recSelectId = ref<number>(Number(props.selected) || 0)
|
||||||
|
const recSelectMenu = ref<string>('patient')
|
||||||
|
|
||||||
|
provide('rec_select_id', recSelectId)
|
||||||
|
provide('rec_select_menu', recSelectMenu)
|
||||||
|
|
||||||
function saveSelection() {
|
function saveSelection() {
|
||||||
|
// Validate that a patient is selected
|
||||||
|
if (!props.selected || props.selected === '') {
|
||||||
|
console.warn('No patient selected')
|
||||||
|
return
|
||||||
|
}
|
||||||
emit('save')
|
emit('save')
|
||||||
emit('update:open', false)
|
emit('update:open', false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handlePageChange(page: number) {
|
||||||
|
emit('fetch', { 'page-number': page })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Watch for changes in recSelectId and emit update:selected
|
||||||
|
watch(recSelectId, (newValue) => {
|
||||||
|
if (newValue > 0) {
|
||||||
|
emit('update:selected', String(newValue))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Watch for changes in selected prop
|
||||||
|
watch(() => props.selected, (newValue) => {
|
||||||
|
recSelectId.value = Number(newValue) || 0
|
||||||
|
})
|
||||||
|
|
||||||
watch(debouncedSearch, (newValue) => {
|
watch(debouncedSearch, (newValue) => {
|
||||||
// Only search if 3+ characters or empty (to clear search)
|
// Only search if 3+ characters or empty (to clear search)
|
||||||
if (newValue.length === 0 || newValue.length >= 3) {
|
if (newValue.length === 0 || newValue.length >= 3) {
|
||||||
emit('fetch', { search: newValue })
|
emit('fetch', { search: newValue })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -63,7 +92,7 @@ watch(debouncedSearch, (newValue) => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<!-- Input Search -->
|
<!-- Input Search -->
|
||||||
<div class="mb-2 max-w-[50%]">
|
<div class="max-w-[50%]">
|
||||||
<Input
|
<Input
|
||||||
v-model="search"
|
v-model="search"
|
||||||
placeholder="Cari berdasarkan No. KTP / No. RM / Nomor Kartu"
|
placeholder="Cari berdasarkan No. KTP / No. RM / Nomor Kartu"
|
||||||
@@ -71,7 +100,12 @@ watch(debouncedSearch, (newValue) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="overflow-x-auto rounded-lg border">
|
<div class="overflow-x-auto rounded-lg border">
|
||||||
<ListPatient :data="patients" :pagination-meta="paginationMeta" />
|
<ListPatient
|
||||||
|
:data="patients"
|
||||||
|
:selected="props.selected"
|
||||||
|
:pagination-meta="paginationMeta"
|
||||||
|
@page-change="handlePageChange"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Footer -->
|
<!-- Footer -->
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ const letters = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
function handleSavePatient() {
|
function handleSavePatient() {
|
||||||
selectedPatientObject.value = null
|
selectedPatientObject.value = null
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
getPatientCurrent(selectedPatient.value)
|
getPatientCurrent(selectedPatient.value)
|
||||||
|
|||||||
Reference in New Issue
Block a user