Files
gxtyzx-uniapp/src/package/coupon/index.vue
T
2024-07-10 13:50:01 +08:00

370 lines
7.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view>
<view class="coupon">
<block v-for="(item,index) in list" :key="index">
<view class="coupon-item web-cell">
<view class="coupon-bg">
<view class="title"><span class="price">8</span><span class="unit">元</span></view>
<view class="desc">满减劵</view>
</view>
<view class="coupon-info web-cell web-cell-content">
<view class="coupon-content">
<view class="title">优惠券名称</view>
<view class="desc web-text-secondary">有效期至:2024-05-29</view>
</view>
<uv-button class="save-btn" size="mini"
:customStyle="{background: 'linear-gradient(to right, #70b915, #008e04)',color: '#ffffff', border: 'none'}"
:text="item.disabled ? '已领取': '领取'" :disabled="item.disabled" @click="save(item,index)"></uv-button>
</view>
</view>
</block>
<!-- <uv-empty mode="order" v-if="list.length == 0"
icon="https://cdn.uviewui.com/uview/empty/data.png"></uv-empty> -->
<uni-load-more v-if="list.length > 0" :status="loadMore"></uni-load-more>
<!-- 登录组件 -->
<ws-login ref="login" :logo="logo" @done="reload" />
</view>
</view>
</template>
<script>
import * as CouponApi from '@/api/booking/coupon'
import {
pageWechatDeposit
} from '@/api/shop/wechatDeposit'
import {
getWeek,
getKey
} from '@/utils/common';
import * as UserCouponApi from '@/api/booking/userCoupon'
export default {
components: {},
data() {
return {
isRefresh: false,
isLogin: false,
userId: 0,
where: {
page: 1,
status: 0
},
canReset: false,
loadMore: 'more',
logo: '',
items: ['待使用(0)', '已使用(0)', '已失效(0)'],
list: [],
styles: [{
value: 'button',
text: '按钮',
checked: true
},
{
value: 'text',
text: '文字'
}
],
colors: ['#333333', '#4cd964', '#dd524d'],
current: 0,
colorIndex: 0,
activeColor: '#108001',
styleType: 'text',
getWeek,
disabled: false
}
},
onLoad(option) {
// 判断是否登录
this.openLogin()
// 加载数据
this.reload()
// if(option.isRefresh){
// this.isRefresh = true
// }
},
onShow(e) {
// 判断是否登录
this.openLogin()
this.reload()
},
// 触底函数
onReachBottom() {
const app = this
const {
where
} = this
if (app.canReset) {
app.where.page = ++where.page;
app.reload()
}
},
methods: {
async reload() {
const app = this
const {
where
} = this
// where.userId = userId;
uni.showLoading({
title: '数据读取中.'
})
app.loadMore = 'loading'
const userCouponIds = []
const userCoupons = await app.getUserCoupon({
userId: uni.getStorageSync('user_id')
}).then(list => {
list.map(d => {
userCouponIds.push(d.couponId)
})
})
console.log('userCoupons: ',userCouponIds);
CouponApi.pageCoupon(where).then(res => {
const list = res.list.map(d => {
if(userCouponIds.indexOf(d.id) == 0){
d.disabled = true
}
return d;
});
if (app.list.length < res.count) {
app.list = app.list.concat(list)
app.canReset = true
app.loadMore = 'no-more'
} else {
app.canReset = false;
app.loadMore = 'no-more'
}
console.log('app.list: ',app.list);
uni.hideLoading()
app.isRefresh = false
}).catch(() => {
uni.showToast({
title: '请检查您的网络.',
icon: 'none'
})
uni.hideLoading()
app.isRefresh = false
})
},
getUserCoupon() {
const app = this;
return new Promise((resolve, reject) => {
UserCouponApi.listUserCoupon({})
.then((result) => {
resolve(result);
})
.catch(reject);
});
},
onClickItem(e) {
const app = this
const {
where,
userId
} = this
const index = e.currentIndex
if (this.current !== e.currentIndex) {
this.current = e.currentIndex
}
if (userId == 0) {
app.openLogin()
return;
}
// 全部
app.where.status = index;
this.where.page = 1;
this.list = [];
this.reload()
},
openUrl(url) {
uni.navigateTo({
url
})
},
toPay(orderId) {
uni.navigateTo({
url: '/package/booking/confirm?id=' + orderId
})
},
closeOrder(item) {
uni.showModal({
title: '确定取消此订单?',
success(o) {
if (o.confirm) {
OrderApi.updateOrder({
orderStatus: 2,
orderId: item.orderId
}).then(msg => {
uni.showToast({
title: msg,
icon: 'none'
})
item.orderStatus = 2;
}).catch(() => {
uni.showToast({
title: '请检查您的网络.',
icon: 'none'
})
uni.hideLoading()
})
}
}
});
},
// 弹出登录提示框
async openLogin() {
this.userId = uni.getStorageSync('user_id');
if (!this.userId) {
this.$refs.login.open('bottom')
return false;
}
},
save(item,index){
const app = this
item.couponId = item.id
app.list[index].disabled = true
UserCouponApi.addUserCoupon(item).then(msg => {
uni.showToast({
title: '领取成功',
icon: 'success'
})
setTimeout(() => {
app.reload()
},2000)
})
}
}
}
</script>
<style lang="scss">
.content {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
height: 150px;
text-align: center;
}
.segmented {
padding: 0 12rpx;
}
.content-text {
font-size: 14px;
color: #666;
}
.color-tag {
width: 25px;
height: 25px;
}
.uni-list {
flex: 1;
}
.coupon {
.coupon-item {
width: 700rpx;
margin: 20rpx auto;
border-radius: 12rpx;
border-bottom: 1px #eee solid;
background: #fff;
.coupon-bg {
width: 140rpx;
height: 140rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 26rpx;
color: #fff;
border-radius: 12rpx 0 0 12rpx;
background: linear-gradient(to right, #70b915, #008e04);
.price {
font-size: 50rpx;
}
}
.coupon-info {
padding: 20rpx;
display: flex;
justify-content: space-between;
.title{
line-height: 2rem;
}
}
.save-btn{
// margin-right: 20rpx;
}
.merchant-avatar {
margin-right: 12rpx;
}
.merchant-name {
// padding-left: 12rpx;
}
.btn-status {
font-size: 30rpx;
display: flex;
}
}
.order-body {
padding: 16px 0;
}
}
.ele-flex {
display: flex;
justify-content: space-between;
}
.card-actions {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
height: 45px;
border-top: 1px #eee solid;
}
.card-actions-item {
display: flex;
flex-direction: row;
align-items: center;
}
.card-actions-item-text {
font-size: 12px;
color: #666;
margin-left: 5px;
}
.close {
top: 60rpx !important;
}
.total-price {
display: flex;
flex-direction: column;
justify-content: flex-start;
font-size: 30rpx;
align-items: flex-start;
padding-left: 6rpx;
margin-left: 450rpx;
.web-text-heading {
font-size: 30rpx !important;
}
}
</style>