@tagplus/components 1.2.12 → 1.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "email": "bruno@tagplus.com.br"
9
9
  }
10
10
  ],
11
- "version": "1.2.12",
11
+ "version": "1.2.15",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -450,7 +450,7 @@ export default {
450
450
  .join(', ')
451
451
  },
452
452
 
453
- suggestionsList(_newValue, _oldValue){
453
+ suggestionsList (_newValue, _oldValue) {
454
454
  this.setSelectedLabel()
455
455
  }
456
456
  },
@@ -503,23 +503,23 @@ export default {
503
503
  },
504
504
 
505
505
  setSelectedLabel () {
506
- if (Array.isArray(this.value)) {
507
- this.value.forEach((item, key) => {
508
- this.suggestionsList.forEach(suggestion => {
509
- if (suggestion[this.valueKey] === item) {
510
- this.selectedLabelsArray.push(suggestion)
511
- }
506
+ if (Array.isArray(this.value)) {
507
+ this.value.forEach((item, key) => {
508
+ this.suggestionsList.forEach(suggestion => {
509
+ if (suggestion[this.valueKey] === item) {
510
+ this.selectedLabelsArray.push(suggestion)
511
+ }
512
+ })
512
513
  })
513
- })
514
- } else if (process.env.DEBUG === 'true') {
515
- console.log(`'${this.$options.name}' recebeu valor em formato inválido.`)
516
- }
514
+ } else if (process.env.DEBUG === 'true') {
515
+ console.log(`'${this.$options.name}' recebeu valor em formato inválido.`)
516
+ }
517
517
 
518
- this.selectedLabels = this.selectedLabelsArray
519
- .map(item => {
520
- return item[this.labelKey]
521
- })
522
- .join(', ')
518
+ this.selectedLabels = this.selectedLabelsArray
519
+ .map(item => {
520
+ return item[this.labelKey]
521
+ })
522
+ .join(', ')
523
523
  },
524
524
 
525
525
  // eslint-disable-next-line no-unused-vars
@@ -10,24 +10,30 @@ export default {
10
10
  }
11
11
  },
12
12
 
13
+ computed: {
14
+ locale () {
15
+ return this.t('locale')
16
+ }
17
+ },
18
+
13
19
  watch: {
14
20
  value: {
15
21
  immediate: true,
16
22
  handler (newValue, oldValue) {
17
- this.formattedValue = formatMoney(newValue, true)
23
+ this.formattedValue = formatMoney(newValue, true, this.locale)
18
24
  }
19
25
  }
20
26
  },
21
27
 
22
28
  methods: {
23
29
  input (evt) {
24
- this.formattedValue = formatMoney(evt, true)
25
- const moneyFormatado = formatMoney(evt, false)
30
+ this.formattedValue = formatMoney(evt, true, this.locale)
31
+ const moneyFormatado = formatMoney(evt, false, this.locale)
26
32
  this.$emit('input', moneyFormatado)
27
33
  },
28
34
 
29
35
  handleChange (evt) {
30
- this.$emit('change', formatMoney(evt, false))
36
+ this.$emit('change', formatMoney(evt, false, this.locale))
31
37
  }
32
38
  }
33
39
 
@@ -1,4 +1,5 @@
1
1
  import { messages } from 'tp-ui/locale'
2
+
2
3
  const defaults = messages().locale.number
3
4
 
4
5
  function format (input, opt = defaults) {
@@ -23,15 +24,31 @@ function unformat (input, precision = defaults.precision) {
23
24
  return currency * negative
24
25
  }
25
26
 
26
- function formatMoney (input, toString = false, precision = defaults.precision) {
27
+ /**
28
+ * Formata dinheiro para float sem arredondar ou para string garantindo decimais completos (.00) e respeitando caracter de decimal
29
+ * @author gteixeira
30
+ * @param {Float} input Valor
31
+ * @param {Boolean} toString Se o retorno será float ou string
32
+ * @param {Object} locale Configuração de localidade para saber número de casas decimais (precision) e caracter de decimal (decimal)
33
+ * @returns
34
+ */
35
+ function formatMoney (input, toString = false, locale = defaults) {
27
36
  const negative = ('' + input).indexOf('-') >= 0 ? -1 : 1
37
+ const precision = locale.number.precision
38
+
28
39
  if (toString) {
29
40
  input = completeZeros(('' + input), precision)
30
41
  }
31
42
  const numbers = onlyNumbers(input, precision)
32
43
  const currency = numbersToCurrency(numbers, precision)
33
44
  if (toString) {
34
- return negative === -1 ? '-' + currency : '' + currency
45
+ let num = negative === -1 ? '-' + currency : '' + currency
46
+ if (locale?.number?.decimal) {
47
+ const decimalChar = locale?.number?.decimal
48
+ num = num.replaceAll(',', decimalChar).replaceAll('.', decimalChar)
49
+ }
50
+
51
+ return num
35
52
  } else {
36
53
  return currency * negative
37
54
  }