商品详情轮播图及评价图点击预览功能

This commit is contained in:
yangdanqi 2022-05-01 18:45:54 +08:00
parent 3918c52643
commit 4f1d542908
2 changed files with 37 additions and 10 deletions

View File

@ -19,7 +19,7 @@
</view>
<view class="grid flex-sub padding-lr col-3 grid-square" v-if="reviewer.picList">
<view class="bg-img" :style="'background-image:url(' + item.url + ');'"
v-for="(item, index) in reviewer.picList" :key="index" v-if="index < 3">
v-for="(item, index) in reviewer.picList" :key="index" v-if="index < 3" :data-url="item.url" :data-imgs="reviewer.picList" @click="viewImage($event)">
</view>
</view>
</view>
@ -42,7 +42,18 @@
}
},
methods: {
viewImage(e) {
let imgList = e.currentTarget.dataset.imgs;
let curUrl = e.currentTarget.dataset.url;
let picList = [];
for(let i = 0; i < imgList.length; i++) {
picList.push(imgList[i].url);
}
uni.previewImage({
urls: picList,
current: curUrl
});
}
}
}
</script>

View File

@ -17,7 +17,7 @@
</uni-transition>
<!-- 轮播图视频 -->
<swiper class="screen-swiper" @change="changeSwiper">
<swiper-item v-for="(item,index) in swiperList" :key="item.id" @click="pauseVideo($event, item)">
<swiper-item v-for="(item,index) in swiperList" :key="item.id" @click="clickSwiper($event, item)">
<image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
<video v-if="item.type=='video'" id="productVideo" :src="item.url" :controls="true" :autoplay="false"
:show-center-play-btn="true" :show-fullscreen-btn="false"></video>
@ -177,7 +177,8 @@
ifShowPageMeta: false,
orderNow: false,
totalPickCount: 0,
ifHasCsMsg: true
ifHasCsMsg: true,
swiperPicUrls: []
}
},
onLoad() {
@ -204,6 +205,11 @@
this.reviewers = productDetail.reviewers;
this.productDetailImgUrl = productDetail.productDetailImgUrl;
this.shopInfo = productDetail.shopInfo;
for (let i = 0; i < this.swiperList.length; i++) {
if (this.swiperList[i].type === 'image') {
this.swiperPicUrls.push(this.swiperList[i].url);
}
}
},
bindEvent() {
uni.$on('product-detail_add2Cart', this.add2Cart);
@ -217,10 +223,20 @@
showAllSpecs() {
this.isShowAllSpecs = !this.isShowAllSpecs;
},
pauseVideo(e, item) {
if (item.type !== 'video') {
return;
clickSwiper(e, item) {
if (item.type === 'image') {
this.viewImage(item.url);
} else if (item.type === 'video') {
this.pauseVideo(e);
}
},
viewImage(url) {
uni.previewImage({
urls: this.swiperPicUrls,
current: url
});
},
pauseVideo(e) {
if (this.productVideoPlaying) {
this.productVideoContext.pause();
} else {