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.

250 lines
6.0 KiB

2 years ago
  1. <template>
  2. <section :class="['tw-relative tw-mt-[30px] tw-overflow-hidden']">
  3. <div class="swiper-container relatedService tw-mx-auto tw-max-w-full tw-overflow-hidden" ref="relatedService">
  4. <div :class="['swiper-wrapper tw-z-0']">
  5. <button :class="[
  6. 'swiper-slide tw-w-fit tw-body-4 tw-border tw-border-solid tw-border-neutral-700 tw-rounded-[12px] tw-px-[16px] tw-py-[10px] md:tw-body-3',
  7. categoryid == 0 ? 'active' : '',
  8. ]" @click="getAll()">{{ $t('service.All') }}
  9. </button>
  10. <button :class="[
  11. 'swiper-slide tw-w-fit tw-body-4 tw-border tw-border-solid tw-border-neutral-700 tw-rounded-[12px] tw-px-[16px] tw-py-[10px] tw-whitespace-nowrap md:tw-body-3',
  12. categoryid == item.ids[0] ? 'active' : '',
  13. ]" v-for="(item, index) in getCategory" :key="index" @click="getCategoryId(item.ids[0])">
  14. {{ item.lang_text }}
  15. </button>
  16. </div>
  17. <div :class="['whitelinear tw-absolute tw-z-10 tw-mt-[-43px] tw-right-0']"></div>
  18. <div :class="[
  19. 'swiper-button-prev rs',
  20. relatedServiceSwiper ? 'md:tw-block' : '',
  21. ]"></div>
  22. <div :class="[
  23. 'swiper-button-next rs',
  24. relatedServiceSwiper ? 'md:tw-block' : '',
  25. ]"></div>
  26. </div>
  27. </section>
  28. </template>
  29. <script>
  30. import { $ } from "dom7";
  31. import Swiper from "swiper/bundle";
  32. export default {
  33. components: {
  34. Swiper,
  35. },
  36. data() {
  37. return {
  38. relatedServiceSwiper: null,
  39. categoryName: "",
  40. categoryid: 0,
  41. };
  42. },
  43. props: {
  44. getCategory: {
  45. type: Array,
  46. },
  47. },
  48. mounted() {
  49. let vm = this;
  50. vm.$nextTick(function () {
  51. vm.relatedServiceSwiper = new Swiper(".swiper-container.relatedService", {
  52. direction: "horizontal",
  53. initialSlide: 0, //slide的索引值,從第0筆開始顯示
  54. slidesPerView: "auto", //顯示的slides数量
  55. slidesPerGroup: 4, //每次slide的數量
  56. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  57. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  58. spaceBetween: 10,
  59. slideToClickedSlide: true,
  60. navigation: {
  61. nextEl: ".swiper-button-next.rs",
  62. prevEl: ".swiper-button-prev.rs",
  63. },
  64. breakpoints: {
  65. 768: {
  66. spaceBetween: 12,
  67. },
  68. },
  69. });
  70. });
  71. },
  72. methods: {
  73. getCategoryId(data) {
  74. this.categoryid = data;
  75. this.$emit("test", this.categoryid);
  76. this.$emit("categoryid", `/service?category=${this.categoryid}`);
  77. },
  78. getAll() {
  79. this.categoryid = 0;
  80. this.$emit("getAllServiceList");
  81. this.$emit("categoryid", `/service`);
  82. },
  83. test() {
  84. if (this.activeIndex == this.categoryid) {
  85. return true;
  86. }
  87. },
  88. },
  89. };
  90. </script>
  91. <style lang="scss" scoped>
  92. .swiper-container {
  93. width: 100% !important;
  94. }
  95. .swiper-slide {
  96. color: #696969;
  97. background-color: white;
  98. }
  99. .active {
  100. background-color: #757575;
  101. color: #fefefe;
  102. }
  103. .swiper-button {
  104. // &-prev.rs {
  105. // z-index: 4;
  106. // text-align: center;
  107. // height: 45px;
  108. // width: 45px;
  109. // background-image: url("~/assets/svg/relatedServiceArrow.svg");
  110. // background-size: 100%;
  111. // transform: rotate(180deg);
  112. // background-repeat: no-repeat;
  113. // // &:focus-visible,
  114. // // &:focus {
  115. // // outline: none;
  116. // // }
  117. // &::after {
  118. // text-align: center;
  119. // color: transparent;
  120. // // background-image: url("~/assets/svg/relatedServiceArrow.svg");
  121. // background-position: center;
  122. // height: 45px;
  123. // width: 45px;
  124. // background-repeat: no-repeat;
  125. // background-size: 100%;
  126. // }
  127. // }
  128. // &-next.rs {
  129. // z-index: 9;
  130. // text-align: center;
  131. // height: 45px;
  132. // width: 45px;
  133. // background-image: url("~/assets/svg/relatedServiceArrow.svg");
  134. // background-size: 100%;
  135. // background-repeat: no-repeat;
  136. // // position: relative;
  137. // &::after {
  138. // text-align: center;
  139. // color: transparent;
  140. // // background-image: url("~/assets/svg/relatedServiceArrow.svg");
  141. // background-position: center;
  142. // background-repeat: no-repeat;
  143. // background-size: cover;
  144. // }
  145. // }
  146. }
  147. .swiper-button {
  148. &-prev.rs {
  149. left: 0;
  150. &::before {
  151. content: "";
  152. display: block;
  153. width: 60px;
  154. height: 100%;
  155. background-image: url("~/assets/svg/swiper_linear.svg");
  156. // background-image: linear-gradient(to left, transparent, #fff);
  157. position: absolute;
  158. left: 0;
  159. top: -4px;
  160. z-index: -1;
  161. transform: rotate(180deg);
  162. @media screen and (min-width: 1366px) {
  163. width: 56px;
  164. }
  165. }
  166. &:after {
  167. content: "";
  168. display: block;
  169. position: absolute;
  170. top: 6px;
  171. right: -6px;
  172. background-image: url("~/assets/svg/relatedServiceArrow.svg");
  173. background-position: center;
  174. background-repeat: no-repeat;
  175. background-size: 32px;
  176. transform: rotate(180deg);
  177. width: 32px;
  178. height: 32px;
  179. }
  180. }
  181. &-next.rs {
  182. right: 0;
  183. &::before {
  184. content: "";
  185. display: block;
  186. width: 60px;
  187. height: 100%;
  188. background-image: url("~/assets/svg/swiper_linear.svg");
  189. // background-image: linear-gradient(to right, transparent, #fff);
  190. position: absolute;
  191. right: 0;
  192. top: 4px;
  193. z-index: -1;
  194. @media screen and (min-width: 1366px) {
  195. width: 56px;
  196. }
  197. }
  198. &:after {
  199. content: "";
  200. display: block;
  201. position: absolute;
  202. top: 6px;
  203. left: -6px;
  204. background-image: url("~/assets/svg/relatedServiceArrow.svg");
  205. background-position: center;
  206. background-repeat: no-repeat;
  207. background-size: 32px;
  208. width: 32px;
  209. height: 32px;
  210. }
  211. }
  212. }
  213. :deep(.swiper-container) {
  214. .swiper-slide {
  215. display: flex;
  216. }
  217. [aria-disabled="true"] {
  218. opacity: 0;
  219. &::after {
  220. pointer-events: none;
  221. }
  222. &::before {
  223. pointer-events: none;
  224. }
  225. }
  226. }
  227. </style>