优惠劵详情: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

@ -6,94 +6,134 @@
<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"
:src="sheep.$url.static('/static/img/shop/app/coupon_icon.png')"
mode="aspectFit"
/>
</view> </view>
<view class="top ss-flex-col ss-col-center"> <view class="top ss-flex-col ss-col-center">
<view class="title ss-m-t-50 ss-m-b-20 ss-m-x-20">{{ state.list.name }}</view> <view class="title ss-m-t-50 ss-m-b-20 ss-m-x-20">{{ state.coupon.name }}</view>
<view class="subtitle ss-m-b-50">{{ state.list.enough }}{{ state.list.amount }}</view> <view class="subtitle ss-m-b-50">
<!-- (state.list.get_status != 'can_get' && state.list.get_status != 'can_use') || {{ fen2yuan(state.coupon.usePrice) }}
state.userCouponId --> {{ state.coupon.discountType === 1
<button class="ss-reset-button ss-m-b-30" :class=" ? '减 ' + fen2yuan(state.coupon.discountPrice) + ' 元'
state.list.get_status == 'can_get' || state.list.get_status == 'can_use' : '打 ' + state.coupon.discountPercent / 10.0 + ' 折' }}
? 'use-btn' </view>
: 'disable-btn' " :disabled="state.list.status_text=='已过期'" @click="getCoupon"> <button
<!-- {{ state.list.get_status_text }} --> class="ss-reset-button ss-m-b-30"
立即使用 :class="state.coupon.canTake || state.coupon.status === 1
? 'use-btn' // 使
: 'disable-btn'
"
:disabled="!state.coupon.canTake"
@click="getCoupon"
>
<text v-if="state.id > 0">{{ state.coupon.canTake ? '' : '' }}</text>
<text v-else>
{{ state.coupon.status === 1 ? '立即使用' : state.coupon.status === 2 ? '已使用' : '已过期' }}
</text>
</button> </button>
<view class="time ss-m-y-30" v-if=" <view class="time ss-m-y-30" v-if="state.coupon.validityType === 2">
state.list.get_status == 'can_get' || 有效期领取后 {{ state.coupon.fixedEndTerm }} 天内可用
state.list.get_status == 'cannot_get' ||
state.list.get_status == 'get_over'
">
领取时间{{ state.list.get_start_time }}{{ state.list.get_end_time }}
</view> </view>
<view class="time ss-m-y-30" v-else> <view class="time ss-m-y-30" v-else>
有效期{{ state.list.use_start_time }}{{ state.list.use_end_time }} 有效期: {{ sheep.$helper.timeFormat(state.coupon.validStartTime, 'yyyy-mm-dd') }}
{{ sheep.$helper.timeFormat(state.coupon.validEndTime, 'yyyy-mm-dd') }}
</view> </view>
<view class="coupon-line ss-m-t-14"></view> <view class="coupon-line ss-m-t-14"></view>
</view> </view>
<view class="bottom"> <view class="bottom">
<view class="type ss-flex ss-col-center ss-row-between ss-p-x-30"> <view class="type ss-flex ss-col-center ss-row-between ss-p-x-30">
<view>优惠券类型</view> <view>优惠券类型</view>
<view>{{ state.list.type_text }}</view> <view>{{ state.coupon.discountType === 1 ? '满减券' : '折扣券' }}</view>
</view> </view>
<!-- TODO 芋艿可优化增加优惠劵的描述 -->
<uni-collapse> <uni-collapse>
<uni-collapse-item title="优惠券说明" v-if="state.list.description"> <uni-collapse-item title="优惠券说明" v-if="state.coupon.description">
<view class="content ss-p-b-20"> <view class="content ss-p-b-20">
<text class="des ss-p-l-30">{{ state.list.description }}</text> <text class="des ss-p-l-30">{{ state.coupon.description }}</text>
</view> </view>
</uni-collapse-item> </uni-collapse-item>
</uni-collapse> </uni-collapse>
</view> </view>
</view> </view>
</view> </view>
<!-- 适用商品 --> <!-- 适用商品 -->
<view class="all-user ss-flex ss-row-center ss-col-center" v-if="state.list.use_scope == 'all_use'"> <view
class="all-user ss-flex ss-row-center ss-col-center"
v-if="state.list.use_scope == 'all_use'"
>
{{ state.list.use_scope_text }} {{ state.list.use_scope_text }}
</view> </view>
<su-sticky v-else bgColor="#fff"> <su-sticky v-else bgColor="#fff">
<view class="goods-title ss-p-20">{{ state.list.use_scope_text }}</view> <view class="goods-title ss-p-20">{{ state.list.use_scope_text }}</view>
<su-tabs :scrollable="true" :list="state.tabMaps" @change="onTabsChange" :current="state.currentTab" <su-tabs
v-if="state.list.use_scope == 'category'"></su-tabs> :scrollable="true"
:list="state.tabMaps"
@change="onTabsChange"
:current="state.currentTab"
v-if="state.list.use_scope == 'category'"
></su-tabs>
</su-sticky> </su-sticky>
<view v-if="state.list.use_scope == 'goods' || state.list.use_scope == 'disabled_goods'"> <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"> <view v-for="(item, index) in state.list.items_value" :key="index">
<s-goods-column class="ss-m-20" size="lg" :data="item" <s-goods-column
class="ss-m-20"
size="lg"
:data="item"
:titleColor="props.goodsFieldsStyle?.title?.color" :titleColor="props.goodsFieldsStyle?.title?.color"
:subTitleColor="props.goodsFieldsStyle?.subtitle?.color" :subTitleColor="props.goodsFieldsStyle?.subtitle?.color"
@click="sheep.$router.go('/pages/goods/index', { id: item.id })" :goodsFields="{ @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> }"
:buttonShow="state.list.use_scope != 'disabled_goods'"
/>
</view> </view>
</view> </view>
<view v-if="state.list.use_scope == 'category'"> <view v-if="state.list.use_scope == 'category'">
<view v-for="(item, index) in state.pagination.data" :key="index"> <view v-for="(item, index) in state.pagination.data" :key="index">
<s-goods-column class="ss-m-20" size="lg" :data="item" <s-goods-column
class="ss-m-20"
size="lg"
:data="item"
:titleColor="props.goodsFieldsStyle?.title?.color" :titleColor="props.goodsFieldsStyle?.title?.color"
:subTitleColor="props.goodsFieldsStyle?.subtitle?.color" :subTitleColor="props.goodsFieldsStyle?.subtitle?.color"
@click="sheep.$router.go('/pages/goods/index', { id: item.id })" :goodsFields="{ @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> }"
:buttonShow="state.list.use_scope != 'disabled_goods'"
></s-goods-column>
</view> </view>
</view> </view>
<uni-load-more v-if="state.pagination.total > 0 && state.list.use_scope == 'category'" <uni-load-more
:status="state.loadStatus" :content-text="{ 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
v-if="state.list.use_scope == 'category' && state.pagination.total === 0"
paddingTop="0"
icon="/static/soldout-empty.png"
text="暂无商品"
>
</s-empty> </s-empty>
</view> </view>
</s-layout> </s-layout>
@ -101,14 +141,11 @@
<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
} from '@dcloudio/uni-app';
import {
reactive
} from 'vue';
import _ from 'lodash'; import _ from 'lodash';
import CouponApi from '@/sheep/api/promotion/coupon';
import { fen2yuan } from '@/sheep/hooks/useGoods';
const pagination = { const pagination = {
data: [], data: [],
@ -117,9 +154,11 @@
last_page: 1, last_page: 1,
}; };
const state = reactive({ const state = reactive({
id: 0, // templateId
couponId: 0, // couponId
coupon: {}, //
list: {}, list: {},
couponId: 0,
userCouponId: 0,
pagination: { pagination: {
data: [], data: [],
current_page: 1, current_page: 1,
@ -133,24 +172,10 @@
// //
const props = defineProps({ const props = defineProps({
includes: {
type: Array,
default () {
return [];
},
},
list: {
type: Array,
default: () => [],
},
goodsFieldsStyle: { goodsFieldsStyle: {
type: Object, type: Object,
default() {}, default() {},
}, }
buyData: {
type: Object,
default () {},
},
}); });
function onTabsChange(e) { function onTabsChange(e) {
@ -159,6 +184,7 @@
state.categoryId = e.value; state.categoryId = e.value;
getGoodsList(state.categoryId); getGoodsList(state.categoryId);
} }
async function getGoodsList(categoryId, page = 1, list_rows = 5) { async function getGoodsList(categoryId, page = 1, list_rows = 5) {
state.loadStatus = 'loading'; state.loadStatus = 'loading';
const res = await sheep.$api.goods.list({ const res = await sheep.$api.goods.list({
@ -180,56 +206,55 @@
} }
} }
} }
async function getCoupon() { async function getCoupon() {
const { const { error, msg } = await sheep.$api.coupon.get(state.id);
error,
msg
} = await sheep.$api.coupon.get(state.couponId);
if (error === 0) { if (error === 0) {
uni.showToast({ uni.showToast({
title: msg, title: msg,
}); });
setTimeout(() => { setTimeout(() => {
getCouponContent(state.couponId, state.userCouponId); getCouponContent(state.id, state.couponId);
}, 1000); }, 1000);
} }
} }
async function getCouponContent(id, c) {
const { async function getCouponContent() {
data const { code, data } = state.id > 0 ? await CouponApi.getCouponTemplate(state.id)
} = await sheep.$api.coupon.detail(id, c); : await CouponApi.getCoupon(state.couponId);
if (code !== 0) {
return;
}
state.coupon = data;
if (true) {
return;
}
state.list = data; state.list = data;
data.items_value.forEach((i) => { data.items_value.forEach((i) => {
state.tabMaps.push({ state.tabMaps.push({ name: i.name, value: i.id });
name: i.name,
value: i.id
});
}); });
state.pagination = pagination; state.pagination = pagination;
if (state.list.use_scope == 'category') { if (state.list.use_scope == 'category') {
getGoodsList(state.tabMaps[0].value); getGoodsList(state.tabMaps[0].value);
} }
} }
// //
function loadmore() { function loadMore() {
if (state.loadStatus !== 'noMore') { if (state.loadStatus !== 'noMore') {
getGoodsList(state.categoryId, state.pagination.current_page + 1); getGoodsList(state.categoryId, state.pagination.current_page + 1);
} }
} }
onLoad((options) => { onLoad((options) => {
if (options.data) { state.id = options.id;
let data = JSON.parse(options.data); state.couponId = options.couponId;
console.log(data); getCouponContent(state.id, state.couponId);
state.list = data;
return;
}
state.couponId = options.id;
state.userCouponId = options.user_coupon_id;
getCouponContent(state.couponId, state.userCouponId);
}); });
// //
onReachBottom(() => { onReachBottom(() => {
loadmore(); loadMore();
}); });
</script> </script>
@ -241,11 +266,13 @@
} }
.detail-wrap { .detail-wrap {
background: linear-gradient(180deg, background: linear-gradient(
180deg,
var(--ui-BG-Main), var(--ui-BG-Main),
var(--ui-BG-Main-gradient), var(--ui-BG-Main-gradient),
var(--ui-BG-Main), var(--ui-BG-Main),
#fff); #fff
);
} }
.detail-box { .detail-box {
@ -253,7 +280,6 @@
border-radius: 6rpx; border-radius: 6rpx;
position: relative; position: relative;
margin-top: 100rpx; margin-top: 100rpx;
.tag-box { .tag-box {
width: 140rpx; width: 140rpx;
height: 140rpx; height: 140rpx;

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') {