@wikala/spmkt 2.31.0 → 3.0.0-beta.0

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.
Files changed (124) hide show
  1. package/MIGRATION_GUIDE.md +261 -0
  2. package/api/product.js +1 -0
  3. package/api/request.js +9 -4
  4. package/api/user.js +1 -1
  5. package/components/Account/AccountDashboard.vue +101 -101
  6. package/components/Account/AccountStore.js +57 -31
  7. package/components/Account/AffiliateReport.vue +56 -60
  8. package/components/Account/{OrderDetail.vue → Orders/OrderDetail.vue} +44 -30
  9. package/components/Account/Orders/Orders.vue +124 -0
  10. package/components/Account/{AccountSettings.vue → Settings/AccountSettings.vue} +4 -4
  11. package/components/Account/Settings/ChangeEmail.vue +136 -0
  12. package/components/Account/Settings/ChangeName.vue +82 -0
  13. package/components/Account/Settings/ChangePassword.vue +91 -0
  14. package/components/Address/Address.vue +38 -57
  15. package/components/Address/AddressBook.vue +77 -57
  16. package/components/Address/AddressSelect.vue +94 -87
  17. package/components/Address/Edit.vue +253 -265
  18. package/components/Address/PostalCode.vue +22 -21
  19. package/components/AgeGate.vue +11 -5
  20. package/components/Auth/Login.vue +62 -44
  21. package/components/Auth/Register.vue +82 -60
  22. package/components/Auth/ResetPassword.vue +45 -30
  23. package/components/Cart/AgeVerification/AgeChecker.vue +3 -3
  24. package/components/Cart/CartBadge.vue +15 -4
  25. package/components/Cart/CartBox.vue +19 -11
  26. package/components/Cart/CartItem.vue +3 -3
  27. package/components/Cart/CartMode.vue +6 -5
  28. package/components/Cart/CartPreview.vue +24 -18
  29. package/components/Cart/Coupon.vue +4 -5
  30. package/components/Cart/CreditCard/Everyware.vue +10 -10
  31. package/components/Cart/CreditCard/ExtendedCreditCard.vue +5 -5
  32. package/components/Cart/CreditCard/SquarePay.vue +18 -16
  33. package/components/Cart/CreditCard/StandardCreditCard.vue +9 -9
  34. package/components/Cart/Delivery/Delivery.vue +16 -12
  35. package/components/Cart/Delivery/DeliveryAddress.vue +1 -1
  36. package/components/Cart/Delivery/DeliveryMethods.vue +1 -1
  37. package/components/Cart/Delivery/DeliveryOptions.vue +15 -9
  38. package/components/Cart/Delivery/DeliveryTypes.vue +8 -5
  39. package/components/Cart/Delivery/ReservationSlots.vue +14 -8
  40. package/components/Cart/Disclaimer.vue +1 -1
  41. package/components/Cart/OrderConfirmation.vue +1 -1
  42. package/components/Cart/Payment/Payment.vue +37 -33
  43. package/components/Cart/Payment/PaymentMethods.vue +6 -4
  44. package/components/Cart/ReviewAndSubmit.vue +9 -7
  45. package/components/Cart/ShoppingCart.vue +42 -31
  46. package/components/Cart/Store/actions.js +1 -1
  47. package/components/Cart/Store/getters.js +2 -1
  48. package/components/Cart/Store/index.js +1 -1
  49. package/components/Cart/Store/mutations.js +7 -5
  50. package/components/Cart/UserIdentity.vue +1 -1
  51. package/components/Category/CategoryFilter.vue +128 -114
  52. package/components/Category/CategorySort.vue +44 -32
  53. package/components/Category/LoadMore.vue +39 -23
  54. package/components/DeliverTo.vue +10 -15
  55. package/components/DeliveryNotice.vue +72 -68
  56. package/components/DobInput.vue +23 -23
  57. package/components/Gmaps/GmapsAutocomplete.vue +139 -78
  58. package/components/Gmaps/GmapsLocations.vue +1 -1
  59. package/components/Gmaps/GmapsSingleLocation.vue +121 -87
  60. package/components/ModalContainer/ModalContainer.vue +12 -9
  61. package/components/ModalContainer/index.js +61 -18
  62. package/components/Product/AddToCart.vue +237 -221
  63. package/components/Product/BoxAddToCart.vue +114 -86
  64. package/components/Product/Compare.vue +68 -48
  65. package/components/Product/CompareBox.vue +128 -123
  66. package/components/Product/Lookup.vue +92 -65
  67. package/components/Product/Photo.vue +105 -66
  68. package/components/Product/Price.vue +64 -43
  69. package/components/Product/ProductAutocomplete.vue +52 -57
  70. package/components/Product/ProductBox.vue +61 -38
  71. package/components/Product/ProductImages.vue +83 -86
  72. package/components/Product/Quantity.vue +115 -53
  73. package/components/Product/QuickView.vue +52 -45
  74. package/components/Product/RelatedProducts.vue +88 -23
  75. package/components/Product/SKU.vue +27 -8
  76. package/components/Product/Variants.vue +335 -341
  77. package/components/Product/reviews-questions/ProductQuestions.vue +226 -198
  78. package/components/Product/reviews-questions/ProductReviews.vue +122 -107
  79. package/components/Product/reviews-questions/Review.vue +54 -59
  80. package/components/Product/reviews-questions/ReviewForm.vue +222 -170
  81. package/components/Product/reviews-questions/ReviewImages.vue +197 -216
  82. package/components/Product/reviews-questions/Vote.vue +83 -57
  83. package/components/QuantityInput.vue +18 -8
  84. package/components/RangeInput.vue +15 -8
  85. package/components/Recaptcha.vue +8 -1
  86. package/components/SelectShippingCountry.vue +81 -62
  87. package/components/TimedOffer.vue +59 -74
  88. package/composables/globals.js +53 -0
  89. package/config.js +5 -2
  90. package/index.js +41 -10
  91. package/install.js +75 -0
  92. package/locales/en.json +2 -1
  93. package/locales/sr.json +2 -1
  94. package/package.json +43 -30
  95. package/utils/directives.js +28 -45
  96. package/utils/event-bus.js +56 -0
  97. package/utils/filters.js +24 -7
  98. package/utils/{gmaps.js → google/gmaps.js} +43 -10
  99. package/utils/{google-analytics-eec.js → google/google-analytics-eec.js} +7 -7
  100. package/babel.config.js +0 -5
  101. package/components/Account/ChangeEmail.vue +0 -133
  102. package/components/Account/ChangeName.vue +0 -92
  103. package/components/Account/ChangePassword.vue +0 -94
  104. package/components/Account/CreditCards.vue +0 -18
  105. package/components/Account/Orders.vue +0 -110
  106. package/components/Account/Settings.vue +0 -18
  107. package/components/Cart/Delivery/DeliveryAddressGuest.spec.js +0 -128
  108. package/components/Cart/Delivery/DeliveryTypes.spec.js +0 -83
  109. package/components/Cart/PCIBadge/SecurityMetrics.vue +0 -11
  110. package/components/Instagram.vue +0 -49
  111. package/components/ProductImageModal.vue +0 -41
  112. package/jest.config.js +0 -16
  113. package/test/e2e/.babelrc.js +0 -8
  114. package/test/e2e/.eslintrc.js +0 -11
  115. package/test/e2e/accAuth.spec.js +0 -64
  116. package/test/e2e/ageGate.spec.js +0 -26
  117. package/test/e2e/checkout.spec.js +0 -106
  118. package/test/e2e/compare.spec.js +0 -52
  119. package/test/e2e/config/data.js +0 -21
  120. package/test/e2e/config/routes.js +0 -11
  121. package/test/e2e/region.spec.js +0 -46
  122. package/test/e2e/search.spec.js +0 -32
  123. package/tests/vueBuefy.js +0 -4
  124. package/tsconfig.json +0 -8
@@ -10,7 +10,7 @@
10
10
  @typing="getAsyncData"
11
11
  @select="select($event)"
12
12
  >
13
- <template slot-scope="props">
13
+ <template #default="props">
14
14
  <div class="media">
15
15
  <div class="media-left">
16
16
  <img width="32" :src="props.option.image" />
@@ -25,81 +25,108 @@
25
25
  </div>
26
26
  </template>
27
27
 
28
- <script>
28
+ <script setup>
29
+ import { ref, onMounted, onBeforeUnmount } from 'vue'
30
+ import { useBuefy, useBus } from '../../composables/globals'
29
31
  import _ from 'underscore'
30
32
  import { request } from '../../api'
31
33
 
32
- export default {
33
- name: 'ProductLookup',
34
- props: ['position', 'productOnPosition', 'label', 'attTemplateId'],
35
- data() {
36
- return {
37
- data: [],
38
- selected: null,
39
- isFetching: false,
40
- selectedIds: []
41
- }
42
- },
34
+ defineOptions({ name: 'ProductLookup' })
43
35
 
44
- methods: {
45
- getAsyncData: _.debounce(function (query) {
46
- if (!query.length) {
47
- this.data = []
48
- return
49
- }
36
+ const props = defineProps({
37
+ position: {
38
+ type: [Number, String],
39
+ default: -1
40
+ },
41
+ productOnPosition: {
42
+ type: [Number, String],
43
+ default: null
44
+ },
45
+ label: {
46
+ type: String,
47
+ default: ''
48
+ },
49
+ attTemplateId: {
50
+ type: [Number, String],
51
+ default: null
52
+ }
53
+ })
50
54
 
51
- //console.log('query ', query)
52
- this.isFetching = true
55
+ // Get global properties and injections
56
+ const $bus = useBus()
57
+ const $buefy = useBuefy()
53
58
 
54
- return request({
55
- baseURL: '',
56
- url: '/products/lookup?q=' + query + '&tid=' + this.attTemplateId,
57
- method: 'get'
58
- })
59
- .then((response) => {
60
- console.log('response: ', response)
61
- this.data = response.data.slice(0, 6)
62
- this.isFetching = false
63
- })
64
- .catch((error) => {
65
- console.log(error)
66
- this.isFetching = false
67
- })
68
- }, 500),
59
+ // Reactive state
60
+ const data = ref([])
61
+ const selected = ref(null)
62
+ const isFetching = ref(false)
63
+ const selectedIds = ref([])
69
64
 
70
- select(option) {
71
- if (!option) {
72
- return
73
- }
74
- if (this.selectedIds.indexOf(option.id.toString()) === -1) {
75
- if (parseInt(this.position) >= 0) {
76
- this.selectedIds[this.position] = option.id
77
- } else {
78
- this.selectedIds.push(option.id.toString())
79
- }
80
- window.location.href = '/compare-products?products=' + this.selectedIds.join(',')
81
- } else {
82
- this.$buefy.dialog.alert({
83
- title: '',
84
- message: "You've already selected " + option.name,
85
- confirmText: 'OK'
86
- })
87
- }
88
- },
65
+ // Methods
66
+ const getAsyncData = _.debounce(function (query) {
67
+ if (!query.length) {
68
+ data.value = []
69
+ return
70
+ }
89
71
 
90
- remove(position) {
91
- this.selectedIds.splice(position, 1)
92
- window.location.href = '/compare-products?products=' + this.selectedIds.join(',')
93
- }
94
- },
72
+ isFetching.value = true
95
73
 
96
- mounted() {
97
- let urlProductIds = new URL(window.location.href).searchParams.get('products').split(',')
98
- this.selectedIds = urlProductIds
74
+ return request({
75
+ baseURL: '',
76
+ url: '/products/lookup?q=' + query + '&tid=' + props.attTemplateId,
77
+ method: 'get'
78
+ })
79
+ .then((response) => {
80
+ console.log('response: ', response)
81
+ data.value = response.data.slice(0, 6)
82
+ isFetching.value = false
83
+ })
84
+ .catch((error) => {
85
+ console.log(error)
86
+ isFetching.value = false
87
+ })
88
+ }, 500)
99
89
 
100
- this.$bus.$on('removeFromCompare', (position) => {
101
- this.remove(position)
90
+ const select = (option) => {
91
+ if (!option) {
92
+ return
93
+ }
94
+ if (selectedIds.value.indexOf(option.id.toString()) === -1) {
95
+ if (parseInt(props.position) >= 0) {
96
+ selectedIds.value[props.position] = option.id
97
+ } else {
98
+ selectedIds.value.push(option.id.toString())
99
+ }
100
+ window.location.href = '/compare-products?products=' + selectedIds.value.join(',')
101
+ } else {
102
+ $buefy.dialog.alert({
103
+ title: '',
104
+ message: "You've already selected " + option.name,
105
+ confirmText: 'OK'
102
106
  })
103
107
  }
104
108
  }
109
+
110
+ const remove = (position) => {
111
+ selectedIds.value.splice(position, 1)
112
+ window.location.href = '/compare-products?products=' + selectedIds.value.join(',')
113
+ }
114
+
115
+ const onRemoveFromCompare = (position) => {
116
+ remove(position)
117
+ }
118
+
119
+ // Lifecycle hooks
120
+ onMounted(() => {
121
+ const urlParams = new URL(window.location.href).searchParams.get('products')
122
+ if (urlParams) {
123
+ selectedIds.value = urlParams.split(',')
124
+ }
125
+
126
+ $bus.on('removeFromCompare', onRemoveFromCompare)
127
+ })
128
+
129
+ onBeforeUnmount(() => {
130
+ $bus.off('removeFromCompare', onRemoveFromCompare)
131
+ })
105
132
  </script>
@@ -1,76 +1,115 @@
1
1
  <template>
2
- <div class="photo-container">
2
+ <div ref="container" class="photo-container">
3
3
  <figure class="zoom" @mousemove="zoom($event)" :style="{ backgroundImage: `url('${photoSrc}')` }">
4
4
  <img ref="img" :src="src" :alt="alt" />
5
5
  </figure>
6
6
  </div>
7
7
  </template>
8
8
 
9
- <script>
10
- export default {
11
- name: 'Photo',
12
- props: {
13
- src: String,
14
- alt: String
15
- },
16
-
17
- data() {
18
- return {
19
- photoSrc: ''
20
- }
21
- },
22
-
23
- methods: {
24
- swapSrc(src = '') {
25
- if (src) {
26
- this.photoSrc = src
27
- } else {
28
- this.photoSrc = this.src
29
- }
30
-
31
- let image = this.$refs.img
32
- let downloadingImage = new Image()
33
-
34
- let photoLoading = null
35
-
36
- downloadingImage.onload = () => {
37
- image.src = this.photoSrc
38
- photoLoading.close()
39
- }
40
-
41
- photoLoading = this.$buefy.loading.open({ container: this.$el })
42
- downloadingImage.src = this.photoSrc
43
- },
44
-
45
- zoom(e) {
46
- let zoomer = e.currentTarget
47
- let offsetX
48
- let offsetY
49
- let x
50
- let y
51
- //console.log(e)
52
- if (e.offsetX && e.offsetY) {
53
- offsetX = e.offsetX
54
- offsetY = e.offsetY
55
- } else if (e.touches && e.touches[0]) {
56
- offsetX = e.touches[0].pageX
57
- offsetY = e.touches[0].pageY
58
- }
59
- x = (offsetX / zoomer.offsetWidth) * 100
60
- y = (offsetY / zoomer.offsetHeight) * 100
61
- zoomer.style.backgroundPosition = x + '% ' + y + '%'
62
- e.preventDefault()
63
- }
64
- },
65
-
66
- mounted() {
67
- this.swapSrc()
68
- this.$bus.$on('changePhoto', src => {
69
- if (!src) {
70
- return false
71
- }
72
- this.swapSrc(src)
73
- })
9
+ <script setup>
10
+ import { ref, onMounted, onBeforeUnmount } from 'vue'
11
+ import { useBuefy } from '../../composables/globals'
12
+ import { eventBus } from '../../utils/event-bus'
13
+
14
+ defineOptions({ name: 'Photo' })
15
+
16
+ const props = defineProps({
17
+ src: String,
18
+ alt: String
19
+ })
20
+
21
+ // Get global properties
22
+ const $buefy = useBuefy()
23
+
24
+ // Template refs
25
+ const img = ref(null)
26
+ const container = ref(null)
27
+
28
+ // Reactive state
29
+ const photoSrc = ref('')
30
+
31
+ // Methods
32
+ const swapSrc = (src = '') => {
33
+ if (src) {
34
+ photoSrc.value = src
35
+ } else {
36
+ photoSrc.value = props.src
37
+ }
38
+
39
+ const image = img.value
40
+ const downloadingImage = new Image()
41
+
42
+ let photoLoading = null
43
+
44
+ downloadingImage.onload = () => {
45
+ image.src = photoSrc.value
46
+ photoLoading.close()
47
+ }
48
+
49
+ photoLoading = $buefy.loading.open({ container: container.value })
50
+ downloadingImage.src = photoSrc.value
51
+ }
52
+
53
+ const zoom = (e) => {
54
+ const zoomer = e.currentTarget
55
+ let offsetX
56
+ let offsetY
57
+ let x
58
+ let y
59
+
60
+ if (e.offsetX && e.offsetY) {
61
+ offsetX = e.offsetX
62
+ offsetY = e.offsetY
63
+ } else if (e.touches && e.touches[0]) {
64
+ offsetX = e.touches[0].pageX
65
+ offsetY = e.touches[0].pageY
66
+ }
67
+ x = (offsetX / zoomer.offsetWidth) * 100
68
+ y = (offsetY / zoomer.offsetHeight) * 100
69
+ zoomer.style.backgroundPosition = x + '% ' + y + '%'
70
+ e.preventDefault()
71
+ }
72
+
73
+ const handleChangePhoto = (src) => {
74
+ if (!src) {
75
+ return false
74
76
  }
77
+ swapSrc(src)
75
78
  }
79
+
80
+ // Lifecycle hooks
81
+ onMounted(() => {
82
+ swapSrc()
83
+ eventBus.on('changePhoto', handleChangePhoto)
84
+ })
85
+
86
+ onBeforeUnmount(() => {
87
+ eventBus.off('changePhoto', handleChangePhoto)
88
+ })
76
89
  </script>
90
+
91
+ <style scoped>
92
+ .photo-container {
93
+ display: flex;
94
+ justify-content: center;
95
+ }
96
+
97
+ figure.zoom {
98
+ background-position: 50% 50%;
99
+ background-size: 200%;
100
+ position: relative;
101
+ overflow: hidden;
102
+ cursor: zoom-in;
103
+ margin: 0;
104
+ }
105
+
106
+ figure.zoom img {
107
+ display: block;
108
+ width: 100%;
109
+ transition: opacity 0.3s;
110
+ }
111
+
112
+ figure.zoom:hover img {
113
+ opacity: 0;
114
+ }
115
+ </style>
@@ -6,7 +6,9 @@
6
6
  </template>
7
7
 
8
8
  <script>
9
+ import { ref, onMounted, onUnmounted } from 'vue'
9
10
  import { formatMoney } from '../../utils/filters'
11
+ import { eventBus } from '../../utils/event-bus'
10
12
 
11
13
  export default {
12
14
  name: 'Price',
@@ -19,67 +21,86 @@ export default {
19
21
  }
20
22
  },
21
23
 
22
- data() {
23
- return {
24
- comparePrice: 0,
25
- price: 0,
26
- from: '',
27
- discountPercent: 0
28
- }
29
- },
24
+ setup(props) {
25
+ const comparePrice = ref(0)
26
+ const price = ref(0)
27
+ const from = ref('')
28
+ const discountPercent = ref(0)
30
29
 
31
- methods: {
32
- formatMoney,
33
- refresh(value, compareValue) {
30
+ const refresh = (value, compareValue) => {
34
31
  if (typeof value === 'object' && value.min) {
35
- this.from = 'from'
36
- this.price = value.min
37
- this.comparePrice = compareValue.min
32
+ from.value = 'from'
33
+ price.value = value.min
34
+ comparePrice.value = compareValue.min
38
35
  } else {
39
- this.comparePrice = value
36
+ comparePrice.value = value
40
37
  if (compareValue === undefined) {
41
- this.price = value * (1 - this.discountPercent)
38
+ price.value = value * (1 - discountPercent.value)
42
39
  } else {
43
- this.price = parseFloat(value)
44
- this.comparePrice = parseFloat(compareValue)
40
+ price.value = parseFloat(value)
41
+ comparePrice.value = parseFloat(compareValue)
45
42
  }
46
43
  }
47
44
  }
48
- },
49
45
 
50
- mounted() {
51
- if (typeof this.value !== 'object') {
52
- this.price = parseFloat(this.value)
53
- this.comparePrice = parseFloat(this.compareValue)
46
+ const handleUpdatePrice = (value, compareValue) => {
47
+ if (!value && !compareValue) {
48
+ return
49
+ }
50
+ if (!props.updatable) {
51
+ return false
52
+ }
53
+ refresh(value, compareValue)
54
54
  }
55
55
 
56
- if (typeof this.value === 'object') {
57
- if (Object.entries(this.value).length === 0) {
58
- console.log('Price empty value', this.value)
59
- this.price = NaN
60
- this.comparePrice = NaN
61
- } else {
62
- if (typeof this.value === 'object') {
63
- this.discountPercent = Math.abs(this.value.min - this.compareValue.min) / this.compareValue.min
56
+ onMounted(() => {
57
+ if (typeof props.value !== 'object') {
58
+ price.value = parseFloat(props.value)
59
+ comparePrice.value = parseFloat(props.compareValue)
60
+ }
61
+
62
+ if (typeof props.value === 'object') {
63
+ if (Object.entries(props.value).length === 0) {
64
+ console.log('Price empty value', props.value)
65
+ price.value = NaN
66
+ comparePrice.value = NaN
64
67
  } else {
65
- this.discountPercent = Math.abs(this.value - this.compareValue) / this.compareValue
68
+ if (typeof props.value === 'object') {
69
+ discountPercent.value = Math.abs(props.value.min - props.compareValue.min) / props.compareValue.min
70
+ } else {
71
+ discountPercent.value = Math.abs(props.value - props.compareValue) / props.compareValue
72
+ }
66
73
  }
67
74
  }
68
- }
69
75
 
70
- this.refresh(this.value, this.compareValue)
76
+ refresh(props.value, props.compareValue)
71
77
 
72
- this.$bus.$on('updatePrice', (value, compareValue) => {
73
- if(!value && !compareValue) {
74
- return
75
- }
76
- if (!this.updatable) {
77
- return false
78
- }
79
- this.refresh(value, compareValue)
78
+ eventBus.on('updatePrice', handleUpdatePrice)
79
+ })
80
+
81
+ onUnmounted(() => {
82
+ eventBus.off('updatePrice', handleUpdatePrice)
80
83
  })
84
+
85
+ return {
86
+ comparePrice,
87
+ price,
88
+ from,
89
+ discountPercent,
90
+ formatMoney
91
+ }
81
92
  }
82
93
  }
83
94
  </script>
84
95
 
85
- <style scoped></style>
96
+ <style scoped>
97
+ .price-old {
98
+ text-decoration: line-through;
99
+ margin-right: 0.5rem;
100
+ opacity: 0.7;
101
+ }
102
+
103
+ .price {
104
+ font-weight: 600;
105
+ }
106
+ </style>
@@ -4,7 +4,7 @@
4
4
  name="productSearchForm"
5
5
  action="/search"
6
6
  method="get"
7
- :class="{ active: active == 1 }"
7
+ :class="{ active: active === 1 }"
8
8
  @mouseover="active = 1"
9
9
  @mouseout="active = 0"
10
10
  >
@@ -15,12 +15,12 @@
15
15
  field="name"
16
16
  icon-pack="fas"
17
17
  :data="data"
18
- :value="q ? q : ''"
18
+ v-model="searchQuery"
19
19
  :icon="isFetching ? '' : 'search'"
20
20
  :loading="isFetching"
21
21
  @typing="searchProducts"
22
22
  @select="onSelected"
23
- @keydown.native.enter="onEnter"
23
+ @keydown.enter="onEnter"
24
24
  >
25
25
  <template v-slot="props">
26
26
  <div class="media">
@@ -37,72 +37,67 @@
37
37
  </div>
38
38
  </form>
39
39
  </template>
40
- <script>
40
+ <script setup>
41
+ import { ref, inject, onMounted } from 'vue'
41
42
  import _ from 'underscore'
42
43
  import liveAddEventListener from '../../utils/native-dom'
43
-
44
44
  import { Product } from '../../api'
45
45
 
46
- export default {
47
- name: 'ProductAutocomplete',
48
-
49
- props: {
50
- q: {
51
- type: String,
52
- required: true
53
- },
54
- searchLimit: {
55
- type: String,
56
- required: true
57
- }
58
- },
46
+ defineOptions({ name: 'ProductAutocomplete' })
59
47
 
60
- data() {
61
- return {
62
- data: [],
63
- selected: null,
64
- isFetching: false,
65
- enter: true,
66
- active: 0
67
- }
48
+ const props = defineProps({
49
+ q: {
50
+ type: String,
51
+ required: true
68
52
  },
53
+ searchLimit: {
54
+ type: String,
55
+ required: true
56
+ }
57
+ })
69
58
 
70
- methods: {
71
- searchProducts: _.debounce(function (query_string) {
72
- if (!query_string.length) {
73
- this.data = []
74
- return
75
- }
76
-
77
- this.isFetching = true
59
+ const navigate = inject('navigate', (url) => { window.location.href = url })
78
60
 
79
- Product.search(query_string)
80
- .then((response) => {
81
- let products = response.data.slice(0, this.searchLimit)
82
- this.data = []
83
- products.forEach((item) => this.data.push(item))
84
- })
85
- .finally(() => {
86
- this.isFetching = false
87
- })
88
- }, 250),
61
+ const productSearchForm = ref(null)
62
+ const searchQuery = ref(props.q || '')
63
+ const data = ref([])
64
+ const isFetching = ref(false)
65
+ const enter = ref(true)
66
+ const active = ref(0)
89
67
 
90
- onEnter() {
91
- if (this.enter) {
92
- this.$refs.productSearchForm.submit()
93
- }
94
- },
68
+ const searchProducts = _.debounce((query_string) => {
69
+ if (!query_string.length) {
70
+ data.value = []
71
+ return
72
+ }
95
73
 
96
- onSelected(product) {
97
- this.enter = false
98
- window.location.href = product.url
99
- }
100
- },
74
+ isFetching.value = true
101
75
 
102
- mounted() {
103
- liveAddEventListener('.search-box .icon', 'click', () => {
104
- document.forms.productSearchForm.submit()
76
+ Product.search(query_string)
77
+ .then((response) => {
78
+ let products = response.data.slice(0, props.searchLimit)
79
+ data.value = []
80
+ products.forEach((item) => data.value.push(item))
81
+ })
82
+ .finally(() => {
83
+ isFetching.value = false
105
84
  })
85
+ }, 250)
86
+
87
+ const onEnter = () => {
88
+ if (enter.value) {
89
+ productSearchForm.value.submit()
106
90
  }
107
91
  }
92
+
93
+ const onSelected = (product) => {
94
+ enter.value = false
95
+ navigate(product?.url)
96
+ }
97
+
98
+ onMounted(() => {
99
+ liveAddEventListener('.search-box .icon', 'click', () => {
100
+ document.forms.productSearchForm.submit()
101
+ })
102
+ })
108
103
  </script>