<template>
	<view class="content">
		<mescroll-body top="0rpx" bottom="148rpx"  ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
		<view class="inner">
			<view class="illness-info" v-for="(item,index) in dataList" :key="index">
			 	<view class="head-box"  >
			 		<view class="left">
			 			<image class="img" src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/detault_head.jpg" mode=""></image>
			 			<text class="name">{{item.userName}}</text>
			 		</view>
			 		<view class="time">{{utils.formatDate(item.createTime)}}</view>
			 	</view>
			 	<view class="illness-text">
			 		{{item.title}}
			 	</view>
			 	<scroll-view v-if="item.photos.length>0" class="imag-scroll" scroll-x="true" >
			 		<view class="imag-list">
			 			<view v-for="(img,imgIndex) in item.photos" :key="imgIndex" class="item" @click="previewImage(item,imgIndex)">
			 				<image class="img" :src="img" mode="aspectFill"></image>
			 			</view>
			 		</view>
			 	</scroll-view>
				<view class="reply" v-for="(subItem,index) in item.replys">
					<view class="reply-title">
						<image class="img" src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/detault_head.jpg" mode=""></image>
						<text class="name">{{subItem.companyNickName}}</text> 
					</view>
					<view class="reply-content">
						医嘱：{{subItem.content}}
					</view>
					<scroll-view v-if="!utils.isEmpty(subItem.images)" class="imag-scroll" scroll-x="true" >
						<view class="imag-list rimag-list">
							<view v-for="(sImg,sIndex) in utils.photosToArr(subItem.images)" :key="sIndex" class="item" @click="sPreviewImage(utils.photosToArr(subItem.images),sIndex)">
								<image class="img rimg" :src="sImg" mode="aspectFill"></image>
							</view>
						</view>
					</scroll-view>
					<view class="reply-time">
						回复时间：{{utils.formatDate(subItem.createTime)}}
					</view>
				</view>
				<view v-if="item.showMore" class="more" @click="loadMoreReply(item)">查看更多</view>
			</view>
		</view>
		</mescroll-body>
		<view class="btn-box">
			<view class="sub-btn" @click="addDocRecord">写记录</view>
		</view>
	</view>
</template>
<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {getMyDocRecordList,getDocRecordReplyList} from '@/api/doc.js'

 
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				docId:null,
				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:'https://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/no_data.png',
						tip: '暂无数据'
					}
				},
				// 列表数据
				dataList: [],
			}
		},
		onLoad(options) {
			this.docId=options.docId;
			var that=this;
			uni.$on('refreshDocRecord', () => {
				that.mescroll.resetUpScroll()
			})
			 
		},
		methods: {
			loadMoreReply(item){
				item.pageNum=item.pageNum+1;
				var data = {
					recordId:item.recordId,
					page: item.pageNum,
					pageSize: item.pageSize
				};
				getDocRecordReplyList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						item.replys = item.replys.concat(res.data.list);
						if(item.replys.length>=res.data.total){
							item.showMore=false
						}
						else{
							item.showMore=true	
						}
					}else{
						 
					}
				});
			},
			previewImage(item,index){
				//预览图片
				uni.previewImage({
					urls: item.photos,
					current: item.photos[index]
				});
			},
			sPreviewImage(subItem,index){
				//预览图片
				console.log(subItem)
				uni.previewImage({
					urls: subItem,
					current: subItem[index]
				});
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					docId:this.docId,
					page: page.num,
					pageSize: page.size
				};
				getMyDocRecordList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						res.data.list.forEach(function(item) {
							item.pageNum=1;
							item.pageSize=10;
							if(item.replys.length==10){
								item.showMore=true;
							}
							else{
								item.showMore=false;
							}
							var images=[];
							if(item.images!=null&&item.images!=""){
								var imgs=item.images.split(",");
								imgs.forEach(function(img) {
									if(img!=""){
										images.push(img)
									}
									
								})
								item.photos=images;
							}
							item.photos=images;
						})
						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();
					}
				});
			},
			addDocRecord() {
				uni.navigateTo({
					url: './addDocRecord?docId='+this.docId
				})
			}
			 
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.content{
		height: 100%;
		
		.inner{
			padding: 20upx;
			.illness-info{
				background: #FFFFFF;
				border-radius: 16upx;
				padding: 30upx;
				margin-bottom: 20rpx;
				.head-box{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.left{
						display: flex;
						align-items: center;
						.img{
							width: 80upx;
							height: 80upx;
							border-radius: 50%;
							margin-right: 20upx;
						}
						.name{
							font-size: 30upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #111111;
						}
					}
					.time{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #808080;
					}
				}
				.illness-text{
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					line-height: 50upx;
					margin-top: 20upx;
				}
				.imag-scroll{
					margin-top: 20upx;
					.imag-list{
						display: flex;
						align-items: center;
						.item{
							flex-shrink: 0;
							width: calc(25% - 8upx);
							height: 160upx;
							margin-right: 10upx;
							overflow: hidden;
							&:first-child{
								border-radius: 12upx 0 0 12upx;
							}
							&:last-child{
								margin-right: 0;
								border-radius: 0 12upx 12upx 0;
							}
							.img{
								width: 100%;
								height: 100%;
							}
						}
					}
				}
				.time-hand-box{
					margin-top: 40upx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.time{
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						line-height: 1;
					}
					.right{
						display: flex;
						align-items: center;
						.item{
							display: flex;
							align-items: center;
							margin-right: 60upx;
							&:last-child{
								margin-right: 0;
							}
							.img{
								width: 28upx;
								height: 28upx;
								margin-right: 10upx;
							}
							.text{
								font-size: 28upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #999999;
								line-height: 1;
							}
						}
					}
				}
				.reply{
					border-bottom: 1rpx solid #f5f5f5;
					display: flex;
					align-items: flex-start;
					flex-direction: column;
					justify-content: flex-start;
					margin-top: 20upx;
					&:last-child {
						border-bottom: none;
						margin-top: 0rpx;
					}
					.reply-title{
						font-size: 30upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #111111;
						line-height: 50upx;
						margin-top: 25upx;
						display: flex;
						align-items: center;
						justify-content: flex-start;
						image{
							width: 50rpx;
							height:50rpx;
							border-radius: 50%;
						}
						.name{
							padding: 8upx 12upx;
							line-height: 40upx;
							background: #E2F6F2;
							border-radius: 6upx;
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #4BC9B1;
							margin-left: 15upx;
						}
					}
					.reply-content{
						margin-top: 20upx;
						padding: 20upx 25upx;
						font-size: 28upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						line-height: 42upx;
						background: #F5F7F7;
						border-radius: 10upx;
					}
					.imag-scroll{
						margin-top: 20upx;
						.imag-list{
							display: flex;
							align-items: center;
							.item{
								flex-shrink: 0;
								width: calc(25% - 8upx);
								height: 160upx;
								margin-right: 10upx;
								overflow: hidden;
								border-radius: 12upx;
								&:first-child{
									//border-radius: 12upx 0 0 12upx;
								}
								&:last-child{
									margin-right: 0;
									//border-radius: 0 12upx 12upx 0;
								}
								.img{
									width: 100%;
									height: 100%;
								}
							}
						}
						.rimag-list{
							.item{
								flex-shrink: 0;
								width: 110upx;
								height: 110upx;
								margin-right: 10upx;
								overflow: hidden;
								border-radius: 12upx;
								.rimg{
									width: 100%;
									height: 100%;
								}
							} 
						}
					}
					.reply-time{
						
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #cacaca;
						padding-bottom: 20rpx;
					}
				 
				}
				.more{
					font-size: 26upx;
					font-family: PingFang SC;
					color: #666666;
					padding: 20rpx 0rpx 0rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				.text-para{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					line-height: 42upx;
					margin-bottom: 23upx;
					&:last-child{
						margin-bottom: 0;
					}
					.name{
						font-size: 28upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #4BC9B1;
						line-height: 42upx;
					}
				}
			}
			 
		}
		.btn-box{
			z-index: 9999;
			width: 100%;
			padding: 30upx;
			position: fixed;
			bottom: 0;
			left: 0;
			box-sizing: border-box;
			background: #FFFFFF;
			.sub-btn{
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #2BC7B9;
				border-radius: 44upx;
			}
		}
		 
	}
</style>
