#7283 #7831 itemMigration #553

Merged
carlossa merged 77 commits from 7283-itemMigration into dev 2024-10-25 07:09:13 +00:00
2 changed files with 89 additions and 181 deletions
Showing only changes of commit 589ee629cf - Show all commits

View File

@ -2,25 +2,15 @@
import { onMounted, ref, reactive, computed, onUnmounted, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { toDate } from 'src/filters';
import FetchData from 'components/FetchData.vue';
import FetchedTags from 'components/ui/FetchedTags.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import VnInputDate from 'src/components/common/VnInputDate.vue';
import EditTableCellValueForm from 'src/components/EditTableCellValueForm.vue';
import ItemFixedPriceFilter from './ItemFixedPriceFilter.vue';
import ItemDescriptorProxy from './Card/ItemDescriptorProxy.vue';
import VnTable from 'components/VnTable/VnTable.vue';
import { useStateStore } from 'stores/useStateStore';
import { dashIfEmpty } from 'src/filters';
import { useVnConfirm } from 'composables/useVnConfirm';
import { useState } from 'src/composables/useState';
import { toCurrency } from 'filters/index';
import useNotify from 'src/composables/useNotify.js';
import axios from 'axios';
import { useArrayData } from 'composables/useArrayData';
import { isLower, isBigger } from 'src/filters/date.js';
import RightMenu from 'src/components/common/RightMenu.vue';
const stateStore = useStateStore();
const { t } = useI18n();
@ -75,39 +65,6 @@ watch(
(data) => onFixedPricesFetched(data)
);
const applyColumnFilter = async (col) => {
try {
const paramKey = col.columnFilter?.filterParamKey || col.field;
params[paramKey] = col.columnFilter.filterValue;
await arrayData.addFilter({ params });
} catch (err) {
console.error('Error applying column filter', err);
}
};
const getColumnInputEvents = (col) => {
return col.columnFilter.type === 'select'
? { 'update:modelValue': () => applyColumnFilter(col) }
: {
'keyup.enter': () => applyColumnFilter(col),
};
};
const defaultColumnFilter = {
component: VnInput,
type: 'text',
filterValue: null,
event: getColumnInputEvents,
attrs: {
dense: true,
},
};
const defaultColumnAttrs = {
align: 'left',
sortable: true,
};
const columns = computed(() => [
{
label: t('item.fixedPrice.itemId'),
@ -127,12 +84,14 @@ const columns = computed(() => [
{
label: t('item.fixedPrice.groupingPrice'),
name: 'rate2',
component: 'input',
align: 'left',
create: true,
},
{
label: t('item.fixedPrice.packingPrice'),
name: 'rate3',
component: 'input',
align: 'left',
create: true,
},
@ -140,6 +99,7 @@ const columns = computed(() => [
{
label: t('item.fixedPrice.minPrice'),
name: 'minPrice',
component: 'input',
align: 'left',
create: true,
},
@ -188,70 +148,14 @@ const columns = computed(() => [
},
]);
const editTableFieldsOptions = [
{
field: 'rate2',
label: t('item.fixedPrice.groupingPrice'),
component: 'input',
attrs: {
type: 'number',
},
},
{
field: 'rate3',
label: t('item.fixedPrice.packingPrice'),
component: 'input',
attrs: {
type: 'number',
},
},
{
field: 'minPrice',
label: t('item.fixedPrice.minPrice'),
component: 'input',
attrs: {
type: 'number',
},
},
{
field: 'hasMinPrice',
label: t('item.fixedPrice.hasMinPrice'),
component: 'checkbox',
attrs: {
'false-value': 0,
'true-value': 1,
},
},
{
field: 'started',
label: t('item.fixedPrice.started'),
component: 'date',
},
{
field: 'ended',
label: t('item.fixedPrice.ended'),
component: 'date',
},
{
field: 'warehouseFk',
label: t('item.fixedPrice.warehouse'),
component: 'select',
attrs: {
options: [],
'option-label': 'name',
'option-value': 'id',
},
},
];
const getRowUpdateInputEvents = (props, resetMinPrice, inputType = 'text') => {
return inputType === 'text'
? {
'keyup.enter': () => upsertPrice(props, resetMinPrice),
blur: () => upsertPrice(props, resetMinPrice),
}
: { 'update:modelValue': () => upsertPrice(props, resetMinPrice) };
};
// const getRowUpdateInputEvents = (props, resetMinPrice, inputType = 'text') => {
// return inputType === 'text'
// ? {
// 'keyup.enter': () => upsertPrice(props, resetMinPrice),
// blur: () => upsertPrice(props, resetMinPrice),
// }
// : { 'update:modelValue': () => upsertPrice(props, resetMinPrice) };
// };
const validations = (row, rowIndex, col) => {
const isNew = !row.id;
@ -281,81 +185,73 @@ const upsertPrice = async ({ row, col, rowIndex }, resetMinPrice = false) => {
}
};
const addRow = () => {
if (!fixedPrices.value || fixedPrices.value.length === 0) {
fixedPrices.value = [];
// const addRow = () => {
// if (!fixedPrices.value || fixedPrices.value.length === 0) {
// fixedPrices.value = [];
const today = Date.vnNew();
const millisecsInDay = 86400000;
const daysInWeek = 7;
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
// const today = Date.vnNew();
// const millisecsInDay = 86400000;
// const daysInWeek = 7;
// const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
const newPrice = {
started: today,
ended: nextWeek,
hasMinPrice: 0,
};
// const newPrice = {
// started: today,
// ended: nextWeek,
// hasMinPrice: 0,
// };
fixedPricesOriginalData.value.push({ ...newPrice });
fixedPrices.value.push({ ...newPrice });
return;
}
// fixedPricesOriginalData.value.push({ ...newPrice });
// fixedPrices.value.push({ ...newPrice });
// return;
// }
const lastItemCopy = JSON.parse(
JSON.stringify(fixedPrices.value[fixedPrices.value.length - 1])
);
delete lastItemCopy.id;
fixedPricesOriginalData.value.push(lastItemCopy);
fixedPrices.value.push(lastItemCopy);
};
// const lastItemCopy = JSON.parse(
// JSON.stringify(fixedPrices.value[fixedPrices.value.length - 1])
// );
// delete lastItemCopy.id;
// fixedPricesOriginalData.value.push(lastItemCopy);
// fixedPrices.value.push(lastItemCopy);
// };
const openEditTableCellDialog = () => {
editTableCellDialogRef.value.show();
};
// const openEditTableCellDialog = () => {
// editTableCellDialogRef.value.show();
// };
const onEditCellDataSaved = async () => {
rowsSelected.value = [];
await fetchFixedPrices();
};
// const onEditCellDataSaved = async () => {
// rowsSelected.value = [];
// await fetchFixedPrices();
// };
const onWarehousesFetched = (data) => {
warehousesOptions.value = data;
// Actualiza las 'options' del elemento con field 'warehouseFk' en 'editTableFieldsOptions'.
const warehouseField = editTableFieldsOptions.find(
(field) => field.field === 'warehouseFk'
);
warehouseField.attrs.options = data;
};
// const onWarehousesFetched = (data) => {
// warehousesOptions.value = data;
// // Actualiza las 'options' del elemento con field 'warehouseFk' en 'editTableFieldsOptions'.
// const warehouseField = editTableFieldsOptions.find(
// (field) => field.field === 'warehouseFk'
// );
// warehouseField.attrs.options = data;
// };
const removePrice = async (id, rowIndex) => {
try {
await axios.delete(`FixedPrices/${id}`);
fixedPrices.value.splice(rowIndex, 1);
fixedPricesOriginalData.value.splice(rowIndex, 1);
notify(t('globals.dataSaved'), 'positive');
} catch (err) {
console.error('Error removing price', err);
}
};
// const removePrice = async (id, rowIndex) => {
// try {
// await axios.delete(`FixedPrices/${id}`);
// fixedPrices.value.splice(rowIndex, 1);
// fixedPricesOriginalData.value.splice(rowIndex, 1);
// notify(t('globals.dataSaved'), 'positive');
// } catch (err) {
// console.error('Error removing price', err);
// }
// };
const updateMinPrice = async (value, props) => {
// El checkbox hasMinPrice se encuentra en la misma columna que el input hasMinPrice
// Por lo tanto le mandamos otro objeto con las mismas propiedades pero con el campo 'field' cambiado
props.row.hasMinPrice = value;
await upsertPrice({
row: props.row,
col: { field: 'hasMinPrice' },
rowIndex: props.rowIndex,
});
};
onMounted(async () => {
stateStore.rightDrawer = true;
params.warehouseFk = user.value.warehouseFk;
await fetchFixedPrices();
});
onUnmounted(() => (stateStore.rightDrawer = false));
// const updateMinPrice = async (value, props) => {
// // El checkbox hasMinPrice se encuentra en la misma columna que el input hasMinPrice
// // Por lo tanto le mandamos otro objeto con las mismas propiedades pero con el campo 'field' cambiado
// props.row.hasMinPrice = value;
// await upsertPrice({
// row: props.row,
// col: { field: 'hasMinPrice' },
// rowIndex: props.rowIndex,
// });
// };
</script>
<template>
@ -372,13 +268,13 @@ onUnmounted(() => (stateStore.rightDrawer = false));
order="id ASC"
:columns="columns"
auto-load
:is-editable="false"
:is-editable="true"
:use-model="true"
>
<template #column-description="{ row }">
<div class="row column full-width justify-between items-start">
{{ row?.description }}
<div v-if="row?.description" class="subName">
{{ row?.name }}
<div v-if="row?.subName" class="subName">
{{ row?.subName.toUpperCase() }}
</div>
</div>
@ -386,7 +282,12 @@ onUnmounted(() => (stateStore.rightDrawer = false));
</template>
</VnTable>
</template>
<style lang="scss" scoped>
.subName {
text-transform: uppercase;
color: var(--vn-label-color);
}
</style>
<i18n>
es:
Add fixed price: Añadir precio fijado

View File

@ -100,6 +100,7 @@ const columns = computed(() => [
{
label: t('item.buyRequest.state'),
name: 'state',
action: (row) => getState(row.isOk),
align: 'left',
},
{
@ -146,7 +147,6 @@ const confirmRequest = async (request) => {
`TicketRequests/${request.id}/confirm`,
params
);
request.itemDescription = data.concept;
request.isOk = true;
notify(t('globals.dataSaved'), 'positive');
@ -338,15 +338,22 @@ onBeforeMount(() => {
url="ticketRequests/filter"
order="id DESC"
:columns="columns"
:is-editable="false"
:is-editable="true"
auto-load
>
<template #column-attender="{ row }">
<template #column-attenderName="{ row }">
<span class="link" @click.stop>
{{ row }}
{{ row.attenderName }}
<WorkerDescriptorProxy :id="row.attenderFk" />
</span>
</template>
<template #column-requesterName="{ row }">
<span class="link" @click.stop>
{{ row.requesterName }}
<WorkerDescriptorProxy :id="row.requesterFk" />
</span>
</template>
</VnTable>
</template>