<template>
	<view class="container">
		<scroll-view class="scroll-list" scroll-x>
			<view class="scoll-box" v-for="ls in Recommendlist" :class="{ active: ls.id === currentId }" @click="tabtap(ls.id)">
				<view class="scoll-name">{{ ls.title }}</view>
			</view>
		</scroll-view>
		<view class="big-box">
			<view v-if="courseList.length ==  0" class="no-data">暂无数据</view>
			<view class="activitylist" v-for="(item, index) in courseList" :key="index" @click="ToDetail(item)">
				<view class="act_box">
					<view class="act_left"><image :src="item.image"></image></view>
					<view class="act_right">
						<view class="right_top">
							<view class="act_tit">{{ item.title }}</view>
							<view class="act_icon"><image src="../../static/img/hot.png"></image></view>
						</view>
						<view class="act_txt">{{ item.abstract }}</view>
						<view class="tip-box flex_item">
							<view v-for="ls in item.label" class="tip">{{ ls }}</view>
						</view>
					</view>
				</view>
				<view class="act_time flex">
					<view class="time_date"></view>
					<view class="act_mony">¥{{ item.money }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { unified, GetUnifiend } from '@/api/course.js';
export default {
	data() {
		return {
			page: 1,
			limit: 100,
			courseList: '', //专题列表
			type: '', //分类类型
			id: '', //分类id
			title: '', //分类标题
			Recommendlist: '', //分类列表
			currentId: 0,
			typesetting: ''
		};
	},
	onLoad(option) {
		this.id = option.recommend_id;
		this.type = option.type;
		this.title = option.title;
		this.typesetting = option.typesetting;
		this.loadData();
		this.listDate();
	},
	methods: {
		//加载分类列表
		listDate(){
			let obj = this;
			unified({
				type: obj.type,
				title: obj.title,
				recommend_id:obj.id
			})
				.then(data => {
					obj.Recommendlist =  data.data.Recommendlist;
					let newDate = {
						id: 0,
						title: '推荐'
					};
					obj.Recommendlist.unshift(newDate);
				})
				.catch(e => {
					console.log(e.message);
				});
		},
		//加载专题列表
		loadData() {
			let obj = this;
			GetUnifiend({
				page: obj.page,
				limit: obj.limit,
				recommend_id:obj.id,
				type:obj.type,
				typesetting:obj.typesetting,
				subject_id:obj.currentId
			})
				.then(data => {
					obj.courseList = data.data.list;
				})
				.catch(e => {
					console.log(e.message);
				});
		},
		//头部导航栏点击事件
		tabtap(item) {
			this.currentId = item;
			this.loadData();
		},
		ToDetail(item) {
			let id = item.id;
			uni.navigateTo({
				url: '/pages/course/detail?id=' + id
			});
		},
		navTo(url) {
			uni.navigateTo({
				url
			});
		}
	}
};
</script>

<style lang="scss">
page {
	width: 100%;
	height: 100%;
	background-color: #f8f6f6;
}
.container {
	width: 100%;
	height: 100%;
	background-color: #f8f6f6;
}
.scroll-list {
	width: 100%;
	height: 70rpx;
	overflow: hidden;
	white-space: nowrap;
	padding: 0rpx 25rpx;
	font-size: 26rpx;
	background-color: #ffffff;
	margin-bottom: 25rpx;
	line-height: 60rpx;
	.scoll-box {
		margin-right: 35rpx;
		text-align: center;
		display: inline-block;
		.scoll-name {
			// margin-left: 25rpx;
		}
		&.active {
			color: #fa2740;
			border-bottom: 4rpx solid #fa2740;
		}
	}
}
.big-box {
	padding: 0 13rpx;
	padding-bottom: 25rpx;
	.no-data{
		width: 100%;
		font-size: 26rpx;
		text-align: center;
	}
	.activitylist {
		margin-top: 20rpx;
		background: rgba(255, 255, 255, 1);
		box-shadow: 0px 5rpx 5rpx 0px rgba(35, 24, 21, 0.06);
		border-radius: 7rpx;
		padding: 0 20rpx;
		.act_box {
			display: flex;
			overflow: hidden;
			padding: 31rpx 0rpx 25rpx 0rpx;
			border-bottom: 1rpx solid rgba(232, 232, 232, 1);
			.act_left {
				width: 240rpx;
				height: 160rpx;
				margin-right: 25rpx;
				image {
					width: 240rpx;
					height: 160rpx;
					border-radius: 10rpx;
				}
			}
			.act_right {
				flex: 1;

				.right_top {
					display: flex;
					justify-content: space-between;

					.act_tit {
						font-size: 30rpx;
						font-weight: bold;
						color: rgba(51, 51, 51, 1);
					}
					.act_icon {
						width: 31rpx;
						height: 44rpx;
						image {
							width: 30rpx;
							height: 44rpx;
						}
					}
				}
				.act_txt {
					width: 90%;
					font-size: 22rpx;
					color: rgba(153, 153, 153, 1);
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					height: 70rpx;
				}
				.tip-box {
					display: flex;
					flex-wrap: wrap;
					font-size: 24rpx;
					.tip {
						background: rgba(103, 134, 251, 0.18);
						color: #6786fb;
						margin-right: 15rpx;
						margin-top: 10rpx;
						padding: 2rpx 10rpx;
					}
				}
			}
		}

		.act_time {
			padding: 25rpx 0rpx;
			.time_date {
				font-size: 24rpx;
				font-weight: bold;
				color: rgba(102, 102, 102, 1);
			}

			.act_mony {
				font-size: 26rpx;
				font-weight: bold;
				color: rgba(255, 0, 0, 1);
			}
		}
	}
}

.Search-box {
	height: 100rpx;
	background: #ffffff;
	padding: 0 24rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 26rpx;

	.Search-text {
		font-size: 28rpx;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
	}

	.Search-box-size {
		width: 620rpx;
		border-radius: 32rpx;
		background-color: #f1f1f1;
		padding-left: 36rpx;
		display: flex;
		align-items: center;
		.box-img {
			height: 32rpx;
			width: 32rpx;
			margin-right: 16rpx;
		}
		.input-box {
			font-size: 26rpx;
			height: 65rpx;
			line-height: 65rpx;
		}

		.box-word {
			font-size: 22rpx;
			font-weight: 500;
			color: rgba(205, 203, 203, 1);
			line-height: 55rpx;
		}
	}
}
</style>
