<template>
	<view class="booksTheCharts_content">
		<u-navbar title="排行榜" bgColor="transparent" leftIconColor="#000" @leftClick="navbarLeftClick"
			:placeholder="true" :safeAreaInsetTop="true" />
		<!-- 	<uni-nav-bar title="排行榜" :border="false" backgroundColor="transparent" leftIcon="back" @clickLeft="navbarLeftClick">
		</uni-nav-bar> -->
		<view class="booksTheCharts_header_bag"></view>
		<!--  :style="`height:${booksTheChartsContentHeigth}px`"-->
		<view class="booksTheCharts_content_body">
			<view class="booksTheCharts_body_btn_list">
				<scroll-view scroll-x="true" class="btn_list_scroll_view">
					<view :class="[`btn_list_scroll_view_item`,oneTitleActive == m.id ?'active':''] "
						v-for="m in oneTitleList" :key="m.id" :data-id="m.id" @tap="handelOneTitle">{{m.title}}</view>
				</scroll-view>
			</view>
			<view class="booksTheCharts_main_body">
				<view class="_main_body_title_list">
					<!-- :style="`height:${titleListscroll}px`" -->
					<scroll-view scroll-y="true" class="_title_list_scroll_view">
						<view :class="['_title_list_scroll_view_item',m.id == twoTitleActive ? 'active':'']"
							v-for="(m,idx) in twoTitleList" :key="m.id" :data-id="m.id" @tap="handelTwoTitle">
							{{m.name}}
						</view>
					</scroll-view>
				</view>
				<view class="_main_body_book_list">
					<!-- :style="`height:${titleListscroll}px`" -->
					<scroll-view scroll-y="true" class="_book_list_scroll_view">
						<view :class="['_book_list_scroll_view_item']" v-for="(m,idx) in booksList" :key="m.id"
							@tap="toBooksReadingDetail(m)">
							<view class="scroll_view_item_book_image">
								<image class="is_image" :src="m.cover"></image>
							</view>
							<view class="scroll_view_item_book_tips">
								<view class="_book_tips_title">
									{{m.title}}
								</view>
								<view class="_book_tips_msg">
									{{m.category_name}}
								</view>
							</view>
						</view>
						<!-- <view class="_book_list_scroll_view_empty">
							<CommFooter />
						</view> -->
					</scroll-view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		isGetSystemInfo
	} from '@/utils/systemInfo.js'
	import CommFooter from '@/components/commFooter/index.vue'
	import {
		baseUrlImage
	} from '@/utils/utils'
	export default {
		components: {
			CommFooter
		},
		data() {
			return {
				booksTheChartsContentHeigth: 0,
				titleListscroll: 0,
				booksList: [],
				oneTitleList: [],
				twoTitleList: [{
						id: '0',
						name: '全部'
					},
					{
						id: '1',
						name: '人气榜'
					},
					{
						id: '2',
						name: '畅销版'
					},
					{
						id: '3',
						name: '新书榜'
					},
					{
						id: '4',
						name: '完结版'
					}
				],
				twoTitleActive: '0',
				oneTitleActive: '0',
			}
		},
		onLoad(options) {
			const {
				windowHeight,
				screenHeight,
				statusBarHeight,
				devicePixelRatio
			} = isGetSystemInfo();
			this.booksTheChartsContentHeigth = screenHeight - statusBarHeight;
			this.twoTitleActive = options.chartsType ? options.chartsType : '0';
			// #ifdef APP-PLUS
			this.titleListscroll = screenHeight - statusBarHeight;
			// #endif
			// #ifdef H5 || MP-WEIXIN
			this.titleListscroll = screenHeight - statusBarHeight - devicePixelRatio * 55;
			// #endif

		},
		onShow() {
			// 
			uni.showLoading({
				title: '加载中...'
			});
			const data = {}
			uni.$u.http.post('/getCategory', data).then((res) => {
				uni.hideLoading();
				if (res.status == 1) {
					const list = res.data.list;
					this.oneTitleList = [{
						id: '0',
						title: '全部'
					}, ...list];
				}
				this.getBooks(this.twoTitleActive, 0);
			}).catch((err) => {
				uni.hideLoading();
				console.log(err, "========")
				this.getBooks(this.twoTitleActive, 0);
			})
		},
		methods: {
			navbarLeftClick() {
				uni.navigateBack()
			},
			getBooks(type, category_id) {
				uni.showLoading({
					title: '加载中...'
				});
				const parameter = {
					custom: {
						token: true
					}
				}
				const data = {
					type,
					category_id,
				}
				uni.$u.http.post('/getChartsCategory', data, parameter).then((res) => {
					uni.hideLoading();
					if (res.status == 1) {
						const {
							module
						} = res.data;
						this.booksList = baseUrlImage(module);
					}
				}).catch((err) => {
					uni.hideLoading();
					console.log(err, "========")
				})
			},
			handelTwoTitle(event) {
				const id = event.currentTarget.dataset.id;
				this.twoTitleActive = id;
				this.getBooks(id, this.oneTitleActive);
			},
			toBooksReadingDetail(row) {
				uni.navigateTo({
					url: `/pages/booksReadingDetail/booksReadingDetail?sid=${row.id}&t=${row.title}`
				})
			},
			handelOneTitle(event) {
				const id = event.currentTarget.dataset.id;
				this.oneTitleActive = id;
				this.getBooks(this.twoTitleActive, id);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.is_image {
		display: block;
		width: 100%;
		height: 100%;
	}

	::v-deep.u-navbar__content__title {
		font-size: 32rpx;
		font-weight: 700;
	}

	.booksTheCharts_content {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100%;
		overflow: hidden;

		.uni-navbar {
			position: relative;
			z-index: 20;
		}

		.booksTheCharts_header_bag {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 330rpx;
			background: linear-gradient(to left bottom, rgba(252, 194, 202, 0.5), rgba(253, 255, 227, 0.5));

		}

		.booksTheCharts_content_body {
			flex: 1;
			display: flex;
			flex-direction: column;
			width: 100%;
			height: 100%;

			.booksTheCharts_body_btn_list {
				display: flex;
				align-items: center;
				width: 100%;
				height: 110rpx;
				box-sizing: border-box;
				padding: 0 32rpx;
				flex: 0 0 auto;
				position: relative;

				.btn_list_scroll_view {
					white-space: nowrap;

					.btn_list_scroll_view_item {
						display: inline-block;
						background-color: transparent;
						height: 64rpx;
						padding: 0 16rpx;
						color: #222222;
						line-height: 64rpx;
						margin-left: 16rpx;
						border-radius: 16rpx;
					}

					.btn_list_scroll_view_item.active {
						background-color: #FF728F;
						color: #fff;
					}

					.btn_list_scroll_view_item:first-child {
						margin-left: 0;
					}
				}
			}

			.booksTheCharts_main_body {
				flex: 1;
				display: flex;
				width: 100%;
				border-top: 2rpx solid #E5E5E5;
				position: relative;
				z-index: 10;
				box-sizing: border-box;

				._main_body_title_list {

					width: 160rpx;
					height: 100%;
					background-color: #F1EEEC;
					flex: 0 0 auto;
					position: relative;

					._title_list_scroll_view {
						position: absolute;
						top: 0;
						left: 0;
						right: 0;
						bottom: 0;

						._title_list_scroll_view_item {
							position: relative;
							width: 100%;
							height: 124rpx;
							text-align: center;
							line-height: 124rpx;
							color: #666666;
							font-size: 32rpx;
						}

						._title_list_scroll_view_item.active {
							background-color: #fff;
							color: #FF728F;
						}

						._title_list_scroll_view_item.active::before {
							position: absolute;
							top: 0;
							left: 0;
							content: '';
							width: 6rpx;
							height: 124rpx;
							background-color: #FF728F;
						}
					}

				}

				._main_body_book_list {
					width: 100%;
					height: 100%;
					background-color: #fff;
					position: relative;


					._book_list_scroll_view {
						position: absolute;
						top: 0;
						left: 0;
						right: 0;
						bottom: 0;
						padding: 32rpx 32rpx 0;
						padding-bottom: constant(safe-area-inset-bottom);
						/* 兼容 iOS 设备 */
						padding-bottom: env(safe-area-inset-bottom);
						/* 兼容 iPhone X 及以上设备 */
						box-sizing: border-box;

						._book_list_scroll_view_item {
							display: flex;
							width: 100%;
							padding-bottom: 32rpx;

							.scroll_view_item_book_image {
								width: 128rpx;
								height: 170rpx;
								flex: 0 0 auto;
								border-radius: 8rpx;
								overflow: hidden;
								box-shadow: 0 0 8rpx rgba(0, 0, 0, 0.2);
							}

							.scroll_view_item_book_tips {
								flex: 1;
								display: flex;
								flex-direction: column;
								justify-content: space-around;
								padding-left: 28rpx;
								overflow: hidden;

								._book_tips_title {
									font-size: 30rpx;
									line-height: 1;
									color: #1A1A1A;
									white-space: nowrap;
									overflow: hidden;
									text-overflow: ellipsis;
								}

								._book_tips_msg {
									font-size: 28rpx;
									line-height: 1;
									color: #999999;
									// white-space: nowrap;
									// overflow: hidden;
									// text-overflow: ellipsis;
									overflow: hidden;
									text-overflow: ellipsis;
									display: -webkit-box;
									-webkit-line-clamp: 2;
									-webkit-box-orient: vertical;
								}
							}
						}

						._book_list_scroll_view_empty {
							width: 100%;
							height: 60rpx;
						}
					}
				}
			}
		}
	}
</style>