jws-frontend/src/components/02_personnel-management/FormInformation.vue

242 lines
6.1 KiB
Vue
Raw Normal View History

2024-04-17 15:44:13 +07:00
<script setup lang="ts">
import useUserStore from 'src/stores/user';
2024-07-30 04:04:17 +00:00
import { selectFilterOptionRefMod } from 'src/stores/utils';
import { onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
2024-04-17 15:44:13 +07:00
const userStore = useUserStore();
2024-07-30 04:04:17 +00:00
const { t } = useI18n();
2024-04-17 15:44:13 +07:00
const hqId = defineModel<string | null | undefined>('hqId');
const brId = defineModel<string | null | undefined>('brId');
const userType = defineModel<string>('userType');
const userRole = defineModel<string>('userRole');
2024-04-18 09:05:32 +07:00
const username = defineModel<string | null | undefined>('username');
2024-04-17 15:44:13 +07:00
const userCode = defineModel<string>('userCode');
defineProps<{
dense?: boolean;
outlined?: boolean;
readonly?: boolean;
separator?: boolean;
2024-04-18 09:05:32 +07:00
usernameReadonly?: boolean;
2024-04-17 15:44:13 +07:00
}>();
async function selectHq(id: string) {
if (!id) return;
brId.value = '';
userStore.userOption.brOpts = [];
await userStore.fetchBrOption(id);
2024-04-18 18:18:31 +07:00
if (userStore.userOption.brOpts.length === 1) {
brId.value = userStore.userOption.brOpts[0].value;
}
2024-04-17 15:44:13 +07:00
}
2024-07-30 04:04:17 +00:00
const hqOptions = ref<Record<string, unknown>[]>([]);
const hqFilter = selectFilterOptionRefMod(
ref(userStore.userOption.hqOpts),
hqOptions,
'label',
);
const brOptions = ref<Record<string, unknown>[]>([]);
const brFilter = selectFilterOptionRefMod(
ref(userStore.userOption.brOpts),
brOptions,
'label',
);
const userTypeOptions = ref<Record<string, unknown>[]>([]);
const userTypeFilter = selectFilterOptionRefMod(
ref(
userStore.userOption.userTypeOpts.map((v) => ({
label: t(v.label),
value: v.value,
})),
),
userTypeOptions,
'label',
);
const roleOptions = ref<Record<string, unknown>[]>([]);
const roleFilter = selectFilterOptionRefMod(
ref(userStore.userOption.roleOpts),
roleOptions,
'label',
);
onMounted(async () => {
if (userStore.userOption.hqOpts[0].value)
await userStore.fetchBrOption(userStore.userOption.hqOpts[0].value);
});
2024-04-17 15:44:13 +07:00
</script>
<template>
2024-07-24 06:39:01 +00:00
<div class="col-md-3 col-12 app-text-muted">
2024-04-22 10:53:56 +07:00
{{ $t('formDialogTitleInformation') }}
</div>
2024-07-24 06:39:01 +00:00
<div class="col-md-9 col-12 row q-col-gutter-md">
2024-04-17 15:44:13 +07:00
<q-select
outlined
2024-07-30 04:04:17 +00:00
clearable
use-input
fill-input
2024-04-17 15:44:13 +07:00
emit-value
map-options
2024-07-30 04:04:17 +00:00
hide-selected
2024-04-17 15:44:13 +07:00
hide-bottom-space
2024-04-18 18:18:31 +07:00
v-model="hqId"
2024-07-30 14:17:47 +07:00
for="select-hq-id"
2024-07-30 04:04:17 +00:00
input-debounce="0"
2024-04-17 15:44:13 +07:00
option-label="label"
option-value="value"
2024-07-30 04:04:17 +00:00
lazy-rules="ondemand"
class="col-md-4 col-6"
:dense="dense"
:readonly="readonly"
:hide-dropdown-icon="readonly"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputCode')"
2024-07-30 04:04:17 +00:00
:options="hqOptions"
2024-04-22 10:53:56 +07:00
:rules="[(val: string) => !!val || $t('formDialogInputHqIdValidate')]"
2024-04-17 15:44:13 +07:00
@update:model-value="(val: string) => selectHq(val)"
2024-07-30 04:04:17 +00:00
@filter="hqFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('noResults') }}
</q-item-section>
</q-item>
</template>
</q-select>
2024-04-17 15:44:13 +07:00
<q-select
outlined
2024-07-30 04:04:17 +00:00
clearable
use-input
fill-input
2024-04-17 15:44:13 +07:00
emit-value
map-options
2024-07-30 04:04:17 +00:00
hide-selected
2024-04-17 15:44:13 +07:00
hide-bottom-space
2024-04-18 18:18:31 +07:00
v-model="brId"
2024-07-30 14:17:47 +07:00
for="select-br-id"
2024-07-30 04:04:17 +00:00
input-debounce="0"
2024-04-17 15:44:13 +07:00
option-label="label"
option-value="value"
2024-07-30 04:04:17 +00:00
lazy-rules="ondemand"
class="col-md-4 col-6"
:dense="dense"
:readonly="readonly"
:hide-dropdown-icon="readonly"
:label="$t('formDialogInputBrId')"
:options="brOptions"
@filter="brFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('noResults') }}
</q-item-section>
</q-item>
</template>
</q-select>
<q-input
lazy-rules="ondemand"
2024-04-25 04:05:48 +00:00
for="input-username"
:dense="dense"
outlined
:readonly="usernameReadonly"
emit-value
map-options
options-dense
hide-bottom-space
2024-07-24 06:39:01 +00:00
class="col-md-4 col-12"
:label="$t('formDialogInputUsername')"
v-model="username"
:rules="[
(val: string) =>
val.length > 2 || $t('formDialogInputUsernameValidate'),
]"
/>
2024-04-17 15:44:13 +07:00
<q-select
outlined
2024-07-30 04:04:17 +00:00
clearable
use-input
fill-input
2024-04-17 15:44:13 +07:00
emit-value
map-options
2024-07-30 04:04:17 +00:00
hide-selected
2024-04-17 15:44:13 +07:00
hide-bottom-space
class="col-6"
2024-07-30 04:04:17 +00:00
v-model="userType"
input-debounce="0"
2024-04-17 15:44:13 +07:00
option-value="value"
2024-07-30 04:04:17 +00:00
option-label="label"
lazy-rules="ondemand"
2024-07-30 14:17:47 +07:00
for="select-user-type"
2024-07-30 04:04:17 +00:00
:dense="dense"
:readonly="readonly"
:hide-dropdown-icon="readonly"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputUserType')"
2024-07-30 04:04:17 +00:00
:options="userTypeOptions"
2024-04-22 10:53:56 +07:00
:rules="[(val: string) => !!val || $t('formDialogInputUserTypeValidate')]"
2024-07-30 04:04:17 +00:00
@filter="userTypeFilter"
2024-07-23 09:41:35 +00:00
>
2024-07-30 04:04:17 +00:00
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('noResults') }}
</q-item-section>
2024-07-23 09:41:35 +00:00
</q-item>
</template>
</q-select>
2024-04-17 15:44:13 +07:00
<q-select
outlined
2024-07-30 04:04:17 +00:00
clearable
use-input
fill-input
2024-04-17 15:44:13 +07:00
emit-value
map-options
2024-07-30 04:04:17 +00:00
hide-selected
2024-04-17 15:44:13 +07:00
hide-bottom-space
class="col-6"
2024-07-30 04:04:17 +00:00
input-debounce="0"
2024-04-17 15:44:13 +07:00
option-label="label"
option-value="value"
2024-07-30 04:04:17 +00:00
lazy-rules="ondemand"
2024-07-30 14:17:47 +07:00
for="select-user-role"
2024-07-30 04:04:17 +00:00
:dense="dense"
2024-04-17 15:44:13 +07:00
v-model="userRole"
2024-07-30 04:04:17 +00:00
:readonly="readonly"
:hide-dropdown-icon="readonly"
:label="$t('formDialogInputUserRole')"
:options="roleOptions"
2024-04-22 10:53:56 +07:00
:rules="[(val: string) => !!val || $t('formDialogInputUserRoleValidate')]"
2024-07-30 04:04:17 +00:00
@filter="roleFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('noResults') }}
</q-item-section>
</q-item>
</template>
</q-select>
<!-- <q-input lazy-rules="ondemand"
2024-04-22 10:53:56 +07:00
id="input-user-code"
2024-04-17 15:44:13 +07:00
:dense="dense"
:outlined="readonly ? false : outlined"
:borderless="readonly"
2024-04-17 15:44:13 +07:00
readonly
hide-bottom-space
class="col-3"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputUserCode')"
2024-04-17 15:44:13 +07:00
v-model="userCode"
/> -->
2024-04-17 15:44:13 +07:00
</div>
<q-separator
v-if="separator"
class="col-12 q-mb-md"
style="padding-block: 0.5px; margin-top: 32px"
/>
</template>