<template>
	<view>
		<view class="top-content">
			<view class="search-cont">
				<view class="inner">
					<u-icon name="search" size="24" color="#C8C9CC"></u-icon>
					<input type="text" v-model="searchValue" placeholder="请输入关键字或作者" confirm-type="search"
						@confirm="doSearch"
						placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
				</view>
			</view>
			<view class="keyword-list">
				<!-- 关键字列表 -->
				<!-- <scroll-view   scroll-x="true" > -->
				<view class="inner">
					<view v-for="(item,index) in cates" :key="index" :class="choseCateId == item.cateId?'item active':'item'" @click="choseCate(item)">
						{{ item.cateName }}
					</view>
				</view>
			<!-- </scroll-view> -->
				<!-- <u-tabs :list="cates" :activeStyle="{fontWeight: '500',color: '#333333',fontSize: '32rpx',lineHeight:'88rpx'}"
					:inactiveStyle="{color: '#999999',fontSize: '28rpx',lineHeight:'88rpx'}" @click="choseCate(item)"
					scrollable="false" lineColor="#388BFF"></u-tabs> -->
			</view>
		</view>

	<!-- 	<mescroll-body :top="top" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
			:down="downOption" :up="upOption"> -->
	<!-- 		<view class="know-list">
				<view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
					<view class="image-box">
						<image class="bg" mode="aspectFill" :src="item.imageUrl"></image>
						<view class="views">
							<image mode="aspectFill" src="@/static/image/icon_goon.png"></image>
							<view class="status">进行中</view>
						</view>
					</view>
					<view class="article-title-box">
						<view class="article-title one-t">王医生学术直播</view>
						<view class="name-title ">
							<image mode="aspectFill" src="@/static/image/icon_doctor.png"></image>
							<view class="one-t">
								王小明-副主任医师/副主任副主任
							</view>
						</view>
						<view class="position-title">
							<image mode="aspectFill" src="@/static/image/icon_hospital.png"></image>
							<view class="one-t">
								北京人民医院
							</view>
						</view>
					</view>
				</view>
			</view> -->
		<!-- </mescroll-body> -->
		<view class="empty-state y-bc" :style="{marginTop:top}" v-if="dataList.length === 0">
			<image class="w300 h300" src="@/static/image/img_blank_nodata.png" mode=""></image>
			<text>暂无数据</text>
		</view>
	</view>
</template>

<script>
	import {
		getArticleCate,
		getArticleList
	} from '@/api/article'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				top: '0px',
				cates: [
					{cateName: '全部',cateId:0},
					{cateName:'待开播',cateId:1},
					{cateName: '直播中',cateId:2},
					{cateName:'看回放',cateId:3},
				],
				choseCateId: 0,
				// 状态栏的高度
				statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
				searchValue: '',
				mescroll: null,
				// 上拉加载的配置
				downOption: {

				},
				upOption: {
					onScroll: true,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon: '/static/image/img_blank_nodata.png',
						tip: '暂无数据'
					},
					textNoMore: '没有更多了~'
				},
				// 列表数据
				dataList: [],
			};
		},
		onShow() {
			//this.getArticleCate();
			var that = this;
			setTimeout(function() {
				let query = uni.createSelectorQuery().select(".top-content");
				query.boundingClientRect(function(data) { //data - 各种参数
					console.log(data.height) // 获取元素宽度
					that.top = data.height + "px";
				}).exec()
			}, 500);
		},
		methods: {
			doSearch() {
				this.mescroll.resetUpScroll()
			},
			getArticleCate() {
				var that = this;
				let data = {};
				getArticleCate(data).then(
					res => {
						if (res.code == 200) {
							this.cates = res.data.map(person => ({
								name: person.cateName
							}));

						} else {
							uni.showToast({
								icon: 'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					keyword: this.searchValue,
					cateId: this.choseCateId,
					page: page.num,
					pageSize: page.size
				};
				// getArticleList(data).then(res => {
				// 	if (res.code == 200) {
				// 		//设置列表数据
				// 		if (page.num == 1) {
				// 			that.dataList = res.data.list;

				// 		} else {
				// 			that.dataList = that.dataList.concat(res.data.list);

				// 		}
				// 		that.mescroll.endBySize(res.data.list.length, res.data.total);

				// 	} else {
				// 		uni.showToast({
				// 			icon: 'none',
				// 			title: "请求失败",
				// 		});
				// 		that.dataList = null;
				// 		that.mescroll.endErr();
				// 	}
				// });
			},
			// 关键词选择
			choseCate(item) {
				this.choseCateId = item.cateId;
				this.mescroll.resetUpScroll()
			},
			// 查看详情
			showDetail(item) {
				uni.navigateTo({
					url: './addForm?articleId='
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #EFF3F7;
	}

	.status_bar {
		width: 100%;

	}
.empty-state {
	padding: 120rpx 24rpx;
	text-align: center;
	font-size: 28rpx;
	color: #999;
}
	.top-content {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
	}

	.top-title {
		height: 88upx;
		line-height: 88upx;
		font-size: 42upx;
		font-family: Source Han Sans CN;
		font-weight: bold;
		color: #222222;
		padding-left: 41upx;
	}

	.search-cont {
		padding: 16upx 30upx;
         background: #fff;
		.inner {
			box-sizing: border-box;
			width: 100%;
			height: 72upx;
			background: #F7F8FA;
			border-radius: 36upx;
			display: flex;
			align-items: center;
			padding: 0 30upx;

			.icon-search {
				width: 28upx;
				height: 28upx;
				margin-right: 20upx;
			}

			input {
				height: 60upx;
				line-height: 60upx;
				flex: 1;
			}
		}
	}

	.keyword-list {
		box-sizing: border-box;
		// padding: 10upx 27upx;
		height: 88rpx;
        background: #FFFFFF;
		flex-shrink: 0;
		.inner {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.item {
			flex:1;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-shrink: 0;
			height: 88upx;
			line-height: 88upx;
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #999999;
            position: relative;
			&.active {
				font-weight: 500;
				color: #333333;
				&::after {
					content: "";
					width: 56upx;
					height: 6upx;
					background: #388BFF;
					position: absolute;
					bottom: 0;
					border-radius: 3rpx 3rpx 3rpx 3rpx;
				}
			}
		}
	}

	.know-list {
		margin-top: 24upx;
		padding: 0 24upx;
		display: flex;
		align-items: center;
		flex-direction: row;
		flex-shrink: 0;
		flex-wrap: wrap; 
		width: 100%;
		box-sizing: border-box;
		.item {
			box-sizing: border-box;
			width: calc(50% - 10rpx); 
			height: 340rpx;
			background: #FFFFFF;
			border-radius: 16upx;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			flex-direction: column;
			margin-bottom: 18rpx;
			margin-right: 18rpx;
			&:nth-child(2){
				margin-right:0;
			}
            .image-box {
            	width: 100%;
            	height: 192rpx;
            	position: relative;
            	border-radius: 16rpx 16rpx 0rpx 0rpx;
            
            	.bg {
            		border-radius: 16rpx 16rpx 0rpx 0rpx;
            		width: 100%;
            		height: 100%;
            	}
            
            	.views {
            		position: absolute;
            		top: 0rpx;
            		left: 0rpx;
            		width: 112rpx;
            		height: 32rpx;
            		display: flex;
            		align-items: center;
            		background: rgba(0, 0, 0, 0.4);
            		border-radius: 16rpx 0rpx 16rpx 0rpx;
            		font-weight: 500;
            		font-size: 20rpx;
            		color: #FFFFFF;
            		font-family: PingFang SC-Bold, PingFang SC;
            
            		image {
            			width: 36rpx;
            			height: 32rpx;
            			margin-right: 8rpx;
            		}
            	}
            
            	.zhibo {
            		position: absolute;
            		top: 50%;
            		left: 50%;
            		transform: translate(-50%, -50%);
            
            		image {
            			width: 56rpx;
            			height: 56rpx;
            		}
            	}
            }
			.article-title-box {
				width: 100%;
				padding: 16rpx;
				display: flex;
				align-items: flex-start;
				flex-direction: column;
				justify-content: space-between;
				height: 148rpx;
				box-sizing: border-box;
			
				.article-title {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #333333;
					.one-t{
						width: 100%;
					}
				}
			
				.name-title {
					display: flex;
					align-items: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 22rpx;
					color: #999999;
			        .one-t{
						width: 80%;
					}
					image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 14rpx;
					}
				}
			
				.position-title {
					display: flex;
					align-items: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 22rpx;
					color: #999999;
			.one-t{
				width: 80%;
			}
					image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 14rpx;
					}
				}
			}
		}
	}
</style>