0
0
Fork 0

feat: refs #5919 workerlocker

This commit is contained in:
Jorge Penadés 2024-05-10 13:07:58 +02:00
parent 626a369f84
commit 7fd4c43b8b
2 changed files with 25 additions and 15 deletions

View File

@ -160,7 +160,7 @@ async function fetch() {
params: { filter: JSON.stringify($props.filter) },
});
if (Array.isArray(data)) data = data[0];
if (Array.isArray(data)) data = data[0] ?? {};
state.set($props.model, data);
originalData.value = data && JSON.parse(JSON.stringify(data));

View File

@ -1,22 +1,31 @@
<script setup>
import { ref } from 'vue';
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import axios from 'axios';
import { useRole } from 'src/composables/useRole';
import FormModel from 'components/FormModel.vue';
import FetchData from 'src/components/FetchData.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import { useArrayData } from 'src/composables/useArrayData';
import FetchData from 'components/FetchData.vue';
const route = useRoute();
const { hasAny } = useRole();
const { t } = useI18n();
const fetchData = ref();
const lockers = ref([]);
const filter = ref({ where: {} });
const { store } = useArrayData('Worker');
const entityId = computed(() => useRoute().params.id);
const filter = computed(() => ({
where: {
gender: store.data?.sex,
or: [{ workerFk: null }, { workerFk: entityId.value }],
},
}));
const getLockers = async (workerLocker) => {
console.log(workerLocker);
filter.value.where.gender = workerLocker.sex;
await fetchData.value.fetch();
};
const canEdit = () => hasAny(['productionBoss', 'hr']);
const save = async (data) =>
await axios.patch(`Lockers/${data.id}`, { workerFk: entityId.value });
</script>
<template>
<FetchData
@ -26,20 +35,21 @@ const getLockers = async (workerLocker) => {
@on-fetch="(data) => (lockers = data)"
/>
<FormModel
:url="`Workers/locker`"
model="Worker"
:filter="{ where: { id: route.params.id } }"
@on-fetch="getLockers"
:url="`Workers/${entityId}/locker`"
model="worker"
auto-load
:save-fn="save"
@on-fetch="() => canEdit() && fetchData.fetch()"
>
<template #form="{ data }">
<VnSelect
:label="t('Locker')"
v-model="data.locker"
v-model="data.id"
:options="lockers"
option-label="code"
option-value="id"
hide-selected
:readonly="!canEdit()"
/>
</template>
</FormModel>