1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <script lang='ts' setup>
- import { Swiper, SwiperSlide } from 'swiper/vue'
- import { Navigation, Pagination } from 'swiper/modules'
- import { getGoodsRecommendListApi } from '~/api/model/goods'
- // import "swiper/css/pagination"
- import 'swiper/css'
- import 'swiper/css/navigation'
- const props = defineProps({
- id: { type: String, default: '' },
- })
- const swiperVertical = ref<any>(null)
- const modules = [Navigation, Pagination]
- const similarGoodsList = ref<any>([])
- watch(() => props.id, (id: any) => {
- if (!id)
- return
- getSimilarGoodsList(id)
- }, {
- immediate: true,
- })
- async function getSimilarGoodsList(id: any) {
- try {
- const params = {
- id,
- pageNo: 1,
- pageSize: 20,
- }
- const data: any = await getGoodsRecommendListApi(params)
- similarGoodsList.value = data.records
- }
- catch (error) {
- console.log('error', error)
- }
- }
- function onVerticalSwiper(swiper: any) {
- swiperVertical.value = swiper
- }
- function onClickLeft() {
- swiperVertical.value.slidePrev()
- }
- function onClickRight() {
- swiperVertical.value.slideNext()
- }
- </script>
- <template>
- <div v-if="similarGoodsList.length" class="w-1400px mx-auto my-160px">
- <h2 class="!mb-60px fw-700 text-40px text-#363C40 text-center custom-title-font">
- Shop Similar Products
- </h2>
- <div>
- <div class="w-1300px mx-auto pos-relative">
- <div
- class="pos-absolute cursor-pointer left--46px top-200px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
- @click="onClickLeft()"
- >
- <img src="~/assets/images/arrow_left.png" alt="" class="w-26px h-26px" srcset="">
- </div>
- <div
- class="pos-absolute cursor-pointer right--46px top-200px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
- @click="onClickRight()"
- >
- <img src="~/assets/images/arrow_right.png" alt="" class="w-26px h-26px" srcset="">
- </div>
- <Swiper
- v-if="similarGoodsList.length"
- :slides-per-view="4" :space-between="55" :modules="modules" :loop="true" :navigation="false"
- :pagination="true" class="pos-relative" @swiper="onVerticalSwiper"
- >
- <SwiperSlide v-for="(item, index) in similarGoodsList" :key="index">
- <common-goods-item :item="item" />
- </SwiperSlide>
- </Swiper>
- </div>
- </div>
- </div>
- </template>
- <style lang='less' scoped>
- </style>
|