@ecomplus/storefront-components 1.0.0-beta.18 → 1.0.0-beta.181
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 +1278 -133
- package/README.md +9 -4
- 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 +2 -2
- 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 +56 -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 +100 -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 +192 -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 +165 -48
- 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 +46 -5
- package/src/js/LoginModal.js +17 -4
- package/src/js/PaymentOption.js +28 -1
- package/src/js/PointsApplier.js +110 -0
- package/src/js/ProductCard.js +97 -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 +35 -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 +66 -28
- 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
package/src/js/APicture.js
CHANGED
|
@@ -69,6 +69,8 @@ export default {
|
|
|
69
69
|
data () {
|
|
70
70
|
return {
|
|
71
71
|
sources: [],
|
|
72
|
+
imgWidth: 0,
|
|
73
|
+
imgHeight: 0,
|
|
72
74
|
height: null,
|
|
73
75
|
opacity: null
|
|
74
76
|
}
|
|
@@ -89,7 +91,8 @@ export default {
|
|
|
89
91
|
}
|
|
90
92
|
const fixedSrc = typeof src === 'object'
|
|
91
93
|
? src.zoom
|
|
92
|
-
? src.zoom.url
|
|
94
|
+
? src.zoom.url
|
|
95
|
+
: defaultImgObj.url
|
|
93
96
|
: src
|
|
94
97
|
return fixedSrc ? fixedSrc.replace(/\.webp$/, '') : this.placeholder
|
|
95
98
|
},
|
|
@@ -115,10 +118,13 @@ export default {
|
|
|
115
118
|
const imgObj = this.src[thumb]
|
|
116
119
|
const { url, size } = (imgObj || this.defaultImgObj)
|
|
117
120
|
srcset = url
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
this.height =
|
|
121
|
+
if (size) {
|
|
122
|
+
[this.imgWidth, this.imgHeight] = size.split('x').map(px => parseInt(px, 10))
|
|
123
|
+
if (clientWidth && this.imgHeight && this.canCalcHeight) {
|
|
124
|
+
this.height = (clientWidth >= this.imgWidth
|
|
125
|
+
? this.imgHeight
|
|
126
|
+
: clientWidth * this.imgHeight / this.imgWidth) +
|
|
127
|
+
'px'
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
130
|
} else {
|
|
@@ -130,8 +136,18 @@ export default {
|
|
|
130
136
|
srcset,
|
|
131
137
|
type: 'image/webp'
|
|
132
138
|
}, {
|
|
133
|
-
srcset: srcset
|
|
134
|
-
|
|
139
|
+
srcset: /\/imgs\/[0-9]{3}px/.test(srcset)
|
|
140
|
+
? srcset.replace(/\/imgs\/[0-9]{3}px/, '')
|
|
141
|
+
: srcset.replace(/\.webp$/, ''),
|
|
142
|
+
type: `image/${(srcset.substr(-9, 4) === '.png' ? 'png' : 'jpeg')}`
|
|
143
|
+
})
|
|
144
|
+
} else if (srcset.endsWith('.avif')) {
|
|
145
|
+
sources.push({
|
|
146
|
+
srcset,
|
|
147
|
+
type: 'image/avif'
|
|
148
|
+
}, {
|
|
149
|
+
srcset: srcset.replace('.avif', '.webp'),
|
|
150
|
+
type: 'image/webp'
|
|
135
151
|
})
|
|
136
152
|
} else {
|
|
137
153
|
sources.push({ srcset })
|
|
@@ -151,6 +167,10 @@ export default {
|
|
|
151
167
|
const { localFallbackSrc } = this
|
|
152
168
|
const $img = $el.tagName === 'IMG' ? $el : $el.lastChild
|
|
153
169
|
$img.style.opacity = 0
|
|
170
|
+
if (this.imgHeight) {
|
|
171
|
+
$img.height = this.imgHeight
|
|
172
|
+
$img.width = this.imgWidth
|
|
173
|
+
}
|
|
154
174
|
$img.onerror = function () {
|
|
155
175
|
console.error(new Error('Image load error'), this)
|
|
156
176
|
$el.style.display = 'none'
|
package/src/js/APrices.js
CHANGED
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
i19interestFree,
|
|
5
5
|
i19of,
|
|
6
6
|
i19to,
|
|
7
|
-
i19upTo
|
|
7
|
+
i19upTo,
|
|
8
|
+
i19youEarn
|
|
8
9
|
} from '@ecomplus/i18n'
|
|
9
10
|
|
|
10
11
|
import {
|
|
@@ -14,14 +15,18 @@ import {
|
|
|
14
15
|
formatMoney
|
|
15
16
|
} from '@ecomplus/utils'
|
|
16
17
|
|
|
18
|
+
import waitStorefrontInfo from './helpers/wait-storefront-info'
|
|
19
|
+
|
|
17
20
|
const getPriceWithDiscount = (price, discount) => {
|
|
18
21
|
const { type, value } = discount
|
|
22
|
+
let priceWithDiscount
|
|
19
23
|
if (value) {
|
|
20
24
|
if (type === 'percentage') {
|
|
21
|
-
|
|
25
|
+
priceWithDiscount = price * (100 - value) / 100
|
|
22
26
|
} else {
|
|
23
|
-
|
|
27
|
+
priceWithDiscount = price - value
|
|
24
28
|
}
|
|
29
|
+
return priceWithDiscount > 0 ? priceWithDiscount : 0
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
|
|
@@ -35,11 +40,16 @@ export default {
|
|
|
35
40
|
},
|
|
36
41
|
isLiteral: Boolean,
|
|
37
42
|
isBig: Boolean,
|
|
43
|
+
isAmountTotal: Boolean,
|
|
38
44
|
installmentsOption: Object,
|
|
39
45
|
discountOption: Object,
|
|
40
46
|
discountText: {
|
|
41
47
|
type: [String, Boolean],
|
|
42
48
|
default: ''
|
|
49
|
+
},
|
|
50
|
+
canShowPriceOptions: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: true
|
|
43
53
|
}
|
|
44
54
|
},
|
|
45
55
|
|
|
@@ -53,9 +63,13 @@ export default {
|
|
|
53
63
|
},
|
|
54
64
|
extraDiscount: {
|
|
55
65
|
type: null,
|
|
56
|
-
value: 0
|
|
66
|
+
value: 0,
|
|
67
|
+
min_amount: 0
|
|
57
68
|
},
|
|
58
|
-
discountLabel: this.discountText
|
|
69
|
+
discountLabel: this.discountText,
|
|
70
|
+
pointsProgramName: null,
|
|
71
|
+
pointsMinPrice: 0,
|
|
72
|
+
earnPointsFactor: 0
|
|
59
73
|
}
|
|
60
74
|
},
|
|
61
75
|
|
|
@@ -66,10 +80,14 @@ export default {
|
|
|
66
80
|
i19of: () => i18n(i19of),
|
|
67
81
|
i19to: () => i18n(i19to),
|
|
68
82
|
i19upTo: () => i18n(i19upTo),
|
|
83
|
+
i19youEarn: () => i18n(i19youEarn),
|
|
69
84
|
|
|
70
85
|
price () {
|
|
71
86
|
const price = getPrice(this.product)
|
|
72
|
-
if (
|
|
87
|
+
if (
|
|
88
|
+
this.extraDiscount.value &&
|
|
89
|
+
(!this.extraDiscount.min_amount || price > this.extraDiscount.min_amount)
|
|
90
|
+
) {
|
|
73
91
|
return getPriceWithDiscount(price, this.extraDiscount)
|
|
74
92
|
}
|
|
75
93
|
return price
|
|
@@ -83,12 +101,29 @@ export default {
|
|
|
83
101
|
}
|
|
84
102
|
},
|
|
85
103
|
|
|
104
|
+
hasVariedPrices () {
|
|
105
|
+
const { variations } = this.product
|
|
106
|
+
if (variations) {
|
|
107
|
+
const productPrice = getPrice(this.product)
|
|
108
|
+
for (let i = 0; i < variations.length; i++) {
|
|
109
|
+
const price = getPrice({
|
|
110
|
+
...this.product,
|
|
111
|
+
...variations[i]
|
|
112
|
+
})
|
|
113
|
+
if (price > productPrice) {
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return false
|
|
119
|
+
},
|
|
120
|
+
|
|
86
121
|
priceWithDiscount () {
|
|
87
|
-
return getPriceWithDiscount(this.price, this.discount)
|
|
122
|
+
return this.canShowPriceOptions && getPriceWithDiscount(this.price, this.discount)
|
|
88
123
|
},
|
|
89
124
|
|
|
90
125
|
installmentValue () {
|
|
91
|
-
if (this.installmentsNumber >= 2) {
|
|
126
|
+
if (this.canShowPriceOptions && this.installmentsNumber >= 2) {
|
|
92
127
|
if (!this.monthlyInterest) {
|
|
93
128
|
return this.price / this.installmentsNumber
|
|
94
129
|
} else {
|
|
@@ -114,7 +149,11 @@ export default {
|
|
|
114
149
|
},
|
|
115
150
|
|
|
116
151
|
updateDiscount (discount) {
|
|
117
|
-
if (
|
|
152
|
+
if (
|
|
153
|
+
discount &&
|
|
154
|
+
(!discount.min_amount || discount.min_amount <= this.price) &&
|
|
155
|
+
(!this.isAmountTotal || discount.apply_at === 'total')
|
|
156
|
+
) {
|
|
118
157
|
this.discount = discount
|
|
119
158
|
if (!this.discountText && this.discountText !== false && discount.label) {
|
|
120
159
|
this.discountLabel = `via ${discount.label}`
|
|
@@ -133,39 +172,39 @@ export default {
|
|
|
133
172
|
},
|
|
134
173
|
|
|
135
174
|
created () {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
return Object.keys(discountCampaign).length > 0
|
|
148
|
-
}
|
|
149
|
-
return false
|
|
150
|
-
}
|
|
151
|
-
if (!getExtraDiscount()) {
|
|
152
|
-
storefront.on('info:apply_discount', getExtraDiscount)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (this.installmentsOption) {
|
|
156
|
-
this.updateInstallments(this.installmentsOption)
|
|
157
|
-
} else if (storefront) {
|
|
158
|
-
const getPaymentInfo = () => {
|
|
159
|
-
const paymentInfo = storefront.info && storefront.info.list_payments
|
|
160
|
-
if (paymentInfo) {
|
|
161
|
-
this.updateInstallments(paymentInfo.installments_option)
|
|
162
|
-
this.updateDiscount(paymentInfo.discount_option)
|
|
163
|
-
return Object.keys(paymentInfo).length > 0
|
|
164
|
-
}
|
|
165
|
-
return false
|
|
175
|
+
if (this.canShowPriceOptions) {
|
|
176
|
+
if (this.discountOption) {
|
|
177
|
+
this.updateDiscount(this.discountOption)
|
|
178
|
+
} else {
|
|
179
|
+
waitStorefrontInfo('apply_discount')
|
|
180
|
+
.then(discountCampaign => {
|
|
181
|
+
if (discountCampaign.available_extra_discount) {
|
|
182
|
+
this.extraDiscount = discountCampaign.available_extra_discount
|
|
183
|
+
}
|
|
184
|
+
})
|
|
166
185
|
}
|
|
167
|
-
if (
|
|
168
|
-
|
|
186
|
+
if (this.installmentsOption) {
|
|
187
|
+
this.updateInstallments(this.installmentsOption)
|
|
188
|
+
} else {
|
|
189
|
+
waitStorefrontInfo('list_payments')
|
|
190
|
+
.then(paymentInfo => {
|
|
191
|
+
this.updateInstallments(paymentInfo.installments_option)
|
|
192
|
+
this.updateDiscount(paymentInfo.discount_option)
|
|
193
|
+
const pointsPrograms = paymentInfo.loyalty_points_programs
|
|
194
|
+
if (this.isLiteral && pointsPrograms) {
|
|
195
|
+
this.$nextTick(() => {
|
|
196
|
+
for (const programId in pointsPrograms) {
|
|
197
|
+
const pointsProgram = pointsPrograms[programId]
|
|
198
|
+
if (pointsProgram && pointsProgram.earn_percentage > 0) {
|
|
199
|
+
this.pointsMinPrice = pointsProgram.min_subtotal_to_earn
|
|
200
|
+
this.pointsProgramName = pointsProgram.name
|
|
201
|
+
this.earnPointsFactor = pointsProgram.earn_percentage / 100
|
|
202
|
+
break
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
})
|
|
169
208
|
}
|
|
170
209
|
}
|
|
171
210
|
}
|
package/src/js/AShare.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
i19email,
|
|
3
|
+
i19on,
|
|
4
|
+
i19share
|
|
5
|
+
} from '@ecomplus/i18n'
|
|
6
|
+
|
|
7
|
+
import { i18n } from '@ecomplus/utils'
|
|
8
|
+
import { ShareNetwork } from 'vue-social-sharing'
|
|
9
|
+
|
|
10
|
+
const shareNetworks = [
|
|
11
|
+
{
|
|
12
|
+
network: 'whatsapp',
|
|
13
|
+
name: 'WhatsApp',
|
|
14
|
+
icon: 'i-whatsapp',
|
|
15
|
+
color: '#25d366'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
network: 'facebook',
|
|
19
|
+
name: 'Facebook',
|
|
20
|
+
icon: 'i-facebook',
|
|
21
|
+
color: '#1877f2'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
network: 'twitter',
|
|
25
|
+
name: 'Twitter',
|
|
26
|
+
icon: 'i-twitter',
|
|
27
|
+
color: '#1da1f2'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
network: 'telegram',
|
|
31
|
+
name: 'Telegram',
|
|
32
|
+
icon: 'i-telegram',
|
|
33
|
+
color: '#0088cc'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
network: 'pinterest',
|
|
37
|
+
name: 'Pinterest',
|
|
38
|
+
icon: 'i-pinterest',
|
|
39
|
+
color: '#bd081c'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
network: 'email',
|
|
43
|
+
name: 'Email',
|
|
44
|
+
icon: 'i-envelope',
|
|
45
|
+
color: '#333333'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
network: 'sms',
|
|
49
|
+
name: 'SMS',
|
|
50
|
+
color: '#333333'
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
export default {
|
|
55
|
+
name: 'TheProduct',
|
|
56
|
+
|
|
57
|
+
components: {
|
|
58
|
+
ShareNetwork
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
props: {
|
|
62
|
+
url: {
|
|
63
|
+
type: String,
|
|
64
|
+
required: true
|
|
65
|
+
},
|
|
66
|
+
title: String,
|
|
67
|
+
description: String
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
computed: {
|
|
71
|
+
i19email: () => i18n(i19email),
|
|
72
|
+
i19on: () => i18n(i19on).toLowerCase(),
|
|
73
|
+
i19share: () => i18n(i19share),
|
|
74
|
+
shareNetworks: () => shareNetworks,
|
|
75
|
+
|
|
76
|
+
localUrl () {
|
|
77
|
+
if (typeof window === 'object' && !this.url.startsWith('http')) {
|
|
78
|
+
return `https://${window.location.hostname}${this.url}`
|
|
79
|
+
}
|
|
80
|
+
return this.url
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
i19edit,
|
|
3
|
+
i19newAddress,
|
|
4
|
+
i19noNumber,
|
|
5
|
+
i19remove
|
|
6
|
+
} from '@ecomplus/i18n'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
i18n,
|
|
10
|
+
fullName as getFullName
|
|
11
|
+
} from '@ecomplus/utils'
|
|
12
|
+
|
|
13
|
+
import AddressForm from './../AddressForm.vue'
|
|
14
|
+
|
|
15
|
+
const { sessionStorage } = window
|
|
16
|
+
const storageKey = 'ecomCustomerAddress'
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
name: 'AccountAddresses',
|
|
20
|
+
|
|
21
|
+
components: {
|
|
22
|
+
AddressForm
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
props: {
|
|
26
|
+
customer: {
|
|
27
|
+
type: Object,
|
|
28
|
+
default () {
|
|
29
|
+
return {}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
zipCode: String,
|
|
33
|
+
formBtnText: String,
|
|
34
|
+
canShowForm: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
data () {
|
|
41
|
+
return {
|
|
42
|
+
isForm: false,
|
|
43
|
+
isNewAddress: false,
|
|
44
|
+
editAddressIndex: -1
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
computed: {
|
|
49
|
+
i19edit: () => i18n(i19edit),
|
|
50
|
+
i19newAddress: () => i18n(i19newAddress),
|
|
51
|
+
i19remove: () => i18n(i19remove),
|
|
52
|
+
i19noNumber: () => i18n(i19noNumber),
|
|
53
|
+
|
|
54
|
+
addresses () {
|
|
55
|
+
return this.customer.addresses || []
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
localAddress: {
|
|
59
|
+
get () {
|
|
60
|
+
let address = this.addresses[this.editAddressIndex]
|
|
61
|
+
if (!address) {
|
|
62
|
+
address = {}
|
|
63
|
+
if (this.zipCode) {
|
|
64
|
+
address.zip = this.zipCode
|
|
65
|
+
}
|
|
66
|
+
if (this.customer.name) {
|
|
67
|
+
address.name = getFullName(this.customer).substr(0, 70)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return address
|
|
71
|
+
},
|
|
72
|
+
set (address) {
|
|
73
|
+
const addresses = [].concat(this.addresses)
|
|
74
|
+
addresses[this.editAddressIndex] = address
|
|
75
|
+
this.$emit('update:customer', {
|
|
76
|
+
...this.customer,
|
|
77
|
+
addresses
|
|
78
|
+
})
|
|
79
|
+
if (address.zip) {
|
|
80
|
+
this.isNewAddress = false
|
|
81
|
+
this.selectAddress(address)
|
|
82
|
+
}
|
|
83
|
+
this.isForm = false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
methods: {
|
|
89
|
+
getLineAddress (address) {
|
|
90
|
+
if (address.line_address) {
|
|
91
|
+
return address.line_address
|
|
92
|
+
} else {
|
|
93
|
+
let lineAddress = `${address.street} ${(address.number || this.i19noNumber)}`
|
|
94
|
+
if (address.complement) {
|
|
95
|
+
lineAddress += ` - ${address.complement}`
|
|
96
|
+
}
|
|
97
|
+
if (address.borough) {
|
|
98
|
+
lineAddress += `, ${address.borough}`
|
|
99
|
+
}
|
|
100
|
+
return lineAddress
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
selectAddress (address) {
|
|
105
|
+
this.$emit('select-address', address._id)
|
|
106
|
+
sessionStorage.setItem(storageKey, JSON.stringify(address))
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
removeAddress (index) {
|
|
110
|
+
const addresses = [].concat(this.addresses)
|
|
111
|
+
addresses.splice(index, 1)
|
|
112
|
+
this.$emit('update:customer', {
|
|
113
|
+
...this.customer,
|
|
114
|
+
addresses
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
watch: {
|
|
120
|
+
addresses (newList, oldList) {
|
|
121
|
+
if (!oldList.length) {
|
|
122
|
+
if (newList.length && this.isNewAddress) {
|
|
123
|
+
this.isForm = this.isNewAddress = false
|
|
124
|
+
}
|
|
125
|
+
} else if (!newList.length) {
|
|
126
|
+
this.isForm = this.isNewAddress = true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
isNewAddress (isAddAddress) {
|
|
131
|
+
if (isAddAddress) {
|
|
132
|
+
this.editAddressIndex = this.addresses.length
|
|
133
|
+
this.isForm = true
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
editAddressIndex (index) {
|
|
138
|
+
if (index > -1) {
|
|
139
|
+
const address = this.addresses[index]
|
|
140
|
+
if (address) {
|
|
141
|
+
this.selectAddress(address)
|
|
142
|
+
}
|
|
143
|
+
this.isForm = true
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
isForm (isVisible) {
|
|
148
|
+
this.$emit('show-form', isVisible)
|
|
149
|
+
if (!isVisible) {
|
|
150
|
+
this.editAddressIndex = -1
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
created () {
|
|
156
|
+
if (!this.addresses.length) {
|
|
157
|
+
this.isNewAddress = true
|
|
158
|
+
const sessionAddress = JSON.parse(sessionStorage.getItem(storageKey))
|
|
159
|
+
if (sessionAddress) {
|
|
160
|
+
const address = {}
|
|
161
|
+
for (const field in sessionAddress) {
|
|
162
|
+
if (sessionAddress[field]) {
|
|
163
|
+
address[field] = sessionAddress[field]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (address._id && address.zip && address.street) {
|
|
167
|
+
this.editAddressIndex = 0
|
|
168
|
+
this.$nextTick(() => {
|
|
169
|
+
this.localAddress = address
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
let addressIndex
|
|
175
|
+
if (this.zipCode) {
|
|
176
|
+
addressIndex = this.addresses.findIndex(addr => addr.zip === this.zipCode)
|
|
177
|
+
}
|
|
178
|
+
if (!(addressIndex >= 0)) {
|
|
179
|
+
addressIndex = this.addresses.findIndex(addr => addr.default)
|
|
180
|
+
if (addressIndex === -1) {
|
|
181
|
+
addressIndex = 0
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const address = this.addresses[addressIndex]
|
|
185
|
+
if (address.name && ((address.street && address.city) || address.name.endsWith('*'))) {
|
|
186
|
+
this.selectAddress(address)
|
|
187
|
+
} else {
|
|
188
|
+
this.editAddressIndex = addressIndex
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|