jws-frontend/src/pages/03_customer-management/components/employer/EmployerFormBasicInfo.vue

290 lines
7.4 KiB
Vue
Raw Normal View History

2024-08-05 15:09:36 +07:00
<script lang="ts" setup>
2024-09-16 14:38:04 +07:00
import { ref, watch } from 'vue';
2024-08-05 15:09:36 +07:00
import { QSelect } from 'quasar';
import { selectFilterOptionRefMod } from 'stores/utils';
import { getRole } from 'src/services/keycloak';
2024-08-20 18:04:27 +07:00
import useOptionStore from 'stores/options';
2024-08-05 15:09:36 +07:00
import { onMounted } from 'vue';
2024-08-20 18:04:27 +07:00
2024-08-07 17:56:59 +07:00
import {
SaveButton,
EditButton,
DeleteButton,
2024-08-09 13:20:38 +07:00
UndoButton,
2024-08-09 14:02:40 +07:00
} from 'components/button';
2024-09-16 14:38:04 +07:00
withDefaults(
defineProps<{
prefixId?: string;
outlined?: boolean;
readonly?: boolean;
2024-09-17 10:00:35 +07:00
onCreate?: boolean;
actionDisabled?: boolean;
customerType?: 'CORP' | 'PERS';
hideAction?: boolean;
}>(),
{
hideAction: false,
},
);
2024-08-07 17:56:59 +07:00
defineEmits<{
(e: 'save'): void;
(e: 'edit'): void;
(e: 'delete'): void;
(e: 'cancel'): void;
}>();
2024-08-05 15:09:36 +07:00
2024-08-20 18:04:27 +07:00
const optionStore = useOptionStore();
2024-08-05 15:09:36 +07:00
const registeredBranchId = defineModel<string>('registeredBranchId', {
required: true,
});
2024-09-17 18:01:13 +07:00
const customerName = defineModel<string>('customerName', { default: '' });
const registerName = defineModel<string>('registerName', { default: '' });
2024-09-16 14:38:04 +07:00
2024-09-17 18:01:13 +07:00
const citizenId = defineModel<string>('citizenId', { default: '' });
const legalPersonNo = defineModel<string>('legalPersonNo', { default: '' });
2024-09-16 14:38:04 +07:00
2024-09-26 09:59:26 +07:00
const businessType = defineModel<string>('businessType');
const jobPosition = defineModel<string>('jobPosition');
2024-09-17 18:01:13 +07:00
const telephoneNo = defineModel<string>('telephoneNo', { default: '' });
2024-09-16 14:38:04 +07:00
2024-08-05 15:09:36 +07:00
const branchOptions = defineModel<{ id: string; name: string }[]>(
'branchOptions',
{ default: [] },
);
const filteredBranchOptions = ref<Record<string, unknown>[]>([]);
let branchFilter: (
value: string,
update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void,
) => void;
onMounted(() => {
branchFilter = selectFilterOptionRefMod(
branchOptions,
filteredBranchOptions,
'name',
);
});
watch(
() => branchOptions.value,
() => {
branchFilter = selectFilterOptionRefMod(
branchOptions,
filteredBranchOptions,
'name',
);
},
);
</script>
<template>
2024-09-16 14:38:04 +07:00
<div class="row q-col-gutter-sm">
2024-09-18 11:42:58 +07:00
<div class="col-12 text-weight-bold text-body1 row items-center">
2024-08-05 15:09:36 +07:00
<q-icon
flat
size="xs"
class="q-pa-sm rounded q-mr-xs"
color="info"
name="mdi-office-building-outline"
style="background-color: var(--surface-3)"
/>
2024-09-16 14:38:04 +07:00
<span>
{{
$t('general.information', {
msg: `${$t('customer.employer')}${
customerType === 'CORP'
? $t('customer.employerLegalEntity')
: $t('customer.employerNaturalPerson')
}`,
})
}}
</span>
<!-- <EditButton
2024-08-08 13:32:46 +07:00
icon-only
2024-08-07 17:56:59 +07:00
v-if="readonly && !create"
type="button"
@click="$emit('edit')"
class="q-ml-auto"
:disabled="actionDisabled"
/>
<DeleteButton
2024-08-08 13:32:46 +07:00
icon-only
2024-08-07 17:56:59 +07:00
v-if="readonly && !create"
@click="$emit('delete')"
type="button"
:disabled="actionDisabled"
/>
2024-08-09 13:20:38 +07:00
<UndoButton
2024-08-08 13:32:46 +07:00
icon-only
2024-08-09 13:20:38 +07:00
v-if="!readonly && !create"
2024-08-07 17:56:59 +07:00
class="q-ml-auto"
2024-08-09 13:20:38 +07:00
type="button"
2024-08-07 17:56:59 +07:00
:disabled="actionDisabled"
2024-08-09 13:20:38 +07:00
@click="$emit('cancel')"
2024-08-07 17:56:59 +07:00
/>
2024-08-09 13:20:38 +07:00
<SaveButton
2024-08-08 13:32:46 +07:00
icon-only
2024-08-09 13:20:38 +07:00
v-if="!readonly"
2024-08-13 12:52:25 +07:00
:class="{ 'q-ml-auto': create }"
2024-08-09 13:20:38 +07:00
@click="$emit('save')"
2024-08-14 09:43:54 +07:00
type="submit"
2024-08-07 17:56:59 +07:00
:disabled="actionDisabled"
2024-09-16 14:38:04 +07:00
/> -->
2024-08-05 15:09:36 +07:00
</div>
2024-08-20 18:04:27 +07:00
2024-08-23 09:19:23 +07:00
<div class="col-12 row q-col-gutter-sm">
2024-09-16 14:38:04 +07:00
<div class="col-12 row q-col-gutter-sm">
<q-select
outlined
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
dense
class="col-6"
option-value="id"
input-debounce="0"
option-label="name"
v-model="registeredBranchId"
:readonly="readonly"
:options="filteredBranchOptions"
:hide-dropdown-icon="readonly"
:label="$t('customer.form.registeredBranch')"
:for="`${prefixId}-input-source-nationality`"
:rules="[
(val) => {
const roles = getRole() || [];
return (
['admin', 'system', 'head_of_admin'].some((v) =>
roles.includes(v),
) ||
!!val ||
$t('form.error.required')
);
},
]"
@filter="branchFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<div
2024-09-17 10:00:35 +07:00
v-if="customerType === 'CORP' && !onCreate"
2024-09-16 14:38:04 +07:00
class="row col-12 q-col-gutter-sm"
>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
2024-09-18 11:42:58 +07:00
class="col-12 col-md-5"
2024-09-16 14:38:04 +07:00
:label="$t('customer.form.customerName')"
for="input-first-name"
v-model="registerName"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('general.taxNo')"
2024-09-26 11:19:05 +07:00
for="input-tax"
2024-09-16 14:38:04 +07:00
v-model="legalPersonNo"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('customer.table.businessTypePure')"
2024-09-26 11:19:05 +07:00
for="input-business-type"
2024-09-17 10:00:35 +07:00
:model-value="optionStore.mapOption(businessType)"
2024-09-16 14:38:04 +07:00
/>
</div>
<div
2024-09-17 10:00:35 +07:00
v-if="customerType === 'PERS' && !onCreate"
2024-09-16 14:38:04 +07:00
class="row col-12 q-col-gutter-sm"
>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-6"
:label="$t('customer.form.employerName')"
for="input-first-name"
v-model="customerName"
/>
<q-input
outlined
class="col-md-3 col-6"
hide-bottom-space
v-model="citizenId"
mask="#############"
:readonly="readonly"
dense
:label="$t('personnel.form.citizenId')"
for="input-citizen-id"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('customer.table.businessTypePure')"
for="input-first-name-en"
2024-09-17 10:00:35 +07:00
:model-value="optionStore.mapOption(businessType)"
2024-09-16 14:38:04 +07:00
/>
</div>
2024-09-17 10:00:35 +07:00
<div v-if="!onCreate" class="row col-12 q-col-gutter-sm">
2024-09-16 14:38:04 +07:00
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-5"
:label="$t('customer.form.jobPosition')"
for="input-first-name-en"
2024-09-17 10:00:35 +07:00
:model-value="optionStore.mapOption(jobPosition)"
2024-09-16 14:38:04 +07:00
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('customer.form.headQuarters.telephoneNo')"
for="input-first-name-en"
v-model="telephoneNo"
>
<template #prepend>
<q-icon
size="xs"
name="mdi-phone-outline"
class="cursor-pointer"
color="primary"
/>
</template>
</q-input>
</div>
</div>
2024-08-05 15:09:36 +07:00
</div>
</template>