cashier_wx/pages/index/components/advertisement.vue

242 lines
5.1 KiB
Vue

<template>
<view class="onecontent flex-between">
<view class="onecontentleft" v-if="bannervo">
现有<text style="color: #FC851E;font-size: 24rpx;">
{{bannervo.coupons==null?116:bannervo.coupons}}人
</text>
已免单
</view>
<view class="onecontentright flex-start">
<view class="onecontentrightimage" v-if="bannervo">
<view class="swiperPanel" @touchstart="startMove" @touchend="endMove">
<view class="swiperItem" v-for="(item, index) in bannervo.counponsInfo" :key="index"
:style="{transform: itemStyle[index].transform, zIndex: itemStyle[index].zIndex, opacity: itemStyle[index].opacity}">
<view class="children">
<image class="pic" :src="item.logo"></image>
</view>
</view>
</view>
</view>
<view class="onecontentrighttext">
<swiper class="swiper" circular :autoplay="true" :vertical='true' :interval="2000">
<swiper-item class="swiperitem" v-for="(item,index) in bannervo.counponsInfo" :key="index">
{{item.name}}已省{{item.money}}元钱
</swiper-item>
</swiper>
</view>
</view>
<!-- 小内切圆 -->
<view class="after"></view>
</view>
</template>
<script setup>
import {
defineProps,
onBeforeUnmount,
reactive,
defineExpose
} from 'vue';
const props = defineProps({
bannervo: {
type: Object,
default: () => ({}) //
},
itemStyle: {
type: Array,
default: () => [{
transform: 'scale(' + (1) + ') translate(-' + (0 * 20) + '%,0px)',
zIndex: 9999,
opacity: 1
}] //
}
});
const slideNote = reactive({
x: 0,
y: 0
})
const startMove = (e) => {
slideNote.x = e.changedTouches[0] ? e.changedTouches[0].pageX : 0;
}
const endMove = (e) => {
// this.itemStyless = []
var newList = props.itemStyle
console.log(newList)
// if ((e.changedTouches[0].pageX - slideNote.x) < 0) {
// 向左滑动
var last = [newList.pop()]
newList = last.concat(newList)
// } else {
// 向右滑动
// newList.push(newList[0])
// newList.splice(0, 1)
// }
console.log(newList)
// this.$emit('changeValue', newList);
}
// 定义定时器变量
let timer = null;
// 启动定时器
const startTimer = () => {
timer = setInterval(() => {
endMove()
}, 1000);
};
// 定义清除定时器的方法
const clearTimer = () => {
if (timer) {
clearInterval(timer);
timer = null;
}
};
// 在组件销毁前清除定时器
onBeforeUnmount(() => {
clearTimer();
});
// 向外暴露清除定时器和启动定时器的方法
defineExpose({
clearTimer,
startTimer
});
// 初始启动定时器
// startTimer();
</script>
<style scoped lang="scss">
.onecontent {
position: relative;
margin-top: -34rpx;
padding: 14rpx 28rpx 44rpx 28rpx;
width: 100%;
background: linear-gradient(92deg, #FCECAA 0%, #fff 100%);
border-radius: 40rpx 0rpx 0rpx 0rpx;
.onecontentleft {
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 700;
font-size: 24rpx;
color: #333333;
display: flex;
align-items: center;
justify-content: center;
text {
color: #FC851E;
}
}
.onecontentright {
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 24rpx;
color: #333333;
display: flex;
align-items: center;
justify-content: center;
.onecontentrightimage {
width: 65rpx;
position: relative;
overflow: hidden;
height: 28rpx;
margin-right: 10rpx;
.swiperPanel {
height: 28rpx;
width: 100rpx;
overflow: hidden;
position: relative;
.swiperItem {
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
transition: all .5s;
/* 定义一个动画关键帧 */
.children {
height: 100%;
width: 25%;
// margin: 2rpx auto;
/* 应用动画,设置动画时长、循环次数和速度曲线 */
.pic {
height: 100%;
width: 100%;
border-radius: 50%;
// box-shadow: 0 0 10px #333;
}
}
}
}
.onecontentrightimageabsolute {
width: 100%;
left: 0;
top: 0;
position: absolute;
z-index: 9;
height: 28rpx;
}
.onecontentrightimageabsolutetow {
width: 100%;
left: 14rpx;
top: 0;
position: absolute;
z-index: 10;
}
// .onecontentrightswiper {
// border: 50%;
// width: 28rpx;
// height: 28rpx;
// background: red;
// }
}
.onecontentrighttext {
width: 232rpx;
.swiper {
height: 28rpx;
// width: 232rpx;
.swiperitem {
width: 100rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 20rpx;
color: #333333;
overflow: hidden; //超出的文本隐藏
text-overflow: ellipsis; //溢出用省略号显示
white-space: nowrap; //溢出不换行
}
}
}
}
.after {
position: absolute;
top: -40rpx;
right: 0rpx;
width: 40rpx;
height: 40rpx;
line-height: 40rpx;
text-align: center;
background-image: radial-gradient(160rpx at 0px 0px, rgba(0, 0, 0, 0) 40rpx, #fff 40rpx);
z-index: 9999;
}
}
</style>