2023-12-27 10:52:17 +00:00
|
|
|
|
<!-- 分销商品列表 -->
|
2023-12-13 03:35:02 +00:00
|
|
|
|
<template>
|
2023-12-27 10:52:17 +00:00
|
|
|
|
<s-layout title="推广商品" :onShareAppMessage="state.shareInfo">
|
|
|
|
|
<view class="goods-item ss-m-20" v-for="item in state.pagination.list" :key="item.id">
|
|
|
|
|
<s-goods-item
|
|
|
|
|
size="lg"
|
|
|
|
|
:img="item.picUrl"
|
|
|
|
|
:title="item.name"
|
|
|
|
|
:subTitle="item.introduction"
|
|
|
|
|
:price="item.price"
|
|
|
|
|
:originPrice="item.marketPrice"
|
|
|
|
|
priceColor="#333"
|
|
|
|
|
@tap="sheep.$router.go('/pages/goods/index', { id: item.id })"
|
|
|
|
|
>
|
|
|
|
|
<template #rightBottom>
|
|
|
|
|
<view class="ss-flex ss-row-between">
|
2024-08-04 09:11:12 +00:00
|
|
|
|
<view class="commission-num" v-if="item.brokerageMinPrice === undefined"
|
|
|
|
|
>预计佣金:计算中</view
|
|
|
|
|
>
|
|
|
|
|
<view
|
|
|
|
|
class="commission-num"
|
|
|
|
|
v-else-if="item.brokerageMinPrice === item.brokerageMaxPrice"
|
|
|
|
|
>
|
2023-12-27 10:52:17 +00:00
|
|
|
|
预计佣金:{{ fen2yuan(item.brokerageMinPrice) }}
|
|
|
|
|
</view>
|
|
|
|
|
<view class="commission-num" v-else>
|
2024-08-04 09:11:12 +00:00
|
|
|
|
预计佣金:{{ fen2yuan(item.brokerageMinPrice) }} ~
|
|
|
|
|
{{ fen2yuan(item.brokerageMaxPrice) }}
|
2023-12-27 10:52:17 +00:00
|
|
|
|
</view>
|
|
|
|
|
<button
|
|
|
|
|
class="ss-reset-button share-btn ui-BG-Main-Gradient"
|
|
|
|
|
@tap.stop="onShareGoods(item)"
|
|
|
|
|
>
|
|
|
|
|
分享赚
|
|
|
|
|
</button>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
</s-goods-item>
|
|
|
|
|
</view>
|
|
|
|
|
<s-empty
|
|
|
|
|
v-if="state.pagination.total === 0"
|
|
|
|
|
icon="/static/goods-empty.png"
|
|
|
|
|
text="暂无推广商品"
|
|
|
|
|
/>
|
|
|
|
|
<!-- 加载更多 -->
|
|
|
|
|
<uni-load-more
|
|
|
|
|
v-if="state.pagination.total > 0"
|
|
|
|
|
:status="state.loadStatus"
|
|
|
|
|
:content-text="{
|
2023-12-13 03:35:02 +00:00
|
|
|
|
contentdown: '上拉加载更多',
|
2023-12-27 10:52:17 +00:00
|
|
|
|
}"
|
|
|
|
|
@tap="loadMore"
|
|
|
|
|
/>
|
|
|
|
|
</s-layout>
|
2023-12-13 03:35:02 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2023-12-27 10:52:17 +00:00
|
|
|
|
import sheep from '@/sheep';
|
|
|
|
|
import $share from '@/sheep/platform/share';
|
|
|
|
|
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
|
|
|
|
import { reactive } from 'vue';
|
2024-08-04 09:11:12 +00:00
|
|
|
|
import _ from 'lodash-es';
|
2023-12-27 10:52:17 +00:00
|
|
|
|
import { showShareModal } from '@/sheep/hooks/useModal';
|
|
|
|
|
import SpuApi from '@/sheep/api/product/spu';
|
|
|
|
|
import BrokerageApi from '@/sheep/api/trade/brokerage';
|
2024-11-07 09:00:56 +00:00
|
|
|
|
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
2023-12-13 03:35:02 +00:00
|
|
|
|
|
2023-12-27 10:52:17 +00:00
|
|
|
|
const state = reactive({
|
|
|
|
|
pagination: {
|
|
|
|
|
list: [],
|
|
|
|
|
total: 0,
|
|
|
|
|
pageNo: 1,
|
2024-10-12 12:23:26 +00:00
|
|
|
|
pageSize: 8,
|
2023-12-27 10:52:17 +00:00
|
|
|
|
},
|
|
|
|
|
loadStatus: '',
|
|
|
|
|
shareInfo: {},
|
|
|
|
|
});
|
2023-12-13 03:35:02 +00:00
|
|
|
|
|
2023-12-27 10:52:17 +00:00
|
|
|
|
function onShareGoods(goodsInfo) {
|
|
|
|
|
state.shareInfo = $share.getShareInfo(
|
|
|
|
|
{
|
2024-11-29 03:10:37 +00:00
|
|
|
|
title: goodsInfo.name,
|
|
|
|
|
image: sheep.$url.cdn(goodsInfo.picUrl),
|
|
|
|
|
desc: goodsInfo.introduction,
|
2023-12-27 10:52:17 +00:00
|
|
|
|
params: {
|
|
|
|
|
page: '2',
|
|
|
|
|
query: goodsInfo.id,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'goods', // 商品海报
|
2024-11-29 03:10:37 +00:00
|
|
|
|
title: goodsInfo.name, // 商品名称
|
|
|
|
|
image: sheep.$url.cdn(goodsInfo.picUrl), // 商品主图
|
|
|
|
|
price: fen2yuan(goodsInfo.price), // 商品价格
|
|
|
|
|
original_price: fen2yuan(goodsInfo.marketPrice), // 商品原价
|
2023-12-27 10:52:17 +00:00
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
showShareModal();
|
|
|
|
|
}
|
2023-12-13 03:35:02 +00:00
|
|
|
|
|
2023-12-27 10:52:17 +00:00
|
|
|
|
async function getGoodsList() {
|
|
|
|
|
state.loadStatus = 'loading';
|
|
|
|
|
let { code, data } = await SpuApi.getSpuPage({
|
|
|
|
|
pageSize: state.pagination.pageSize,
|
|
|
|
|
pageNo: state.pagination.pageNo,
|
|
|
|
|
});
|
2024-11-07 09:00:56 +00:00
|
|
|
|
|
2023-12-27 10:52:17 +00:00
|
|
|
|
if (code !== 0) {
|
2024-11-07 09:00:56 +00:00
|
|
|
|
state.loadStatus = 'error'; // 处理错误状态
|
2023-12-27 10:52:17 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-11-07 09:00:56 +00:00
|
|
|
|
|
|
|
|
|
// 使用 Promise.all 来等待所有佣金请求完成
|
|
|
|
|
await Promise.all(
|
|
|
|
|
data.list.map(async (item) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await BrokerageApi.getProductBrokeragePrice(item.id);
|
|
|
|
|
item.brokerageMinPrice = res.data.brokerageMinPrice;
|
|
|
|
|
item.brokerageMaxPrice = res.data.brokerageMaxPrice;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`获取商品【${item.name}】的佣金时出错:`, error);
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 在所有请求完成后合并列表和更新状态
|
2023-12-27 10:52:17 +00:00
|
|
|
|
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';
|
|
|
|
|
}
|
2023-12-13 03:35:02 +00:00
|
|
|
|
|
2023-12-27 10:52:17 +00:00
|
|
|
|
onLoad(() => {
|
|
|
|
|
getGoodsList();
|
|
|
|
|
});
|
2023-12-13 03:35:02 +00:00
|
|
|
|
|
2023-12-27 10:52:17 +00:00
|
|
|
|
// 加载更多
|
|
|
|
|
function loadMore() {
|
|
|
|
|
if (state.loadStatus === 'noMore') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
state.pagination.pageNo++;
|
|
|
|
|
getGoodsList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 上拉加载更多
|
|
|
|
|
onReachBottom(() => {
|
|
|
|
|
loadMore();
|
|
|
|
|
});
|
2023-12-13 03:35:02 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-12-27 10:52:17 +00:00
|
|
|
|
.goods-item {
|
|
|
|
|
.commission-num {
|
|
|
|
|
font-size: 24rpx;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
color: $red;
|
|
|
|
|
}
|
2023-12-13 03:35:02 +00:00
|
|
|
|
|
2023-12-27 10:52:17 +00:00
|
|
|
|
.share-btn {
|
|
|
|
|
width: 120rpx;
|
|
|
|
|
height: 50rpx;
|
|
|
|
|
border-radius: 25rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|