✨ 我的收藏:接入完成
parent
4e85f86529
commit
3b5c84f970
|
@ -1,12 +1,11 @@
|
||||||
|
<!-- 我的商品收藏 -->
|
||||||
<template>
|
<template>
|
||||||
<s-layout title="商品收藏">
|
<s-layout title="商品收藏">
|
||||||
<view class="cart-box ss-flex ss-flex-col ss-row-between">
|
<view class="cart-box ss-flex ss-flex-col ss-row-between">
|
||||||
<!-- 头部 -->
|
<!-- 头部 -->
|
||||||
<view class="cart-header ss-flex ss-col-center ss-row-between ss-p-x-30">
|
<view class="cart-header ss-flex ss-col-center ss-row-between ss-p-x-30">
|
||||||
<view class="header-left ss-flex ss-col-center ss-font-26">
|
<view class="header-left ss-flex ss-col-center ss-font-26">
|
||||||
共
|
共 <text class="goods-number ui-TC-Main ss-flex">{{ state.pagination.total }}</text> 件商品
|
||||||
<text class="goods-number ui-TC-Main ss-flex">{{ state.pagination.total }}</text>
|
|
||||||
件商品
|
|
||||||
</view>
|
</view>
|
||||||
<view class="header-right">
|
<view class="header-right">
|
||||||
<button
|
<button
|
||||||
|
@ -20,15 +19,16 @@
|
||||||
v-if="!state.editMode && state.pagination.total"
|
v-if="!state.editMode && state.pagination.total"
|
||||||
class="ss-reset-button ui-TC-Main"
|
class="ss-reset-button ui-TC-Main"
|
||||||
@tap="state.editMode = true"
|
@tap="state.editMode = true"
|
||||||
>编辑</button
|
|
||||||
>
|
>
|
||||||
|
编辑
|
||||||
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 内容 -->
|
<!-- 内容 -->
|
||||||
<view class="cart-content">
|
<view class="cart-content">
|
||||||
<view
|
<view
|
||||||
class="goods-box ss-r-10 ss-m-b-14"
|
class="goods-box ss-r-10 ss-m-b-14"
|
||||||
v-for="item in state.pagination.data"
|
v-for="item in state.pagination.list"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
>
|
>
|
||||||
<view class="ss-flex ss-col-center">
|
<view class="ss-flex ss-col-center">
|
||||||
|
@ -44,12 +44,10 @@
|
||||||
@tap.stop="onSelect(item.spuId)"
|
@tap.stop="onSelect(item.spuId)"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<!-- :skuText="item.goods.subtitle" -->
|
|
||||||
<s-goods-item
|
<s-goods-item
|
||||||
:title="item.spuName"
|
:title="item.spuName"
|
||||||
:img="item.picUrl"
|
:img="item.picUrl"
|
||||||
:price="item.price"
|
:price="item.price"
|
||||||
|
|
||||||
priceColor="#FF3000"
|
priceColor="#FF3000"
|
||||||
:titleWidth="400"
|
:titleWidth="400"
|
||||||
@tap="
|
@tap="
|
||||||
|
@ -57,11 +55,11 @@
|
||||||
id: item.spuId,
|
id: item.spuId,
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
>
|
/>
|
||||||
</s-goods-item>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 底部 -->
|
<!-- 底部 -->
|
||||||
<su-fixed bottom :val="0" placeholder v-show="state.editMode">
|
<su-fixed bottom :val="0" placeholder v-show="state.editMode">
|
||||||
<view class="cart-footer ss-flex ss-col-center ss-row-between ss-p-x-30 border-bottom">
|
<view class="cart-footer ss-flex ss-col-center ss-row-between ss-p-x-30 border-bottom">
|
||||||
|
@ -79,9 +77,9 @@
|
||||||
<view class="footer-right">
|
<view class="footer-right">
|
||||||
<button
|
<button
|
||||||
class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main"
|
class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main"
|
||||||
@tap="onCancel"
|
@tap="onCancel">
|
||||||
>取消收藏</button
|
取消收藏
|
||||||
>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</su-fixed>
|
</su-fixed>
|
||||||
|
@ -92,7 +90,7 @@
|
||||||
:content-text="{
|
:content-text="{
|
||||||
contentdown: '上拉加载更多',
|
contentdown: '上拉加载更多',
|
||||||
}"
|
}"
|
||||||
@tap="loadmore"
|
@tap="loadMore"
|
||||||
/>
|
/>
|
||||||
<s-empty v-if="state.pagination.total === 0" text="暂无收藏" icon="/static/collect-empty.png" />
|
<s-empty v-if="state.pagination.total === 0" text="暂无收藏" icon="/static/collect-empty.png" />
|
||||||
</s-layout>
|
</s-layout>
|
||||||
|
@ -103,98 +101,89 @@
|
||||||
import { reactive } from 'vue';
|
import { reactive } from 'vue';
|
||||||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import FavoriteApi from '@/sheep/api/product/favorite';
|
||||||
|
import { resetPagination } from '@/sheep/util';
|
||||||
|
|
||||||
const sys_navBar = sheep.$platform.navbar;
|
const sys_navBar = sheep.$platform.navbar;
|
||||||
const pagination = {
|
|
||||||
data: [],
|
|
||||||
current_page: 1,
|
|
||||||
total: 1,
|
|
||||||
last_page: 1,
|
|
||||||
};
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
pagination: {
|
pagination: {
|
||||||
data: [],
|
list: [],
|
||||||
current_page: 1,
|
total: 0,
|
||||||
total: 1,
|
pageNo: 1,
|
||||||
last_page: 1,
|
pageSize: 6,
|
||||||
},
|
},
|
||||||
loadStatus: '',
|
loadStatus: '',
|
||||||
|
|
||||||
editMode: false,
|
editMode: false,
|
||||||
selectedCollectList: [],
|
selectedCollectList: [], // 选中的 SPU 数组
|
||||||
selectAll: false,
|
selectAll: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function getData(page = 1, list_rows = 6) {
|
async function getData() {
|
||||||
state.loadStatus = 'loading';
|
state.loadStatus = 'loading';
|
||||||
let res = await sheep.$api.user.favorite.list({
|
const { code, data } = await FavoriteApi.getFavoritePage({
|
||||||
pageSize:list_rows,
|
pageNo: state.pagination.pageNo,
|
||||||
pageNo:page,
|
pageSize: state.pagination.pageSize,
|
||||||
});
|
});
|
||||||
if (res.code === 0) {
|
if (code !== 0) {
|
||||||
console.log('yudao收藏列表',res)
|
return;
|
||||||
let orderList = _.concat(state.pagination.data, res.data.list);
|
|
||||||
state.pagination = {
|
|
||||||
...res.data,
|
|
||||||
data: orderList,
|
|
||||||
};
|
|
||||||
// 没有原接口文档不太理解这字段意思
|
|
||||||
if (state.pagination.current_page < state.pagination.last_page) {
|
|
||||||
state.loadStatus = 'more';
|
|
||||||
} else {
|
|
||||||
state.loadStatus = 'noMore';
|
|
||||||
}
|
}
|
||||||
}
|
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';
|
||||||
function formatPrice(e) {
|
|
||||||
return e.length === 1 ? e[0] : e.join('~');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 单选选中
|
// 单选选中
|
||||||
const onSelect = (id) => {
|
const onSelect = (spuId) => {
|
||||||
if (!state.selectedCollectList.includes(id)) {
|
if (!state.selectedCollectList.includes(spuId)) {
|
||||||
state.selectedCollectList.push(id);
|
state.selectedCollectList.push(spuId);
|
||||||
} else {
|
} else {
|
||||||
state.selectedCollectList.splice(state.selectedCollectList.indexOf(id), 1);
|
state.selectedCollectList.splice(state.selectedCollectList.indexOf(spuId), 1);
|
||||||
}
|
}
|
||||||
state.selectAll = state.selectedCollectList.length === state.pagination.data.length;
|
state.selectAll = state.selectedCollectList.length === state.pagination.list.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 全选
|
// 全选
|
||||||
const onSelectAll = () => {
|
const onSelectAll = () => {
|
||||||
state.selectAll = !state.selectAll;
|
state.selectAll = !state.selectAll;
|
||||||
if (!state.selectAll) {
|
if (!state.selectAll) {
|
||||||
state.selectedCollectList = [];
|
state.selectedCollectList = [];
|
||||||
} else {
|
} else {
|
||||||
state.pagination.data.forEach((item) => {
|
state.selectedCollectList = state.pagination.list.map((item) => item.spuId);
|
||||||
if (state.selectedCollectList.includes(item.goods_id)) {
|
|
||||||
state.selectedCollectList.splice(state.selectedCollectList.indexOf(item.goods_id), 1);
|
|
||||||
}
|
|
||||||
state.selectedCollectList.push(item.goods_id);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function onCancel() {
|
async function onCancel() {
|
||||||
if (state.selectedCollectList) {
|
if (!state.selectedCollectList) {
|
||||||
state.selectedCollectList = state.selectedCollectList.toString();
|
return;
|
||||||
const { code } = await sheep.$api.user.favorite.cancel(state.selectedCollectList);
|
}
|
||||||
if (code === 0) {
|
// 取消收藏
|
||||||
|
for (const spuId of state.selectedCollectList) {
|
||||||
|
await FavoriteApi.deleteFavorite(spuId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清空选择 + 重新加载
|
||||||
state.editMode = false;
|
state.editMode = false;
|
||||||
state.selectedCollectList = [];
|
state.selectedCollectList = [];
|
||||||
state.selectAll = false;
|
state.selectAll = false;
|
||||||
state.pagination = pagination;
|
resetPagination(state.pagination);
|
||||||
|
await getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载更多
|
||||||
|
function loadMore() {
|
||||||
|
if (state.loadStatus === 'noMore') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
state.pagination.pageNo++;
|
||||||
getData();
|
getData();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
// 加载更多
|
|
||||||
function loadmore() {
|
|
||||||
if (state.loadStatus !== 'noMore') {
|
|
||||||
getData(state.pagination.current_page + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onReachBottom(() => {
|
onReachBottom(() => {
|
||||||
loadmore();
|
loadMore();
|
||||||
});
|
});
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
getData();
|
getData();
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const FavoriteApi = {
|
||||||
|
// 获得商品收藏分页
|
||||||
|
getFavoritePage: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/favorite/page',
|
||||||
|
method: 'GET',
|
||||||
|
params: data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 取消商品收藏
|
||||||
|
deleteFavorite: (spuId) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/favorite/delete',
|
||||||
|
method: 'DELETE',
|
||||||
|
data: {
|
||||||
|
spuId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FavoriteApi;
|
|
@ -26,7 +26,7 @@
|
||||||
:style="[{ color: priceColor }]"
|
:style="[{ color: priceColor }]"
|
||||||
v-if="price && Number(price) > 0"
|
v-if="price && Number(price) > 0"
|
||||||
>
|
>
|
||||||
¥{{ price }}
|
¥{{ fen2yuan(price) }}
|
||||||
</view>
|
</view>
|
||||||
<view v-if="score && Number(price) > 0">+</view>
|
<view v-if="score && Number(price) > 0">+</view>
|
||||||
<view class="price-text ss-flex ss-col-center" v-if="score">
|
<view class="price-text ss-flex ss-col-center" v-if="score">
|
||||||
|
@ -54,6 +54,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||||
/**
|
/**
|
||||||
* 订单卡片
|
* 订单卡片
|
||||||
*
|
*
|
||||||
|
|
|
@ -100,3 +100,16 @@ export function handleTree(data, id = 'id', parentId = 'parentId', children = 'c
|
||||||
});
|
});
|
||||||
return treeData !== '' ? treeData : data;
|
return treeData !== '' ? treeData : data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置分页对象
|
||||||
|
*
|
||||||
|
* TODO 芋艿:需要处理其它页面
|
||||||
|
*
|
||||||
|
* @param pagination 分页对象
|
||||||
|
*/
|
||||||
|
export function resetPagination(pagination) {
|
||||||
|
pagination.list = [];
|
||||||
|
pagination.total = 0;
|
||||||
|
pagination.pageNo = 1;
|
||||||
|
}
|
Loading…
Reference in New Issue