<template>
	<view style="letter-spacing: 1rpx;">
		<tn-nav-bar :isBack="false" backTitle="" :bottomShadow="true" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-between">
				<view class="tn-flex tn-flex-col-center tn-flex-row-left">
					<view style="padding-left: 15rpx;" @click="goBack()">
						<text class="tn-icon-left" style="font-size: 40rpx;"></text>
					</view>
					<view class="tn-margin-top"
						style="text-shadow:  1rpx 0 0 #FFF, 0 1rpx 0 #FFF, -1rpx 0 0 #FFF , 0 -1rpx 0 #FFF;">
						<tn-tabs :list="[{name:'活动详情'}]" :current="topCurrent" activeColor="#000" :bold="false"
							:fontSize="36"></tn-tabs>
					</view>
				</view>
			</view>
		</tn-nav-bar>
		<view :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<image :src="apiImgUrl+info.activity_image" style="width: 100%;" mode="widthFix"></image>
			<view style="padding:20rpx 30rpx;">
				<view style="font-size: 30rpx;font-weight: 600;">{{info.activity_name}}</view>
				<view style="margin-top: 40rpx;">
					<view>
						<text style="color: #26BB71;">●</text>
						<text style="margin-left: 10rpx;font-weight: 600;">开始时间：</text>
						<text style="color: #979797;">{{info.activity_start_time}}</text>
					</view>
					<view style="margin: 15rpx 0rpx;">
						<text style="color: #BE7E28;">●</text>
						<text style="margin-left: 10rpx;font-weight: 600;">结束时间：</text>
						<text style="color: #979797;">{{info.activity_end_time}}</text>
					</view>
					<view>
						<text style="color: #DB5022;">●</text>
						<text style="margin-left: 10rpx;font-weight: 600;">活动地点：</text>
						<text style="color: #979797;">{{info.activity_location}}</text>
					</view>
				</view>
				<view style="margin-top: 60rpx;font-size: 32rpx;font-weight: 600;">活动介绍</view>
				<view>
					<view class="ks_html" style="line-height: 50rpx;margin-top: 20rpx;">
						<div v-html="info.activity_content"></div>
					</view>
				</view>
				<view v-if="info.activity_type==1||info.activity_type==3" style="height: 180rpx;"></view>
				<view v-if="info.activity_type==2" style="padding-bottom: 180rpx;">
					<view style="margin-top: 60rpx;font-size: 32rpx;font-weight: 600;">问卷问题</view>
					<tn-form labelPosition="top" :model="form" ref="form">
						<tn-form-item label="1.问题xxxx（多选题）" prop="hobby">
							<tn-checkbox-group v-model="form.hobby" size="40" activeColor="#82B2FF" wrap>
								<tn-checkbox name="10">
									A:选项1
								</tn-checkbox>
								<tn-checkbox name="5">
									B:选项2
								</tn-checkbox>
								<tn-checkbox name="6">
									C:选项3
								</tn-checkbox>
								<tn-checkbox name="7">
									D:选项4
								</tn-checkbox>
							</tn-checkbox-group>
						</tn-form-item>
						<tn-form-item label="2.问题xxxx（单选题）" prop="danxuan">
							<tn-radio-group v-model="form.danxuan" size="40" activeColor="#82B2FF" wrap>
								<tn-radio name="3">
									A、选项1
								</tn-radio>
								<tn-radio name="8">
									B、选项2
								</tn-radio>
							</tn-radio-group>
						</tn-form-item>
						<tn-form-item label="3.问题xxxx（问答题）" prop="wenda">
							<tn-input placeholder="请填写答案" v-model="form.wenda" type="textarea" />
						</tn-form-item>
					</tn-form>
				</view>
			</view>
		</view>
		<view style="position: fixed;bottom: 30rpx; width: 100%;">
			<!--			<view class="tn-flex tn-flex-center tn-flex-row-center tn-flex-col-center"-->
			<!--				style="background-color: #FDF2EC;text-align: center;padding: 30rpx;">-->
			<!--				<view style="font-weight: 600;">-->
			<!--					<text style="margin-right: 10rpx;">距报名结束剩<text style="color: #F73909;">119</text>天</text>-->
			<!--					<tn-count-down fontColor="#F73909" backgroundColor="#FDF2EC" :fontSize="30" :timestamp="86400"-->
			<!--						:showDays="true" :showHours="true" :showSeconds="true" :showMinutes="true"></tn-count-down>-->
			<!--				</view>-->
			<!--			</view>-->
			<view style="text-align: center;padding:0 30rpx;" v-if="info.activity_type==1">
				<button class="mmy" hover-class="none" @click="application_add" v-if="info.type=='未开始'">确认报名</button>
				<button class="mmy" hover-class="none" :disabled="true"
					v-if="info.type=='已结束'||info.type=='进行中'">报名已结束</button>

			</view>
			<view style="text-align: center;padding:0 30rpx;" v-if="info.activity_type==2">
				<button class="mmy" hover-class="none" @click="application_add" v-if="info.type=='进行中'">确认提交</button>
				<button class="mmy" hover-class="none" :disabled="true" v-if="info.type=='已结束'">问卷已结束</button>
			</view>
			<view style="text-align: center;padding:0 30rpx;" v-if="info.activity_type==3">
				<button class="mmy" hover-class="none" @click="juanMod=true" v-if="info.type=='进行中'">我要捐助</button>
				<button class="mmy" hover-class="none" :disabled="true" v-if="info.type=='已结束'">捐助已结束</button>
			</view>
		</view>
		<tn-modal v-model="juanMod" :custom="true">
			<view style="padding: 20rpx;text-align: center;font-size: 40rpx;">感谢您的捐助</view>
			<tn-form :labelWidth="180">
				<tn-form-item label="捐助金额">
					<tn-input v-model="money" type="decimal" placeholder="请填写捐助金额" />
				</tn-form-item>
			</tn-form>
			<view class="tn-flex tn-flex-row-center" style="margin-top: 50rpx;">
				<tn-button @click="juanMod=false" backgroundColor="#E6E6E6" fontColor="#838383">我再想想</tn-button>
				<tn-button @click="juanzhuDo" backgroundColor="#28B93D" fontColor="#ffffff"
					style="margin-left: 70rpx;">确定捐助</tn-button>
			</view>
		</tn-modal>
	</view>
</template>

<script>
	import {
		eventInfo,
		applicationAdd
	} from '@/util/api.js';
	import store from '@/store/index.js'
	export default {
		data() {
			return {
				money: '',
				juanMod: false,
				button: [{
						text: '取消',
						backgroundColor: '#E6E6E6',
						fontColor: '#FFFFFF',
						shape: 'round'
					},
					{
						text: '确定',
						backgroundColor: 'tn-bg-indigo',
						fontColor: '#FFFFFF'
					}
				],
				form: {
					wenda: '',
					danxuan: '',
					hobby: [],
				},
				topCurrent: 0,
				id: 0,
				info: {},
				apiImgUrl: this.$store.state.imgUrl
			}
		},
		mounted() {
			// this.$wxshare({
			// 	url: 'http://ysh.0rui.cn/#/pages/index/event_info',
			// 	data: {
			// 		url: window.location.href.split("#")[0],
			// 	},
			// 	share_data: {
			// 		title: '河南省青年企业家协会开展走进开封市龙亭区暨产业考察交流活动',
			// 		desc: '河南省青年企业家协会开展走进开封市龙亭区暨产业考察交流活动',
			// 		imgUrl: 'http://ysh.0rui.cn/static/ser.png',
			// 		link: "http://ysh.0rui.cn/#/pages/index/event_info", // 分享链接，该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
			// 	}
			// })
			// var id =  this.$route.query.id;
			// this.id = id;
			// this.getEventInfo();
		},
		onLoad(d) {
			console.log(d);
			this.id = d.id;
			this.getEventInfo();
		},
		methods: {
			juanzhuDo() {
				this.juanMod = false;
				uni.showToast({
					title: '感谢您的捐助！',
					icon: 'none',
					duration: 2000
				});
			},
			application_add() {
				var uid = uni.getStorageSync('uid');
				if (!uid) {
					uni.showToast({
						title: '请登录后报名！',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				applicationAdd({
						association_id: store.state.Gid,
						member_id: uid,
						activity_id: this.id,
						application_time: new Date().toISOString().slice(0, 19).replace('T', ' ')
					})
					.then(res => {
						if (res.code == 1) {
							uni.showToast({
								title: '报名成功！',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			getEventInfo() {
				eventInfo({
						association_id: store.state.Gid,
						id: this.id
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							var key = res.data;
							if (key.activity_content.indexOf("<img") != -1) {
								key.activity_content = getApp().addWidthToImages(key.activity_content);
							}
							this.info = key;
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			goBack() {
				if (getCurrentPages().length > 1) {
					uni.navigateBack()
				} else {
					uni.redirectTo({
						url: '/pages/index/index'
					})

				}
			}
		}
	}
</script>

<style>
	.mmy {
		background-color: #F73909;
		border-radius: 30px;
		height: 80rpx;
		width: 100%;
		color: #FFF;
		line-height: 80rpx;
		font-size: 28rpx;
	}
</style>