<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="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 @click="open=!open" class="intro" style="width: 100%;" >
			<text class="text-bold text-lg">审核流程</text>
			<text :class="open?'cuIcon-fold':'cuIcon-unfold'" class=" margin-left-10"></text>
		</view>

		<view class="history" v-if="open" :style="{marginBottom:safeAreaBottom}">
			<u-time-line>
				<u-time-line-item nodeTop="2" v-for="(item,index) in historyList" :key="index">
					<template v-slot:node>
						<view class="u-node bg-white">
							<u-icon name="clock-fill" color="#e0e3ea" :size="28"></u-icon>
						</view>
					</template>
					<template v-slot:content>
						<view>
							<view class="">{{item.createTime}}</view>
							<view style="width: 636rpx;">
								<view class="content">
									<view class="nav-title">
										<view class="">
											<text>【{{item.assigneeName?item.assigneeName:'联兑通平台'}}】在
												[{{item.createTime}}] 开始处理 [{{item.historyActivityName}}] 环节</text>
										</view>
										<view class="" v-if="item.historyActivityDurationTime">
											任务历时：
											[{{item.historyActivityDurationTime}}]
										</view>
										<view class="" v-if="item.comment">
											批复意见：
											[{{item.comment}}]
										</view>
										<view class="" v-if="item.endTime">
											结束时间：
											[{{item.endTime}}]
										</view>
									</view>
								</view>
							</view>
						</view>
					</template>
				</u-time-line-item>
			</u-time-line>
		</view>


		<block v-if="detail.auditStatus=='WAITING_MALL'">
			<view class="" style="height: 90rpx;"></view>
			<view :style="{marginBottom:safeAreaBottom}"
				class="footer-fixed padding-20  bg-white flex justify-end margin-right-30"
				style="box-sizing: border-box;z-index: 999;border-top: 1rpx solid #f1f1f1;">
				<view @click="opinionShow=true;pass=true" class="cu-btn df btn-bg-color  round margin-right-20"
					style="padding-left: 46rpx;padding-right: 46rpx;">
					通过
				</view>
				<view @click="opinionShow=true;pass=false" class="cu-btn df btn-line-color  round "
					style="padding-left: 46rpx;padding-right: 46rpx;">
					拒绝
				</view>
			</view>
		</block>

		<u-modal :show-cancel-button="true" confirm-color="#FF9447" @confirm="opinionConfirm" title="审核意见"
			:mask-close-able="true" v-model="opinionShow">
			<view class="slot-content" style="margin: 20rpx;">
				<u-form label-width="150" ref="uForm">
					<u-form-item :border-bottom="false">
						<u-input height="150" placeholder="请输入审核意见" v-model="auditAdvice" />
					</u-form-item>
				</u-form>
			</view>
		</u-modal>
	</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: '',
				transparent: '',
				//活动详情
				detail: {},
				opinionShow: false,
				pass: false,
				auditAdvice: '',
				pass: false,
				//流程详情
				flowDetail: {},
				//审核历史
				historyList: [],
				open:true
			}
		},
		onLoad(options) {
			this.id = options.id
			if (!this.id) {
				this.$u.toast('系统错误')
				return
			}
			this.fetchDetail()
		},
		methods: {
			async getHistoryFlowList(processInstanceId) {
				this.$api.flow.historyFlowList({
					processInstanceId
				}).then(res => {
					this.historyList = res.data
				})
			},
			fetchDetail() {
				this.$api.activity.detail({
					id: this.id
				}).then(res => {
					this.detail = res.data
					this.getTaskId(this.detail.processInstanceId)
					this.getHistoryFlowList(this.detail.processInstanceId)
				})
			},
			getTaskId(processInstanceId) {
				let params = {
					assignee: this.$global.flow_prefix.mall + this.vuex_mallId,
					processInstanceId
				}
				this.$api.flow.getTaskId(params).then(res => {
					this.flowDetail = res.data.records[0]
				})
			},
			opinionConfirm() {
				if (this.pass) {
					this.doPass()
				} else {
					this.doFail()
				}
			},
			doPass() {
				this.flowDetail.comment = this.auditAdvice ? this.auditAdvice : '同意'
				this.flowDetail.flag = 'ok'
				this.flowDetail.variables.pass = true
				this.$api.flow.flowAuditSubmit(this.flowDetail).then(res => {
					if (res.success) {
						this.$dialog.showModal('操作成功', false).then(() => {
							this.fetchDetail()
						})
					}
				})
			},
			doFail() {
				this.flowDetail.comment = this.auditAdvice ? this.auditAdvice : '不同意'
				this.flowDetail.variables.pass = true
				this.$api.flow.flowAuditSubmit(this.flowDetail).then(res => {
					if (res.success) {
						this.$dialog.showModal('操作成功', false).then(() => {
							this.fetchDetail()
						})
					}
				})
			}
		}
	}
</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: 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;
					}
				}
			}
		}
	}



	.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>
