<template>
  <view class="mysignupList" :style="{ height: contentHeight }">
    <u-tabs
      :list="list"
      :is-scroll="false"
      :current="current"
      @change="change"
      :active-color="mainColor"
    ></u-tabs>
    <u-empty v-if="g.length == 0" text="暂无报名记录" mode="list"></u-empty>
		
    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh - 50px);
        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="details">
		  <view class="item" v-for="(x, i) in g" :key="i" >
			  <view class="box-top">
			  	<image :src="x.ActivityModel.ImageList[0]" mode="aspectFill" style="width: 110px;height: 67px;border-radius: 8px;"></image>
				<view style="margin-left: 10px;height: 67px;">
					<view class="box-title">{{x.ActivityModel.ActivityTitle}}</view>
					<view class="box-top-r-b">
						<u-icon name="contact" :size="24" color="#999999" style='margin-right: 5px;' ></u-icon>
						<view style="max-width: 70px;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>
			  <view class="box-Remark">
				  <view class="box-Remark-top">
					  <view style="width: calc(100vw - 110px);">
						 Remark：{{x.Remark==''?'无':x.Remark}}
					  </view>
					  <view class="box-Remark-top-r" style="color: #00C6C1;" v-if="x.Status==0">已报名</view>
					  <view class="box-Remark-top-r" style="color: #FF4646;" v-if="x.Status==1">已取消</view>
				  </view>
				  <view class="box-Remark-b" v-if="x.Status==0">
					  <view class="box-Remark-btn" @click="cancel(x,i)">
						  取消
					  </view>
				  </view>
			  </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>
   
   <auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth>
   <u-modal v-model="show" content="是否取消报名？" :show-cancel-button='true' @confirm='queren'></u-modal>
  </view>
</template>

<script>
import auth from "@/components/auth/index.vue";
export default {
  components: {
    auth
  },
  data() {
    return {
      pageTitle: "报名列表",
      showAuth:false,
	  u:{},
	  show:false,
	  current:0,
      list: [
        { name: "不限" },
        { name: "正常" },
        { name: "取消" },
      ],
      mainColor: "",
      contentHeight: 0,
      
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
		  Status:-1
	  },
      page_count: 1,
      g: [],
      loading: false,
	  status: "loadmore",
	  loadText: {
	    loadmore: "轻轻上拉，加载更多",
	    loading: "努力加载中",
	    nomore: "没有更多了",
	  },
	  bmobj:{}
    };
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
  },
  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: function (option) {    
    this.u = uni.getStorageSync("mall_UserInfo");
    if (!this.u) {
      this.u = {
    	nickName: "未登录",
    	avatarUrl: ""
      };
      this.showAuth = true;
    }	else{
    	this.init();
    }
  },
  methods: {
    change(index) {
		this.current = index
      this.msg.Status = index-1;
      this.msg.pageIndex = 1;
      this.g = [];
      this.loading = true;
      this.init();
    },
    init() {
      
	  this.request2(
	  	{
	  		url: '/api/AppletMiai/GetMyEnrollPageList',
	  		data: this.msg
	  	},
	  	res => {
	  		if(res.resultCode==1){
	  				this.loading = false;
	  				this.g = this.g.concat(res.data.pageData);
					 this.page_count = res.data.pageCount;
					 if (this.page_count == 1) {
					   this.status = "nomore";
				}
	  		}
	  	}
	  );
    },
    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()
	},
	cancel(x,i){
		this.bmobj={
			EnrollId:x.Id,
			index:i
		}
		
		this.show=true
	},
	queren(){
		this.request2(
			{
				url: '/api/AppletMiai/CancelActivityEnrollInfo',
				data: {EnrollId:this.bmobj.EnrollId}
			},
			res => {
				if(res.resultCode==1){
					uni.showToast({
						title: '取消成功',
						icon: 'success',
					})
					if(this.msg.Status == 0){
						this.g.splice(this.bmobj.index,1)
					}else{
						this.g[this.bmobj.index].Status=1;
						this.$forceUpdate()
					}
					
				}
			}
		);
	}
	
  },
};
</script>
<style>
.mysignupList {
  width: 100%;
  height: 100%;
  background: #FFF;
  position: relative;
}

.mysignupList .loading {
  width: 180rpx;
  height: 180rpx;
  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;
}
.mysignupList .details{
	padding: 15px;
	display: flex;
	flex-direction: column;
	
}
.mysignupList .item{
	margin-bottom: 15px;
}
.mysignupList .box-top{
	width: 100%;
	height: 67px;
	display: flex;
	align-items: center;
}
.mysignupList .box-title{
	width: calc(100vw - 30px - 110px - 10px);
	font-size: 15px;
	color: #000000;font-weight: 500;
	line-height: 22px;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}
.mysignupList .box-top-r-b{
	width: 100%;
	display: flex;
	align-items: center;
	font-size: 11px;
	color: #666666;
	margin-top: 8px;
}
.mysignupList .box-Remark{
	width: 100%;
	padding: 14px 10px;
	font-size: 11px;
	color: #777777;
	background: #EDEDED;
	margin-top: 13px;
	border-radius: 6px;
	
}
.mysignupList .box-Remark-top{
	width: 100%;
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
}
.mysignupList .box-Remark-top-r{
	font-size: 11px;
}
.mysignupList .box-Remark-b{
	width: 100%;
	display: flex;
	justify-content: flex-end;
	margin-top: 5px;
}
.mysignupList .box-Remark-btn{
	width: 60px;
	height: 25px;
	border-radius: 12.5px;
	border:1px solid #333333;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
	color: #333333;
}









</style>
