【代码优化】商城:优化 /promotion/activity/list-by-spu-id 的逻辑
parent
49e8b9f5c3
commit
eb3d0ff6b0
|
@ -7,13 +7,26 @@
|
||||||
<!-- 骨架屏 -->
|
<!-- 骨架屏 -->
|
||||||
<detailSkeleton v-if="state.skeletonLoading" />
|
<detailSkeleton v-if="state.skeletonLoading" />
|
||||||
<!-- 下架/售罄提醒 -->
|
<!-- 下架/售罄提醒 -->
|
||||||
<s-empty v-else-if="state.goodsInfo === null" text="商品不存在或已下架" icon="/static/soldout-empty.png" showAction
|
<s-empty
|
||||||
actionText="再逛逛" actionUrl="/pages/goods/list" />
|
v-else-if="state.goodsInfo === null"
|
||||||
|
text="商品不存在或已下架"
|
||||||
|
icon="/static/soldout-empty.png"
|
||||||
|
showAction
|
||||||
|
actionText="再逛逛"
|
||||||
|
actionUrl="/pages/goods/list"
|
||||||
|
/>
|
||||||
<block v-else>
|
<block v-else>
|
||||||
<view class="detail-swiper-selector">
|
<view class="detail-swiper-selector">
|
||||||
<!-- 商品轮播图 -->
|
<!-- 商品轮播图 -->
|
||||||
<su-swiper class="ss-m-b-14" isPreview :list="formatGoodsSwiper(state.goodsInfo.sliderPicUrls)"
|
<su-swiper
|
||||||
otStyle="tag" imageMode="widthFix" dotCur="bg-mask-40" :seizeHeight="750" />
|
class="ss-m-b-14"
|
||||||
|
isPreview
|
||||||
|
:list="formatGoodsSwiper(state.goodsInfo.sliderPicUrls)"
|
||||||
|
otStyle="tag"
|
||||||
|
imageMode="widthFix"
|
||||||
|
dotCur="bg-mask-40"
|
||||||
|
:seizeHeight="750"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 价格+标题 -->
|
<!-- 价格+标题 -->
|
||||||
<view class="title-card detail-card ss-p-y-40 ss-p-x-20">
|
<view class="title-card detail-card ss-p-y-40 ss-p-x-20">
|
||||||
|
@ -34,16 +47,23 @@
|
||||||
<!-- 满减送/限时折扣活动的提示 -->
|
<!-- 满减送/限时折扣活动的提示 -->
|
||||||
<div class="tag-content">
|
<div class="tag-content">
|
||||||
<view class="tag-box ss-flex">
|
<view class="tag-box ss-flex">
|
||||||
<view class="tag ss-m-r-10" v-for="promos in state.activityInfo"
|
<view
|
||||||
:key="promos.id" @tap="onActivity">
|
class="tag ss-m-r-10"
|
||||||
|
v-for="promos in state.activityInfo"
|
||||||
|
:key="promos.id"
|
||||||
|
@tap="onActivity"
|
||||||
|
>
|
||||||
{{ promos.name }}
|
{{ promos.name }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 优惠劵 -->
|
<!-- 优惠劵 -->
|
||||||
<view class="get-coupon-box ss-flex ss-col-center ss-m-l-20" @tap="state.showModel = true"
|
<view
|
||||||
v-if="state.couponInfo.length">
|
class="get-coupon-box ss-flex ss-col-center ss-m-l-20"
|
||||||
|
@tap="state.showModel = true"
|
||||||
|
v-if="state.couponInfo.length"
|
||||||
|
>
|
||||||
<view class="discounts-title ss-m-r-8">领券</view>
|
<view class="discounts-title ss-m-r-8">领券</view>
|
||||||
<text class="cicon-forward"></text>
|
<text class="cicon-forward"></text>
|
||||||
</view>
|
</view>
|
||||||
|
@ -54,30 +74,51 @@
|
||||||
|
|
||||||
<!-- 功能卡片 -->
|
<!-- 功能卡片 -->
|
||||||
<view class="detail-cell-card detail-card ss-flex-col">
|
<view class="detail-cell-card detail-card ss-flex-col">
|
||||||
<detail-cell-sku v-model="state.selectedSku.goods_sku_text" :sku="state.selectedSku"
|
<detail-cell-sku
|
||||||
@tap="state.showSelectSku = true" />
|
v-model="state.selectedSku.goods_sku_text"
|
||||||
|
:sku="state.selectedSku"
|
||||||
|
@tap="state.showSelectSku = true"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 规格与数量弹框 -->
|
<!-- 规格与数量弹框 -->
|
||||||
<s-select-sku :goodsInfo="state.goodsInfo" :show="state.showSelectSku" @addCart="onAddCart"
|
<s-select-sku
|
||||||
@buy="onBuy" @change="onSkuChange" @close="state.showSelectSku = false" />
|
:goodsInfo="state.goodsInfo"
|
||||||
|
:show="state.showSelectSku"
|
||||||
|
@addCart="onAddCart"
|
||||||
|
@buy="onBuy"
|
||||||
|
@change="onSkuChange"
|
||||||
|
@close="state.showSelectSku = false"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 评价 -->
|
<!-- 评价 -->
|
||||||
<detail-comment-card class="detail-comment-selector" :goodsId="state.goodsId" />
|
<detail-comment-card class="detail-comment-selector" :goodsId="state.goodsId" />
|
||||||
<!-- 详情 -->
|
<!-- 详情 -->
|
||||||
<detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
|
<detail-content-card
|
||||||
|
class="detail-content-selector"
|
||||||
|
:content="state.goodsInfo.description"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 活动跳转:拼团/秒杀/砍价活动 -->
|
<!-- 活动跳转:拼团/秒杀/砍价活动 -->
|
||||||
<detail-activity-tip v-if="state.activityList.length > 0" :activity-list="state.activityList" />
|
<detail-activity-tip
|
||||||
|
v-if="state.activityList.length > 0"
|
||||||
|
:activity-list="state.activityList"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 详情 tabbar -->
|
<!-- 详情 tabbar -->
|
||||||
<detail-tabbar v-model="state.goodsInfo">
|
<detail-tabbar v-model="state.goodsInfo">
|
||||||
<view class="buy-box ss-flex ss-col-center ss-p-r-20" v-if="state.goodsInfo.stock > 0">
|
<view class="buy-box ss-flex ss-col-center ss-p-r-20" v-if="state.goodsInfo.stock > 0">
|
||||||
<button class="ss-reset-button add-btn ui-Shadow-Main" @tap="state.showSelectSku = true">
|
<button
|
||||||
|
class="ss-reset-button add-btn ui-Shadow-Main"
|
||||||
|
@tap="state.showSelectSku = true"
|
||||||
|
>
|
||||||
加入购物车
|
加入购物车
|
||||||
</button>
|
</button>
|
||||||
<button class="ss-reset-button buy-btn ui-Shadow-Main" @tap="state.showSelectSku = true">
|
<button
|
||||||
|
class="ss-reset-button buy-btn ui-Shadow-Main"
|
||||||
|
@tap="state.showSelectSku = true"
|
||||||
|
>
|
||||||
立即购买
|
立即购买
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
|
@ -87,12 +128,19 @@
|
||||||
</detail-tabbar>
|
</detail-tabbar>
|
||||||
|
|
||||||
<!-- 优惠劵弹窗 -->
|
<!-- 优惠劵弹窗 -->
|
||||||
<s-coupon-get v-model="state.couponInfo" :show="state.showModel" @close="state.showModel = false"
|
<s-coupon-get
|
||||||
@get="onGet" />
|
v-model="state.couponInfo"
|
||||||
|
:show="state.showModel"
|
||||||
|
@close="state.showModel = false"
|
||||||
|
@get="onGet"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 满减送/限时折扣活动弹窗 -->
|
<!-- 满减送/限时折扣活动弹窗 -->
|
||||||
<s-activity-pop v-model="state.activityInfo" :show="state.showActivityModel"
|
<s-activity-pop
|
||||||
@close="state.showActivityModel = false" />
|
v-model="state.activityInfo"
|
||||||
|
:show="state.showActivityModel"
|
||||||
|
@close="state.showActivityModel = false"
|
||||||
|
/>
|
||||||
</block>
|
</block>
|
||||||
</s-layout>
|
</s-layout>
|
||||||
</view>
|
</view>
|
||||||
|
@ -128,7 +176,7 @@
|
||||||
showModel: false, // 是否展示 Coupon 优惠劵的弹窗
|
showModel: false, // 是否展示 Coupon 优惠劵的弹窗
|
||||||
couponInfo: [], // 可领取的 Coupon 优惠劵的列表
|
couponInfo: [], // 可领取的 Coupon 优惠劵的列表
|
||||||
showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
|
showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
|
||||||
activityInfo: [], // 【满减送/限时折扣】可参与的 Activity 营销活动的列表
|
activityInfo: [], // 【满减送/限时折扣】可参与的 Activity 营销活动的列表 TODO 芋艿:正在接入中
|
||||||
activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
|
activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -154,11 +202,13 @@
|
||||||
}
|
}
|
||||||
sheep.$router.go('/pages/order/confirm', {
|
sheep.$router.go('/pages/order/confirm', {
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
items: [{
|
items: [
|
||||||
|
{
|
||||||
skuId: e.id,
|
skuId: e.id,
|
||||||
count: e.goods_num,
|
count: e.goods_num,
|
||||||
categoryId: state.goodsInfo.categoryId
|
categoryId: state.goodsInfo.categoryId,
|
||||||
}]
|
},
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -184,7 +234,8 @@
|
||||||
|
|
||||||
const shareInfo = computed(() => {
|
const shareInfo = computed(() => {
|
||||||
if (isEmpty(state.goodsInfo)) return {};
|
if (isEmpty(state.goodsInfo)) return {};
|
||||||
return sheep.$platform.share.getShareInfo({
|
return sheep.$platform.share.getShareInfo(
|
||||||
|
{
|
||||||
title: state.goodsInfo.name,
|
title: state.goodsInfo.name,
|
||||||
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
image: sheep.$url.cdn(state.goodsInfo.picUrl),
|
||||||
desc: state.goodsInfo.introduction,
|
desc: state.goodsInfo.introduction,
|
||||||
|
@ -192,13 +243,15 @@
|
||||||
page: '2',
|
page: '2',
|
||||||
query: state.goodsInfo.id,
|
query: state.goodsInfo.id,
|
||||||
},
|
},
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
type: 'goods', // 商品海报
|
type: 'goods', // 商品海报
|
||||||
title: state.goodsInfo.name, // 商品名称
|
title: state.goodsInfo.name, // 商品名称
|
||||||
image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
|
image: sheep.$url.cdn(state.goodsInfo.picUrl), // 商品主图
|
||||||
price: fen2yuan(state.goodsInfo.price), // 商品价格
|
price: fen2yuan(state.goodsInfo.price), // 商品价格
|
||||||
original_price: fen2yuan(state.goodsInfo.marketPrice), // 商品原价
|
original_price: fen2yuan(state.goodsInfo.marketPrice), // 商品原价
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function getCoupon() {
|
async function getCoupon() {
|
||||||
|
@ -240,20 +293,12 @@
|
||||||
// 2. 加载优惠劵信息
|
// 2. 加载优惠劵信息
|
||||||
getCoupon();
|
getCoupon();
|
||||||
|
|
||||||
// 3. 加载营销活动信息
|
// 3. 获得单个商品,进行中的拼团、秒杀、砍价活动信息
|
||||||
ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
|
ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
|
||||||
if (res.code !== 0) {
|
if (res.code !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.data.forEach(activity => {
|
state.activityList = res.data;
|
||||||
if ([1, 2, 3].includes(activity.type)) { // 情况一:拼团/秒杀/砍价
|
|
||||||
state.activityList.push(activity);
|
|
||||||
} else if (activity.type === 5) { // 情况二:满减送
|
|
||||||
state.activityInfo.push(activity);
|
|
||||||
} else { // 情况三:限时折扣 TODO puhui999:【折扣】
|
|
||||||
console.log('待实现!优先级不高');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import request from '@/sheep/request';
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
const ActivityApi = {
|
const ActivityApi = {
|
||||||
// 获得单个商品,近期参与的每个活动
|
// 获得单个商品,进行中的拼团、秒杀、砍价活动信息
|
||||||
getActivityListBySpuId: (spuId) => {
|
getActivityListBySpuId: (spuId) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/promotion/activity/list-by-spu-id',
|
url: '/promotion/activity/list-by-spu-id',
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
:subTitleColor="data.fields.introduction.color"
|
:subTitleColor="data.fields.introduction.color"
|
||||||
:topRadius="data.borderRadiusTop"
|
:topRadius="data.borderRadiusTop"
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
@click="sheep.$router.go('/pages/goods/groupon', { id: item.activityId })"
|
@click="sheep.$router.go('/pages/goods/seckill', { id: item.activityId })"
|
||||||
>
|
>
|
||||||
<!-- 购买按钮 -->
|
<!-- 购买按钮 -->
|
||||||
<template v-slot:cart>
|
<template v-slot:cart>
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
:subTitleColor="data.fields.introduction.color"
|
:subTitleColor="data.fields.introduction.color"
|
||||||
:topRadius="data.borderRadiusTop"
|
:topRadius="data.borderRadiusTop"
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
@tap="sheep.$router.go('/pages/goods/groupon', { id: item.activityId })"
|
@tap="sheep.$router.go('/pages/goods/seckill', { id: item.activityId })"
|
||||||
>
|
>
|
||||||
<!-- 购买按钮 -->
|
<!-- 购买按钮 -->
|
||||||
<template v-slot:cart>
|
<template v-slot:cart>
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
:topRadius="data.borderRadiusTop"
|
:topRadius="data.borderRadiusTop"
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
:titleWidth="330 - marginLeft - marginRight"
|
:titleWidth="330 - marginLeft - marginRight"
|
||||||
@click="sheep.$router.go('/pages/goods/groupon', { id: item.activityId })"
|
@click="sheep.$router.go('/pages/goods/seckill', { id: item.activityId })"
|
||||||
@getHeight="calculateGoodsColumn($event, 'left')"
|
@getHeight="calculateGoodsColumn($event, 'left')"
|
||||||
>
|
>
|
||||||
<!-- 购买按钮 -->
|
<!-- 购买按钮 -->
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
:topRadius="data.borderRadiusTop"
|
:topRadius="data.borderRadiusTop"
|
||||||
:bottomRadius="data.borderRadiusBottom"
|
:bottomRadius="data.borderRadiusBottom"
|
||||||
:titleWidth="330 - marginLeft - marginRight"
|
:titleWidth="330 - marginLeft - marginRight"
|
||||||
@click="sheep.$router.go('/pages/goods/groupon', { id: item.activityId })"
|
@click="sheep.$router.go('/pages/goods/seckill', { id: item.activityId })"
|
||||||
@getHeight="calculateGoodsColumn($event, 'right')"
|
@getHeight="calculateGoodsColumn($event, 'right')"
|
||||||
>
|
>
|
||||||
<!-- 购买按钮 -->
|
<!-- 购买按钮 -->
|
||||||
|
|
Loading…
Reference in New Issue