Kaynağa Gözat

[ADD] unformat input currency value for calculate

Gogs 7 yıl önce
ebeveyn
işleme
5ae217b8aa

+ 8 - 1
src/components/filters/currency.js

@@ -1,4 +1,7 @@
-const currency = (value = '0', symbol = '$', symbolPosition = 'before', thousandsSeparator = '.', decimalPlaces = 2, decimalSeparator = ',') => {
+/**
+ * 
+ */
+const currency = (value = '0', symbol = '$', symbolPosition = 'before', thousandsSeparator = '.', decimalPlaces = 2, decimalSeparator = ',', decimalZeros = false) => {
     if (!(value instanceof String)) {
         value = value.toString()
     }
@@ -13,6 +16,10 @@ const currency = (value = '0', symbol = '$', symbolPosition = 'before', thousand
 
     value = value.join(decimalSeparator)
 
+    if (!decimalZeros) {
+        value = value.replace(/([\.|,]\d)0$/, '$1')
+    }
+
     return symbolPosition === 'before' ? `${symbol} ${value}` : `${value} ${symbol}`
 }
 

+ 8 - 8
src/components/steps/PaymentAmount.vue

@@ -41,17 +41,17 @@
         computed: {
             amountReceived: {
                 get() {
-                    return this.$options.filters.currency(this.initialPayment)
+                    let formatted = this.$options.filters.currency(this.initialPayment)
+
+                    return !!this.initialPayment ? formatted : formatted.replace(/\d/, '')
                 },
                 set(value) {
-                    // value = Number.isNaN(value) ? 0 : value
-
-                    // this.changeInitialPayment(value)
-                    // this.computePaymentResidual(value)
+                    value = value.replace(/[\.|,](\d{0,2}$)/, '?$1').split(/\?/)
+                    value[0] = value[0].replace(/[^0-9]/g, '')
+                    value = Number.parseFloat(value.join('.')) || 0
 
-                    // if (this.paymentType === 'credit') {
-                    //     this.computePaymentLines()
-                    // }
+                    this.changeInitialPayment(value)
+                    this.computePaymentResidual(value)
                 }
             },
             ...mapGetters([

+ 0 - 1
src/store/modules/payment.js

@@ -217,7 +217,6 @@ const actions = {
      * @param {*} payload 
      */
     [CHANGE_INITIAL_PAYMENT] ({ commit }, payload) {
-        console.log('changePaymentTerm', payload)
         commit(SET_INITIAL_PAYMENT, payload)
     },
     /**