营销:适配商城装修组件【优惠券】
parent
04b0b87126
commit
92e164747a
|
|
@ -0,0 +1,12 @@
|
||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// 获得优惠劵模板列表
|
||||||
|
getCouponTemplateListByIds: (ids) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/promotion/coupon-template/list-by-ids',
|
||||||
|
method: 'GET',
|
||||||
|
params: { ids }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -42,7 +42,7 @@
|
||||||
<!-- 营销组件:小程序直播 -->
|
<!-- 营销组件:小程序直播 -->
|
||||||
<s-live-block v-if="type === 'mplive'" :data="data" :styles="styles" />
|
<s-live-block v-if="type === 'mplive'" :data="data" :styles="styles" />
|
||||||
<!-- 营销组件:优惠券 -->
|
<!-- 营销组件:优惠券 -->
|
||||||
<s-coupon-block v-if="type === 'coupon'" :data="data" :styles="styles" />
|
<s-coupon-block v-if="type === 'CouponCard'" :data="data" :styles="styles" />
|
||||||
|
|
||||||
<!-- 会员组件:会员卡片 -->
|
<!-- 会员组件:会员卡片 -->
|
||||||
<s-user-card v-if="type === 'userCard'" />
|
<s-user-card v-if="type === 'userCard'" />
|
||||||
|
|
|
||||||
|
|
@ -1,126 +1,54 @@
|
||||||
<!-- 优惠券组 -->
|
<!-- 优惠券组 -->
|
||||||
<template>
|
<template>
|
||||||
<view>
|
<scroll-view class="scroll-box" scroll-x scroll-anchoring>
|
||||||
<!-- 样式1 -->
|
<view class="coupon-box ss-flex">
|
||||||
<view class="lg-coupon-wrap" v-if="mode == 1">
|
<view
|
||||||
<scroll-view class="scroll-box" scroll-x scroll-anchoring>
|
class="coupon-item"
|
||||||
<view class="coupon-box ss-flex">
|
:style="[couponBg, { marginLeft: `${data.space}px` }]"
|
||||||
<view
|
v-for="(item, index) in couponList"
|
||||||
class="coupon-item"
|
:key="index"
|
||||||
:style="[couponBg, { marginLeft: data.space + 'px' }]"
|
>
|
||||||
v-for="(item, index) in couponList"
|
<su-coupon
|
||||||
:key="index"
|
:size="SIZE_LIST[columns - 1]"
|
||||||
>
|
:textColor="data.textColor"
|
||||||
<su-coupon
|
background=""
|
||||||
size="lg"
|
:couponId="item.id"
|
||||||
:textColor="data.fill.color"
|
:title="item.name"
|
||||||
background=""
|
:type="formatCouponDiscountType(item)"
|
||||||
:couponId="item.id"
|
:value="formatCouponDiscountValue(item)"
|
||||||
:title="item.amount_text"
|
:sellBy="formatValidityType(item)"
|
||||||
:value="item.amount"
|
>
|
||||||
:surplus="item.stock"
|
<template v-slot:btn>
|
||||||
:type="item.type"
|
<!-- 两列时,领取按钮坚排 -->
|
||||||
:sellBy="`${item.get_start_time.substring(0, 10)} 至 ${item.get_end_time.substring(
|
<button
|
||||||
0,
|
v-if="columns === 2"
|
||||||
10,
|
@click.stop="onGetCoupon(item.id)"
|
||||||
)}`"
|
class="ss-reset-button card-btn vertical"
|
||||||
|
:style="[btnStyles]"
|
||||||
>
|
>
|
||||||
<template v-slot:btn>
|
<view class="btn-text">立即领取</view>
|
||||||
<button
|
</button>
|
||||||
class="ss-reset-button card-btn"
|
<button
|
||||||
:style="[btnStyles]"
|
v-else
|
||||||
@click.stop="onGetCoupon(item.id)"
|
class="ss-reset-button card-btn"
|
||||||
>
|
:style="[btnStyles]"
|
||||||
{{ item.get_status_text }}
|
@click.stop="onGetCoupon(item.id)"
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
</su-coupon>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</scroll-view>
|
|
||||||
</view>
|
|
||||||
<!-- 样式2 -->
|
|
||||||
<view class="md-coupon-wrap" v-if="mode == 2">
|
|
||||||
<scroll-view class="scroll-box" scroll-x scroll-anchoring>
|
|
||||||
<view class="coupon-box ss-flex">
|
|
||||||
<view
|
|
||||||
class="coupon-item"
|
|
||||||
:style="[couponBg, { marginLeft: data.space + 'px' }]"
|
|
||||||
v-for="(item, index) in couponList"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<su-coupon
|
|
||||||
size="md"
|
|
||||||
:textColor="data.fill.color"
|
|
||||||
background=""
|
|
||||||
:title="item.amount_text"
|
|
||||||
:value="item.amount"
|
|
||||||
:surplus="item.stock"
|
|
||||||
:couponId="item.id"
|
|
||||||
:type="item.type"
|
|
||||||
:sellBy="`${item.get_start_time.substring(0, 10)} 至 ${item.get_end_time.substring(
|
|
||||||
0,
|
|
||||||
10,
|
|
||||||
)}`"
|
|
||||||
>
|
>
|
||||||
<template v-slot:btn>
|
立即领取
|
||||||
<button
|
</button>
|
||||||
@click.stop="onGetCoupon(item.id)"
|
</template>
|
||||||
class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
|
</su-coupon>
|
||||||
:style="[btnStyles]"
|
</view>
|
||||||
>
|
|
||||||
<view class="btn-text">{{ item.get_status_text }}</view>
|
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
</su-coupon>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</scroll-view>
|
|
||||||
</view>
|
</view>
|
||||||
<!-- 样式3 -->
|
</scroll-view>
|
||||||
<view class="xs-coupon-wrap" v-if="mode == 3">
|
|
||||||
<scroll-view class="scroll-box" scroll-x scroll-anchoring>
|
|
||||||
<view class="coupon-box ss-flex">
|
|
||||||
<view
|
|
||||||
class="coupon-item"
|
|
||||||
:style="[couponBg, { marginLeft: data.space + 'px' }]"
|
|
||||||
v-for="(item, index) in couponList"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<su-coupon
|
|
||||||
size="xs"
|
|
||||||
:textColor="data.fill.color"
|
|
||||||
background=""
|
|
||||||
:title="item.amount_text"
|
|
||||||
:value="item.amount"
|
|
||||||
:surplus="item.stock"
|
|
||||||
:couponId="item.id"
|
|
||||||
:type="item.type"
|
|
||||||
:sellBy="`${item.get_start_time.substring(0, 10)} 至 ${item.get_end_time.substring(
|
|
||||||
0,
|
|
||||||
10,
|
|
||||||
)}`"
|
|
||||||
>
|
|
||||||
<template v-slot:btn>
|
|
||||||
<button
|
|
||||||
class="ss-reset-button card-btn"
|
|
||||||
:style="[btnStyles]"
|
|
||||||
@click.stop="onGetCoupon(item.id)"
|
|
||||||
>
|
|
||||||
{{ item.get_status_text }}
|
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
</su-coupon>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</scroll-view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
|
import TemplateApi from '@/sheep/api/promotion/coupon';
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
|
import {CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum} from "@/sheep/util/const";
|
||||||
|
import {floatToFixed2, formatDate} from "@/sheep/util";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -132,14 +60,48 @@
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { mode, button } = props.data;
|
const { columns, button } = props.data;
|
||||||
|
const SIZE_LIST = ['lg', 'md', 'xs']
|
||||||
const couponBg = {
|
const couponBg = {
|
||||||
background: `url(${sheep.$url.cdn(props.data.fill.bgImage)}) no-repeat top center / 100% 100%`,
|
background: `url(${sheep.$url.cdn(props.data.bgImg)}) no-repeat top center / 100% 100%`,
|
||||||
};
|
};
|
||||||
const btnStyles = {
|
const btnStyles = {
|
||||||
background: button.bgColor,
|
background: button.bgColor,
|
||||||
color: button.color,
|
color: button.color,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 格式化【折扣类型】
|
||||||
|
const formatCouponDiscountType = (coupon) => {
|
||||||
|
if(coupon.discountType === PromotionDiscountTypeEnum.PRICE.type) {
|
||||||
|
return 'reduce'
|
||||||
|
}
|
||||||
|
if(coupon.discountType === PromotionDiscountTypeEnum.PERCENT.type) {
|
||||||
|
return 'percent'
|
||||||
|
}
|
||||||
|
return `未知【${coupon.discountType}】`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化【折扣】
|
||||||
|
const formatCouponDiscountValue = (coupon) => {
|
||||||
|
if(coupon.discountType === PromotionDiscountTypeEnum.PRICE.type) {
|
||||||
|
return floatToFixed2(coupon.discountPrice)
|
||||||
|
}
|
||||||
|
if(coupon.discountType === PromotionDiscountTypeEnum.PERCENT.type) {
|
||||||
|
return coupon.discountPercent
|
||||||
|
}
|
||||||
|
return `未知【${coupon.discountType}】`
|
||||||
|
}
|
||||||
|
// 格式化【有效期限】
|
||||||
|
const formatValidityType = (row) => {
|
||||||
|
if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
|
||||||
|
return `${formatDate(row.validStartTime)} 至 ${formatDate(row.validEndTime)}`
|
||||||
|
}
|
||||||
|
if (row.validityType === CouponTemplateValidityTypeEnum.TERM.type) {
|
||||||
|
return `领取后第 ${row.fixedStartTerm} - ${row.fixedEndTerm} 天内可用`
|
||||||
|
}
|
||||||
|
return '未知【' + row.validityType + '】'
|
||||||
|
}
|
||||||
|
|
||||||
const couponList = ref([]);
|
const couponList = ref([]);
|
||||||
//立即领取优惠券
|
//立即领取优惠券
|
||||||
async function onGetCoupon(id) {
|
async function onGetCoupon(id) {
|
||||||
|
|
@ -149,15 +111,16 @@
|
||||||
title: msg,
|
title: msg,
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
});
|
});
|
||||||
} else {
|
return
|
||||||
let { data } = await sheep.$api.coupon.list({ ids: props.data.couponIds.join(',') });
|
|
||||||
couponList.value = [...data.data];
|
|
||||||
}
|
}
|
||||||
|
await getCouponTemplateList()
|
||||||
}
|
}
|
||||||
onMounted(async () => {
|
const getCouponTemplateList = async () => {
|
||||||
let { data } = await sheep.$api.coupon.list({ ids: props.data.couponIds.join(',') });
|
const { data } = await TemplateApi.getCouponTemplateListByIds(props.data.couponIds.join(','));
|
||||||
// couponList.value = [...data.data, ...data.data, ...data.data, ...data.data];
|
couponList.value = data;
|
||||||
couponList.value = [...data.data];
|
}
|
||||||
|
onMounted(() => {
|
||||||
|
getCouponTemplateList()
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -168,25 +131,21 @@
|
||||||
border-radius: 25rpx;
|
border-radius: 25rpx;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
line-height: 50rpx;
|
line-height: 50rpx;
|
||||||
|
&.vertical {
|
||||||
|
width: 50rpx;
|
||||||
|
height: 140rpx;
|
||||||
|
margin: auto 20rpx auto 0;
|
||||||
|
|
||||||
|
.btn-text {
|
||||||
|
font-size: 24rpx;
|
||||||
|
text-align: center;
|
||||||
|
writing-mode: vertical-lr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.coupon-item {
|
.coupon-item {
|
||||||
&:nth-of-type(1) {
|
&:nth-of-type(1) {
|
||||||
margin-left: 0 !important;
|
margin-left: 0 !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.md-coupon-wrap {
|
|
||||||
.card-btn {
|
|
||||||
width: 50rpx;
|
|
||||||
height: 140rpx;
|
|
||||||
margin: auto 0;
|
|
||||||
margin-right: 20rpx;
|
|
||||||
|
|
||||||
.btn-text {
|
|
||||||
font-size: 24rpx;
|
|
||||||
text-align: center;
|
|
||||||
writing-mode: vertical-lr;
|
|
||||||
writing-mode: tb-lr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="u-page__item" v-if="tabbar?.items.length > 0">
|
<view class="u-page__item" v-if="tabbar?.items?.length > 0">
|
||||||
<su-tabbar
|
<su-tabbar
|
||||||
:value="path"
|
:value="path"
|
||||||
:fixed="true"
|
:fixed="true"
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
</view>
|
</view>
|
||||||
<view class="ss-m-b-28">
|
<view class="ss-m-b-28">
|
||||||
<view class="title-text ss-m-b-10">{{ props.title }}</view>
|
<view class="title-text ss-m-b-10">{{ props.title }}</view>
|
||||||
<view class="surplus-text">仅剩:{{ props.surplus }}张</view>
|
<view class="surplus-text" v-if="props.surplus">仅剩:{{ props.surplus }}张</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="card-right ss-flex ss-row-center">
|
<view class="card-right ss-flex ss-row-center">
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
{{ state.stateMap[props.state] }}
|
{{ state.stateMap[props.state] }}
|
||||||
</button>
|
</button>
|
||||||
</slot>
|
</slot>
|
||||||
<view class="surplus-text ss-m-t-24">仅剩:{{ props.surplus }}张</view>
|
<view class="surplus-text ss-m-t-24" v-if="props.surplus">仅剩:{{ props.surplus }}张</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -159,7 +159,7 @@
|
||||||
},
|
},
|
||||||
surplus: {
|
surplus: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 1000,
|
default: 0,
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
// ========== MALL - 营销模块 ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠类型枚举
|
||||||
|
*/
|
||||||
|
export const PromotionDiscountTypeEnum = {
|
||||||
|
PRICE: {
|
||||||
|
type: 1,
|
||||||
|
name: '满减'
|
||||||
|
},
|
||||||
|
PERCENT: {
|
||||||
|
type: 2,
|
||||||
|
name: '折扣'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠劵模板的有限期类型的枚举
|
||||||
|
*/
|
||||||
|
export const CouponTemplateValidityTypeEnum = {
|
||||||
|
DATE: {
|
||||||
|
type: 1,
|
||||||
|
name: '固定日期可用'
|
||||||
|
},
|
||||||
|
TERM: {
|
||||||
|
type: 2,
|
||||||
|
name: '领取之后可用'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 营销的商品范围枚举
|
||||||
|
*/
|
||||||
|
export const PromotionProductScopeEnum = {
|
||||||
|
ALL: {
|
||||||
|
scope: 1,
|
||||||
|
name: '通用劵'
|
||||||
|
},
|
||||||
|
SPU: {
|
||||||
|
scope: 2,
|
||||||
|
name: '商品劵'
|
||||||
|
},
|
||||||
|
CATEGORY: {
|
||||||
|
scope: 3,
|
||||||
|
name: '品类劵'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个整数转换为分数保留两位小数
|
||||||
|
* @param {number | string | undefined} num 整数
|
||||||
|
* @return {number} 分数
|
||||||
|
*/
|
||||||
|
export const formatToFraction = (num) => {
|
||||||
|
if (typeof num === 'undefined') return 0
|
||||||
|
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num
|
||||||
|
return parseFloat((parsedNumber / 100).toFixed(2))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个数转换为 1.00 这样
|
||||||
|
* 数据呈现的时候使用
|
||||||
|
*
|
||||||
|
* @param {number | string | undefined} num 整数
|
||||||
|
* @return {string} 分数
|
||||||
|
*/
|
||||||
|
export const floatToFixed2 = (num) => {
|
||||||
|
let str = '0.00'
|
||||||
|
if (typeof num === 'undefined') {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
const f = formatToFraction(num)
|
||||||
|
const decimalPart = f.toString().split('.')[1]
|
||||||
|
const len = decimalPart ? decimalPart.length : 0
|
||||||
|
switch (len) {
|
||||||
|
case 0:
|
||||||
|
str = f.toString() + '.00'
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
str = f.toString() + '.0'
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
str = f.toString()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个分数转换为整数
|
||||||
|
*
|
||||||
|
* @param {number | string | undefined} num 分数
|
||||||
|
* @return {number} 整数
|
||||||
|
*/
|
||||||
|
export const convertToInteger = (num) => {
|
||||||
|
if (typeof num === 'undefined') return 0
|
||||||
|
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num
|
||||||
|
// TODO 分转元后还有小数则四舍五入
|
||||||
|
return Math.round(parsedNumber * 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间日期转换
|
||||||
|
* @param {dayjs.ConfigType} date 当前时间,new Date() 格式
|
||||||
|
* @param {string} format 需要转换的时间格式字符串
|
||||||
|
* @description format 字符串随意,如 `YYYY-mm、YYYY-mm-dd`
|
||||||
|
* @description format 季度:"YYYY-mm-dd HH:MM:SS QQQQ"
|
||||||
|
* @description format 星期:"YYYY-mm-dd HH:MM:SS WWW"
|
||||||
|
* @description format 几周:"YYYY-mm-dd HH:MM:SS ZZZ"
|
||||||
|
* @description format 季度 + 星期 + 几周:"YYYY-mm-dd HH:MM:SS WWW QQQQ ZZZ"
|
||||||
|
* @returns {string} 返回拼接后的时间字符串
|
||||||
|
*/
|
||||||
|
export function formatDate(date, format) {
|
||||||
|
// 日期不存在,则返回空
|
||||||
|
if (!date) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
// 日期存在,则进行格式化
|
||||||
|
if (format === undefined) {
|
||||||
|
format = 'YYYY-MM-DD HH:mm:ss'
|
||||||
|
}
|
||||||
|
return dayjs(date).format(format)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue