jws-frontend/src/components/03_customer-management/FormEmployeeHealthCheck.vue

341 lines
9.3 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue';
import useAddressStore, {
District,
Province,
SubDistrict,
2024-08-09 15:06:41 +07:00
} from 'stores/address';
import { EmployeeCheckupCreate } from 'stores/employee/types';
2024-09-05 11:13:33 +07:00
import { selectFilterOptionRefMod } from 'stores/utils';
2024-07-30 04:04:51 +00:00
import { QSelect } from 'quasar';
2024-08-22 09:32:29 +07:00
import DatePicker from '../shared/DatePicker.vue';
2024-11-12 09:29:19 +07:00
import SelectInput from 'components/shared/SelectInput.vue';
2024-08-09 02:10:06 +00:00
import {
AddButton,
EditButton,
DeleteButton,
SaveButton,
UndoButton,
2024-08-09 14:02:40 +07:00
} from 'components/button';
2024-08-07 18:33:02 +07:00
const adrressStore = useAddressStore();
const addrOptions = reactive<{
provinceOps: Province[];
districtOps: District[];
subDistrictOps: SubDistrict[];
}>({
provinceOps: [],
districtOps: [],
subDistrictOps: [],
});
2024-08-13 13:31:29 +07:00
const currentIndex = defineModel<number>('currentIndex');
const employeeCheckup = defineModel<EmployeeCheckupCreate[]>('employeeCheckup');
2024-11-12 09:29:19 +07:00
const checkupResultsOption = defineModel<{ label: string; value: string }[]>(
'checkupResultsOption',
{ required: true },
);
2024-07-26 11:44:00 +00:00
const checkupTypeOption = defineModel<{ label: string; value: string }[]>(
'checkupTypeOption',
{ required: true },
);
2024-06-11 12:27:58 +00:00
const medicalBenefitOption = defineModel<{ label: string; value: string }[]>(
'medicalBenefitOption',
2024-07-26 11:44:00 +00:00
{ required: true },
2024-06-11 12:27:58 +00:00
);
const insuranceCompanyOption = defineModel<{ label: string; value: string }[]>(
'insuranceCompanyOption',
2024-07-26 11:44:00 +00:00
{ required: true },
2024-06-11 12:27:58 +00:00
);
const tab = ref();
withDefaults(
defineProps<{
title?: string;
dense?: boolean;
outlined?: boolean;
readonly?: boolean;
typeCustomer?: string;
prefixId: string;
showBtnSave?: boolean;
hideAction?: boolean;
}>(),
{
hideAction: false,
showBtnSave: false,
},
);
2024-08-06 03:14:56 +00:00
defineEmits<{
2024-08-06 04:51:17 +00:00
(e: 'save', index: number): void;
2024-08-07 18:33:02 +07:00
(e: 'edit', index: number): void;
(e: 'delete', index: number): void;
2024-08-09 15:26:52 +07:00
(e: 'undo', index: number): void;
2024-08-06 03:14:56 +00:00
}>();
async function fetchProvince() {
const result = await adrressStore.fetchProvince();
if (result) addrOptions.provinceOps = result;
2024-07-30 04:04:51 +00:00
provinceFilter = selectFilterOptionRefMod(
ref(addrOptions.provinceOps),
provinceOptions,
'name',
);
}
function removeData(index: number) {
if (!employeeCheckup.value) return;
if (employeeCheckup.value.length === 1) return;
employeeCheckup.value.splice(index, 1);
if (index) if (tab.value === `tab${index}`) tab.value = `tab${index - 1}`;
if (tab.value === `tab${employeeCheckup.value.length}`)
tab.value = `tab${employeeCheckup.value.length - 1}`;
}
onMounted(async () => {
await fetchProvince();
tab.value = 'tab0';
});
2024-07-26 11:44:00 +00:00
2024-07-30 04:04:51 +00:00
const provinceOptions = ref<Record<string, unknown>[]>([]);
let provinceFilter: (
value: string,
update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void,
) => void;
2024-07-26 11:44:00 +00:00
2024-11-12 09:29:19 +07:00
const checkupResultsOptions = ref<Record<string, unknown>[]>([]);
const checkupResultsFilter = selectFilterOptionRefMod(
checkupResultsOption,
checkupResultsOptions,
'label',
);
2024-07-26 11:44:00 +00:00
const checkupTypeOptions = ref<Record<string, unknown>[]>([]);
const checkupTypeFilter = selectFilterOptionRefMod(
checkupTypeOption,
checkupTypeOptions,
'label',
);
const medicalBenefitOptions = ref<Record<string, unknown>[]>([]);
const medicalBenefitFilter = selectFilterOptionRefMod(
medicalBenefitOption,
medicalBenefitOptions,
'label',
);
const insuranceCompanyOptions = ref<Record<string, unknown>[]>([]);
const insuranceCompanyFilter = selectFilterOptionRefMod(
insuranceCompanyOption,
insuranceCompanyOptions,
'label',
);
</script>
<template>
2024-11-15 14:38:51 +07:00
<div class="row">
2024-08-06 03:14:56 +00:00
<div
v-for="(checkup, index) in employeeCheckup"
v-bind:key="index"
class="col-12 row q-col-gutter-sm"
2024-08-06 04:51:17 +00:00
:class="{ 'q-pt-lg': index !== 0 }"
2024-08-19 17:17:38 +07:00
:id="`${prefixId}-checkup-${index}`"
2024-08-06 03:14:56 +00:00
>
2024-08-06 04:51:17 +00:00
<q-separator
v-if="index > 0"
class="full-width"
style="padding-block: 0.1px"
spaced="lg"
/>
<span class="col-12 flex justify-between items-center">
2024-08-26 16:24:08 +07:00
{{ $t('general.times', { number: index + 1 }) }}
<div class="row items-center" v-if="!hideAction">
2024-08-09 02:10:06 +00:00
<UndoButton
2024-08-09 15:26:52 +07:00
v-if="!readonly && !!checkup.id && !checkup.statusSave"
2024-08-09 02:10:06 +00:00
id="btn-info-health-undo"
icon-only
2024-08-09 15:26:52 +07:00
@click="$emit('undo', index)"
2024-08-09 02:10:06 +00:00
type="button"
2024-08-13 13:31:29 +07:00
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
2024-08-09 02:10:06 +00:00
/>
2024-08-07 18:33:02 +07:00
<SaveButton
2024-08-09 02:10:06 +00:00
icon-only
id="btn-info-health-save"
2024-08-07 18:33:02 +07:00
v-if="!readonly && !checkup.statusSave"
@click="$emit('save', index)"
2024-08-15 12:37:43 +07:00
type="submit"
2024-08-13 13:31:29 +07:00
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
2024-08-07 18:33:02 +07:00
/>
<EditButton
2024-08-09 02:10:06 +00:00
icon-only
id="btn-info-health-edit"
2024-08-09 15:26:52 +07:00
v-if="!readonly && checkup.statusSave"
2024-08-07 18:33:02 +07:00
@click="$emit('edit', index)"
type="button"
2024-08-13 13:31:29 +07:00
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
2024-08-07 18:33:02 +07:00
/>
<DeleteButton
2024-08-09 02:10:06 +00:00
icon-only
id="btn-info-health-delete"
2024-08-09 17:04:02 +07:00
v-if="!readonly && !!checkup.id && checkup.statusSave"
2024-08-07 18:33:02 +07:00
@click="$emit('delete', index)"
type="button"
2024-08-13 13:31:29 +07:00
:disabled="!(currentIndex === -1) && !(currentIndex === index)"
2024-08-07 18:33:02 +07:00
/>
</div>
2024-08-06 03:14:56 +00:00
</span>
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
2024-11-12 09:29:19 +07:00
class="col-6"
2024-08-06 03:14:56 +00:00
input-debounce="0"
option-value="value"
option-label="label"
2024-11-12 09:29:19 +07:00
v-model="checkup.checkupResult"
2024-08-06 03:14:56 +00:00
:dense="dense"
2024-08-09 15:26:52 +07:00
:readonly="readonly || checkup.statusSave"
2024-11-12 09:29:19 +07:00
:options="checkupResultsOptions"
2024-08-09 15:26:52 +07:00
:hide-dropdown-icon="readonly || checkup.statusSave"
2024-11-12 09:29:19 +07:00
:for="`${prefixId}-select-health-checkresult`"
:label="$t('customerEmployee.formHealthCheck.result')"
@filter="checkupResultsFilter"
2024-08-06 03:14:56 +00:00
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
2024-08-26 16:24:08 +07:00
{{ $t('general.noData') }}
2024-08-06 03:14:56 +00:00
</q-item-section>
</q-item>
</template>
</q-select>
2024-11-12 09:29:19 +07:00
2024-08-06 03:14:56 +00:00
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
2024-11-12 09:29:19 +07:00
class="col-6"
2024-08-06 03:14:56 +00:00
input-debounce="0"
2024-11-12 09:29:19 +07:00
option-value="value"
option-label="label"
v-model="checkup.checkupType"
2024-08-06 03:14:56 +00:00
:dense="dense"
2024-08-09 15:26:52 +07:00
:readonly="readonly || checkup.statusSave"
2024-11-12 09:29:19 +07:00
:options="checkupTypeOptions"
2024-08-09 15:26:52 +07:00
:hide-dropdown-icon="readonly || checkup.statusSave"
2024-11-12 09:29:19 +07:00
:for="`${prefixId}-select-checkup-type`"
:label="$t('customerEmployee.formHealthCheck.checkupType')"
@filter="checkupTypeFilter"
2024-08-06 03:14:56 +00:00
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
2024-08-26 16:24:08 +07:00
{{ $t('general.noData') }}
2024-08-06 03:14:56 +00:00
</q-item-section>
</q-item>
</template>
</q-select>
<!-- @filter="provinceFilter" -->
<q-input
:dense="dense"
outlined
2024-08-09 15:26:52 +07:00
:readonly="readonly || checkup.statusSave"
2024-08-06 03:14:56 +00:00
hide-bottom-space
2024-11-12 09:29:19 +07:00
class="col-12"
2024-08-26 16:24:08 +07:00
:label="$t('customerEmployee.formHealthCheck.hospital')"
2024-08-06 03:14:56 +00:00
v-model="checkup.hospitalName"
:for="`${prefixId}-input-hospital`"
/>
2024-11-12 09:29:19 +07:00
<div class="col-md col-6">
2024-11-12 09:29:19 +07:00
<DatePicker
v-model="checkup.coverageStartDate"
:id="`${prefixId}-input-coverage-start-date`"
:readonly="readonly || checkup.statusSave"
clearable
/>
</div>
<div class="col">
<DatePicker
:label="$t('customerEmployee.formHealthCheck.coverageExpireDate')"
v-model="checkup.coverageExpireDate"
:id="`${prefixId}-input-coverage-expire-date`"
:readonly="readonly || checkup.statusSave"
2024-12-04 15:42:15 +07:00
:disabled-dates="
(date: Date) =>
date.getTime() <
((checkup.coverageStartDate &&
new Date(checkup.coverageStartDate).getTime()) ||
Date.now())
"
2024-11-12 09:29:19 +07:00
clearable
/>
</div>
2024-08-06 03:14:56 +00:00
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
class="col-md-6 col-12"
2024-08-06 03:14:56 +00:00
input-debounce="0"
option-value="value"
option-label="label"
v-model="checkup.medicalBenefitScheme"
:dense="dense"
2024-08-09 15:26:52 +07:00
:readonly="readonly || checkup.statusSave"
:hide-dropdown-icon="readonly || checkup.statusSave"
2024-08-06 03:14:56 +00:00
:options="medicalBenefitOptions"
:for="`${prefixId}-select-province`"
2024-08-26 16:24:08 +07:00
:label="$t('customerEmployee.formHealthCheck.medicalBenefit')"
2024-08-06 03:14:56 +00:00
@filter="medicalBenefitFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
2024-08-26 16:24:08 +07:00
{{ $t('general.noData') }}
2024-08-06 03:14:56 +00:00
</q-item-section>
</q-item>
</template>
</q-select>
<q-input
2024-08-26 16:24:08 +07:00
:label="$t('general.remark')"
2024-08-06 03:14:56 +00:00
:dense="dense"
outlined
2024-08-09 15:26:52 +07:00
:readonly="readonly || checkup.statusSave"
2024-08-06 03:14:56 +00:00
hide-bottom-space
class="col-12"
v-model="checkup.remark"
type="textarea"
:for="`${prefixId}-input-remark`"
/>
</div>
</div>
</template>
2024-08-06 04:51:17 +00:00
<style scoped></style>