fix: #6896 OrderCatalogItem actions
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Javier Segarra 2024-11-30 01:35:25 +01:00
parent 0e1552f962
commit 0f0d906e08
1 changed files with 34 additions and 19 deletions

View File

@ -1,41 +1,53 @@
<script setup> <script setup>
import toCurrency from '../../../filters/toCurrency'; import toCurrency from '../../../filters/toCurrency';
import { ref } from 'vue'; import { inject, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import axios from 'axios'; import axios from 'axios';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import useNotify from 'composables/useNotify'; import useNotify from 'composables/useNotify';
import { useArrayData } from 'composables/useArrayData'; import { useArrayData } from 'composables/useArrayData';
import VnInputNumber from 'src/components/common/VnInputNumber.vue';
const { t } = useI18n(); const { t } = useI18n();
const { notify } = useNotify(); const { notify } = useNotify();
const emit = defineEmits(['added']); const emit = defineEmits(['added']);
const route = useRoute(); const route = useRoute();
const props = defineProps({ const props = defineProps({
prices: { item: {
type: Array, type: Array,
required: true, required: true,
}, },
}); });
const onItemSaved = inject('onItemSaved');
const fields = ref((props.prices || []).map((item) => ({ ...item, quantity: 0 }))); const prices = ref((props.item.prices || []).map((item) => ({ ...item, quantity: 0 })));
const descriptorData = useArrayData('orderData'); const descriptorData = useArrayData('orderData');
const isLoading = ref(false); const isLoading = ref(false);
const addToOrder = async () => { const addToOrder = async () => {
if (isLoading.value) return; if (isLoading.value) return;
isLoading.value = true; isLoading.value = true;
const items = (fields.value || []).filter((item) => Number(item.quantity) > 0); const items = (prices.value || []).filter((item) => Number(item.quantity) > 0);
await axios.post('/OrderRows/addToOrder', { await axios.post('/OrderRows/addToOrder', {
items, items,
orderFk: Number(route.params.id), orderFk: Number(route.params.id),
}); });
notify(t('globals.dataSaved'), 'positive'); notify(t('globals.dataSaved'), 'positive');
emit('added'); await descriptorData.fetch({});
descriptorData.fetch({}); onItemSaved({ ...props, items, saved: true });
emit('added', items);
isLoading.value = false; isLoading.value = false;
}; };
const canAddToOrder = () => { const canAddToOrder = () => {
return (fields.value || []).some((item) => Number(item.quantity) > 0); let canAddToOrder = (prices.value || []).some((price) => Number(price.quantity) > 0);
if (canAddToOrder) {
const excedQuantity = prices.value.reduce(
(acc, { quantity }) => acc + quantity,
0
);
if (excedQuantity > props.item.available) {
canAddToOrder = false;
}
}
return canAddToOrder;
}; };
</script> </script>
@ -44,30 +56,33 @@ const canAddToOrder = () => {
<QForm @submit="addToOrder"> <QForm @submit="addToOrder">
<QMarkupTable class="shadow-0"> <QMarkupTable class="shadow-0">
<tbody> <tbody>
<tr v-for="item in fields" :key="item.warehouse"> <tr v-for="price in prices" :key="price.warehouse">
<td class="text-bold q-pr-md td" style="width: 35%"> <td class="text-bold q-pr-md td" style="width: 35%">
{{ item.warehouse }} {{ price.warehouse }}
</td> </td>
<td class="text-right" style="width: 35%"> <td class="text-right" style="width: 35%">
<span <span
class="link" class="link"
@click=" @click.shift="
() => { () => {
item.quantity += item.grouping; price.quantity -= price.grouping;
}
"
@click.exact="
() => {
price.quantity += price.grouping;
} }
" "
> >
{{ item.grouping }} {{ price.grouping }}
</span> </span>
x {{ toCurrency(item.price) }} x {{ toCurrency(price.price) }}
</td> </td>
<td class="text-right"> <td class="text-right">
<QInput <VnInputNumber
v-model.number="item.quantity" v-model.number="price.quantity"
type="number" :step="price.grouping"
:step="item.grouping"
min="0" min="0"
dense
/> />
</td> </td>
</tr> </tr>