2023-09-22 08:57:23 +08:00

480 lines
11 KiB
Vue

<template>
<view class="bookshelfListBody_content">
<view class="bookshelfListBody_content_header">
<view class="_header_left">
<view class="_header_name" v-if="!swipeActionBatch">
列表
</view>
<view class="_header_name" v-else-if="swipeActionBatch">
<u-checkbox-group @change="handelbookBatch" v-model="delCheckedAll">
<u-checkbox activeColor="#FF728F" labelSize="32rpx" labelColor="#1A1A1A" label="全选"
name="all" />
</u-checkbox-group>
</view>
</view>
<view class="_header_right">
<view class="_header_right_edit" @tap="handelSwipeBatch" v-if="!swipeActionBatch">
批量编辑
</view>
<view class="_header_right_confim" v-else-if="swipeActionBatch" @tap="bathComplete">
完成
</view>
</view>
</view>
<view class="bookshelfListBody_content_body">
<view class="_content_body_list">
<view class="_swipe_action_box" @longpress="swipeActionLongpress(m)" v-for="m in bookshelfList"
:key="m.id">
<view class="_swipe_action_box_book_image">
<image class="is_image" :src="m.cover" />
</view>
<view class="_swipe_action_book_info">
<view class="_book_info_title">
{{m.title}}
</view>
<view class="_book_info_chapter">
{{m.history_txt}}
</view>
<view class="_book_info_tips">
{{m.txt}}
</view>
</view>
<view class="_swipe_action_book_button" v-if="swipeActionList.indexOf(m.id) == -1">
<view class="_book_button_text" v-if="!swipeActionBatch" @tap="toNovelReading(m)">
去阅读
</view>
<view class="_book_button_checkbox_box" v-else-if="swipeActionBatch">
<u-checkbox-group @change="handelcheckbox($event,m)" v-model="m.checkedFlag">
<u-checkbox :name="m.id" activeColor="#FF728F" />
</u-checkbox-group>
</view>
</view>
<view class="_swipe_action_book_del" v-else @tap="deleteBook(m)">
删除
</view>
</view>
<!-- <view class="_swipe_action_box" @longpress="swipeActionLongpress(m)" v-for="m in bookshelfList"
:key="m.id">
<fui-swipe-action @click="onClick">
<view class="_swipe_action_box_book_image">
<image class="is_image" :src="m.cover" />
</view>
<view class="_swipe_action_book_info">
<view class="_book_info_title">
{{m.title}}
</view>
<view class="_book_info_chapter">
{{m.history_txt}}
</view>
<view class="_book_info_tips">
{{m.txt}}
</view>
</view>
<view class="_swipe_action_book_button" v-if="swipeActionList.indexOf(m.id) == -1">
<view class="_book_button_text" v-if="!swipeActionBatch" @tap="toNovelReading(m)">
去阅读
</view>
<view class="_book_button_checkbox_box" v-else-if="swipeActionBatch">
<u-checkbox-group @change="handelcheckbox($event,m)" v-model="m.checkedFlag">
<u-checkbox :name="m.id" activeColor="#FF728F" />
</u-checkbox-group>
</view>
</view>
<view class="_swipe_action_book_del" v-else @tap="deleteBook(m)">
删除
</view>
</fui-swipe-action>
</view> -->
<view class="_swipe_action_box" @tap="toBookCity">
<view class="_swipe_action_add_img_box">
<view class="_swipe_action_add_img">
<image class="is_image" src="/static/images/bookshelf/_swipe_add.png" />
</view>
</view>
<view class="_swipe_action_no_tips">
去找书
</view>
</view>
</view>
</view>
<u-popup :show="swipeActionBatch" mode="bottom" :overlay="false" bgColor="transparent" zIndex="999"
:safeAreaInsetBottom="false">
<view class="bookshelf_checked_all_del" @tap="checkedAllDel">
<view class="_all_del_button">
<image v-if="booksIds.length" class="is_image" src="/static/images/bookshelf/del_all.png" />
<image v-else class="is_image" src="/static/images/bookshelf/del_all_checked.png"></image>
</view>
</view>
</u-popup>
</view>
</template>
<script>
import config from '@/config/index';
import {
isGetSystemInfo
} from '@/utils/systemInfo.js'
export default {
data() {
return {
swipeActionList: [],
swipeActionBatch: false,
bookshelfList: [],
delCheckedAll: [],
booksIds: [],
// options1: [{
// text: '删除',
// style: {
// backgroundColor: '#FF728F'
// }
// }],
}
},
mounted() {
const {
windowHeight = 0, screenHeight = 0, windowTop = 0
} = isGetSystemInfo();
const footerSafeHeight = screenHeight - windowHeight - windowTop;
if (footerSafeHeight) {
this.footerSafeHeight = footerSafeHeight;
}
},
methods: {
getBooksData() {
// uni.showLoading({
// title: '加载中...'
// });
const data = {}
uni.$u.http.post('/getBookshelf', data).then((res) => {
// setTimeout(() => {
// uni.hideLoading();
// }, 1000);
if (res.status == 1) {
const {
module
} = res.data;
if (Array.isArray(module)) {
this.bookshelfList = module.map((m, idx) => {
return {
...m,
cover: `${config.baseUrl}${m.cover}`,
checkedFlag: [],
}
});
} else {
this.bookshelfList = [];
}
}
}).catch((err) => {
// setTimeout(() => {
// uni.hideLoading();
// }, 1000);
console.log(err, "========")
})
},
// 长安删除多个
swipeActionLongpress(row) {
if (!this.swipeActionBatch) {
const swipeActionList = [...this.swipeActionList];
if (swipeActionList.indexOf(row.id) != -1) {
this.swipeActionList = swipeActionList.filter((m) => m != row.id);;
} else {
this.swipeActionList = [...swipeActionList, row.id];
}
}
},
// 批量选择
handelSwipeBatch() {
uni.hideTabBar({
animation: true
})
this.swipeActionBatch = true;
this.swipeActionList = [];
this.$emit('bookshelfContentBodyZindexFn', 999);
},
// 去书城
toBookCity() {
uni.reLaunch({
url: '/pages/bookCity/bookCity/index'
});
},
// 删除单个
deleteBook(row) {
this.handelDeleteBookFn([row.id]);
},
// 选择全部
handelbookBatch(isCheckeds) {
this.delCheckedAll = isCheckeds;
const bookshelfList = [...this.bookshelfList];
const ids = [];
this.bookshelfList = bookshelfList.map((m) => {
ids.push(m.id);
return {
...m,
checkedFlag: isCheckeds.length ? [m.id] : [],
}
})
this.booksIds = ids;
},
handelcheckbox(e, row) {
const booksIds = [...this.booksIds];
if (e.length) {
this.booksIds = [...booksIds, row.id];
this.delCheckedAll = this.booksIds.length == this.bookshelfList.length ? ['all'] : [];
} else {
this.delCheckedAll = [];
this.booksIds = booksIds.filter((m) => m != row.id);
}
},
handelDeleteBookFn(ids, allType = false) {
uni.showLoading({
title: '加载中...'
});
const parameter = {
custom: {
token: true
}
}
const data = {
ids: JSON.stringify(ids),
}
uni.$u.http.post('/delBookshelf', data, parameter).then((res) => {
uni.hideLoading();
if (res.status == 1) {
this.getBooksData();
if (allType) {
this.bathComplete();
}
}
}).catch((err) => {
uni.hideLoading();
console.log(err, "========")
})
},
checkedAllDel() {
this.handelDeleteBookFn(this.booksIds, true);
},
// 选择全部之后完成
bathComplete() {
this.swipeActionBatch = false;
uni.showTabBar({
animation: true
})
this.delCheckedAll = [];
this.booksIds = [];
this.$emit('bookshelfContentBodyZindexFn', 2);
const bookshelfList = [...this.bookshelfList];
this.bookshelfList = bookshelfList.map((m) => {
return {
...m,
checkedFlag: [],
}
})
},
toNovelReading(row) {
uni.navigateTo({
url: `/pages/booksReadingDetail/booksReadingDetail?sid=${row.sid}&t=${row.title}`
})
}
}
}
</script>
<style lang="scss" scoped>
.is_image {
display: block;
width: 100%;
height: 100%;
}
::v-deep.u-checkbox {
margin-bottom: 0;
margin-top: 0;
}
.bookshelfListBody_content {
width: 100%;
.bookshelfListBody_content_header {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
height: 40rpx;
._header_left {
._header_name {
font-size: 32rpx;
line-height: 1;
color: #1A1A1A;
}
}
._header_right {
._header_right_edit {
font-size: 28rpx;
line-height: 1;
color: #929292;
}
._header_right_confim {
font-size: 32rpx;
line-height: 1;
color: #1A1A1A;
}
}
}
.bookshelfListBody_content_body {
width: 100%;
._content_body_list {
width: 100%;
// .bookshelf_list_swipe_action {
// width: 100%;
._swipe_action_box {
display: flex;
width: 100%;
height: 192rpx;
overflow: hidden;
position: relative;
margin-top: 32rpx;
margin-bottom: 32rpx;
._swipe_action_box_book_image {
width: 144rpx;
height: 192rpx;
flex: 0 0 auto;
border-radius: 8rpx;
overflow: hidden;
box-shadow: 0 0 8rpx rgba(0, 0, 0, 0.2);
}
._swipe_action_book_info {
flex: 1;
display: flex;
flex-direction: column;
padding-left: 28rpx;
padding-top: 16rpx;
padding-bottom: 16rpx;
flex-shrink: 0;
._book_info_title {
width: 100%;
font-size: 32rpx;
line-height: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #1A1A1A;
}
._book_info_chapter {
width: 100%;
font-size: 26rpx;
line-height: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #6F6F6F;
margin-top: 36rpx;
}
._book_info_tips {
width: 100%;
font-size: 24rpx;
line-height: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #999999;
margin-top: 20rpx;
}
}
._swipe_action_book_button {
display: flex;
align-items: center;
justify-content: flex-end;
width: 100rpx;
height: 100%;
flex: 0 0 auto;
._book_button_text {
font-size: 28rpx;
color: #FF728F;
line-height: 1;
}
}
._swipe_action_book_del {
position: absolute;
top: 0;
right: 0;
width: 100rpx;
height: 192rpx;
text-align: center;
line-height: 192rpx;
color: #ffffff;
background-color: #FF728F;
font-size: 28rpx;
}
._swipe_action_add_img_box {
display: flex;
justify-content: center;
align-items: center;
width: 144rpx;
height: 192rpx;
flex: 0 0 auto;
background-color: #F6F6F6;
._swipe_action_add_img {
width: 42rpx;
height: 42rpx;
}
}
._swipe_action_no_tips {
flex: 1;
display: flex;
align-items: center;
padding-left: 28rpx;
font-size: 32rpx;
color: #AAAAAA;
}
}
// }
}
}
.bookshelf_checked_all_del {
// position: fixed;
// bottom: 0;
// left: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 130rpx;
z-index: 1000;
background-color: #fff;
padding-bottom: constant(safe-area-inset-bottom);
/* 兼容 iOS 设备 */
padding-bottom: env(safe-area-inset-bottom);
._all_del_button {
width: 150rpx;
height: 56rpx;
}
}
}
</style>