<template>
	<view class="column " style="height: calc(100% - 300rpx);">
		<view class="top-content flex-1" >
			<!-- 搜索框 -->
			<view class="search-cont">
				<view class="inner">
					<image class="icon-search" src="/static/images/search.png" mode=""></image>
					<input type="text" v-model="keyword" placeholder="输入关键字搜索" confirm-type="search" @confirm="doSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
				</view>
			</view>
			<!-- <view class="cate-list" v-if="showcate">
				关键字列表
				<scroll-view   scroll-x="true" >
					<view class="inner">
						<view v-for="(item,index) in cateOptions" :key="index" :class="cateId == item.dictValue?'item active':'item'" @click="choseCate(item)">
							{{ item.dictLabel }}
						</view>
					</view>
				</scroll-view>
			</view> -->
		</view>
		<mescroll-body ref="mescrollRef" top="92rpx"
		 @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="article-list">
				<view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
					<view class="left">
						<view class="title ellipsis2">{{ item.title }}</view>
						<view class="info-box">
							<view class="readers">
								<view class="head-box"  >
									<view class="head"  >
										<image class="eye" mode="aspectFill"  src="https://beiliyo-2025.obs.cn-north-4.myhuaweicloud.com/fs/20250115/1736944490230.png" ></image> 
									</view>
								</view>
								<view class="readings">
									<image class="eye" src="/static/images/eye.png" ></image>
									<text class="num">{{item.views}}</text>
								</view>
							</view>
							<!-- <view class="time-box">{{item.createTime}}</view> -->
						</view>
					</view>
					<view class="right">
						<image :src="item.imageUrl" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</mescroll-body>
		
	</view>
</template>

<script>
	
	import {getDictByKey} from '@/api/common.js'
	import {getDoctorArticleList} from '@/api/doctorArticle.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				cateOptions:[],
				cateId:0,
				keyword: '',
				mescroll:null,
				downOption: {   //下拉刷新
				 	use:true,
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
						tip: '暂无数据'
					}
				},
				dataList: [],
				showcate:true
			};
		},
		onShow() {
			this.getDictByKey("sys_doctor_article_cate");
		},
		onLoad(option) {
			if (option.title) {
			    uni.setNavigationBarTitle({
			      title: option.title
			    });
			  }
			if(option.cateId){
				this.showcate=false
				this.cateId=option.cateId
			}
			console.log('标题',option)
		},
		methods:{
			getDictByKey(key){
				//获取tab标题列表
				var data={key:key}
				console.log(data)
				getDictByKey(data).then(
					res => {
						if(res.code==200){
							this.cateOptions=res.data;
						}
					},
					err => {
					}
				);
				
			},
			doSearch(){
				this.mescroll.resetUpScroll()
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据  点击tab标题获取列表数据
				var that = this;
				var data = {
					keyword:this.keyword,
					cateId:this.cateId,
					pageNum: page.num,
					pageSize: page.size
				};
				console.log(data)
				getDoctorArticleList(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.cateId = item.dictValue;
				this.mescroll.resetUpScroll()
			},
			// 查看详情
			showDetail(item) {
				uni.navigateTo({
					url: './doctorArticleDetails?articleId=' + item.articleId
				})
			}
		}
	}
</script>

<style lang="scss">
	.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;
		background-color: #FFFFFF;
	}
	.search-cont{
		padding: 16upx 30upx;
		background-color: #FFFFFF;
		.inner{
			box-sizing: border-box;
			width: 100%;
			height: 72upx;
			background: #F7F7F7;
			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;
			}
		}
	}
	.cate-list{
		box-sizing: border-box;
		background: #fff;
		padding: 10upx 27upx;
		height: 100upx;
		.inner{
			display: flex;
		}
		.item{
			flex-shrink: 0;
			padding: 0 24upx;
			height: 64upx;
			line-height: 64upx;
			font-size: 28upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #018C39;
			background: #ffffff;
			border: 1px solid #018C39;
			border-radius: 32upx;
			margin: 0 20upx 20upx 0;
			&.active{
				color: #FFFFFF;
				background:#018C39;
				border: 1px solid #018C39;
			}
		}
	}
	.article-list{
		margin-top: 20upx;
		padding: 0 10upx;
		.item{
			box-sizing: border-box;
			height: 271upx;
			background: #FFFFFF;
			border-radius: 16upx;
			padding: 40upx 30upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20upx;
			.left{
				flex: 1;
				padding-right: 40upx;
				height: 190upx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title{
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					line-height: 48upx;
				}
				.info-box{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.readers{
						display: flex;
						align-items: center;
						.head-box{
							margin-right: 27upx;
							display: flex;
							align-items: center;
							.head{
								width: 48upx;
								height: 48upx;
								border-radius: 50%;
								overflow: hidden;
								box-shadow: 0 0 0 1px #fff;
								margin-right: -10upx;
								image{
									width: 100%;
									height: 100%;
								}
							}
						}
						.readings{
							display: flex;
							align-items: center;
							.eye{
								width: 26upx;
								height: 20upx;
								margin-right: 9upx;
							}
							.num{
								font-size: 24upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #999999;
								line-height: 1;
							}
						}
					}
					.time{
						font-size: 24upx;
						line-height: 1;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
					}
				}
			}
			.right{
				width: 250upx;
				height: 190upx;
				border-radius: 8upx;
				overflow: hidden;
				image{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>
