- enhancing data input. allowing empty values. allowing 0 values for oversea share and tariff
This commit is contained in:
parent
88516ccfca
commit
b3fbfa7ce3
5 changed files with 45 additions and 46 deletions
|
|
@ -1,15 +1,17 @@
|
|||
export const parseNumberFromString = (value, decimals = 2) => {
|
||||
export const parseNumberFromString = (value, decimals = 2, allowZero = false) => {
|
||||
|
||||
if (typeof value === 'number') return value;
|
||||
if(typeof value === 'string' && value.trim().length === 0) return null;
|
||||
if (!value || typeof value !== 'string') return 0;
|
||||
|
||||
|
||||
/* determine decimal separator */
|
||||
const lastDot = value.lastIndexOf('.');
|
||||
const lastComma = value.lastIndexOf(',');
|
||||
const decimalSeparator = (lastDot > lastComma) ? '.' : ',';
|
||||
const hasSeperator = !(lastDot === -1 && lastComma === -1);
|
||||
const hasSeparator = !(lastDot === -1 && lastComma === -1);
|
||||
|
||||
if (hasSeperator) {
|
||||
if (hasSeparator) {
|
||||
/* remove all digit grouping */
|
||||
value = (decimalSeparator === '.') ? value.replace(',', '') : value.replace('.', '');
|
||||
|
||||
|
|
@ -23,11 +25,11 @@ export const parseNumberFromString = (value, decimals = 2) => {
|
|||
const parsed = parseFloat(normalizedValue);
|
||||
|
||||
if(parsed > 10e10)
|
||||
return 0;
|
||||
return null;
|
||||
|
||||
|
||||
if (isNaN(parsed)) return 0;
|
||||
return Math.round(parsed * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
||||
if (isNaN(parsed)) return null;
|
||||
const final = Math.round(parsed * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
||||
return (final === 0 && !allowZero) ? null : final;
|
||||
}
|
||||
|
||||
export class UrlSafeBase64 {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ export default {
|
|||
computed: {
|
||||
...mapStores(useMaterialStore, useCustomsStore),
|
||||
tariffRatePercent() {
|
||||
return this.tariffRate ? (this.tariffRate * 100).toFixed(2) : '';
|
||||
return ((this.tariffRate ?? null) !== null) ? (this.tariffRate * 100).toFixed(2) : '';
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
|
@ -134,16 +134,16 @@ export default {
|
|||
});
|
||||
},
|
||||
validateTariffRate(event) {
|
||||
const percentValue = parseNumberFromString(event.target.value, 4);
|
||||
const percentValue = parseNumberFromString(event.target.value, 2, true);
|
||||
|
||||
const validatedPercent = Math.max(0, Math.min(999.99, percentValue));
|
||||
const validatedDecimal = validatedPercent / 100;
|
||||
const validatedPercent = (percentValue === null) ? null : Math.max(0, Math.min(999.99, percentValue));
|
||||
const validatedDecimal = (validatedPercent === null) ? null : validatedPercent / 100;
|
||||
|
||||
if (validatedDecimal !== this.tariffRate) {
|
||||
this.$emit('update:tariffRate', validatedDecimal);
|
||||
}
|
||||
|
||||
event.target.value = validatedPercent.toFixed(2);
|
||||
event.target.value = validatedPercent === null ? null : validatedPercent.toFixed(2);
|
||||
},
|
||||
activateEditMode() {
|
||||
this.modalSelectMaterial = true;
|
||||
|
|
|
|||
|
|
@ -153,20 +153,15 @@ export default {
|
|||
const unitType = this.huDimensionUnits.find(unit => unit.id === value)?.value;
|
||||
const decimals = (unitType === 'cm') ? 2 : ((unitType === 'm') ? 3 : 0);
|
||||
|
||||
if (this.length) {
|
||||
const parsedLength = parseFloat(this.length.toFixed(decimals));
|
||||
const parsedLength = (this.length ?? null) === null ? null : parseFloat(this.length.toFixed(decimals));
|
||||
this.$emit('update:length', parsedLength);
|
||||
}
|
||||
|
||||
if (this.height) {
|
||||
const parsedHeight = parseFloat(this.height.toFixed(decimals));
|
||||
const parsedHeight = (this.height ?? null) === null ? null : parseFloat(this.height.toFixed(decimals));
|
||||
this.$emit('update:height', parsedHeight);
|
||||
}
|
||||
|
||||
if (this.weight) {
|
||||
const parsedWidth = parseFloat(this.width.toFixed(decimals));
|
||||
const parsedWidth = (this.width ?? null) === null ? null : parseFloat(this.width.toFixed(decimals));
|
||||
this.$emit('update:width', parsedWidth);
|
||||
}
|
||||
|
||||
|
||||
this.$emit('update:dimensionUnit', unitType);
|
||||
}
|
||||
|
|
@ -206,32 +201,31 @@ export default {
|
|||
},
|
||||
validateDimension(type, event) {
|
||||
const decimals = (this.huDimensionUnitSelected === 2) ? 2 : ((this.huDimensionUnitSelected === 3) ? 3 : 0);
|
||||
const parsed = parseNumberFromString(event.target.value, decimals);
|
||||
|
||||
const parsed = event.target.value.trim().length === 0 ? null : parseNumberFromString(event.target.value, decimals);
|
||||
|
||||
this.$emit(`update:${type}`, parsed);
|
||||
|
||||
// Force update the input field with the correctly formatted value
|
||||
const formattedValue = parsed.toFixed(decimals);
|
||||
const formattedValue = parsed ? parsed.toFixed(decimals) : '';
|
||||
const inputRef = `${type}Input`;
|
||||
this.updateInputValue(inputRef, formattedValue);
|
||||
},
|
||||
validateWeight(type, event) {
|
||||
const decimals = (this.huWeightUnitSelected === 2) ? 3 : ((this.huWeightUnitSelected === 3) ? 6 : 0);
|
||||
const parsed = parseNumberFromString(event.target.value, decimals);
|
||||
const parsed = event.target.value.trim().length === 0 ? null : parseNumberFromString(event.target.value, decimals);
|
||||
|
||||
this.$emit('update:weight', parsed);
|
||||
|
||||
// Force update the input field with the correctly formatted value
|
||||
const formattedValue = parsed.toFixed(decimals);
|
||||
const formattedValue = parsed ? parsed.toFixed(decimals) : '';
|
||||
this.updateInputValue('weightInput', formattedValue);
|
||||
},
|
||||
validateCount(event) {
|
||||
const parsed = parseNumberFromString(event.target.value, 0);
|
||||
const parsed = event.target.value.trim().length === 0 ? null : parseNumberFromString(event.target.value, 0);
|
||||
this.$emit('update:unitCount', parsed);
|
||||
|
||||
// Force update the input field with the correctly formatted value
|
||||
const formattedValue = parsed.toString();
|
||||
const formattedValue = parsed ? parsed.toString() : '';
|
||||
this.updateInputValue('unitCountInput', formattedValue);
|
||||
},
|
||||
updateStackable(value) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ export default {
|
|||
return this.price?.toFixed(2) ?? '';
|
||||
},
|
||||
overSeaSharePercent() {
|
||||
return this.overSeaShare ? (this.overSeaShare * 100).toFixed(2) : '';
|
||||
return ((this.overSeaShare ?? null) !== null) ? (this.overSeaShare * 100).toFixed(2) : '';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -66,29 +66,33 @@ export default {
|
|||
}
|
||||
},
|
||||
validatePrice(event) {
|
||||
const value = parseNumberFromString(event.target.value, 2);
|
||||
const validatedValue = Math.max(0, value);
|
||||
const value = (event.target.value.trim().length === 0) ? null : parseNumberFromString(event.target.value, 2);
|
||||
|
||||
const validatedValue = value === null ? null : Math.max(0, value);
|
||||
|
||||
if (validatedValue !== this.price) {
|
||||
this.$emit('update:price', validatedValue);
|
||||
}
|
||||
|
||||
event.target.value = validatedValue.toFixed(2);
|
||||
event.target.value = validatedValue?.toFixed(2) ?? '';
|
||||
},
|
||||
updateIncludeFcaFee(value) {
|
||||
this.$emit('update:includeFcaFee', value);
|
||||
},
|
||||
validateOverSeaShare(event) {
|
||||
const percentValue = parseNumberFromString(event.target.value, 4);
|
||||
|
||||
const validatedPercent = Math.max(0, Math.min(100, percentValue));
|
||||
const validatedDecimal = validatedPercent / 100;
|
||||
const percentValue = (event.target.value.trim().length === 0) ? null : parseNumberFromString(event.target.value, 2, true);
|
||||
|
||||
|
||||
const validatedPercent = percentValue === null ? null : Math.max(0, Math.min(100, percentValue));
|
||||
const validatedDecimal = validatedPercent === null ? null :validatedPercent / 100;
|
||||
|
||||
if (validatedDecimal !== this.overSeaShare) {
|
||||
this.$emit('update:overSeaShare', validatedDecimal);
|
||||
}
|
||||
|
||||
event.target.value = validatedPercent.toFixed(2);
|
||||
|
||||
event.target.value = validatedPercent?.toFixed(2) ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,17 +169,16 @@ export default {
|
|||
success = await this.premiseEditStore.savePackaging();
|
||||
}
|
||||
|
||||
console.log("save success: ", success);
|
||||
|
||||
if(success) {
|
||||
this.$refs.toast.addToast({
|
||||
icon: 'floppy-disk',
|
||||
message: `Changes on ${type} saved.`,
|
||||
|
||||
variant: 'primary',
|
||||
duration: 3000
|
||||
})
|
||||
}
|
||||
// if(success) {
|
||||
// this.$refs.toast.addToast({
|
||||
// icon: 'floppy-disk',
|
||||
// message: `Changes on ${type} saved.`,
|
||||
//
|
||||
// variant: 'primary',
|
||||
// duration: 3000
|
||||
// })
|
||||
// }
|
||||
|
||||
},
|
||||
updateMaterial(id, action) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue