Solucion a comentarios 4
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
1d37b91e09
commit
081d4bf5fc
File diff suppressed because it is too large
Load Diff
|
@ -1,129 +1,56 @@
|
|||
<script setup>
|
||||
import { computed, onBeforeMount, ref, watch } from 'vue';
|
||||
import { reactive, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import axios from 'axios';
|
||||
|
||||
import { useState } from 'src/composables/useState';
|
||||
import { useStateStore } from 'stores/useStateStore';
|
||||
import useNotify from 'src/composables/useNotify';
|
||||
|
||||
import FormModel from 'src/components/FormModel.vue';
|
||||
import VnRow from 'components/ui/VnRow.vue';
|
||||
|
||||
const { notify } = useNotify();
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const state = useState();
|
||||
const stateStore = useStateStore();
|
||||
const route = useRoute();
|
||||
|
||||
const isLoading = ref(false);
|
||||
const extension = ref('');
|
||||
const worker = ref({});
|
||||
const workersRef = ref(null);
|
||||
const formInitialData = reactive({});
|
||||
|
||||
const hasChanged = computed(() => {
|
||||
return extension.value !== worker.value?.sip?.extension;
|
||||
});
|
||||
|
||||
onBeforeMount(() => getData(route.params.id));
|
||||
|
||||
watch(
|
||||
() => route.params.id,
|
||||
(newValue) => {
|
||||
getData(newValue);
|
||||
}
|
||||
);
|
||||
|
||||
const getData = async (id) => {
|
||||
const filter = {
|
||||
const filter = {
|
||||
include: [
|
||||
{
|
||||
relation: 'sip',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
const url = `Workers/${id}`;
|
||||
const { data } = await axios.get(url, {
|
||||
params: { filter: JSON.stringify(filter) },
|
||||
});
|
||||
extension.value = data.sip.extension;
|
||||
state.set('extension', data.sip.extension);
|
||||
worker.value = data;
|
||||
} catch (error) {
|
||||
state.set('extension', null);
|
||||
extension.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
const setInitialData = () => {
|
||||
extension.value = worker.value?.sip?.extension;
|
||||
state.set('extension', worker.value?.sip?.extension);
|
||||
};
|
||||
watch(
|
||||
() => route.params.id,
|
||||
() => state.set('extension', null)
|
||||
);
|
||||
|
||||
const onSubmit = async () => {
|
||||
isLoading.value = true;
|
||||
const onFetch = (data) => state.set('extension', data?.sip?.extension);
|
||||
|
||||
const payload = {
|
||||
extension: extension.value,
|
||||
userFk: Number(route.params.id),
|
||||
};
|
||||
try {
|
||||
await axios.patch('Sips', payload);
|
||||
notify('worker.card.dataSavedCard', 'positive');
|
||||
|
||||
if (workersRef.value) workersRef.value.fetch();
|
||||
} catch (error) {
|
||||
notify(error.error, 'negative');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const updateModelValue = () => {
|
||||
state.set('extension', extension.value);
|
||||
};
|
||||
const updateModelValue = (data) => state.set('extension', data);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="#st-actions" v-if="stateStore?.isSubToolbarShown()">
|
||||
<QBtnGroup push class="q-gutter-x-sm">
|
||||
<QBtn
|
||||
:disabled="!hasChanged"
|
||||
:label="t('globals.reset')"
|
||||
:loading="isLoading"
|
||||
@click="setInitialData"
|
||||
color="primary"
|
||||
flat
|
||||
icon="restart_alt"
|
||||
type="reset"
|
||||
/>
|
||||
<QBtn
|
||||
:disabled="!hasChanged"
|
||||
:label="t('globals.save')"
|
||||
:loading="isLoading"
|
||||
@click="onSubmit"
|
||||
color="primary"
|
||||
icon="save"
|
||||
/>
|
||||
</QBtnGroup>
|
||||
</Teleport>
|
||||
|
||||
<div class="full-width flex justify-center">
|
||||
<QCard class="card-width q-pa-lg">
|
||||
<QCardSection>
|
||||
<FormModel
|
||||
:filter="filter"
|
||||
:form-initial-data="formInitialData"
|
||||
:url="`Workers/${route.params.id}`"
|
||||
auto-load
|
||||
model="DeviceProductionUser"
|
||||
@on-fetch="onFetch"
|
||||
>
|
||||
<template #form="{ data }">
|
||||
<VnRow class="row q-gutter-md q-mb-md">
|
||||
<div class="col">
|
||||
<QInput
|
||||
:label="t('worker.summary.sipExtension')"
|
||||
v-model="extension"
|
||||
@update:model-value="updateModelValue()"
|
||||
:model-value="data?.sip?.extension"
|
||||
@update:model-value="updateModelValue"
|
||||
/>
|
||||
</div>
|
||||
</VnRow>
|
||||
</QCardSection>
|
||||
</QCard>
|
||||
</div>
|
||||
</template>
|
||||
</FormModel>
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue