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.

202 lines
4.8 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. {{ 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. choicesIndex: {
  54. type: Number
  55. },
  56. item: {
  57. type: Object,
  58. },
  59. choices: {
  60. type: Object
  61. },
  62. hasValue: {
  63. type: Number,
  64. },
  65. seeMore: {
  66. type: Boolean,
  67. },
  68. },
  69. data() {
  70. return {
  71. value: 0,
  72. currentPirce: "US",
  73. };
  74. },
  75. computed: {
  76. currency() {
  77. return this.$store.getters.getCurrency;
  78. },
  79. show() {
  80. if (this.index + 1 <= 3) {
  81. return true;
  82. } else {
  83. if (this.seeMore == true) {
  84. return true;
  85. } else {
  86. return false;
  87. }
  88. }
  89. },
  90. inventories() {
  91. return Number(this.item.inventories[this.choicesIndex][this.choices.text]);
  92. },
  93. price() {
  94. return Number(this.item.prices[this.choicesIndex][this.choices.text]);
  95. },
  96. totalPrice() {
  97. return Math.round(this.price * this.value * 100) / 100;
  98. },
  99. },
  100. watch: {
  101. hasValue: {
  102. handler: function () {
  103. if (this.hasValue == null) {
  104. this.value = 0;
  105. }
  106. },
  107. },
  108. choicesIndex: {
  109. handler: function (newVal, oldVal) {
  110. if (newVal !== oldVal) {
  111. this.value = 0;
  112. }
  113. },
  114. },
  115. item: {
  116. handler: function () {
  117. let vm = this;
  118. vm.$nextTick(function () {
  119. vm.$emit("selected", {
  120. choice_id: this.choices.choice_id,
  121. choice_name: this.choices.text,
  122. spec_id: this.item.spec_id,
  123. spec_name: this.item.title,
  124. number: this.value,
  125. total: this.totalPrice,
  126. });
  127. })
  128. },
  129. }
  130. },
  131. methods: {
  132. add() {
  133. this.value += 1;
  134. if (this.value !== 0) {
  135. this.$emit("disabled", this.index);
  136. }
  137. this.$emit("selected", {
  138. choice_id: this.choices.choice_id,
  139. choice_name: this.choices.text,
  140. spec_id: this.item.spec_id,
  141. spec_name: this.item.title,
  142. number: this.value,
  143. total: this.totalPrice,
  144. });
  145. },
  146. reduce() {
  147. if (this.value !== 0) {
  148. this.value -= 1;
  149. this.$emit("selected", {
  150. choice_id: this.choices.choice_id,
  151. choice_name: this.choices.text,
  152. spec_id: this.item.spec_id,
  153. spec_name: this.item.title,
  154. number: this.value,
  155. total: this.totalPrice,
  156. });
  157. }
  158. },
  159. },
  160. };
  161. </script>
  162. <style lang="scss" scoped>
  163. .custom-button {
  164. background-position: center;
  165. background-repeat: no-repeat;
  166. background-size: 12px;
  167. }
  168. .button {
  169. &-reduce {
  170. background-image: url("~/assets/svg/reduce.svg");
  171. background-color: #e5e5e5;
  172. }
  173. &-add {
  174. background-image: url("~/assets/svg/add.svg");
  175. background-color: #f48800;
  176. }
  177. }
  178. .bounce-enter-active {
  179. animation: bounce-in 0.3s ease-out;
  180. }
  181. .bounce-leave-active {
  182. animation: bounce-in 0.3s reverse;
  183. }
  184. @keyframes bounce-in {
  185. 0% {
  186. opacity: 0;
  187. }
  188. 50% {
  189. opacity: 0.5;
  190. }
  191. 100% {
  192. opacity: 1;
  193. }
  194. }
  195. </style>