<template>
  <view class="baomingList" :style="{ height: contentHeight }">
    <u-empty v-if="g.length == 0" text="暂无报名记录" mode="list"></u-empty>
    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh);
        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" v-if="type==0">
		  <view class="interDList" v-for="(x, i) in g" :key="i">
			    <view style="position: relative;">
				  <u-avatar :src="x.Photo" size="80"></u-avatar>
				  <image v-if="x.Sex==1" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-nan.png" style="width: 32rpx;height: 32rpx;position: absolute;right: 0;bottom: 0;"></image>
				  <image v-if="x.Sex==2" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-nv.png" style="width: 32rpx;height: 32rpx;position: absolute;right: 0;bottom: 0;"></image>
			    </view>
				<view :style="{'width':(windowWidth-30-45-20-30)+'px','margin-left':'10px'}">
					<view class="teinfo">{{x.UserName}}</view>
					<view class="teinfo2" >
						
					</view>
				</view>
				<view class="gzbtn" @click.stop="setFollowTeacher(x,i)" v-if="UserId != x.UserId">
					<view class="iconstyle" :style="{background:mainColor,border:'none'}" v-if="x.IsFocus==0">
						<u-icon name="plus" color="#FFF" size="32"></u-icon>
					</view>
					<view class="iconstyle" :style="{background:mainColor}" v-if="x.IsFocus==1">
						<u-icon name="success" color="#FFF" size="32"></u-icon>
					</view>
					<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-hu.png" style="width: 50rpx;height: 50rpx;" v-if="x.IsFocus==2"></image>
					
				</view>
		  </view>
	  </view>
	  <view v-if="type==1" class="ftBox">
		  <view v-for="(x, i) in g" :key="i">
			  <view class="interDList"  style="border-bottom: none;">
					<view style="position: relative;">
					  <u-avatar :src="x.Photo" size="80"></u-avatar>
					  <image v-if="x.Sex==1" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-nan.png" style="width: 32rpx;height: 32rpx;position: absolute;right: 0;bottom: 0;"></image>
					  <image v-if="x.Sex==2" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-nv.png" style="width: 32rpx;height: 32rpx;position: absolute;right: 0;bottom: 0;"></image>
					</view>
					<view class="interDList-r" :style="{'width':(windowWidth-30-45-20-30)+'px','margin-left':'10px'}">
						<view class="teinfo">{{x.UserName}}</view>
						<view class="teinfo2" style="font-size: 11px">
							<u-icon name="contact" :size="24" color="#999999" style='margin-right: 5px;' ></u-icon>
							<view style="max-width: 200rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis">{{x.Name}}</view>
							<u-icon name="friends-o" :size="24" color="#999999" style='margin-right: 5px;margin-left: 10px;' ></u-icon>
							<view>{{x.PeopleNum}}</view>
							<u-icon name="phone-o" :size="24" color="#999999" style='margin-right: 5px;margin-left: 10px;' ></u-icon>
							<view>{{x.Mobile}}</view>
						</view>
					</view>
					<view class="gzbtn" @click.stop="setFollowTeacher(x,i)" v-if="UserId != x.UserId">
						<view class="iconstyle" :style="{background:mainColor,border:'none'}" v-if="x.IsFocus==0">
							<u-icon name="plus" color="#FFF" size="32"></u-icon>
						</view>
						<view class="iconstyle" :style="{background:mainColor}" v-if="x.IsFocus==1">
							<u-icon name="success" color="#FFF" size="32"></u-icon>
						</view>
						<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-hu.png" style="width: 50rpx;height: 50rpx;" v-if="x.IsFocus==2"></image>
						
					</view>
			  </view>
			  <view class="box-Remark" v-if="x.Remark!=''">
				  {{x.Remark}}
			  </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>
    <!-- 取消提示 -->
   
  </view>
</template>

<script>

export default {
  
  data() {
    return {
      pageTitle: "报名列表",
	  showAuth:false,
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
		  ActivityId:0,
	  },
	  type:0,
      mainColor: "",
	  secondary:'',
	  pricecolor:'',
      contentHeight: 0,
      page: 1,
      page_count: 1,
      g: [],
      loading: false,
	  status: "loadmore",
	  count:0,
	  loadText: {
	    loadmore: "轻轻上拉，加载更多",
	    loading: "努力加载中",
	    nomore: "没有更多了",
	  },
	  windowWidth:0,
	  UserId: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;
	this.UserId = uni.getStorageSync('mall_UserInfo')?uni.getStorageSync('mall_UserInfo').UserId : 0;
  },
  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(options){
		console.log(options)
		if(options){
			this.type= options.type;
			this.msg.ActivityId= options.ActivityId;
		}
		
		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/AppletMiai/GetActivityEnrollPageList',
      		data: this.msg
      	},
      	res => {
      		if(res.resultCode==1){
				this.loading = false;
				this.count = res.data.count;
				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){
		let ID=0
		if(x.IsFocus!=0){
			ID = x.MyFollowId
		}
		this.request2({
				url: '/api/AppletMiai/GetFollowMember',
				data: {
					ID:ID,
					UserId:x.UserId,
				}
			},
			res => {
				uni.showToast({
					title:res.message,
					icon:'none'
				})
				
				this.request2(
					{
						url: '/api/AppletMiai/GetActivityEnrollPageList',
						data: {
							  pageIndex: 1,
							  pageSize:10,
							  ActivityId:this.msg.ActivityId,
							  Id:x.Id
						  },
					},
					res => {
						if(res.resultCode==1){
							this.g[i] = res.data.pageData[0]
							this.$forceUpdate()
						}
					}
				);
				
			}
		);
	},
    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()
	},
	
  },
};
</script>
<style>
.baomingList {
  width: 100%;
  height: 100vh;
  background: #FFF;
}

.baomingList .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;
}
.baomingList .interDList{
	width:calc(100vw - 30px) ;
	display: flex;
	flex-direction: row;
	align-items: center;
	padding: 15px 0;
	border-bottom: 1px solid #f5f5f5;
	
}
.baomingList .followTeacher-top{
	width: 100%;
	height: 35px;
	padding: 0 15px;
	display: flex;
	flex-direction: row;
	align-items: center;
	font-size: 11px;
	color: #999999;
	background: #FAF8F9;
}
.baomingList .ftBox{
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
}
.baomingList .teinfo{
	width: 100%;
	overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
	font-size: 15px;
}
.baomingList .gzbtn{
	width: 69px;
	height: 26px;
	border-radius: 4px;
	margin-left: 8px;
	color: #111111;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	font-size: 13px;
	
}
.iconstyle{
	width: 50rpx;
	height: 50rpx;
	border-radius: 25rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}
.interDList-r{
	height: 40px;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}
.teinfo2{
	display: flex;
	align-items: center;
}
.box-Remark{
	width: calc(100vw - 30px - 80rpx - 20rpx);
	padding: 14px 10px;
	background: #EDEDED;
	font-size: 11px;
	color: #777777;
	margin-left: 100rpx;
	border-radius: 6px;
}
</style>
