<template>
	<scroll-view 
		:scroll-y="true"
		@scroll="scrollHandler"
		@scrolltoupper="scrollTopHandler"
		@scrolltolower="lower"
		style="height: 100vh;">
		
		<view class="teacherDetails">
			<view
			  class="headStatus"
			  v-if="scrollTop > 50 "
			  :style="[
			    headStyle,
			    {
			      zIndex: scrollTop < 10 ? 'unset' : 2,
			      opacity: scrollTop < 10 ? '100' : scrollTop,
				  background:'#FFF'
			    },
			  ]"
			>
			  <view class="arrow" @click="goback">
			    <u-icon name="arrow-left" size="48" color="#000"></u-icon>
			  </view>
			  <view class="title" style="color: #000000;" v-if="scrollTop > 50">{{pageTitle}}</view>
			  <view class="arrow"></view>
			</view>
			<view class="course-top">
				<view class="teacherbox">
					<u-avatar :src="teacher.teacherResult.TeacherLogo" size="140"></u-avatar>
					<view class="teacherbox-r">
						<text style="font-size: 16px;color: #121212;font-weight: bold;">{{teacher.teacherResult.Name}}</text>
						<text style="font-size: 12px;color: #999999;margin: 10px 0;">{{teacher.teacherResult.Major}}</text>
						<view class="teacherbox-b">
							<view class="teacher-b-item" :style="{background:mc}" v-for="(x, i) in teacher.teacherResult.LableNameList" :key="ci">
								{{x}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="course-ti">
				<view class="course-ti-c">
					<view class="course-ti-cont">
						<text style="font-weight: bold;">{{teacher.teacherResult.WorkYears}}</text>
						<text class="huixin">教龄</text>
					</view>
					<view class="course-ti-cont">
						<text style="font-weight: bold;">{{teacher.teacherResult.FollowteacherNum}}</text>
						<text class="huixin">粉丝</text>
					</view>
					<view class="course-ti-cont2" :style="{background:mc}" @click="setFollowTeacher()">
						<u-icon name="plus" size='30' color="#FFF" v-if="teacher.teacherResult.Followteacher==0"></u-icon>
						<text style="margin-left: 5px;" v-if="teacher.teacherResult.Followteacher==0">关注</text>
						<text style="margin-left: 5px;" v-if="teacher.teacherResult.Followteacher>0">已关注</text>
					</view>
				</view>
			</view>
			<view class="kecheng">
				<view class="tiaoti">
					<view class="tiaoti-l"></view>
					<text style="font-size: 16px;color: #1B1D1E;margin-left: 5px;">教师简介</text>
				</view>
				<view style="padding: 10px;">
				  
				  <h-parse :content="teacher.teacherResult.Introduction" @navigate="clickDescription"></h-parse>
				</view>
				<view class="tiaoti">
					<view class="tiaoti-l"></view>
					<text style="font-size: 16px;color: #1B1D1E;margin-left: 5px;">课程目录</text>
				</view>
				<view class="good" v-for="(cx, ci) in g" :key="ci" @click="clickHandler(cx)" v-if="g.length>0">
						  <view class="good-img">
							<image mode="aspectFill" :src="cx.CoverImage" style="width: 100%; height: 100%;border-radius: 4px;" ></image>
						  </view>
						  <view class="good-r" :style="{'width': (windowWidth -15 - 125 -26)+'px'}">
							  <view class="good-name">
								{{ cx.Name }}
							  </view>
							  <view class="good-r-b">
								  <text>本教程共分{{cx.CourseNum}}个章节</text>
							  </view>
						  </view>
				</view>
				<u-empty text="暂无课程" v-if='g.length==0' font-size="36" mode="list" ></u-empty>
				<u-loadmore  :status="status" :load-text="loadText" :font-size="24" :margin-top="20"
				 :margin-bottom="20" bg-color="#FFF" />
			</view>
			<view class="goback" @click="goback" :style="{'padding-top':paddingHTop}">
				<u-icon name="arrow-left" size="48" color="#121212"></u-icon>
			</view>
			<auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gob'></auth>
		</view>
		
	</scroll-view>
</template>

<script>
	import hParse from "@/components/u-parse/parse.vue";
	import auth from "../../components/auth/index.vue";
	export default {
		data(){
			return{
				mc:'',
				pricecolor:'',
				secondary:'',
				paddingHTop:0,
				id:0,
				teacher:{},
				windowWidth:0,
				scrollTop:0,
				headStyle:{},
				pageTitle:'教师详情',
				UserId:0,
				u:{},
				showAuth:false,
				msg:{
					pageIndex: 1,
					pageSize: 10,
					TeacherId: 0,
				},
				
				page_count: 1,
				g: [],
				status: "loadmore",
				loadText: {
					loadmore: "轻轻上拉，加载更多",
					loading: "努力加载中",
					nomore: "没有更多课程了",
				},
			}
		},
		components: {
		  hParse,
		  auth
		},
		onLoad(options) {
			console.log(options,'options')
			if(options && options.ID){
				this.id = options.ID;
				this.msg.TeacherId = options.ID;
				
				this.getTeacher()//根据老师id获取老师详情
				this.init()//根据老师id获取老师的课程列表
			}
		},
		created() {
			this.mc = this.$uiConfig.mainColor;
			this.pricecolor = this.$uiConfig.pricecolor;
			this.secondary = this.$uiConfig.secondary;
			this.nav = uni.getMenuButtonBoundingClientRect().top;
			this.paddingHTop = this.nav +'px';
			this.windowWidth = this.$utils.SystemInfo().windowWidth;
			this.headStyle.paddingTop = this.nav +'px';
		},
		methods:{
			clickDescription(e) {
			  console.log(e);
			},
			goback(){
				uni.navigateBack({})
			},
			init(){
				this.request2({
						url: '/api/AppletSchool/GetTeacherGoodsList',
						data: this.msg
					},
					res => {
						if (res.resultCode == 1) {
							this.g = this.g.concat(res.data.pageData);
							this.page_count = res.data.pageCount;
							if (this.page_count == 1) {
								this.status = "nomore";
							} else {
								this.status = "loadmore";
							}
						}
				
						uni.hideNavigationBarLoading();
					}
				);
			},
			getTeacher(){
				if(uni.getStorageSync("mall_UserInfo")){
					this.UserId = uni.getStorageSync("mall_UserInfo").UserId ? uni.getStorageSync("mall_UserInfo").UserId:0
				}
				this.request2({
						url: '/api/AppletSchool/GetTeacherModel',
						data: {ID: this.id,UserId:this.UserId }
					},
					res => {
						this.teacher= res.data;
						this.pageTitle = res.data.teacherResult.Name
					}
				);
			},
			clickHandler(item) {
			  uni.navigateTo({ url: "/pages/school/courseInfo?GoodsId=" + item.Id });
			},
			scrollHandler(e) {
			  this.scrollTop = e.detail.scrollTop;
			  //this.$forceUpdate();
			},
			scrollTopHandler() {
			  this.scrollTop = 0;
			},
			setFollowTeacher(){//关注和取消老师
				this.u = uni.getStorageSync("mall_UserInfo");
				if (!this.u) {
				  this.u = {
					nickName: "未登录",
					avatarUrl: ""
				  };
				  this.showAuth = true;
				}else{
					this.followTeacher()
					
				}
			},
			followTeacher(){
				this.request2({
						url: '/api/AppletEducation/FollowTeacher',
						data: {
							ID: this.teacher.teacherResult.Followteacher,
							TeacherId:this.id,
						}
					},
					res => {
						
						
						this.request2({
								url: '/api/AppletSchool/GetTeacherModel',
								data: {ID: this.id,UserId:this.UserId }
							},
							res2 => {
								this.teacher.teacherResult.Followteacher = res2.data.teacherResult.Followteacher
								this.teacher.teacherResult.FollowteacherNum = res2.data.teacherResult.FollowteacherNum
							}
						);
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						});
						
					}
				);
			},
			reloadUserinfo() {
			  this.u = uni.getStorageSync("mall_UserInfo");
			  this.getTeacher()
			},
			gob(){
				this.showAuth = false;
			},
			lower(e) {
				if (this.msg.pageIndex < this.page_count) {
					this.status = "loading";
					this.msg.pageIndex++;
					this.init();
				} else {
					
					this.status = "nomore";
				}
			},

		}
	}
</script>

<style>
	.teacherDetails .headStatus {
		  overflow: hidden;
		  position: relative;
		  width: 140vw;
		  padding-right: 40vw;
		  padding-bottom: 10px;
		  position: fixed;
		  left: 0;
		  right: 0;
		  top: 0;
		  display: flex;
		  flex-direction: row;
		  align-items: center;
		  justify-content: space-between;
		 
		}
	.teacherDetails .course-top{
		width: 100%;
		height: 200px;
		background: rgba(167, 210, 200, 0.5);
	}
	.teacherDetails .goback{
		margin-left: 8px;
		position: fixed;
		top: 0;
		left: 0;
	}
	.teacherDetails .teacherbox{
		width: calc(100vw - 35px);
		display: flex;
		flex-direction: row;
		align-items: flex-start;
		padding-top: 80px;
		margin-left: 25px;
	}
	.teacherDetails .teacherbox-r{
		margin-left: 15px;
		width: calc(100vw - 120px);
		display: flex;
		flex-direction: column;
		
	}
	.teacherDetails .teacherbox-b{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
	}
	.teacherDetails .teacher-b-item{
		padding: 2px 4px;
		border-radius: 2px;
		font-size: 10px;
		color: #FAF8F9;
		margin-right: 5px;
		margin-bottom: 5px;
	}
	.teacherDetails .course-ti{
		width: 100%;
		height: 100px;
		background: #F5F6F7;
		margin-top: -20px;
		font-family: aa;
		border-top-right-radius: 20px;
		border-top-left-radius: 20px;
	}
	.teacherDetails .course-ti-c{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-around;
		padding-top: 15px;
	}
	.course-ti-cont2{
		width: 69px;
		height: 26px;
		display: flex;flex-direction: row;
		align-items: center;
		justify-content: center;
		font-size: 13px;
		color: #FFFFFF;
		border-radius: 4px;
	}
	.teacherDetails .course-ti-cont{
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 15px;
		color: #121212;
	}
	.teacherDetails .huixin{
		font-size: 12px;
		color: #9A9A9A;
		margin-top: 10px;
	}
	.teacherDetails .kecheng{
		width: 100%;
		margin-top: -30px;
		background: #FFF;
		border-top-right-radius: 20px;
		border-top-left-radius: 20px;
		padding-top: 10px;
		margin-bottom: 20px;
	}
	.teacherDetails .tiaoti{
		width: 100%;
		height: 35px;
		display: flex;
		flex-direction: row;
		align-items: center;
		font-weight: bold;
	}
	.teacherDetails .tiaoti-l{
		width: 3px;
		height: 14px;
		margin-left: 12px;
		background-image: linear-gradient(
		  to bottom,
		  #00D6A6,
		  #B5FFEE
		);
	}
	.teacherDetails  .good{
		background: #fff;
		padding: 10px 13px;
		display: flex;
		flex-direction: row;
		font-family: aa;
		
	}
	.teacherDetails .good-r-b{
		font-size: 11px;
		color: #9A9A9A;
	}
	.teacherDetails .good-img{
	width: 125px;
	height: 70px;
	border-radius: 4px;
	box-shadow:0 4px 10px 1px #D2D2D2;
}
.teacherDetails .good-r{
	margin-left: 15px;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	padding: 3px;
}
.teacherDetails .good .good-name {
  /* height: 37px; */
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 3px;
  font-size: 14px;
  color: #1B1D1E;
  
}
.teacherDetails .arrow {
	  height: 24px;
	  margin: 5px 10px;
	  width: 24px;
	}
</style>
