<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);
        width: calc(100vw);
        overflow: hidden;
		padding-bottom: 50px;
      "
    >
      <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" @click="goActiveDetail(x)">
			  <view class="box-top">
			  	<image :src="x.CoverImg" mode="aspectFill" style="width: 110px;height: 67px;border-radius: 8px;"></image>
				<view style="margin-left: 10px;height: 67px;">
					<view class="box-title">{{x.ActivityName}}</view>
					<view style="font-size: 12px;color: #666666;margin-top: 8px;">活动类型:{{x.TypeName}}</view>
				</view>
			  </view>
			  <view class="box-top-r-b">
			  	<u-icon name="contact" :size="28" color="#999999" style='margin-right: 5px;' ></u-icon>
			  	<view style="max-width: 280rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis">{{x.LinkMan}}</view>
			  	<u-icon name="friends-o" :size="28" color="#999999" style='margin-right: 5px;margin-left: 10px;' ></u-icon>
			  	<view>{{x.PeopleNum}}</view>
			  	<u-icon name="phone-o" :size="28" color="#999999" style='margin-right: 5px;margin-left: 10px;' ></u-icon>
			  	<view>{{x.LinkTel}}</view>
				<u-icon name="star-o" :size="28" :color="mainColor" style='margin-right: 5px;margin-left: 10px;' ></u-icon>
				<view v-if="x.Money>0" :style="{color:mainColor}">{{x.Money}}</view>
				<view v-if="x.Money==0" :style="{color:mainColor}">免费</view>
			  </view>
			  <view class="box-Remark">
				  <view class="box-Remark-top">
					  <view style="width: calc(100vw - 110px);">
						 备注：{{x.Remark==''?'无':x.Remark}}
					  </view>
					  <view class="box-Remark-top-r" style="color: #00C6C1;" v-if="x.Status!=1 && x.IsApplyForCancel!=1">已报名</view>
					  <view class="box-Remark-top-r" style="color: #00C6C1;" v-if="x.Status!=1 && x.IsApplyForCancel==1 && x.ApplyForCancelStatus==0">待审核</view>
					  <view class="box-Remark-top-r" style="color: #00C6C1;" v-if="x.Status!=1 && x.IsApplyForCancel==1 && x.ApplyForCancelStatus==1">通过</view>
					  <view class="box-Remark-top-r" style="color: #FF4646;" v-if="x.Status!=1 && x.IsApplyForCancel==1 && x.ApplyForCancelStatus==2">拒绝</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!=1 && x.IsApplyForCancel!=1">
					  <view class="box-Remark-btn" @click.native.stop="cancel(x,i)">
						  取消
					  </view>
				  </view>
				  <view style="width: calc(100vw - 110px);" v-if="x.CancelRemark!=null && x.CancelRemark!=''">
				  		取消备注：{{x.CancelRemark==''?'无':x.CancelRemark}}
				  </view>
				  <view style="width: calc(100vw - 110px);" v-if="x.RejectRemark!=null && x.ApplyForCancelStatus==2">
				  		审核未通过理由：{{x.RejectRemark==''?'无':x.RejectRemark}}
				  </view>
				  <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-popup v-model="show" mode="center" length="80%">
   	<view style='display: flex;flex-direction: column;align-items: center;background: #fff;'>
   		<view style="display: flex;align-items: center;justify-content: center;height:70px ;">
   			<Text>是否取消订单？</Text>
   		</view>
   		<view style="display: flex;flex-direction: column;height:80px ;margin-left: 15px;width: 100%;" >
   			<Text style='margin-left: 10px;margin-top: 5px;'>备注</Text>
   			<input class="uni-input inputM" style='margin-left: 10px;margin-top: 5px;' v-model="cancelRemark" placeholder="输入备注" />
   		</view>
   		<view style="display: flex;flex-direction: row;align-items: center;height: 50px;border-top: 1px solid #F5F5F5;width: 100%;">
   			<view style="width: 50%;display: flex;align-items: center;justify-content: center" @click="show=false">
   				<Text>取消</Text>
   			</view>
   			<view style="width: 50%;color: #a0cfff;display: flex;align-items: center;justify-content: center" @click="queren">
   				<Text>确定</Text>
   			</view>
   		</view>
   	</view>
   </u-popup>
  </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,
		  EnrollState:3
	  },
      page_count: 1,
      g: [],
      loading: false,
	  status: "loadmore",
	  loadText: {
	    loadmore: "轻轻上拉，加载更多",
	    loading: "努力加载中",
	    nomore: "没有更多了",
	  },
	  bmobj:{},
	  cancelRemark:'',
    };
  },
  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
		if(index==0){
			this.msg.EnrollState = 3
		}else{
			this.msg.EnrollState = index;
		}
      
      this.msg.pageIndex = 1;
      this.g = [];
      this.loading = true;
      this.init();
    },
    init() {
      
	  this.request2(
	  	{
	  		url: '/api/AppletTrade/GetUserJoinActivityPageList',
	  		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={
			ActivityId:x.ActivityId,
			index:i
		}
		
		this.show=true
	},
	queren(){
		this.request2(
			{
				url: '/api/AppletTrade/CancelCommerceConsult',
				data: {ActivityId:this.bmobj.ActivityId,CancelRemark:this.cancelRemark}
			},
			res => {
				if(res.resultCode==1){
					uni.showToast({
						title: '操作成功',
						icon: 'success',
					})
					if(res.data != 1){
						if(this.msg.EnrollState==1){
							this.g.splice(this.bmobj.index,1)
						}else{
							this.g[this.bmobj.index].Status=2
						}
						
					}else{
						this.g[this.bmobj.index].IsApplyForCancel=1;
						this.g[this.bmobj.index].CancelRemark = this.cancelRemark;
						
					}
					this.show=false
				}
			}
		);
	},
	//跳转至活动详情
	goActiveDetail(item){
		uni.navigateTo({
			url: '/pages/kotra/activeInnerDetail?Id=' + item.ActivityId +'&isFromActive='+'1',					
		});
	}
	
  },
};
</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: 13px;
	color: #666666;
	margin-top: 10px;
}
.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>
