<template>
	<view class="safe-area-inset-bottom">
		<my-bar title="发布活动" :transparent="transparent">
			<view slot="content" class="publish">
				<image :src="detail.pic" style="height: 380rpx;width: 100%;"></image>
			</view>
		</my-bar>
		<view class="clock">
			<!-- <view class="cu-btn round sm" style="background-color: #dcdcdc;">
				<u-icon name="clock"></u-icon>
				<text class="margin-left-10">设置响应倒计时</text>
			</view>
			<view class="tips">
				<text>*</text>
				<text>如未在限定时间内响应，系统默认自动推送给旗下商户。</text>
			</view> -->
		</view>

		<view class="content">
			<text class="title">{{detail.title}}</text>
			<view class="data" style="margin-top: 30rpx;">
				<u-icon name="clock"></u-icon>
				<text class="margin-left-10">{{detail.beginTime | date('mm/dd hh:MM:ss')}} 至 {{detail.endTime | date('mm/dd hh:MM:ss')}}</text>
			</view>
			<view class="data">
				<u-icon name="map"></u-icon>
				<text class="margin-left-10">仅限全天河区内报名</text>
			</view>
			<view class="data flex">
				<view class="flex">
					<u-icon name="grid"></u-icon>
					<text class="margin-left-10">{{detail.labelNames}}</text>
				</view>
				<view class="flex margin-left-50">
					<u-icon name="bag"></u-icon>
					<text class="margin-left-10">活动供应价{{detail.supplyPrice}}%</text>
				</view>
			</view>
			<view class="data">
				<u-icon name="home-fill"></u-icon>
				<text class="margin-left-10">联营积分全场通用</text>
			</view>
		</view>
		
		<view class="intro" v-if="current==1">
			<view class="flex">
				<u-icon name="coupon"></u-icon>
				<text class="margin-left-10">商场活动补贴</text>
			</view>
			<view class="desc" style="display: flex;border-bottom: 1rpx solid #DDDDDD;align-items: center;">
				<u-input v-model="value" placeholder="请输入折扣" style="width: 90%;"/>
				<text class="padding-left-20">%</text>
			</view>
		</view>

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

		<view class="attend">
			<view class="margin-bottom-20">
				<u-icon name="calendar-fill"></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 3" :key="index">
						<view class="item">
							<image src="../../static/del/del2.png" mode=""></image>
							<view>
								<text>{{name | ellipsis}}</text>
								<text>0.5折</text>
							</view>
						</view>
					</view>
				</view>
				<view class="center" style="width: 10%;margin-right: 15rpx;">
					<u-icon name="more-circle" size="80" color="#ababab"></u-icon>
				</view>
			</view>
		</view>

		<view @click="operate" class="center" style="margin:50rpx 0rpx 20rpx;">
			<view class="cu-btn btn-bg-color" style="width: 90%;height: 86rpx;border-radius: 12rpx;">
				<block v-if="current==0">
					<text v-if="detail.auditStatus==0">待审核</text>
					<text v-if="detail.auditStatus==1">审核通过</text>
					<text v-if="detail.auditStatus==2">审核不通过</text>
					<text v-if="detail.auditStatus==3">已停用</text>
				</block>
				<block v-if="current==1">
					<text>参加活动</text>
				</block>
				<block v-if="current==2">
					<text>退出活动</text>
				</block>
			</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, //0 发起活动详情，1可参加活动详情，2已参加活动详情
				transparent: '',
				name: '星巴克',
				detail: {}
			}
		},
		onLoad(options) {
			this.id = options.id
			this.current = options.current || 0
			if (!this.id) {
				this.$u.toast('系统错误')
				return
			}
			this.fetchDetail()
		},
		methods: {
			fetchDetail() {
				this.$api.activity.detail({
					id: this.id
				}).then(res => {
					this.detail = res.data
				})
			},
			operate() {
				if (this.current == 0) {
					return
				}
				if (this.current == 1) {
					//参加活动
					this.join()
				} else if (this.current == 2) {
					//退出活动
					this.exit()
				}

			},
			join() {
				this.$dialog.showModal("确定参加？").then(res => {
					let operateList = [{
						activityId: this.id,
						joinType: 1,
						joinId: this.vuex_mallId
					}]
					this.$api.activity.join(operateList).then(res => {
						if (res.success) {
							this.$dialog.showModal("参加成功", false).then(() => {
								this.$util.isReloadAndBack()
							})
						}
					})
				})
			},
			exit() {
				this.$dialog.showModal("确定退出？").then(res => {
					let operateList = [{
						activityId: this.id,
						joinType: 1,
						joinId: this.vuex_mallId
					}]
					this.$api.activity.exit(operateList).then(res => {
						if (res.success) {
							this.$dialog.showModal("退出成功", false).then(() => {
								this.$util.isReloadAndBack()
							})
						}
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.publish {
		overflow: hidden;
		border-radius: 10rpx;
		height: 380rpx;
		position: absolute;
		bottom: 20rpx;
		left: 0;
		right: 0;
		width: 92%;
		margin: 0 auto -120rpx;
		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: 120rpx;
		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: 15rpx 30rpx;
		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: 190rpx;
				height: $width;
				background-color: #eeeeee;
				border-radius: 50rpx;
				display: flex;

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

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

					text:first-child {
						font-weight: 800;
						margin-bottom: 4rpx;
					}
				}
			}
		}
	}
</style>
