<template>
	<view class="page">
		<view class="content">
			<scroller @init="initScroller" @down="refreshData" @up="getData" style="height: 100%;" :up="optUp"
				@scroll="navFloatShow(scroller)" :fixed="true">
				<image src="/static/images/ic_activitydetail_bg.png" mode="aspectFill" class="swiper-item"></image>
				<view class="rule-desc">公民选择劳动参与义务植树,实际劳动工作量按照<全名义务植树尽责形式管理办法(试行)>规定折算植树株数</view>
				<view class="explain" @click="openExplain()">尽责形式说明</view>
				<view :class="fixedSearch? 'fixed-box':'nofixed-box'">
					<view class="list-title-box">
						<view class="list-title">劳动尽责活动</view>
						<view class="list-mine" @click="openMine">我参与的</view>
					</view>
					<view class="search">
						<input type="text" confirm-type="search" @input="onSearchInput" placeholder="请输入要收搜的内容"
							@confirm="doSearch" class="search-content" />
						<image src="../../static/images/ic_search.png" mode="scaleToFill" class="search-icon"></image>
					</view>
				</view>

				<!-- 列表 -->
				<view class="list-box">
					<view class="item" v-for="(item,index) in list" :key="index" @click="openDetail(item.activityId)">
						<view class="activity-item">
							<view class="activity-item-box">
								<view class="activity-item-num">
									{{item.joinedCount}}/{{item.joinCount}}
								</view>
								<image :src="imgUrl+item.img" mode="scaleToFill" class="img"></image>
							</view>
							<view class="activity-content">
								<rich-text class="activity-name" :nodes="item.name"></rich-text>
								<view class="item-type">
									<view class="type-type">{{item.activityType}}</view>
									<view class="type-theme">{{item.theme}}</view>
								</view>
								<view class="activity-time">{{item.startTime}}</view>
								<!-- <rich-text class="activity-desc" :nodes="item.content"></rich-text> -->
							</view>
						</view>
					</view>
				</view>
			</scroller>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import scroller from '@/components/scroller/scroller.vue';
	export default {
		components: {
			scroller
		},

		data() {
			return {
				currentIndex: 1,
				list: [],
				list2: [],
				scroller: {},
				scroller2: {},
				optUp: {
					auto: true,
					onScroll: true,
					page: {
						num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
						size: 10 //每页数据条数,默认10
					},
					empty: {
						tip: '暂无数据~'
					}
				},
				token: "",
				imgUrl: this.$api.common.imgUrl,
				searchContent: "",
				fixedSearch: false,
				activityType: '',
			}
		},
		onLoad(res) {
			if (res.index) {
				this.currentIndex = res.index
			}
			if (res.type) {
				this.activityType = res.type
			}
		},
		onShow(res) {
			this.token = getApp().globalData.token
		},
		methods: {
			...mapMutations(['login']),
			tabChange(i) {
				this.currentIndex = i;
				if (i == 1) {
					this.bg = this.bg1
				} else {
					this.bg = this.bg2
				}
				if (this.currentIndex == 2) {
					if (this.token == "") {
						uni.setStorageSync("loginOriginUrl", "/pages/duty/activitylist");
						uni.navigateTo({
							url: "/pages/user/login"
						})
					} else {
						console.log(this.list2)
						this.getData2()
					}
				}
			},
			openExplain() {
				uni.navigateTo({
					url: "/pages/duty/dutyexplain"
				})
			},
			openMine() {
				if (this.token == '') {
					uni.setStorageSync("loginOriginUrl", "/pages/duty/activitynewlist");
					uni.navigateTo({
						url: "/pages/user/login"
					})
				} else {
					uni.navigateTo({
						url: '/pages/duty/activityminelist'
					})
				}
			},
			closePage() {
				uni.navigateBack()
			},
			/*收搜*/
			doSearch() {
				uni.hideKeyboard()
				if (this.searchContent == "") {
					this.$alert("请输入关键字");
				}
				this.refreshData()
			},
			/*初始化滚动*/
			initScroller(scroller) {
				this.scroller = scroller;
				this.loadData();
			},

			/*刷新数据*/
			refreshData() {
				uni.showLoading({
					title: '刷新中'
				});
				this.scroller.resetUpScroll();
			},
			onSearchInput: function(event) {
				this.searchContent = event.target.value
				console.log(event.target.value)
				if (event.target.value == "") {
					uni.hideKeyboard();
					this.refreshData();
				}
			},
			/*加载数据*/
			loadData() {
				this.list = [];
				this.scroller.resetUpScroll();
			},
			/*滚动时导航栏浮动*/
			navFloatShow(scroller) {
				if (scroller) {
					if (scroller.scrollTop > 350) {
						if (!this.fixedSearch) {
							this.fixedSearch = true;
						}
					} else {
						if (this.fixedSearch) {
							this.fixedSearch = false;
						}
					}
				}
			},
			//获取列表数据
			getData() {
				this.$app.request({
					url: this.$api.duty.getActivityList,
					method: 'GET',
					data: {
						page: this.scroller.num,
						rows: this.scroller.size,
						activityType: this.activityType,
						'keywords': this.searchContent
					},
					dataType: 'json',
					success: res => {
						if (res.rows != undefined) {
							if (this.scroller.num == 1) {
								this.list = [];
							}
							var tempList = []
							tempList = res.rows
							if (tempList.length > 0) {
								for (var i = 0; i < tempList.length; i++) {
									if (tempList[i].photo) {
										var index = tempList[i].photo.indexOf(",")
										if (index != -1) {
											tempList[i].img = tempList[i].photo.substring(0, index)
										}
										tempList[i].img = tempList[i].photo
									}
								}
								this.list = this.list.concat(tempList);
							}
							this.scroller.endBySize(res.rows.length, res.rows.total);
							this.showPageLoading = false;
						} else {
							this.scroller.endSuccess();
							this.$alert(res.msg);
						}
					},
					fail: res => {
						this.scroller.endErr();
					},
					complete: res => {
						uni.stopPullDownRefresh();
						uni.hideLoading();
					}
				});
			},

			//获取列表数据
			// getData2() {
			// 	this.$app.request({
			// 		url: this.$api.duty.getMineActivity,
			// 		method: 'GET',
			// 		dataType: 'json',
			// 		header: {
			// 			token: this.token
			// 		},

			// 		success: res => {
			// 			console.log(res.status)
			// 			if (res != undefined && res.status == undefined) {
			// 				for (var i = 0; i < res.length; i++) {
			// 					if (res[i].activityDTO.photo) {
			// 						var index = res[i].activityDTO.photo.indexOf(",")
			// 						if (index != -1) {
			// 							res[i].img = res[i].activityDTO.photo.substring(0, index)
			// 						}
			// 						res[i].img = res[i].activityDTO.photo
			// 					}
			// 				}
			// 				this.list2 = res;
			// 			} else {
			// 				this.list2 = []
			// 			}

			// 		},
			// 		fail: res => {
			// 			uni.showToast({
			// 				icon: "error",
			// 				title: "加载失败"
			// 			})
			// 		},
			// 		complete: res => {}
			// 	});
			// },
			openDetail(id) {
				uni.navigateTo({
					url: "/pages/duty/activitydetail?id=" + id + "&type=" + -1
				})
			},
			openDetailType(id, ss) {
				uni.navigateTo({
					url: "/pages/duty/activitydetail?id=" + id + "&type=" + 2 + "&itemId=" + ss
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;

	}

	.page {
		display: flex;
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		height: 100%;
		background: #F4F4F4;
	}

	.content-scroller {
		flex: 1;
		width: 100%;
		height: 100rpx;
	}

	.swiper-item {
		width: 100%;
		height: 400rpx;
		margin: 0rpx;
	}

	.rule-desc {
		font-size: 30.67rpx;
		background: white;
		color: black;
		padding: 20rpx;
		margin-top: -10rpx;
	}

	.explain {
		width: 100%;
		background: #ffffff;
		margin-top: 10rpx;
		padding: 20rpx;
		font-size: 27rpx;
	}

	.list-title-box {
		display: flex;
		flex-direction: row;
		margin-top: 10rpx;
		justify-content: space-between;
	}

	.list-title {
		flex: 2;
		padding: 20rpx;
		background: white;
		font-size: 27rpx;
		font-weight: 400;
		color: #40B344;
		line-height: 52rpx;
	}

	.list-mine {
		flex: 1;
		padding: 20rpx;
		background: white;
		margin-left: 20rpx;
		font-size: 27rpx;
		font-weight: 400;
		color: #393A3D;
		line-height: 52rpx;
	}

	.fixed-box {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		padding-top: 40rpx;
		background: #f4f4f4;
		z-index: 10;
		padding-bottom: 10rpx;
	}

	.nofixed-box {
		position: static;
	}


	.content {
		width: 100%;
		position: relative;
		height: 100%;
	}

	.box {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		height: 100%;
		width: 98%;
		position: absolute;
		top: 170rpx;
		left: 50%;
		transform: translate(-50%, 0);
		-webkit-transform: translate(-50%, 0);
		box-shadow: 0rpx 7rpx 33rpx 16rpx rgba(188, 226, 204, 0.15);
		border-radius: 30rpx;

		.title-img {
			width: 443rpx;
			height: 203rpx;
			align-self: center;
		}

		.title-text {
			color: white;
			text-align: center;
			align-self: center;
			display: flex;
			flex-direction: column;
			font-size: 30rpx;
			font-weight: 400;
		}
	}

	.tab-bar {
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		padding-top: 15rpx;

		.tab-active {
			text-align: center;
			font-size: 40rpx;
			font-weight: bold;
			color: #00821E;
		}

		.tab-default {
			text-align: center;
			font-size: 40rpx;
			font-weight: 200;
			color: #00821E;
		}
	}

	.title-box {
		width: 100%;
		height: 800rpx;
		background-image: url('../../static/images/ic_activity_bg.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}

	.state-bar {
		position: absolute;
		top: 0%;
		left: 0%;
		width: 100%;
		margin: 45rpx 0rpx;
		height: 100rpx;
		display: flex;
		flex-direction: row;
		align-items: center;

		image {
			width: 50rpx;
			height: 50rpx;
			margin-left: 20rpx;
		}

		.tab {
			display: flex;
			flex-direction: row;
			color: white;
			justify-content: center;
			font-size: 40rpx;
			align-self: center;
			text-align: center;
			width: 100%;
			margin-left: -70rpx;

			:last-child {
				margin-left: 40rpx;
			}

			.tab-1 {
				border-bottom-width: 8rpx;
				border-bottom-style: solid;
				border-bottom-color: white;
			}
		}
	}

	.container-box {
		display: flex;
		flex-direction: column;
		background-color: white;
		justify-content: center;
		align-items: flex-start;
		margin: 20rpx;
		padding: 30rpx 0rpx;
		border-top-left-radius: 30rpx;
		border-top-right-radius: 30rpx;
		height: 100%;

		.area-box {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			margin: 30rpx;

			.area-title {
				font-size: 30rpx;
				color: #747474;
			}

			.area-picker {
				background-color: #E8F6EE;
				margin-left: 20rpx;
				color: #b3b3b3;
				padding: 10rpx 30rpx;
			}
		}
	}

	/*搜索*/
	.search {
		display: flex;
		flex-direction: row;
		align-items: center;
		background: white;
		border-radius: 50rpx;
		margin: 20rpx 20rpx 0rpx 20rpx;
		box-shadow: 6rpx 9rpx 18rpx 3rpx rgba(140, 140, 140, 0.17);
		align-self: center;

		.search-content {
			padding: 10rpx 24rpx 10rpx 24rpx;
			margin-right: 15rpx;
			flex: 1;
			display: flex;
			align-items: center;
		}

		/deep/.input {
			color: #8cc7b5;
		}

		.search-icon {
			width: 30rpx;
			height: 30rpx;
			margin-right: 15rpx;
		}

	}

	.list-box {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: flex-start;
		padding: 20rpx;
		width: 95%;
		height: 100%;

		.item {
			display: flex;
			flex-direction: column;
			background: white;
			border-radius: 10rpx;
			margin: 20rpx 0rpx;
			width: 100%;
			box-shadow: 0rpx 7rpx 33rpx 16rpx rgba(188, 226, 204, 0.15);

			.item-content {
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 10rpx;

				image {
					width: 200rpx;
					height: 130rpx;
				}

				.item-box {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: flex-start;
					width: 100%;
					margin-left: 20rpx;

					.item-title {
						color: #747474;

					}

					.item-person {
						color: #747474;
					}

					.item-bottom {
						display: flex;
						flex-direction: row;
						width: 95%;
						justify-content: space-between;
						color: #747474;

						.item-status {
							color: #00821E;
							border: 1rpx #8cc7b5 solid;
							font-size: 20rpx;
							text-align: center;
							padding: 0rpx 10rpx;
							align-self: center;
						}
					}
				}
			}



			.title {
				font-size: 30rpx;
				display: -webkit-box;
				text-overflow: ellipsis;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;
				overflow: hidden;
				padding: 10rpx;
				color: #000;
			}


		}

	}


	.activity-item {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: flex-start;
		padding: 10rpx 40rpx 10rpx 10rpx;

		.activity-img {
			width: 163rpx;
			height: 163rpx;
			min-width: 163rpx;
			min-height: 163rpx;
		}
	}


	.activity-item-box {
		width: 192rpx;
		height: 192rpx;
		position: relative;

		.activity-item-num {
			color: white;
			background: #0DB77E;
			width: fit-content;
			max-width: fit-content;
			padding: 0rpx 10rpx;
			border-top-right-radius: 20rpx;
			border-bottom-right-radius: 20rpx;
			position: absolute;
			top: 15rpx;
			font-size: 18rpx;
			left: 0;
			z-index: 2;
		}

		.img {
			width: 192rpx;
			height: 192rpx;
			position: relative;
			top: 0;
		}
	}

	.activity-content {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-start;
		margin-left: 10rpx;
		width: 75%;
		height: 200rpx;


		.activity-name {
			display: -webkit-box;
			font-size: 32rpx;
			color: black;
			font-weight: bold;
			text-overflow: ellipsis;
			word-break: break-all;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
			overflow: hidden;
			width: 100%;
		}

		.activity-time {
			font-size: 28rpx;
			color: gray;
		}

		.activity-desc {
			display: -webkit-box;
			font-size: 28rpx;
			color: gray;
			font-weight: bold;
			text-overflow: ellipsis;
			word-break: break-all;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
			overflow: hidden;
			width: 100%;
		}
	}

	.empty-data {
		align-items: center;
		align-self: center;
	}

	.item-type {
		display: flex;
		flex-direction: row;

		.type-theme {
			display: -webkit-box;
			background: #E9F7FF;
			font-size: 28rpx;
			padding: 0rpx 15rpx;
			margin-left: 10rpx;
			text-overflow: ellipsis;
			word-break: break-all;
			text-align: center;
			color: #12D577;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
			overflow: hidden;
		}

		.type-type {
			display: -webkit-box;
			background: #ECFFF9;
			font-size: 28rpx;
			text-overflow: ellipsis;
			word-break: break-all;
			color: #009FFF;
			text-align: center;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
			overflow: hidden;
			padding: 0rpx 15rpx;
		}
	}
</style>
