@ecomplus/storefront-components 1.0.0-beta.19 → 1.0.0-beta.191
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/.version +0 -0
- package/CHANGELOG.md +1333 -135
- package/all.js +3 -1
- package/dist/1.storefront-components.min.js +2 -0
- package/dist/1.storefront-components.min.js.map +1 -0
- package/dist/2.storefront-components.min.js +5 -0
- package/dist/2.storefront-components.min.js.map +1 -0
- package/dist/3.storefront-components.min.js +5 -0
- package/dist/3.storefront-components.min.js.map +1 -0
- package/dist/storefront-components.min.js +33 -12
- package/dist/storefront-components.min.js.map +1 -1
- package/package.json +17 -12
- package/src/APagination.vue +2 -0
- package/src/AShare.vue +2 -0
- package/src/AccountAddresses.vue +3 -0
- package/src/AccountForm.vue +3 -0
- package/src/AccountPoints.vue +3 -0
- package/src/BuyTogether.vue +3 -0
- package/src/EarnPointsProgress.vue +3 -0
- package/src/ItemCustomizations.vue +2 -0
- package/src/KitProductVariations.vue +3 -0
- package/src/PointsApplier.vue +2 -0
- package/src/ProductQuickview.vue +3 -0
- package/src/QuantitySelector.vue +3 -0
- package/src/RecommendedItems.vue +3 -0
- package/src/ShippingLine.vue +1 -0
- package/src/TheCart.vue +3 -0
- package/src/html/APagination.html +90 -0
- package/src/html/APrices.html +24 -4
- package/src/html/AShare.html +31 -0
- package/src/html/AccountAddresses.html +90 -0
- package/src/html/AccountForm.html +269 -0
- package/src/html/AccountPoints.html +39 -0
- package/src/html/AddressForm.html +9 -7
- package/src/html/BuyTogether.html +60 -0
- package/src/html/CartItem.html +86 -38
- package/src/html/CartQuickview.html +28 -5
- package/src/html/DiscountApplier.html +3 -3
- package/src/html/EarnPointsProgress.html +28 -0
- package/src/html/InputDate.html +1 -1
- package/src/html/InputDocNumber.html +1 -0
- package/src/html/InputPhone.html +1 -1
- package/src/html/InstantSearch.html +3 -3
- package/src/html/ItemCustomizations.html +14 -0
- package/src/html/KitProductVariations.html +92 -0
- package/src/html/LoginBlock.html +34 -32
- package/src/html/LoginModal.html +9 -4
- package/src/html/PaymentOption.html +7 -5
- package/src/html/PointsApplier.html +26 -0
- package/src/html/ProductCard.html +68 -8
- package/src/html/ProductGallery.html +21 -3
- package/src/html/ProductQuickview.html +64 -0
- package/src/html/ProductVariations.html +30 -3
- package/src/html/QuantitySelector.html +85 -0
- package/src/html/RecommendedItems.html +48 -0
- package/src/html/SearchEngine.html +101 -24
- package/src/html/ShippingCalculator.html +84 -3
- package/src/html/ShippingLine.html +5 -2
- package/src/html/TheAccount.html +43 -9
- package/src/html/TheCart.html +156 -0
- package/src/html/TheProduct.html +416 -138
- package/src/js/APagination.js +74 -0
- package/src/js/APicture.js +27 -7
- package/src/js/APrices.js +80 -41
- package/src/js/AShare.js +83 -0
- package/src/js/AccountAddresses.js +201 -0
- package/src/js/AccountForm.js +312 -0
- package/src/js/AccountPoints.js +63 -0
- package/src/js/AddressForm.js +80 -35
- package/src/js/BuyTogether.js +246 -0
- package/src/js/CartItem.js +67 -14
- package/src/js/CartQuickview.js +20 -1
- package/src/js/DiscountApplier.js +181 -50
- package/src/js/EarnPointsProgress.js +77 -0
- package/src/js/InputDate.js +8 -8
- package/src/js/InputDocNumber.js +20 -0
- package/src/js/ItemCustomizations.js +10 -0
- package/src/js/KitProductVariations.js +218 -0
- package/src/js/LoginBlock.js +47 -6
- package/src/js/LoginModal.js +18 -10
- package/src/js/PaymentOption.js +28 -1
- package/src/js/PointsApplier.js +110 -0
- package/src/js/ProductCard.js +115 -11
- package/src/js/ProductGallery.js +32 -12
- package/src/js/ProductQuickview.js +72 -0
- package/src/js/ProductVariations.js +76 -19
- package/src/js/QuantitySelector.js +175 -0
- package/src/js/RecommendedItems.js +178 -0
- package/src/js/SearchEngine.js +185 -55
- package/src/js/ShippingCalculator.js +176 -35
- package/src/js/ShippingLine.js +44 -5
- package/src/js/TheAccount.js +97 -6
- package/src/js/TheCart.js +146 -0
- package/src/js/TheProduct.js +387 -43
- package/src/js/helpers/add-idle-callback.js +7 -0
- package/src/js/helpers/check-form-validity.js +3 -0
- package/src/js/helpers/favorite-products.js +24 -0
- package/src/js/helpers/scroll-to-element.js +10 -0
- package/src/js/helpers/sort-apps.js +14 -0
- package/src/js/helpers/wait-storefront-info.js +21 -0
- package/src/scss/APicture.scss +2 -0
- package/src/scss/APrices.scss +13 -1
- package/src/scss/AccountAddresses.scss +27 -0
- package/src/scss/AccountForm.scss +5 -0
- package/src/scss/AccountPoints.scss +17 -0
- package/src/scss/BuyTogether.scss +38 -0
- package/src/scss/CartItem.scss +17 -1
- package/src/scss/EarnPointsProgress.scss +6 -0
- package/src/scss/InstantSearch.scss +1 -0
- package/src/scss/KitProductVariations.scss +72 -0
- package/src/scss/LoginBlock.scss +5 -0
- package/src/scss/PaymentOption.scss +10 -1
- package/src/scss/ProductCard.scss +63 -25
- package/src/scss/ProductGallery.scss +4 -2
- package/src/scss/ProductQuickview.scss +36 -0
- package/src/scss/ProductVariations.scss +20 -4
- package/src/scss/QuantitySelector.scss +39 -0
- package/src/scss/RecommendedItems.scss +28 -0
- package/src/scss/SearchEngine.scss +9 -5
- package/src/scss/ShippingCalculator.scss +42 -1
- package/src/scss/ShippingLine.scss +24 -0
- package/src/scss/TheAccount.scss +4 -0
- package/src/scss/TheCart.scss +54 -0
- package/src/scss/TheProduct.scss +146 -1
- package/webpack.config.js +20 -6
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import {
|
|
2
|
+
i19a,
|
|
3
|
+
i19birthdate,
|
|
4
|
+
i19cellphone,
|
|
5
|
+
i19companyRegistration,
|
|
6
|
+
i19contactPhone,
|
|
7
|
+
i19corporateName,
|
|
8
|
+
i19docNumber,
|
|
9
|
+
i19emailAddress,
|
|
10
|
+
i19female,
|
|
11
|
+
i19fullName,
|
|
12
|
+
i19Gender,
|
|
13
|
+
i19inscriptionNumber,
|
|
14
|
+
i19InscriptionType,
|
|
15
|
+
i19iReadAndAccept,
|
|
16
|
+
i19male,
|
|
17
|
+
i19nickname,
|
|
18
|
+
i19emailMarketingOptInMsg,
|
|
19
|
+
i19personalRegistration,
|
|
20
|
+
i19privacyPolicy,
|
|
21
|
+
i19save,
|
|
22
|
+
i19saved
|
|
23
|
+
} from '@ecomplus/i18n'
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
$ecomConfig,
|
|
27
|
+
i18n,
|
|
28
|
+
fullName as getFullName,
|
|
29
|
+
birthDate as getBirthDate,
|
|
30
|
+
phone as getPhone
|
|
31
|
+
} from '@ecomplus/utils'
|
|
32
|
+
|
|
33
|
+
import cloneDeep from 'lodash.clonedeep'
|
|
34
|
+
import checkFormValidity from './helpers/check-form-validity'
|
|
35
|
+
import InputDocNumber from './../InputDocNumber.vue'
|
|
36
|
+
import InputPhone from './../InputPhone.vue'
|
|
37
|
+
import InputDate from './../InputDate.vue'
|
|
38
|
+
|
|
39
|
+
const countryCode = $ecomConfig.get('country_code')
|
|
40
|
+
|
|
41
|
+
const { sessionStorage } = window
|
|
42
|
+
const storageKey = 'ecomCustomerAccount'
|
|
43
|
+
|
|
44
|
+
const countInvalidInputs = (attr = ':invalid') => {
|
|
45
|
+
return document.querySelectorAll(`.account-form input${attr}`).length
|
|
46
|
+
}
|
|
47
|
+
const formValidateClass = 'was-validated'
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
name: 'AccountForm',
|
|
51
|
+
|
|
52
|
+
components: {
|
|
53
|
+
InputDocNumber,
|
|
54
|
+
InputPhone,
|
|
55
|
+
InputDate
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
props: {
|
|
59
|
+
isShort: Boolean,
|
|
60
|
+
isGuestAccess: Boolean,
|
|
61
|
+
customer: {
|
|
62
|
+
type: Object,
|
|
63
|
+
default () {
|
|
64
|
+
return {}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
privacyPolicyUrl: {
|
|
68
|
+
type: String,
|
|
69
|
+
default: typeof window === 'object' ? window.privacyPolicyUrl : null
|
|
70
|
+
},
|
|
71
|
+
hasSubmitBtn: {
|
|
72
|
+
type: Boolean,
|
|
73
|
+
default: true
|
|
74
|
+
},
|
|
75
|
+
btnText: {
|
|
76
|
+
type: String,
|
|
77
|
+
default () {
|
|
78
|
+
return i18n(i19save)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
data () {
|
|
84
|
+
return {
|
|
85
|
+
localCustomer: cloneDeep(this.customer),
|
|
86
|
+
fullName: getFullName(this.customer),
|
|
87
|
+
storageInterval: null,
|
|
88
|
+
btnLabel: this.btnText,
|
|
89
|
+
isPrivacyOptIn: Boolean(this.customer._id)
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
computed: {
|
|
94
|
+
i19a: () => i18n(i19a),
|
|
95
|
+
i19birthdate: () => i18n(i19birthdate),
|
|
96
|
+
i19cellphone: () => i18n(i19cellphone),
|
|
97
|
+
i19companyRegistration: () => i18n(i19companyRegistration),
|
|
98
|
+
i19contactPhone: () => i18n(i19contactPhone),
|
|
99
|
+
i19corporateName: () => i18n(i19corporateName),
|
|
100
|
+
i19docNumber: () => i18n(i19docNumber),
|
|
101
|
+
i19emailAddress: () => i18n(i19emailAddress),
|
|
102
|
+
i19female: () => i18n(i19female),
|
|
103
|
+
i19fullName: () => i18n(i19fullName),
|
|
104
|
+
i19Gender: () => i18n(i19Gender),
|
|
105
|
+
i19inscriptionNumber: () => i18n(i19inscriptionNumber),
|
|
106
|
+
i19InscriptionType: () => i18n(i19InscriptionType),
|
|
107
|
+
i19iReadAndAccept: () => i18n(i19iReadAndAccept),
|
|
108
|
+
i19male: () => i18n(i19male),
|
|
109
|
+
i19nickname: () => i18n(i19nickname),
|
|
110
|
+
i19emailMarketingOptInMsg: () => i18n(i19emailMarketingOptInMsg),
|
|
111
|
+
i19personalRegistration: () => i18n(i19personalRegistration),
|
|
112
|
+
i19privacyPolicy: () => i18n(i19privacyPolicy),
|
|
113
|
+
|
|
114
|
+
birthdate: {
|
|
115
|
+
get () {
|
|
116
|
+
return getBirthDate(this.localCustomer)
|
|
117
|
+
},
|
|
118
|
+
set (dateStr) {
|
|
119
|
+
if (dateStr.length === 8) {
|
|
120
|
+
const dateNumber = (start, ln) => parseInt(dateStr.substr(start, ln), 10)
|
|
121
|
+
let day, month, year
|
|
122
|
+
if (countryCode === 'BR') {
|
|
123
|
+
day = dateNumber(0, 2)
|
|
124
|
+
month = dateNumber(2, 2)
|
|
125
|
+
year = dateNumber(4, 4)
|
|
126
|
+
} else {
|
|
127
|
+
day = dateNumber(6, 2)
|
|
128
|
+
month = dateNumber(4, 2)
|
|
129
|
+
year = dateNumber(0, 4)
|
|
130
|
+
}
|
|
131
|
+
const currentYear = new Date().getFullYear()
|
|
132
|
+
if (year < currentYear - 125) {
|
|
133
|
+
year = currentYear - 125
|
|
134
|
+
} else if (year > currentYear) {
|
|
135
|
+
year = currentYear
|
|
136
|
+
}
|
|
137
|
+
this.localCustomer.birth_date = { day, month, year }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
phoneNumber: {
|
|
143
|
+
get () {
|
|
144
|
+
return this.getPhoneStr(0)
|
|
145
|
+
},
|
|
146
|
+
set (phoneStr) {
|
|
147
|
+
this.localCustomer.phones[0] = this.parsePhoneStr(phoneStr)
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
secondPhoneNumber: {
|
|
152
|
+
get () {
|
|
153
|
+
return this.getPhoneStr(1)
|
|
154
|
+
},
|
|
155
|
+
set (phoneStr) {
|
|
156
|
+
const { phones } = this.localCustomer
|
|
157
|
+
phones[phones.length > 0 ? 1 : 0] = this.parsePhoneStr(phoneStr)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
methods: {
|
|
163
|
+
getPhoneStr (index = 0) {
|
|
164
|
+
const { phones } = this.localCustomer
|
|
165
|
+
if (phones[index] && phones[index].number.charAt(0) !== '*') {
|
|
166
|
+
return getPhone(this.localCustomer.phones[index])
|
|
167
|
+
}
|
|
168
|
+
return ''
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
parsePhoneStr (phoneStr) {
|
|
172
|
+
let code, number
|
|
173
|
+
if (phoneStr.charAt(0) === '+') {
|
|
174
|
+
code = parseInt(phoneStr.substr(1, 2))
|
|
175
|
+
number = phoneStr.substr(3)
|
|
176
|
+
} else {
|
|
177
|
+
number = phoneStr
|
|
178
|
+
}
|
|
179
|
+
const phoneObj = { number }
|
|
180
|
+
if (code >= 1 && code <= 999) {
|
|
181
|
+
phoneObj.country_code = code
|
|
182
|
+
}
|
|
183
|
+
return phoneObj
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
update () {
|
|
187
|
+
if (this.$el.checkValidity()) {
|
|
188
|
+
this.$emit('update:customer', this.localCustomer)
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
mergeLocalCustomer (newCustomer) {
|
|
193
|
+
for (const field in newCustomer) {
|
|
194
|
+
if (newCustomer[field]) {
|
|
195
|
+
const localValue = this.localCustomer[field]
|
|
196
|
+
if (
|
|
197
|
+
!localValue ||
|
|
198
|
+
(typeof localValue === 'object' && !Object.keys(localValue).length) ||
|
|
199
|
+
['addresses', 'orders', 'loyalty_points_entries'].includes(field)
|
|
200
|
+
) {
|
|
201
|
+
if (field === 'name') {
|
|
202
|
+
this.fullName = getFullName({
|
|
203
|
+
name: newCustomer[field]
|
|
204
|
+
})
|
|
205
|
+
} else {
|
|
206
|
+
this.localCustomer[field] = newCustomer[field]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
saveToStorage () {
|
|
214
|
+
sessionStorage.setItem(storageKey, JSON.stringify(this.localCustomer))
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
submit () {
|
|
218
|
+
this.$nextTick(() => {
|
|
219
|
+
const $form = this.$el
|
|
220
|
+
if (!countInvalidInputs('.is-invalid')) {
|
|
221
|
+
if (!this.localCustomer.display_name) {
|
|
222
|
+
this.localCustomer.display_name = this.localCustomer.name.given_name
|
|
223
|
+
}
|
|
224
|
+
if (checkFormValidity($form)) {
|
|
225
|
+
this.saveToStorage()
|
|
226
|
+
this.save()
|
|
227
|
+
} else if ($form.classList.contains(formValidateClass) && !countInvalidInputs()) {
|
|
228
|
+
this.save()
|
|
229
|
+
}
|
|
230
|
+
$form.classList.add(formValidateClass)
|
|
231
|
+
} else {
|
|
232
|
+
$form.classList.remove(formValidateClass)
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
save () {
|
|
238
|
+
this.update()
|
|
239
|
+
this.$emit('submit', this.localCustomer)
|
|
240
|
+
this.btnLabel = i18n(i19saved) + '...'
|
|
241
|
+
setTimeout(() => {
|
|
242
|
+
this.btnLabel = this.btnText
|
|
243
|
+
}, 3000)
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
watch: {
|
|
248
|
+
fullName (nameStr) {
|
|
249
|
+
const fixedFullName = nameStr.replace(/\s{2,}/g, ' ')
|
|
250
|
+
if (fixedFullName !== this.fullName) {
|
|
251
|
+
this.fullName = fixedFullName
|
|
252
|
+
} else {
|
|
253
|
+
const names = fixedFullName.trim().split(' ')
|
|
254
|
+
this.localCustomer.name = {
|
|
255
|
+
given_name: names.shift()
|
|
256
|
+
}
|
|
257
|
+
const { name } = this.localCustomer
|
|
258
|
+
if (names.length) {
|
|
259
|
+
name.family_name = names.pop()
|
|
260
|
+
if (names.length) {
|
|
261
|
+
name[name.family_name ? 'middle_name' : 'family_name'] = names.join(' ')
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
customer: {
|
|
268
|
+
handler () {
|
|
269
|
+
this.mergeLocalCustomer(this.customer)
|
|
270
|
+
},
|
|
271
|
+
deep: true
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
localCustomer: {
|
|
275
|
+
handler () {
|
|
276
|
+
if (this.isGuestAccess) {
|
|
277
|
+
this.$nextTick(this.update)
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
deep: true
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
created () {
|
|
285
|
+
const sessionCustomer = JSON.parse(sessionStorage.getItem(storageKey))
|
|
286
|
+
if (sessionCustomer) {
|
|
287
|
+
this.mergeLocalCustomer(sessionCustomer)
|
|
288
|
+
}
|
|
289
|
+
this.storageInterval = setInterval(() => {
|
|
290
|
+
if (Object.keys(this.localCustomer).length) {
|
|
291
|
+
this.saveToStorage()
|
|
292
|
+
}
|
|
293
|
+
}, 7000)
|
|
294
|
+
if (!this.localCustomer._id) {
|
|
295
|
+
this.localCustomer.accepts_marketing = true
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
mounted () {
|
|
300
|
+
const $inputs = this.$el.querySelectorAll('input')
|
|
301
|
+
for (let i = 0; i < $inputs.length; i++) {
|
|
302
|
+
if (!$inputs[i].value) {
|
|
303
|
+
$inputs[i].focus()
|
|
304
|
+
break
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
destroyed () {
|
|
310
|
+
clearInterval(this.storageInterval)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
i19available,
|
|
3
|
+
i19loyaltyPoints,
|
|
4
|
+
i19pointsEarned,
|
|
5
|
+
i19upTo
|
|
6
|
+
} from '@ecomplus/i18n'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
i18n,
|
|
10
|
+
formatDate,
|
|
11
|
+
formatMoney
|
|
12
|
+
} from '@ecomplus/utils'
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
name: 'AccountPoints',
|
|
16
|
+
|
|
17
|
+
props: {
|
|
18
|
+
customer: {
|
|
19
|
+
type: Object,
|
|
20
|
+
default () {
|
|
21
|
+
return {}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
computed: {
|
|
27
|
+
i19available: () => i18n(i19available),
|
|
28
|
+
i19loyaltyPoints: () => i18n(i19loyaltyPoints),
|
|
29
|
+
i19pointsEarned: () => i18n(i19pointsEarned),
|
|
30
|
+
i19upTo: () => i18n(i19upTo),
|
|
31
|
+
|
|
32
|
+
validPointsEntries () {
|
|
33
|
+
const pointsEntries = this.customer.loyalty_points_entries
|
|
34
|
+
if (pointsEntries) {
|
|
35
|
+
return pointsEntries.filter(pointsEntry => {
|
|
36
|
+
const validThru = pointsEntry.valid_thru
|
|
37
|
+
return (!validThru || new Date(validThru).getTime() >= Date.now()) &&
|
|
38
|
+
pointsEntry.active_points > 0
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
return []
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
totalPoints () {
|
|
45
|
+
if (this.validPointsEntries.length) {
|
|
46
|
+
return this.validPointsEntries.reduce((prev, curr) => (prev + curr.active_points), 0)
|
|
47
|
+
}
|
|
48
|
+
return 0
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
totalCashback () {
|
|
52
|
+
if (this.validPointsEntries.length) {
|
|
53
|
+
return this.validPointsEntries.reduce((prev, curr) => (prev + (curr.active_points * curr.ratio)), 0)
|
|
54
|
+
}
|
|
55
|
+
return 0
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
methods: {
|
|
60
|
+
formatDate,
|
|
61
|
+
formatMoney
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/js/AddressForm.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from '@ecomplus/utils'
|
|
21
21
|
|
|
22
22
|
import axios from 'axios'
|
|
23
|
+
import checkFormValidity from './helpers/check-form-validity'
|
|
23
24
|
import InputZipCode from '../InputZipCode.vue'
|
|
24
25
|
|
|
25
26
|
const countryCode = $ecomConfig.get('country_code')
|
|
@@ -38,19 +39,32 @@ export default {
|
|
|
38
39
|
return {}
|
|
39
40
|
}
|
|
40
41
|
},
|
|
41
|
-
zipCode: String
|
|
42
|
+
zipCode: String,
|
|
43
|
+
btnText: {
|
|
44
|
+
type: String,
|
|
45
|
+
default () {
|
|
46
|
+
return i18n(i19save)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
42
49
|
},
|
|
43
50
|
|
|
44
51
|
data () {
|
|
52
|
+
const localAddress = {
|
|
53
|
+
_id: getRandomObjectId(),
|
|
54
|
+
zip: '',
|
|
55
|
+
province_code: '',
|
|
56
|
+
...this.address
|
|
57
|
+
}
|
|
58
|
+
if (localAddress.name && localAddress.name.endsWith('*')) {
|
|
59
|
+
delete localAddress.name
|
|
60
|
+
}
|
|
61
|
+
if (localAddress.line_address && localAddress.line_address.endsWith('*')) {
|
|
62
|
+
delete localAddress.line_address
|
|
63
|
+
}
|
|
45
64
|
return {
|
|
46
|
-
localAddress
|
|
47
|
-
_id: getRandomObjectId(),
|
|
48
|
-
zip: '',
|
|
49
|
-
province_code: '',
|
|
50
|
-
...this.address
|
|
51
|
-
},
|
|
65
|
+
localAddress,
|
|
52
66
|
isZipReady: countryCode !== 'BR',
|
|
53
|
-
|
|
67
|
+
zipLoading: null,
|
|
54
68
|
addressFromZip: {},
|
|
55
69
|
isNoNumber: false
|
|
56
70
|
}
|
|
@@ -66,7 +80,6 @@ export default {
|
|
|
66
80
|
i19provinceCode: () => i18n(i19provinceCode),
|
|
67
81
|
i19recipient: () => i18n(i19recipient),
|
|
68
82
|
i19reference: () => i18n(i19reference),
|
|
69
|
-
i19save: () => i18n(i19save),
|
|
70
83
|
i19street: () => i18n(i19street),
|
|
71
84
|
i19zipCode: () => i18n(i19zipCode),
|
|
72
85
|
|
|
@@ -77,39 +90,35 @@ export default {
|
|
|
77
90
|
set (value) {
|
|
78
91
|
this.localAddress.province_code = value.toUpperCase().slice(0, 2)
|
|
79
92
|
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
zipInfoLink () {
|
|
96
|
+
return countryCode === 'BR'
|
|
97
|
+
? 'https://buscacepinter.correios.com.br/app/endereco/index.php'
|
|
98
|
+
: null
|
|
80
99
|
}
|
|
81
100
|
},
|
|
82
101
|
|
|
83
102
|
methods: {
|
|
84
103
|
updateZipState () {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
if (countryCode === 'BR' && this.localAddress.zip.length >= 8) {
|
|
105
|
+
if (this.zipLoading !== this.localAddress.zip) {
|
|
106
|
+
this.addressFromZip = {}
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
this.fetchAddressInfo(this.localAddress.zip)
|
|
109
|
+
}, this.zipLoading ? 150 : 50)
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
this.zipLoading = null
|
|
92
113
|
}
|
|
93
|
-
$form.classList.add('was-validated')
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
watch: {
|
|
98
|
-
zipCode (zip) {
|
|
99
|
-
this.localAddress.zip = zip
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
'localAddress.zip' () {
|
|
103
|
-
this.updateZipState()
|
|
104
114
|
},
|
|
105
115
|
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
axios.get(`https://viacep.com.br/ws/${this.localAddress.zip}/json/`)
|
|
116
|
+
fetchAddressInfo (zipCode, isRetry = false) {
|
|
117
|
+
if (zipCode === this.localAddress.zip) {
|
|
118
|
+
this.zipLoading = zipCode
|
|
119
|
+
axios.get(`https://viacep.com.br/ws/${zipCode}/json/`, { timeout: 4000 })
|
|
111
120
|
.then(({ data }) => {
|
|
112
|
-
if (!data.erro) {
|
|
121
|
+
if (!data.erro && zipCode === this.localAddress.zip) {
|
|
113
122
|
;[
|
|
114
123
|
['province_code', data.uf],
|
|
115
124
|
['city', data.localidade],
|
|
@@ -130,14 +139,50 @@ export default {
|
|
|
130
139
|
})
|
|
131
140
|
.catch(err => {
|
|
132
141
|
console.error(err)
|
|
142
|
+
if (!isRetry) {
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
this.fetchAddressInfo(zipCode, true)
|
|
145
|
+
}, 300)
|
|
146
|
+
}
|
|
133
147
|
})
|
|
134
148
|
.finally(() => {
|
|
135
|
-
this.
|
|
136
|
-
|
|
149
|
+
if (zipCode === this.zipLoading) {
|
|
150
|
+
this.zipLoading = null
|
|
151
|
+
}
|
|
137
152
|
})
|
|
138
153
|
}
|
|
139
154
|
},
|
|
140
155
|
|
|
156
|
+
submit (ev) {
|
|
157
|
+
const $form = this.$el
|
|
158
|
+
if (checkFormValidity($form)) {
|
|
159
|
+
this.$emit('update:address', this.localAddress)
|
|
160
|
+
}
|
|
161
|
+
$form.classList.add('was-validated')
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
watch: {
|
|
166
|
+
zipCode (zip) {
|
|
167
|
+
this.localAddress.zip = zip
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
'localAddress.zip' (zip) {
|
|
171
|
+
this.updateZipState()
|
|
172
|
+
this.$emit('update:zip-code', zip)
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
zipLoading (zip) {
|
|
176
|
+
if (zip) {
|
|
177
|
+
this.isZipReady = false
|
|
178
|
+
setTimeout(() => {
|
|
179
|
+
this.isZipReady = true
|
|
180
|
+
}, 1500)
|
|
181
|
+
} else {
|
|
182
|
+
this.isZipReady = true
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
|
|
141
186
|
isNoNumber (isNoNumber) {
|
|
142
187
|
if (isNoNumber) {
|
|
143
188
|
delete this.localAddress.number
|