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.

150 lines
3.7 KiB

2 years ago
  1. <template>
  2. <div
  3. :class="[
  4. 'changeCurrency tw-relative tw-justify-center tw-items-center',
  5. hideSwitchPrice ? 'tw-hidden' : 'tw-flex',
  6. ]"
  7. >
  8. <div
  9. :class="[
  10. 'tw-flex tw-items-center tw-mx-[12px] tw-cursor-pointer tw-py-[8px] tw-rounded-[4px]',
  11. show ? 'show' : '',
  12. ]"
  13. @click="show = !show"
  14. v-click-outside="clickOutSide"
  15. >
  16. <div class="tw-body-3 tw-mr-[15px]">
  17. {{ price }}
  18. </div>
  19. <img src="@/assets/svg/down-arrow.svg" />
  20. </div>
  21. <transition name="fade">
  22. <div
  23. v-show="show"
  24. class="tw-rounded-[10px] tw-bg-white tw-px-[12px] tw-py-[8px] tw-absolute tw-top-[40px] tw-left-0 tw-w-max tw-z-10"
  25. >
  26. <button
  27. class="tw-grid tw-grid-cols-[20px_auto] tw-gap-[25px] tw-px-[12px] tw-py-[11px] tw-w-full tw-bg-white hover:tw-bg-primary-pale hover:tw-text-primary-1 hover:tw-rounded-[10px]"
  28. @click="Currencystatus('USD')"
  29. >
  30. <div class="tw-body-4 tw-font-bold" value="USD">USD</div>
  31. <div class="tw-body-4 tw-text-left">{{ $t("U.S. Dollar") }}</div>
  32. </button>
  33. <button
  34. class="tw-grid tw-grid-cols-[20px_auto] tw-gap-[25px] tw-px-[12px] tw-py-[11px] tw-w-full tw-bg-white hover:tw-bg-primary-pale hover:tw-text-primary-1 hover:tw-rounded-[10px]"
  35. @click="Currencystatus('TWD')"
  36. >
  37. <div class="tw-body-4 tw-font-bold tw-mr-[20px]" value="TWD">TWD</div>
  38. <div class="tw-body-4 tw-text-left">
  39. {{ $t("New Taiwan Dollar") }}
  40. </div>
  41. </button>
  42. </div>
  43. </transition>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. show: false,
  51. price: "",
  52. changeCurrency: false,
  53. };
  54. },
  55. mounted() {
  56. this.change();
  57. },
  58. computed: {
  59. currentLang() {
  60. return this.$i18n.locale;
  61. },
  62. hideSwitchPrice() {
  63. let vm = this;
  64. if (vm.$route.matched.length > 0) {
  65. if (vm.$route.matched[0].path == "/service/checkout/:id?") {
  66. vm.$store.dispatch("hideSwitchPrice", true);
  67. } else {
  68. vm.$store.dispatch("hideSwitchPrice", false);
  69. }
  70. }
  71. return this.$store.getters.getHidePrice;
  72. },
  73. },
  74. watch: {
  75. currentLang: {
  76. handler: function () {
  77. this.change();
  78. }
  79. }
  80. },
  81. methods: {
  82. change() {
  83. if (process.browser) {
  84. let storageprice = localStorage.getItem("currency");
  85. if (storageprice) {
  86. this.price = storageprice;
  87. this.$store.dispatch("updateCurrency", storageprice);
  88. } else {
  89. if (this.$i18n.locale == 'zh-tw') {
  90. this.price = "TWD";
  91. this.$store.dispatch("updateCurrency", "TWD");
  92. } else {
  93. this.price = "USD";
  94. this.$store.dispatch("updateCurrency", "USD");
  95. }
  96. }
  97. }
  98. },
  99. Currencystatus(data) {
  100. this.price = data;
  101. localStorage.setItem("currency", data);
  102. this.$store.dispatch("updateCurrency", data);
  103. this.show = false;
  104. },
  105. clickOutSide() {
  106. this.show = false;
  107. },
  108. },
  109. };
  110. </script>
  111. <style lang="scss" scoped>
  112. .changeCurrency > div {
  113. border-radius: 4px;
  114. &:hover {
  115. &::before {
  116. opacity: 0.08;
  117. // background-color: rgba(238, 149, 70, 0.6);
  118. bottom: 0;
  119. content: " ";
  120. display: block;
  121. left: 0;
  122. pointer-events: none;
  123. position: absolute;
  124. right: 0;
  125. top: 0;
  126. width: 100%;
  127. height: 100%;
  128. }
  129. }
  130. }
  131. .changeCurrency > div.show {
  132. &::before {
  133. opacity: 0.24;
  134. background-color: rgba(238, 149, 70, 0.6);
  135. bottom: 0;
  136. content: " ";
  137. display: block;
  138. left: 0;
  139. pointer-events: none;
  140. position: absolute;
  141. right: 0;
  142. top: 0;
  143. width: 100%;
  144. height: 100%;
  145. }
  146. }
  147. </style>