<template>
	<view class="page">
		<image class="back1" src="../../static/images/bj.png" mode=""></image>
		<view class="index-navbar">
			<view class="" style="position: relative;">
				<image class="back1" style="height: 200rpx;" src="../../static/images/bj.png" mode="s"></image>
				<u-navbar title-width='300' title='' :is-back="false" :border-bottom="false"
					:background="{background:'rgba(0,0,0,0)'}" :isFixed="true">
					<view class="u-flex u-row-between" style="padding: 0  28rpx ;width: 100vw;">
						<view class="">
							logo
						</view>
						<view class="index-search u-flex" style="margin-left: 54rpx;" @click="toindexsearch">
							<u-icon name="search" color="#979797" size="30"></u-icon>
							<input style="margin-left: 12rpx;" type="text" class="text1" placeholder="请输入书名、作者搜索"
								:disabled="true">
						</view>
						<view class="button u-flex u-row-center">
							<image src="../../static/images/release.png"
								style="width: 24rpx; height: 24rpx;margin-right: 8rpx;" mode="">
							</image>
							<text @click='contribute'>投稿</text>
						</view>
					</view>
				</u-navbar>
				<!-- <view class="back"></view> -->
			</view>
			<view class="u-flex u-row-between pad" style="margin-top:36rpx ;">
				<view class="" v-for="(item,index) in list" :key="index" @click="onchange(index)">
					<text :class="curret==index?'one':'two' ">{{item}}</text>
					<view v-if="curret==index" class="bottom">
					</view>
				</view>
			</view>
		</view>
		<view class="" style="height: 200rpx;"></view>
		<view v-if="curret==0" class="back pad">
			<view class="wrap" v-if="curret==0">
				<swiper class="swiper" style="height: 280rpx;border-radius: 20rpx;" circular>
					<swiper-item v-for="(item,index) in imagelist" :key="index" @click="toinfo(item.jump_id,item.jump_type)">
						<image style="width: 100%;height: 100%;border-radius: 20rpx;" mode="scaleToFill"
							:src="item.image"></image>
					</swiper-item>
				</swiper>
			</view>
			<view class="jiang">
				<view class="u-flex u-row-between">
					<text class="title1">获奖教材</text>
					<view class="look" @click="tomore(3)">查看更多</view>
				</view>
				<view class="cai u-flex ">
					<view class="item " v-for="(item,index) in awardlist.slice(0,6)" :key="index"
						@click="toinfo(item.id)">
						<image :src="item.image" class="bookimg" mode=""></image>
						<view class="title2 u-line-1">
							{{item.title}}
						</view>
						<view class="u-line-1 author">
							{{item.author}}
						</view>
						<view class="bottom1">
							<text class="ding">定价</text>
							<text class="money" v-if="item.book_type==0">{{item.entity_price}}</text>
							<text class="money" v-if="item.book_type==1">{{item.price}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="newbox">
				<view class="u-flex u-row-between">
					<text class="title1">新书推荐</text>
					<view class="look" @click="tomore(4)">查看更多</view>
				</view>
				<view class="cai u-flex ">
					<view class="item " v-for="(item,index) in newlist.slice(0,6)" :key="index"
						@click="toinfo(item.id)">
						<image :src="item.image" class="bookimg" mode=""></image>
						<view class="title2 u-line-1">
							{{item.title}}
						</view>
						<view class="u-line-1 author">
							{{item.author}}
						</view>
						<view class="bottom1">
							<text class="ding">定价</text>
							<text class="money" v-if="item.book_type==0">{{item.entity_price}}</text>
							<text class="money" v-if="item.book_type==1">{{item.price}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="" style="height: 30rpx;"></view>
		</view>
		<view v-show="curret==1" style="position: relative;z-index: 1;margin-top: 24rpx;" class="">
			<ty-paper ref='paper'></ty-paper>
		</view>
		<view v-show="curret==2" style="position: relative;z-index: 1;margin-top: 24rpx;" class="">
			<ty-electronic ref='electronic'></ty-electronic>
		</view>
		<view v-if="curret==3" style="position: relative;z-index: 1;margin-top: 24rpx;" class="">
			<ty-video></ty-video>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					'首页', '纸质书', '电子书', '名师教学视频'
				],
				curret: 0,
				page: 1,
				limit: 10,
				page1: 1,
				limit1: 10,
				awardlist: [],
				newlist: [],
				imagelist: []
			}
		},
		onLoad() {
			this.getnewlist()
			this.getawardslist()
			this.getBanner()
		},
		methods: {
			tomore(index) {
				this.curret = 1
				this.$refs.paper.current = index
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				})
			},
			//轮播图
			getBanner() {
				this.$u.post('/api/banner/getBanner').then(res => {
					if (res.code == 1) {
						this.imagelist = res.data
						console.log('imagelist', this.imagelist);
					}
				})
			},
			// 新书推荐
			getnewlist() {
				this.$u.post('api/books/getBooksList', {
					is_new_recommend: 0,
					page: this.page,
					limit: this.limit
				}).then(res => {
					this.newlist = res.data.data
				})
			},
			//获奖推荐
			getawardslist() {
				this.$u.post('api/books/getBooksList', {
					is_awards: 0,
					page: this.page1,
					limit: this.limit1
				}).then(res => {
					// console.log('award', res);
					this.awardlist = res.data.data
				})
			},
			onchange(index) {
				this.curret = index
				if (this.curret == 0) {
					this.getnewlist()
					this.getawardslist()
					this.getBanner()
				}
				if(this.curret==1){
					this.$refs.paper.getBooksList()
				}
				if(this.curret==2){
					this.$refs.electronic.getBooksList()
				}
			},
			toindexsearch() {
				uni.navigateTo({
					url: "/pages/index/index-search"
				})
			},
			toinfo(id, type = 0) {
				if (type == 0) {
					uni.navigateTo({
						url: '/pages/index/bookinfo?id=' + id
					})
				}
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/index/video?id=' + id
					})
				}
			},
			contribute() {
				if(uni.getStorageSync('token')){
					uni.navigateTo({
						url: '/pages/index/contribute'
					})
				}else{
					this.$u.toast('请登录后操作')
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.item2 {
		margin-top: 24rpx;
	}

	.title3 {
		width: 314rpx;
		height: 40rpx;
		font-size: 28rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #333333;
		margin-top: 16rpx;
	}

	.video {
		flex-wrap: wrap;
	}

	.newbox {
		// width: 702rpx;
		min-height: 870rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin-top: 20rpx;
		padding: 28rpx 20rpx;
	}

	.bottom1 {
		margin-top: 16rpx;
	}

	.item {
		margin-top: 20rpx;
	}

	.money {
		font-size: 28rpx;
		font-family: SFPro, SFPro;
		font-weight: 400;
		color: #CC3300;
		margin-left: 8rpx;
	}

	.ding {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #222222;
	}

	.author {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #444444;
		margin-top: 8rpx;
		width: 202rpx;
		height: 34rpx;
	}

	.author2 {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #444444;
		margin-top: 8rpx;
		width: 322rpx;
	}

	.title2 {
		width: 198rpx;
		height: 36rpx;
		font-size: 26rpx;
		font-family: SFPro, SFPro;
		font-weight: 500;
		color: #333333;
		line-height: 30rpx;
		margin-top: 16rpx;
	}

	.bookimg {
		width: 202rpx;
		height: 266rpx;
		background: #D8D8D8;
		border-radius: 8rpx;
	}

	.cai {
		padding-top: 10rpx;
		flex-wrap: wrap;
	}

	.look {
		width: 130rpx;
		height: 40rpx;
		background: rgba(6, 169, 113, 0.1);
		border-radius: 24rpx;
		font-size: 20rpx;
		font-weight: 400;
		color: #06A971;
		line-height: 40rpx;
		text-align: center;
		// padding: 6rpx 12rpx;
		box-sizing: border-box;
	}

	.title1 {
		font-size: 32rpx;
		font-family: STSongti-SC, STSongti-SC;
		font-weight: bold;
		color: #000000;
	}

	.jiang {
		// width: 702rpx;
		// height: 978rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		padding: 28rpx 20rpx;
		margin-top: 28rpx;
	}

	.back {
		position: relative;
		min-height: 80vh;
		z-index: 99;
	}

	.wrap {
		margin-top: 40rpx;
		height: 280rpx;
		border-radius: 20rpx;
	}

	.pad {
		padding: 0 28rpx;
		// height: 21px;
	}

	.one {
		font-size: 32rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #222222;
	}

	.two {
		font-size: 30rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #555555;
	}

	.bottom {
		width: 64rpx;
		height: 12rpx;
		background: linear-gradient(270deg, rgba(6, 169, 113, 0) 0%, #0ED4AA 100%);
		margin-top: -15rpx;
	}

	.index-search {
		width: 414rpx;
		height: 60rpx;
		background: #FFFFFF;
		border-radius: 38rpx;
		padding-left: 34rpx;
	}

	.page {
		// padding: 0 28rpx;
		// min-height: 92.5vh;
		background: rgba(243, 243, 243, 1);
		position: relative;
		z-index: 1;
	}

	.button {
		width: 128rpx;
		height: 60rpx;
		background: #06A971;
		border-radius: 30rpx;
		// margin-left: 24rpx;
		line-height: 60rpx;
		text-align: center;
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}

	.back1 {
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
		width: 100vw;
		height: 432rpx;
	}

	.index-navbar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		z-index: 999;

		// overflow: hidden;
	}

	.cai :not(:last-child) {
		margin-right: 8rpx;
	}
</style>