<!-- 普通模式演示(vue) -->
<template>
	<view class="content">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<!-- 需要固定在顶部不滚动的view放在slot="top"的view中，如果需要跟着滚动，则不要设置slot="top" -->
			<!-- 注意！此处的z-tabs为独立的组件，可替换为第三方的tabs，若需要使用z-tabs，请在插件市场搜索z-tabs并引入，否则会报插件找不到的错误 -->
			<template #top>
				<u-tabs :list="tabList" @click="tabChange" lineColor="#eb3729"
					activeStyle="font-size: 32rpx;color: #eb3729;"></u-tabs>
			</template>
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
		
			<view v-show="tabIndex == 0">
				<view @click="toDetail(item)"  class="volume" v-for="(item ,index) in dataList" :key="index">
					<u--image :src="item.poster" width="300rpx" height="168.75rpx" mode="aspectFill" radius="8rpx"></u--image>
					<view class="volume-info">
						<view class="volume-title u-line-2">{{item.volumeName}}</view>
						<view class="volume-level">{{item.level}}</view>
						<view class="volume-price">
							<view style="height: 30rpx;">已学习{{item.views}}/{{item.totalNode}}</view>
							<!-- <view v-if="!item.isPaid" @click.stop="onBuy(item.id)" class="btn-pay"><u-button type="primary" size="mini">立即报名</u-button> </view> -->
							<view  class="btn-pay"><u-button type="success" size="mini">去学习</u-button> </view>
						</view>
					</view>
				</view>
			</view>
			<view v-show="tabIndex == 1">
				<view  @click="toDetail(item)" class="volume" v-for="(item ,index) in dataList" :key="index">
					<u--image :src="item.poster" width="300rpx" height="168.75rpx" mode="aspectFill" radius="8rpx"></u--image>
					<view class="volume-info">
						<view class="volume-title u-line-2">{{item.volumeName}}</view>
						<view class="volume-level">{{item.level}}</view>
						<view class="volume-price">
							<view style="height: 30rpx;">已学习{{item.views}}/{{item.totalNode}}</view>
							<!-- <view v-if="!item.isPaid" @click.stop="onBuy(item.id)" class="btn-pay"><u-button type="primary" size="mini">立即报名</u-button> </view> -->
							<view  class="btn-pay"><u-button type="info" size="mini">已结束</u-button> </view>
						</view>
					</view>
				</view>
			</view>
			<view v-show="tabIndex == 2">
				<view  @click="toDetailByNodeViews(item)" class="volume" v-for="(item ,index) in dataList" :key="index">
					<u--image :src="item.node.poster" width="300rpx" height="168.75rpx" mode="aspectFill" radius="8rpx"></u--image>
					<view class="volume-info">
						<view class="volume-title u-line-2">{{item.node.nodeName}}</view>
						<view class="volume-level"></view>
						<view class="volume-price">
							<view style="height: 30rpx;">{{item.updateTime}}</view>
						</view>
					</view>
				</view>
			</view>
			
		</z-paging>
	</view>
</template>

<script>
	import * as SubjectApi from '@/api/subject.js'
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				tabList: [{name: '学习中'},{name: '已结束'},{name: '学习记录'}],
				tabIndex: 0,
			}
		},
		methods: {
			tabChange({index}) {
				this.tabIndex = index;
				//当切换tab或搜索时请调用组件的reload方法，请勿直接调用：queryList方法！！
				this.$refs.paging.reload();
			},
			queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageNo: pageNo,
					pageSize: pageSize,
					isExpiry: this.tabIndex
				}
				if(this.tabIndex == 2) {
					SubjectApi.getNodeViewsList(params).then(res => {
						this.$refs.paging.complete(res.data);
					}).catch( res => {
						this.$refs.paging.complete(false);
					})
				}else {
					SubjectApi.getPaidVolume(params).then(res => {
						this.$refs.paging.complete(res.data);
					}).catch( res => {
						this.$refs.paging.complete(false);
					})
				}
				
				
			},
			toDetailByNodeViews(item) {
				this.$yrouter.push({
					path: "/pages/subject/detail/detail",
					query: {
						sid: item.subjectId,
						vid: item.volumeId,
						nid: item.nodeId
					}
				});
			},
			toDetail(item) {
				this.$yrouter.push({
					path: "/pages/subject/detail/detail",
					query: {
						sid: item.subjectId,
						vid: item.id
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		position: relative;
		height: 150rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0rpx 30rpx;
	}

	.item-detail {
		padding: 5rpx 15rpx;
		border-radius: 10rpx;
		font-size: 28rpx;
		color: white;
		background-color: #007AFF;
	}

	.item-line {
		position: absolute;
		bottom: 0rpx;
		left: 0rpx;
		height: 1px;
		width: 100%;
		background-color: #eeeeee;
	}
	
	.volume{
		display: flex;
		padding: 30rpx;
		justify-content: space-between;
		&-info {
			width: 350rpx;
		}
		&-title {
			font-size: 32rpx;
			height: 80rpx;
		}
		
		&-level {
			font-size: 24rpx;
			color: #6c6c6c;
			margin-bottom: 10rpx;
		}
		
		&-price {
			margin-top: 8rpx;
			font-size: 26rpx;
			color: #666666;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		
		.btn-pay{
			width: 130rpx;
		}
	}
</style>
