forked from verdnatura/salix-front
feat: remove future itemFixedPrices
This commit is contained in:
parent
8a4b3302cf
commit
77c7a9e03a
|
@ -1,6 +1,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref, reactive, computed, onUnmounted, watch, nextTick } from 'vue';
|
import { onMounted, ref, reactive, onUnmounted, watch, nextTick } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import FetchedTags from 'components/ui/FetchedTags.vue';
|
import FetchedTags from 'components/ui/FetchedTags.vue';
|
||||||
|
@ -21,7 +22,9 @@ import axios from 'axios';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
import { isLower, isBigger } from 'src/filters/date.js';
|
import { isLower, isBigger } from 'src/filters/date.js';
|
||||||
import RightMenu from 'src/components/common/RightMenu.vue';
|
import RightMenu from 'src/components/common/RightMenu.vue';
|
||||||
|
import { QCheckbox } from 'quasar';
|
||||||
|
|
||||||
|
const checked = ref(false);
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { openConfirmationModal } = useVnConfirm();
|
const { openConfirmationModal } = useVnConfirm();
|
||||||
|
@ -302,7 +305,7 @@ async function saveOnRowChange(_, row) {
|
||||||
}
|
}
|
||||||
const tableRef = ref();
|
const tableRef = ref();
|
||||||
function checkLastVisibleRow() {
|
function checkLastVisibleRow() {
|
||||||
const tableBody = tableRef.value.$el.querySelector('tbody.q-virtual-scroll__content');
|
const tableBody = tableRef.value.$el.querySelector('tbody');
|
||||||
if (!tableBody) return;
|
if (!tableBody) return;
|
||||||
const rows = tableBody.querySelectorAll('tr');
|
const rows = tableBody.querySelectorAll('tr');
|
||||||
let lastVisibleRow = null;
|
let lastVisibleRow = null;
|
||||||
|
@ -351,7 +354,7 @@ const addRow = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
function highlightNewRow(index) {
|
function highlightNewRow(index) {
|
||||||
const tableBody = tableRef.value.$el.querySelector('tbody.q-virtual-scroll__content');
|
const tableBody = tableRef.value.$el.querySelector('tbody');
|
||||||
const row = tableBody.querySelectorAll('tr')[index];
|
const row = tableBody.querySelectorAll('tr')[index];
|
||||||
if (row) {
|
if (row) {
|
||||||
row.classList.add('highlight');
|
row.classList.add('highlight');
|
||||||
|
@ -365,11 +368,15 @@ const openEditTableCellDialog = () => {
|
||||||
};
|
};
|
||||||
async function showBadDates() {
|
async function showBadDates() {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get('FixedPrices/filter', {
|
if (!checked.value) fixedPrices.value = fixedPricesOriginalData.value;
|
||||||
params: {
|
else {
|
||||||
showBadDates: true,
|
const { data } = await axios.get('FixedPrices/filter', {
|
||||||
},
|
params: {
|
||||||
});
|
showBadDates: checked.value,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
fixedPrices.value = data;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
@ -388,6 +395,16 @@ const onWarehousesFetched = (data) => {
|
||||||
warehouseField.attrs.options = data;
|
warehouseField.attrs.options = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeFuturePrice = async () => {
|
||||||
|
try {
|
||||||
|
rowsSelected.value.forEach(({ id }) => {
|
||||||
|
const rowIndex = fixedPrices.value.findIndex((r) => r.id === id);
|
||||||
|
removePrice(id, rowIndex);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error removing price', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
const removePrice = async (id, rowIndex) => {
|
const removePrice = async (id, rowIndex) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`FixedPrices/${id}`);
|
await axios.delete(`FixedPrices/${id}`);
|
||||||
|
@ -399,10 +416,6 @@ const removePrice = async (id, rowIndex) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function onScroll({ to, ref }) {
|
|
||||||
console.log(to, ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateMinPrice = async (value, props) => {
|
const updateMinPrice = async (value, props) => {
|
||||||
// El checkbox hasMinPrice se encuentra en la misma columna que el input hasMinPrice
|
// 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
|
// Por lo tanto le mandamos otro objeto con las mismas propiedades pero con el campo 'field' cambiado
|
||||||
|
@ -438,12 +451,20 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</RightMenu>
|
</RightMenu>
|
||||||
|
<VnSubToolbar>
|
||||||
|
<template #st-data>
|
||||||
|
<QCheckbox
|
||||||
|
size="sm"
|
||||||
|
v-model="checked"
|
||||||
|
:label="t(`Show future items`)"
|
||||||
|
@update:model-value="showBadDates"
|
||||||
|
>
|
||||||
|
</QCheckbox>
|
||||||
|
</template>
|
||||||
|
</VnSubToolbar>
|
||||||
<QPage class="column items-center q-pa-md">
|
<QPage class="column items-center q-pa-md">
|
||||||
{{ rowsSelected }}
|
|
||||||
<QTable
|
<QTable
|
||||||
ref="tableRef"
|
ref="tableRef"
|
||||||
@virtual-scroll="onScroll"
|
|
||||||
virtual-scroll
|
|
||||||
dense
|
dense
|
||||||
:rows="fixedPrices"
|
:rows="fixedPrices"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
|
@ -454,7 +475,6 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
||||||
class="full-width q-mt-md"
|
class="full-width q-mt-md"
|
||||||
:no-data-label="t('globals.noResults')"
|
:no-data-label="t('globals.noResults')"
|
||||||
@row-click="saveOnRowChange"
|
@row-click="saveOnRowChange"
|
||||||
:virtual-scroll-item-size="48"
|
|
||||||
>
|
>
|
||||||
<template #top-row="{ cols }">
|
<template #top-row="{ cols }">
|
||||||
<QTr>
|
<QTr>
|
||||||
|
@ -489,6 +509,19 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
||||||
{{ t('Add fixed price') }}
|
{{ t('Add fixed price') }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
</QIcon>
|
</QIcon>
|
||||||
|
<!-- <QIcon
|
||||||
|
v-if="!(checked && rowsSelected.length > 0)"
|
||||||
|
v-else-if="tableRef?.rows?.length > 0"
|
||||||
|
@click.stop="removeFuturePrice()"
|
||||||
|
class="fill-icon-on-hover"
|
||||||
|
color="primary"
|
||||||
|
name="delete"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<QTooltip>
|
||||||
|
{{ t('Add fixed price') }}
|
||||||
|
</QTooltip>
|
||||||
|
</QIcon>-->
|
||||||
</QTh>
|
</QTh>
|
||||||
<QTh
|
<QTh
|
||||||
v-for="col in props.cols"
|
v-for="col in props.cols"
|
||||||
|
@ -593,7 +626,6 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
||||||
:show-event="false"
|
:show-event="false"
|
||||||
v-model="props.row.started"
|
v-model="props.row.started"
|
||||||
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
||||||
:options="(date) => date > props.row.ended"
|
|
||||||
v-bind="
|
v-bind="
|
||||||
isBigger(props.row.started)
|
isBigger(props.row.started)
|
||||||
? {
|
? {
|
||||||
|
@ -611,7 +643,6 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
||||||
style="max-width: 125px"
|
style="max-width: 125px"
|
||||||
:show-event="false"
|
:show-event="false"
|
||||||
v-model="props.row.ended"
|
v-model="props.row.ended"
|
||||||
:options="isLower(props.row.started)"
|
|
||||||
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
||||||
v-bind="
|
v-bind="
|
||||||
isLower(props.row.started)
|
isLower(props.row.started)
|
||||||
|
@ -673,24 +704,38 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
||||||
</QTd>
|
</QTd>
|
||||||
</template>
|
</template>
|
||||||
</QTable>
|
</QTable>
|
||||||
<QPageSticky :offset="[20, 20]">
|
<QPageSticky :offset="[20, 0]">
|
||||||
<QBtn @click="showBadDates()" color="primary" fab icon="edit" />
|
|
||||||
<QTooltip>
|
|
||||||
{{ t('Edit fixed price(s)') }}
|
|
||||||
</QTooltip>
|
|
||||||
</QPageSticky>
|
|
||||||
<QPageSticky :offset="[20, -20]">
|
|
||||||
<QBtn @click="addRow()" color="primary" fab icon="add" />
|
<QBtn @click="addRow()" color="primary" fab icon="add" />
|
||||||
<QTooltip>
|
<QTooltip>
|
||||||
{{ t('Add') }}
|
{{ t('Add') }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
</QPageSticky>
|
</QPageSticky>
|
||||||
<QPageSticky v-if="rowsSelected.length" :offset="[20, 20]">
|
<QPageSticky v-if="rowsSelected.length" :offset="[20, 60]">
|
||||||
<QBtn @click="openEditTableCellDialog()" color="primary" fab icon="edit" />
|
<QBtn @click="openEditTableCellDialog()" color="primary" fab icon="edit" />
|
||||||
<QTooltip>
|
<QTooltip>
|
||||||
{{ t('Edit fixed price(s)') }}
|
{{ t('Edit fixed price(s)') }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
</QPageSticky>
|
</QPageSticky>
|
||||||
|
<QPageSticky
|
||||||
|
:offset="[20, 120]"
|
||||||
|
v-if="tableRef?.rows?.length > 0 && checked && rowsSelected.length > 0"
|
||||||
|
>
|
||||||
|
<QBtn
|
||||||
|
color="primary"
|
||||||
|
fab
|
||||||
|
icon="delete"
|
||||||
|
@click.stop="
|
||||||
|
openConfirmationModal(
|
||||||
|
t('This row will be removed'),
|
||||||
|
t('Do you want to clone this item?'),
|
||||||
|
() => removeFuturePrice()
|
||||||
|
)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
<QTooltip>
|
||||||
|
{{ t('Add') }}
|
||||||
|
</QTooltip>
|
||||||
|
</QPageSticky>
|
||||||
<QDialog ref="editTableCellDialogRef">
|
<QDialog ref="editTableCellDialogRef">
|
||||||
<EditTableCellValueForm
|
<EditTableCellValueForm
|
||||||
edit-url="FixedPrices/editFixedPrice"
|
edit-url="FixedPrices/editFixedPrice"
|
||||||
|
@ -712,27 +757,6 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
||||||
}
|
}
|
||||||
/* height or max-height is important */
|
/* height or max-height is important */
|
||||||
|
|
||||||
.q-table__top,
|
|
||||||
.q-table__bottom,
|
|
||||||
tbody tr:first-child td {
|
|
||||||
/* bg color is important for th; just specify one */
|
|
||||||
background-color: #00b4ff;
|
|
||||||
}
|
|
||||||
thead tr th {
|
|
||||||
position: sticky;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
thead tr:first-child th {
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* this is when the loading indicator appears */
|
|
||||||
|
|
||||||
/* prevent scrolling behind sticky top row on focus */
|
|
||||||
tbody
|
|
||||||
/* height of all previous header rows */ {
|
|
||||||
scroll-margin-top: 148px;
|
|
||||||
}
|
|
||||||
tbody tr.highlight .q-td {
|
tbody tr.highlight .q-td {
|
||||||
animation: highlight-animation 4s ease-in-out;
|
animation: highlight-animation 4s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue