<template>
	<view class="box">

		<!-- 自定义导航 -->
		<view class="zdyNavBox">
			<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
			<view class="zdyNav">
				<view class="zdyNavLeft">
					<image src="../../static/img/nav_icon_back.png" mode="aspectFit" class="backImg" @click="goback">
					</image>

				</view>
				<view class="zdyNavTitle">活动</view>
				<image src="../../static/img/icon_nav_add.png" mode="aspectFit" class="addImg" @click="goAdd"></image>
			</view>
		</view>
		<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
		<view style="height: 44px;"></view>

		<view class="tab">
			<view class="tabLine" :class="{tabActive:tabIndex==''}" @click="tabClick('')">全部</view>
			<view class="tabLine" :class="{tabActive:tabIndex=='未启用'}" @click="tabClick('未启用')">未启用</view>
			<view class="tabLine" :class="{tabActive:tabIndex=='未开始'}" @click="tabClick('未开始')">未开始</view>
			<view class="tabLine" :class="{tabActive:tabIndex=='进行中'}" @click="tabClick('进行中')">进行中</view>
			<view class="tabLine" :class="{tabActive:tabIndex=='已结束'}" @click="tabClick('已结束')">已结束</view>
		</view>

		<view class="conBox">
			<view class="itemHistory" v-for="(item,index) in itemData" :key="index">
				<image :src="item.Img" mode="" class="itemImg" @click="goDetail(item.ID)"></image>
				<view class="timeBox">
					<image v-if="item.state=='进行中'" src="../../static/img/bg_huangse.png" mode="" class="state"></image>
					<image v-if="item.state=='未开始'" src="../../static/img/bg_hongse.png" mode="" class="state"></image>
					<image v-if="item.state=='未启用'" src="../../static/img/bg_weiqiyong.png" mode="" class="state">
					</image>
					<image v-if="item.state=='已结束'" src="../../static/img/bg_jieshu.png" mode="" class="state"></image>

					<view class="time" v-if="item.StartTime">{{item.StartTime.slice(0,10)}}-{{item.EndTime.slice(0,10)}}
					</view>
				</view>
				<view class="name">{{item.ActivityName}}</view>

				<view class="btns">
					<view class="btnBox">
						<view class="btn" style="width: 120rpx;" @click="changeMore(item)">更多</view>
						<view class="btn" @click="goSign(item)">报名详情</view>
						<view class="btn" @click="goStatis(item)">数据统计</view>
						<view class="btn" style="width: 120rpx;" @click="goshare(item)">分享</view>
					</view>
					<view class="moreBtn" v-if="item.showMoreBtn==true">
						<view class="more" @click="goEdit(item.ID)">
							<image src="../../static/img/icon_bianji.png" mode="" class="btnImg"></image>
							<view class="btn2">编辑</view>
						</view>
						<view class="more" @click="open(item)" v-if="item.state=='未启用'">
							<image src="../../static/img/icon_tingyong.png" mode="" class="btnImg"></image>
							<view class="btn2">启用</view>
						</view>
						<view class="more" @click="stop(item)" v-else>
							<image src="../../static/img/icon_tingyong.png" mode="" class="btnImg"></image>
							<view class="btn2">停用</view>
						</view>
						
					</view>

				</view>

			</view>

			<!-- 上拉 加载更多 -->
			<view class="noMore" v-if="noMoreShow && (itemData.length!=0)">没有更多数据</view>
			<!-- 无数据空白页 -->
			<nodata v-if="itemData.length==0"></nodata>

		</view>


	</view>
</template>

<script scoped>
	import nodata from '../../components/nodata/nodata.vue'
	export default {
		components: {
			nodata,
		},

		data() {
			return {
				iStatusBarHeight: '',
				page: 1,
				itemData: [],
				noMoreShow: false,
				tabIndex: '',
                type:'',
			}
		},
		// onBackPress(options){
		// 	if (options.from === 'navigateBack') {
		// 	        return false
		// 	    }
		// 	console.log(options)
		// 	console.log("返回")
		// 	return true; 
		// },
		onLoad(opt) {
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.page = 1
			this.myOrderCoupon();
			this.type=opt.type
		},


		methods: {
			
			goAdd(){
				uni.navigateTo({
					url:'choice?type=2'
				})
			},
			goshare(item){
				//app交互
				var standalone = window.navigator.standalone
				var userAgent = window.navigator.userAgent.toLowerCase()
				var safari = /safari/.test(userAgent)
				var ios = /iphone|ipod|ipad|mac/.test(userAgent)
				var android = /android/.test(userAgent)
				if (ios) {
								 if ( true) {//!standalone&& !safari
								   window.webkit.messageHandlers.goShare.postMessage(item)
								 }
				} else if (android) {
								 window.android.postMessage()
				}
			},
			goback(){
				if(this.type==2){
					uni.navigateBack()
				}else{
					//app交互
					var standalone = window.navigator.standalone
					var userAgent = window.navigator.userAgent.toLowerCase()
					var safari = /safari/.test(userAgent)
					var ios = /iphone|ipod|ipad|mac/.test(userAgent)
					var android = /android/.test(userAgent)
					if (ios) {
									 if ( true) {//!standalone&& !safari
									   window.webkit.messageHandlers.goMyNav.postMessage(null)
									 }
					} else if (android) {
									 window.android.postMessage()
					}
				}
			   
			},
			open(item) {
				var that = this;
				uni.showLoading({
					title: '加载中'
				});
				that.$http('openH5SetTheGuest/updateAtivitySate', {
					id: item.ID,
					clState: 2
				}, 'POST').then(res => {
					uni.showToast({
						title: '成功',
						icon: 'none',
						duration: 3000
					});
						
					that.page = 1;
					that.myOrderCoupon()
				})
			
			},
			stop(item) {

				var that = this;
				uni.showModal({
					title: '提示',
					content: '停用后，用户将不可见此活动',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中'
							});
							that.$http('openH5SetTheGuest/updateAtivitySate', {
								id: item.ID,
								clState: 1
							}, 'POST').then(res => {
								uni.showToast({
									title: '成功',
									icon: 'none',
									duration: 3000
								});

								that.page = 1;
								that.myOrderCoupon()
							})
						} else if (res.cancel) {

						}
					}
				});


			},
			changeMore(item) {
				item.showMoreBtn = !item.showMoreBtn
			},
			tabClick(state) {
				this.tabIndex = state;


				this.page = 1;
				this.myOrderCoupon()
			},
			goDetail(id) {
				uni.navigateTo({
					url: 'activityDetail?id=' + id
				})
			},
			goEdit(id) {
				uni.navigateTo({
					url: 'eadit?id=' + id
				})
			},
			goSign(item) {
				uni.navigateTo({
					url: 'signJkDetail?activity=' + JSON.stringify(item)
				})
			},
			goStatis(item) {
				uni.navigateTo({
					url: 'statistics?activity=' + JSON.stringify(item)
				})
			},
			myOrderCoupon() {
				uni.showLoading({
					title: '加载中'
				})
				this.$http('openH5SetTheGuest/getAtivity', {

					page: this.page,
					limit: 10,
					state: this.tabIndex
				}, 'GET').then(res => {
					uni.hideLoading();
					// var list = res.data.Items
					var list = res.data.Items

					list.forEach((item, index) => {

						item.showMoreBtn = false

					})

					if (this.page == 1) {
						this.itemData = list
					} else {
						this.itemData = this.itemData.concat(list)
					}

					if (list.length < 10) {
						this.noMoreShow = true
					} else {
						this.noMoreShow = false
					}





				})
			},


		},

		// 下拉刷新 上拉加载更多
		onPullDownRefresh() {
			this.page = 1
			this.myOrderCoupon()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.page++;
			this.myOrderCoupon()
		},
	}
</script>

<style scoped lang="less">
	.box {
		background: #F4F5F7;
		min-height: 100vh;

	}

	.zdyNavBox {
		width: 100vw;
		background: #FFFFFF;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9999999;


	}

	.zdyNav {
		height: 44px;
		display: flex;
		justify-content: space-between;

		align-items: center;

	}

	.backImg {
		width: 44rpx;
		height: 44rpx;
		margin-left: 10rpx;
		margin-right: 20rpx;
	}

	.homeImg {
		width: 44rpx;
		height: 44rpx;

	}

	.zdyNavLeft {
		display: flex;
		align-items: center;
	}

	.zdyNavTitle {

		height: 44px;
		background: #FFFFFF;
		text-align: center;
		font-size: 34rpx;
		line-height: 44px;
	}

	.addImg {
		width: 36rpx;
		height: 36rpx;
		margin-right: 20rpx;
	}

	.tab {
		background: #FFFFFF;
		display: flex;
		justify-content: space-between;
		line-height: 87rpx;
		position: fixed;
		width: calc(100vw - 100rpx);
		padding-left: 50rpx;
		padding-right: 50rpx;
		height: 87rpx;
		z-index: 11;
		border-top: 1rpx solid #EEEEEE;
	}

	.tabLine {

		font-size: 32rpx;
		color: #666666;

		text-align: center;
	}

	.tabActive {
		color: #3F90F7;
		font-weight: bold;
		border-bottom: 4rpx solid #3F90F7;

	}

	.conBox {
		padding-top: 107rpx;
	}

	.itemHistory {
		margin: 0rpx 24rpx 20rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		
	}

	.itemImg {
		height: 280rpx;
		width: 702rpx;
		border-radius: 10rpx 10rpx 0px 0px;
		display: block;
		
	}

	.timeBox {
		display: flex;
		margin-top: -52rpx;
		align-items: flex-end;
		position: relative;
	}

	.state {
		width: 102rpx;
		height: 53rpx;
		
		
	}

	.time {
		padding: 5rpx 10rpx;
		color: #FFFFFF;
		font-size: 24rpx;
		background: rgba(0, 0, 0, 0.5);
		margin-left: -8rpx;
		border-radius: 0 10rpx 0 0;
		
	}

	.name {
		padding: 24rpx 20rpx;
		color: #333333;
		font-size: 28rpx;
		background: #FFFFFF;
		border-radius: 0 0 10rpx 10rpx;
		border-bottom: 1rpx solid #eeeeee;
	}

	.btns {
		position: relative;
	}

	.btnBox {
		padding: 26rpx 20rpx;
		border-radius: 0 0 10rpx 10rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.moreBtn {
		background-image: url("../../static/img/bg_more.png");
		background-size: 100% 100%;
		width: 196rpx;
		height: 234rpx;

		position: absolute;
		z-index: 999;
		top: 84rpx;
	}

	.more {
		display: flex;
		align-items: center;
		padding: 32rpx 46rpx 0;
	}

	.btnImg {
		width: 32rpx;
		height: 32rpx;
		margin-right: 15rpx;

	}

	.btn {
		font-size: 28rpx;
		color: #333333;
		width: 160rpx;
		height: 60rpx;
		border-radius: 30rpx;
		border: 1rpx solid #DDDDDD;
		text-align: center;
		line-height: 60rpx;
	}

	.btn2 {
		font-size: 28rpx;
		color: #333333;

		height: 60rpx;
		border-radius: 30rpx;

		text-align: center;
		line-height: 60rpx;
	}

	.noMore {
		text-align: center;
		line-height: 50rpx;
		color: #999999;
		font-size: 28rpx;
	}
</style>
