From 867f807f810070f6160f397b33db350247484e0c Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:37:06 +0600 Subject: [PATCH] Fixed: Vendor Subscription Product commission value Type Incorrectly Assigned --- .../commission/AdminCommission.vue | 4 +- src/admin/components/CombineInput.vue | 53 +++++++------------ 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/assets/src/js/setup-wizard/commission/AdminCommission.vue b/assets/src/js/setup-wizard/commission/AdminCommission.vue index 9295f94c71..50b6c5700f 100644 --- a/assets/src/js/setup-wizard/commission/AdminCommission.vue +++ b/assets/src/js/setup-wizard/commission/AdminCommission.vue @@ -76,10 +76,10 @@ fixedCOmmissionhandler(data) { if (data.fixed === '') { - data.fixed = this.fixedCommission.fixed ?? 0; + data.fixed = 0; } if (data.percentage === '') { - data.percentage = this.fixedCommission.percentage ?? 0; + data.percentage = 0; } this.fixedCommission = data; diff --git a/src/admin/components/CombineInput.vue b/src/admin/components/CombineInput.vue index f4951985ab..9f41c6cf20 100644 --- a/src/admin/components/CombineInput.vue +++ b/src/admin/components/CombineInput.vue @@ -9,8 +9,8 @@ ref="percentage" :id="percentageId" :name="percentageName" - v-model="percentage" - v-on:input="onInput" + :value="formatPositiveValue( value.percentage ?? '' )" + v-on:input="( e ) => onInput(e.target.value, 'percentage')" style="border: none !important;" />
@@ -69,28 +69,6 @@ import Debounce from "debounce"; } }, }, - data() { - return { - fixed: this.formatPositiveValue( this.value.fixed ) ?? '', - percentage: this.formatPositiveValue( this.value.percentage ) ?? '' - }; - }, - watch: { - value: { - handler(newVal, oldVal) { - let newPercentage = this.validatePercentage( newVal.percentage ); - let oldPercentage = this.validatePercentage( oldVal.percentage ); - - if ( ! newPercentage || '' === newPercentage || Number( newPercentage ) < 0 || Number( newPercentage ) > 100 ) { - newPercentage = oldPercentage; - } - - this.fixed = this.formatPositiveValue( newVal.fixed ); - this.percentage = this.formatPositiveValue( newPercentage ); - }, - deep: true - } - }, methods: { validatePercentage( percentage ) { if ( Number( percentage ) < 0 || Number( percentage ) > 100 ) { @@ -99,19 +77,28 @@ import Debounce from "debounce"; return percentage; }, - onInput: Debounce( function() { + validateNegative( value ) { + if ( Number( value ) < 0 ) { + value = ''; + } + + return value; + }, + + onInput: Debounce( function( currentValue, type ) { let self = this; - let data = { - fixed: self.fixed ? accounting.unformat(self.fixed, dokan.currency.decimal) : '', - percentage: self.percentage ? accounting.unformat(self.percentage, dokan.currency.decimal): '' - }; + let data = JSON.parse( JSON.stringify( { ...self.value }) ); + data[ type ] = '' !== currentValue ? String( currentValue ) : ''; + + data.fixed = '' !== data.fixed ? self.validateNegative( accounting.unformat( data.fixed, dokan.currency.decimal ) ) : ''; + data.percentage = '' !== data.percentage ? self.validateNegative( self.validatePercentage( accounting.unformat( data.percentage, dokan.currency.decimal ) ) ) : ''; this.$emit('change', data); }, 500 ), formatPositiveValue: ( value ) => { - if ( value === '' ) { - return value; + if ( undefined === value || value === '' ) { + return ''; } return accounting.formatNumber( value, dokan.currency.precision, dokan.currency.thousand, dokan.currency.decimal );