@ecomplus/storefront-components 1.0.0-beta.193 → 1.0.0-beta.195
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/CHANGELOG.md +10 -0
- package/LICENSE +21 -0
- package/dist/1.storefront-components.min.js.map +1 -1
- package/dist/2.storefront-components.min.js.map +1 -1
- package/dist/3.storefront-components.min.js.map +1 -1
- package/dist/storefront-components.min.js.map +1 -1
- package/package.json +3 -2
- package/src/js/AddressForm.js +43 -25
- package/src/js/InputDocNumber.js +20 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomplus/storefront-components",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.195",
|
|
4
4
|
"description": "Vue components for E-Com Plus Storefront",
|
|
5
5
|
"main": "dist/storefront-components.min.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,5 +49,6 @@
|
|
|
49
49
|
"vue": "2.6.14",
|
|
50
50
|
"vue-cleave-component": "^2.1.3",
|
|
51
51
|
"vue-social-sharing": "^3.0.9"
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "7bd93207fb4aabba3ee8811f764db781771e227f"
|
|
53
54
|
}
|
package/src/js/AddressForm.js
CHANGED
|
@@ -113,37 +113,55 @@ export default {
|
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
setAddressFields (zipCode, fields) {
|
|
117
|
+
if (zipCode === this.localAddress.zip) {
|
|
118
|
+
fields.forEach(([field, value]) => {
|
|
119
|
+
this.$set(this.localAddress, field, value || '')
|
|
120
|
+
this.$set(this.addressFromZip, field, Boolean(value))
|
|
121
|
+
})
|
|
122
|
+
this.$nextTick(() => {
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
if (this.$refs.inputNumber) {
|
|
125
|
+
this.$refs.inputNumber.select()
|
|
126
|
+
}
|
|
127
|
+
}, 300)
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
fetchAddressInfo (zipCode) {
|
|
117
133
|
if (zipCode === this.localAddress.zip) {
|
|
118
134
|
this.zipLoading = zipCode
|
|
119
|
-
axios.get(`https://
|
|
135
|
+
axios.get(`https://brasilapi.com.br/api/cep/v2/${zipCode}`, { timeout: 4000 })
|
|
120
136
|
.then(({ data }) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
].forEach(([field, value]) => {
|
|
128
|
-
this.$set(this.localAddress, field, value || '')
|
|
129
|
-
this.$set(this.addressFromZip, field, Boolean(value))
|
|
130
|
-
})
|
|
131
|
-
this.$nextTick(() => {
|
|
132
|
-
setTimeout(() => {
|
|
133
|
-
if (this.$refs.inputNumber) {
|
|
134
|
-
this.$refs.inputNumber.select()
|
|
135
|
-
}
|
|
136
|
-
}, 300)
|
|
137
|
-
})
|
|
138
|
-
}
|
|
137
|
+
this.setAddressFields(zipCode, [
|
|
138
|
+
['province_code', data.state],
|
|
139
|
+
['city', data.city],
|
|
140
|
+
['borough', data.neighborhood],
|
|
141
|
+
['street', data.street]
|
|
142
|
+
])
|
|
139
143
|
})
|
|
140
144
|
.catch(err => {
|
|
141
145
|
console.error(err)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
axios.get(`https://viacep.com.br/ws/${zipCode}/json/`, { timeout: 4000 })
|
|
148
|
+
.then(({ data }) => {
|
|
149
|
+
if (!data.erro) {
|
|
150
|
+
this.setAddressFields(zipCode, [
|
|
151
|
+
['province_code', data.uf],
|
|
152
|
+
['city', data.localidade],
|
|
153
|
+
['borough', data.bairro],
|
|
154
|
+
['street', data.logradouro]
|
|
155
|
+
])
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
.catch(e => console.error(e))
|
|
159
|
+
.finally(() => {
|
|
160
|
+
if (zipCode === this.zipLoading) {
|
|
161
|
+
this.zipLoading = null
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
}, 300)
|
|
147
165
|
})
|
|
148
166
|
.finally(() => {
|
|
149
167
|
if (zipCode === this.zipLoading) {
|
package/src/js/InputDocNumber.js
CHANGED
|
@@ -22,37 +22,40 @@ export default {
|
|
|
22
22
|
type: [String, Number],
|
|
23
23
|
required: true
|
|
24
24
|
},
|
|
25
|
-
isCompany: Boolean
|
|
25
|
+
isCompany: Boolean,
|
|
26
|
+
allowBoth: Boolean
|
|
26
27
|
},
|
|
27
28
|
|
|
28
29
|
computed: {
|
|
29
30
|
placeholder () {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (countryCode === 'BR') {
|
|
32
|
+
if (this.allowBoth) return 'CPF / CNPJ'
|
|
33
|
+
return this.isCompany ? 'CNPJ' : 'CPF'
|
|
34
|
+
}
|
|
35
|
+
return i18n(i19docNumber)
|
|
35
36
|
},
|
|
36
37
|
|
|
37
38
|
pattern () {
|
|
38
39
|
if (countryCode === 'BR') {
|
|
39
|
-
if (this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return '[\\d]{3}\\..{10}'
|
|
43
|
-
}
|
|
40
|
+
if (this.allowBoth) return '[\\d]{11}|[\\d]{14}'
|
|
41
|
+
if (this.isCompany) return '[\\d]{2}\\..{15}'
|
|
42
|
+
return '[\\d]{3}\\..{10}'
|
|
44
43
|
}
|
|
45
44
|
return '[\\d]+{9,19}'
|
|
46
45
|
},
|
|
47
46
|
|
|
48
47
|
isInvalid () {
|
|
49
48
|
if (countryCode === 'BR') {
|
|
50
|
-
const docNumber = this.localValue.toString().replace(
|
|
49
|
+
const docNumber = this.localValue.toString().replace(/\D/g, '')
|
|
50
|
+
if (this.allowBoth) {
|
|
51
|
+
if (docNumber.length === 11) return !validateCPF(this.localValue)
|
|
52
|
+
if (docNumber.length === 14) return !validateCNPJ(this.localValue)
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
const docNumberLegacy = this.localValue.toString().replace(/D/g, '')
|
|
51
56
|
if (this.isCompany) {
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
} else if (docNumber.length === 11) {
|
|
57
|
+
if (docNumberLegacy.length === 14) return !validateCNPJ(this.localValue)
|
|
58
|
+
} else if (docNumberLegacy.length === 11) {
|
|
56
59
|
return !validateCPF(this.localValue)
|
|
57
60
|
}
|
|
58
61
|
}
|
|
@@ -69,6 +72,7 @@ export default {
|
|
|
69
72
|
},
|
|
70
73
|
|
|
71
74
|
cleaveOptions () {
|
|
75
|
+
if (this.allowBoth) return { blocks: [30] }
|
|
72
76
|
return countryCode === 'BR'
|
|
73
77
|
? this.isCompany
|
|
74
78
|
? { blocks: [2, 3, 3, 4, 2], delimiters: ['.', '.', '/', '-'] }
|