<template>
	<view class="container">
		<scroll-view scroll-x="true" class="class-box flex b-t" :scroll-left="scrollLeft" :scroll-with-animation="true">
			<view @click="tabClick(idx)" class="item" :style="{ width: topNavWidth }" v-for="(item, idx) in zyList" :key="idx">
				<view class="status" :class="{ action: idx == tabCurrentIndex }">{{ item.text }}</view>
			</view>
		</scroll-view>
		<view class="Search-box flex">
			<view class="Search-box flex">
				<image class="box-img" src="../../static/img/shousuo.png"></image>
				<input class="box-word" type="text" @input="onKeyInput" placeholder="请输入关键字" v-model="keyword" />
			</view>
		</view>
		<scroll-view scroll-y class="second-part" @scrolltolower="getDoctorList">
			<view v-for="(item, index) in DoctorList" :key="index" class="template flex_item" @click="ToExpert(item.uid)">
				<view class="left-img"><image :src="item.photo"></image></view>
				<view class="center-word">
					<text class="one">{{ item.name }}</text>
					<text class="two">
						职位：{{ item.doctor_level == 1 ? "医师" : item.doctor_level == 2 ? "主治医师" : item.doctor_level == 3 ? "副主任医师" : "主任医师"}}
					</text>
				</view>
				<view class="right-label flex">
					<image src="../../static/img/img014.png"></image>
					咨询问诊
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>
<script>
import uniPopup from '@/components/uni-popup/uni-popup.vue';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import { getDoctorList } from '@/api/doctor.js';
import { getDocterTypeList } from '@/api/doctor.js'
export default {
	components: {
		uniPopup
	},
	data() {
		return {
			topNavWidth: '25%', //设置导航默认宽度
			tabCurrentIndex: 0,
			zyList: [],
			DoctorList: [],
			keyword:'',
			limit: 10, //每次加载数据条数
			page: 1, //当前页数
			loadingType: 'more', //加载更多状态
			loading:0,//判断是否为点击搜索按钮跳转加载
			itemWidht: '',
			type: 0,
		};
	},
	computed: {
		scrollLeft() {
			if (this.tabCurrentIndex > 1) {
				return this.itemWidht * (this.tabCurrentIndex - 1.5);
			} else {
				return 0;
			}
		}
	},
	onLoad(){
		this.getZyList()
	},
	//下拉刷新
	onPullDownRefresh() {
		this.page = 1
		this.getDoctorList('refresh');
	},
	methods: {
		// 获取项目宽度
		numClassWidht() {
			uni.createSelectorQuery()
				.select('.container')
				.fields(
					{
						size: true
					},
					data => {
						// 设置项目宽度
						this.itemWidht = Math.floor((data.width / 750) * 187.5);
					}
				)
				.exec();
		},
		// 头部点击切换
		tabClick(index) {
			this.tabCurrentIndex = index
			this.type = this.zyList[index].id
			this.getDoctorList('tab')
		},
		getZyList() {
			getDocterTypeList().then(res => {
				console.log(res)
				this.zyList = res.data.data
				this.type = this.zyList[0].id
				this.$nextTick(() => {
					this.numClassWidht();
				});
				this.getDoctorList();
			})
		},
		onKeyInput(e){
			this.keyword = e.detail.value;
			console.log(this.keyword)
			this.getDoctorList('refresh');
		},
		//获取医生列表
		getDoctorList(type) {
			let obj = this;
			//这里是将订单挂载到tab列表下
			if (type !== 'refresh' && type !== 'tab') {
				//没有更多数据直接跳出方法
				if (obj.loadingType === 'nomore') {
					return;
				} else {
					// 设置当前为数据载入中
					obj.loadingType = 'loading';
				}
			} else {
				//当重新加载数据时更新状态为可继续添加数据
				obj.loadingType = 'more';
			}
			if(type == 'tab') {
				obj.DoctorList = []
				obj.page = 1
				obj.loadingType = 'loading'
			}
			getDoctorList({
				hospital: '',
				keyword:obj.keyword,
				sort: '',
				page: obj.page,
				limit: obj.limit,
				type: obj.type
			})
				.then(({ data }) => {
					if (type === 'refresh') {
						obj.DoctorList = [];
					}
					obj.DoctorList = obj.DoctorList.concat(data.list);
					console.log(obj.DoctorList)
					//判断是否还有下一页，有是more  没有是nomore
					if (obj.limit == data.list.length) {
						obj.page++;
						obj.loadingType = 'more';
					} else {
						obj.loadingType = 'nomore';
					}
					// 判断是否为刷新数据
					if (type === 'refresh') {
						// 判断是否为点击搜索按钮跳转加载
						if (obj.loading == 1) {
							uni.hideLoading();
						} else {
							uni.stopPullDownRefresh();
						}
					}
				})
				.catch(e => {
					console.log(e)
					obj.loadingType = 'nomore';
					// obj.$api.msg(e.message);
					uni.hideLoading();
				});
		},
		ToExpert(item){
			uni.navigateTo({
				url: '/pages/doctor/expert?id='+item
			});
		},
	}
};
</script>

<style lang="scss">
	page{
		width: 100%;
		height: 100%;
	}
.container {
	height: 100%;
	.second-part{
		height: calc(100% - 100px);
	}
	.flex {
		display: flex;
		align-items: center;
	}
	.Search-box {
		overflow: hidden;
		width: 100%;
		padding: 20rpx;
		background-color: #ffffff;
		justify-content: space-around;
		.Search-box {
			width: 89%;
			height: 72rpx;
			border-radius: 36rpx;
			background-color: #f8f6f6;
			justify-content: flex-start;
			padding-left: 54rpx;
			.box-img {
				height: 30rpx;
				width: 30rpx;
				margin-right: 20rpx;
			}
			.box-word {
				font-size: $uni-font-size-base - 2rpx;
				font-weight: 500;
				color: #666666;
			}
		}
		.Search-word {
			width: 11%;
			font-size: $uni-font-size-lg - 2rpx;
			font-weight: 500;
			color: #666666;
			.word {
				float: right;
			}
		}
	}
		.template {
			width: 100%;
			background: #ffffff;
			overflow: hidden;
			padding: 25rpx;
			box-shadow: 0px 5px 5px 0px rgba(35, 24, 21, 0.06);
			border-radius: 12rpx;
			position: relative;
			.left-img {
				width: 140rpx;
				height: 140rpx;
				image{
					width: 100%;
					height: 100%;;
					border-radius: 100%;
				}
			}
			.center-word {
				width: 52%;
				padding-left: 25rpx;
				.one {
					font-size: $uni-font-size-lg - 2rpx;
					font-weight: 500;
					color: $uni-text-color;
					line-height: 36rpx;
					display: block;
					margin-bottom: 10rpx;
				}
				.two {
					font-size: $uni-font-size-sm;
					font-weight: 500;
					color: #666666;
					line-height: 36rpx;
					display: block;
				}
			}

			.right-label {
				padding: 16rpx;
				border: 1px solid $base-color;
				border-radius: 7rpx;
				font-size: $font-sm - 1rpx;
				font-weight: 500;
				color: $base-color;
				align-items: center;
				image {
					width: 30rpx;
					height: 26rpx;
					margin-right: 8rpx;
				}
			}
		}
	
}

.popup {
	width: 536rpx;
	.img {
		width: 100%;
	}
	.row {
		background: #ffffff;
		overflow: hidden;
		border-radius: 0 0 10rpx 10rpx;
		padding: 45rpx 45rpx;
		margin-top: -15rpx;
		.row-1 {
			font-size: $font-lg + 4rpx;
			font-weight: 500;
			color: rgba(51, 51, 51, 1);
			line-height: 53rpx;
			text-align: center;
		}
		.row-2 {
			font-size: $uni-font-size-lg;
			font-weight: 500;
			color: $font-color-dark;
			line-height: 44rpx;
			text-align: center;
			margin-top: 35rpx;
		}
		.row-3 {
			width: 80%;
			height: 70rpx;
			margin: 0 auto;
			margin-top: 40rpx;
			background: linear-gradient(0deg, rgba(126, 153, 254, 1), rgba(151, 143, 250, 1));
			border-radius: 34rpx;
			justify-content: center;
			font-size: $uni-font-size-lg + 4rpx;
			font-weight: 500;
			color: #f8f9f9;
		}
	}
}
.close_icon {
	width: 52rpx;
	height: 52rpx;
	margin: 88rpx auto 0;
	image {
		width: 100%;
		height: 100%;
	}
}
//支付弹窗
.payment {
	background-color: #ffffff;
	border-radius: 15rpx 15rpx 0rpx 0rpx;
	.first {
		border-bottom: 2rpx solid $border-color-light;
		padding: 38rpx 25rpx;
		.word {
			font-size: $uni-font-size-base;
			font-weight: bold;
			color: $font-color-dark;
		}
		image {
			width: 25rpx;
			height: 25rpx;
		}
	}
	.pay-type-list {
		margin-top: 20upx;
		background-color: #fff;
		padding-left: 40upx;
		.type-item {
			height: 120upx;
			padding: 20upx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-right: 60upx;
			font-size: 30upx;
			position: relative;
		}
		.icon {
			width: 100upx;
			font-size: 52upx;
		}
		.img {
			color: #fe8e2e;
			width: 50rpx;
			height: 50rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.tit {
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 4upx;
		}
		.con {
			flex: 1;
			display: flex;
			flex-direction: column;
			padding-left: 25rpx;
			font-size: $font-sm;
			color: $font-color-light;
		}
	}
	.one {
		height: 20rpx;
		background-color: #f6f6f6;
	}
	.Third {
		.two1 { 
			width: 55%;
			background-color: #ffffff;
			padding-left: 25rpx;
			.two1-1 {
				font-size: $uni-font-size-base;
				font-weight: 400;
				color: $font-color-dark;
			}
			.two1-2 {
				font-size: $uni-font-size-sm;
				font-weight: bold;
				color: $color-red1;
			}
			.size {
				font-size: $uni-font-size-lg + 4rpx;
			}
		}
		.two2 {
			width: 45%;
			background: $color-red1;
			color: #ffffff;
			font-size: $uni-font-size-lg;
			font-weight: 550;
			text-align: center;
			padding: 30rpx 0rpx;
		}
	}
}
// 头部时间段样式
	.class-box {
		white-space: nowrap;
		height: 40px;
		position: relative;
		background-color: #fff;
		.item {
			text-align: center;
			display: inline-block;
			color: $font-color-base;
			height: 100%;
			background-color: #ffffff;
			line-height: 1;
			.status {
				font-size:30rpx;
				margin: 0 auto;
				width: 60px;
				height: 100%;
				line-height: 40px;
				&.action {
					color: #6786fb;
					font-weight: bold;
					position: relative;
					&:after {
						content: '';
						position: absolute;
						left: 50%;
						bottom:5px;
						transform: translateX(-50%);
						width: 33px;
						height: 0;
						border-bottom: 2px solid #6786fb;
					}
				}
			}
		}
	}
</style>
