<template>
	<view class="container">
		<z-nav-bar title="经典查阅"></z-nav-bar>
		<view>
			<view class="home_bg">
				<view class="icon_hua">
					<image src="../../static/icon/home_icon_3.png" mode="aspectFit" class="icon_hua_1"></image>
				</view>
				<view class="hehan">
					<image src="../../static/icon/hehan.png" mode="aspectFit" class="icon_hua_1"></image>
				</view>
				<!-- 	<view class="search_box flexbox" @click="onPageJump('../peanut/searchFor')">
					<view class="search">
						<text class="icon_search"></text>
						<text class="prompt">请输入书名</text>
					</view>
				</view> -->
			</view>
			<view class="mytabs">
				<view :class="['item','item1', contentShow == 1 ? 'active' :'']" @click="TabData(1)">
					中医经典
				</view>
				<view :class="['item','item2', contentShow == 2 ? 'active' :'']" @click="TabData(2)">
					国学经典
				</view>
			</view>


			<view class="listenList">
				<view class="" v-if="bookList.length > 0">
					<u-row gutter="16" justify="flex-start">
						<u-col span="12" v-for="(item,index) in bookList" :key="index">
							<view>
								<view class="flexbox yigoumaiList">
									<view class="info">
										<view class="videoBox demo-layout bg-purple" @click="goDetail(item)">
											<image v-if="item.images != '' && item.images != null" :src="item.images"
												mode="scaleToFill"></image>
											<image v-else src="../../static/icon/wufeng.jpg" mode="scaleToFill"></image>
										</view>
									</view>
									<view class="btns">
										<view class="text">
											<view class="bookName" @click="goDetail(item)">{{item.name}}</view>
											<!-- <view class="author">												
													作者：<text v-if="item.authorName == null || item.authorName == ''">暂无</text>
													<text v-else>{{item.authorName}}</text>
												</view> -->
										</view>

										<view class="flexbox icons" v-if="iosHide">
											<!-- 	<view class="item ">
												<view @click="goRead(item)">
													<image src="../../static/icon/home6.png" mode="aspectFit"></image>
												</view>
												<view class="v1"><text>读 书</text></view>
											</view> -->
											<view class="item ">
												<view v-if="item.clockIn != null && item.clockIn != 2"
													@click="goDaKa(item)">
													<image src="../../static/icon/home1.png" mode="aspectFit"></image>
												</view>
												<view v-else @click="noOp()">
													<image class="gray" src="../../static/icon/home1.png"
														mode="aspectFit"></image>
												</view>
												<view class="v1"><text>打 卡</text></view>
											</view>
											<view class="item ">
												<view v-if="item.canListen" @click="goToListenFree(item)">
													<image src="../../static/icon/home2.png" mode="aspectFit"></image>
												</view>
												<view v-else @click="noOp()">
													<image class="gray" src="../../static/icon/home2.png"
														mode="aspectFit"></image>
												</view>
												<view class="v1"><text>听 书</text></view>
											</view>
											<!-- <view class="item " @click="goPingshu(item)">
												<view class="">
													<image src="../../static/icon/home3.png" mode="aspectFit"></image>
												</view>
												<view class="v1"><text>书 评</text></view>
											</view>
											<view class="item ">
												<view class="" v-if="item.teachIn != null && item.teachIn != 0"
													@click="goJiangShu(item)">
													<image src="../../static/icon/home4.png" mode="aspectFit"></image>
												</view>
												<view class="" v-else @click="noOp()">
													<image class="gray" src="../../static/icon/home4.png"
														mode="aspectFit"></image>
												</view>
												<view class="v1">
													<text>讲 书</text>
												</view>
											</view> -->
										</view>
									</view>
								</view>

							</view>
						</u-col>
					</u-row>
					<view>
						<view v-if="status==0" style="text-align: center;">
							<u-loading-icon style="display: inline-block;"></u-loading-icon>
							<font style='vertical-align: super;margin-left: 10px;font-size: 26rpx;color: #909399;'>努力加载中
							</font>
						</view>
						<view v-if="status==1">
							<u-divider text="全部加载完成"></u-divider>
						</view>
					</view>
				</view>
				<u-divider v-else text="暂无经典查阅图书~"></u-divider>
			</view>



		</view>


		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<z-navigation></z-navigation>
	</view>
</template>

<script>
	import $http from '@/config/requestConfig.js';
	import {
		mapState
	} from 'vuex';

	export default {
		data() {
			return {
				searchValue: '',
				contentShow: 1,
				page: 1,
				totalPage: 1,
				status: 3,
				bookList: [],
			}
		},
		onShow() {

		},
		onLoad() {
			this.bookList = []
			this.getData()
		},

		onHide() {
			this.page = 1
		},
		onPullDownRefresh() {
			console.log('下拉刷新了')
			// this.contentShow = 1
			this.page = 1
			this.getData()
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			// this.loadingNow = true
			console.log('到底了')
			if (this.page + 1 <= this.totalPage) {
				this.page++
				this.getData()
			} else {
				this.status = 1
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		methods: {
			// 获取数据列表
			getData() {
				$http.request({
					url: "book/book/getClassicsBookList",
					method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
					data: {
						'bookType': this.contentShow,
						'page': this.page,
						'limit': 10
					},
					header: { //默认 无 说明：请求头
						'Content-Type': 'application/json'
					},
				}).then(res => {
					if (res.code == 0) {
						console.log(res, '获取经典查阅书籍')
						if (res.page.records.length > 0) {
							for (var i = 0; i < res.page.records.length; i++) {
								this.bookList.push(res.page.records[i])
							}
							this.totalPage = res.page.pages
							if (this.page == this.totalPage) {
								this.status = 1
							} else {
								this.status = 3
							}
						}
					}

				});

			},


			// 搜索
			checkDisable() {

			},

			searchList(res) {
				console.log(res, 'res')
				// uni.showToast({
				// 	title: '搜索：' + res,
				// 	icon: 'none'
				// })
				if (res == '') {
					this.showSearchList = false
					this.searchList = []
				} else {
					this.getSearch()
				}

			},
			inputBook(res) {
				console.log('----input:', res)
				if (res == '') {
					this.searchList = []
				} else {
					this.getSearch()
				}
			},
			clearBook(res) {
				console.log('----clear:', res)
				// uni.showToast({
				// 	title: 'clear事件，清除值为：',
				// 	icon: 'none'
				// })
				this.searchValue = ''
				this.showSearchList = false
			},
			blurBook(res) {
				// console.log('----blur:', res)
				// if (res == '') {
				// 	this.showSearchList = false
				// 	this.searchList = []
				// } else {
				// 	this.getSearch()
				// }
			},
			focusBook(e) {
				console.log('----focus:')
				// uni.showToast({
				// 	title: 'focus事件，输出值为：' + e.value,
				// 	icon: 'none'
				// })
				// 等于1 就是有权限
				// this.showSearchList = true

			},


			// 切换
			TabData(e) {
				this.contentShow = e
				this.page = 1
				this.bookList = []
				this.getData()
			},


			// 读书
			goRead(e) {

			},

			// 跳转到打卡
			goDaKa(val) {
				uni.navigateTo({
					url: '../clock/clock?bookid=' + val.id
				})
			},
			// 跳转到听书详情
			goToListenFree(item) {
				// console.log(item,'item')								
				uni.navigateTo({
					url: "../listen/listen?bookid=" + item.id // 前台播放版本
				});
			},
			// 跳转详情页
			goDetail(item) {
				uni.navigateTo({
					url: '../eBook/bookContent?Id=' + item.id
				});
			},
			// 点不过去的
			noOp() {
				uni.showToast({
					title: '该书未开通此功能',
					icon: 'none'
				})
			},
		},

		components: {

		},
	}
</script>

<style lang="scss" scoped>
	* {
		font-size: 28rpx;
	}

	.flexbox {
		display: flex;
	}

	.u-row {
		flex-wrap: wrap;
	}

	.u-col {
		overflow: hidden;
		margin-bottom: 30rpx;
		overflow: hidden;
	}

	uni-image {
		width: auto !important;
		height: 350rpx;
	}

	.home_bg {
		background-image: url('../../static/icon/home_bg.jpg');
		background-position: center center;
		background-repeat: no-repeat;
		background-size: cover;
		padding: 20rpx;
		position: relative;

		// margin-bottom:60rpx;
		// height: 400rpx; margin-bottom: 130rpx;
		.icon_hua_1 {
			// margin: 0 auto;
			width: 100%;
			text-align: center;
			height: 80rpx;
			margin-bottom: 20rpx;

			image {
				width: 150rpx;
				height: 80rpx;
			}
		}

		.icon_hua {
			width: 100%;
			text-align: center;
			display: block;

			image {
				width: 150rpx;
				height: 150rpx;
				margin: 0 auto;
			}
		}

		.hehan {
			width: 50%;
			margin: 0 auto;
		}

		.search_box {
			margin: 10rpx auto 0 auto;
			margin-top: 20rpx;
			align-items: center;
			width: calc(100% - 30rpx);
			margin-top: 0;
			margin-bottom: 20rpx;

			.search {
				height: 56upx;
				display: flex;
				width: 86%;
				margin: 0 auto;
				align-items: center;
				padding: 0upx 40upx;
				background-color: #fff;
				border-radius: 20upx;
				box-shadow: 0 0px 10px 1px #54a96633;
			}

			.prompt {
				color: #838383;
				font-size: 24rpx;

			}

			.icon_search {
				background-image: url('@/static/icon/map_ic_search.png');
				background-position: center center;
				background-repeat: no-repeat;
				background-size: cover;
				width: 36upx;
				height: 36upx;
				margin-right: 20upx;
			}
		}


	}


	.mytabs {
		margin: 30rpx auto 30rpx auto;
		height: 80rpx;
		padding: 0 20rpx;
		display: flex;

		.item {
			border-radius: 10rpx;
			background-color: #c6ead0;
			width: 48%;
			// margin: 0 10rpx;
			text-align: center;
			color: #3c7f56;
			font-size: 36rpx;
			line-height: 80rpx;
		}

		.item.active {
			background-color: #3c7f56;
			color: #fff;
		}

		.item1 {
			margin-right: 20rpx;
		}
	}


	.listenList {
		padding: 0 20rpx;
		box-sizing: border-box;
		width: calc(100% - 10rpx);



		.yigoumaiList {
			background-color: #fff;

			.btns {
				margin-left: 20rpx;
				width: calc(100% - 200rpx);
				box-sizing: border-box;
				font-size: 34rpx;
				justify-content: space-between;

				.item {
					margin-bottom: 30rpx;
					width: 20%;
					text-align: center;

					image {
						display: block;
						height: 108rpx;
					}

					.v1 {
						margin-top: -10rpx;
					}
				}
			}

			.author {
				font-size: 28rpx;
				color: #999;
			}

			.info {
				width: 200rpx;

				image {
					width: 100%;
					height: 280rpx;
					border-radius: 20rpx;
				}
			}

			.icons {
				margin-top: 10rpx;

				text {
					font-size: 26rpx;
					margin-top: -10rpx;
					color: #999;
				}
			}


			.bookName {
				margin-top: 10rpx;
				display: block;
				white-space: nowrap;
				// font-weight: bold;
				overflow-x: hidden;
				text-overflow: ellipsis;
				font-size: 30rpx;
				color: #333;
				padding: 10rpx 0;
			}
		}
	}

	.gray {
		-webkit-filter: grayscale(100%);
		-moz-filter: grayscale(100%);
		-ms-filter: grayscale(100%);
		-o-filter: grayscale(100%);
		filter: grayscale(100%);
		filter: gray;
	}
</style>