<template>
	<view class="safe-area-inset-bottom">
		<my-bar title="活动详情" :transparent="transparent">
			<view slot="content" class="publish">
				<image @click="$util.preview(detail.poster)" :src="detail.poster" style="height: 340rpx;width: 100%;">
				</image>
			</view>
		</my-bar>
		<view class="clock">
		</view>
		<view class="content">
			<text class="title">{{detail.title}}</text>

			<view class="data flex" style="margin-top: 30rpx;">
				<u-icon name="eye" color="#EF9944"></u-icon>
				<view v-if="detail.auditStatus=='WAITING_MALL'" class="margin-left-10">
					审核状态：
					<text style="color: #EF9944;">待审核</text>
				</view>
				<view v-if="detail.auditStatus=='WAITING_PLATFORM'" class="margin-left-10">
					审核状态：
					<text style="color: #EF9944;">待平台审核</text>
				</view>
				<view v-if="detail.auditStatus=='PASS'" class="margin-left-10">
					审核状态：
					<text style="color: #19be6b;">审核通过</text>
				</view>
				<view v-if="detail.auditStatus=='FAIL'" class="margin-left-10">
					审核状态：
					<text style="color: #fa3534;">审核不通过</text>
				</view>
				<view v-if="detail.auditStatus=='STOP'" class="margin-left-10">
					审核状态：
					<text style="color: #fa3534;">活动已停用</text>
				</view>
			</view>
			<view class="data" style="margin-top: 30rpx;">
				<u-icon name="clock" color="#EF9944"></u-icon>
				<text class="margin-left-10">开始时间：{{detail.beginTime}}</text>
			</view>
			<view class="data" style="margin-top: 30rpx;">
				<u-icon name="clock" color="#EF9944"></u-icon>
				<text class="margin-left-10">结束时间：{{detail.endTime}}</text>
			</view>
			<view class="data" style="margin-top: 30rpx;">
				<u-icon name="grid" color="#EF9944"></u-icon>
				<text class="margin-left-10">活动分类：{{detail.labelKey}}</text>
			</view>
			<view class="data" style="margin-top: 30rpx;">
				<u-icon name="coupon" color="#EF9944"></u-icon>
				<text class="margin-left-10">活动折扣：{{detail.discount * 10}} 折</text>
			</view>
		</view>

		<view class="attend" v-if="!$isEmpty(joinRecords)">
			<view class="margin-bottom-20">
				<u-icon name="calendar-fill" color="#EF9944"></u-icon>
				<text class="margin-left-10">已参加</text>
			</view>
			<view class="flex">
				<view class="flex " style="width: 90%;">
					<view class="data" v-for="(item,index) in joinRecords" :key="index">
						<view class="item">
							<image style="border-radius: 50%;" :src="item.joinLogo" mode="aspectFill"></image>
							<view>
								<text>{{item.joinName | ellipsis}}</text>
								<text>{{item.discount * 10}}折</text>
							</view>
						</view>
					</view>
				</view>
				<view v-if="detail.activityJoinRecords.length>3" class="center" style="width: 10%;margin-right: 15rpx;">
					<u-icon name="more-circle" size="80" color="#ababab"></u-icon>
				</view>
			</view>
		</view>


		<view class="intro">
			<view class="flex">
				<u-icon name="bookmark" color="#EF9944"></u-icon>
				<text class="margin-left-10">活动介绍</text>
			</view>
			<view class="desc">
				{{detail.intro}}
			</view>
		</view>
	</view>
</template>

<script>
	import myBar from "@/components/my-bar.vue"
	export default {
		components: {
			myBar
		},
		onPageScroll(obj) {
			this.transparent = obj.scrollTop * 0.006;
		},
		filters: {
			// 名称超出显示省略号
			ellipsis(value) {
				if (!value) return '';
				if (value.length > 4) {
					return value.slice(0, 3) + '...'
				}
				return value
			}
		},
		data() {
			return {
				id: '',
				current: 0,
				transparent: '',
				//活动详情
				detail: {},
				joinRecords:[]
			}
		},
		onLoad(options) {
			this.id = options.id
			if (!this.id) {
				this.$u.toast('系统错误')
				return
			}
			this.fetchDetail()
			this.getJoinRecord()
		},
		methods: {
			getJoinRecord() {
				let params = {
					activityId: this.id
				}
				this.$api.joinRecord.list(params).then(res => {
					this.joinRecords = res.data.records
				})
			},
			fetchDetail() {
				this.$api.activity.detail({
					id: this.id
				}).then(res => {
					this.detail = res.data
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.publish {
		overflow: hidden;
		border-radius: 10rpx;
		height: 320rpx;
		position: absolute;
		bottom: 20rpx;
		left: 0;
		right: 0;
		width: 90%;
		margin: 0 auto -50rpx;
		border-radius: 10rpx;
		box-shadow: 0rpx 16rpx 8rpx -8rpx #a8a8a8;

		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;

		text {
			font-size: 26rpx;
			color: #797979;
		}
	}

	.clock {
		background-color: #FFFFFF;
		height: 80rpx;
		padding-bottom: 20rpx;

		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		align-items: center;

		.tips {
			margin-top: 10rpx;
			font-size: 24rpx;
			color: #FF9447;
		}
	}

	.content {
		padding: 0rpx 30rpx 15rpx;
		background-color: #FFFFFF;

		.title {
			line-height: 50rpx;
			font-weight: 800;
			font-size: 32rpx;
		}

		.data {
			margin: 20rpx 0;
			color: #787878;
		}
	}

	.intro {
		margin-top: 15rpx;
		padding: 15rpx 30rpx;
		background-color: #FFFFFF;

		.desc {
			color: #9a9a9a;
			margin-top: 20rpx;
			line-height: 46rpx;
			font-size: 28rpx;
		}
	}

	.attend {
		margin-top: 15rpx;
		padding: 15rpx 0 15rpx 30rpx;
		background-color: #FFFFFF;

		.data {
			margin: 10rpx 20rpx 10rpx 0;
			$width: 80rpx;

			.item {
				width: 200rpx;
				height: $width;
				background-color: #f0f0f0;
				border-radius: 50rpx;
				display: flex;

				image {
					width: $width;
					height: $width;
				}

				view {
					padding-left: 10rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					font-size: 20rpx;

					text:first-child {
						margin-bottom: 4rpx;
					}
				}
			}
		}
	}

	.history {
		background-color: #ffff;
		box-sizing: border-box;
		padding: 40rpx 20rpx 20rpx 50rpx;
	}

	.nav-title {
		font-weight: 300;
		font-size: 28upx;
		padding-top: 20rpx;
		line-height: 50rpx;
	}

	.content {
		box-shadow: 0 8rpx 10rpx rgba(234, 234, 234, 0.5), 8rpx 0rpx 10rpx rgba(234, 234, 234, .5), -8rpx 0rpx 10rpx rgba(234, 234, 234, .5);
		background-color: #FFFFFF;
		padding: 20rpx;
		border-radius: 10rpx;
		margin: 20rpx 0;
	}
</style>
