forked from verdnatura/salix-front
feat: addRow withour dialog
This commit is contained in:
parent
0e5e7c3fda
commit
ebf329bfc6
|
@ -45,6 +45,10 @@ const $props = defineProps({
|
|||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
createAsDialog: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
cardClass: {
|
||||
type: String,
|
||||
default: 'flex-one',
|
||||
|
@ -239,6 +243,11 @@ defineExpose({
|
|||
redirect: redirectFn,
|
||||
selected,
|
||||
});
|
||||
|
||||
function handleOnDataSaved(_, res) {
|
||||
if (_.onDataSaved) _.onDataSaved(this);
|
||||
else $props.create.onDataSaved(_);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<QDrawer
|
||||
|
@ -556,8 +565,16 @@ defineExpose({
|
|||
</template>
|
||||
</CrudModel>
|
||||
</div>
|
||||
<QPageSticky v-if="create" :offset="[20, 20]" style="z-index: 2">
|
||||
<QBtn @click="showForm = !showForm" color="primary" fab icon="add" />
|
||||
<QPageSticky :offset="[20, 20]" style="z-index: 2">
|
||||
<QBtn
|
||||
@click="
|
||||
() =>
|
||||
createAsDialog ? (showForm = !showForm) : handleOnDataSaved(create)
|
||||
"
|
||||
color="primary"
|
||||
fab
|
||||
icon="add"
|
||||
/>
|
||||
<QTooltip>
|
||||
{{ create.title }}
|
||||
</QTooltip>
|
||||
|
@ -566,7 +583,7 @@ defineExpose({
|
|||
<FormModelPopup
|
||||
v-bind="create"
|
||||
:model="$attrs['data-key'] + 'Create'"
|
||||
@on-data-saved="(_, res) => create.onDataSaved(res)"
|
||||
@on-data-saved="handleOnDataSaved"
|
||||
>
|
||||
<template #form-inputs="{ data }">
|
||||
<div class="grid-create">
|
||||
|
|
|
@ -192,6 +192,10 @@ const columns = computed(() => [
|
|||
field: 'warehouseFk',
|
||||
name: 'warehouseFk',
|
||||
...defaultColumnAttrs,
|
||||
component: 'select',
|
||||
attrs: {
|
||||
options: warehousesOptions,
|
||||
},
|
||||
},
|
||||
{
|
||||
align: 'right',
|
||||
|
@ -230,16 +234,19 @@ const validations = (row, rowIndex, col) => {
|
|||
);
|
||||
};
|
||||
|
||||
async function upsertFixedPrice(row) {
|
||||
try {
|
||||
const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row);
|
||||
return data;
|
||||
} catch (err) {
|
||||
console.error('Error editing 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,
|
||||
});
|
||||
};
|
||||
|
||||
const upsertPrice = async ({ row, col, rowIndex }, resetMinPrice = false) => {
|
||||
if (!validations(row, rowIndex, col)) return;
|
||||
// if (!validations(row, rowIndex, col)) return;
|
||||
|
||||
try {
|
||||
if (resetMinPrice) row.hasMinPrice = 0;
|
||||
|
@ -249,6 +256,14 @@ const upsertPrice = async ({ row, col, rowIndex }, resetMinPrice = false) => {
|
|||
console.error('Error editing price', err);
|
||||
}
|
||||
};
|
||||
async function upsertFixedPrice(row) {
|
||||
try {
|
||||
const { data } = await axios.patch('FixedPrices/upsertFixedPrice', row);
|
||||
return data;
|
||||
} catch (err) {
|
||||
console.error('Error editing price', err);
|
||||
}
|
||||
}
|
||||
async function saveOnRowChange(row) {
|
||||
if (rowsSelected.value.length > 1) return;
|
||||
if (rowsSelected.value[0]?.id === row.id) return;
|
||||
|
@ -299,24 +314,24 @@ function checkLastVisibleRow() {
|
|||
}
|
||||
const addRow = (fixedPrice = null) => {
|
||||
const lastvisible = checkLastVisibleRow();
|
||||
if (!fixedPrices.value || fixedPrices.value.length === 0) {
|
||||
fixedPrices.value = [];
|
||||
// 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;
|
||||
// }
|
||||
if (fixedPrice) {
|
||||
lastItem.value = fixedPrice;
|
||||
return;
|
||||
|
@ -326,7 +341,7 @@ const addRow = (fixedPrice = null) => {
|
|||
JSON.stringify(fixedPrices.value[fixedPrices.value.length - 1])
|
||||
);
|
||||
lastItem.value = lastItemCopy;
|
||||
// tableRef.value.create.formInitialData = lastItem;
|
||||
tableRef.value.create.formInitialData = lastItem;
|
||||
delete lastItemCopy.id;
|
||||
fixedPricesOriginalData.value.splice(lastvisible, 0, lastItemCopy);
|
||||
fixedPrices.value.unshift(lastItemCopy);
|
||||
|
@ -523,7 +538,7 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
|||
{{ row.name }}
|
||||
</span>
|
||||
<ItemDescriptorProxy :id="row.itemFk" />
|
||||
<FetchedTags style="width: 200px" :item="row" :max-length="6" />
|
||||
<FetchedTags style="max-width: 220px" :item="row" :max-length="6" />
|
||||
</QTd>
|
||||
</template>
|
||||
<template #column-rate2="props">
|
||||
|
@ -556,8 +571,8 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
|||
<QCheckbox
|
||||
:model-value="props.row.hasMinPrice"
|
||||
@update:model-value="updateMinPrice($event, props)"
|
||||
:true-value="'true'"
|
||||
:false-value="'false'"
|
||||
:false-value="0"
|
||||
:true-value="1"
|
||||
/>
|
||||
<VnInput
|
||||
class="col"
|
||||
|
@ -640,12 +655,6 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
|||
</QTd>
|
||||
</template>
|
||||
</VnTable>
|
||||
<QPageSticky :offset="[20, 0]">
|
||||
<QBtn @click="addRow()" color="primary" fab icon="add" />
|
||||
<QTooltip>
|
||||
{{ t('Add') }}
|
||||
</QTooltip>
|
||||
</QPageSticky>
|
||||
|
||||
<QDialog ref="editTableCellDialogRef">
|
||||
<EditTableCellValueForm
|
||||
|
@ -670,6 +679,9 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
|||
& .q-checkbox {
|
||||
& .q-checkbox__inner {
|
||||
position: relative !important;
|
||||
&.q-checkbox__inner--truthy {
|
||||
color: var(--q-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue