<template>
	<view class="container">
		<image class="cbg" :src="base.imgHost('common_bg.png')"></image>
		<view class="wrap">
			<topBanner  v-if="banner_list.length>0" :banner_list="banner_list"></topBanner>
			<view class="list">
				<view>
					<view v-if="list.length>0">
						<view class="list-item" v-for="item in list">
							<view class="list-item-status">
								<view  :class="{'list-item-status-text':item.course_status===10,'list-item-status-textEnd':item.course_status!=10}">{{item.date_status}}</view>
								<view  :class="{
									'list-item-status-status':item.course_signs[0]['status']===0||item.course_signs[0]['status']===3,
									'list-item-status-statusSuccess':item.course_signs[0]['status']===1,
									'list-item-status-statusFail':item.course_signs[0]['status']===2
								}">{{item.course_signs[0]['status_text']==='备选'?'待审核':item.course_signs[0]['status_text']}}</view>
							</view>
							<view class="list-item-name">
								<view>
									<image :src="base.imgHost('me-icon1.png')"></image>
									<text>
										<block v-if="item.type">{{item.type_detail?item.type_detail.name+' | ':''}}</block>
										{{item.name}}
									</text>
								</view>
								<view>
									<image :src="base.imgHost('mybook-icon3.png')"></image>
									<text>开课日期：{{item.start_date?item.start_date:'待定'}}</text>
								</view>
							</view>
							<view class="list-item-buttom">
								<view>
									<u-button  v-if="item.course_status===10" size="mini" :custom-style="{'color':'#b79373',
									'border-color':'transparent','font-size': '26rpx',
									'padding': 0}" :hair-line="false" @click="clickShareId(item)" shape="circle" open-type="share">
										<image :src="base.imgHost('mycourse-share.png')"></image>
										<text>分享</text>
									</u-button>
								</view>
								<view class="list-item-btn">
									<text  @click="toUrl(item.id,3)" v-if="item.course_signs[0]['status']===1 && item.is_fee===0">进入</text>
									<text  @click="toUrl(item.id,1)" v-if="item.course_signs[0]['status']===1 && item.is_fee===1">进入</text>
									
									<text @click="toUrl(item.id,2)"  v-if="item.course_signs[0]['status']===0||item.course_signs[0]['status']===3">查看进度</text>
									<text @click="toUrl(item.id,2)"  v-if="item.course_signs[0]['status']===2">查看</text>
								</view>
							</view>
						</view>
					</view>

				</view>

			</view>

		</view>
	</view>
</template>

<script>
	import topBanner from '@/components/topBanner.vue'
	export default {
		components: {
			topBanner
		},
		data() {
			return {
				banner_list: [],
				list: [],
				historyList: [],
				shareObj: {}
			}
		},
		onShareAppMessage(res) {
			console.log("res", res)
			console.log("this.shareObj", this.shareObj)
			if (res.from === 'button') {
				return {
					path: "/packages/course/detail?id=" + this.shareObj.id, //这是为了传参 onload(data){let id=data.id;}
					title: this.shareObj.name,
					imageUrl: '/static/share.jpg'
				}
			}
			return this.base.shareInfo
		},
		//发送到朋友圈
		onShareTimeline(res) {
			if (res.from === 'button') {
				return {
					path: "/packages/course/detail?id=" + this.shareObj.id, //这是为了传参 onload(data){let id=data.id;}
					title: this.shareObj.name,
					imageUrl: '/static/share.jpg'
				}
			}
			return this.base.shareInfo
		},
		onLoad() {
			console.log("selectOptions", this.selectOptions)
			this.getMyCourse()
			this.getBannerList()
		},
		methods: {
			async getMyCourse() {
				const res = await this.$u.api.courseMy()
				this.list = res.list.data
			},
			clickShareId(item) {
				this.shareObj = item
			},
			toUrl(id,type) {
				// 付费审核通过
				if(type===1){
					uni.navigateTo({
						url: '/packages/mycourse/detail?id=' + id
					})
				}else if(type===2){
					// 审核不通过 或待审核 备选
					uni.navigateTo({
						url: '/packages/mycourse/courseStatus?id=' + id
					})
				}else if(type===3){
					// 不付费的 审核通过
					uni.navigateTo({
						url: '/packages/course/freeDetail?id=' + id
					})
				}
				
			},
			async getBannerList() {
				const res = await this.$u.api.otherBanner({
					position: 2
				})
				if(res.length>0){
					this.banner_list =  res.sort((a,b)=>{a.sort-b.sort})
					
				}
			},
		}

	}
</script>

<style scoped lang="scss">
	.container {
		padding: 30rpx;
		width: 100%;
		height: 100vh;

		.cbg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100vh;
		}

		.wrap {
			position: relative;
			height: 100%;
			overflow-x: hidden;
			overflow-y: scroll;

			.list {
				margin-top: 50rpx;

				&-title {
					margin-bottom: 30rpx;
					color: #333;
					font-size: 42rpx;
				}

				&-item {
					background-color: #fff;
					padding: 30rpx;
					margin-bottom: 30rpx;
					border-radius: 20rpx;
					// border-bottom: 2px solid #b79373
					box-shadow: 0 -1rpx 20rpx #bed2ec;
					&-status{
						display: flex;
						justify-content: space-between;
						align-items: center;
						font-size:28rpx;
						padding-bottom:20rpx;
						border-bottom: 1px solid #f5f5f5;
						&>view:last-child{
							padding:5rpx 20rpx;
							border-radius: 28rpx 0 28rpx 28rpx;
							color:#fff;
						}
						&-text{
							color:#b08c6c;
							font-size:28rpx;
						}
						&-textEnd{
							color:#999;
							font-size:28rpx;
						}
						&-status{
							background-color: #bf976e;
							font-size:24rpx;
						}
						&-statusSuccess{
							background-color: #00b318;
							font-size:24rpx;
						}
						&-statuFail{
							background-color: #999999;
							font-size:24rpx;
						}
					}
					&-name {
						padding:20rpx 0;
						border-bottom: 1px solid #f5f5f5;
						&>view{
							display: flex;
							justify-content: space-between;
							align-items: baseline;
							font-size:28rpx;
							image{
								width:24rpx;
								height:24rpx;
								margin-right:20rpx;
							}
							text{
								display: inline-block;
								width:calc(100% - 44rpx);
								font-size: 28rpx;
								line-height: 1.5;
							}
						}
						&>view:first-child{
							margin-bottom:20rpx;
						}
					}

					&-hisname {
						color: #888888
					}

					&-buttom {
						display: flex;
						justify-content: space-between;
						align-items: center;
						color: #b79373;
						margin-top: 20rpx;

						&>view:first-child {
							display: flex;
							align-items: center;

							image {
								width: 26rpx;
								height: 26rpx;
								margin: 0 10rpx;
							}
						}
					}

					&-btn {
						color:#b08c6c;
						// background: linear-gradient(to right, #5e5fbc, #0d0398);
						// border-radius: 30rpx;
						// color: #fff;
						// text-align: center;
						// padding: 10rpx 20rpx;
						// width: 140rpx;
					}
				}
			}

		}
	}
</style>