<template>
	<view class="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 class="top-fixed">
			 <u-tabs
			  :current="tabIndex"
			  :scrollable="true"
			  :list="tabs"  
			  lineColor="#2583EB"
			 @change="deptChange">
			 </u-tabs>
		</view>
		<mescroll-body top="176rpx" bottom="0" ref="mescrollRef" @init="mescrollInit"    :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">
		<view class="doctors" v-if="dataList.length>0">
			<view class="doctor-box">
				<view class="doctor" @click="navTo('/pages_doctor/doctorDetails?doctorId='+item.doctorId)" v-for="(item,index) in dataList">
					<view class="item">
						<view class="left">
							<view class="head-box"> 
								<image mode="aspectFill" class="doc-img" :src="item.avatar"></image>
								<view class="isline" v-if="item.workStatus==1">
									<view class="img">
										<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/isline.png"></image>
										<view class="name">在线</view>
									</view>
								</view>
							</view>
						</view>
						<view class="right"> 
							<view class="doc-box">
								<view class="doc-name">
									{{item.doctorName}}
								</view>
								<view class="doc-position">{{item.position}}</view>
								<view class="doc-dept">{{item.deptName}}</view>
							</view>
							<view class="hospital-box">
								<!-- <view class="tag" v-if="item.hospitalLevel!=null">
									<text>{{$getDictLabelName(hosLevelOptions,item.hospitalLevel)}}</text>
								</view> -->
								<view class="name">{{item.hospitalName||''}} </view>
							</view>
							<view class="doc-spec">
								<view class="spec ellipsis2">{{item.speciality}}</view>
							</view>
							<view class="doc-count">
								<view class="name">好评:</view>
								<view class="count">{{item.pingStar}}分</view>
								<view class="name">接诊量:</view>
								<view class="count">{{item.orderNumber}}</view>
								<view class="name">平均响应:</view>
								<view class="count">{{item.speed||''}}分钟</view>
							</view>
							<view class="doc-price"  >
								<view class="btn">
									咨询医生￥
									<text v-for="(price,index) in item.prices">
										{{price.price.toFixed(2)}} <text v-if="index==0">/</text>
									</text>
								</view>
							</view>
						</view>
						
					</view>
					
				</view>
				
			</view>
		</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {getDoctorList} from '@/api/doctor.js'
	import {getDepartmentList} from '@/api/department.js'
	import {getDictByKey} from '@/api/common.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				keyword: '',
				hosLevelOptions:[],
				tabIndex:0,
				tabs:[
					{name:"全部",deptId:0}
				],
				deptId:0,
				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: []
			}
		},
		onLoad(options) {
			if(options.deptId!=null){
				this.deptId=options.deptId;
			}
			if(options.keyword!=null){
				this.keyword=options.keyword;
			}
			console.log(this.deptId)
			this.getDictByKey("sys_hospital_level");
			this.getDepartmentList()
		},
		onShow() {
		},
		methods: {
			doSearch(){
				this.mescroll.resetUpScroll()
			},
			getDictByKey(key){
				var data={key:key}
				getDictByKey(data).then(
					res => {
						if(res.code==200){
							if(key=="sys_hospital_level"){
								this.hosLevelOptions=res.data;
							}
						}
					},
					err => {
					}
				);
				
			},
			getDepartmentList(page) {
				var that = this;
				var data = {
				};
				getDepartmentList(data).then(res => {
					if(res.code==200){
						res.data.forEach(function(value,index,array){
							var data={name:value.deptName,deptId:value.deptId}
							that.tabs.push(data);
							if(value.deptId==that.deptId){
								that.tabIndex=index+1;
								console.log(that.tabIndex)
							}
						});
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				});
			},
			deptChange(item){
				this.deptId=item.deptId
				this.mescroll.resetUpScroll()
			},
			navTo(url){
				uni.navigateTo({
					url: url
				})
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调*/
			upCallback(page) {   
				//联网加载数据
				var that = this;
				var data = {
					keyword:this.keyword,
					deptId:this.deptId,
					pageNum: page.num,
					pageSize: page.size
				};
				getDoctorList(data).then(res => {
					if(res.code==200){
						if (page.num == 1) {
							res.data.list.forEach(function(value,index,array){
								value.prices=JSON.parse(value.priceJson)
							});
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						console.log(that.dataList[0])
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			
			
		}
	}
</script>

<style lang="scss">
	page{
		
		height: 100%;
		background: #f6f6f6;
	}
</style>
<style scoped lang="scss">
	.content{
		height: 100%;
		padding: 0rpx 20rpx;
		.search-cont{
			position:fixed;
			height: 88upx;
			top: 0;
			left: 0;
			z-index: 10;
			width: 100%;
			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;
				}
			}
		}
		.top-fixed{
			width: 100%;
			position: fixed;
			top: 88rpx;
			left: 0;
			z-index: 10;
			height: 88upx;
			background-color: #fff;
		}
		.doctors{
			margin: 15rpx 0rpx;
			padding: 15rpx;
			box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
			background-color: #fff;
			border-radius: 15rpx;
			.title-box{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-start;
				.title{
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #111111;
				}
				.line{
					margin-right: 15rpx;
					height: 30rpx;
					width: 6rpx;
					background-color: #2583EB;
					
				}
				 
			}
		}
	}
	 
</style>
