优惠劵详情:50%

pull/29/head^2
YunaiV 2023-12-16 12:46:11 +08:00
parent 894f57a551
commit 815457844d
3 changed files with 354 additions and 317 deletions

View File

@ -1,350 +1,376 @@
<!-- 优惠券详情 --> <!-- 优惠券详情 -->
<template> <template>
<s-layout title="优惠券详情"> <s-layout title="优惠券详情">
<view class="bg-white"> <view class="bg-white">
<!-- 详情卡片 --> <!-- 详情卡片 -->
<view class="detail-wrap ss-p-20"> <view class="detail-wrap ss-p-20">
<view class="detail-box"> <view class="detail-box">
<view class="tag-box ss-flex ss-col-center ss-row-center"> <view class="tag-box ss-flex ss-col-center ss-row-center">
<image class="tag-image" :src="sheep.$url.static('/static/img/shop/app/coupon_icon.png')" <image
mode="aspectFit"></image> class="tag-image"
</view> :src="sheep.$url.static('/static/img/shop/app/coupon_icon.png')"
<view class="top ss-flex-col ss-col-center"> mode="aspectFit"
<view class="title ss-m-t-50 ss-m-b-20 ss-m-x-20">{{ state.list.name }}</view> />
<view class="subtitle ss-m-b-50">{{ state.list.enough }}{{ state.list.amount }}</view> </view>
<!-- (state.list.get_status != 'can_get' && state.list.get_status != 'can_use') || <view class="top ss-flex-col ss-col-center">
state.userCouponId --> <view class="title ss-m-t-50 ss-m-b-20 ss-m-x-20">{{ state.coupon.name }}</view>
<button class="ss-reset-button ss-m-b-30" :class=" <view class="subtitle ss-m-b-50">
state.list.get_status == 'can_get' || state.list.get_status == 'can_use' {{ fen2yuan(state.coupon.usePrice) }}
? 'use-btn' {{ state.coupon.discountType === 1
: 'disable-btn' " :disabled="state.list.status_text=='已过期'" @click="getCoupon"> ? '减 ' + fen2yuan(state.coupon.discountPrice) + ' 元'
<!-- {{ state.list.get_status_text }} --> : '打 ' + state.coupon.discountPercent / 10.0 + ' 折' }}
立即使用 </view>
</button> <button
<view class="time ss-m-y-30" v-if=" class="ss-reset-button ss-m-b-30"
state.list.get_status == 'can_get' || :class="state.coupon.canTake || state.coupon.status === 1
state.list.get_status == 'cannot_get' || ? 'use-btn' // 使
state.list.get_status == 'get_over' : 'disable-btn'
"> "
领取时间{{ state.list.get_start_time }}{{ state.list.get_end_time }} :disabled="!state.coupon.canTake"
</view> @click="getCoupon"
<view class="time ss-m-y-30" v-else> >
有效期{{ state.list.use_start_time }}{{ state.list.use_end_time }} <text v-if="state.id > 0">{{ state.coupon.canTake ? '' : '' }}</text>
</view> <text v-else>
<view class="coupon-line ss-m-t-14"></view> {{ state.coupon.status === 1 ? '立即使用' : state.coupon.status === 2 ? '已使用' : '已过期' }}
</view> </text>
<view class="bottom"> </button>
<view class="type ss-flex ss-col-center ss-row-between ss-p-x-30"> <view class="time ss-m-y-30" v-if="state.coupon.validityType === 2">
<view>优惠券类型</view> 有效期领取后 {{ state.coupon.fixedEndTerm }} 天内可用
<view>{{ state.list.type_text }}</view> </view>
</view> <view class="time ss-m-y-30" v-else>
<uni-collapse> 有效期: {{ sheep.$helper.timeFormat(state.coupon.validStartTime, 'yyyy-mm-dd') }}
<uni-collapse-item title="优惠券说明" v-if="state.list.description"> {{ sheep.$helper.timeFormat(state.coupon.validEndTime, 'yyyy-mm-dd') }}
<view class="content ss-p-b-20"> </view>
<text class="des ss-p-l-30">{{ state.list.description }}</text> <view class="coupon-line ss-m-t-14"></view>
</view> </view>
</uni-collapse-item> <view class="bottom">
</uni-collapse> <view class="type ss-flex ss-col-center ss-row-between ss-p-x-30">
</view> <view>优惠券类型</view>
</view> <view>{{ state.coupon.discountType === 1 ? '满减券' : '折扣券' }}</view>
</view> </view>
<!-- 适用商品 --> <!-- TODO 芋艿可优化增加优惠劵的描述 -->
<view class="all-user ss-flex ss-row-center ss-col-center" v-if="state.list.use_scope == 'all_use'"> <uni-collapse>
{{ state.list.use_scope_text }} <uni-collapse-item title="优惠券说明" v-if="state.coupon.description">
</view> <view class="content ss-p-b-20">
<text class="des ss-p-l-30">{{ state.coupon.description }}</text>
</view>
</uni-collapse-item>
</uni-collapse>
</view>
</view>
</view>
<su-sticky v-else bgColor="#fff"> <!-- 适用商品 -->
<view class="goods-title ss-p-20">{{ state.list.use_scope_text }}</view> <view
<su-tabs :scrollable="true" :list="state.tabMaps" @change="onTabsChange" :current="state.currentTab" class="all-user ss-flex ss-row-center ss-col-center"
v-if="state.list.use_scope == 'category'"></su-tabs> v-if="state.list.use_scope == 'all_use'"
</su-sticky> >
<view v-if="state.list.use_scope == 'goods' || state.list.use_scope == 'disabled_goods'"> {{ state.list.use_scope_text }}
<view v-for="(item, index) in state.list.items_value" :key="index"> </view>
<s-goods-column class="ss-m-20" size="lg" :data="item"
:titleColor="props.goodsFieldsStyle?.title?.color" <su-sticky v-else bgColor="#fff">
:subTitleColor="props.goodsFieldsStyle?.subtitle?.color" <view class="goods-title ss-p-20">{{ state.list.use_scope_text }}</view>
@click="sheep.$router.go('/pages/goods/index', { id: item.id })" :goodsFields="{ <su-tabs
:scrollable="true"
:list="state.tabMaps"
@change="onTabsChange"
:current="state.currentTab"
v-if="state.list.use_scope == 'category'"
></su-tabs>
</su-sticky>
<view v-if="state.list.use_scope == 'goods' || state.list.use_scope == 'disabled_goods'">
<view v-for="(item, index) in state.list.items_value" :key="index">
<s-goods-column
class="ss-m-20"
size="lg"
:data="item"
:titleColor="props.goodsFieldsStyle?.title?.color"
:subTitleColor="props.goodsFieldsStyle?.subtitle?.color"
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
:goodsFields="{
title: { show: true }, title: { show: true },
subtitle: { show: true }, subtitle: { show: true },
price: { show: true }, price: { show: true },
original_price: { show: true }, original_price: { show: true },
sales: { show: true }, sales: { show: true },
stock: { show: false }, stock: { show: false },
}" :buttonShow="state.list.use_scope != 'disabled_goods'"></s-goods-column> }"
</view> :buttonShow="state.list.use_scope != 'disabled_goods'"
</view> />
<view v-if="state.list.use_scope == 'category'"> </view>
<view v-for="(item, index) in state.pagination.data" :key="index"> </view>
<s-goods-column class="ss-m-20" size="lg" :data="item" <view v-if="state.list.use_scope == 'category'">
:titleColor="props.goodsFieldsStyle?.title?.color" <view v-for="(item, index) in state.pagination.data" :key="index">
:subTitleColor="props.goodsFieldsStyle?.subtitle?.color" <s-goods-column
@click="sheep.$router.go('/pages/goods/index', { id: item.id })" :goodsFields="{ class="ss-m-20"
size="lg"
:data="item"
:titleColor="props.goodsFieldsStyle?.title?.color"
:subTitleColor="props.goodsFieldsStyle?.subtitle?.color"
@click="sheep.$router.go('/pages/goods/index', { id: item.id })"
:goodsFields="{
title: { show: true }, title: { show: true },
subtitle: { show: true }, subtitle: { show: true },
price: { show: true }, price: { show: true },
original_price: { show: true }, original_price: { show: true },
sales: { show: true }, sales: { show: true },
stock: { show: false }, stock: { show: false },
}" :buttonShow="state.list.use_scope != 'disabled_goods'"></s-goods-column> }"
</view> :buttonShow="state.list.use_scope != 'disabled_goods'"
</view> ></s-goods-column>
<uni-load-more v-if="state.pagination.total > 0 && state.list.use_scope == 'category'" </view>
:status="state.loadStatus" :content-text="{ </view>
<uni-load-more
v-if="state.pagination.total > 0 && state.list.use_scope == 'category'"
:status="state.loadStatus"
:content-text="{
contentdown: '上拉加载更多', contentdown: '上拉加载更多',
}" @tap="loadmore" /> }"
<s-empty v-if="state.list.use_scope == 'category' && state.pagination.total === 0" paddingTop="0" @tap="loadMore"
icon="/static/soldout-empty.png" text="暂无商品"> />
</s-empty> <s-empty
</view> v-if="state.list.use_scope == 'category' && state.pagination.total === 0"
</s-layout> paddingTop="0"
icon="/static/soldout-empty.png"
text="暂无商品"
>
</s-empty>
</view>
</s-layout>
</template> </template>
<script setup> <script setup>
import sheep from '@/sheep'; import sheep from '@/sheep';
import { import { onLoad, onReachBottom } from '@dcloudio/uni-app';
onLoad, import { reactive } from 'vue';
onReachBottom import _ from 'lodash';
} from '@dcloudio/uni-app'; import CouponApi from '@/sheep/api/promotion/coupon';
import { import { fen2yuan } from '@/sheep/hooks/useGoods';
reactive
} from 'vue';
import _ from 'lodash';
const pagination = { const pagination = {
data: [], data: [],
current_page: 1, current_page: 1,
total: 1, total: 1,
last_page: 1, last_page: 1,
}; };
const state = reactive({ const state = reactive({
list: {}, id: 0, // templateId
couponId: 0, couponId: 0, // couponId
userCouponId: 0, coupon: {}, //
pagination: {
data: [],
current_page: 1,
total: 1,
last_page: 1,
},
tabMaps: [],
loadStatus: '',
categoryId: 0,
});
// list: {},
const props = defineProps({ pagination: {
includes: { data: [],
type: Array, current_page: 1,
default () { total: 1,
return []; last_page: 1,
}, },
}, tabMaps: [],
list: { loadStatus: '',
type: Array, categoryId: 0,
default: () => [], });
},
goodsFieldsStyle: {
type: Object,
default () {},
},
buyData: {
type: Object,
default () {},
},
});
function onTabsChange(e) { //
state.pagination = pagination; const props = defineProps({
state.currentTab = e.index; goodsFieldsStyle: {
state.categoryId = e.value; type: Object,
getGoodsList(state.categoryId); default() {},
} }
async function getGoodsList(categoryId, page = 1, list_rows = 5) { });
state.loadStatus = 'loading';
const res = await sheep.$api.goods.list({ function onTabsChange(e) {
category_id: categoryId, state.pagination = pagination;
list_rows, state.currentTab = e.index;
page, state.categoryId = e.value;
is_category_deep: false, getGoodsList(state.categoryId);
}); }
if (res.error === 0) {
let couponlist = _.concat(state.pagination.data, res.data.data); async function getGoodsList(categoryId, page = 1, list_rows = 5) {
state.pagination = { state.loadStatus = 'loading';
...res.data, const res = await sheep.$api.goods.list({
data: couponlist, category_id: categoryId,
}; list_rows,
if (state.pagination.current_page < state.pagination.last_page) { page,
state.loadStatus = 'more'; is_category_deep: false,
} else { });
state.loadStatus = 'noMore'; if (res.error === 0) {
} let couponlist = _.concat(state.pagination.data, res.data.data);
} state.pagination = {
} ...res.data,
async function getCoupon() { data: couponlist,
const { };
error, if (state.pagination.current_page < state.pagination.last_page) {
msg state.loadStatus = 'more';
} = await sheep.$api.coupon.get(state.couponId); } else {
if (error === 0) { state.loadStatus = 'noMore';
uni.showToast({ }
title: msg, }
}); }
setTimeout(() => {
getCouponContent(state.couponId, state.userCouponId); async function getCoupon() {
}, 1000); const { error, msg } = await sheep.$api.coupon.get(state.id);
} if (error === 0) {
} uni.showToast({
async function getCouponContent(id, c) { title: msg,
const { });
data setTimeout(() => {
} = await sheep.$api.coupon.detail(id, c); getCouponContent(state.id, state.couponId);
state.list = data; }, 1000);
data.items_value.forEach((i) => { }
state.tabMaps.push({ }
name: i.name,
value: i.id async function getCouponContent() {
}); const { code, data } = state.id > 0 ? await CouponApi.getCouponTemplate(state.id)
}); : await CouponApi.getCoupon(state.couponId);
state.pagination = pagination; if (code !== 0) {
if (state.list.use_scope == 'category') { return;
getGoodsList(state.tabMaps[0].value); }
} state.coupon = data;
} if (true) {
// return;
function loadmore() { }
if (state.loadStatus !== 'noMore') { state.list = data;
getGoodsList(state.categoryId, state.pagination.current_page + 1); data.items_value.forEach((i) => {
} state.tabMaps.push({ name: i.name, value: i.id });
} });
onLoad((options) => { state.pagination = pagination;
if (options.data) { if (state.list.use_scope == 'category') {
let data = JSON.parse(options.data); getGoodsList(state.tabMaps[0].value);
console.log(data); }
state.list = data; }
return;
} //
state.couponId = options.id; function loadMore() {
state.userCouponId = options.user_coupon_id; if (state.loadStatus !== 'noMore') {
getCouponContent(state.couponId, state.userCouponId); getGoodsList(state.categoryId, state.pagination.current_page + 1);
}); }
// }
onReachBottom(() => {
loadmore(); onLoad((options) => {
}); state.id = options.id;
state.couponId = options.couponId;
getCouponContent(state.id, state.couponId);
});
//
onReachBottom(() => {
loadMore();
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.goods-title { .goods-title {
font-size: 34rpx; font-size: 34rpx;
font-weight: bold; font-weight: bold;
color: #333333; color: #333333;
} }
.detail-wrap { .detail-wrap {
background: linear-gradient(180deg, background: linear-gradient(
var(--ui-BG-Main), 180deg,
var(--ui-BG-Main-gradient), var(--ui-BG-Main),
var(--ui-BG-Main), var(--ui-BG-Main-gradient),
#fff); var(--ui-BG-Main),
} #fff
);
}
.detail-box { .detail-box {
// background-color: var(--ui-BG); // background-color: var(--ui-BG);
border-radius: 6rpx; border-radius: 6rpx;
position: relative; position: relative;
margin-top: 100rpx; margin-top: 100rpx;
.tag-box {
width: 140rpx;
height: 140rpx;
background: var(--ui-BG);
border-radius: 50%;
position: absolute;
top: -70rpx;
left: 50%;
z-index: 6;
transform: translateX(-50%);
.tag-box { .tag-image {
width: 140rpx; width: 104rpx;
height: 140rpx; height: 104rpx;
background: var(--ui-BG); border-radius: 50%;
border-radius: 50%; }
position: absolute; }
top: -70rpx;
left: 50%;
z-index: 6;
transform: translateX(-50%);
.tag-image { .top {
width: 104rpx; background-color: #fff;
height: 104rpx; border-radius: 20rpx 20rpx 0 0;
border-radius: 50%; -webkit-mask: radial-gradient(circle at 16rpx 100%, #0000 16rpx, red 0) -16rpx;
} padding: 110rpx 0 0 0;
} position: relative;
z-index: 5;
.top { .title {
background-color: #fff; font-size: 40rpx;
border-radius: 20rpx 20rpx 0 0; color: #333;
-webkit-mask: radial-gradient(circle at 16rpx 100%, #0000 16rpx, red 0) -16rpx; font-weight: bold;
padding: 110rpx 0 0 0; }
position: relative;
z-index: 5;
.title { .subtitle {
font-size: 40rpx; font-size: 28rpx;
color: #333; color: #333333;
font-weight: bold; }
}
.subtitle { .use-btn {
font-size: 28rpx; width: 386rpx;
color: #333333; height: 80rpx;
} line-height: 80rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
border-radius: 40rpx;
color: $white;
}
.use-btn { .disable-btn {
width: 386rpx; width: 386rpx;
height: 80rpx; height: 80rpx;
line-height: 80rpx; line-height: 80rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient)); background: #e5e5e5;
border-radius: 40rpx; border-radius: 40rpx;
color: $white; color: $white;
} }
.disable-btn { .time {
width: 386rpx; font-size: 26rpx;
height: 80rpx; font-weight: 400;
line-height: 80rpx; color: #999999;
background: #e5e5e5; }
border-radius: 40rpx;
color: $white;
}
.time { .coupon-line {
font-size: 26rpx; width: 95%;
font-weight: 400; border-bottom: 2rpx solid #eeeeee;
color: #999999; }
} }
.coupon-line { .bottom {
width: 95%; background-color: #fff;
border-bottom: 2rpx solid #eeeeee; border-radius: 0 0 20rpx 20rpx;
} -webkit-mask: radial-gradient(circle at 16rpx 0%, #0000 16rpx, red 0) -16rpx;
} padding: 40rpx 30rpx;
.bottom { .type {
background-color: #fff; height: 96rpx;
border-radius: 0 0 20rpx 20rpx; border-bottom: 2rpx solid #eeeeee;
-webkit-mask: radial-gradient(circle at 16rpx 0%, #0000 16rpx, red 0) -16rpx; }
padding: 40rpx 30rpx; }
.type { .des {
height: 96rpx; font-size: 24rpx;
border-bottom: 2rpx solid #eeeeee; font-weight: 400;
} color: #666666;
} }
}
.des { .all-user {
font-size: 24rpx; width: 100%;
font-weight: 400; height: 300rpx;
color: #666666; font-size: 34rpx;
} font-weight: bold;
} color: #333333;
}
.all-user { </style>
width: 100%;
height: 300rpx;
font-size: 34rpx;
font-weight: bold;
color: #333333;
}
</style>

View File

@ -25,6 +25,14 @@ const CouponApi = {
params, params,
}); });
}, },
// 获得优惠劵模版
getCouponTemplate: (id) => {
return request({
url: '/app-api/promotion/coupon-template/get',
method: 'GET',
params: { id },
});
},
// 我的优惠劵列表 // 我的优惠劵列表
getCouponPage: (params) => { getCouponPage: (params) => {
return request({ return request({
@ -41,6 +49,14 @@ const CouponApi = {
data: { templateId }, data: { templateId },
}); });
}, },
// 获得优惠劵
getCoupon: (id) => {
return request({
url: '/app-api/promotion/coupon/get',
method: 'GET',
params: { id },
});
},
}; };
export default CouponApi; export default CouponApi;

View File

@ -80,12 +80,7 @@
import { fen2yuan } from '../../hooks/useGoods'; import { fen2yuan } from '../../hooks/useGoods';
import sheep from '../../index'; import sheep from '../../index';
const state = reactive({ const state = reactive({});
stateMap: {
0: '立即领取',
1: '去使用',
},
});
const isDisable = computed(() => { const isDisable = computed(() => {
if (props.type === 'coupon') { if (props.type === 'coupon') {