【功能完善】商品列表,增加满减送提示(优化)
parent
9df0194aeb
commit
ff6769001d
|
@ -60,12 +60,14 @@
|
||||||
</s-layout>
|
</s-layout>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, toRaw, ref } from 'vue';
|
import { reactive } from 'vue';
|
||||||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
|
import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
|
import { appendSettlementProduct } from '@/sheep/hooks/useGoods';
|
||||||
|
import OrderApi from '@/sheep/api/trade/order';
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
activityId: 0, // 获得编号
|
activityId: 0, // 获得编号
|
||||||
|
@ -105,128 +107,36 @@
|
||||||
|
|
||||||
// 加载商品信息
|
// 加载商品信息
|
||||||
async function getList() {
|
async function getList() {
|
||||||
// state.loadStatus = 'loading';
|
|
||||||
// 处理拓展参数
|
// 处理拓展参数
|
||||||
const params = {};
|
const params = {};
|
||||||
if (state.activityInfo.productScope === 2) {
|
if (state.activityInfo.productScope === 2) {
|
||||||
// const params = toRaw(state.activityInfo.productScopeValues)
|
params.ids = state.activityInfo.productSpuIds.join(',');
|
||||||
// 请求数据
|
|
||||||
const { code, data } = await SpuApi.getSpuListByIds(
|
|
||||||
state.activityInfo.productScopeValues.join(','),
|
|
||||||
);
|
|
||||||
if (code !== 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 使用 map 提取每个对象的 id 属性
|
|
||||||
const ids = data.map((item) => item.id);
|
|
||||||
// 使用 join 方法将 id 数组连接成一个用逗号分隔的字符串
|
|
||||||
const idsString = ids.join(',');
|
|
||||||
// 获取结算信息
|
|
||||||
settleData.value = await getSettlementByIds(idsString);
|
|
||||||
// 处理获得的数据
|
|
||||||
const ms = enrichDataWithSkus(data, settleData.value);
|
|
||||||
state.pagination.list = ms;
|
|
||||||
// state.pagination.total = data.total;
|
|
||||||
// state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
|
|
||||||
} else if (state.activityInfo.productScope === 3) {
|
} else if (state.activityInfo.productScope === 3) {
|
||||||
params.categoryIds = state.activityInfo.productScopeValues.join(',');
|
params.categoryIds = state.activityInfo.productSpuIds.join(',');
|
||||||
state.loadStatus = 'loading';
|
|
||||||
const { code, data } = await SpuApi.getSpuPage({
|
|
||||||
pageNo: state.pagination.pageNo,
|
|
||||||
pageSize: state.pagination.pageSize,
|
|
||||||
...params,
|
|
||||||
});
|
|
||||||
if (code !== 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 使用 map 提取每个对象的 id 属性
|
|
||||||
const ids = data.list.map((item) => item.id);
|
|
||||||
// 使用 join 方法将 id 数组连接成一个用逗号分隔的字符串
|
|
||||||
const idsString = ids.join(',');
|
|
||||||
// 获取结算信息
|
|
||||||
settleData.value = await getSettlementByIds(idsString);
|
|
||||||
// 处理获得的数据
|
|
||||||
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';
|
|
||||||
} else {
|
|
||||||
state.loadStatus = 'loading';
|
|
||||||
const { code, data } = await SpuApi.getSpuPage({
|
|
||||||
pageNo: state.pagination.pageNo,
|
|
||||||
pageSize: state.pagination.pageSize,
|
|
||||||
});
|
|
||||||
if (code !== 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 使用 map 提取每个对象的 id 属性
|
|
||||||
const ids = data.list.map((item) => item.id);
|
|
||||||
// 使用 join 方法将 id 数组连接成一个用逗号分隔的字符串
|
|
||||||
const idsString = ids.join(',');
|
|
||||||
// 获取结算信息
|
|
||||||
settleData.value = await getSettlementByIds(idsString);
|
|
||||||
// 处理获得的数据
|
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
|
// 请求数据
|
||||||
|
state.loadStatus = 'loading';
|
||||||
|
const { code, data } = await SpuApi.getSpuPage({
|
||||||
|
pageNo: state.pagination.pageNo,
|
||||||
|
pageSize: state.pagination.pageSize,
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 拼接结算信息(营销)
|
||||||
|
await OrderApi.getSettlementProduct(data.list.map((item) => item.id).join(',')).then((res) => {
|
||||||
|
if (res.code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
appendSettlementProduct(data.list, res.data);
|
||||||
|
});
|
||||||
|
state.pagination.list = _.concat(state.pagination.list, data.list);
|
||||||
|
state.pagination.total = data.total;
|
||||||
|
state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
|
||||||
mountMasonry();
|
mountMasonry();
|
||||||
}
|
}
|
||||||
//获取结算信息
|
|
||||||
const settleData = ref();
|
|
||||||
async function getSettlementByIds(ids) {
|
|
||||||
const { data } = await SpuApi.getSettlementProduct(ids);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
//计算展示价格的函数
|
|
||||||
function enrichDataWithSkus(data, array) {
|
|
||||||
// 创建一个映射,以 id 为键,存储 data 数组中的对象
|
|
||||||
const dataMap = new Map(
|
|
||||||
data.map((item) => [
|
|
||||||
item.id,
|
|
||||||
{
|
|
||||||
...item,
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
|
|
||||||
// 遍历 array 数组
|
|
||||||
array.forEach((item) => {
|
|
||||||
// 初始化 discountPrice 和 vipPrice 为 null
|
|
||||||
let discountPrice = null;
|
|
||||||
let vipPrice = null;
|
|
||||||
let foundType4 = false;
|
|
||||||
let foundType6 = false;
|
|
||||||
|
|
||||||
// 遍历 skus 数组,寻找 type 为 4 和 6 的首个条目
|
|
||||||
item.skus.forEach((sku) => {
|
|
||||||
if (!foundType4 && sku.type === 4) {
|
|
||||||
discountPrice = sku.price;
|
|
||||||
foundType4 = true;
|
|
||||||
}
|
|
||||||
if (!foundType6 && sku.type === 6) {
|
|
||||||
vipPrice = sku.price;
|
|
||||||
foundType6 = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果已经找到 type 为 4 和 6 的条目,则不需要继续遍历
|
|
||||||
if (foundType4 && foundType6) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新 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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 返回更新后的数据数组
|
|
||||||
return Array.from(dataMap.values());
|
|
||||||
}
|
|
||||||
// 加载活动信息
|
// 加载活动信息
|
||||||
async function getActivity(id) {
|
async function getActivity(id) {
|
||||||
const { code, data } = await RewardActivityApi.getRewardActivity(id);
|
const { code, data } = await RewardActivityApi.getRewardActivity(id);
|
||||||
|
@ -252,32 +162,28 @@
|
||||||
onLoad(async (options) => {
|
onLoad(async (options) => {
|
||||||
state.activityId = options.activityId;
|
state.activityId = options.activityId;
|
||||||
await getActivity(state.activityId);
|
await getActivity(state.activityId);
|
||||||
await getList();
|
await getList(state.activityId);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.goods-list-box {
|
.goods-list-box {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
.left-list {
|
.left-list {
|
||||||
margin-right: 10rpx;
|
margin-right: 10rpx;
|
||||||
margin-bottom: 20rpx;
|
margin-bottom: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.right-list {
|
.right-list {
|
||||||
margin-left: 10rpx;
|
margin-left: 10rpx;
|
||||||
margin-bottom: 20rpx;
|
margin-bottom: 20rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tip-box {
|
.tip-box {
|
||||||
background: #fff0e7;
|
background: #fff0e7;
|
||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
.activity-left-image {
|
.activity-left-image {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
@ -285,7 +191,6 @@
|
||||||
width: 58rpx;
|
width: 58rpx;
|
||||||
height: 36rpx;
|
height: 36rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.activity-right-image {
|
.activity-right-image {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -293,14 +198,12 @@
|
||||||
width: 72rpx;
|
width: 72rpx;
|
||||||
height: 50rpx;
|
height: 50rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.type-text {
|
.type-text {
|
||||||
font-size: 26rpx;
|
font-size: 26rpx;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: #ff6000;
|
color: #ff6000;
|
||||||
line-height: 42rpx;
|
line-height: 42rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tip-content {
|
.tip-content {
|
||||||
font-size: 26rpx;
|
font-size: 26rpx;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
|
|
@ -217,6 +217,7 @@
|
||||||
|
|
||||||
onPageScroll(() => {});
|
onPageScroll(() => {});
|
||||||
import countDown from '@/sheep/components/countDown/index.vue';
|
import countDown from '@/sheep/components/countDown/index.vue';
|
||||||
|
import OrderApi from '@/sheep/api/trade/order';
|
||||||
|
|
||||||
const bgColor = {
|
const bgColor = {
|
||||||
bgColor: '#E93323',
|
bgColor: '#E93323',
|
||||||
|
@ -323,7 +324,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSettlementByIds(ids) {
|
async function getSettlementByIds(ids) {
|
||||||
let { data, code } = await SpuApi.getSettlementProduct(ids);
|
let { data, code } = await OrderApi.getSettlementProduct(ids);
|
||||||
if (code !== 0 || data.length !== 1) {
|
if (code !== 0 || data.length !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,8 @@
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import { resetPagination } from '@/sheep/util';
|
import { resetPagination } from '@/sheep/util';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
|
import OrderApi from '@/sheep/api/trade/order';
|
||||||
|
import { appendSettlementProduct } from '@/sheep/hooks/useGoods';
|
||||||
|
|
||||||
const sys_navBar = sheep.$platform.navbar;
|
const sys_navBar = sheep.$platform.navbar;
|
||||||
const emits = defineEmits(['close', 'change']);
|
const emits = defineEmits(['close', 'change']);
|
||||||
|
@ -277,15 +279,14 @@
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 使用 map 提取每个对象的 id 属性
|
// 拼接结算信息(营销)
|
||||||
const ids = data.list.map((item) => item.id);
|
await OrderApi.getSettlementProduct(data.list.map((item) => item.id).join(',')).then((res) => {
|
||||||
// 使用 join 方法将 id 数组连接成一个用逗号分隔的字符串
|
if (res.code !== 0) {
|
||||||
const idsString = ids.join(',');
|
return;
|
||||||
// 获取结算信息
|
}
|
||||||
settleData.value = await getSettlementByIds(idsString);
|
appendSettlementProduct(data.list, res.data);
|
||||||
// 处理获得的数据
|
});
|
||||||
const ms = enrichDataWithSkus(data.list, settleData.value);
|
state.pagination.list = _.concat(state.pagination.list, data.list);
|
||||||
state.pagination.list = _.concat(state.pagination.list, ms);
|
|
||||||
state.pagination.total = data.total;
|
state.pagination.total = data.total;
|
||||||
state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
|
state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
|
||||||
mountMasonry();
|
mountMasonry();
|
||||||
|
@ -300,57 +301,6 @@
|
||||||
getList(state.currentSort, state.currentOrder);
|
getList(state.currentSort, state.currentOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取结算信息
|
|
||||||
const settleData = ref();
|
|
||||||
async function getSettlementByIds(ids) {
|
|
||||||
const { data } = await SpuApi.getSettlementProduct(ids);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
//计算展示价格的函数
|
|
||||||
function enrichDataWithSkus(data, array) {
|
|
||||||
// 创建一个映射,以 id 为键,存储 data 数组中的对象
|
|
||||||
const dataMap = new Map(data.map((item) => [item.id, { ...item }]));
|
|
||||||
|
|
||||||
// 遍历 array 数组
|
|
||||||
array.forEach((item) => {
|
|
||||||
// 初始化 discountPrice 和 vipPrice 为 null
|
|
||||||
let discountPrice = null;
|
|
||||||
let vipPrice = null;
|
|
||||||
let foundType4 = false;
|
|
||||||
let foundType6 = false;
|
|
||||||
|
|
||||||
// 遍历 skus 数组,寻找 type 为 4 和 6 的首个条目
|
|
||||||
item.skus.forEach((sku) => {
|
|
||||||
debugger;
|
|
||||||
if (!foundType4 && sku.promotionType === 4) {
|
|
||||||
discountPrice = sku.payPrice;
|
|
||||||
foundType4 = true;
|
|
||||||
}
|
|
||||||
if (!foundType6 && sku.promotionType === 6) {
|
|
||||||
vipPrice = sku.payPrice;
|
|
||||||
foundType6 = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果已经找到 type 为 4 和 6 的条目,则不需要继续遍历
|
|
||||||
if (foundType4 && foundType6) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新 dataMap 中对应的对象
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 返回更新后的数据数组
|
|
||||||
return Array.from(dataMap.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
state.categoryId = options.categoryId;
|
state.categoryId = options.categoryId;
|
||||||
state.keyword = options.keyword;
|
state.keyword = options.keyword;
|
||||||
|
|
|
@ -53,6 +53,18 @@ const OrderApi = {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// 获得商品结算信息
|
||||||
|
getSettlementProduct: (spuIds) => {
|
||||||
|
return request({
|
||||||
|
url: '/trade/order/settlement-product',
|
||||||
|
method: 'GET',
|
||||||
|
params: { spuIds },
|
||||||
|
custom: {
|
||||||
|
showLoading: false,
|
||||||
|
showError: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
// 创建订单
|
// 创建订单
|
||||||
createOrder: (data) => {
|
createOrder: (data) => {
|
||||||
return request({
|
return request({
|
||||||
|
|
|
@ -141,9 +141,11 @@
|
||||||
/**
|
/**
|
||||||
* 商品卡片
|
* 商品卡片
|
||||||
*/
|
*/
|
||||||
import { computed, reactive, onMounted, ref } from 'vue';
|
import { computed, reactive, onMounted } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
|
import OrderApi from '@/sheep/api/trade/order';
|
||||||
|
import { appendSettlementProduct } from '@/sheep/hooks/useGoods';
|
||||||
|
|
||||||
// 布局类型
|
// 布局类型
|
||||||
const LayoutTypeEnum = {
|
const LayoutTypeEnum = {
|
||||||
|
@ -234,61 +236,19 @@
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取结算信息
|
|
||||||
const settleData = ref()
|
|
||||||
async function getSettlementByIds(ids) {
|
|
||||||
const { data } = await SpuApi.getSettlementProduct(ids);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
//计算展示价格的函数
|
|
||||||
async function enrichDataWithSkus(data, array) {
|
|
||||||
// 创建一个映射,以 id 为键,存储 data 数组中的对象
|
|
||||||
const dataMap = new Map(data.map(item => [item.id, { ...item }]));
|
|
||||||
|
|
||||||
// 遍历 array 数组
|
|
||||||
array.forEach(item => {
|
|
||||||
// 初始化 discountPrice 和 vipPrice 为 null
|
|
||||||
let discountPrice = null;
|
|
||||||
let vipPrice = null;
|
|
||||||
let foundType4 = false;
|
|
||||||
let foundType6 = false;
|
|
||||||
|
|
||||||
// 遍历 skus 数组,寻找 type 为 4 和 6 的首个条目
|
|
||||||
item.skus.forEach(sku => {
|
|
||||||
if (!foundType4 && sku.type === 4) {
|
|
||||||
discountPrice = sku.price;
|
|
||||||
foundType4 = true;
|
|
||||||
}
|
|
||||||
if (!foundType6 && sku.type === 6) {
|
|
||||||
vipPrice = sku.price;
|
|
||||||
foundType6 = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果已经找到 type 为 4 和 6 的条目,则不需要继续遍历
|
|
||||||
if (foundType4 && foundType6) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新 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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 返回更新后的数据数组
|
|
||||||
return Array.from(dataMap.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 加载商品列表
|
// 加载商品列表
|
||||||
const ms = await getGoodsListByIds(spuIds.join(','));
|
state.goodsList = await getGoodsListByIds(spuIds.join(','));
|
||||||
settleData.value = await getSettlementByIds(spuIds.join(','))
|
// 拼接结算信息(营销)
|
||||||
state.goodsList = await enrichDataWithSkus(ms,settleData.value)
|
await OrderApi.getSettlementProduct(state.goodsList.map((item) => item.id).join(',')).then(
|
||||||
|
(res) => {
|
||||||
|
if (res.code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
appendSettlementProduct(state.goodsList, res.data);
|
||||||
|
},
|
||||||
|
);
|
||||||
// 只有双列布局时需要
|
// 只有双列布局时需要
|
||||||
if (layoutType === LayoutTypeEnum.TWO_COL) {
|
if (layoutType === LayoutTypeEnum.TWO_COL) {
|
||||||
// 分列
|
// 分列
|
||||||
|
|
|
@ -11,11 +11,7 @@
|
||||||
<view v-if="tagStyle.show" class="tag-icon-box">
|
<view v-if="tagStyle.show" class="tag-icon-box">
|
||||||
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
|
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
|
||||||
</view>
|
</view>
|
||||||
<image
|
<image class="xs-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="aspectFit" />
|
||||||
class="xs-img-box"
|
|
||||||
:src="sheep.$url.cdn(data.image || data.picUrl)"
|
|
||||||
mode="aspectFit"
|
|
||||||
></image>
|
|
||||||
<view
|
<view
|
||||||
v-if="goodsFields.title?.show || goodsFields.name?.show || goodsFields.price?.show"
|
v-if="goodsFields.title?.show || goodsFields.name?.show || goodsFields.price?.show"
|
||||||
class="xs-goods-content ss-flex-col ss-row-around"
|
class="xs-goods-content ss-flex-col ss-row-around"
|
||||||
|
@ -27,23 +23,24 @@
|
||||||
>
|
>
|
||||||
{{ data.title || data.name }}
|
{{ data.title || data.name }}
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里是新加的会员价和限时优惠 -->
|
<!-- 活动信息 -->
|
||||||
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
|
<view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
|
||||||
<view class="card" v-if="iconShow">{{ iconShow }}</view>
|
<view class="card" v-if="discountText">{{ discountText }}</view>
|
||||||
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
|
<view class="card2" v-if="data.rewardActivity">
|
||||||
|
{{ data.rewardActivity.ruleDescriptions[0] }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里是新加的会员价和限时优惠结束 -->
|
|
||||||
<view
|
<view
|
||||||
v-if="goodsFields.price?.show"
|
v-if="goodsFields.price?.show"
|
||||||
class="xs-goods-price font-OPPOSANS"
|
class="xs-goods-price font-OPPOSANS"
|
||||||
:style="[{ color: goodsFields.price.color }]"
|
:style="[{ color: goodsFields.price.color }]"
|
||||||
>
|
>
|
||||||
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
||||||
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
|
<!-- 活动价格 -->
|
||||||
<text v-else-if="iconShow == '会员价'">{{ fen2yuan(data.vipPrice) }}</text>
|
<text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
|
||||||
<text v-else>{{
|
<text v-else>
|
||||||
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
|
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
|
||||||
}}</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -70,23 +67,24 @@
|
||||||
>
|
>
|
||||||
{{ data.title || data.name }}
|
{{ data.title || data.name }}
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里是新加的会员价和限时优惠 -->
|
<!-- 活动信息 -->
|
||||||
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
|
<view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
|
||||||
<view class="card" v-if="iconShow">{{ iconShow }}</view>
|
<view class="card" v-if="discountText">{{ discountText }}</view>
|
||||||
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
|
<view class="card2" v-if="data.rewardActivity">
|
||||||
|
{{ data.rewardActivity.ruleDescriptions[0] }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里是新加的会员价和限时优惠结束 -->
|
|
||||||
<view
|
<view
|
||||||
v-if="goodsFields.price?.show"
|
v-if="goodsFields.price?.show"
|
||||||
class="sm-goods-price font-OPPOSANS"
|
class="sm-goods-price font-OPPOSANS"
|
||||||
:style="[{ color: goodsFields.price.color }]"
|
:style="[{ color: goodsFields.price.color }]"
|
||||||
>
|
>
|
||||||
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
||||||
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
|
<!-- 活动价格 -->
|
||||||
<text v-else-if="iconShow == '会员价'">{{ fen2yuan(data.vipPrice) }}</text>
|
<text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
|
||||||
<text v-else>{{
|
<text v-else>
|
||||||
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
|
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
|
||||||
}}</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -94,13 +92,9 @@
|
||||||
<!-- md卡片:竖向,一行放两个,图上内容下 -->
|
<!-- md卡片:竖向,一行放两个,图上内容下 -->
|
||||||
<view v-if="size === 'md'" class="md-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
|
<view v-if="size === 'md'" class="md-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
|
||||||
<view v-if="tagStyle.show" class="tag-icon-box">
|
<view v-if="tagStyle.show" class="tag-icon-box">
|
||||||
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
|
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)" />
|
||||||
</view>
|
</view>
|
||||||
<image
|
<image class="md-img-box" :src="sheep.$url.cdn(data.image || data.picUrl)" mode="widthFix" />
|
||||||
class="md-img-box"
|
|
||||||
:src="sheep.$url.cdn(data.image || data.picUrl)"
|
|
||||||
mode="widthFix"
|
|
||||||
></image>
|
|
||||||
<view
|
<view
|
||||||
class="md-goods-content ss-flex-col ss-row-around ss-p-b-20 ss-p-t-20 ss-p-x-16"
|
class="md-goods-content ss-flex-col ss-row-around ss-p-b-20 ss-p-t-20 ss-p-x-16"
|
||||||
:id="elId"
|
:id="elId"
|
||||||
|
@ -130,12 +124,13 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</slot>
|
</slot>
|
||||||
<!-- 这里是新加的会员价和限时优惠 -->
|
<!-- 活动信息 -->
|
||||||
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
|
<view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
|
||||||
<view class="card" v-if="iconShow">{{ iconShow }}</view>
|
<view class="card" v-if="discountText">{{ discountText }}</view>
|
||||||
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
|
<view class="card2" v-if="data.rewardActivity">
|
||||||
|
{{ data.rewardActivity.ruleDescriptions[0] }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里是新加的会员价和限时优惠结束 -->
|
|
||||||
<view class="ss-flex ss-col-bottom">
|
<view class="ss-flex ss-col-bottom">
|
||||||
<view
|
<view
|
||||||
v-if="goodsFields.price?.show"
|
v-if="goodsFields.price?.show"
|
||||||
|
@ -143,13 +138,12 @@
|
||||||
:style="[{ color: goodsFields.price.color }]"
|
:style="[{ color: goodsFields.price.color }]"
|
||||||
>
|
>
|
||||||
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
||||||
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
|
<!-- 活动价格 -->
|
||||||
<text v-else-if="iconShow == '会员价'">{{ fen2yuan(data.vipPrice) }}</text>
|
<text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
|
||||||
<text v-else>{{
|
<text v-else>
|
||||||
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
|
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
|
||||||
}}</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view
|
<view
|
||||||
v-if="
|
v-if="
|
||||||
(goodsFields.original_price?.show || goodsFields.marketPrice?.show) &&
|
(goodsFields.original_price?.show || goodsFields.marketPrice?.show) &&
|
||||||
|
@ -193,7 +187,7 @@
|
||||||
class="lg-img-box"
|
class="lg-img-box"
|
||||||
:src="sheep.$url.cdn(data.image || data.picUrl)"
|
:src="sheep.$url.cdn(data.image || data.picUrl)"
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
></image>
|
/>
|
||||||
<view class="lg-goods-content ss-flex-1 ss-flex-col ss-row-between ss-p-b-10 ss-p-t-20">
|
<view class="lg-goods-content ss-flex-1 ss-flex-col ss-row-between ss-p-b-10 ss-p-t-20">
|
||||||
<view>
|
<view>
|
||||||
<view
|
<view
|
||||||
|
@ -219,12 +213,13 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</slot>
|
</slot>
|
||||||
<!-- 这里是新加的会员价和限时优惠 -->
|
<!-- 活动信息 -->
|
||||||
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
|
<view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
|
||||||
<view class="card" v-if="iconShow">{{ iconShow }}</view>
|
<view class="card" v-if="discountText">{{ discountText }}</view>
|
||||||
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
|
<view class="card2" v-if="data.rewardActivity">
|
||||||
|
{{ data.rewardActivity.ruleDescriptions[0] }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里是新加的会员价和限时优惠结束 -->
|
|
||||||
<view class="ss-flex ss-col-bottom ss-m-t-10">
|
<view class="ss-flex ss-col-bottom ss-m-t-10">
|
||||||
<view
|
<view
|
||||||
v-if="goodsFields.price?.show"
|
v-if="goodsFields.price?.show"
|
||||||
|
@ -243,11 +238,11 @@
|
||||||
:style="[{ color: originPriceColor }]"
|
:style="[{ color: originPriceColor }]"
|
||||||
>
|
>
|
||||||
<text class="price-unit ss-font-20">{{ priceUnit }}</text>
|
<text class="price-unit ss-font-20">{{ priceUnit }}</text>
|
||||||
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
|
<!-- 活动价格 -->
|
||||||
<text v-else-if="iconShow == '会员价'">{{ fen2yuan(data.vipPrice) }}</text>
|
<text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
|
||||||
<text v-else>{{
|
<text v-else>
|
||||||
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
|
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
|
||||||
}}</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="ss-m-t-8 ss-flex ss-col-center ss-flex-wrap">
|
<view class="ss-m-t-8 ss-flex ss-col-center ss-flex-wrap">
|
||||||
|
@ -264,15 +259,13 @@
|
||||||
<!-- sl卡片:竖向型,一行放一个,图片上内容下边 -->
|
<!-- sl卡片:竖向型,一行放一个,图片上内容下边 -->
|
||||||
<view v-if="size === 'sl'" class="sl-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
|
<view v-if="size === 'sl'" class="sl-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
|
||||||
<view v-if="tagStyle.show" class="tag-icon-box">
|
<view v-if="tagStyle.show" class="tag-icon-box">
|
||||||
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)"></image>
|
<image class="tag-icon" :src="sheep.$url.cdn(tagStyle.src || tagStyle.imgUrl)" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<image
|
<image
|
||||||
class="sl-img-box"
|
class="sl-img-box"
|
||||||
:src="sheep.$url.cdn(data.image || data.picUrl)"
|
:src="sheep.$url.cdn(data.image || data.picUrl)"
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
></image>
|
/>
|
||||||
|
|
||||||
<view class="sl-goods-content">
|
<view class="sl-goods-content">
|
||||||
<view>
|
<view>
|
||||||
<view
|
<view
|
||||||
|
@ -302,20 +295,21 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</slot>
|
</slot>
|
||||||
<!-- 这里是新加的会员价和限时优惠 -->
|
<!-- 活动信息 -->
|
||||||
<view class="iconBox" v-if="data.discountPrice || data.vipPrice || data.reward">
|
<view class="iconBox" v-if="data.promotionType > 0 || data.rewardActivity">
|
||||||
<view class="card" v-if="iconShow">{{ iconShow }}</view>
|
<view class="card" v-if="discountText">{{ discountText }}</view>
|
||||||
<view class="card2" v-if="data.reward">{{ data.reward.ruleDescriptions[0] }}</view>
|
<view class="card2" v-if="data.rewardActivity">
|
||||||
|
{{ data.rewardActivity.ruleDescriptions[0] }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里是新加的会员价和限时优惠结束 -->
|
|
||||||
<view v-if="goodsFields.price?.show" class="ss-flex ss-col-bottom font-OPPOSANS">
|
<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 }]">
|
<view class="sl-goods-price ss-m-r-12" :style="[{ color: goodsFields.price.color }]">
|
||||||
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
<text class="price-unit ss-font-24">{{ priceUnit }}</text>
|
||||||
<text v-if="iconShow == '限时优惠'">{{ fen2yuan(data.discountPrice) }}</text>
|
<!-- 活动价格 -->
|
||||||
<text v-else-if="iconShow == '会员价'">{{ fen2yuan(data.vipPrice) }}</text>
|
<text v-if="data.promotionPrice > 0">{{ fen2yuan(data.promotionPrice) }}</text>
|
||||||
<text v-else>{{
|
<text v-else>
|
||||||
isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price)
|
{{ isArray(data.price) ? fen2yuan(data.price[0]) : fen2yuan(data.price) }}
|
||||||
}}</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
v-if="
|
v-if="
|
||||||
|
@ -371,14 +365,11 @@
|
||||||
* @event {Function()} click - 点击卡片
|
* @event {Function()} click - 点击卡片
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { computed, reactive, getCurrentInstance, onMounted, nextTick, ref } from 'vue';
|
import { computed, getCurrentInstance, onMounted, nextTick } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { fen2yuan, formatSales } from '@/sheep/hooks/useGoods';
|
import { fen2yuan, formatSales } from '@/sheep/hooks/useGoods';
|
||||||
import { formatStock } from '@/sheep/hooks/useGoods';
|
import { formatStock } from '@/sheep/hooks/useGoods';
|
||||||
import goodsCollectVue from '@/pages/user/goods-collect.vue';
|
|
||||||
import { isArray } from 'lodash-es';
|
import { isArray } from 'lodash-es';
|
||||||
// 数据
|
|
||||||
const state = reactive({});
|
|
||||||
|
|
||||||
// 接收参数
|
// 接收参数
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
@ -478,25 +469,18 @@
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
//判断限时优惠和会员价标签内容暂时导致页面出错,又舍不得丢,等着把新的数据整合到商品信息中,也用起来
|
|
||||||
const iconShow = handle();
|
|
||||||
|
|
||||||
function handle() {
|
// 优惠文案
|
||||||
if (props.data.discountPrice === null && props.data.vipPrice === null) {
|
const discountText = computed(() => {
|
||||||
// 如果两个值都为 null,则不展示任何内容
|
const promotionType = props.data.promotionType;
|
||||||
return '';
|
if (promotionType === 4) {
|
||||||
} else if (props.data.discountPrice === null) {
|
|
||||||
// 如果 discountPrice 为 null,展示 vipPrice
|
|
||||||
return '会员价';
|
|
||||||
} else if (props.data.vipPrice === null) {
|
|
||||||
// 如果 vipPrice 为 null,展示 discountPrice
|
|
||||||
return '限时优惠';
|
return '限时优惠';
|
||||||
} else if (props.data.discountPrice < props.data.vipPrice) {
|
} else if (promotionType === 6) {
|
||||||
return '限时优惠';
|
|
||||||
} else if (props.data.discountPrice > props.data.vipPrice) {
|
|
||||||
return '会员价';
|
return '会员价';
|
||||||
}
|
}
|
||||||
}
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
// 组件样式
|
// 组件样式
|
||||||
const elStyles = computed(() => {
|
const elStyles = computed(() => {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -382,3 +382,27 @@ export function convertProductPropertyList(skus) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function appendSettlementProduct(spus, settlementInfos) {
|
||||||
|
if (!settlementInfos || settlementInfos.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const spu of spus) {
|
||||||
|
const settlementInfo = settlementInfos.find((info) => info.spuId === spu.id);
|
||||||
|
if (!settlementInfo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 选择价格最小的 SKU 设置到 SPU 上
|
||||||
|
const settlementSku = settlementInfo.skus
|
||||||
|
.filter((sku) => sku.promotionPrice > 0)
|
||||||
|
.reduce((prev, curr) => (prev.promotionPrice < curr.promotionPrice ? prev : curr));
|
||||||
|
if (settlementSku) {
|
||||||
|
spu.promotionType = settlementSku.promotionType;
|
||||||
|
spu.promotionPrice = settlementSku.promotionPrice;
|
||||||
|
}
|
||||||
|
// 设置【满减送】活动
|
||||||
|
if (settlementInfo.rewardActivity) {
|
||||||
|
spu.rewardActivity = settlementInfo.rewardActivity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue