<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="mescroll"  top="190rpx" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="cases-list">
				<view class="item" v-for="(item,index) in dataList" :key="index">
					<!-- 文字 -->
					<view class="dec-text ellipsis2">{{item.title}}</view>
					<!-- 有图 -->
					<view class="images-box"  v-if="item.imgs!=null"  >
						<view class="img-item" v-for="(subitem,j) in utils.photosToArr(item.imgs)" @click="showImg(item.imgs)" :key="j">
							<image :src="subitem" mode="aspectFill" ></image>
						</view>
					</view>
					<!-- 医生信息 -->
					<view class="doc-info">
						<view class="head">
							<image :src="item.doctorHeadImg" mode="aspectFill"></image>
						</view>
						<view class="name">{{item.doctorName}}</view>
						<view class="line"></view>
						<view class="posit">
							{{utils.getDictLabelName("doctorPosition",item.doctorPosition)}}
						</view>
						<view class="line"></view>
						<view class="address">{{item.hospitalName}}</view>
					</view>
					<view class="answer-box">
						<!-- 文字回答 -->
						<text class="text-inner" v-if="item.orderType == '1' ">{{item.replyContent}}</text>
						<!-- 语音回答 -->
						<view class="voice-inner" v-if="item.orderType == '2'">
							<free-audio 
								startPic='/static/images/play.png' 
								endPic='/static/images/pause.png'
								activeColor="#018C39"
								:audioId="'audio'+index"
								:url='item.replyAudioUrl'
							></free-audio>
						</view>
					</view>
					<view class="read-box">
						<image src="../../static/images/eye.png" mode=""></image>
						<text class="text">{{item.views}}人看过</text>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import {getDepartmentList,getDoctorCase} from '@/api/doctorOrder.js'
	import freeAudio from '@/components/chengpeng-audio/free-audio.vue'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	
	export default {
		components: { freeAudio},
		mixins: [MescrollMixin], 
		data() {
			return {
				depts:[],
				deptId:0,
				searchVal:"",
				// tab切换
				casesCateChose: 1,
				// 上拉加载的配置
				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() {
			this.getDepartmentList()
		},
		methods: {
			changeDept(item) {
				this.deptId = item.departmentId;
				this.mescroll.resetUpScroll()
				
			},
			getDepartmentList(){
				getDepartmentList().then(res => {
					if(res.code==200){
						var allDept={departmentId:0,departmentName:"全部"}
						this.depts.push(allDept);
						this.depts=this.depts.concat(res.data);
						console.log(this.depts)
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
					}
				});
			},
			goSearch(){
				this.mescroll.resetUpScroll()
			},
			showImg(urls) {
				 var imgArr =urls.split(',');
				 //预览图片
				 uni.previewImage({
				 	urls: imgArr,
				 	current: imgArr[0]
				 });
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					departmentId:this.deptId,
					title:this.searchVal,
					page: page.num,
					pageSize: page.size
				};
				getDoctorCase(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();
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.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{
				height: 60upx;
				line-height: 60upx;
				flex: 1;
			}
		}
	}
	.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-fixed{
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
	}
	.top-seat{
		width: 100%;
		height: 212upx;
	}
	// 问诊案例
	.cases-list{
		padding: 20upx;
		.item{
			padding: 30upx;
			background: #FFFFFF;
			border-radius: 16upx;
			margin-bottom: 20upx;
			.dec-text{
				font-size: 32upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #111111;
				line-height: 48upx;
			}
			.images-box{
				margin-top: 10upx;
				display: flex;
				flex-wrap: wrap;
				.img-item{
					width: 155upx;
					height: 155upx;
					background: #F5F5F5;
					border-radius: 8upx;
					margin: 0 10upx 10upx 0;
					overflow: hidden;
					image{
						width: 100%;
						height: 100%;
					}
					&:nth-child(4n){
						margin-right: 0;
					}
				}
			}
			.doc-info{
				display: flex;
				align-items: center;
				margin: 30upx 0 20upx;
				.head{
					width: 60upx;
					height: 60upx;
					background: #F2F5F9;
					border-radius: 50%;
					margin-right: 20upx;
					overflow: hidden;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.name{
					font-size: 28upx;
					line-height: 1;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
				}
				.line{
					width: 1px;
					height: 22upx;
					background: #DDDDDD;
					margin: 0 16upx;
				}
				.posit,
				.address{
					font-size: 26upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}
			.answer-box{
				width: 100%;
				// height: 117upx;
				background: #F5F7F7;
				border-radius: 10upx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				.text-inner{
					// height: 84upx;
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
					line-height: 42upx;
					padding: 15upx;
				}
			}
			.read-box{
				margin-top: 30upx;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				image{
					width: 24upx;
					height: 19upx;
					margin-right: 10upx;
				}
				.text{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}
		}
	}
</style>
