<template>
	<view>
		<view class="top-content">
			<!-- 搜索框 -->
			<view class="search-cont">
				<view class="inner">
					<image class="icon-search" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/icon_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>
		<mescroll-body  top="88rpx"  ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="hos-list">
				<view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
					<view class="left">
						<image :src="item.imgUrl" mode="aspectFit"></image>
					</view>
					<view class="right">
						<view class="title one-t">{{ item.hospitalName }}</view>
						<view class="desc">
							<text class="tag">二甲</text>
							<text class="tag">综合医院</text>
						</view>
						<view class="address-box">
							<view class="address-left">
								<view class="address one-t">{{item.address}}</view>
							</view>
							<view class="address-right">
								<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/icon_arrow_r.png"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import {getHospitalList} from '@/api/hospital.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				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://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/empty_icon.png',
						tip: '暂无数据'
					}
				},
				dataList: []
			};
		},
		onShow() {
		},
		methods:{
			doSearch(){
				this.mescroll.resetUpScroll()
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					keyword:this.keyword,
					pageNum: page.num,
					pageSize: page.size
				};
				getHospitalList(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();
					}
				});
			},
			// 查看详情
			showDetail(item) {
				uni.navigateTo({
					url: './hospitalDetails?hospitalId=' + item.hospitalId
				})
			}
		}
	}
</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%;
			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;
			}
		}
	}
	.hos-list{
		margin-top: 20upx;
		padding: 0 10upx;
		.item{
			width: 100%;
			box-sizing: border-box;
			background: #FFFFFF;
			border-radius: 15upx;
			padding: 30upx;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			margin-bottom: 20upx;
			.left{
				width: 190upx;
				height: 190upx;
				border-radius: 8upx;
				image{
					width: 190upx;
					height: 190upx;
				}
			}
			.right{
				height:190upx;
				width: calc(100% - 210rpx);
				padding-left: 20upx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title{
					width: 100%;
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #111111;
				}
				.desc{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111;
					.tag{
						margin-right: 10rpx;
					}
				}
				.address-box{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.address-left{
						width: calc(100% - 30rpx);
						display: flex;
						align-items: center;
						justify-content: flex-start;
						.address{
							font-size: 28upx;
							font-family: PingFang SC;
							color: #9a9a9c;
						}
					}
					.address-right{
						image{
							width: 30upx;
							height: 30upx;
						}
						
					}
				}
			}
			
		}
	}
</style>
