@tagplus/components 4.0.0 → 4.0.1

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": "4.0.0",
11
+ "version": "4.0.1",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -14,6 +14,11 @@ export default {
14
14
  allowEmpty: {
15
15
  type: Boolean,
16
16
  default: false
17
+ },
18
+
19
+ valorCusto: {
20
+ type: Boolean,
21
+ default: false
17
22
  }
18
23
  },
19
24
 
@@ -28,21 +33,21 @@ export default {
28
33
  immediate: true,
29
34
  handler (newValue, oldValue) {
30
35
  if (newValue === '' && this.allowEmpty) { this.formattedValue = ''; return }
31
- this.formattedValue = formatMoney(newValue, true, this.locale)
36
+ this.formattedValue = formatMoney(newValue, true, this.locale, this.valorCusto)
32
37
  }
33
38
  }
34
39
  },
35
40
 
36
41
  methods: {
37
42
  input (evt) {
38
- this.formattedValue = formatMoney(evt, true, this.locale)
39
- const moneyFormatado = formatMoney(evt, false, this.locale)
43
+ this.formattedValue = formatMoney(evt, true, this.locale, this.valorCusto)
44
+ const moneyFormatado = formatMoney(evt, false, this.locale, this.valorCusto)
40
45
 
41
46
  this.$emit('input', moneyFormatado)
42
47
  },
43
48
 
44
49
  handleChange (evt) {
45
- this.$emit('change', formatMoney(evt, false, this.locale))
50
+ this.$emit('change', formatMoney(evt, false, this.locale, this.valorCusto))
46
51
  }
47
52
  }
48
53
 
@@ -21,7 +21,7 @@ function format (input, opt = defaults) {
21
21
  }
22
22
 
23
23
  function unformat (input, precision = defaults.precision) {
24
- const negative = (`${ input}`).indexOf('-') >= 0 ? -1 : 1
24
+ const negative = (`${input}`).indexOf('-') >= 0 ? -1 : 1
25
25
  const numbers = onlyNumbers(input)
26
26
  const currency = numbersToCurrency(numbers, precision)
27
27
 
@@ -36,8 +36,8 @@ function unformat (input, precision = defaults.precision) {
36
36
  * @param {Object} locale Configuração de localidade para saber número de casas decimais (precision) e caracter de decimal (decimal)
37
37
  * @returns
38
38
  */
39
- function formatMoney (input, toString = false, locale = defaults) {
40
- let inputString = (`${ input}`)
39
+ function formatMoney (input, toString = false, locale = defaults, valorCusto = false) {
40
+ let inputString = (`${input}`)
41
41
 
42
42
  // Impede de digitar . ou , porque o formatador já adiciona
43
43
  if ((inputString.slice(-1).match(/[.,]/))) {
@@ -50,12 +50,12 @@ function formatMoney (input, toString = false, locale = defaults) {
50
50
  input = completeZeros(inputString, locale)
51
51
  }
52
52
 
53
- const precision = locale.number.precision
53
+ const precision = valorCusto ? 3 : locale.number.precision
54
54
  const numbers = onlyNumbers(input, precision)
55
55
  const currency = numbersToCurrency(numbers, precision)
56
56
 
57
57
  if (toString) {
58
- let num = negative === -1 ? `-${ currency}` : `${ currency}`
58
+ let num = negative === -1 ? `-${currency}` : `${currency}`
59
59
 
60
60
  if (locale?.number?.decimal) {
61
61
  const decimalChar = locale?.number?.decimal