2024-08-07 10:31:42 +08:00
|
|
|
|
<!-- 优惠券中心 -->
|
|
|
|
|
<template>
|
|
|
|
|
<s-layout title="优惠券" :bgStyle="{ color: '#f2f2f2' }">
|
|
|
|
|
<su-sticky bgColor="#fff">
|
|
|
|
|
<su-tabs
|
|
|
|
|
:list="tabMaps"
|
|
|
|
|
:scrollable="false"
|
|
|
|
|
@change="onTabsChange"
|
|
|
|
|
:current="state.currentTab"
|
|
|
|
|
/>
|
|
|
|
|
</su-sticky>
|
|
|
|
|
<s-empty
|
|
|
|
|
v-if="state.pagination.total === 0"
|
|
|
|
|
icon="/static/coupon-empty.png"
|
|
|
|
|
text="暂无优惠券"
|
|
|
|
|
/>
|
|
|
|
|
<!-- 情况一:领劵中心 -->
|
|
|
|
|
<template v-if="state.currentTab === 0">
|
|
|
|
|
<view v-for="item in state.pagination.list" :key="item.id">
|
2024-10-21 17:47:58 +08:00
|
|
|
|
<!-- @tap="sheep.$router.go('/pages/coupon/detail', { id: item.id })" -->
|
2024-08-07 10:31:42 +08:00
|
|
|
|
<s-coupon-list
|
|
|
|
|
:data="item"
|
2024-10-21 17:47:58 +08:00
|
|
|
|
|
2024-08-07 10:31:42 +08:00
|
|
|
|
>
|
|
|
|
|
<template #default>
|
|
|
|
|
<button
|
|
|
|
|
class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
|
|
|
|
|
:class="!item.canTake ? 'border-btn' : ''"
|
|
|
|
|
@click.stop="getBuy(item.id)"
|
|
|
|
|
:disabled="!item.canTake"
|
|
|
|
|
>
|
|
|
|
|
{{ item.canTake ? '立即领取' : '已领取' }}
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</s-coupon-list>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
<!-- 情况二:我的优惠劵 -->
|
|
|
|
|
<template v-else>
|
|
|
|
|
<view v-for="item in state.pagination.list" :key="item.id">
|
2024-10-21 17:47:58 +08:00
|
|
|
|
<!-- @tap="sheep.$router.go('/pages/coupon/detail', { couponId: item.id })" -->
|
2024-08-07 10:31:42 +08:00
|
|
|
|
<s-coupon-list
|
|
|
|
|
:data="item"
|
|
|
|
|
type="user"
|
|
|
|
|
>
|
|
|
|
|
<template #default>
|
|
|
|
|
<button
|
|
|
|
|
class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
|
2024-08-07 21:40:27 +08:00
|
|
|
|
:class="item.status !== 1 ? 'disabled-btn' : ''"
|
2024-08-07 10:31:42 +08:00
|
|
|
|
:disabled="item.status !== 1"
|
2024-10-21 17:47:58 +08:00
|
|
|
|
@click.stop="sheep.$router.go('/pages/index/category', { couponId: item.id })"
|
2024-08-07 10:31:42 +08:00
|
|
|
|
>
|
|
|
|
|
{{ item.status === 1 ? '立即使用' : item.status === 2 ? '已使用' : '已过期' }}
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</s-coupon-list>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-08-07 21:40:27 +08:00
|
|
|
|
<uni-load-more
|
|
|
|
|
v-if="state.pagination.total > 0"
|
|
|
|
|
:status="state.loadStatus"
|
|
|
|
|
:content-text="{
|
2024-08-07 10:31:42 +08:00
|
|
|
|
contentdown: '上拉加载更多',
|
2024-08-07 21:40:27 +08:00
|
|
|
|
}"
|
|
|
|
|
@tap="loadMore"
|
|
|
|
|
/>
|
2024-08-07 10:31:42 +08:00
|
|
|
|
</s-layout>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import sheep from '@/sheep';
|
|
|
|
|
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
|
|
|
|
import { reactive } from 'vue';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import { resetPagination } from '@/sheep/util';
|
|
|
|
|
import CouponApi from '@/sheep/api/promotion/coupon';
|
|
|
|
|
|
|
|
|
|
// 数据
|
|
|
|
|
const state = reactive({
|
|
|
|
|
currentTab: 0, // 当前 tab
|
|
|
|
|
type: '1',
|
|
|
|
|
pagination: {
|
|
|
|
|
list: [],
|
|
|
|
|
total: 0,
|
|
|
|
|
pageNo: 1,
|
2024-08-07 21:40:27 +08:00
|
|
|
|
pageSize: 5,
|
2024-08-07 10:31:42 +08:00
|
|
|
|
},
|
|
|
|
|
loadStatus: '',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const tabMaps = [
|
|
|
|
|
{
|
|
|
|
|
name: '领券中心',
|
|
|
|
|
value: 'all',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: '已领取',
|
|
|
|
|
value: '1',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: '已使用',
|
|
|
|
|
value: '2',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: '已失效',
|
|
|
|
|
value: '3',
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// TODO yunai:
|
|
|
|
|
function onTabsChange(e) {
|
|
|
|
|
state.currentTab = e.index;
|
|
|
|
|
state.type = e.value;
|
2024-08-07 21:40:27 +08:00
|
|
|
|
resetPagination(state.pagination);
|
2024-08-07 10:31:42 +08:00
|
|
|
|
if (state.currentTab === 0) {
|
2024-08-07 21:40:27 +08:00
|
|
|
|
getData();
|
2024-08-07 10:31:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
getCoupon();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获得优惠劵模版列表
|
|
|
|
|
async function getData() {
|
|
|
|
|
state.loadStatus = 'loading';
|
|
|
|
|
const { data, code } = await CouponApi.getCouponTemplatePage({
|
|
|
|
|
pageNo: state.pagination.pageNo,
|
|
|
|
|
pageSize: state.pagination.pageSize,
|
|
|
|
|
});
|
|
|
|
|
if (code !== 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
state.pagination.list = _.concat(state.pagination.list, data.list);
|
|
|
|
|
state.pagination.total = data.total;
|
|
|
|
|
state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获得我的优惠劵
|
|
|
|
|
async function getCoupon() {
|
|
|
|
|
state.loadStatus = 'loading';
|
|
|
|
|
const { data, code } = await CouponApi.getCouponPage({
|
|
|
|
|
pageNo: state.pagination.pageNo,
|
|
|
|
|
pageSize: state.pagination.pageSize,
|
2024-08-07 21:40:27 +08:00
|
|
|
|
status: state.type,
|
2024-08-07 10:31:42 +08:00
|
|
|
|
});
|
|
|
|
|
if (code !== 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
state.pagination.list = _.concat(state.pagination.list, data.list);
|
|
|
|
|
state.pagination.total = data.total;
|
|
|
|
|
state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 领取优惠劵
|
|
|
|
|
async function getBuy(id) {
|
|
|
|
|
const { code } = await CouponApi.takeCoupon(id);
|
|
|
|
|
if (code !== 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '领取成功',
|
|
|
|
|
});
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
resetPagination(state.pagination);
|
|
|
|
|
getData();
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载更多
|
|
|
|
|
function loadMore() {
|
|
|
|
|
if (state.loadStatus === 'noMore') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
state.pagination.pageNo++;
|
|
|
|
|
if (state.currentTab === 0) {
|
|
|
|
|
getData();
|
|
|
|
|
} else {
|
|
|
|
|
getCoupon();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onLoad((Option) => {
|
|
|
|
|
// 领劵中心
|
|
|
|
|
if (Option.type === 'all' || !Option.type) {
|
|
|
|
|
getData();
|
2024-08-07 21:40:27 +08:00
|
|
|
|
// 我的优惠劵
|
2024-08-07 10:31:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
Option.type === 'geted'
|
|
|
|
|
? (state.currentTab = 1)
|
|
|
|
|
: Option.type === 'used'
|
2024-08-07 21:40:27 +08:00
|
|
|
|
? (state.currentTab = 2)
|
|
|
|
|
: (state.currentTab = 3);
|
2024-08-07 10:31:42 +08:00
|
|
|
|
state.type = state.currentTab;
|
|
|
|
|
getCoupon();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onReachBottom(() => {
|
|
|
|
|
loadMore();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.card-btn {
|
|
|
|
|
// width: 144rpx;
|
2024-10-16 18:09:51 +08:00
|
|
|
|
padding: 0 12rpx;
|
2024-08-07 10:31:42 +08:00
|
|
|
|
height: 50rpx;
|
|
|
|
|
border-radius: 40rpx;
|
|
|
|
|
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
|
|
|
|
|
color: #ffffff;
|
|
|
|
|
font-size: 24rpx;
|
|
|
|
|
font-weight: 400;
|
2024-10-16 18:09:51 +08:00
|
|
|
|
flex: 1;
|
|
|
|
|
margin: 0 10px;
|
2024-08-07 10:31:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.border-btn {
|
|
|
|
|
background: linear-gradient(90deg, var(--ui-BG-Main-opacity-4), var(--ui-BG-Main-light));
|
|
|
|
|
color: #fff !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.disabled-btn {
|
|
|
|
|
background: #cccccc;
|
|
|
|
|
background-color: #cccccc !important;
|
|
|
|
|
color: #fff !important;
|
|
|
|
|
}
|
|
|
|
|
</style>
|