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>
|
<script setup>
|
||||||
import { computed, onBeforeMount, ref, watch } from 'vue';
|
import { reactive, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
import { useState } from 'src/composables/useState';
|
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';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
|
|
||||||
const { notify } = useNotify();
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
|
||||||
const state = useState();
|
const state = useState();
|
||||||
const stateStore = useStateStore();
|
const route = useRoute();
|
||||||
|
|
||||||
const isLoading = ref(false);
|
const formInitialData = reactive({});
|
||||||
const extension = ref('');
|
|
||||||
const worker = ref({});
|
|
||||||
const workersRef = ref(null);
|
|
||||||
|
|
||||||
const hasChanged = computed(() => {
|
const filter = {
|
||||||
return extension.value !== worker.value?.sip?.extension;
|
include: [
|
||||||
});
|
{
|
||||||
|
relation: 'sip',
|
||||||
onBeforeMount(() => getData(route.params.id));
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => route.params.id,
|
() => route.params.id,
|
||||||
(newValue) => {
|
() => state.set('extension', null)
|
||||||
getData(newValue);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const getData = async (id) => {
|
const onFetch = (data) => state.set('extension', data?.sip?.extension);
|
||||||
const filter = {
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
relation: 'sip',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
const updateModelValue = (data) => state.set('extension', data);
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSubmit = async () => {
|
|
||||||
isLoading.value = true;
|
|
||||||
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Teleport to="#st-actions" v-if="stateStore?.isSubToolbarShown()">
|
<FormModel
|
||||||
<QBtnGroup push class="q-gutter-x-sm">
|
:filter="filter"
|
||||||
<QBtn
|
:form-initial-data="formInitialData"
|
||||||
:disabled="!hasChanged"
|
:url="`Workers/${route.params.id}`"
|
||||||
:label="t('globals.reset')"
|
auto-load
|
||||||
:loading="isLoading"
|
model="DeviceProductionUser"
|
||||||
@click="setInitialData"
|
@on-fetch="onFetch"
|
||||||
color="primary"
|
>
|
||||||
flat
|
<template #form="{ data }">
|
||||||
icon="restart_alt"
|
<VnRow class="row q-gutter-md q-mb-md">
|
||||||
type="reset"
|
<div class="col">
|
||||||
/>
|
<QInput
|
||||||
<QBtn
|
:label="t('worker.summary.sipExtension')"
|
||||||
:disabled="!hasChanged"
|
:model-value="data?.sip?.extension"
|
||||||
:label="t('globals.save')"
|
@update:model-value="updateModelValue"
|
||||||
:loading="isLoading"
|
/>
|
||||||
@click="onSubmit"
|
</div>
|
||||||
color="primary"
|
</VnRow>
|
||||||
icon="save"
|
</template>
|
||||||
/>
|
</FormModel>
|
||||||
</QBtnGroup>
|
|
||||||
</Teleport>
|
|
||||||
|
|
||||||
<div class="full-width flex justify-center">
|
|
||||||
<QCard class="card-width q-pa-lg">
|
|
||||||
<QCardSection>
|
|
||||||
<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()"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</VnRow>
|
|
||||||
</QCardSection>
|
|
||||||
</QCard>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue