This commit is contained in:
parent
626a369f84
commit
7fd4c43b8b
|
@ -160,7 +160,7 @@ async function fetch() {
|
||||||
params: { filter: JSON.stringify($props.filter) },
|
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);
|
state.set($props.model, data);
|
||||||
originalData.value = data && JSON.parse(JSON.stringify(data));
|
originalData.value = data && JSON.parse(JSON.stringify(data));
|
||||||
|
|
|
@ -1,22 +1,31 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { useRole } from 'src/composables/useRole';
|
||||||
import FormModel from 'components/FormModel.vue';
|
import FormModel from 'components/FormModel.vue';
|
||||||
import FetchData from 'src/components/FetchData.vue';
|
|
||||||
import VnSelect from 'src/components/common/VnSelect.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 { t } = useI18n();
|
||||||
const fetchData = ref();
|
const fetchData = ref();
|
||||||
const lockers = 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) => {
|
const canEdit = () => hasAny(['productionBoss', 'hr']);
|
||||||
console.log(workerLocker);
|
|
||||||
filter.value.where.gender = workerLocker.sex;
|
const save = async (data) =>
|
||||||
await fetchData.value.fetch();
|
await axios.patch(`Lockers/${data.id}`, { workerFk: entityId.value });
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
<FetchData
|
||||||
|
@ -26,20 +35,21 @@ const getLockers = async (workerLocker) => {
|
||||||
@on-fetch="(data) => (lockers = data)"
|
@on-fetch="(data) => (lockers = data)"
|
||||||
/>
|
/>
|
||||||
<FormModel
|
<FormModel
|
||||||
:url="`Workers/locker`"
|
:url="`Workers/${entityId}/locker`"
|
||||||
model="Worker"
|
model="worker"
|
||||||
:filter="{ where: { id: route.params.id } }"
|
|
||||||
@on-fetch="getLockers"
|
|
||||||
auto-load
|
auto-load
|
||||||
|
:save-fn="save"
|
||||||
|
@on-fetch="() => canEdit() && fetchData.fetch()"
|
||||||
>
|
>
|
||||||
<template #form="{ data }">
|
<template #form="{ data }">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Locker')"
|
:label="t('Locker')"
|
||||||
v-model="data.locker"
|
v-model="data.id"
|
||||||
:options="lockers"
|
:options="lockers"
|
||||||
option-label="code"
|
option-label="code"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
hide-selected
|
hide-selected
|
||||||
|
:readonly="!canEdit()"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</FormModel>
|
</FormModel>
|
||||||
|
|
Loading…
Reference in New Issue