<template>
	<view class="page">
		<view class="padd">
			<view class="wrap">
				<u-swiper :list="list1" mode='number' height='750' indicator-pos="bottomRight"></u-swiper>
			</view>
			<view class="back" style="margin-top: 24rpx;">
				<view class="">{{datainfo.title}}</view>
				<view class="item-jian">教材级别：{{datainfo.level.title}}</view>
				<view class="item-jian">适用层次：{{datainfo.arrangement.title}}</view>
				<view class="item-jian">适用专业：{{datainfo.speciality.title}}</view>
				<view class="item-jian">ISBN：{{datainfo.isbn}}</view>
				<view class="item-jian">作者：{{datainfo.author}}</view>
				<view class="item-jian" v-if="datainfo.is_free==1">纸质定价：¥{{datainfo.entity_price}}</view>
			</view>
		</view>
		<view class="height"></view>
		<view class="series" v-if="datainfo.is_series==0">
			<view class="u-flex u-row-between">
				<view class="abount">相关系列</view>
				<view class="updown" @click="toupdown(2)">系列下载</view>
			</view>
			<view class="" style="margin-top: 24rpx;">
				<swiper style="height: 400rpx;" class="swiper" circular :indicator-dots="true" :autoplay="true">
					<swiper-item v-for="(parent,index) in swiptlist" :key="index">
						<view class="u-flex  swiper-item">
							<view class="" v-for="child in parent" @click="toinfo(child.id)">
								<image :src="child.image" style="width: 196rpx;height: 280rpx;" mode=""></image>
								<view class="u-line-1" style="width: 196rpx;">{{child.title}}</view>
								<view class="">
									定价：<span style="color:rgba(204, 51, 0, 1) ;">¥{{child.price}}</span>
								</view>
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<view class="height"></view>
		<view class="content">
			<view class="">
				<u-tabs active-color='#06A971' :list="list" :is-scroll="false" :current="current"
					@change="change"></u-tabs>
			</view>
			<view v-if="current==0" class="padd content-box">
				<view class="u-flex">
					<view class="">
						<view class="chu">开本:{{datainfo.format}}</view>
						<view class="chu">印制:{{datainfo.print}}</view>
						<view class="chu">版次:{{datainfo.edition}}</view>
					</view>
					<view class="" style="margin-left: 100rpx;">
						<view class="chu">印张:{{datainfo.sheet}}</view>
						<view class="chu">出版日期:{{pubdate}}</view>
						<view class="chu">出版单位:{{datainfo.publisher}}</view>
					</view>
				</view>
				<view class="tu">
					<view class="" style="position: relative;">
						<view class="brief">前言</view>
						<image class="image" src="/static/images/compile.png" mode=""></image>
					</view>
					<view class="fonta" v-html="datainfo.preface">
						<!-- {{}} -->
					</view>
				</view>
				<view class="tu">
					<view class="" style="position: relative;">
						<view class="brief">内容简介</view>
						<image class="image" src="/static/images/compile2.png" mode=""></image>
					</view>
					<view class="fonta" v-html='datainfo.content_desc'>
						<!-- {{}} -->
					</view>
				</view>
				<view class="tu">
					<view class="" style="position: relative;">
						<view class="brief">作者简介</view>
						<image class="image" src="/static/images/compile2.png" mode=""></image>
					</view>
					<view class="fonta" v-html="datainfo.author_desc">
						<!-- {{}} -->
					</view>
				</view>
			</view>
			<view v-if="current==1" class="padd data">
				<!-- 样章 -->
				<view class="" v-if="specimen_file.length>0">
					<view class="sample">样章</view>
					<view @click='toyang(item.url)' class="" v-for="(item,index) in specimen_file" :key="index"
						style="display: flex;margin-top: 28rpx;">
						<view class="" style="display: flex;">
							<image src="/static/images/pdf.png" class="image3" mode=""></image>
							<view class="pdf u-line-1" style="width: 530rpx;">{{item.title}}</view>
						</view>
						<image src="/static/images/updown.png" mode="" style="width: 32rpx;height: 32rpx;"></image>
					</view>
				</view>
				<view class="">
					<view class="sample u-flex u-row-between">
						<view class="">资源包</view>
						<view v-if="datainfo.is_free==1&&book_type==0" class="u-flex">
							<view class="selling">资源售价</view>
							<!-- <view class="selling">纸质售价</view> -->
							<view class="money5">¥{{price}}</view>
							<view class="button4" @click="orderinfo">付费下载</view>
						</view>
					</view>
					<view class="courseware">课件</view>
					<view @click='touser(item.url)' v-for="(item,index) in courseware_file" :key="index" class=""
						style="display: flex;margin-top: 28rpx;justify-content: space-between;">
						<div style="display: flex;">
							<image src="/static/images/video.png" class="image3" mode=""></image>
							<view class="pdf u-line-1" style="width: 530rpx;">{{item.title}}</view>
						</div>
						<image src="/static/images/updown.png" mode="" style="width: 32rpx;height: 32rpx;"></image>
					</view>
					<view class="" v-if="resource_file.length>0">
						<view class="courseware">资源</view>
						<view @click='touser(item.url)' v-for="(item,index) in resource_file" :key="index" class=""
							style="display: flex;margin-top: 28rpx;justify-content: space-between;">
							<view class="" style="display: flex;">
								<image src="/static/images/pdf.png" class="image3" mode=""></image>
								<view class="pdf u-line-1" style="width: 530rpx;">{{item.title}}</view>
							</view>
							<image src="/static/images/updown.png" mode="" style="width: 32rpx;height: 32rpx;"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="" style=" height: 190rpx;"></view>
		<view class="bottom u-flex">
			<view v-if="datainfo.book_type==0" class="left" @click="stylebook">样书申请</view>
			<!-- <view v-if="datainfo.book_type==1" class="left" @click="stylebook">样书申请</view> -->
			<view v-if="datainfo.is_certificate==0" class="" style="position: relative;flex: 1;">
				<view class="timeback" style="position: absolute">
					体验到期时间：{{card.free_end_time}}
				</view>
				<view @click="show=true" class="right">体验下载</view>
			</view>
			<view v-if="datainfo.book_type==1&&(datainfo.is_free==0||datainfo.is_certificate==0||datainfo.is_pay==0)"
				class="left" @click="stylebook">在线阅读</view>
			<view v-if="datainfo.is_free==0" class="right" @click="show=true">免费下载</view>
			<!-- <view v-if="datainfo.is_certificate==0" @click="show=true" class="right">体验下载</view> -->
			<view v-if="datainfo.is_pay==0" class="right" @click="show=true">已购买，可下载</view>
			<view v-if="datainfo.is_pay==1&&datainfo.book_type==1" class="right" @click="orderinfo">立即购买</view>
			<view v-if="datainfo.is_pay!=0&&datainfo.is_certificate!=0&&datainfo.is_free!=0" class="right"
				@click="toyang()">在线试读</view>
		</view>
		<u-popup v-model="show" mode="bottom" border-radius="24">
			<view class="" style="padding: 32rpx 28rpx;">
				<view class="u-flex u-row-center" style="text-align: center;position: relative;">
					<view class="courseware" style="margin-top: 0;">资源下载</view>
					<image @click="show= false" src="../../static/images/close.png"
						style="width: 44rpx;height: 44rpx;position: absolute;top: 0;right: 0;" mode=""></image>
				</view>
				<view class="" v-if="specimen_file.length>0">
					<view class="sample">样章</view>
					<view @click="toyang(item.url)" class="u-row-between" v-for="(item,index) in specimen_file"
						:key="index" style="display: flex;margin-top: 28rpx;">
						<view class="" style="display: flex;">
							<image src="/static/images/pdf.png" class="image3" mode=""></image>
							<view class="pdf u-line-1" style="width: 530rpx;">{{item.title}}</view>
						</view>
						<image src="/static/images/updown.png" mode="" style="width: 32rpx;height: 32rpx;"></image>
					</view>
				</view>
				<view class="">
					<view class="sample u-flex u-row-between">
						<view class="">资源包</view>
					</view>
					<view class="courseware">电子书</view>
					<view v-for="(item,index) in courseware_file" :key="index" class=""
						style="display: flex;margin-top: 28rpx;justify-content: space-between;">
						<div style="display: flex;">
							<image src="/static/images/pdf.png" class="image3" mode=""></image>
							<view class="pdf u-line-1" style="width: 530rpx;">{{item.title}}</view>
						</div>
						<image src="/static/images/updown.png" mode="" style="width: 32rpx;height: 32rpx;"></image>
					</view>
					<view class="courseware">课件</view>
					<view v-for="(item,index) in courseware_file" :key="index" class=""
						style="display: flex;margin-top: 28rpx;justify-content: space-between;">
						<div style="display: flex;">
							<image src="/static/images/video.png" class="image3" mode=""></image>
							<view class="pdf u-line-1" style="width: 530rpx;">{{item.title}}</view>
						</div>
						<image src="/static/images/updown.png" mode="" style="width: 32rpx;height: 32rpx;"></image>
					</view>
					<view class="" v-if="resource_file.length>0">
						<view class="courseware">资源</view>
						<view v-for="(item,index) in resource_file" :key="index" class=""
							style="display: flex;margin-top: 28rpx;justify-content: space-between;">
							<view class="" style="display: flex;">
								<image src="/static/images/pdf.png" class="image3" mode=""></image>
								<view class="pdf u-line-1" style="width: 530rpx;">{{item.title}}</view>
							</view>
							<image src="/static/images/updown.png" mode="" style="width: 32rpx;height: 32rpx;"></image>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '内容介绍',
				}, {
					name: '资料',
				}],
				current: 0,
				show: false,
				list1: [],
				id: '',
				datainfo: {
					sheet: '',
					publisher: '',
					preface: "",
					author_desc: '',
					title: '',
					isbn: '',
					author: '',
					entity_price: '',
					format: '',
					print: '',
					edition: '',
					content_desc: "",
					level: {
						title: ''
					},
					arrangement: {
						title: ''
					},
					speciality: {
						title: ''
					},
					series_id: '',
					is_series: '', //是否可以系列购买
					is_certificate: '', //是否体验中
					is_pay: '', //是否已购买
					is_free: '', //是否免费
					book_type: '',
				},
				swiptlist: [],
				pubdate: '',
				courseware_file: [],
				resource_file: [],
				specimen_file: [],
				price: '', //资源价格,
				url: '',
				card:{
					free_end_time:''
				}
			};
		},
		onLoad(options) {
			this.id = options.id
			this.getBookInfo()
		},
		methods: {
			//跳转下载
			touser(url) {
				if (this.datainfo.is_free == 0 || this.datainfo.is_pay == 0 || this.datainfo.is_certificate == 0) {
					window.location.href = url
				} else {
					uni.showModal({
						title: '提示',
						content: '所选资料为付费资料，请购买后下载',
						confirmText: '我知道了',
						success: function(res) {
							if (res.confirm) {

							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			toyang() {
				if (this.url != '') {
					window.location.href = this.url
				} else {
					this.$u.toast('暂无试读资源')
				}
			},
			//跳转详情
			toinfo(id) {
				this.id = id
				this.getBookInfo()
			},
			//立即购买
			orderinfo() {
				if (uni.getStorageSync("token")) {
					this.$u.post('api/order/createOrder', {
						goods_id: this.id,
						type: 0
					}).then(res => {
						if (res.code == 1) {
							uni.setStorageSync('bookid', this.id)
							uni.navigateTo({
								url: '/pages/index/orderinfo?id=' + res.data.id + '&&index=' + 1
							})
						}
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '请先登录',
						confirmText: '我知道了',
						success: function(res) {
							if (res.confirm) {

							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			// 系列
			getSeriesBooks() {
				this.$u.post('api/books/getSeriesBooks', {
					series_id: this.series_id
				}).then(res => {
					this.swiptlist = res.data.reduce((a, b) => {
						let lastIndex = a.length - 1
						if (a[lastIndex].length < 3) {
							a[lastIndex].push(b)
						} else {
							a.push([b])
						}
						return a
					}, [
						[]
					])

				})
			},
			//详情
			getBookInfo() {
				this.$u.post('api/books/getBookInfo', {
					id: this.id
				}).then(res => {
					console.log('info', res);
					this.datainfo = res.data
					this.series_id = res.data.series_id
					this.pubdate = res.data.pubdate.slice(0, 4) + '年' + res.data.pubdate.slice(5, 7) + "月"
					this.getSeriesBooks()
					this.courseware_file = res.data.courseware_file
					this.resource_file = res.data.resource_file
					this.specimen_file = res.data.specimen_file
					this.card = res.data.cer
					if (res.data.specimen_file.length > 0) {
						this.url = res.data.specimen_file[0].url
					}
					this.price = res.data.price
					var arr = res.data.banner.map(item => {
						let obj = {}
						obj.image = item
						return obj
					})
					console.log(arr);
					this.list1 = arr
				})
			},
			change(index) {
				this.current = index;
			},
			toupdown(index) {
				if (uni.getStorageSync('token')) {
					uni.setStorageSync('bookid', this.id)
					uni.navigateTo({
						url: '/pages/index/updown?id=' + this.series_id + "&&index=" + index
					})
				}else{
					this.$u.toast('请登录后下载')
				}
			},
			stylebook() {
				uni.navigateTo({
					url: '/pages/index/stylebook?id=' + this.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.timeback {
		width: 412rpx;
		height: 64rpx;
		background: url('../../static/images/rectangle.png') no-repeat;
		position: absolute;
		top: -64rpx;
		right: 0;
		background-size: 100%;
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #06A971;
		line-height: 56rpx;
		text-align: center;
	}

	.courseware {
		font-size: 28rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #222222;
		margin-top: 24rpx;
	}

	.money5 {
		font-size: 32rpx;
		font-family: SFPro, SFPro;
		font-weight: 500;
		color: #CC3300;
	}

	.button4 {
		width: 120rpx;
		height: 52rpx;
		background: #06A971;
		border-radius: 6rpx;
		margin-left: 16rpx;
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 52rpx;
	}

	.selling {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #555555;
		margin-right: 4rpx;
	}

	.image3 {
		width: 28rpx;
		height: 28rpx;
	}

	.pdf {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #222222;
		margin-left: 24rpx;
		margin-right: 80rpx;
	}

	.sample {
		height: 72rpx;
		background: #F5F5F5;
		border-radius: 8rpx;
		font-size: 28rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #222222;
		padding: 14rpx 10rpx 14rpx 20rpx;
		margin-top: 28rpx;
	}

	.data {
		border-top: 2rpx solid rgba(151, 151, 151, 0.1);
		padding-top: 26rpx !important;
	}

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

	.tu {
		margin-top: 32rpx;
	}

	.image {
		width: 694rpx;
		height: 50rpx;
	}

	.brief {
		position: absolute;
		left: 28rpx;
		font-size: 28rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #06A971;
		line-height: 50rpx;
	}

	.chu {
		margin-top: 20rpx;
	}

	.content-box {
		border-top: 2rpx solid rgba(151, 151, 151, 0.1);
		padding-top: 42rpx !important;
	}

	::v-deep .u-tab-bar {
		background-color: #06A971 !important;
	}


	// 系列
	.series {
		padding: 44rpx 28rpx 32rpx;
	}

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

	.updown {
		width: 134rpx;
		height: 56rpx;
		background: #06A971;
		border-radius: 6rpx;
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 56rpx;
		text-align: center;
	}

	.wrap {
		height: 750rpx;
		padding: 0 106rpx;
	}

	.back {
		padding: 0 0 40rpx 0;
		background: #fff;
	}

	.padd {
		padding: 0 28rpx;
	}

	.page {
		// background: #F5F5F5;
		min-height: 100vh;
	}

	.height {
		width: 750rpx;
		height: 20rpx;
		background: #F5F5F5;
	}

	.item-jian {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #444444;
		margin-top: 18rpx;
	}

	.bottom {
		width: 750rpx;
		height: 166rpx;
		background: #FFFFFF;
		padding: 16rpx 28rpx 0;
		position: fixed;
		bottom: 0;
		left: 0;

		.left {
			width: 336rpx;
			height: 88rpx;
			background: #FFA30E;
			border-radius: 12rpx;
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 88rpx;
		}

		.right {
			flex: 1;
			// min-width: 336rpx;
			height: 88rpx;
			background: #06A971;
			border-radius: 12rpx;
			font-size: 32rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 88rpx;
			margin-left: 12rpx;
		}
	}

	.swiper-item :not(:last-child) {
		margin-right: 14rpx;
	}
</style>