You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
4.4 KiB

2 years ago
  1. <template>
  2. <div v-show="show" :class="[
  3. 'optionItem',
  4. index <= 2
  5. ? 'tw-pb-[10px] tw-mb-[10px] tw-border-0 tw-border-b tw-border-solid tw-border-neutrals-100'
  6. : '',
  7. seeMore
  8. ? 'tw-pb-[10px] tw-mb-[10px] tw-border-0 tw-border-b tw-border-solid tw-border-neutrals-100'
  9. : '',
  10. ]">
  11. <div :class="['tw-flex tw-justify-between tw-items-center']">
  12. <div>
  13. <h4 class="t12 tw-mb-[4px] tw-text-neutrals-900 md:t16 md:tw-font-normal">
  14. {{ $t(item.title) }}
  15. </h4>
  16. <!-- <div
  17. class="t12 tw-mb-[4px] tw-text-neutrals-500 md:t16 md:tw-font-normal"
  18. >
  19. {{ $t("Notes : Inclusive Of oooooooooo") }}
  20. </div> -->
  21. <div class="t12 tw-mb-[4px] tw-text-neutrals-900 md:tw-hidden">
  22. ${{ price.toLocaleString() }} {{ currency }}
  23. </div>
  24. </div>
  25. <div class="tw-flex tw-justify-between tw-items-center">
  26. <div class="t12 tw-mr-[35px] tw-text-neutrals-900 tw-hidden md:tw-block md:t16 md:tw-font-normal">
  27. ${{ price.toLocaleString() }} {{ currency }}
  28. </div>
  29. <button :class="[
  30. 'custom-button button-reduce tw-text-transparent tw-p-[6px] tw-rounded-[8px] tw-max-w-[24px] tw-max-h-[24px] tw-mr-[16px] md:tw-max-w-[30px] md:tw-max-h-[30px] md:tw-mr-[42px]',
  31. value == 0 ? 'tw-bg-neutrals-200' : 'tw-bg-primary-default',
  32. ]" @click="reduce()">
  33. reduce
  34. </button>
  35. <div class="tw-min-w-[24px] tw-text-center md:t18 md:tw-font-normal">
  36. {{ value }}
  37. </div>
  38. <button :class="[
  39. 'custom-button button-add tw-text-transparent tw-p-[6px] tw-rounded-[8px] tw-max-w-[24px] tw-max-h-[24px] tw-ml-[16px] md:tw-max-w-[30px] md:tw-max-h-[30px] md:tw-text-medium md:tw-ml-[42px]',
  40. ]" @click="add()">
  41. add
  42. </button>
  43. </div>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. export default {
  49. props: {
  50. index: {
  51. type: Number,
  52. },
  53. item: {
  54. type: Object,
  55. },
  56. hasValue: {
  57. type: Number,
  58. },
  59. seeMore: {
  60. type: Boolean,
  61. },
  62. },
  63. data() {
  64. return {
  65. value: 0,
  66. currentPirce: "US",
  67. };
  68. },
  69. computed: {
  70. currency() {
  71. return this.$store.getters.getCurrency;
  72. },
  73. show() {
  74. if (this.index + 1 <= 3) {
  75. return true;
  76. } else {
  77. if (this.seeMore == true) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. },
  84. inventories() {
  85. return Number(this.item.inventories[0][this.item.title]);
  86. },
  87. price() {
  88. return Number(this.item.prices[0][this.item.title]);
  89. },
  90. totalPrice() {
  91. return Math.round(this.price * this.value * 100) / 100;
  92. },
  93. },
  94. watch: {
  95. hasValue: {
  96. handler: function () {
  97. if (this.hasValue == null) {
  98. this.value = 0;
  99. }
  100. },
  101. },
  102. index: {
  103. handler: function (newVal, oldVal) {
  104. if (newVal !== oldVal) {
  105. this.value = 0;
  106. }
  107. },
  108. },
  109. item: {
  110. handler: function () {
  111. let vm = this;
  112. vm.$nextTick(function () {
  113. vm.$emit("selected", {
  114. spec_id: this.item.spec_id,
  115. spec_name: this.item.title,
  116. number: this.value,
  117. total: this.totalPrice,
  118. });
  119. })
  120. },
  121. }
  122. },
  123. methods: {
  124. add() {
  125. this.value += 1;
  126. if (this.value !== 0) {
  127. this.$emit("disabled", this.index);
  128. }
  129. this.$emit("selected", {
  130. spec_id: this.item.spec_id,
  131. spec_name: this.item.title,
  132. number: this.value,
  133. total: this.totalPrice,
  134. });
  135. },
  136. reduce() {
  137. if (this.value !== 0) {
  138. this.value -= 1;
  139. this.$emit("selected", {
  140. spec_id: this.item.spec_id,
  141. spec_name: this.item.title,
  142. number: this.value,
  143. total: this.totalPrice,
  144. });
  145. }
  146. },
  147. },
  148. };
  149. </script>
  150. <style lang="scss" scoped>
  151. .custom-button {
  152. background-position: center;
  153. background-repeat: no-repeat;
  154. background-size: 12px;
  155. }
  156. .button {
  157. &-reduce {
  158. background-image: url("~/assets/svg/reduce.svg");
  159. background-color: #e5e5e5;
  160. }
  161. &-add {
  162. background-image: url("~/assets/svg/add.svg");
  163. background-color: #f48800;
  164. }
  165. }
  166. .bounce-enter-active {
  167. animation: bounce-in 0.3s ease-out;
  168. }
  169. .bounce-leave-active {
  170. animation: bounce-in 0.3s reverse;
  171. }
  172. @keyframes bounce-in {
  173. 0% {
  174. opacity: 0;
  175. }
  176. 50% {
  177. opacity: 0.5;
  178. }
  179. 100% {
  180. opacity: 1;
  181. }
  182. }
  183. </style>