<template>
  <view class="page">
	<view class="page-info">
	  	<view class="banner">
	  		<view class="title">{{tableData.title}}</view>
			<view class="banner-info-top">
				<view class="times">{{tableData.createdAt}}</view>
				<view><u-icon name="eye"></u-icon>{{tableData.viewsNumber || 0}}人</view>
			</view>
	  		<view class="banner-info-item">
				<u-parse :html="tableData.content"></u-parse>
	  			
				<image :src="imgurl+tableData.coverImage" style="width: 100%; height: 100vw; border-radius: 10rpx; margin-top: 30rpx;"></image>
	  		</view>
	  	</view>
		<view class="info-box">
			<view class="title">营销推广活动信息</view>
			<view class="info-item">场地：{{tableData.cereBasicInformationVenue.venueName?tableData.cereBasicInformationVenue.venueName:'无'}}</view>
			<view class="info-item">起止时间：{{tableData.startTime}}至{{tableData.endTime}}</view>
			<view class="info-item">联系人：{{tableData.contactPerson}}</view>
			<view class="info-item">联系电话：{{tableData.contactPhone}}</view>
			<view class="info-item">已参与报名人数：<span>{{tableData.registeredCount || 0}}</span>人</view>
		</view>
	</view>
	
	
    <!-- 底部 -->
	<view style="height: 125rpx;"></view>
    <view class="page-footer" v-if="tableData.reviewStatus == 2">
		<!-- <view class="footer-service">
				<u-image :showLoading="true" :src="$imgUrl('/sevice-icon.png')"  width="30rpx" height="30rpx"></u-image>
				<text>客服</text>
			</view> -->
		<view class="footer-btn">
			<u-button type="success" @click="baoShow">报名参加</u-button>
		</view>
			<!-- <view class="footer-service">
				<u-image :showLoading="true"  :src="$imgUrl('/share-icon.png')"  width="30rpx" height="30rpx"></u-image>
				<text>分享</text>
			</view> -->
	
    </view>
	<u-popup class="userForm" v-model="joinShow" mode="center" border-radius="20" :closeable="true" width="90%" >
		<view style="padding: 30rpx;">
			<u-form class="form-box" :model="form" ref="uForm" :label-width="120" >
				<view style="padding: 10rpx;">
					<view class="title">请填写您的报名信息</view>
					<u-form-item label="*姓名"><u-input v-model="form.userName" /></u-form-item>
					<u-form-item label="*电话"><u-input v-model="form.userPhone" /></u-form-item>
					<u-button type="success" @click="submit">提交</u-button>
				</view>
			</u-form>
		</view>
	</u-popup>
	<u-toast ref="uToast" />
  </view>
</template>

<script>

export default {
  data() {
    return {
		tableData:{},
		swiperList: [
			{
				id: 0,
				type: 'image',
				url: this.$imgUrl('/img/1.jpg')
			}
		],
		joinShow: false,
		form: {
			activityId:'',
			userId:'',
			createTime:'',
			createUser:'',
			userName: '',
			userPhone: '',
		},
		pagesize: {
			id:null,
		},
		imgurl:''
    };
  },
  onLoad(option){
	  this.imgurl = this.$img
		let str = unescape(option.scene);

if(option.scene){
		let str = unescape(option.scene)
		// 使用 split() 方法按等号分割字符串，并获取第二个元素（索引为1），即带单引号的值
		let valueWithQuotes = str.split('=')[1];
		
		// 使用 slice() 或 substring() 去除两端的单引号
		let value = valueWithQuotes.slice(1, -1); 
		this.pagesize.id = value
		this.form.activityId = value
}else{
	
	this.pagesize.id =  JSON.parse(option.item)
	this.form.activityId = JSON.parse(option.item)
}
	this.$http.sendRequest('/cereMarketingActivity/queryById', 'POST',this.pagesize,1).then(res => {
		this.tableData =res.data.data	
		let obj ={
			id:option.item,
			viewsNumber:Number(this.tableData.viewsNumber)+1
		}
		this.$http.sendRequest('/cereMarketingActivity/edit', 'POST',obj,1).then(res => {
			
		})
	})


  },
  methods: {
	  baoShow(){
		  this.joinShow = true
		  this.form.userName = ''
		  this.form.userPhone = ''
	  },
		submit() {
			if (!this.form.userName) {
				uni.showToast({
					icon: 'none',
					title: '请输入姓名'
				});
				return
			}
			
			
			if (!this.form.userPhone) {
				uni.showToast({
					icon: 'none',
					title: '请输入联系电话'
				});
				return 
			}
			this.form.createTime = this.getCurrentDateTime()
			this.$http.sendRequest('/cereEventRegistration/add', 'POST',this.form,1).then(res => {
			
				// uni.showToast({
				// 	title: res.data.message,
				// 	duration: 2000,
					
				// })
				this.$refs.uToast.show({
									title: res.data.message,
									url: '/pages/home/home'
								})
			     // uni.switchTab({
			     // 	url: '/pages/home/home'
			     // })
			})
			this.joinShow = false
			
		
		},
		leaseAdd(){
			uni.navigateTo({
				url: '/pages/leaseAdd/leaseAdd'
			})
		},
		 getCurrentDateTime() {
		  const now = new Date();
		  const year = now.getFullYear();
		  const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的，所以需要+1
		  const day = String(now.getDate()).padStart(2, '0');
		  const hours = String(now.getHours()).padStart(2, '0');
		  const minutes = String(now.getMinutes()).padStart(2, '0');
		  const seconds = String(now.getSeconds()).padStart(2, '0');
		
		  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		},
  }
};
</script>

<style scoped lang="scss">
@import 'marketingDetail.scss';
</style>
