【功能完善】商品列表,展示满减送、限时折扣的信息

pull/102/MERGE
YunaiV 2024-09-16 09:16:16 +08:00
parent f03fcf1373
commit b741a1d148
3 changed files with 163 additions and 51 deletions

View File

@ -118,7 +118,7 @@
</template>
<script setup>
import { reactive,ref } from 'vue';
import { reactive, ref } from 'vue';
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import _ from 'lodash-es';
@ -278,13 +278,13 @@
return;
}
// 使 map id
const ids = data.list.map(item => item.id);
const ids = data.list.map((item) => item.id);
// 使 join id
const idsString = ids.join(',');
//
settleData.value = await getSettlementByIds(idsString)
settleData.value = await getSettlementByIds(idsString);
//
const ms = enrichDataWithSkus(data.list,settleData.value)
const ms = enrichDataWithSkus(data.list, settleData.value);
state.pagination.list = _.concat(state.pagination.list, ms);
state.pagination.total = data.total;
state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
@ -301,7 +301,7 @@
}
//
const settleData = ref()
const settleData = ref();
async function getSettlementByIds(ids) {
const { data } = await SpuApi.getSettlementProduct(ids);
return data;
@ -310,10 +310,10 @@
//
function enrichDataWithSkus(data, array) {
// id data
const dataMap = new Map(data.map(item => [item.id, { ...item }]));
const dataMap = new Map(data.map((item) => [item.id, { ...item }]));
// array
array.forEach(item => {
array.forEach((item) => {
// discountPrice vipPrice null
let discountPrice = null;
let vipPrice = null;
@ -321,13 +321,14 @@
let foundType6 = false;
// skus type 4 6
item.skus.forEach(sku => {
if (!foundType4 && sku.type === 4) {
discountPrice = sku.price;
item.skus.forEach((sku) => {
debugger;
if (!foundType4 && sku.promotionType === 4) {
discountPrice = sku.payPrice;
foundType4 = true;
}
if (!foundType6 && sku.type === 6) {
vipPrice = sku.price;
if (!foundType6 && sku.promotionType === 6) {
vipPrice = sku.payPrice;
foundType6 = true;
}
@ -338,10 +339,11 @@
});
// dataMap
if (dataMap.has(item.id)) {
dataMap.get(item.id).discountPrice = discountPrice;
dataMap.get(item.id).vipPrice = vipPrice;
dataMap.get(item.id).reward = item.reward;
if (dataMap.has(item.spuId)) {
debugger;
dataMap.get(item.spuId).discountPrice = discountPrice;
dataMap.get(item.spuId).vipPrice = vipPrice;
dataMap.get(item.spuId).reward = item.rewardActivity;
}
});

View File

@ -14,11 +14,11 @@ const SpuApi = {
});
},
// 获得商品结算信息
getSettlementProduct: (ids) => {
getSettlementProduct: (spuIds) => {
return request({
url: '/trade/order/settlementProduct',
url: '/trade/order/settlement-product',
method: 'GET',
params: { ids },
params: { spuIds },
custom: {
showLoading: false,
showError: false,

View File

@ -27,13 +27,23 @@
>
{{ data.title || data.name }}
</view>
<!-- 这里是新加的会员价和限时优惠 -->
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
<view class="card" v-if="iconShow">{{ iconShow }}</view>
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
</view>
<!-- 这里是新加的会员价和限时优惠结束 -->
<view
v-if="goodsFields.price?.show"
class="xs-goods-price font-OPPOSANS"
:style="[{ color: goodsFields.price.color }]"
>
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
<text v-else-if="iconShow == ''">{{ fen2yuan(data.vipPrice) }}</text>
<text v-else>{{
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
}}</text>
</view>
</view>
</view>
@ -60,13 +70,23 @@
>
{{ data.title || data.name }}
</view>
<!-- 这里是新加的会员价和限时优惠 -->
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
<view class="card" v-if="iconShow">{{ iconShow }}</view>
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
</view>
<!-- 这里是新加的会员价和限时优惠结束 -->
<view
v-if="goodsFields.price?.show"
class="sm-goods-price font-OPPOSANS"
:style="[{ color: goodsFields.price.color }]"
>
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
<text v-else-if="iconShow == ''">{{ fen2yuan(data.vipPrice) }}</text>
<text v-else>{{
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
}}</text>
</view>
</view>
</view>
@ -110,6 +130,12 @@
</view>
</view>
</slot>
<!-- 这里是新加的会员价和限时优惠 -->
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
<view class="card" v-if="iconShow">{{ iconShow }}</view>
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
</view>
<!-- 这里是新加的会员价和限时优惠结束 -->
<view class="ss-flex ss-col-bottom">
<view
v-if="goodsFields.price?.show"
@ -117,7 +143,11 @@
:style="[{ color: goodsFields.price.color }]"
>
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
<text v-else-if="iconShow == ''">{{ fen2yuan(data.vipPrice) }}</text>
<text v-else>{{
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
}}</text>
</view>
<view
@ -189,6 +219,12 @@
</view>
</view>
</slot>
<!-- 这里是新加的会员价和限时优惠 -->
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
<view class="card" v-if="iconShow">{{ iconShow }}</view>
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
</view>
<!-- 这里是新加的会员价和限时优惠结束 -->
<view class="ss-flex ss-col-bottom ss-m-t-10">
<view
v-if="goodsFields.price?.show"
@ -207,7 +243,11 @@
:style="[{ color: originPriceColor }]"
>
<text class="price-unit ss-font-20">{{ priceUnit }}</text>
<view class="ss-m-l-8">{{ fen2yuan(data.marketPrice) }}</view>
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
<text v-else-if="iconShow == ''">{{ fen2yuan(data.vipPrice) }}</text>
<text v-else>{{
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
}}</text>
</view>
</view>
<view class="ss-m-t-8 ss-flex ss-col-center ss-flex-wrap">
@ -262,10 +302,20 @@
</view>
</view>
</slot>
<!-- 这里是新加的会员价和限时优惠 -->
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
<view class="card" v-if="iconShow">{{ iconShow }}</view>
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
</view>
<!-- 这里是新加的会员价和限时优惠结束 -->
<view v-if="goodsFields.price?.show" class="ss-flex ss-col-bottom font-OPPOSANS">
<view class="sl-goods-price ss-m-r-12" :style="[{ color: goodsFields.price.color }]">
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
<text v-else-if="iconShow == ''">{{ fen2yuan(data.vipPrice) }}</text>
<text v-else>{{
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
}}</text>
</view>
<view
v-if="
@ -321,12 +371,12 @@
* @event {Function()} click - 点击卡片
*
*/
import { computed, reactive, getCurrentInstance, onMounted, nextTick } from 'vue';
import { computed, reactive, getCurrentInstance, onMounted, nextTick, ref } from 'vue';
import sheep from '@/sheep';
import { fen2yuan, formatSales } from '@/sheep/hooks/useGoods';
import { formatStock } from '@/sheep/hooks/useGoods';
import goodsCollectVue from '@/pages/user/goods-collect.vue';
import { isArray } from 'lodash-es';
//
const state = reactive({});
@ -337,17 +387,29 @@
default() {
return {
//
price: { show: true },
price: {
show: true,
},
//
stock: { show: true },
stock: {
show: true,
},
//
name: { show: true },
name: {
show: true,
},
//
introduction: { show: true },
introduction: {
show: true,
},
//
marketPrice: { show: true },
marketPrice: {
show: true,
},
//
salesCount: { show: true },
salesCount: {
show: true,
},
};
},
},
@ -416,7 +478,26 @@
default: false,
},
});
//
const iconShow = handle();
function handle() {
debugger;
if (props.data.discountPrice === null && props.data.vipPrice === null) {
// null
return '';
} else if (props.data.discountPrice === null) {
// discountPrice null vipPrice
return '会员价';
} else if (props.data.vipPrice === null) {
// vipPrice null discountPrice
return '限时优惠';
} else if (props.data.discountPrice < props.data.vipPrice) {
return '限时优惠';
} else if (props.data.discountPrice > props.data.vipPrice) {
return '会员价';
}
}
//
const elStyles = computed(() => {
return {
@ -454,7 +535,10 @@
function getGoodsPriceCardWH() {
if (props.size === 'md') {
const view = uni.createSelectorQuery().in(proxy);
view.select(`#${elId}`).fields({ size: true, scrollOffset: true });
view.select(`#${elId}`).fields({
size: true,
scrollOffset: true,
});
view.exec((data) => {
let totalHeight = 0;
const goodsPriceCard = data[0];
@ -469,7 +553,6 @@
});
}
}
onMounted(() => {
nextTick(() => {
getGoodsPriceCardWH();
@ -763,4 +846,31 @@
color: #ffffff;
}
}
.card {
width: fit-content;
height: fit-content;
padding: 2rpx 10rpx;
background-color: red;
color: #ffffff;
font-size: 24rpx;
}
.card2 {
width: fit-content;
height: fit-content;
padding: 2rpx 10rpx;
background-color: rgb(255, 242, 241);
color: #ff2621;
font-size: 24rpx;
margin-left: 5rpx;
}
.iconBox {
width: 100%;
height: fit-content;
margin-top: 10rpx;
display: flex;
justify-content: flex-start;
}
</style>