接入我的足迹
parent
f3659c7929
commit
c2f29333dc
|
@ -31,32 +31,32 @@
|
||||||
<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">
|
||||||
<label
|
<label
|
||||||
class="check-box ss-flex ss-col-center ss-p-l-10"
|
class="check-box ss-flex ss-col-center ss-p-l-10"
|
||||||
v-if="state.editMode"
|
v-if="state.editMode"
|
||||||
@tap="onSelect(item.goods_id)"
|
@tap="onSelect(item.spuId)"
|
||||||
>
|
>
|
||||||
<radio
|
<radio
|
||||||
:checked="state.selectedCollectList.includes(item.goods_id)"
|
:checked="state.selectedSpuIdList.includes(item.spuId)"
|
||||||
color="var(--ui-BG-Main)"
|
color="var(--ui-BG-Main)"
|
||||||
style="transform: scale(0.8)"
|
style="transform: scale(0.8)"
|
||||||
@tap.stop="onSelect(item.goods_id)"
|
@tap.stop="onSelect(item.spuId)"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<s-goods-item
|
<s-goods-item
|
||||||
:title="item.goods.title"
|
:title="item.spuName"
|
||||||
:img="item.goods.image"
|
:img="item.picUrl"
|
||||||
:price="item.goods.price[0]"
|
:price="item.price"
|
||||||
:skuText="item.goods.subtitle"
|
:skuText="item.introduction"
|
||||||
priceColor="#FF3000"
|
priceColor="#FF3000"
|
||||||
:titleWidth="400"
|
:titleWidth="400"
|
||||||
@tap="
|
@tap="
|
||||||
sheep.$router.go('/pages/goods/index', {
|
sheep.$router.go('/pages/goods/index', {
|
||||||
id: item.goods_id,
|
id: item.spuId,
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
|
@ -78,13 +78,23 @@
|
||||||
<view>全选</view>
|
<view>全选</view>
|
||||||
</label>
|
</label>
|
||||||
</view>
|
</view>
|
||||||
<view class="footer-right">
|
<view class="footer-right ss-flex">
|
||||||
<button
|
<button
|
||||||
class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main"
|
:class="['ss-reset-button pay-btn ss-font-28 ',
|
||||||
@tap="onCancel"
|
{
|
||||||
|
'ui-BG-Main-Gradient': state.selectedSpuIdList.length > 0,
|
||||||
|
'ui-Shadow-Main': state.selectedSpuIdList.length > 0
|
||||||
|
}]"
|
||||||
|
@tap="onDelete"
|
||||||
>
|
>
|
||||||
删除足迹
|
删除足迹
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
class="ss-reset-button ui-BG-Main-Gradient pay-btn ss-font-28 ui-Shadow-Main ml-2"
|
||||||
|
@tap="onClean"
|
||||||
|
>
|
||||||
|
清空
|
||||||
|
</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</su-fixed>
|
</su-fixed>
|
||||||
|
@ -95,7 +105,7 @@
|
||||||
:content-text="{
|
:content-text="{
|
||||||
contentdown: '上拉加载更多',
|
contentdown: '上拉加载更多',
|
||||||
}"
|
}"
|
||||||
@tap="loadmore"
|
@tap="loadMore"
|
||||||
/>
|
/>
|
||||||
<s-empty
|
<s-empty
|
||||||
v-if="state.pagination.total === 0"
|
v-if="state.pagination.total === 0"
|
||||||
|
@ -110,100 +120,105 @@
|
||||||
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 SpuHistoryApi from "@/sheep/api/product/history";
|
||||||
|
import {cloneDeep} from "@/sheep/helper/utils";
|
||||||
|
|
||||||
const sys_navBar = sheep.$platform.navbar;
|
const sys_navBar = sheep.$platform.navbar;
|
||||||
const pagination = {
|
const pagination = {
|
||||||
data: [],
|
list: [],
|
||||||
current_page: 1,
|
pageNo: 1,
|
||||||
total: 1,
|
total: 1,
|
||||||
last_page: 1,
|
pageSize: 10,
|
||||||
};
|
};
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
pagination: {
|
pagination: cloneDeep(pagination),
|
||||||
data: [],
|
|
||||||
current_page: 1,
|
|
||||||
total: 1,
|
|
||||||
last_page: 1,
|
|
||||||
},
|
|
||||||
loadStatus: '',
|
loadStatus: '',
|
||||||
editMode: false,
|
editMode: false,
|
||||||
selectedCollectList: [],
|
selectedSpuIdList: [],
|
||||||
selectAll: false,
|
selectAll: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function getData(page = 1, list_rows = 10) {
|
async function getList() {
|
||||||
state.loadStatus = 'loading';
|
state.loadStatus = 'loading';
|
||||||
let res = await sheep.$api.user.view.list({
|
const { code, data } = await SpuHistoryApi.getBrowseHistoryPage({
|
||||||
list_rows,
|
pageNo: state.pagination.pageNo,
|
||||||
page,
|
pageSize: state.pagination.pageSize,
|
||||||
});
|
});
|
||||||
if (res.error === 0) {
|
if (code !== 0) {
|
||||||
let orderList = _.concat(state.pagination.data, res.data.data);
|
return;
|
||||||
state.pagination = {
|
}
|
||||||
...res.data,
|
|
||||||
data: orderList,
|
state.pagination.list = _.concat(state.pagination.list, data.list);
|
||||||
};
|
state.pagination.total = data.total;
|
||||||
if (state.pagination.current_page < state.pagination.last_page) {
|
if (state.pagination.list.length < state.pagination.total) {
|
||||||
state.loadStatus = 'more';
|
state.loadStatus = 'more';
|
||||||
} else {
|
} else {
|
||||||
state.loadStatus = 'noMore';
|
state.loadStatus = 'noMore';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 格式化价格
|
|
||||||
function formatPrice(e) {
|
|
||||||
return e.length === 1 ? e[0] : e.join('~');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 单选选中
|
// 单选选中
|
||||||
const onSelect = (id) => {
|
const onSelect = (id) => {
|
||||||
if (!state.selectedCollectList.includes(id)) {
|
if (!state.selectedSpuIdList.includes(id)) {
|
||||||
state.selectedCollectList.push(id);
|
state.selectedSpuIdList.push(id);
|
||||||
} else {
|
} else {
|
||||||
state.selectedCollectList.splice(state.selectedCollectList.indexOf(id), 1);
|
state.selectedSpuIdList.splice(state.selectedSpuIdList.indexOf(id), 1);
|
||||||
}
|
}
|
||||||
state.selectAll = state.selectedCollectList.length === state.pagination.data.length;
|
state.selectAll = state.selectedSpuIdList.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.selectedSpuIdList = [];
|
||||||
} else {
|
} else {
|
||||||
state.pagination.data.forEach((item) => {
|
state.pagination.list.forEach((item) => {
|
||||||
if (state.selectedCollectList.includes(item.goods_id)) {
|
if (state.selectedSpuIdList.includes(item.spuId)) {
|
||||||
state.selectedCollectList.splice(state.selectedCollectList.indexOf(item.goods_id), 1);
|
state.selectedSpuIdList.splice(state.selectedSpuIdList.indexOf(item.spuId), 1);
|
||||||
}
|
}
|
||||||
state.selectedCollectList.push(item.goods_id);
|
state.selectedSpuIdList.push(item.spuId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
async function onCancel() {
|
// 删除足迹
|
||||||
if (state.selectedCollectList) {
|
async function onDelete() {
|
||||||
state.selectedCollectList = state.selectedCollectList.toString();
|
if (state.selectedSpuIdList.length <= 0) {
|
||||||
const { error } = await sheep.$api.user.view.delete({
|
return;
|
||||||
goods_id: state.selectedCollectList,
|
}
|
||||||
});
|
|
||||||
if (error === 0) {
|
const { code } = await SpuHistoryApi.deleteBrowseHistory(state.selectedSpuIdList);
|
||||||
state.editMode = false;
|
if (code === 0) {
|
||||||
state.selectedCollectList = [];
|
reload();
|
||||||
state.selectAll = false;
|
|
||||||
state.pagination = pagination;
|
|
||||||
getData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 清空
|
||||||
|
async function onClean() {
|
||||||
|
const { code } = await SpuHistoryApi.cleanBrowseHistory();
|
||||||
|
if (code === 0) {
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function reload() {
|
||||||
|
state.editMode = false;
|
||||||
|
state.selectedSpuIdList = [];
|
||||||
|
state.selectAll = false;
|
||||||
|
state.pagination = pagination;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
|
||||||
// 加载更多
|
// 加载更多
|
||||||
function loadmore() {
|
function loadMore() {
|
||||||
if (state.loadStatus !== 'noMore') {
|
if (state.loadStatus !== 'noMore') {
|
||||||
getData(state.pagination.current_page + 1);
|
state.pagination.pageNo += 1;
|
||||||
|
getList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onReachBottom(() => {
|
onReachBottom(() => {
|
||||||
loadmore();
|
loadMore();
|
||||||
});
|
});
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
getData();
|
getList();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
import request from '@/sheep/request';
|
||||||
|
|
||||||
|
const SpuHistoryApi = {
|
||||||
|
// 删除商品浏览记录
|
||||||
|
deleteBrowseHistory: (spuIds) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/browse-history/delete',
|
||||||
|
method: 'DELETE',
|
||||||
|
data: { spuIds },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 清空商品浏览记录
|
||||||
|
cleanBrowseHistory: () => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/browse-history/clean',
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品浏览记录分页
|
||||||
|
getBrowseHistoryPage: (data) => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/browse-history/page',
|
||||||
|
method: 'GET',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 获得商品浏览记录数量
|
||||||
|
getBrowseHistoryCount: () => {
|
||||||
|
return request({
|
||||||
|
url: '/app-api/product/browse-history/get-count',
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export default SpuHistoryApi;
|
|
@ -74,12 +74,12 @@ const VIDEO_SUFFIX_LIST = ['.avi', '.mp4']
|
||||||
* @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表
|
* @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表
|
||||||
*/
|
*/
|
||||||
export function formatGoodsSwiper(urlList) {
|
export function formatGoodsSwiper(urlList) {
|
||||||
return urlList.filter(url => url).map((url, key) => {
|
return urlList?.filter(url => url).map((url, key) => {
|
||||||
const isVideo = VIDEO_SUFFIX_LIST.some(suffix => url.includes(suffix));
|
const isVideo = VIDEO_SUFFIX_LIST.some(suffix => url.includes(suffix));
|
||||||
const type = isVideo ? 'video' : 'image'
|
const type = isVideo ? 'video' : 'image'
|
||||||
const src = $url.cdn(url);
|
const src = $url.cdn(url);
|
||||||
return { type, src }
|
return { type, src }
|
||||||
});
|
}) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue