<template style="background: #black;">
	<view class="container" >
		<view style="font-size: 40upx;font-weight: bold;padding:20upx;background: white;">{{item.title}}</view>
		<view style="font-size: 26upx;color: #666;padding: 0px 20upx;background: white;">{{'发布日期：'+formatDate(item.create_time)}}</view>
		<view class="uni-common-mt" style="background:#FFF; padding:20upx;background: white;">
			<rich-text :nodes="item.content"></rich-text>
		</view>
		<!-- <view class="interviewee">
			<view v-for="(itemInfo,index1) in item.itemList" :key="index1"  >
				<text  class="input_left"   >{{itemInfo.k_val}}:</text>
				<input type="text" :value="itemInfo.item" disabled="true" />
			</view>
		</view> -->
		<!-- <view class="form-box" v-for="(itemInfo,index1) in item.itemList" :key="index1"  >
			<view class="form-item">
				<text class="label">{{itemInfo.k_val}}:</text>
				<input type="text" v-model="itemInfo.item"/>
			</view>
		</view> -->
		<view style="clear: both;"></view>
		<view class="occupied"></view>
		<view v-if="item.sign_status==null&&item.compareTime" class="footer-btn"  @click="submit()">
			<view class="btn">报名</view>
		</view>
		<view v-if="item.sign_status==0" class="footer-btn"  >
			<view class="btn" style="background: #e5e5e5;">已报名</view>
		</view>
		<view v-if="item.sign_status==1" class="footer-btn" >
			<view class="btn" style="background: #e5e5e5;" >已签到</view>
		</view>
		<view v-if="item.sign_status==2" class="footer-btn" >
			<view class="btn" style="background: #e5e5e5;" >已签退</view>
		</view>
	</view>
</template>

<script>
import { getActiveInfo,signUpActive,iOpenidGetUserInfo,signInActive } from '@/common/api.js';
import { callbackRequest, alertTip, compare,formatDate ,getStorage,devEnv} from '@/common/util.js';
export default {
	components: {
	},
	data() {
		return {
			id:0,
			item:{},
			formatDate: formatDate,
			userId: getStorage('userInfo').userId,
			sign_status:false,
			queryType:0,  //1签到 ，2签退
			userInfo:{},
			currentUser:{}
			
		};
	},
	onLoad(options) {
		var params = "id="+options.id;
		this.id = this.getUrlParams('id',params)==""?0:this.getUrlParams('id',params);
		
		
		this.queryType=this.getUrlParams('queryType',params)==""?0:this.getUrlParams('queryType',params);
		this.getActiveInfo();
		
		
		
	},
	methods: {
		compareTime(time1){
			var endDateTime = time1;
			var nowDateTime = new Date().getTime();
			if(endDateTime>nowDateTime){
				return true;
			}else{
				return false;
			}
		},
		getUrlParams(names,params) {
		   var urlSearch =params;
		   var urlValue="";
		   //以？*&来拆分
		   var params = urlSearch.split(/[?*&]/);
		    for(var i=0;i<params.length;i++){
		    //如果url参数里包含传递过来names字段，则取=后面的部分
		        if(params[i].indexOf(names) >= 0 ){
		            urlValue=params[i].split("=")[1];
		            return urlValue;
		        }
		    }
		 
		   return urlValue;
		},
		signIn(){
			let params = {
				method: signInActive, // 签到
				data: { 
					activeId:this.id ,
					userId:this.userId,
					status:this.queryType
				} //分三种情况
			};
			callbackRequest(params)
			.then(res =>{
				if (res.data.returnCode == 1) {
					//this.getActiveInfo();
					if(this.queryType==1){
						this.$set(this.item,'sign_status',1);
					}else if(this.queryType==2){
						this.$set(this.item,'sign_status',2);
					}
					alertTip(res.data.returnMsg);
				}
				else {
					alertTip(res.data.returnMsg);
				}
			})
			console.log(this.queryType);
		},
		getActiveInfo(){
			let params = {
				method: getActiveInfo, // 申请的审批
				data: { 
					id:this.id,
					userId:this.userId
				} //分三种情况
			};
			callbackRequest(params)
			.then(res =>{
				if (res.data.returnCode == 1) {
					
					this.item = res.data.returnData;
					var compareTime = this.compareTime(this.item.signup_endtime);
					this.item.compareTime = compareTime;
					console.log(this.item)
					var content = this.item.content.replace(/\<img/gi,"<img style='max-width:100%'");
					content = content.replace(/	/g,"　　");
					this.item.content = content;
					//this.sign_status = this.item.sign_status==null?true:false;
					if(this.queryType=="1"&&this.item.sign_status==0){
						this.signIn();
					}
				}
				else {
					alertTip(res.data.returnMsg);
				}
			})
		},
		submit(){
			let params = {
				method: signUpActive, // 申请的审批
				data: { 
					activeId:this.id ,
					userId:this.userId
				} //分三种情况
			};
			callbackRequest(params)
			.then(res =>{
				if (res.data.returnCode == 1) {
					this.$set(this.item,'sign_status',0);
					alertTip("报名成功");
					//this.getActiveInfo();
				}
				else {
					alertTip(res.data.returnMsg);
				}
			})
		},
	
	}
};
</script>
<style lang="scss">
	@import '@/static/css/common.scss';
	 img{max-width:100%!important}
	 .interviewee {
	 	padding: 0upx 30upx 0;
	 	background: #fff;
	 	margin: 30rpx 30rpx 0;
	 	border-radius: 10rpx;
	 	.input_left {
	 		width: 150rpx;
	 		color: #333333;
	 		font-size: 28rpx;
	 		font-weight: bold;
	 	}
	 }
	 .interviewee view {
	 	line-height: 40rpx;
	 	padding: 20rpx 0;
	 	color: #333333;
	 	font-size: 28rpx;
	 	border-bottom: 1px solid #eee;
	 	display: flex;
	 	align-items: center;
	 	position: relative;
	 }
	 .interviewee view:last-child {
	 	border-bottom: 0px;
	 }
	 .interviewee view input {
	 	font-size: 28rpx;
	 	margin-left: 20rpx;
	 }
	.uni-common-mt>>>.ql-align-right{
		  text-align: right;
	  }
</style>
