<template>
	<view class="page">
		<view class="content">
			<view style="background: #ECECEC;padding:20rpx;">
				<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>
			<!-- Banner -->
			<scroller @init="initScroller" @down="refreshData" @up="getData" :up="optUp"
				@scroll="navFloatShow(scroller)" :fixed="false">
				<!-- <view class="num-box">
					<image src="../../static/images/ic_notify_icon.png" mode="aspectFill"></image>
					<text>您一共有{{totalNum}}张国土绿化荣誉证书</text>
				</view> -->
				<!-- 列表 -->
				<view class="content-box">
					<view class="item" v-for="(item,index) in list" :key="index">
						<image :src="imgUrl+item.fileId" mode="scaleToFill"></image>
						<view class="item-content" @click="showImg(item.fileId)">
							<view class="title">{{item.activityDTO.name}}</view>
							<view class="time">{{item.activityDTO.startTime}}</view>
							<view class="btn">查看详情</view>
						</view>
					</view>
				</view>
			</scroller>
		</view>

		<pageLoading v-if="showPageLoading"></pageLoading>
	</view>
</template>

<script>
	import scroller from '@/components/scroller/scroller.vue';
	import pageLoading from '@/components/loading/pageLoading.vue';
	export default {
		components: {
			pageLoading,
			scroller
		},
		data() {
			return {
				userName: "昵称",
				scroller: {},
				optUp: {
					auto: true,
					onScroll: true,
					page: {
						num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
						size: 10 //每页数据条数,默认10
					},
					empty: {
						tip: '暂无数据~'
					}
				},
				totalNum: 0,
				showPageLoading: true,
				list: [],
				phone: "",
				idcard: "",
				token: "",
				imgUrl: this.$api.common.imgUrl
			}
		},
		onLoad(res) {
			this.token = getApp().globalData.token;
			this.userName = res.name;
			this.phone = res.phone;
		},
		methods: {
			showImg(fileId) {
				if (fileId != "") {
					var _self = this;
					var url = _self.imgUrl + fileId
					uni.previewImage({
						urls: [url]
					})
				} else {
					uni.showToast({
						icon: "error",
						title: "证书有误"
					})
				}

			},
			onSearchInput(event) {
				this.searchContent = event.target.value
				console.log(event.target.value)
				if (event.target.value == "") {
					uni.hideKeyboard();
					this.refreshData();
				}
			},
			doSearch() {
				uni.hideKeyboard()
				if (this.searchContent == "") {
					this.$alert("请输入关键字");
				}
				this.refreshData()
			},
			/*初始化滚动*/
			initScroller(scroller) {
				this.scroller = scroller;
				this.loadData();
			},

			/*刷新数据*/
			refreshData() {
				uni.showLoading({
					title: '刷新中'
				});
				this.scroller.resetUpScroll();
			},

			/*加载数据*/
			loadData() {
				this.list = [];
				this.scroller.resetUpScroll();
			},
			/*滚动时导航栏浮动*/
			navFloatShow(scroller) {

			},
			//获取列表数据
			getData() {

				this.$app.request({
					url: this.$api.duty.doSearchCerifUnit,
					method: 'GET',
					data: {
						'name': this.userName,
						'phone': this.phone,
						'rows': this.scroller.size,
						'page': this.scroller.num,
						'keywords': this.searchContent
					},
					header: {
						token: this.token
					},
					dataType: 'json',
					success: res => {
						console.log(res)
						if (res.rows != undefined) {
							if (this.scroller.num == 1) {
								this.list = [];
							}
							var tempList = []
							tempList = res.rows
							this.list = this.list.concat(tempList);
							console.log(this.list)
							this.totalNum = res.total
							this.scroller.endBySize(res.rows.length, res.total);
							this.showPageLoading = false;
						} else {
							this.scroller.endSuccess();
							this.$alert(res.msg);
						}
					},
					fail: res => {
						console.log(res)
						this.scroller.endErr();
					},
					complete: res => {
						uni.stopPullDownRefresh();
						uni.hideLoading();
						this.showPageLoading = false;
					}
				});

			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background: #F6F6F6;
	}

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

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

	.title-box {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		padding: 20rpx;

		.title {
			font-size: 40rpx;
			font-weight: 300;
			color: black;
		}

		.name {
			font-size: 30rpx;
			font-weight: 200;
			color: #139847;
		}
	}

	.num-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		background: #15A652;
		justify-content: flex-start;
		box-shadow: 0rpx 7rpx 33rpx 16rpx rgba(188, 226, 204, 0.15);
		border-radius: 40rpx;
		padding: 65rpx;
		margin: 0rpx 20rpx;

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

		text {
			color: #fff;
			font-size: 30rpx;
			text-align: center;
			width: 85%;
		}
	}

	.content-box {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: flex-start;
		padding: 20rpx;

		.item {
			display: flex;
			flex-direction: row;
			background: #fff;
			width: 95%;
			padding: 20rpx;

			image {
				width: 500rpx;
				height: 218rpx;
			}

			.item-content {
				display: flex;
				flex-direction: column;
				width: 100%;
				padding: 20rpx 15rpx;

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

				.time {
					font-size: 20rpx;
					color: #646464;
					margin-top: 10rpx;
				}

				.btn {
					font-size: 20rpx;
					color: #ffffff;
					margin-top: 10rpx;
					margin-right: 15rpx;
					align-self: flex-end;
					background: #53B584;
					padding: 0rpx 60rpx;
					border-radius: 20rpx;
				}
			}
		}
	}

	/*搜索*/
	.search {
		display: flex;
		flex-direction: row;
		align-items: center;
		background: #FFFFFF;
		border-radius: 50rpx;
		align-self: center;
		margin: 20rpx 20rpx 0rpx 20rpx;

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

	}
</style>
