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.

210 lines
4.9 KiB

2 years ago
2 years ago
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. if(this.item.prices){
  92. return Number(this.item.inventories[this.choicesIndex][this.choices.text]);
  93. }else{
  94. return 0;
  95. }
  96. },
  97. price() {
  98. if(this.item.prices){
  99. return Number(this.item.prices[this.choicesIndex][this.choices.text]);
  100. }else{
  101. return 0;
  102. }
  103. },
  104. totalPrice() {
  105. return Math.round(this.price * this.value * 100) / 100;
  106. },
  107. },
  108. watch: {
  109. hasValue: {
  110. handler: function () {
  111. if (this.hasValue == null) {
  112. this.value = 0;
  113. }
  114. },
  115. },
  116. choicesIndex: {
  117. handler: function (newVal, oldVal) {
  118. if (newVal !== oldVal) {
  119. this.value = 0;
  120. }
  121. },
  122. },
  123. item: {
  124. handler: function () {
  125. let vm = this;
  126. vm.$nextTick(function () {
  127. vm.$emit("selected", {
  128. choice_id: this.choices.choice_id,
  129. choice_name: this.choices.text,
  130. spec_id: this.item.spec_id,
  131. spec_name: this.item.title,
  132. number: this.value,
  133. total: this.totalPrice,
  134. });
  135. })
  136. },
  137. }
  138. },
  139. methods: {
  140. add() {
  141. this.value += 1;
  142. if (this.value !== 0) {
  143. this.$emit("disabled", this.index);
  144. }
  145. this.$emit("selected", {
  146. choice_id: this.choices.choice_id,
  147. choice_name: this.choices.text,
  148. spec_id: this.item.spec_id,
  149. spec_name: this.item.title,
  150. number: this.value,
  151. total: this.totalPrice,
  152. });
  153. },
  154. reduce() {
  155. if (this.value !== 0) {
  156. this.value -= 1;
  157. this.$emit("selected", {
  158. choice_id: this.choices.choice_id,
  159. choice_name: this.choices.text,
  160. spec_id: this.item.spec_id,
  161. spec_name: this.item.title,
  162. number: this.value,
  163. total: this.totalPrice,
  164. });
  165. }
  166. },
  167. },
  168. };
  169. </script>
  170. <style lang="scss" scoped>
  171. .custom-button {
  172. background-position: center;
  173. background-repeat: no-repeat;
  174. background-size: 12px;
  175. }
  176. .button {
  177. &-reduce {
  178. background-image: url("~/assets/svg/reduce.svg");
  179. background-color: #e5e5e5;
  180. }
  181. &-add {
  182. background-image: url("~/assets/svg/add.svg");
  183. background-color: #f48800;
  184. }
  185. }
  186. .bounce-enter-active {
  187. animation: bounce-in 0.3s ease-out;
  188. }
  189. .bounce-leave-active {
  190. animation: bounce-in 0.3s reverse;
  191. }
  192. @keyframes bounce-in {
  193. 0% {
  194. opacity: 0;
  195. }
  196. 50% {
  197. opacity: 0.5;
  198. }
  199. 100% {
  200. opacity: 1;
  201. }
  202. }
  203. </style>