<template>
|
<view class="myTracks">
|
<u-navbar title="我的足迹">
|
<div slot="right">
|
<div class="light-color edit" @click="isEdit = !isEdit">{{ !isEdit ? '编辑' : '完成'}}</div>
|
</div>
|
</u-navbar>
|
<u-notice-bar mode="vertical" :list="['右划删除浏览记录']"></u-notice-bar>
|
<!-- 顶部选项卡 -->
|
<view class="tabs">
|
<view
|
class="tab-item"
|
:class="{active: activeTab === 'video'}"
|
@click="switchTab('video')"
|
>
|
视频
|
</view>
|
<view
|
class="tab-item"
|
:class="{active: activeTab === 'goods'}"
|
@click="switchTab('goods')"
|
>
|
商品
|
</view>
|
</view>
|
|
<!-- 视频浏览记录列表 -->
|
<view v-if="activeTab === 'video'" class="video-list">
|
<view
|
v-for="(item, index) in videoHistory"
|
:key="index"
|
class="video-item"
|
@click="goToVideoPlay(item, index)"
|
>
|
<u-swipe-action style="width: 100%;" :show="item.show" :index="index" :key="item.id"
|
@click="deleteVideoView(item.id)" @open="open" :options="options">
|
<view style="display: flex;" @click="goToVideoPlay(item, index)">
|
<image class="video-cover" :src="item.coverUrl" mode="aspectFill"></image>
|
<view class="video-info">
|
<view class="video-title">{{item.title}}</view>
|
<view class="video-author">{{item.authorName}}</view>
|
<view class="video-meta">
|
<text>播放至: {{formatPlayTime(item.playAt)}}</text>
|
<text class="separator">|</text>
|
<text>{{formatDate(item.playTime)}}</text>
|
</view>
|
</view>
|
</view>
|
|
</u-swipe-action>
|
</view>
|
<div @click="deleteVideoView(item.id)" v-if="isEdit" class="submit">
|
删除所选
|
</div>
|
<view v-if="videoHistory.length === 0" class="empty-tip">
|
暂无视频浏览记录
|
</view>
|
</view>
|
<view v-else-if="activeTab === 'goods'">
|
<view v-for="(item, index) in trackList" :key="index">
|
<view class="myTracks-title" @click="navigateToStore(item)">{{item.storeName}}</view>
|
<view class="myTracks-items">
|
|
<u-swipe-action style="width: 100%;" :show="item.show" :index="index" :key="item.id"
|
@click="delTracks" @open="open" :options="options">
|
|
<view class="myTracks-item">
|
<u-checkbox-group v-if="isEdit" class="store-line-check">
|
<u-checkbox shape="circle" :active-color="lightColor" v-model="item.checked"
|
@change="checkboxChangeDP(item)"></u-checkbox>
|
</u-checkbox-group>
|
<view class="myTracks-item-img" @click.stop="navigateToDetail(item)">
|
<image :src="item.thumbnail"></image>
|
</view>
|
<view class="myTracks-item-content" @click.stop="navigateToDetail(item)">
|
<view class="myTracks-item-title">
|
{{ item.goodsName }}
|
<view class="myTracks-item-title-desc"> </view>
|
</view>
|
<view class="myTracks-item-price">
|
¥{{ item.price | unitPrice }}
|
</view>
|
</view>
|
</view>
|
</u-swipe-action>
|
|
</view>
|
<view class="myTracks-divider"></view>
|
<div @click="handleClickDeleteSelected(item.id)" v-if="isEdit" class="submit">
|
删除所选
|
</div>
|
</view>
|
|
<view v-if="trackList.length === 0" class="empty-tip">
|
暂无商品浏览记录
|
</view>
|
</view>
|
|
</view>
|
</template>
|
|
<script>
|
import '@/components/uview-components/uview-ui';
|
|
import {
|
myTrackList,
|
deleteHistoryListId,
|
myVideoHistory
|
} from "@/api/members.js";
|
import storage from '@/utils/storage';
|
|
export default {
|
data() {
|
return {
|
activeTab: 'video', // 当前激活的tab
|
videoHistory: [], // 视频浏览列表
|
isEdit:false,
|
whetherEmpty: false, //是否数据为空
|
params: {
|
pageNumber: 1,
|
pageSize: 10,
|
order: "desc",
|
sort: "updateTime",
|
},
|
lightColor:this.$lightColor,
|
options: [{
|
text: '删除',
|
style: {
|
backgroundColor: '#dd524d'
|
}
|
}],
|
trackList: [], //商品浏览列表
|
};
|
},
|
|
/**
|
* 滑到底部加载下一页数据
|
*/
|
onReachBottom() {
|
this.params.pageNumber++;
|
this.getList();
|
},
|
onShow() {
|
this.params.pageNumber = 1
|
this.trackList = [];
|
this.getList();
|
},
|
onPullDownRefresh() {
|
this.trackList = [];
|
this.getList();
|
},
|
methods: {
|
// 切换tab
|
switchTab(tab) {
|
this.activeTab = tab
|
},
|
|
// 跳转到视频详情页
|
goToVideoPlay(item, index) {
|
const playInfo = {
|
videoList: this.videoHistory,
|
nomore: true,
|
pageNumber: this.params.pageNumber,
|
playIndex: index
|
}
|
uni.setStorageSync("playInfo", playInfo)
|
uni.navigateTo({
|
url: `/pages/video/video-play?authorId=${storage.getUserInfo().id}&videoFrom=history`
|
})
|
},
|
|
// 格式化播放时间 (秒 -> 分:秒)
|
formatPlayTime(seconds) {
|
const secsInt = Math.floor(seconds); // 去掉小数部分
|
const mins = Math.floor(secsInt / 60)
|
const secs = secsInt % 60
|
return `${mins}:${secs < 10 ? '0' + secs : secs}`
|
},
|
|
// 格式化日期
|
formatDate(timestamp) {
|
const now = new Date()
|
const date = new Date(timestamp)
|
|
// 如果是今天
|
if (date.toDateString() === now.toDateString()) {
|
const hours = date.getHours().toString().padStart(2, '0')
|
const minutes = date.getMinutes().toString().padStart(2, '0')
|
return `${hours}:${minutes}`
|
}
|
|
// 如果是昨天
|
const yesterday = new Date(now)
|
yesterday.setDate(now.getDate() - 1)
|
if (date.toDateString() === yesterday.toDateString()) {
|
return '昨天'
|
}
|
|
// 其他情况显示日期
|
const month = date.getMonth() + 1
|
const day = date.getDate()
|
return `${month}月${day}日`
|
},
|
checkboxChangeDP(val){
|
console.log(val)
|
},
|
// 删除视频浏览记录
|
deleteVideoView(id) {
|
deleteHistoryListId([id], 'video').then((res) => {
|
if (res.data.code == 200) {
|
this.videoHistory = [];
|
this.params.pageNumber = 1
|
this.getList();
|
} else {
|
uni.showToast({
|
title: res.data.message,
|
duration: 2000,
|
icon: "none",
|
});
|
}
|
});
|
},
|
// 删除所选的数据
|
handleClickDeleteSelected(val){
|
const ids = this.trackList.filter(item=>item.checked).map(item=>item.goodsId);
|
if(!ids.length){
|
uni.showToast({
|
title:"请选择删除数据",
|
icon:"none"
|
})
|
}else{
|
this.delTracks(0,ids)
|
}
|
},
|
/**
|
* 导航到店铺
|
*/
|
navigateToStore(val) {
|
uni.navigateTo({
|
url: "/pages/product/shopPage?id=" + val.storeId,
|
});
|
},
|
open(index) {
|
// 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
|
// 原本为'false',再次设置为'false'会无效
|
this.trackList[index].show = true;
|
this.trackList.map((val, idx) => {
|
if (index != idx) this.trackList[idx].show = false;
|
})
|
},
|
/**
|
* 跳转详情
|
*/
|
navigateToDetail(item) {
|
uni.navigateTo({
|
url: "/pages/product/goods?id=" + item.id + "&goodsId=" + item.goodsId,
|
});
|
},
|
|
/**
|
* 获取我的足迹列表
|
*/
|
getList() {
|
uni.showLoading({
|
title: "加载中",
|
});
|
if (this.activeTab === 'goods') {
|
myTrackList(this.params).then((res) => {
|
uni.stopPullDownRefresh();
|
uni.hideLoading();
|
if (res.statusCode == 200) {
|
res.data.result.records.length &&
|
res.data.result.records.forEach((item) => {
|
item.show = false;
|
item.checked = false
|
});
|
|
let data = res.data.result.records;
|
if (data.total == 0) {
|
this.whetherEmpty = true;
|
} else {
|
this.trackList.push(...data);
|
}
|
}
|
});
|
} else if (this.activeTab === 'video') {
|
myVideoHistory(this.params).then(res => {
|
res.data.data.length &&
|
res.data.data.forEach((item) => {
|
item.show = false;
|
item.checked = false
|
});
|
|
let data = res.data.data;
|
if (data.total == 0) {
|
this.whetherEmpty = true;
|
} else {
|
this.videoHistory = [
|
...this.videoHistory,
|
...res.data.data.filter(
|
(newItem) => !this.videoHistory.some((oldItem) => oldItem.id === newItem.id)
|
),
|
];
|
}
|
})
|
}
|
|
},
|
/**
|
* 删除足迹
|
*/
|
delTracks(index,ids) {
|
deleteHistoryListId(ids || this.trackList[index].goodsId, 'goods').then((res) => {
|
if (res.data.code == 200) {
|
this.trackList = [];
|
this.params.pageNumber = 1
|
this.getList();
|
} else {
|
uni.showToast({
|
title: res.data.message,
|
duration: 2000,
|
icon: "none",
|
});
|
}
|
});
|
},
|
},
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.submit{
|
position: fixed;
|
bottom: 20rpx;
|
left: 10%;
|
width: 80%;
|
height: 80rpx;
|
color: #fff;
|
border-radius: 100px;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
background: $light-color;
|
}
|
.myTracks {
|
width: 100%;
|
padding-top: 2rpx;
|
}
|
|
.myTracks-title {
|
width: 100%;
|
height: 110rpx;
|
padding-left: 20rpx;
|
font-size: 28rpx;
|
color: #666;
|
font-weight: bold;
|
background-color: #fff;
|
align-items: center;
|
display: -webkit-box;
|
display: -webkit-flex;
|
display: flex;
|
}
|
|
.myTracks-items {
|
padding-top: 2rpx;
|
align-items: center;
|
display: -webkit-box;
|
display: -webkit-flex;
|
display: flex;
|
flex-direction: column;
|
}
|
|
.myTracks-item {
|
width: 100%;
|
height: 226rpx;
|
padding-left: 20rpx;
|
padding-right: 20rpx;
|
margin-bottom: 2rpx;
|
// border-radius: 6/@px;
|
background-color: #fff;
|
position: relative;
|
align-items: center;
|
display: -webkit-box;
|
display: -webkit-flex;
|
display: flex;
|
}
|
|
.myTracks-item-img {
|
margin-right: 20rpx;
|
border-radius: 8rpx;
|
|
image {
|
width: 130rpx;
|
height: 130rpx;
|
border-radius: 8rpx;
|
}
|
}
|
|
.myTracks-item-title {
|
font-size: 28rpx;
|
color: #333;
|
}
|
|
.myTracks-item-title-desc {
|
font-size: 28rpx;
|
color: #999;
|
}
|
|
.myTracks-item-price {
|
font-size: 28rpx;
|
color: $light-color;
|
padding: 10rpx 0 0 0;
|
}
|
|
.myTracks-action {
|
display: flex;
|
justify-content: space-between;
|
position: fixed;
|
bottom: 0;
|
left: 0;
|
width: 100%;
|
background: #fff;
|
height: 75rpx;
|
align-items: center;
|
padding: 0 32rpx;
|
}
|
|
.myTracks-action-btn {
|
width: 130rpx;
|
height: 60rpx;
|
line-height: 60rpx;
|
}
|
|
.myTracks-divider {
|
width: 100%;
|
height: 20rpx;
|
}
|
|
|
|
.myTracks-action-check {
|
align-items: center;
|
display: -webkit-box;
|
display: -webkit-flex;
|
display: flex;
|
}
|
.edit{
|
padding-right: 32rpx;
|
}
|
.container {
|
padding: 20rpx;
|
}
|
|
/* 选项卡样式 */
|
.tabs {
|
display: flex;
|
margin-bottom: 20rpx;
|
border-bottom: 1rpx solid #eee;
|
}
|
|
.tab-item {
|
flex: 1;
|
text-align: center;
|
padding: 20rpx 0;
|
font-size: 32rpx;
|
color: #666;
|
}
|
|
.tab-item.active {
|
color: #007AFF;
|
position: relative;
|
}
|
|
.tab-item.active::after {
|
content: '';
|
position: absolute;
|
bottom: 0;
|
left: 50%;
|
transform: translateX(-50%);
|
width: 80rpx;
|
height: 4rpx;
|
background-color: #007AFF;
|
}
|
|
/* 视频列表样式 */
|
.video-list {
|
padding: 10rpx 0;
|
}
|
|
.video-item {
|
display: flex;
|
padding-bottom: 10rpx;
|
padding-left: 20rpx;
|
border-bottom: 1rpx solid #f5f5f5;
|
}
|
|
.video-cover {
|
width: 220rpx;
|
height: 160rpx;
|
border-radius: 8rpx;
|
margin-right: 20rpx;
|
}
|
|
.video-info {
|
flex: 1;
|
display: flex;
|
flex-direction: column;
|
justify-content: space-between;
|
}
|
|
.video-title {
|
font-size: 30rpx;
|
color: #333;
|
display: -webkit-box;
|
-webkit-box-orient: vertical;
|
-webkit-line-clamp: 2;
|
overflow: hidden;
|
line-height: 1.4;
|
}
|
|
.video-author {
|
font-size: 26rpx;
|
color: #999;
|
}
|
|
.video-meta {
|
font-size: 24rpx;
|
color: #999;
|
}
|
|
.separator {
|
margin: 0 10rpx;
|
}
|
|
.empty-tip {
|
text-align: center;
|
padding: 100rpx 0;
|
color: #999;
|
font-size: 28rpx;
|
}
|
</style>
|