<template>
	<view class="page">

		<view class="status-bar"></view>

		<view class="content">
			<scroller @init="initScroller" @down="refreshData" @up="getList" :up="optUp"
				@scroll="navFloatShow(scroller)" :fixed="false">
				<!-- 轮播图 -->
				<swiper v-if="slider.length > 0" class="swiper" :indicator-dots="false" :autoplay="true"
					:circular="true">
					<swiper-item v-for="(item, index) in slider" :key="index">
						<navigator class="item" hover-class="none" :url="'/pages/duty/list'">
							<image :lazy-load="true" :src="item.imageUrl" mode="scaleToFill"></image>
						</navigator>
					</swiper-item>
				</swiper>
				<view class="func-box">
					<view class="item" @click="openActivity()">
						<image src="../../static/images/ic_labour_pious_icon.png" mode="scaleToFill"></image>
						<text>劳动尽责</text>
					</view>
					<view class="item" @click="openCertificate">
						<image src="../../static/images/ic_certify_search_icon.png" mode="scaleToFill"></image>
						<text>证书查询</text>
					</view>
					<view class="item" @click="openExplain">
						<image src="../../static/images/ic_duty_answer_icon.png" mode="scaleToFill"></image>
						<text>尽责说明</text>
					</view>
				</view>
				<view class="thick-divider"></view>
				<view @click="openList" class="title-item">
					<view class="title-item-line">
						<view class="line-green"></view>
						<view class="title-item-title">最新活动</view>
					</view>
					<view class="title-item-content">更多></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>
							</view>
						</view>
					</view>
				</view>
				<!-- <view class="duty-box">
					<view class="duty-content" v-if="list.length>0">
						<block v-for="(item,index) in list" :key="index">
							<view class="activity-item" @click="openDetail(item.activityId)">

								<view class="activity-item-box">
									<view class="activity-item-num">
										{{item.joinedCount}}/{{item.joinCount}}
									</view>
									<image :src="imgUrl+item.img" mode="aspectFill" 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>
						</block>
					</view>
					<view v-else>
						<emptyView></emptyView>
					</view>
				</view> -->
			</scroller>
		</view>
		<pageLoading v-if="showPageLoading"></pageLoading>
	</view>
</template>

<script>
	import pageLoading from '@/components/loading/pageLoading.vue';
	export default {
		components: {
			pageLoading
		},
		data() {
			return {
				showPageLoading: true,
				slider: [{
					imageUrl: "/static/images/ic_duty_title_bg.png"
				}], //轮播图
				list: [],
				scroller: {},
				optUp: {
					isLock: true,
					auto: true,
					onScroll: true,
					page: {
						num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
						size: 3 //每页数据条数,默认10
					},
					empty: {
						tip: '暂无数据~'
					}
				},
				imgUrl: this.$api.common.imgUrl,

			};
		},
		onLoad(res) {
			this.getList()
		},
		methods: {
			doSearch() {

			},
			onSearchInput(event) {

			},
			openActivity() {
				uni.navigateTo({
					url: '/pages/duty/activitynewlist'
				})
			},
			openExplain() {
				uni.navigateTo({
					url: "/pages/duty/dutyexplain"
				})
			},
			openCertificate() {
				uni.navigateTo({
					url: "/pages/user/mine_certif_search"
				})
			},
			openDetail(id) {
				uni.navigateTo({
					url: "/pages/duty/activitydetail?id=" + id + "&type=" + 1
				})
			},
			openList() {
				uni.navigateTo({
					url: "/pages/duty/activitynewlist"
				})
			},
			/*初始化滚动*/
			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 == "") {
					this.refreshData()
				}
			},
			/*加载数据*/
			loadData() {
				this.list = [];
				this.scroller.resetUpScroll();
			},
			/*滚动时导航栏浮动*/
			navFloatShow(scroller) {

			},
			getList() {
				var _self = this;
				_self.$app.request({
					url: _self.$api.duty.getActivityList,
					method: 'GET',
					data: {
						'rows': '10',
						'page': '1',
					},
					dataType: 'json',
					success: res => {
						uni.hideLoading()
						if (res.rows != undefined) {
							var tempList = []
							tempList = res.rows
							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
								}
							}
							_self.list = tempList
							_self.showPageLoading = false;
							_self.scroller.endBySize(res.rows.length, 3);
						} else {
							_self.scroller.endSuccess();
							_self.$alert(res.msg);
						}
					},
					fail: res => {
						uni.hideLoading()
						_self.scroller.endErr();
					},
					complete: res => {
						uni.hideLoading()
						uni.stopPullDownRefresh();
						_self.showPageLoading = false;
					}
				});
			}
		}

	};
</script>

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

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

	.content {
		flex: 1;
		width: 100%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		margin-top: 20rpx;
	}

	.thick-divider {
		height: 10rpx;
		background: #f2f2f2;
		width: 100%;
	}

	/*幻灯片广告 */
	.swiper {
		height: 420rpx;
		margin: 14rpx 24rpx 0;

		image {
			height: 420rpx;
			width: 100%;
			border-radius: 15rpx;
			//box-shadow: 0 0 12px #dddee1;
		}

		.current {
			width: 98%;
			height: 350rpx;
			margin: 1.0% 1.0%;
			transition: all 0.2s ease-in 0s;
		}

		.item {
			position: relative;

			.title {
				position: absolute;
				left: 0;
				bottom: 0;
				display: flex;
				justify-content: center;
				width: 100%;

				text {
					margin: 7% 6%;
					display: flex;
					align-items: center;
					color: #fff;
					display: -webkit-box;
					text-overflow: ellipsis;
					word-break: break-all;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					font-size: 34rpx;
					padding: 14rpx 20rpx;
					max-width: 610rpx;
					line-height: 1.3;
					border-radius: 5rpx;
				}
			}
		}
	}

	.func-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-around;
		padding: 20rpx 10rpx;

		.item {
			display: flex;
			flex-direction: column;
			align-items: center;

			image {
				width: 80rpx;
				height: 80rpx;
			}

			text {
				color: black;
				font-size: 30rpx;
				margin-top: 10rpx;
			}
		}
	}

	.divider-img {
		width: 94%;
		height: 120rpx;
		align-self: center;
		margin: 10rpx 20rpx;
	}

	/*搜索*/
	.search {
		padding: 10rpx 24rpx 10rpx 24rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.search-content {
			background: #f2f2f2;
			border-radius: 15px;
			padding: 10rpx 24rpx 10rpx 24rpx;
			margin-right: 15rpx;
			flex: 1;
			display: flex;
			align-items: center;
		}

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

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

		.btn {
			color: #b3b3b3;
		}
	}

	.duty-box {
		display: flex;
		flex-direction: row;
		height: 100%;
		width: 100%;

		.duty-content {
			display: flex;
			flex-direction: column;
			width: 100%;

			.content-left {
				display: flex;
				flex-direction: column;
				background-image: url('/static/images/ic_duty_index_item_1.png');
				width: 48%;
				height: 120%;
				min-height: 100%;
				background-size: 100% 100%;
				background-repeat: no-repeat;
				margin: 10rpx;
				padding: 15rpx;

				.title {
					display: -webkit-box;
					text-overflow: ellipsis;
					word-break: break-all;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					font-size: 32rpx;
				}

				.btn {
					background: #169302;
					border-radius: 15rpx;
					padding: 10rpx 15rpx;
					width: 140rpx;
					color: white;
					text-align: center;
					font-size: 25rpx;
					margin-top: 20rpx;
					align-self: flex-end;
				}

				.time {
					margin-top: 20rpx;
					font-size: 25rpx;
				}
			}

			.content-right {
				display: flex;
				flex-direction: column;
				width: 48%;
				height: 120%;
				margin: 10rpx;

				.right-item-top {
					display: flex;
					flex-direction: column;
					background-image: url('/static/images/ic_duty_index_item_2.png');
					width: 100%;
					height: 50%;
					min-height: 53%;
					background-size: 100% 100%;
					background-repeat: no-repeat;

					.title {
						display: -webkit-box;
						text-overflow: ellipsis;
						word-break: break-all;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						overflow: hidden;
						font-size: 32rpx;
						padding: 15rpx;
					}

					.btn {
						background: #169302;
						border-radius: 15rpx;
						padding: 10rpx 15rpx;
						width: 140rpx;
						color: white;
						text-align: center;
						font-size: 25rpx;
						margin-top: 20rpx;
						margin-left: 10rpx;
						align-self: flex-start;
					}
				}

				.right-item-bottom {
					display: flex;
					flex-direction: column;
					margin-top: 10rpx;
					background-image: url('/static/images/ic_duty_index_item_3.png');
					width: 100%;
					height: 50%;
					min-height: 50%;
					background-size: 100% 100%;
					background-repeat: no-repeat;

					.title {
						display: -webkit-box;
						text-overflow: ellipsis;
						word-break: break-all;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						overflow: hidden;
						font-size: 32rpx;
						padding: 15rpx;
					}

					.btn {
						background: #169302;
						border-radius: 15rpx;
						padding: 10rpx 15rpx;
						width: 140rpx;
						color: white;
						text-align: center;
						margin-left: 10rpx;
						font-size: 25rpx;
						margin-top: 20rpx;
						align-self: flex-start;
					}
				}
			}
		}
	}

	.title-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 20rpx 30rpx;

		.title-item-line {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: center;
		}

		.title-item-title {
			color: black;
			font-size: 32rpx;
			display: flex;
			flex-direction: row;
			margin-left: 10rpx;
		}

		.title-item-content {
			color: #3A3B3E;
			font-size: 28rpx;
			margin-right: 10rpx;
		}
	}

	.line-green {
		width: 10rpx;
		background: #0DB77E;
		height: 30rpx;
	}


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

		.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: flex-start;
		align-items: flex-start;
		margin-left: 10rpx;

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

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

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

	.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;
		}
	}
	
	.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;
			}
	
	
		}
	
	}
</style>
