forked from verdnatura/salix-front
WIP
This commit is contained in:
parent
6c4901076f
commit
b22d54f490
|
@ -1,7 +1,7 @@
|
|||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import VnInput from 'components/common/VnInput.vue';
|
||||
import isValidDate from "filters/isValidDate";
|
||||
import isValidDate from 'filters/isValidDate';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
|
|
|
@ -9,6 +9,8 @@ import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
|
|||
import VnInputDate from 'src/components/common/VnInputDate.vue';
|
||||
import EditTableCellValueForm from 'src/components/EditTableCellValueForm.vue';
|
||||
import ItemFixedPriceFilter from './ItemFixedPriceFilter.vue';
|
||||
// TODO: mostrar item descriptor en fetchedtags
|
||||
import ItemDescriptorProxy from './Card/ItemDescriptorProxy.vue';
|
||||
|
||||
import { useStateStore } from 'stores/useStateStore';
|
||||
import { dashIfEmpty } from 'src/filters';
|
||||
|
@ -25,7 +27,7 @@ const { openConfirmationModal } = useVnConfirm();
|
|||
const state = useState();
|
||||
const { notify } = useNotify();
|
||||
|
||||
const fixedPricesFetchRef = ref(null);
|
||||
// const fixedPricesFetchRef = ref(null);
|
||||
const editTableCellDialogRef = ref(null);
|
||||
const user = state.getUser();
|
||||
const fixedPrices = ref([]);
|
||||
|
@ -59,9 +61,19 @@ const arrayData = useArrayData('ItemFixedPrices', {
|
|||
});
|
||||
const store = arrayData.store;
|
||||
|
||||
const fetchFixedPrices = async () => {
|
||||
await arrayData.fetch({ append: false });
|
||||
};
|
||||
|
||||
const onFixedPricesFetched = (data) => {
|
||||
fixedPrices.value = data;
|
||||
// el objetivo de guardar una copia de las rows es evitar guardar cambios si la data no cambió al disparar los eventos
|
||||
fixedPricesOriginalData.value = JSON.parse(JSON.stringify(data));
|
||||
};
|
||||
|
||||
watch(
|
||||
() => store.data,
|
||||
(value) => (fixedPrices.value = value)
|
||||
(data) => onFixedPricesFetched(data)
|
||||
);
|
||||
|
||||
const applyColumnFilter = async (col) => {
|
||||
|
@ -261,12 +273,6 @@ const editTableFieldsOptions = [
|
|||
},
|
||||
];
|
||||
|
||||
const onFixedPricesFetched = (data) => {
|
||||
fixedPrices.value = data;
|
||||
// el objetivo de esto es guardar los valores iniciales de todas las rows para evitar guardar cambios si la data no cambió al disparar los eventos
|
||||
fixedPricesOriginalData.value = JSON.parse(JSON.stringify(data));
|
||||
};
|
||||
|
||||
const getRowUpdateInputEvents = (props, resetMinPrice, inputType = 'text') => {
|
||||
return inputType === 'text'
|
||||
? {
|
||||
|
@ -309,7 +315,6 @@ const addRow = () => {
|
|||
fixedPrices.value = [];
|
||||
|
||||
const today = Date.vnNew();
|
||||
|
||||
const millisecsInDay = 86400000;
|
||||
const daysInWeek = 7;
|
||||
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
|
||||
|
@ -317,10 +322,12 @@ const addRow = () => {
|
|||
fixedPricesOriginalData.value.push({
|
||||
started: today,
|
||||
ended: nextWeek,
|
||||
hasMinPrice: 0,
|
||||
});
|
||||
fixedPrices.value.push({
|
||||
started: today,
|
||||
ended: nextWeek,
|
||||
hasMinPrice: 0,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -339,7 +346,7 @@ const openEditTableCellDialog = () => {
|
|||
|
||||
const onEditCellDataSaved = async () => {
|
||||
rowsSelected.value = [];
|
||||
await fixedPricesFetchRef.value.fetch();
|
||||
await fetchFixedPrices();
|
||||
};
|
||||
|
||||
const onWarehousesFetched = (data) => {
|
||||
|
@ -373,11 +380,34 @@ const updateMinPrice = async (value, props) => {
|
|||
});
|
||||
};
|
||||
|
||||
const isLower = (date) => {
|
||||
// TODO: APLICAR ESTO A CHIPS A LAS FECHAS DE ENDED DATE
|
||||
let today = Date.vnNew();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
date = new Date(date);
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
const timeDifference = today - date;
|
||||
if (timeDifference > 0) return 'warning';
|
||||
};
|
||||
|
||||
const isBigger = (date) => {
|
||||
// TODO: APLICAR ESTO A CHIPS A LAS FECHAS DE STARTED DATE
|
||||
let today = Date.vnNew();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
date = new Date(date);
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
const timeDifference = today - date;
|
||||
if (timeDifference < 0) return 'warning';
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
stateStore.rightDrawer = true;
|
||||
params.warehouseFk = user.value.warehouseFk;
|
||||
const { data } = await arrayData.fetch({ append: false });
|
||||
onFixedPricesFetched(data);
|
||||
await fetchFixedPrices();
|
||||
});
|
||||
|
||||
onUnmounted(() => (stateStore.rightDrawer = false));
|
||||
|
@ -524,7 +554,7 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
|||
<QTd class="col" style="min-width: 150px">
|
||||
<VnInputDate
|
||||
v-model="props.row.started"
|
||||
v-on="getRowUpdateInputEvents(props)"
|
||||
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
||||
/>
|
||||
</QTd>
|
||||
</template>
|
||||
|
@ -532,7 +562,7 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
|||
<QTd class="col" style="min-width: 150px">
|
||||
<VnInputDate
|
||||
v-model="props.row.ended"
|
||||
v-on="getRowUpdateInputEvents(props)"
|
||||
v-on="getRowUpdateInputEvents(props, false, 'date')"
|
||||
/>
|
||||
</QTd>
|
||||
</template>
|
||||
|
@ -544,7 +574,7 @@ onUnmounted(() => (stateStore.rightDrawer = false));
|
|||
option-label="name"
|
||||
option-value="id"
|
||||
v-model="props.row.warehouseFk"
|
||||
v-on="getRowUpdateInputEvents(props)"
|
||||
v-on="getRowUpdateInputEvents(props, false, 'select')"
|
||||
/>
|
||||
</QTd>
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue