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.

151 lines
3.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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. disabled ? 'disabled' : '',
  7. disabled ? 'tw-text-neutrals-300' : 'tw-text-black',
  8. ]"
  9. >
  10. <div
  11. :class="[
  12. 'tw-flex tw-items-center tw-mx-[12px] tw-cursor-pointer tw-py-[8px] tw-rounded-[4px]'
  13. ]"
  14. >
  15. <div class="tw-body-3 tw-mr-[15px] t16 tw-font-normal">
  16. {{ price }}
  17. </div>
  18. <img v-if="disabled" src="@/assets/svg/down-arrow-disabled.svg" />
  19. <img v-else 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 tw-shadow-[0_2px_20px_rgba(0,0,0,0.15)]"
  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('NTD')"
  36. >
  37. <div class="tw-body-4 tw-font-bold tw-mr-[20px]" value="NTD">NTD</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. disabled: true,
  51. show: false,
  52. price: "",
  53. changeCurrency: false,
  54. };
  55. },
  56. mounted() {
  57. this.change();
  58. },
  59. computed: {
  60. currentLang() {
  61. return this.$i18n.locale;
  62. },
  63. hideSwitchPrice() {
  64. let vm = this;
  65. if (vm.$route.matched.length > 0) {
  66. if (vm.$route.matched[0].path == "/service/checkout/:id?") {
  67. vm.$store.dispatch("hideSwitchPrice", true);
  68. } else {
  69. vm.$store.dispatch("hideSwitchPrice", false);
  70. }
  71. }
  72. return this.$store.getters.getHidePrice;
  73. },
  74. },
  75. watch: {
  76. currentLang: {
  77. handler: function () {
  78. this.change();
  79. }
  80. }
  81. },
  82. methods: {
  83. change() {
  84. if (process.browser) {
  85. let storageprice = localStorage.getItem("currency");
  86. if (storageprice) {
  87. this.price = storageprice;
  88. this.$store.dispatch("updateCurrency", storageprice);
  89. } else {
  90. if (this.$i18n.locale == 'zh-tw') {
  91. this.price = "NTD";
  92. this.$store.dispatch("updateCurrency", "NTD");
  93. } else {
  94. this.price = "USD";
  95. this.$store.dispatch("updateCurrency", "USD");
  96. }
  97. }
  98. }
  99. },
  100. Currencystatus(data) {
  101. this.price = data;
  102. localStorage.setItem("currency", data);
  103. this.$store.dispatch("updateCurrency", data);
  104. this.show = false;
  105. },
  106. clickOutSide() {
  107. this.show = false;
  108. },
  109. },
  110. };
  111. </script>
  112. <style lang="scss" scoped>
  113. .changeCurrency > div {
  114. border-radius: 4px;
  115. &:hover {
  116. &::before {
  117. opacity: 0.08;
  118. // background-color: rgba(238, 149, 70, 0.6);
  119. bottom: 0;
  120. content: " ";
  121. display: block;
  122. left: 0;
  123. pointer-events: none;
  124. position: absolute;
  125. right: 0;
  126. top: 0;
  127. width: 100%;
  128. height: 100%;
  129. }
  130. }
  131. }
  132. .changeCurrency > div.show {
  133. &::before {
  134. opacity: 0.24;
  135. background-color: rgba(238, 149, 70, 0.6);
  136. bottom: 0;
  137. content: " ";
  138. display: block;
  139. left: 0;
  140. pointer-events: none;
  141. position: absolute;
  142. right: 0;
  143. top: 0;
  144. width: 100%;
  145. height: 100%;
  146. }
  147. }
  148. </style>