<template>
	<view class="web_box">
		<!-- <u-navbar height="44" leftIcon="arrow-left" leftIconColor="#000" leftText="我的收藏" @leftClick="leftClick" :autoBack="true" bgColor="#fff">
		</u-navbar> -->
		<view class="list" v-if="collectList.length > 0">
			<block v-for="(item,index) in collectList" :key="index">
				<view class="list_item hflex acenter" @click="toDetail(index)">
					<image :src="item.img" mode="widthFix" style="width: 322rpx;border-radius: 16rpx;"></image>
					<view class="img_right">
						<view class="title">{{item.name}}</view>
						<view class="text_style1">总学时：{{item.period}}学时</view>
						<view class="text_style1">讲师：{{item.lecturer}}</view>
						<view class="hflex acenter jbetween">
							<view class="order_price">￥{{item.price}}</view>
							<u-icon v-if="show" name="star-fill" color="#fa6400" size="22" @tap.stop="collect(index)"></u-icon>
							<u-icon v-else name="star" color="#fa6400" size="22" ></u-icon>
						</view>
					</view>
				</view>
			</block>
		</view> 
		<view class="list vflex acenter jcenter" v-else>
			<image src="../../static/images/common/collect_none.png" class="img_none"></image>
			<view class="text_none">
				暂无收藏
			</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		data() {
			return {
				collectList:[],
				page: 1,
				limit: 10,
				total: 0,
				show: true
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			leftClick() {
				
			},
			// 获取我的收藏
			getList() {
				var that = this
				$api.req({
					url: '/api/User/myCourseList',
					data: {
						page: that.page,
						limit: that.limit,
						type: 3
					}
				}, function(res) {
					console.log("我的课程",res);
					if (res.code == 1) {
						if(that.page == 1) {
							that.collectList = res.data.list
							that.total = res.data.count
						} else {
							that.collectList = that.collectList.concat(res.data.list)
							that.total = res.data.count
						}
						
					}
				})
			},
			// 点击前往详情页
			toDetail(index) {
				let id = this.collectList[index].id
				$api.jump('/pages/index/course/detail?id=' + id)
			},
			// 取消收藏
			collect(index) {
				var that = this
				let id = that.collectList[index].id
				$api.req({
					url: '/api/Index/collectionCancelCourse',
					data: {
						id: id,
						type: 0
					}
				}, function(res) {
					if (res.code == 1) {
						$api.info(res.msg)
						that.show = false
					}
				})
			},
			// 触底事件
			onReachBottom() {
				console.log("到底了");
				console.log(this.page );
				console.log(this.limit);
				console.log(Number(this.total));
				if (Number(this.page) * Number(this.limit) >= Number(this.total)) {
					$api.info("没有更多了")
				} else {
					this.page++
					this.getList()
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.web_box::v-deep {
		padding: 0 30rpx;
		
		.u-navbar {
			width: 100%;
			box-sizing: border-box;
			padding: 36px 16px 58rpx 0;
		}
		.list {
			width: 100%;
		}
		.list_item {
			width: 100%;
			box-sizing: border-box;
			padding: 6rpx;
			background: #FFFFFF;
			box-shadow: 0px 2px 6px 0px rgba(213,213,213,0.5);
			border-radius: 24rpx;
			margin-top: 20rpx;
		}
		.img_right {
			width: calc(100% - 322rpx);
			padding-left: 12rpx;
		}
		.title {
			font-size: 28rpx;
			font-weight: 600;
			color: #333333;
			padding-bottom: 14rpx;
		}
		.text_style1 {
			font-size: 20rpx;
			font-weight: 400;
			color: #999999;
			padding-bottom: 12rpx;
		}
		.order_price {
			font-size: 32rpx;
			font-weight: 600;
			color: #FA6400;
		}
		.text_none {
			font-size: 32rpx;
			color: #333333;
			margin-top: 44rpx;
		}
		.img_none {
			margin-top: 300rpx;
			width: 570rpx;
			height: 328rpx;
		}
	}
</style>