<template>
|
<div>
|
<div class="title spaceBetween">
|
<span
|
:class="paymentStatus == 0 ? 'paymentStatus' : 'place'"
|
@click="
|
() => {
|
paymentStatus = 0;
|
this.paginationData.page = 1;
|
this.collectionList = [];
|
this.getBookData();
|
}
|
"
|
>图书收藏</span
|
>
|
<span class="splitline"></span>
|
<span
|
:class="paymentStatus == 1 ? 'paymentStatus' : 'place'"
|
@click="
|
() => {
|
paymentStatus = 1;
|
this.paginationData.page = 1;
|
this.collectionList = [];
|
this.getResourceData();
|
}
|
"
|
>资源收藏</span
|
>
|
</div>
|
<div class="content" v-loading="loading">
|
<el-empty
|
v-if="collectionList.length == 0 && orderList.length == 0 && !loading"
|
:image-size="200"
|
description="暂无数据"
|
></el-empty>
|
<template>
|
<template v-if="paymentStatus == 0">
|
<div
|
class="bookItem"
|
v-for="(item, index) in collectionList"
|
:key="index"
|
>
|
<div class="wrapImg">
|
<img class="autoImg" :src="item.icon" alt="" />
|
</div>
|
<div class="information">
|
<div>
|
<span class="name ellipsis" @click="toDetail(item)">{{
|
item.name
|
}}</span>
|
<div class="cancelCollection">
|
<span @click="cancleBookCollect(item)">取消收藏</span>
|
</div>
|
</div>
|
<p class="author">
|
作者:{{
|
item.caupress_author ? item.caupress_author : "未知作者"
|
}}
|
</p>
|
<p class="author" v-if="item.caupress_publicationDate">
|
出版时间:{{
|
moment(item.caupress_publicationDate).format("YYYY-MM-DD")
|
}}
|
</p>
|
<p class="author" v-if="item.caupress_ISBN">
|
ISBN:{{ item.caupress_ISBN }}
|
</p>
|
<p class="payPrice">
|
定价:
|
<span
|
>¥ <span>{{ item.price }}</span>
|
</span>
|
</p>
|
</div>
|
</div>
|
</template>
|
<template v-else>
|
<div
|
class="resourcesItem"
|
v-for="(item, index) in orderList"
|
:key="index"
|
>
|
<span @click="preview(item)" class="resourcesPre"
|
>资源名称:
|
<span style="color: #333">{{ item.name }}</span>
|
</span>
|
<span
|
>资源类型:
|
<span style="color: #333">{{
|
RefCodeConvertFormat(item.caupress_fileType)
|
}}</span>
|
<div
|
class="cancelCollection"
|
@click="cancleResourceCollect(item)"
|
>
|
取消收藏
|
</div>
|
</span>
|
</div>
|
</template>
|
</template>
|
</div>
|
<!-- 分页 -->
|
<div
|
class="pageinateBox"
|
v-if="collectionList.length > 0 || orderList.length > 0"
|
>
|
<el-pagination
|
@size-change="
|
(val) => {
|
paginationData.limit = val;
|
if (paymentStatus == 0) {
|
getBookData();
|
} else {
|
getResourceData();
|
}
|
}
|
"
|
@current-change="
|
(val) => {
|
paginationData.page = val;
|
getBookData();
|
if (paymentStatus == 0) {
|
getBookData();
|
} else {
|
getResourceData();
|
}
|
}
|
"
|
background=""
|
:current-page="paginationData.page - 0"
|
:page-size="paginationData.limit"
|
prev-text="上一页"
|
next-text="下一页"
|
layout="total, prev, pager, next, slot, jumper"
|
:total="paginationData.totalCount"
|
>
|
</el-pagination>
|
</div>
|
</div>
|
</template>
|
<script>
|
export default {
|
data() {
|
return {
|
paginationData: {
|
page: 1,
|
totalCount: 0,
|
limit: 5,
|
totalPage: 0,
|
},
|
collectionList: [],
|
paymentStatus: 0,
|
loading: false,
|
orderList: [],
|
};
|
},
|
created() {
|
// 用于恢复 跳转详情页之前的分页
|
if (localStorage.getItem("searchPage")) {
|
this.paginationData = JSON.parse(localStorage.getItem("searchPage"));
|
localStorage.removeItem("searchPage");
|
this.paymentStatus = JSON.parse(localStorage.getItem("insideTabs"));
|
localStorage.removeItem("insideTabs");
|
}
|
if (this.paymentStatus == 0) {
|
this.getBookData();
|
} else {
|
this.getResourceData();
|
}
|
},
|
methods: {
|
RefCodeConvertFormat(refCode) {
|
switch (refCode) {
|
case "caupress_video":
|
return "视频";
|
case "caupress_audio":
|
return "音频";
|
case "caupress_pdf":
|
return "PDF";
|
case "caupress_zip":
|
return "Zip";
|
default:
|
break;
|
}
|
},
|
// 获取图书收藏
|
getBookData() {
|
this.loading = true;
|
this.paginationData.limit = 5;
|
let { limit, page } = this.paginationData;
|
this.paymentStatus == 0 ? "AppUserProductLink" : "AppUserCmsItemLink";
|
let query = {
|
queryType: "AppUserProductLink",
|
linkType: "Favorite",
|
paging: {
|
start: limit * page - limit,
|
size: limit,
|
},
|
sort: [],
|
fields: {
|
caupress_author: [],
|
caupress_ISBN: [],
|
caupress_publicationDate: [],
|
},
|
coverSize: {
|
width: 120,
|
},
|
};
|
this.MG.store.getProductList(query).then((res) => {
|
this.JumpToPreviousPage(res.datas);
|
this.collectionList = res.datas;
|
this.paginationData.totalCount = res.total;
|
this.loading = false;
|
});
|
},
|
// 获取资源收藏
|
getResourceData() {
|
this.loading = true;
|
this.paginationData.limit = 12;
|
let { limit, page } = this.paginationData;
|
this.MG.resource
|
.getItem({
|
path: "*",
|
queryType: "AppUserCmsItemLink",
|
linkType: "Favorite",
|
paging: {
|
start: limit * page - limit,
|
size: limit,
|
},
|
fields: {
|
caupress_author: [],
|
caupress_ISBN: [],
|
caupress_publicationDate: [],
|
caupress_fileType: [],
|
caupress_file: [],
|
},
|
coverSize: {
|
width: 120,
|
},
|
})
|
.then((res) => {
|
this.JumpToPreviousPage(res.datas);
|
this.orderList = res.datas;
|
this.paginationData.totalCount = res.total;
|
this.loading = false;
|
});
|
},
|
// 取消图书收藏
|
cancleBookCollect(item) {
|
this.$confirm("确定取消收藏吗?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
this.loading = true;
|
let data = {
|
productIds: [item.id],
|
linkType: "Favorite",
|
};
|
this.MG.store.delProductLink(data).then((res) => {
|
if (res) {
|
this.loading = false;
|
this.$message({
|
type: "success",
|
message: "取消收藏成功!",
|
});
|
this.getBookData();
|
}
|
});
|
})
|
.catch(() => {
|
this.$message({
|
type: "info",
|
message: "已取消操作",
|
});
|
});
|
},
|
// 取消资源收藏
|
cancleResourceCollect(item) {
|
this.$confirm("确定取消收藏吗?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
this.loading = true;
|
let data = {
|
cmsItemIds: [item.id],
|
linkType: "Favorite",
|
};
|
this.MG.resource.delCmsItemLink(data).then((res) => {
|
if (res) {
|
this.loading = false;
|
this.$message({
|
type: "success",
|
message: "取消收藏成功!",
|
});
|
this.getResourceData();
|
}
|
});
|
})
|
.catch(() => {
|
this.$message({
|
type: "info",
|
message: "已取消操作",
|
});
|
});
|
},
|
// 去往详情页
|
toDetail(item) {
|
let LinkTag = item.datas.LinkTag;
|
// 根据不同页面收藏的跳转不同页面
|
let jumpPath =
|
LinkTag == "bookStore" ? "bookStore-detail" : "teachingServices-detail";
|
this.saveInformation();
|
this.$router.push({
|
name: jumpPath,
|
query: {
|
id: item.id,
|
cmsPath: item.rootCmsItemId,
|
},
|
});
|
},
|
//去资源详情
|
preview(item) {
|
let previewType = item.caupress_fileType.split("_")[1];
|
this.saveInformation();
|
if (previewType == "zip") {
|
this.$message({
|
type: "warning",
|
message: "此文件类型不支持预览",
|
});
|
} else {
|
this.$router.push({
|
name: `preview-${previewType}`,
|
query: {
|
md5: item.caupress_file,
|
titleName: item.name,
|
},
|
});
|
}
|
},
|
// 处理当当前页面的数据已全部取消收藏后,跳转至前一页
|
JumpToPreviousPage(datas) {
|
if (this.paginationData.page > 1 && datas.length == 0) {
|
this.paginationData.page -= 1;
|
this.getBookData();
|
}
|
},
|
// 保存当前页面信息,用于详情页返回时恢复页面数据
|
saveInformation() {
|
localStorage.setItem(
|
"searchPage",
|
JSON.stringify({ ...this.paginationData })
|
);
|
localStorage.setItem("selectedTab", JSON.stringify(2));
|
localStorage.setItem("insideTabs", JSON.stringify(this.paymentStatus));
|
},
|
},
|
};
|
</script>
|
<style lang="less" scoped>
|
.title {
|
font-size: 18px;
|
font-weight: 700;
|
letter-spacing: 1.8px;
|
border-top: 2px solid #008e3f;
|
line-height: 36px;
|
padding-left: 40px;
|
background: #d8f7e6;
|
line-height: 60px;
|
color: #00873c;
|
.splitline {
|
width: 1px;
|
height: 24px;
|
background-color: #008e3f;
|
}
|
}
|
.spaceBetween {
|
padding-left: 0;
|
display: flex;
|
justify-content: space-evenly;
|
align-items: center;
|
span {
|
font-weight: 400;
|
}
|
.paymentStatus {
|
font-weight: 700;
|
}
|
.place {
|
cursor: pointer;
|
}
|
}
|
.content {
|
min-height: 600px;
|
padding: 40px 40px 0 40px;
|
.cancelCollection {
|
cursor: pointer;
|
float: right;
|
color: #e50021;
|
}
|
.bookItem {
|
display: flex;
|
justify-content: space-between;
|
border-bottom: 1px solid #eeeeee;
|
padding-bottom: 40px;
|
margin-bottom: 40px;
|
.wrapImg {
|
position: relative;
|
border: 1px solid #e6e6e6;
|
background: #ffffff;
|
width: 150px;
|
height: 200px;
|
}
|
.information {
|
width: 520px;
|
font-size: 16px;
|
.name {
|
cursor: pointer;
|
width: 450px;
|
display: inline-block;
|
font-size: 24px;
|
font-weight: 700;
|
line-height: 24px;
|
padding-bottom: 20px;
|
color: #333333;
|
}
|
|
.author {
|
color: #666666;
|
padding: 8px 0;
|
}
|
.payPrice {
|
color: #333333;
|
padding: 14px 0;
|
span {
|
font-size: 14px;
|
color: #e50021;
|
span {
|
font-size: 24px;
|
}
|
}
|
}
|
}
|
}
|
.resourcesItem {
|
font-size: 16px;
|
color: #666;
|
display: flex;
|
line-height: 50px;
|
> span {
|
width: 50%;
|
}
|
}
|
}
|
.pageinateBox {
|
text-align: center;
|
padding: 40px 0;
|
:deep(.el-pagination.is-background .btn-next) {
|
padding: 0 10px;
|
}
|
:deep(.el-pagination.is-background .btn-prev) {
|
padding: 0 10px;
|
}
|
}
|
.resourcesPre {
|
cursor: pointer;
|
}
|
</style>
|