<template>
	<view class="content">
		<view class="top-fixed">
			 <u-tabs
			  :current="type"
			  :scrollable="false"
			  :list="tabs"  
			  lineColor="#2583EB"
			 @change="typeChange">
			 </u-tabs>
		</view>
		<mescroll-body top="88rpx" bottom="0" ref="mescrollRef" @init="mescrollInit"    :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">
		<view class="doctors">
			<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">
									<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.pingStar}}</view>
								<view class="name">平均响应:</view>
								<view class="count"></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 {getMyDoctorList} from '@/api/doctor.js'
	import {getDictByKey} from '@/api/common.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				hosLevelOptions:[],
				tabs:[
					{
						index:1,
						name:'关注医生'
					},
					{
						index:2,
						name:'签约医生'
					}
					 
				],
				type: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) {
			this.getDictByKey("sys_hospital_level");
		},
		methods: {
			getDictByKey(key){
				var data={key:key}
				getDictByKey(data).then(
					res => {
						if(res.code==200){
							if(key=="sys_hospital_level"){
								this.hosLevelOptions=res.data;
							}
						}
					},
					err => {
					}
				);
				
			},
			typeChange(item){
				this.type=item.index
				console.log(this.type)
				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 = {
					type:this.type+1,
					pageNum: page.num,
					pageSize: page.size
				};
				getMyDoctorList(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);
							 
						}
						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%;
		.top-fixed{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 10;
			height: 88upx;
			background-color: #fff;
		}
		.doctors{
			margin: 15rpx;
			padding: 15rpx;
			box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
			background-color: #fff;
			border-radius: 15rpx;
		}
		 
		
	}
	 
</style>
