diff --git a/src/pages/Item/components/ItemProposal.vue b/src/pages/Item/components/ItemProposal.vue index 144787b85..43196eb2d 100644 --- a/src/pages/Item/components/ItemProposal.vue +++ b/src/pages/Item/components/ItemProposal.vue @@ -10,29 +10,6 @@ import notifyResults from 'src/utils/notifyResults'; const MATCH_VALUES = [5, 6, 7, 8]; const { t } = useI18n(); -const extractNumericValue = (percentageString) => { - const match = percentageString.match(/(\d+(\.\d+)?)/); - return match ? parseFloat(match[0]) : null; -}; -const compatibilityItem = (value) => `${100 * (value / MATCH_VALUES.length)}%`; -const gradientStyle = (value) => { - let color = 'white'; - const perc = extractNumericValue(compatibilityItem(value)); - switch (true) { - case perc >= 0 && perc < 33: - color = 'orange'; - break; - case perc >= 33 && perc < 66: - color = 'yellow'; - break; - - default: - color = 'green'; - break; - } - return color; -}; -const tagColor = (match) => `color: ${!match ? 'red' : 'var(--vn-label-color)'}`; const $props = defineProps({ itemLack: { type: Object, @@ -52,20 +29,17 @@ const $props = defineProps({ }); const proposalSelected = ref([]); const quantity = ref(-1); +const sale = computed(() => $props.sales[0]); +const saleFk = computed(() => sale.value.saleFk); +const filter = computed(() => ({ + itemFk: $props.itemLack.itemFk, + sales: saleFk.value, +})); +const proposalTableRef = ref(null); const defaultColumnAttrs = { align: 'center', sortable: false, }; -const sale = computed(() => $props.sales[0]); -const saleFk = computed(() => sale.value.saleFk); -const statusConditionalValue = (row) => { - const total = MATCH_VALUES.reduce((acc, i) => acc + row[`match${i}`], 0); - return total; -}; -const proposalTableRef = ref(null); -const emit = defineEmits(['onDialogClosed', 'itemReplaced']); - -const conditionalValuePrice = (price) => (price > 1.3 ? 'match' : 'not-match'); const columns = computed(() => [ { ...defaultColumnAttrs, @@ -157,8 +131,44 @@ const columns = computed(() => [ field: 'located', }, ]); + +const extractNumericValue = (percentageString) => { + const match = percentageString.match(/(\d+(\.\d+)?)/); + return match ? parseFloat(match[0]) : null; +}; +const compatibilityItem = (value) => `${100 * (value / MATCH_VALUES.length)}%`; + +const gradientStyle = (value) => { + let color = 'white'; + const perc = extractNumericValue(compatibilityItem(value)); + switch (true) { + case perc >= 0 && perc < 33: + color = 'orange'; + break; + case perc >= 33 && perc < 66: + color = 'yellow'; + break; + + default: + color = 'green'; + break; + } + return color; +}; +const tagColor = (match) => `color: ${!match ? 'red' : 'var(--vn-label-color)'}`; + +const statusConditionalValue = (row) => { + const total = MATCH_VALUES.reduce((acc, i) => acc + row[`match${i}`], 0); + return total; +}; + +const emit = defineEmits(['onDialogClosed', 'itemReplaced']); + +const conditionalValuePrice = (price) => (price > 1.3 ? 'match' : 'not-match'); + const isSelected = (row) => proposalSelected.value.some((item) => row.itemFk === item.itemFk); + function change(row) { if (isSelected(row)) { confirm(row); @@ -166,6 +176,7 @@ function change(row) { } proposalSelected.value = [row]; } + async function confirm() { try { const substitutionFk = proposalSelected.value[0].itemFk; @@ -190,10 +201,7 @@ async function confirm() { console.error(error); } } -const filter = computed(() => ({ - itemFk: $props.itemLack.itemFk, - sales: saleFk.value, -})); + const isSelectionAvailable = (itemProposal) => { const { price2 } = itemProposal; const salePrice = sale.value.price; @@ -276,8 +284,9 @@ const isSelectionAvailable = (itemProposal) => {