Files
barter-app/pages/property/coupon/coupon.vue

293 lines
6.4 KiB
Vue

<template>
<view class="Coupon">
<!-- 分类 -->
<view class="scroll-top">
<scroll-view class="scroll-view_H" scroll-x="true" :scroll-into-view='"nav"+selectNavId'
scroll-with-animation="true">
<view v-for="(item,index) in navList" :key="index" :id="'nav'+item.id" @click="selectNav(item.id)"
:class="['scroll-view-item_H',selectNavId === item.id ?'scroll-view-item_H_selected':'']">
{{item.name}}
<block v-if='index === 0'>({{count.all}})</block>
<block v-if='index === 1'>({{count.services}})</block>
<block v-if='index === 2'>({{count.reductions}})</block>
<block v-if='index === 3'>({{count.exchanges}})</block>
</view>
</scroll-view>
<scroll-view class="scroll-view_H-1" scroll-x="true" :scroll-into-view='"nav"+selectCategoryId'
scroll-with-animation="true">
<view v-for="(item,index) in categroyList" :key="index" :id="'nav'+item.id"
@click="selectCategory(item.id)"
:class="['scroll-view-item_H-1',selectCategoryId === item.id ?'scroll-view-item_H_selected-1':'']">
{{item.name}}
</view>
</scroll-view>
</view>
<!-- 有优惠券列表 -->
<view class="coupon-content">
<couponTemplate v-for="(item,index) in lists" :key='index' :item="{...item}" :action="actions" />
</view>
<!-- 没有优惠券列表 -->
<no-list v-if="lists.length === 0" name='no-counpon' :txt="showTxt" />
<!-- <u-toast ref="uToast" /> -->
<u-toast ref="uToast" />
</view>
</template>
<script>
import {
myCoupon
} from '@/apis/interfaces/coupon'
import couponTemplate from '@/components/coupon-template/coupon-template-1'
export default {
data() {
return {
actions: {
name: '去使用',
type: 'toUsed'
},
lists:[],
count:{
all:0,
services:0,
reductions:0,
exchanges:0,
},
navList: [{
id: '',
name: '全部'
}, {
id: '1',
name: '服务券'
},
{
id: '2',
name: '代金券'
},
{
id: '3',
name: '提货券'
}
],
categroyList: [{
id: '4',
name: '新到'
},
{
id: '5',
name: '即将到期'
},
{
id: '1',
name: '待使用'
}, {
id: '2',
name: '已使用'
}, {
id: '3',
name: '已过期'
}
],
selectCategoryId: '', // 默认选择分类 默认第一个
selectNavId: '',
showTxt: '没有任何优惠券哦~',
};
},
components: {
couponTemplate
},
onLoad(e) {
this.getMyCoupon()
},
onShow() {
if (wx.getStorageSync('refresh')) {
this.lists = []
this.getMyCoupon()
}
},
onPullDownRefresh() {
this.lists = []
this.getMyCoupon()
},
methods: {
// 优惠券列表
getMyCoupon() {
let data = {
type: this.selectNavId
}
if(this.selectCategoryId==='4' || this.selectCategoryId==='5'){
data.status = ''
if(this.selectCategoryId === '4'){
data.time = 'new'
}else{
data.time = 'expire'
}
}else{
data.status = this.selectCategoryId
}
console.log(data)
myCoupon(data).then(res => {
console.log(res)
this.lists = res.lists
this.count = res.count
uni.stopPullDownRefresh()
wx.setStorageSync('refresh', false)
}).catch(err => {
this.$refs.uToast.show({
title: err.message,
duration: 3000
})
})
},
// 切换商品分类
selectNav(id) {
console.log(id)
this.selectNavId = id
this.getMyCoupon()
},
selectCategory(id) {
console.log(id)
this.selectCategoryId = id
this.getMyCoupon()
}
}
}
</script>
<style lang="scss" scoped>
.Coupon {
width: 100%;
min-height: 100vh;
box-sizing: border-box;
padding-bottom: 20rpx;
background-color: #F7F7F7;
.coupon-nav {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-around;
box-sizing: border-box;
background-color: #fff;
padding: 30rpx 60rpx 0 60rpx;
color: #cacaca;
.nav-item {
padding: 20rpx 30rpx 30rpx 30rpx;
border-bottom: solid 4rpx #fff;
font-size: 36rpx;
font-weight: bold;
}
.nav-item-select {
border-bottom: solid 6rpx $main-color;
color: $main-color;
}
}
.scroll-top {
position: sticky;
top: 0;
z-index: 1000;
.scroll-view_H {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
box-sizing: border-box;
white-space: nowrap;
width: 100%;
padding: 30rpx 30rpx 0 30rpx;
background-color: #fff;
.scroll-view-item_H {
margin-right: 60rpx;
padding: 20rpx 0 40rpx 0;
// height: 100rpx;
display: inline-block;
min-width: 120rpx;
font-size: 28rpx;
border-bottom: #fff;
background-color: #fff;
transition: .1s;
text-align: center;
}
.scroll-view-item_H_selected {
// border-bottom: solid $main-color 4rpx;
color: $main-color;
font-weight: bold;
// font-size: 36rpx;
// transition: .3s;
text-shadow: 6rpx 8rpx 30rpx rgba($color: $main-color, $alpha: .5);
position: relative;
&:after {
// content: '';
// position: absolute;
// bottom: 10rpx;
// left: 0;
// height: 8rpx;
// width: 100%;
// background-color: $main-color;
}
}
}
.scroll-view_H-1 {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
box-sizing: border-box;
white-space: nowrap;
width: 100%;
padding: 0 30rpx 30rpx 30rpx;
background-color: #fff;
// position: sticky;
// top: 100rpx;
// z-index: 1000;
.scroll-view-item_H-1 {
display: inline-block;
min-width: 120rpx;
font-size: 24rpx;
border-bottom: #fff;
background-color: #f7f7f7;
margin-left: 20rpx;
padding: 10rpx 30rpx;
text-align: center;
border-radius: 40rpx;
}
.scroll-view-item_H_selected-1 {
// border-bottom: solid $main-color 4rpx;
color: #fff;
font-weight: bold;
background-image: linear-gradient(to left, $main-color, $main-color-light);
// font-size: 36rpx;
// transition: .3s;
// text-shadow: 6rpx 8rpx 30rpx rgba($color: $main-color, $alpha: .5);
position: relative;
&:after {
// content: '';
// position: absolute;
// bottom: 10rpx;
// left: 0;
// height: 8rpx;
// width: 100%;
// background-color: $main-color;
}
}
}
}
}
</style>