<template>
  <view class="followTeacher" :style="{ height: contentHeight }">
    <view class="followTeacher-top">共关注{{count}}位老师</view>
    <u-empty v-if="g.length == 0" text="暂无关注教师" mode="list"></u-empty>
    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh-35px);
        width: calc(100vw);
        overflow: hidden;
        
      "
    >
      <scroll-view
        :scroll-y="true"
        :enable-back-to-top="true"
        :enable-flex="true"
        @scrolltolower="lower"
        :style="{ height: '100%' }"
      >
	  <view class="ftBox">
		  <view class="interDList" v-for="(x, i) in g" :key="i" @click="goteacher(x)">
		  	<u-avatar :src="x.TeacherLogo" size="110"></u-avatar>
		  	<view :style="{'width':(windowWidth-30-55-20-70)+'px','margin-left':'10px'}">
		  		<view class="teinfo">{{x.Name}}</view>
		  		<view class="teinfo" style="margin-top: 10px;font-size: 11px;color: #999999;">{{x.Major}}</view>
		  	</view>
			<view class="gzbtn" @click.stop="setFollowTeacher(x,i)" >
				<text style="color: #999999;">取消关注</text>
			</view>
			<!-- <view class="gzbtn" v-if="x.Followteacher==0" :style="{background:mainColor,'border':'0.5px solid'+mainColor}" @click="setFollowTeacher(x,i)">
				<text style="color: #FFF;">关注</text>
			</view> -->
		  </view>
	  </view>
       
       <u-loadmore
         :status="status"
         :load-text="loadText"
         :font-size="24"
         :margin-top="20"
         :margin-bottom="20"
         bg-color="#FFF"
       />
      </scroll-view>
	 
    </view>
    <!-- 加载中 -->
    <view class="loading" v-if="loading">
      <u-loading mode="flower" size="48">></u-loading>
      <Text style="color: #fff; margin-top: 10rpx;">加载中...</Text>
    </view>
    <!-- 取消提示 -->

    <u-toast ref="uToast" />
   <auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth>
   
  </view>
</template>

<script>
import auth from "../../../components/auth/index.vue";
export default {
  components: {
    auth
  },
  data() {
    return {
      pageTitle: "教师关注",
	  showAuth:false,
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
	  },
      mainColor: "",
	  secondary:'',
	  pricecolor:'',
      contentHeight: 0,
      page: 1,
      page_count: 1,
      g: [],
      loading: false,
	  status: "loadmore",
	  count:0,
	  loadText: {
	    loadmore: "轻轻上拉，加载更多",
	    loading: "努力加载中",
	    nomore: "没有更多了",
	  },
	  windowWidth:0,
    };
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
	this.secondary = this.$uiConfig.secondary;
	this.pricecolor = this.$uiConfig.pricecolor;
	this.windowWidth = this.$utils.SystemInfo().windowWidth;
  },
  mounted() {
    let currentPages = getCurrentPages();
    let u = "/" + currentPages[currentPages.length - 1].route;
    let pages = wx.getStorageSync("basedata")
      ? wx.getStorageSync("basedata").bar_title
      : [];
    pages.forEach((x) => {
      if (x.value == u) {
        this.pageTitle = x.new_name ? x.new_name : x.name;
      }
    });
    uni.setNavigationBarTitle({
      title: this.pageTitle,
    });
	
  },
	onLoad(){
		this.u = uni.getStorageSync("mall_UserInfo");
		if (!this.u) {
		  this.u = {
			nickName: "未登录",
			avatarUrl: ""
		  };
		  this.showAuth = true;
		}	else{
			this.init();
		}
	},
  methods: {
    init() {
	  this.loading = true;
      this.request2(
      	{
      		url: '/api/AppletEducation/GetFollowTeacherPageList',
      		data: this.msg
      	},
      	res => {
      		if(res.resultCode==1){
				this.loading = false;
				this.count = res.data.count;
				// res.data.pageData.forEach(x=>{
				// 	x.Followteacher=1;//1为关注
				// })
				this.g = this.g.concat(res.data.pageData);
				 this.page_count = res.data.pageCount;
				 if (this.page_count == 1) {
				   this.status = "nomore";
				 }
      		}
      	}
      );
    },
	setFollowTeacher(x,i){
		this.request2({
				url: '/api/AppletEducation/FollowTeacher',
				data: {
					ID: x.ID,
					TeacherId:x.TeacherId,
				}
			},
			res => {
				this.g.splice(i,1)
				this.count--
				uni.showToast({
					title: res.message,
					icon: 'none',
					duration: 2000
				});
				
			}
		);
	},
    lower(e) {
	  if (this.msg.pageIndex < this.page_count) {
		this.msg.pageIndex++;
			this.status = "loading";
		this.init();
	  } else {
		
			this.status = "nomore";
	  }
    },
	reloadUserinfo() {
	  this.u = uni.getStorageSync("mall_UserInfo");
	  // this.showAuth=false;
	  this.init();
	},
	//关闭登录窗口
	gbAuth(){
		uni.navigateBack()
	},
	goteacher(item){//老师详情
		uni.navigateTo({ url: '/pages/school/teacherDetails?ID='+item.TeacherId })
	}
  },
};
</script>
<style>
.followTeacher {
  width: 100%;
  height: 100vh;
  background: #FFF;
}

.followTeacher .loading {
  width: 200rpx;
  height: 200rpx;
  background: #000000;
  opacity: 0.7;
  border-radius: 10rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: fixed;
  left: 50%;
  top: 30%;
  margin-left: -100rpx;
  z-index: 999;
}
.followTeacher .interDList{
	width:calc(100vw - 30px) ;
	display: flex;
	flex-direction: row;
	align-items: center;
	padding: 20px 0;
	border-bottom: 1px solid #f5f5f5;
	
}
.followTeacher .followTeacher-top{
	width: 100%;
	height: 35px;
	padding: 0 15px;
	display: flex;
	flex-direction: row;
	align-items: center;
	font-size: 11px;
	color: #999999;
	background: #FAF8F9;
}
.followTeacher .ftBox{
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
}
.followTeacher .teinfo{
	width: 100%;
	overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
	font-size: 15px;
}
.followTeacher .gzbtn{
	width: 69px;
	height: 26px;
	border-radius: 4px;
	margin-left: 8px;
	border: 0.5px solid #999999;
	color: #111111;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
}
</style>
