<template>
	<view class="content">

		<!-- 导航 -->
		<view class="nav">
			<view class="leftView" @click="back">
				<image src="../../static/mobile/backBtn.png" mode=""
					style="width: 22rpx; height: 40rpx; padding-left: 24rpx;"></image>
			</view>
			<view class="navTitle">搜索</view>
			<view class="rightView">

			</view>
		</view>

		<!-- content -->
		<!-- <view class="commend"> -->
		<!-- 搜索 -->
		<view class="searchBoxBg">
			<searchBox placeholder="请输入搜索内容" @search='search($event)'></searchBox>
		</view>
		<view class="top" v-if="itemArr.length!=0">为你找到“{{searchValue}}”相关结果共{{TotalSize}}条</view>

		<!-- </view> -->

		<!-- item -->

		<view class="itemBg">
			<view v-for="(item,index) in itemArr" :key="index" :class="{line:index>0}" class="twoItem" @click="goDetail(item)">
				<image :src="item.LogoImg" mode="" class="img2"></image>
				<view class="rightItem">
					<view class="title">{{item.Title}}</view>
					<view class="title2">{{item.Comment}}</view>
				</view>
			</view>
		</view>



		<!-- 上拉 加载更多 -->
		<view class="noMore" v-if="noMoreShow">没有更多数据</view>
		<!-- 无数据空白页 -->
		<nodata v-if="itemArr.length==0 && isFirst == false" style="padding-top: 30%;"></nodata>

		<view class="gotop" @click="gotoTop">
			<image src="../../static/pcimg/btn_top@2x.png" mode="" class="gotopImg"></image>
		</view>

	</view>
</template>

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


		data() {
			return {
				searchValue: '',
				page: 1,
				itemArr: [],
				TotalSize: '',
				noMoreShow: false,
				isFirst:true,
			}
		},
		onLoad() {

		},
		methods: {
			gotoTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			goDetail(item) {
				uni.navigateTo({
					url: 'detail?id=' + item.ID
				})
			},
			back() {
				uni.navigateBack({

				})
			},
			search(val) {
				console.log(val);
				this.isFirst = false
				this.searchValue = val
				if (this.searchValue.length != 0) {
					this.page = 1
					this.getItemData()
				} else {
					this.itemArr = [];
					this.TotalSize = ''
					this.noMoreShow = false
				}
			},
			getItemData() {
				uni.showLoading({
					title: '加载中'
				})

				let url = 'trainingOpenApiV3/searchPageData',
					params = {
						page: this.page,
						limit: 10,
						title: this.searchValue,

					}
				this.$http(url, params, 'GET').then(res => {
					uni.hideLoading();
					var data = res.data


					// 处理 undefined和null转为空白字符串

					for (const key in data) {
						data[key] = this.$praseStrEmpty(data[key])
					}

					this.TotalSize = data.TotalSize


					if (this.page == 1) {
						this.itemArr = data.Items
					} else {
						this.itemArr = this.itemArr.concat(data.Items)
					}
					if (data.Items.length < 10) {
						this.noMoreShow = true
					} else {
						this.noMoreShow = false
					}
					if (this.itemArr.length == 0) {
						this.noMoreShow = false
					}



				})
			},

		}
	}
</script>

<style scoped>
	.content {
		min-height: 100vh;
		background-color: #FFFFFF;
		padding-top: 88rpx;
		padding-bottom: 20rpx;

	}

	.nav {
		position: fixed;
		left: 0;
		top: 0;
		width: 100vw;
		height: 88rpx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		align-items: center;
		z-index: 999;
		border-bottom: #eeeeee 2rpx solid;
	}

	.navTitle {
		font-size: 36rpx;
		font-weight: bold;
		color: #3c3c3c;

	}

	.leftView {
		width: 30%;
	}

	.rightView {
		width: 30%;
		display: flex;
		justify-content: flex-end;
		padding-right: 24rpx;
	}

	.rightImg {
		width: 40rpx;
		height: 40rpx;

	}

	.searchBoxBg {
		position: fixed;
		left: 0;
		top: 88rpx;
		width: calc(100vw - 50rpx);

		background-color: #FFFFFF;

		padding: 0 24rpx;
		z-index: 999;

	}


	.top {
		padding: 130rpx 24rpx 0;
		text-align: left;
		font-size: 24rpx;
		color: #999999;
		background-color: #FFFFFF;
	}




	.itemBg {

		background-color: #FFFFFF;
		padding: 0 30rpx;

	}

	.twoItem {
		display: flex;
		background-color: #FFFFFF;
		padding: 30rpx 0;
		
	}
	.line{
		border-top: #eeeeee 2rpx solid;
	}
	.title {
		font-size: 28rpx;
		font-weight: bold;
		color: #3c3c3c;
		
		/* 隐藏文字显示 ...不换行 */
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.title2 {

		font-size: 24rpx;
		color: #999999;
		//超过固定行数 隐藏
		display: -webkit-box;
		overflow: hidden;
		text-overflow: ellipsis;
		word-wrap: break-word;
		white-space: normal !important;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
		margin: 14rpx 0;
	}


	.img2 {
		width: 240rpx;
		height: 135rpx;
		border-radius: 10rpx;
	}

	.rightItem {
		margin-left: 30rpx;
		width: calc(100vw - 300rpx);
	}

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

	.gotopImg {
		width: 100rpx;
		height: 100rpx;
	}

	.gotop {
		position: fixed;
		right: 15rpx;
		bottom: 100rpx;
		cursor: pointer;
	}
</style>
