pull/100/head
岳琳红 2024-09-09 17:45:01 +08:00
parent 8f9375911c
commit 9cf068a1bb
6 changed files with 500 additions and 380 deletions

View File

@ -146,7 +146,8 @@
formatSales, formatSales,
formatGoodsSwiper, formatGoodsSwiper,
fen2yuan, fen2yuan,
handList handList,
handListPrice
} from '@/sheep/hooks/useGoods'; } from '@/sheep/hooks/useGoods';
import detailNavbar from './components/detail/detail-navbar.vue'; import detailNavbar from './components/detail/detail-navbar.vue';
import detailCellSku from './components/detail/detail-cell-sku.vue'; import detailCellSku from './components/detail/detail-cell-sku.vue';
@ -185,7 +186,14 @@
// //
function onSkuChange(e) { function onSkuChange(e) {
state.selectedSku = e; console.log('传来的规格改变',e)
if(e.type == 4){
settleData.value = e
setShow.value = true
}else{
state.selectedSku = e;
setShow.value = false
}
} }
// //
@ -271,21 +279,23 @@
async function getSettlementByIds(ids) { async function getSettlementByIds(ids) {
const { data } = await SpuApi.getSettlementProduct(ids); const { data } = await SpuApi.getSettlementProduct(ids);
settleData.value = handle(data) settleData.value = handle(data)
console.log('结算信息',data)
console.log('处理后数据',settleData.value) console.log('处理后数据',settleData.value)
state.goodsInfo.skus = handListPrice(state.goodsInfo.skus,data[0].skus)
console.log('要传递的数据',state.goodsInfo)
} }
// //
function handle(array){ function handle(array){
let setList = {} let setList = {}
array.forEach(item => { array.some(item => {
item.skus.forEach(items => { return item.skus.some(items => {
if(items.type == 4){ if (items.type === 4) {
setShow.value = true setShow.value = true;
setList = items setList = items;
return; return true; // truesome
} }
}) return false; //
}) });
});
// //
state.goodsInfo.skus.forEach(item =>{ state.goodsInfo.skus.forEach(item =>{
if(item.id == setList.skuId){ if(item.id == setList.skuId){

View File

@ -121,8 +121,7 @@
v-if="state.orderInfo.price.discountPrice > 0" v-if="state.orderInfo.price.discountPrice > 0"
> >
<view class="item-title">活动优惠</view> <view class="item-title">活动优惠</view>
<view class="ss-flex ss-col-center"> <view class="ss-flex ss-col-center" @tap="state.showDiscount = true">
<!-- @tap="state.showDiscount = true" TODO 芋艿后续要把优惠信息打进去 -->
<text class="item-value text-red"> <text class="item-value text-red">
-{{ fen2yuan(state.orderInfo.price.discountPrice) }} -{{ fen2yuan(state.orderInfo.price.discountPrice) }}
</text> </text>

View File

@ -5,15 +5,61 @@
<view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠</view> <view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠</view>
<view class="titleLi">促销</view> <view class="titleLi">促销</view>
<scroll-view class="model-content" scroll-y :scroll-with-animation="false" :enable-back-to-top="true"> <scroll-view class="model-content" scroll-y :scroll-with-animation="false" :enable-back-to-top="true">
<view class="actBox" v-for="item in state.activityInfo" :key="item.id"> <view class="actBox">
<view class="boxCont ss-flex ss-col-top ss-m-b-40" @tap="onGoodsList(item)"> <view class="boxCont ss-flex ss-col-top ss-m-b-40" @tap="onGoodsList(state.activityInfo[0])">
<view class="model-content-tag ss-flex ss-row-center">{{item.typeName}}</view> <view class="model-content-tag ss-flex ss-row-center">满减</view>
<view class="model-content-title"> <view class="model-content-title">
<view class="contBu" v-for="rule in state.activityMap[item.id]?.rules" :key="rule"> <view class="contBu">
{{ formatRewardActivityRule(state.activityMap[item.id], rule) }} <text v-for="(item,index) in state.activityMap[state.activityInfo[0]?.id]?.reduc"
:key="index">{{fen2yuan(item.discountPrice)}}元减{{fen2yuan(item.limit)}};</text>
</view> </view>
<view class="ss-m-b-24 cotBu-txt"> <view class="ss-m-b-24 cotBu-txt">
{{formatDateRange(item.startTime,item.endTime)}} {{formatDateRange(state.activityInfo[0]?.startTime,state.activityInfo[0]?.endTime)}}
</view>
</view>
<text class="cicon-forward" />
</view>
</view>
<view class="actBox">
<view class="boxCont ss-flex ss-col-top ss-m-b-40" @tap="onGoodsList(state.activityInfo[0])">
<view class="model-content-tag ss-flex ss-row-center">包邮</view>
<view class="model-content-title">
<view class="contBu">
<text v-for="(item,index) in state.activityMap[state.activityInfo[0]?.id]?.ship"
:key="index" v-show="item.bull">{{fen2yuan(item.discountPrice)}}元包邮;</text>
</view>
<view class="ss-m-b-24 cotBu-txt">
{{formatDateRange(state.activityInfo[0]?.startTime,state.activityInfo[0]?.endTime)}}
</view>
</view>
<text class="cicon-forward" />
</view>
</view>
<view class="actBox">
<view class="boxCont ss-flex ss-col-top ss-m-b-40" @tap="onGoodsList(state.activityInfo[0])">
<view class="model-content-tag ss-flex ss-row-center">送积分</view>
<view class="model-content-title">
<view class="contBu">
<text v-for="(item,index) in state.activityMap[state.activityInfo[0]?.id]?.scor"
:key="index" v-show="item.bull">{{fen2yuan(item.discountPrice)}}元送{{item.value}}积分;</text>
</view>
<view class="ss-m-b-24 cotBu-txt">
{{formatDateRange(state.activityInfo[0]?.startTime,state.activityInfo[0]?.endTime)}}
</view>
</view>
<text class="cicon-forward" />
</view>
</view>
<view class="actBox">
<view class="boxCont ss-flex ss-col-top ss-m-b-40" @tap="onGoodsList(state.activityInfo[0])">
<view class="model-content-tag ss-flex ss-row-center">送优惠券</view>
<view class="model-content-title">
<view class="contBu">
<text v-for="(item,index) in state.activityMap[state.activityInfo[0]?.id]?.cou"
:key="index" v-show="item.bull">{{fen2yuan(item.discountPrice)}}元送{{item.value}}张优惠券;</text>
</view>
<view class="ss-m-b-24 cotBu-txt">
{{formatDateRange(state.activityInfo[0]?.startTime,state.activityInfo[0]?.endTime)}}
</view> </view>
</view> </view>
<text class="cicon-forward" /> <text class="cicon-forward" />
@ -61,9 +107,9 @@
} from 'vue'; } from 'vue';
import RewardActivityApi from '@/sheep/api/promotion/rewardActivity'; import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
import { import {
formatRewardActivityRule,
fen2yuan, fen2yuan,
formatDateRange formatDateRange,
handActitList
} from '@/sheep/hooks/useGoods'; } from '@/sheep/hooks/useGoods';
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@ -92,7 +138,8 @@
if (res.code !== 0) { if (res.code !== 0) {
return; return;
} }
state.activityMap[activity.id] = res.data; state.activityMap[activity.id] = handActitList(res.data.rules);
console.log('最终数据', state)
}) })
}); });
} }

View File

@ -1,23 +1,12 @@
<template> <template>
<su-popup <su-popup :show="show" type="bottom" round="20" @close="emits('close')" showClose backgroundColor="#f2f2f2">
:show="show" <view class="model-box">
type="bottom" <view class="title ss-m-t-38 ss-m-l-20 ss-m-b-40">活动优惠</view>
round="20" <scroll-view class="model-content ss-m-l-20" scroll-y :scroll-with-animation="false"
@close="emits('close')" :enable-back-to-top="true">
showClose <view v-for="(item, index) in state.orderInfo.promotions" :key="index">
backgroundColor="#f2f2f2" <view class="ss-flex ss-m-b-40 subtitle">
> <!-- <view>{{ item.goods_ids.length }}</view>
<view class="model-box">
<view class="title ss-m-t-38 ss-m-l-20 ss-m-b-40">活动优惠</view>
<scroll-view
class="model-content ss-m-l-20"
scroll-y
:scroll-with-animation="false"
:enable-back-to-top="true"
>
<view v-for="(item, index) in state.orderInfo.promo_infos" :key="index">
<view class="ss-flex ss-m-b-40 subtitle">
<view>{{ item.goods_ids.length }}</view>
<view v-if="item.activity_type === 'full_discount'"> <view v-if="item.activity_type === 'full_discount'">
{{ item.discount_rule.full }}{{ item.discount_rule.discount }},已减 {{ item.discount_rule.full }}{{ item.discount_rule.discount }},已减
</view> </view>
@ -25,90 +14,99 @@
<view v-if="item.activity_type === 'full_reduce'"> <view v-if="item.activity_type === 'full_reduce'">
{{ item.discount_rule.full }}{{ item.discount_rule.discount }},已减 {{ item.discount_rule.full }}{{ item.discount_rule.discount }},已减
</view> </view>
<view class="price-text">{{ item.promo_discount_money || '0.00' }}</view> <view class="price-text">{{ item.promo_discount_money || '0.00' }}</view> -->
</view> <view>
<scroll-view class="scroll-box" scroll-x scroll-anchoring> {{item.description}}
<view class="ss-flex"> </view>
<view v-for="i in item.goods_ids" :key="i"> </view>
<image class="content-img" :src="sheep.$url.cdn(getGoodsImg(i))" /> </view>
</view> </scroll-view>
</view> </view>
</scroll-view> <view class="modal-footer ss-flex">
</view> <button class="confirm-btn ss-reset-button" @tap="emits('close')"></button>
</scroll-view> </view>
</view> </su-popup>
<view class="modal-footer ss-flex">
<button class="confirm-btn ss-reset-button" @tap="emits('close')"></button>
</view>
</su-popup>
</template> </template>
<script setup> <script setup>
import { computed, reactive } from 'vue'; import {
import sheep from '@/sheep'; computed,
const props = defineProps({ reactive
promoInfo: { } from 'vue';
type: Array, import sheep from '@/sheep';
default: () => [], import {
}, fen2yuan
goodsList: { } from '@/sheep/hooks/useGoods';
type: Array, const props = defineProps({
default: () => [], promoInfo: {
}, type: Array,
modelValue: { default: () => [],
type: Object, },
default() {}, goodsList: {
}, type: Array,
show: { default: () => [],
type: Boolean, },
default: false, modelValue: {
}, type: Object,
}); default () {},
const emits = defineEmits(['close']); },
const state = reactive({ show: {
orderInfo: computed(() => props.modelValue), type: Boolean,
}); default: false,
const getGoodsImg = (e) => { },
let goodsImg = ''; });
state.orderInfo.goods_list.forEach((i) => { const emits = defineEmits(['close']);
if (e == i.goods_id) { const state = reactive({
goodsImg = i.goods.image; orderInfo: computed(() => props.modelValue),
} });
}); const getGoodsImg = (e) => {
return goodsImg; let goodsImg = '';
}; state.orderInfo.goods_list.forEach((i) => {
if (e == i.goods_id) {
goodsImg = i.goods.image;
}
});
return goodsImg;
};
console.log('shuju', props)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.model-box { .model-box {
height: 60vh; height: 60vh;
} }
.model-content {
height: 54vh; .model-content {
} height: 54vh;
.modal-footer { }
width: 100%;
height: 120rpx; .modal-footer {
background: #fff; width: 100%;
} height: 120rpx;
.confirm-btn { background: #fff;
width: 710rpx; }
margin-left: 20rpx;
height: 80rpx; .confirm-btn {
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient)); width: 710rpx;
border-radius: 40rpx; margin-left: 20rpx;
color: #fff; height: 80rpx;
} background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
.content-img { border-radius: 40rpx;
width: 140rpx; color: #fff;
height: 140rpx; }
margin-right: 20rpx;
margin-bottom: 20rpx; .content-img {
} width: 140rpx;
.subtitle { height: 140rpx;
font-size: 28rpx; margin-right: 20rpx;
font-weight: 500; margin-bottom: 20rpx;
color: #333333; }
}
.price-text { .subtitle {
color: #ff3000; font-size: 28rpx;
} font-weight: 500;
color: #333333;
}
.price-text {
color: #ff3000;
}
</style> </style>

View File

@ -13,6 +13,8 @@
<view class="ss-flex"> <view class="ss-flex">
<view class="price-text"> <view class="price-text">
{{ fen2yuan( state.selectedSku.price || goodsInfo.price) }} {{ fen2yuan( state.selectedSku.price || goodsInfo.price) }}
<text class="iconBox" v-if="state.selectedSku.type == 6"></text>
<text class="iconBox" v-if="state.selectedSku.type == 4"></text>
</view> </view>
</view> </view>
<view class="stock-text ss-m-l-20"> <view class="stock-text ss-m-l-20">
@ -96,6 +98,7 @@
() => state.selectedSku, () => state.selectedSku,
(newVal) => { (newVal) => {
emits('change', newVal); emits('change', newVal);
console.log('选中的sku信息',state.selectedSku)
}, { }, {
immediate: true, // immediate: true, //
deep: true, // deep: true, //
@ -403,4 +406,13 @@
} }
} }
} }
.iconBox {
width: fit-content;
height: fit-content;
padding: 2rpx 10rpx;
background-color: rgb(255, 242, 241);
color: #ff2621;
font-size: 24rpx;
margin-left: 5rpx;
}
</style> </style>

View File

@ -1,7 +1,11 @@
import { ref } from 'vue'; import {
ref
} from 'vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import $url from '@/sheep/url'; import $url from '@/sheep/url';
import { formatDate } from '@/sheep/util'; import {
formatDate
} from '@/sheep/util';
/** /**
* 格式化销量 * 格式化销量
@ -10,8 +14,8 @@ import { formatDate } from '@/sheep/util';
* @return {string} 格式化后的销量字符串 * @return {string} 格式化后的销量字符串
*/ */
export function formatSales(type, num) { export function formatSales(type, num) {
let prefix = type !== 'exact' && num < 10 ? '销量' : '已售'; let prefix = type !== 'exact' && num < 10 ? '销量' : '已售';
return formatNum(prefix, type, num) return formatNum(prefix, type, num)
} }
/** /**
@ -21,7 +25,7 @@ export function formatSales(type, num) {
* @return {string} 格式化后的销量字符串 * @return {string} 格式化后的销量字符串
*/ */
export function formatExchange(type, num) { export function formatExchange(type, num) {
return formatNum('已兑换', type, num) return formatNum('已兑换', type, num)
} }
@ -32,7 +36,7 @@ export function formatExchange(type, num) {
* @return {string} 格式化后的销量字符串 * @return {string} 格式化后的销量字符串
*/ */
export function formatStock(type, num) { export function formatStock(type, num) {
return formatNum('库存', type, num) return formatNum('库存', type, num)
} }
/** /**
@ -43,27 +47,27 @@ export function formatStock(type, num) {
* @return {string} 格式化后的销量字符串 * @return {string} 格式化后的销量字符串
*/ */
export function formatNum(prefix, type, num) { export function formatNum(prefix, type, num) {
num = (num || 0); num = (num || 0);
// 情况一:精确数值 // 情况一:精确数值
if (type === 'exact') { if (type === 'exact') {
return prefix + num; return prefix + num;
} }
// 情况二:小于等于 10 // 情况二:小于等于 10
if (num < 10) { if (num < 10) {
return `${prefix}≤10`; return `${prefix}≤10`;
} }
// 情况三:大于 10除第一位外其它位都显示为0 // 情况三:大于 10除第一位外其它位都显示为0
// 例如100 - 199 显示为 100+ // 例如100 - 199 显示为 100+
// 9000 - 9999 显示为 9000+ // 9000 - 9999 显示为 9000+
const numStr = num.toString(); const numStr = num.toString();
const first = numStr[0]; const first = numStr[0];
const other = '0'.repeat(numStr.length - 1); const other = '0'.repeat(numStr.length - 1);
return `${prefix}${first}${other}+`; return `${prefix}${first}${other}+`;
} }
// 格式化价格 // 格式化价格
export function formatPrice(e) { export function formatPrice(e) {
return e.length === 1 ? e[0] : e.join('~'); return e.length === 1 ? e[0] : e.join('~');
} }
// 视频格式后缀列表 // 视频格式后缀列表
@ -76,12 +80,15 @@ const VIDEO_SUFFIX_LIST = ['.avi', '.mp4']
* @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表 * @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表
*/ */
export function formatGoodsSwiper(urlList) { export function formatGoodsSwiper(urlList) {
return urlList?.filter(url => url).map((url, key) => { return urlList?.filter(url => url).map((url, key) => {
const isVideo = VIDEO_SUFFIX_LIST.some(suffix => url.includes(suffix)); const isVideo = VIDEO_SUFFIX_LIST.some(suffix => url.includes(suffix));
const type = isVideo ? 'video' : 'image' const type = isVideo ? 'video' : 'image'
const src = $url.cdn(url); const src = $url.cdn(url);
return { type, src } return {
}) || []; type,
src
}
}) || [];
} }
/** /**
@ -91,18 +98,18 @@ export function formatGoodsSwiper(urlList) {
* @return {string} 颜色的 class 名称 * @return {string} 颜色的 class 名称
*/ */
export function formatOrderColor(order) { export function formatOrderColor(order) {
if (order.status === 0) { if (order.status === 0) {
return 'info-color'; return 'info-color';
} }
if (order.status === 10 if (order.status === 10 ||
|| order.status === 20 order.status === 20 ||
|| (order.status === 30 && !order.commentStatus)) { (order.status === 30 && !order.commentStatus)) {
return 'warning-color'; return 'warning-color';
} }
if (order.status === 30 && order.commentStatus) { if (order.status === 30 && order.commentStatus) {
return 'success-color'; return 'success-color';
} }
return 'danger-color'; return 'danger-color';
} }
/** /**
@ -111,25 +118,25 @@ export function formatOrderColor(order) {
* @param order 订单 * @param order 订单
*/ */
export function formatOrderStatus(order) { export function formatOrderStatus(order) {
if (order.status === 0) { if (order.status === 0) {
return '待付款'; return '待付款';
} }
if (order.status === 10 && order.deliveryType === 1) { if (order.status === 10 && order.deliveryType === 1) {
return '待发货'; return '待发货';
} }
if (order.status === 10 && order.deliveryType === 2) { if (order.status === 10 && order.deliveryType === 2) {
return '待核销'; return '待核销';
} }
if (order.status === 20) { if (order.status === 20) {
return '待收货'; return '待收货';
} }
if (order.status === 30 && !order.commentStatus) { if (order.status === 30 && !order.commentStatus) {
return '待评价'; return '待评价';
} }
if (order.status === 30 && order.commentStatus) { if (order.status === 30 && order.commentStatus) {
return '已完成'; return '已完成';
} }
return '已关闭'; return '已关闭';
} }
/** /**
@ -138,22 +145,22 @@ export function formatOrderStatus(order) {
* @param order 订单 * @param order 订单
*/ */
export function formatOrderStatusDescription(order) { export function formatOrderStatusDescription(order) {
if (order.status === 0) { if (order.status === 0) {
return `请在 ${ formatDate(order.payExpireTime) } 前完成支付`; return `请在 ${ formatDate(order.payExpireTime) } 前完成支付`;
} }
if (order.status === 10) { if (order.status === 10) {
return '商家未发货,请耐心等待'; return '商家未发货,请耐心等待';
} }
if (order.status === 20) { if (order.status === 20) {
return '商家已发货,请耐心等待'; return '商家已发货,请耐心等待';
} }
if (order.status === 30 && !order.commentStatus) { if (order.status === 30 && !order.commentStatus) {
return '已收货,快去评价一下吧'; return '已收货,快去评价一下吧';
} }
if (order.status === 30 && order.commentStatus) { if (order.status === 30 && order.commentStatus) {
return '交易完成,感谢您的支持'; return '交易完成,感谢您的支持';
} }
return '交易关闭'; return '交易关闭';
} }
/** /**
@ -162,26 +169,26 @@ export function formatOrderStatusDescription(order) {
* @param order 订单 * @param order 订单
*/ */
export function handleOrderButtons(order) { export function handleOrderButtons(order) {
order.buttons = [] order.buttons = []
if (order.type === 3) { // 查看拼团 if (order.type === 3) { // 查看拼团
order.buttons.push('combination'); order.buttons.push('combination');
} }
if (order.status === 20) { // 确认收货 if (order.status === 20) { // 确认收货
order.buttons.push('confirm'); order.buttons.push('confirm');
} }
if (order.logisticsId > 0) { // 查看物流 if (order.logisticsId > 0) { // 查看物流
order.buttons.push('express'); order.buttons.push('express');
} }
if (order.status === 0) { // 取消订单 / 发起支付 if (order.status === 0) { // 取消订单 / 发起支付
order.buttons.push('cancel'); order.buttons.push('cancel');
order.buttons.push('pay'); order.buttons.push('pay');
} }
if (order.status === 30 && !order.commentStatus) { // 发起评价 if (order.status === 30 && !order.commentStatus) { // 发起评价
order.buttons.push('comment'); order.buttons.push('comment');
} }
if (order.status === 40) { // 删除订单 if (order.status === 40) { // 删除订单
order.buttons.push('delete'); order.buttons.push('delete');
} }
} }
/** /**
@ -190,31 +197,31 @@ export function handleOrderButtons(order) {
* @param afterSale 售后 * @param afterSale 售后
*/ */
export function formatAfterSaleStatus(afterSale) { export function formatAfterSaleStatus(afterSale) {
if (afterSale.status === 10) { if (afterSale.status === 10) {
return '申请售后'; return '申请售后';
} }
if (afterSale.status === 20) { if (afterSale.status === 20) {
return '商品待退货'; return '商品待退货';
} }
if (afterSale.status === 30) { if (afterSale.status === 30) {
return '商家待收货'; return '商家待收货';
} }
if (afterSale.status === 40) { if (afterSale.status === 40) {
return '等待退款'; return '等待退款';
} }
if (afterSale.status === 50) { if (afterSale.status === 50) {
return '退款成功'; return '退款成功';
} }
if (afterSale.status === 61) { if (afterSale.status === 61) {
return '买家取消'; return '买家取消';
} }
if (afterSale.status === 62) { if (afterSale.status === 62) {
return '商家拒绝'; return '商家拒绝';
} }
if (afterSale.status === 63) { if (afterSale.status === 63) {
return '商家拒收货'; return '商家拒收货';
} }
return '未知状态'; return '未知状态';
} }
/** /**
@ -223,31 +230,31 @@ export function formatAfterSaleStatus(afterSale) {
* @param afterSale 售后 * @param afterSale 售后
*/ */
export function formatAfterSaleStatusDescription(afterSale) { export function formatAfterSaleStatusDescription(afterSale) {
if (afterSale.status === 10) { if (afterSale.status === 10) {
return '退款申请待商家处理'; return '退款申请待商家处理';
} }
if (afterSale.status === 20) { if (afterSale.status === 20) {
return '请退货并填写物流信息'; return '请退货并填写物流信息';
} }
if (afterSale.status === 30) { if (afterSale.status === 30) {
return '退货退款申请待商家处理'; return '退货退款申请待商家处理';
} }
if (afterSale.status === 40) { if (afterSale.status === 40) {
return '等待退款'; return '等待退款';
} }
if (afterSale.status === 50) { if (afterSale.status === 50) {
return '退款成功'; return '退款成功';
} }
if (afterSale.status === 61) { if (afterSale.status === 61) {
return '退款关闭'; return '退款关闭';
} }
if (afterSale.status === 62) { if (afterSale.status === 62) {
return `商家不同意退款申请,拒绝原因:${afterSale.auditReason}`; return `商家不同意退款申请,拒绝原因:${afterSale.auditReason}`;
} }
if (afterSale.status === 63) { if (afterSale.status === 63) {
return `商家拒绝收货,不同意退款,拒绝原因:${afterSale.auditReason}`; return `商家拒绝收货,不同意退款,拒绝原因:${afterSale.auditReason}`;
} }
return '未知状态'; return '未知状态';
} }
/** /**
@ -256,13 +263,13 @@ export function formatAfterSaleStatusDescription(afterSale) {
* @param afterSale 售后 * @param afterSale 售后
*/ */
export function handleAfterSaleButtons(afterSale) { export function handleAfterSaleButtons(afterSale) {
afterSale.buttons = []; afterSale.buttons = [];
if ([10, 20, 30].includes(afterSale.status)) { // 取消订单 if ([10, 20, 30].includes(afterSale.status)) { // 取消订单
afterSale.buttons.push('cancel'); afterSale.buttons.push('cancel');
} }
if (afterSale.status === 20) { // 退货信息 if (afterSale.status === 20) { // 退货信息
afterSale.buttons.push('delivery'); afterSale.buttons.push('delivery');
} }
} }
/** /**
@ -272,28 +279,28 @@ export function handleAfterSaleButtons(afterSale) {
* @return {{s: string, ms: number, h: string, m: string}} 持续时间 * @return {{s: string, ms: number, h: string, m: string}} 持续时间
*/ */
export function useDurationTime(toTime, fromTime = '') { export function useDurationTime(toTime, fromTime = '') {
toTime = getDayjsTime(toTime); toTime = getDayjsTime(toTime);
if (fromTime === '') { if (fromTime === '') {
fromTime = dayjs(); fromTime = dayjs();
} }
let duration = ref(toTime - fromTime); let duration = ref(toTime - fromTime);
if (duration.value > 0) { if (duration.value > 0) {
setTimeout(() => { setTimeout(() => {
if (duration.value > 0) { if (duration.value > 0) {
duration.value -= 1000; duration.value -= 1000;
} }
}, 1000); }, 1000);
} }
let durationTime = dayjs.duration(duration.value); let durationTime = dayjs.duration(duration.value);
return { return {
h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours()) h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours())
.toString() .toString()
.padStart(2, '0'), .padStart(2, '0'),
m: durationTime.minutes().toString().padStart(2, '0'), m: durationTime.minutes().toString().padStart(2, '0'),
s: durationTime.seconds().toString().padStart(2, '0'), s: durationTime.seconds().toString().padStart(2, '0'),
ms: durationTime.$ms, ms: durationTime.$ms,
}; };
} }
/** /**
@ -302,19 +309,19 @@ export function useDurationTime(toTime, fromTime = '') {
* @return {dayjs.Dayjs} * @return {dayjs.Dayjs}
*/ */
function getDayjsTime(time) { function getDayjsTime(time) {
time = time.toString(); time = time.toString();
if (time.indexOf('-') > 0) { if (time.indexOf('-') > 0) {
// 'date' // 'date'
return dayjs(time); return dayjs(time);
} }
if (time.length > 10) { if (time.length > 10) {
// 'timestamp' // 'timestamp'
return dayjs(parseInt(time)); return dayjs(parseInt(time));
} }
if (time.length === 10) { if (time.length === 10) {
// 'unixTime' // 'unixTime'
return dayjs.unix(parseInt(time)); return dayjs.unix(parseInt(time));
} }
} }
/** /**
@ -324,7 +331,7 @@ function getDayjsTime(time) {
* @returns {string} 例如说 1.00 * @returns {string} 例如说 1.00
*/ */
export function fen2yuan(price) { export function fen2yuan(price) {
return (price / 100.0).toFixed(2) return (price / 100.0).toFixed(2)
} }
/** /**
@ -342,33 +349,33 @@ export function fen2yuan(price) {
* @param skus 商品 SKU 数组 * @param skus 商品 SKU 数组
*/ */
export function convertProductPropertyList(skus) { export function convertProductPropertyList(skus) {
let result = []; let result = [];
for (const sku of skus) { for (const sku of skus) {
if (!sku.properties) { if (!sku.properties) {
continue continue
} }
for (const property of sku.properties) { for (const property of sku.properties) {
// ① 先处理属性 // ① 先处理属性
let resultProperty = result.find(item => item.id === property.propertyId) let resultProperty = result.find(item => item.id === property.propertyId)
if (!resultProperty) { if (!resultProperty) {
resultProperty = { resultProperty = {
id: property.propertyId, id: property.propertyId,
name: property.propertyName, name: property.propertyName,
values: [] values: []
} }
result.push(resultProperty) result.push(resultProperty)
} }
// ② 再处理属性值 // ② 再处理属性值
let resultValue = resultProperty.values.find(item => item.id === property.valueId) let resultValue = resultProperty.values.find(item => item.id === property.valueId)
if (!resultValue) { if (!resultValue) {
resultProperty.values.push({ resultProperty.values.push({
id: property.valueId, id: property.valueId,
name: property.valueName name: property.valueName
}) })
} }
} }
} }
return result; return result;
} }
/** /**
@ -379,53 +386,100 @@ export function convertProductPropertyList(skus) {
* @returns {string} 规格字符串 * @returns {string} 规格字符串
*/ */
export function formatRewardActivityRule(activity, rule) { export function formatRewardActivityRule(activity, rule) {
if (activity.conditionType === 10) { if (activity.conditionType === 10) {
return `${fen2yuan(rule.limit)} 元减 ${fen2yuan(rule.discountPrice)}`; return `${fen2yuan(rule.limit)} 元减 ${fen2yuan(rule.discountPrice)}`;
} }
if (activity.conditionType === 20) { if (activity.conditionType === 20) {
return `${rule.limit} 件减 ${fen2yuan(rule.discountPrice)}`; return `${rule.limit} 件减 ${fen2yuan(rule.discountPrice)}`;
} }
return ''; return '';
} }
// 新增将时间搓转换为开始时间-结束时间的格式 // 新增将时间搓转换为开始时间-结束时间的格式
export function formatDateRange(startTimestamp, endTimestamp) { export function formatDateRange(startTimestamp, endTimestamp) {
// 定义一个辅助函数来格式化时间戳为 YYYY.MM.DD 格式 // 定义一个辅助函数来格式化时间戳为 YYYY.MM.DD 格式
const formatDate = (timestamp) => { const formatDate = (timestamp) => {
const date = new Date(timestamp); const date = new Date(timestamp);
const year = date.getFullYear(); const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始所以需要+1 const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始所以需要+1
const day = String(date.getDate()).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0');
return `${year}.${month}.${day}`; return `${year}.${month}.${day}`;
}; };
// 格式化开始和结束时间 // 格式化开始和结束时间
const start = formatDate(startTimestamp); const start = formatDate(startTimestamp);
const end = formatDate(endTimestamp); const end = formatDate(endTimestamp);
// 返回格式化的日期范围 // 返回格式化的日期范围
return `${start}-${end}`; return `${start}-${end}`;
} }
//处理活动信息 //处理活动信息
export function handList(orders) { export function handList(orders) {
const typeMap = { const typeMap = {
'1':'秒杀活动', '1': '秒杀活动',
'2':'砍价活动', '2': '砍价活动',
'3':'拼团活动', '3': '拼团活动',
'4':'限时折扣', '4': '限时折扣',
'5':'满减送', '5': '满减送',
'6':'会员折扣', '6': '会员折扣',
'7':'优惠券', '7': '优惠券',
'8':'积分' '8': '积分'
};
// 给每个订单对象添加 typeName 属性
// console.log('函数',orders)
let updatedOrders = orders.map(order => {
return {
...order, // 展开现有的订单对象属性
typeName: typeMap[order.type] // 添加 typeName 属性
};
});
return updatedOrders
}; };
// 给每个订单对象添加 typeName 属性
// console.log('函数',orders)
let updatedOrders = orders.map(order => {
return {
...order, // 展开现有的订单对象属性
typeName: typeMap[order.type] // 添加 typeName 属性
};
});
return updatedOrders
};
//根据skuid来修改价格并添加时间
export function handListPrice(array,array2) {
// 将 array2 转换为一个以 skuId 为键的对象,以便于快速查找
const array2Map = array2.reduce((acc, item) => {
acc[item.skuId] = { price: item.price, type: item.type,endTime:item.endTime };
return acc;
}, {});
// 遍历 array 数组并更新 price 和 type
array.forEach(item => {
if (array2Map[item.id]) {
// 如果在 array2Map 中找到了对应的 skuId即 id
item.price = array2Map[item.id].price;
item.type = array2Map[item.id].type;
item.endTime = array2Map[item.id].endTime;
}
});
// 返回更新后的 array
return array;
};
//处理活动数据
export function handActitList(rules) {
const rules2 = {
reduc: rules.map(item => ({
discountPrice: item.discountPrice,
limit: item.limit,
bull: true // 默认为 true
})),
cou: rules.map(item => ({
discountPrice: item.discountPrice,
value: item.couponCounts.reduce((acc, count) => acc + count, 0), // 计算 couponCounts 中各项之和
bull: item.givePoint // 对应 givePoint
})),
ship: rules.map(item => ({
discountPrice: item.discountPrice,
bull: item.freeDelivery // 对应 freeDelivery
})),
scor: rules.map(item => ({
discountPrice: item.discountPrice,
value: item.point, // 直接使用 point
bull: item.givePoint // 对应 givePoint
}))
};
return rules2
};