<template>
	<view class="content">
		<view class="consu-list">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
				<view v-for="(item,index) in dataList" :key="index" class="item" @click="showImg(item)">
					<view class="ordersn-box">
						<view class="num">处方单号：{{item.rpId}}</view>
						<view class="status-box">
							<text   class="text info" v-if="item.status==0">待开方</text>
							<text   class="text success" v-if="item.status==1">已开方</text>
							<text   class="text black" v-if="item.status==2">已拒绝</text>
						</view>
					</view>
					<view class="drug-list" >
						<view  class="drug-item" v-for="(subItme,index) in item.items" >
							<view class="drug-info"  >
								<view class="name-box ellipsis2">
									<view  class="tag">处方药</view>{{subItme.drugName}}
								</view>
							</view>
						</view>
					</view>
					<view class="ask-text" v-if="item.status==1">诊断结果：{{item.diagnose}}</view>
					<view class="ask-text" v-if="item.status==2">审核结果：{{item.auditReason}}</view>
					<view class="patient-text" v-if="item.status==1">医生：{{item.doctorName}} </view>
					<view class="patient-text">患者：{{item.patientName}} {{item.patientAge}}岁 {{item.patientGender==1?'男':'女'}} </view>
					<view class="ask-time" v-if="item.createTime!=null">提交时间：{{item.createTime}}</view>
					<view class="ask-time" v-if="item.rpCreateTime!=null">开方时间：{{item.rpCreateTime}}</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import {getMyPrescribeList} from '@/api/prescribe.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
				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://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/no_data.png',
						tip: '暂无数据'
					}
				},
				// 列表数据
				dataList: []
			}
		},
		onLoad() {
			
		},
		methods: {
			 
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					page: page.num,
					pageSize: page.size
				};
				getMyPrescribeList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						res.data.list.forEach(function(element) {
						   element.items=JSON.parse(element.drugs);
						});
						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();
					}
				});
			},
			showImg(item) {
				 var imgArr = [];
				 imgArr.push(item.rpUrl)
				 //预览图片
				 uni.previewImage({
				 	urls: imgArr,
				 	current: imgArr[0]
				 });
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 20upx;
		.top-fixed{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 10;
		}
		.pub-tab-box{
			box-sizing: border-box;
			width: 100%;
			padding: 0 40upx;
			background-color: #FFFFFF;
			.tab-inner{
				height: 88upx;
				line-height: 88upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				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;
				}
			}
		}
		.consu-list{
			.item{
				background: #FFFFFF;
				border-radius: 16upx;
				padding: 40upx 30upx;
				position: relative;
				margin-bottom: 20upx;
				.ordersn-box{
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 0upx 0 10upx;
					.num{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						line-height: 1;
					}
					.status-box{
						display: flex;
						align-items: center;
						.recom-box{
							width: 108upx;
							height: 30upx;
							line-height: 30upx;
							text-align: left;
							padding-left: 8upx;
							font-size: 22upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #FFFFFF;
							background-image: url(https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/recom.png);
							background-repeat: no-repeat;
							background-size: 100% 100%;
							margin-right: 8upx;
						}
						.text{
							font-size: 28upx;
							font-family: PingFang SC;
							font-weight: 500;
							line-height: 1;
							&.success{
								color: #2BC7B9;
							}
							&.black{
								color: #111111;
							}
							&.info{
								color: #999999;
							}
						}
					}
				}
				.doctor-info{
					display: flex;
					align-items: center;
					.img-box{
						width: 80upx;
						height: 80upx;
						background: #E0FFF8;
						border-radius: 50%;
						overflow: hidden;
						margin-right: 20upx;
						image{
							width: 100%;
							height: 100%;
						}
					}
					.name{
						font-size: 28upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						line-height: 48upx;
						text{
							margin-right: 10upx;
						}
					}
				}
				.ask-text{
					margin: 24rpx 0rpx;
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					line-height: 42upx;
				}
				.patient-text{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					margin-bottom: 15upx;
				}
				.ask-time{
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
				 
			}
		}
	}
	.drug-list{
		.drug-item{
			padding: 10upx 0;
			border-bottom: 1px soli #F0F0F0;
			display: flex;
			align-items: center;
			.drug-info{
				width: 100%;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.name-box{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					line-height: 40upx;
					.tag{
						display: inline-block;
						padding: 0 6upx;
						height: 30upx;
						background: linear-gradient(90deg, #66b2ef 0%, #2BC7B9 100%);
						border-radius: 4upx;
						margin-right: 10upx;
						font-size: 22upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #FFFFFF;
						line-height: 30upx;
						float: left;
						margin-top: 7upx;
					}
				}
				 
				 
			}
		}
	}
</style>
