0
0
Fork 0

feat: refs #6273 freelance form & vnRadio

This commit is contained in:
Jorge Penadés 2024-06-04 17:38:04 +02:00
parent a1bfe4c7ff
commit 7e0ceca623
2 changed files with 36 additions and 49 deletions

View File

@ -0,0 +1,6 @@
<script setup>
const model = defineModel({ type: Boolean, required: true });
</script>
<template>
<QRadio v-model="model" v-bind="$attrs" dense :dark="true" class="q-mr-sm" />
</template>

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { onMounted, ref } from 'vue'; import { onBeforeMount, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useUserConfig } from 'src/composables/useUserConfig'; import { useUserConfig } from 'src/composables/useUserConfig';
import VnRow from 'components/ui/VnRow.vue'; import VnRow from 'components/ui/VnRow.vue';
@ -12,43 +12,18 @@ import VnSelectDialog from 'src/components/common/VnSelectDialog.vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import FormModel from 'components/FormModel.vue'; import FormModel from 'components/FormModel.vue';
import CreateBankEntityForm from 'src/components/CreateBankEntityForm.vue'; import CreateBankEntityForm from 'src/components/CreateBankEntityForm.vue';
import VnRadio from 'src/components/common/VnRadio.vue';
import { useStateStore } from 'src/stores/useStateStore';
const { t } = useI18n(); const { t } = useI18n();
const state = useStateStore();
const newWorkerForm = ref({
companyFk: null,
payMethodFk: null,
firstName: null,
lastNames: null,
birth: null,
fi: null,
code: null,
phone: null,
postcode: null,
provinceFk: null,
city: null,
street: null,
name: null,
email: null,
bossFk: null,
iban: null,
bankEntityFk: null,
});
const companiesOptions = ref([]); const companiesOptions = ref([]);
const workersOptions = ref([]); const workersOptions = ref([]);
const payMethodsOptions = ref([]); const payMethodsOptions = ref([]);
const bankEntitiesOptions = ref([]); const bankEntitiesOptions = ref([]);
const postcodesOptions = ref([]); const postcodesOptions = ref([]);
const isFreelancer = ref(false); const formData = ref({ isFreelance: false });
const onFetchWorkerConfig = (workerConfig) => {
newWorkerForm.value.payMethodFk = workerConfig.payMethodFk;
};
const onBankEntityCreated = (data) => {
bankEntitiesOptions.value.push(data);
};
function handleLocation(data, location) { function handleLocation(data, location) {
const { town, code, provinceFk, countryFk } = location ?? {}; const { town, code, provinceFk, countryFk } = location ?? {};
@ -58,15 +33,15 @@ function handleLocation(data, location) {
data.countryFk = countryFk; data.countryFk = countryFk;
} }
onMounted(async () => { onBeforeMount(async () => {
const userInfo = await useUserConfig().fetch(); const userInfo = await useUserConfig().fetch();
newWorkerForm.value = { companyFk: userInfo.companyFk }; formData.value.companyFk = userInfo.companyFk;
}); });
</script> </script>
<template> <template>
<FetchData <FetchData
url="WorkerConfigs/findOne" url="WorkerConfigs/findOne"
@on-fetch="(data) => onFetchWorkerConfig(data)" @on-fetch="(data) => (formData.payMethodFk = data.payMethodFk)"
:filter="{ field: ['payMethodFk'] }" :filter="{ field: ['payMethodFk'] }"
auto-load auto-load
/> />
@ -93,15 +68,21 @@ onMounted(async () => {
<QPage> <QPage>
<VnSubToolbar> <VnSubToolbar>
<template #st-data> <template #st-data>
<QRadio v-model="isFreelancer" :val="false" :label="`${t('Internal')}`" /> <VnRadio
<QRadio v-model="isFreelancer" :val="true" :label="`${t('External')}`" /> v-model="formData.isFreelance"
:val="false"
:label="`${t('Internal')}`"
@update:model-value="state.set('worker', formData)"
/>
<VnRadio
v-model="formData.isFreelance"
:val="true"
:label="`${t('External')}`"
@update:model-value="state.set('worker', formData)"
/>
</template> </template>
</VnSubToolbar> </VnSubToolbar>
<FormModel <FormModel url-create="Workers/new" model="worker" :form-initial-data="formData">
url-create="Workers/new"
model="worker"
:form-initial-data="newWorkerForm"
>
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<VnRow> <VnRow>
<VnInput <VnInput
@ -169,19 +150,19 @@ onMounted(async () => {
v-model="data.fi" v-model="data.fi"
:label="t('worker.create.fi')" :label="t('worker.create.fi')"
:rules="validate('Worker.fi')" :rules="validate('Worker.fi')"
:disable="isFreelancer" :disable="formData.isFreelance"
/> />
<VnInputDate <VnInputDate
v-model="data.birth" v-model="data.birth"
:label="t('worker.create.birth')" :label="t('worker.create.birth')"
:rules="validate('Worker.birth')" :rules="validate('Worker.birth')"
:disable="isFreelancer" :disable="formData.isFreelance"
/> />
<VnInput <VnInput
v-model="data.phone" v-model="data.phone"
:label="t('worker.create.phone')" :label="t('worker.create.phone')"
:rules="validate('Worker.phone')" :rules="validate('Worker.phone')"
:disable="isFreelancer" :disable="formData.isFreelance"
/> />
</VnRow> </VnRow>
<VnRow> <VnRow>
@ -191,7 +172,7 @@ onMounted(async () => {
:options="postcodesOptions" :options="postcodesOptions"
v-model="data.location" v-model="data.location"
@update:model-value="(location) => handleLocation(data, location)" @update:model-value="(location) => handleLocation(data, location)"
:disable="isFreelancer" :disable="formData.isFreelance"
> >
</VnLocation> </VnLocation>
</VnRow> </VnRow>
@ -200,7 +181,7 @@ onMounted(async () => {
:label="t('worker.create.street')" :label="t('worker.create.street')"
v-model="data.street" v-model="data.street"
:rules="validate('Worker.street')" :rules="validate('Worker.street')"
:disable="isFreelancer" :disable="formData.isFreelance"
/> />
</VnRow> </VnRow>
<VnRow> <VnRow>
@ -213,13 +194,13 @@ onMounted(async () => {
map-options map-options
hide-selected hide-selected
:rules="validate('Worker.payMethodFk')" :rules="validate('Worker.payMethodFk')"
:disable="isFreelancer" :disable="formData.isFreelance"
/> />
<VnInput <VnInput
v-model="data.iban" v-model="data.iban"
:label="t('worker.create.iban')" :label="t('worker.create.iban')"
:rules="validate('Worker.iban')" :rules="validate('Worker.iban')"
:disable="isFreelancer" :disable="formData.isFreelance"
> >
<template #append> <template #append>
<QIcon name="info" class="cursor-info"> <QIcon name="info" class="cursor-info">
@ -236,11 +217,11 @@ onMounted(async () => {
hide-selected hide-selected
:roles-allowed-to-create="['salesAssistant', 'hr']" :roles-allowed-to-create="['salesAssistant', 'hr']"
:rules="validate('Worker.bankEntity')" :rules="validate('Worker.bankEntity')"
:disable="isFreelancer" :disable="formData.isFreelance"
> >
<template #form> <template #form>
<CreateBankEntityForm <CreateBankEntityForm
@on-data-saved="onBankEntityCreated($event)" @on-data-saved="(data) => bankEntitiesOptions.push(data)"
/> />
</template> </template>
<template #option="scope"> <template #option="scope">