<template>
	<view>
		<view class="top-fixed">
			<!-- 搜索框 -->
			<view class="search-cont">
				<view class="inner">
					<image class="icon-search" src="@/static/images/search.png" mode=""></image>
					<input type="text" v-model="searchVal" placeholder="输入医生姓名搜索" confirm-type="搜索" @confirm="goSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
				</view>
			</view>
			<!-- tab切换 -->
			<view class="pub-tab-box">
				<view class="tab-inner">
					<view 
						v-for="(item,index) in depts" 
						:key="index"
						:class="deptId == item.departmentId?'item active':'item'"
						@click="changeDept(item)"
					>
						<view class="text">
							{{ item.departmentName }}
							<image v-show="deptId == item.departmentId" class="tab-bg" src="@/static/images/tab_bg.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 数据列表 -->
		<mescroll-body ref="mescrollRef" top="190rpx" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="doc-list">
				<view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
					<!-- 头像 -->
					<view class="head-box">
						<image :src="item.headImg" mode="aspectFill"></image>
					</view>
					<!-- 详细信息 -->
					<view class="info">
						<!-- 姓名等 -->
						<view class="top">
							<text class="name">{{ item.doctorName }}</text>
							<view class="line"></view>
							<text class="other">{{utils.getDictLabelName("doctorPosition",item.position)}}</text>
							<view class="line"></view>
							<text class="other">{{ item.departmentName }}</text>
						</view>
						<!-- 单位 -->
						<view class="unit-box">
							<!-- <view class="level">三甲</view> -->
							<view class="name">{{ item.hospitalName }}</view>
						</view>
						<!-- 擅长 -->
						<view class="expertise ellipsis2">
							擅长：{{ item.doctorDesc }}
						</view>
						<!-- 评分 -->
						<!-- <view class="rate-box">
							<view class="star">
								<image src="@/static/images/star.png" mode=""></image>
								<text>{{ item.pings }}</text>
							</view>
							<view class="line"></view>
							<view class="num-box">
								<text class="label">接诊数</text>
								<text class="num">{{ item.orders }}</text>
							</view>
							<view class="line"></view>
							<view class="num-box">
								<text class="label">响应速度</text>
								<text class="num">{{ item.speed }}分钟</text>
							</view>
						</view> -->
						<!-- 价格 -->
						<view class="price-box" v-if="item.price!=null&&item.price.length>0">
							<view class="btn-item" v-for="(subitme) in item.price">
								<text class="label" >{{subitme.priceType==1?'图文':'语音'}}</text>
								<text class="num">¥{{subitme.price.toFixed(2)}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import {getDepartmentList,getDoctorList} from '@/api/doctorOrder.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				searchVal:"",
				depts:[],
				deptId:0,
				doctorType:0,
				// tab切换
				mescroll:null,
				// 上拉加载的配置
				upOption: {
					onScroll:true,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						icon:'/static/images/no_data.png',
						tip: '暂无数据'
					}
				},
				// 列表数据
				dataList: []
			};
		},
		onLoad(option) {
			if(option.doctorType!=null){
				this.doctorType=option.doctorType
			}
			this.getDepartmentList();
		},
		methods: {
			getDepartmentList(){
				getDepartmentList().then(res => {
					if(res.code==200){
						var allDept={departmentId:0,departmentName:"全部"}
						this.depts.push(allDept);
						this.depts=this.depts.concat(res.data);
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				});
			
			},
			// tab切换
			changeDept(item) {
				this.deptId = item.departmentId;
				this.mescroll.resetUpScroll()
				
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					doctorType:this.doctorType,
					departmentId:this.deptId,
					doctorName:this.searchVal,
					page: page.num,
					pageSize: page.size
				};
				getDoctorList(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();
					}
				});
			},
			 goSearch(){
				 this.mescroll.resetUpScroll()
			 },
			// 查看医生资料详情
			showDetail(item) {
				uni.navigateTo({
					url: './doctorDetail?doctorId=' + item.doctorId
				})
			}
		}
	}
</script>

<style lang="scss">
	.top-fixed{
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
	}
	.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{
				flex: 1;
				height: 60upx;
				line-height: 60upx;
			}
		}
	}
	.pub-tab-box{
		padding: 0 33upx;
		background-color: #FFFFFF;
		.tab-inner{
			height: 88upx;
			line-height: 88upx;
			display: flex;
			overflow-x: auto;
		}
		.item{
			font-size: 28upx;
			white-space: nowrap;
			line-height: 1;
			font-family: PingFang SC;
			font-weight: 500;
			color: #666666;
			margin-right: 60upx;
			display: flex;
			align-items: center;
			justify-content: center;
			&:last-child{
				margin-right: 0;
			}
			&.active{
				font-weight: bold;
				color: #333333;
			}
			.text{
				position: relative;
				z-index: 1;
			}
			.tab-bg{
				width: 72upx;
				height: 28upx;
				position: absolute;
				top: 17upx;
				left: 50%;
				transform: translateX(-36upx);
				z-index: -1;
			}
		}
	}
	.top-seat{
		width: 100%;
		height: 192upx;
	}
	.doc-list{
		padding: 20upx;
		.item{
			box-sizing: border-box;
			// height: 433upx;
			background: #FFFFFF;
			border: 4upx solid #FFFFFF;
			border-radius: 16upx;
			padding: 40upx 30upx;
			display: flex;
			margin-bottom: 20upx;
			.head-box{
				width: 120upx;
				height: 120upx;
				background: #EDF1F4;
				border-radius: 50%;
				overflow: hidden;
				margin-right: 30upx;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.info{
				width: calc(100% - 150upx);
				.top{
					display: flex;
					align-items: center;
					font-family: PingFang SC;
					line-height: 1;
					.name{
						font-size: 34upx;
						font-weight: bold;
						color: #111111;
					}
					.line{
						width: 1px;
						height: 26upx;
						background: #DDDDDD;
						margin: 0 20upx;
					}
					.other{
						font-size: 28upx;
						font-weight: 500;
						color: #333333;
					}
				}
				.unit-box{
					display: flex;
					margin-top: 24upx;
					.level{
						padding: 0 10upx;
						height: 30upx;
						line-height: 30upx;
						font-size: 22upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #FFFFFF;
						background: #018C39;
						border-radius: 10upx 4upx 10upx 4upx;
						margin-right: 12upx;
					}
					.name{
						font-size: 28upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #333333;
						line-height: 30upx;
					}
				}
				.expertise{
					font-size: 26upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
					line-height: 42upx;
					margin: 22upx 0 0upx;
				}
				.rate-box{
					display: flex;
					align-items: center;
					.star{
						display: flex;
						align-items: center;
						image{
							width: 22upx;
							height: 22upx;
							margin-right: 10upx;
						}
						text{
							font-size: 26upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #CEA764;
							line-height: 1;
						}
					}
					.line{
						width: 1px;
						height: 20upx;
						background: #DDDDDD;
						margin: 0 20upx;
					}
					.num-box{
						display: flex;
						align-items: center;
						font-family: PingFang SC;
						.label{
							font-size: 24upx;
							font-weight: 500;
							color: #999999;
							line-height: 1;
							margin-right: 7px;
						}
						.num{
							font-size: 26upx;
							font-weight: bold;
							color: #CEA764;
							line-height: 1;
						}
					}
				}
				.price-box{
					display: flex;
					align-items: center;
					margin-top: 38upx;
					.btn-item{
						display: flex;
						align-items: center;
						justify-content: center;
						width: 164upx;
						height: 56upx;
						line-height: 56upx;
						border: 1px solid rgba(43, 199, 185, 0.5);
						border-radius: 28upx;
						font-family: PingFang SC;
						margin-right: 30upx;
						&:last-child{
							margin-right: 0;
						}
						.label{
							font-size: 26upx;
							font-weight: 500;
							color: #018C39;
							margin-right: 5upx;
						}
						.num{
							font-size: 28upx;
							font-weight: bold;
							color: #018C39;
						}
					}
				}
			}
		}
	}
</style>
