指定满减送的活动列表:100%

pull/36/MERGE
YunaiV 2024-01-06 20:40:39 +08:00
parent eb9138a668
commit b95e711f80
5 changed files with 116 additions and 65 deletions

View File

@ -1,11 +1,13 @@
<!-- 指定满减送的活动列表 -->
<template>
<s-layout class="activity-wrap" :title="state.activityInfo.title">
<!-- 活动信息 -->
<su-sticky bgColor="#fff">
<view class="ss-flex ss-col-top tip-box">
<view class="type-text ss-flex ss-row-center">{{ state.activityInfo.type_text }}</view>
<view class="type-text ss-flex ss-row-center">满减</view>
<view class="ss-flex-1">
<view class="tip-content" v-for="item in state.activityInfo.texts" :key="item">
{{ item }}
<view class="tip-content" v-for="item in state.activityInfo.rules" :key="item">
{{ formatRewardActivityRule(state.activityInfo, item) }}
</view>
</view>
<image class="activity-left-image" src="/static/activity-left.png" />
@ -13,6 +15,7 @@
</view>
</su-sticky>
<!-- 商品信息 -->
<view class="ss-flex ss-flex-wrap ss-p-x-20 ss-m-t-20 ss-col-top">
<view class="goods-list-box">
<view class="left-list" v-for="item in state.leftGoodsList" :key="item.id">
@ -39,7 +42,7 @@
@getHeight="mountMasonry($event, 'right')"
>
<template v-slot:cart>
<button class="ss-reset-button cart-btn"> </button>
<button class="ss-reset-button cart-btn" />
</template>
</s-goods-column>
</view>
@ -52,7 +55,7 @@
:content-text="{
contentdown: '上拉加载更多',
}"
@tap="loadmore"
@tap="loadMore"
/>
</s-layout>
</template>
@ -61,27 +64,32 @@
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import _ from 'lodash';
import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
import { formatRewardActivityRule } from '@/sheep/hooks/useGoods';
import SpuApi from '@/sheep/api/product/spu';
const state = reactive({
activityId: 0, //
activityInfo: {}, //
pagination: {
data: [],
current_page: 1,
list: [],
total: 1,
last_page: 1,
pageNo: 1,
pageSize: 8,
},
loadStatus: '',
leftGoodsList: [],
rightGoodsList: [],
activityId: 0,
activityInfo: {},
});
//
let count = 0;
let leftHeight = 0;
let rightHeight = 0;
function mountMasonry(height = 0, where = 'left') {
if (!state.pagination.data[count]) return;
if (!state.pagination.list[count]) return;
if (where === 'left') {
leftHeight += height;
@ -89,57 +97,64 @@
rightHeight += height;
}
if (leftHeight <= rightHeight) {
state.leftGoodsList.push(state.pagination.data[count]);
state.leftGoodsList.push(state.pagination.list[count]);
} else {
state.rightGoodsList.push(state.pagination.data[count]);
state.rightGoodsList.push(state.pagination.list[count]);
}
count++;
}
async function getList(activityId, page = 1, list_rows = 6) {
state.loadStatus = 'loading';
const res = await sheep.$api.goods.activityList({
list_rows,
activity_id: activityId,
page,
});
if (res.error === 0) {
if (page >= 2) {
let couponList = _.concat(state.pagination.data, res.data.data);
state.pagination = {
...res.data,
data: couponList,
};
} else {
state.pagination = res.data;
}
mountMasonry();
if (state.pagination.current_page < state.pagination.last_page) {
state.loadStatus = 'more';
} else {
state.loadStatus = 'noMore';
}
//
async function getList() {
//
const params = {};
if (state.activityInfo.productScope === 2) {
params.ids = state.activityInfo.productSpuIds.join(',');
} else if (state.activityInfo.productScope === 3) {
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;
}
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();
}
//
async function getActivity(id) {
const { error, data } = await sheep.$api.activity.activity(id);
if (error === 0) {
const { code, data } = await RewardActivityApi.getRewardActivity(id);
if (code === 0) {
state.activityInfo = data;
}
}
//
function loadmore() {
if (state.loadStatus !== 'noMore') {
getList(state.activityId, state.pagination.current_page + 1);
function loadMore() {
if (state.loadStatus === 'noMore') {
return;
}
state.pagination.pageNo++;
getList();
}
//
onReachBottom(() => {
loadmore();
loadMore();
});
onLoad((options) => {
onLoad(async (options) => {
state.activityId = options.activityId;
getList(state.activityId);
getActivity(state.activityId);
await getActivity(state.activityId);
await getList(state.activityId);
});
</script>
<style lang="scss" scoped>

View File

@ -38,17 +38,6 @@ export default {
},
}),
// 商品评价列表
comment: (id, params = {}) =>
request2({
url: 'product/comment/list?spuId=' + id,
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品查询
activity: (params = {}) =>
request({

View File

@ -0,0 +1,14 @@
import request from '@/sheep/request';
const RewardActivityApi = {
// 获得满减送活动
getRewardActivity: (id) => {
return request({
url: '/app-api/promotion/reward-activity/get',
method: 'GET',
params: { id },
});
}
};
export default RewardActivityApi;

View File

@ -12,15 +12,9 @@
<view v-for="item in state.activityInfo" :key="item.id">
<view class="ss-flex ss-col-top ss-m-b-40" @tap="onGoodsList(item)">
<view class="model-content-tag ss-flex ss-row-center">满减</view>
<!-- TODO 芋艿先简单做未来再搞成满 xxx yyy -->
<!-- <view class="ss-m-l-20 model-content-title ss-flex-1">-->
<!-- <view class="ss-m-b-24" v-for="text in item.texts" :key="text">-->
<!-- {{ text }}-->
<!-- </view>-->
<!-- </view>-->
<view class="ss-m-l-20 model-content-title ss-flex-1">
<view class="ss-m-b-24">
{{ item.name }}
<view class="ss-m-b-24" v-for="rule in state.activityMap[item.id]?.rules" :key="rule">
{{ formatRewardActivityRule(state.activityMap[item.id], rule) }}
</view>
</view>
<text class="cicon-forward" />
@ -32,7 +26,10 @@
</template>
<script setup>
import sheep from '@/sheep';
import { computed, reactive } from 'vue';
import { computed, reactive, watch } from 'vue';
import RewardActivityApi from '@/sheep/api/promotion/rewardActivity';
import { formatRewardActivityRule } from '@/sheep/hooks/useGoods';
const props = defineProps({
modelValue: {
type: Object,
@ -46,7 +43,26 @@
const emits = defineEmits(['close']);
const state = reactive({
activityInfo: computed(() => props.modelValue),
activityMap: {}
});
watch(
() => props.show,
() => {
//
if (props.show) {
state.activityInfo?.forEach(activity => {
RewardActivityApi.getRewardActivity(activity.id).then(res => {
if (res.code !== 0) {
return;
}
state.activityMap[activity.id] = res.data;
})
});
}
},
);
function onGoodsList(e) {
sheep.$router.go('/pages/activity/index', {
activityId: e.id,

View File

@ -368,3 +368,20 @@ export function convertProductPropertyList(skus) {
}
return result;
}
/**
* 格式化满减送活动的规则
*
* @param activity 活动信息
* @param rule 优惠规格
* @returns {string} 规格字符串
*/
export function formatRewardActivityRule(activity, rule) {
if (activity.conditionType === 10) {
return `${fen2yuan(rule.limit)} 元减 ${fen2yuan(rule.discountPrice)}`;
}
if (activity.conditionType === 20) {
return `${rule.limit} 件减 ${fen2yuan(rule.discountPrice)}`;
}
return '';
}