forked from verdnatura/salix-front
ZoneWarehouses and ZoneWareousesCreate refactor
This commit is contained in:
parent
e38f3fc60d
commit
78e81c6f75
|
@ -1,33 +1,20 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
|
||||||
|
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
import VnRow from 'components/ui/VnRow.vue';
|
||||||
import FormPopup from 'components/FormPopup.vue';
|
import FormPopup from 'components/FormPopup.vue';
|
||||||
|
|
||||||
import axios from 'axios';
|
const emit = defineEmits(['onSubmitCreateWarehouse']);
|
||||||
|
|
||||||
const emit = defineEmits(['onSubmit']);
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
|
||||||
|
|
||||||
const ZoneWarehouseFormData = reactive({
|
const ZoneWarehouseFormData = reactive({
|
||||||
warehouseFk: null,
|
warehouseFk: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const warehousesOptions = ref([]);
|
const warehousesOptions = ref([]);
|
||||||
|
|
||||||
const createZoneWarehouse = () => {
|
|
||||||
try {
|
|
||||||
axios.post(`Zones/${route.params.id}/warehouses`, ZoneWarehouseFormData);
|
|
||||||
emit('onSubmit');
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -37,7 +24,10 @@ const createZoneWarehouse = () => {
|
||||||
auto-load
|
auto-load
|
||||||
@on-fetch="(data) => (warehousesOptions = data)"
|
@on-fetch="(data) => (warehousesOptions = data)"
|
||||||
/>
|
/>
|
||||||
<FormPopup model="ZoneWarehouse" @on-submit="createZoneWarehouse()">
|
<FormPopup
|
||||||
|
model="ZoneWarehouse"
|
||||||
|
@on-submit="emit('onSubmitCreateWarehouse', ZoneWarehouseFormData)"
|
||||||
|
>
|
||||||
<template #form-inputs>
|
<template #form-inputs>
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<VnRow class="row q-gutter-md q-mb-md">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
|
@ -17,12 +17,11 @@ const { openConfirmationModal } = useVnConfirm();
|
||||||
const paginateRef = ref(null);
|
const paginateRef = ref(null);
|
||||||
const createWarehouseDialogRef = ref(null);
|
const createWarehouseDialogRef = ref(null);
|
||||||
|
|
||||||
const arrayData = useArrayData('ZoneWarehouses', {
|
const arrayData = useArrayData('ZoneWarehouses');
|
||||||
url: `Zones/${route.params.id}/warehouses`,
|
|
||||||
filter: { include: 'warehouse' },
|
|
||||||
});
|
|
||||||
const store = arrayData.store;
|
const store = arrayData.store;
|
||||||
|
|
||||||
|
const data = computed(() => store.data);
|
||||||
|
|
||||||
const urlPath = computed(() => `Zones/${route.params.id}/warehouses`);
|
const urlPath = computed(() => `Zones/${route.params.id}/warehouses`);
|
||||||
|
|
||||||
const columns = computed(() => [
|
const columns = computed(() => [
|
||||||
|
@ -34,17 +33,23 @@ const columns = computed(() => [
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const deleteWarehouse = async (row, rows, rowIndex) => {
|
const deleteWarehouse = async (row) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`${urlPath.value}/${row.id}`);
|
await axios.delete(`${urlPath.value}/${row.id}`);
|
||||||
if (rowIndex || rowIndex === 0) rows.splice(rowIndex, 1);
|
fetchWarehouses();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const openCreateWarehouseForm = () => {
|
const createZoneWarehouse = async (ZoneWarehouseFormData) => {
|
||||||
createWarehouseDialogRef.value.show();
|
console.log(ZoneWarehouseFormData);
|
||||||
|
try {
|
||||||
|
await axios.post(urlPath.value, ZoneWarehouseFormData);
|
||||||
|
fetchWarehouses();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
@ -57,6 +62,8 @@ watch(
|
||||||
);
|
);
|
||||||
|
|
||||||
const fetchWarehouses = () => paginateRef.value.fetch();
|
const fetchWarehouses = () => paginateRef.value.fetch();
|
||||||
|
|
||||||
|
const openCreateWarehouseForm = () => createWarehouseDialogRef.value.show();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -70,7 +77,7 @@ const fetchWarehouses = () => paginateRef.value.fetch();
|
||||||
auto-load
|
auto-load
|
||||||
>
|
>
|
||||||
<template #body="{ rows }">
|
<template #body="{ rows }">
|
||||||
<QTable :rows="rows" :columns="columns" hide-header>
|
<QTable :rows="data" :columns="columns" hide-header>
|
||||||
<template #body="{ row, rowIndex }">
|
<template #body="{ row, rowIndex }">
|
||||||
<QTr>
|
<QTr>
|
||||||
<QTd>
|
<QTd>
|
||||||
|
@ -101,12 +108,12 @@ const fetchWarehouses = () => paginateRef.value.fetch();
|
||||||
</template>
|
</template>
|
||||||
</VnPaginate>
|
</VnPaginate>
|
||||||
</div>
|
</div>
|
||||||
|
<QDialog ref="createWarehouseDialogRef">
|
||||||
|
<ZoneCreateWarehouse @on-submit-create-warehouse="createZoneWarehouse" />
|
||||||
|
</QDialog>
|
||||||
<QPageSticky position="bottom-right" :offset="[18, 18]">
|
<QPageSticky position="bottom-right" :offset="[18, 18]">
|
||||||
<QBtn fab icon="add" color="primary" @click="openCreateWarehouseForm()">
|
<QBtn fab icon="add" color="primary" @click="openCreateWarehouseForm()">
|
||||||
<QTooltip>{{ t('warehouses.add') }}</QTooltip>
|
<QTooltip>{{ t('warehouses.add') }}</QTooltip>
|
||||||
<QDialog ref="createWarehouseDialogRef">
|
|
||||||
<ZoneCreateWarehouse @on-submit="fetchWarehouses()" />
|
|
||||||
</QDialog>
|
|
||||||
</QBtn>
|
</QBtn>
|
||||||
</QPageSticky>
|
</QPageSticky>
|
||||||
</QPage>
|
</QPage>
|
||||||
|
|
Loading…
Reference in New Issue