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.
high-mini/pages/user/coupon/coupon.vue

628 lines
14 KiB

<template>
<view>
<view class="tabr" :style="{top:headerTop}">
4 years ago
<view :class="{on:typeClass=='valid'}" @tap="switchType('valid')">可用({{couponValidList.length}})</view>
<view :class="{on:typeClass=='invalid'}" @tap="switchType('invalid')">已失效</view>
<view class="border" :class="typeClass"></view>
</view>
4 years ago
<view class="place"></view>
<view class="list">
<!-- 优惠券列表 -->
<view class="sub-list valid" :class="subState">
<view class="tis" v-if="couponValidList.length==0">
<image mode="widthFix" style="width: 70vw;" src="../../../static/img/noorder.png"></image>
</view>
4 years ago
<view class="row" v-for="(row,index) in couponValidList" :key="index">
<!-- 删除按钮 -->
<view class="menu" @tap.stop="deleteCoupon(row.id,couponValidList)">
<view class="icon shanchu"></view>
</view>
<!-- content -->
4 years ago
<view class="carrier">
<view class="left">
<view class="title">
4 years ago
{{row.highDiscount.discountName}}
</view>
<view class="term">
4 years ago
截止时间:{{row.highDiscount.salesEndTime | formatDate('-')}}
</view>
<view class="gap-top"></view>
<view class="gap-bottom"></view>
</view>
<view class="right">
<view class="ticket">
<view class="num">
4 years ago
{{row.highDiscount.discountPrice}}
</view>
<view class="unit">
</view>
</view>
<view class="criteria">
4 years ago
{{row.highDiscount.discountName}}
</view>
4 years ago
<view class="use" @click="jumpcoupons(row.id)">
去使用
</view>
</view>
</view>
</view>
</view>
<view class="sub-list invalid" :class="subState">
<view class="tis" v-if="couponinvalidList.length==0">
<image mode="widthFix" style="width: 70vw;" src="../../../static/img/noorder.png"></image>
</view>
4 years ago
<view class="row" v-for="(row,index) in couponinvalidList" :key="index">
<!-- 删除按钮 -->
<view class="menu" @tap.stop="deleteCoupon(row.id,couponinvalidList)">
<view class="icon shanchu"></view>
</view>
<!-- content -->
4 years ago
<view class="carrier">
<view class="left">
<view class="title">
4 years ago
{{row.highDiscount.discountName}}
</view>
<view class="term">
4 years ago
截止时间:{{row.highDiscount.salesEndTime | formatDate('-')}}
</view>
<view class="icon shixiao">
4 years ago
</view>
<view class="gap-top"></view>
<view class="gap-bottom"></view>
</view>
<view class="right invalid">
<view class="ticket">
<view class="num">
4 years ago
{{row.highDiscount.discountPrice}}
</view>
<view class="unit">
</view>
</view>
<view class="criteria">
4 years ago
{{row.highDiscount.discountName}}
</view>
<view class="use">
4 years ago
已失效
</view>
</view>
</view>
</view>
</view>
</view>
4 years ago
</view>
</template>
<script>
4 years ago
import {
getUserDiscountList
} from '../../../Utils/Api.js';
export default {
data() {
return {
4 years ago
couponValidList: [],
couponinvalidList: [],
headerTop: 0,
//控制滑动效果
4 years ago
typeClass: 'valid',
subState: '',
theIndex: null,
oldIndex: null,
isStop: false,
pageNum: 1,
pageSize: 10,
isNoMoreData: false,
loadingText: ''
}
},
4 years ago
onPageScroll(e) {
},
//下拉刷新,需要自己在page.json文件中配置开启页面下拉刷新 "enablePullDownRefresh": true
onPullDownRefresh() {
4 years ago
setTimeout(function() {
uni.stopPullDownRefresh();
}, 1000);
},
onLoad() {
4 years ago
this.getUserDiscountList(1);
//兼容H5下排序栏位置
// #ifdef H5
4 years ago
//定时器方式循环获取高度为止,这么写的原因是onLoad中head未必已经渲染出来。
let Timer = setInterval(() => {
let uniHead = document.getElementsByTagName('uni-page-head');
if (uniHead.length > 0) {
this.headerTop = uniHead[0].offsetHeight + 'px';
clearInterval(Timer); //清除定时器
}
}, 1);
// #endif
},
4 years ago
filters: {
//过滤器 用于格式化时间
formatDate: function(value, spe = '/') {
let data = new Date(value);
let year = data.getFullYear();
let month = data.getMonth() + 1;
let day = data.getDate();
let h = data.getHours();
let mm = data.getMinutes();
let s = data.getSeconds();
month = month >= 10 ? month : "0" + month;
day = day >= 10 ? day : "0" + day;
h = h >= 10 ? h : "0" + h;
mm = mm >= 10 ? mm : "0" + mm;
s = s >= 10 ? s : "0" + s;
4 years ago
return `${year}${spe}${month}${spe}${day} ${h}:${mm}:${s}`;
}
},
onReachBottom() {
if (this.typeClass == 'valid') {
this.pageNum = 1;
this.couponValidList = []
this.isNoMoreData = false;
this.getUserDiscountList(1);
} else {
this.pageNum = 1;
this.couponinvalidList = []
this.isNoMoreData = false;
this.getUserDiscountList(2);
}
},
methods: {
4 years ago
//查询我的优惠券
getUserDiscountList(item) {
uni.showLoading({
title: '加载中...'
})
if (this.isNoMoreData) {
uni.hideLoading()
this.loadingText = '到底了';
return false;
}
let pagenum = this.pageNum;
let params = {
pageNum: pagenum,
status: item,
pageSize: this.pageSize
}
getUserDiscountList(params).then(res => {
if (res.return_code == '000000') {
uni.hideLoading();
this.isNoMoreData = res.return_data.list.length == this.pageSize ? false : true;
if (res.return_data.total == (this.pageNum * this.pageSize)) {
this.isNoMoreData = true;
}
4 years ago
if (this.typeClass == 'valid') {
this.couponValidList = this.couponValidList.concat(res.return_data.list);
} else {
this.couponinvalidList = this.couponinvalidList.concat(res.return_data.list);
}
this.pageNum = res.return_data.list.length == this.pageSize ? ++pagenum : pagenum;
4 years ago
} else {
this.couponValidList = [];
this.couponinvalidList = [];
uni.hideLoading()
}
})
},
//跳转详情
jumpcoupons(e) {
uni.navigateTo({
url: '../mineCouponsDestails/mineCouponsDestails?id=' + e
4 years ago
})
},
switchType(type) {
if (this.typeClass == type) {
return;
}
uni.pageScrollTo({
4 years ago
scrollTop: 0,
duration: 0
})
this.typeClass = type;
4 years ago
this.subState = this.typeClass == '' ? '' : 'show' + type;
setTimeout(() => {
this.oldIndex = null;
this.theIndex = null;
4 years ago
this.subState = this.typeClass == 'valid' ? '' : this.subState;
}, 200)
if (this.typeClass == 'valid') {
this.pageNum = 1;
this.couponValidList = []
this.isNoMoreData = false;
this.getUserDiscountList(1);
} else {
this.pageNum = 1;
this.couponinvalidList = []
this.isNoMoreData = false;
this.getUserDiscountList(2);
}
},
//控制左滑删除效果-begin
4 years ago
touchStart(index, event) {
//多点触控不触发
4 years ago
if (event.touches.length > 1) {
this.isStop = true;
4 years ago
return;
}
this.oldIndex = this.theIndex;
this.theIndex = null;
//初始坐标
4 years ago
this.initXY = [event.touches[0].pageX, event.touches[0].pageY];
},
4 years ago
touchMove(index, event) {
//多点触控不触发
4 years ago
if (event.touches.length > 1) {
this.isStop = true;
4 years ago
return;
}
let moveX = event.touches[0].pageX - this.initXY[0];
let moveY = event.touches[0].pageY - this.initXY[1];
4 years ago
if (this.isStop || Math.abs(moveX) < 5) {
return;
}
4 years ago
if (Math.abs(moveY) > Math.abs(moveX)) {
// 竖向滑动-不触发左滑效果
this.isStop = true;
return;
}
4 years ago
if (moveX < 0) {
this.theIndex = index;
this.isStop = true;
4 years ago
} else if (moveX > 0) {
if (this.theIndex != null && this.oldIndex == this.theIndex) {
this.oldIndex = index;
this.theIndex = null;
this.isStop = true;
4 years ago
setTimeout(() => {
this.oldIndex = null;
4 years ago
}, 150)
}
}
},
4 years ago
touchEnd(index, $event) {
//解除禁止触发状态
this.isStop = false;
},
4 years ago
//删除商品
4 years ago
deleteCoupon(id, List) {
let len = List.length;
4 years ago
for (let i = 0; i < len; i++) {
if (id == List[i].id) {
List.splice(i, 1);
break;
}
}
this.oldIndex = null;
this.theIndex = null;
},
4 years ago
discard() {
//丢弃
}
4 years ago
}
}
</script>
<style lang="scss">
4 years ago
view {
display: flex;
flex-wrap: wrap;
4 years ago
}
4 years ago
page {
position: relative;
background-color: #f5f5f5;
}
.hidden {
display: none !important;
}
4 years ago
.place {
width: 100%;
height: 95upx;
}
4 years ago
.tabr {
background-color: #fff;
width: 94%;
height: 95upx;
padding: 0 3%;
border-bottom: solid 1upx #dedede;
position: fixed;
top: 0;
z-index: 10;
4 years ago
view {
width: 50%;
height: 90upx;
justify-content: center;
align-items: center;
font-size: 32upx;
color: #999;
}
4 years ago
.on {
color: #0083f5;
}
4 years ago
.border {
height: 4upx;
background-color: #0083f5;
transition: all .3s ease-out;
4 years ago
&.invalid {
transform: translate3d(100%, 0, 0);
}
}
4 years ago
}
4 years ago
.list {
width: 100%;
display: block;
position: relative;
}
4 years ago
@keyframes showValid {
4 years ago
0% {
transform: translateX(-100%);
}
100% {
transform: translateX(0);
}
}
4 years ago
@keyframes showInvalid {
4 years ago
0% {
transform: translateX(0);
}
100% {
transform: translateX(-100%);
}
}
4 years ago
.sub-list {
&.invalid {
position: absolute;
top: 0;
4 years ago
left: 100%;
display: none;
}
4 years ago
&.showvalid {
display: flex;
animation: showValid 0.20s linear both;
}
4 years ago
&.showinvalid {
display: flex;
animation: showInvalid 0.20s linear both;
}
4 years ago
width: 100%;
padding: 20upx 0 120upx 0;
4 years ago
.tis {
width: 100%;
height: 60upx;
justify-content: center;
align-items: center;
font-size: 32upx;
}
4 years ago
.row {
width: 92%;
4 years ago
height: 24vw;
margin: 20upx auto 10upx auto;
border-radius: 8upx;
// box-shadow: 0upx 0 10upx rgba(0,0,0,0.1);
align-items: center;
position: relative;
overflow: hidden;
z-index: 4;
border: 0;
4 years ago
.menu {
.icon {
color: #fff;
4 years ago
font-size: 50upx;
}
4 years ago
position: absolute;
width: 28%;
height: 100%;
right: 0;
justify-content: center;
align-items: center;
background-color: red;
color: #fff;
z-index: 2;
}
4 years ago
.carrier {
@keyframes showMenu {
4 years ago
0% {
transform: translateX(0);
}
100% {
transform: translateX(-28%);
}
}
4 years ago
@keyframes closeMenu {
4 years ago
0% {
transform: translateX(-28%);
}
100% {
transform: translateX(0);
}
}
4 years ago
&.open {
animation: showMenu 0.25s linear both;
}
4 years ago
&.close {
animation: closeMenu 0.15s linear both;
}
4 years ago
background-color: #fff;
position: absolute;
width: 100%;
padding: 0 0;
height: 100%;
z-index: 3;
flex-wrap: nowrap;
4 years ago
.left {
width: 100%;
4 years ago
.title {
padding-top: 3vw;
width: 90%;
margin: 0 5%;
font-size: 36upx;
}
4 years ago
.term {
width: 90%;
margin: 0 5%;
font-size: 26upx;
color: #999;
}
4 years ago
position: relative;
4 years ago
.gap-top,
.gap-bottom {
position: absolute;
width: 20upx;
height: 20upx;
right: -10upx;
border-radius: 100%;
background-color: #f5f5f5;
}
4 years ago
.gap-top {
top: -10upx;
}
4 years ago
.gap-bottom {
bottom: -10upx;
}
4 years ago
.shixiao {
position: absolute;
right: 20upx;
font-size: 150upx;
z-index: 6;
4 years ago
color: rgba(153, 153, 153, 0.2)
}
}
4 years ago
.right {
flex-shrink: 0;
width: 28%;
color: #fff;
4 years ago
background: linear-gradient(to right, #ec625c, #ee827f);
&.invalid {
background: linear-gradient(to right, #aaa, #999);
.use {
color: #aaa;
}
}
4 years ago
justify-content: center;
4 years ago
.ticket,
.criteria {
width: 100%;
}
.ticket {
padding-top: 1vw;
justify-content: center;
align-items: baseline;
height: 6vw;
4 years ago
.num {
font-size: 42upx;
font-weight: 600;
}
4 years ago
.unit {
font-size: 24upx;
}
}
4 years ago
.criteria {
justify-content: center;
4 years ago
font-size: 28upx;
}
4 years ago
.use {
width: 50%;
height: 40upx;
justify-content: center;
align-items: center;
font-size: 24upx;
background-color: #fff;
color: #ee827f;
border-radius: 40upx;
padding: 0 10upx;
}
}
}
4 years ago
/*
<view class="carrier" :class="[theIndex==index?'open':oldIndex==index?'close':'']" @touchstart="touchStart(index,$event)" @touchmove="touchMove(index,$event)" @touchend="touchEnd(index,$event)">
<view class="left">
<view class="title">
10元日常用品类
</view>
<view class="term">
2019-04-01~2019-05-30
</view>
</view>
<view class="right">
<view class="ticket">
<view class="num">
10
</view>
<view class="unit">
</view>
</view>
<view class="criteria">
满50使用
</view>
<view class="use">
去使用
</view>
</view>
</view>
*
* */
}
}
</style>