<template>
	<view class="container safe-area-inset-bottom">
		<MessageNotification />
		<view class="all" v-if="status==1||status==4">
			<!-- 处方 -->
			<view class="head">
				<view class="head_record_top">
					<view class="record">
						处方编号：{{infoList.prescription_no}}
					</view>
					<view class="record_state">
						{{data.type==1 ? '普通':'常用'}}
					</view>
				</view>
				<!-- 医院 -->
				<view class="head_record">
					<image :src="data.store['offical_seal'] ||''" mode=""></image>
					<view class="record_yard">
						<view class="yard">
							{{data.store.name}}
						</view>
						<view class="state">
							处方笺
						</view>
					</view>
				</view>
				<!-- 时间 -->
				<view class="head_record_time">
					开具日期：{{infoList.created_at}}
				</view>
			</view>

			<!-- 信息 -->
			<view class="my_info">
				<view class="info">
					<view class="info_item">
						<view class="name">
							姓名：
							<text>{{infoList.patient.name}}</text>
						</view>
					</view>
					<view class="info_item">
						<view class="name">
							性别：
							<text>{{infoList.patient.sex%2==0?'女':'男'}}</text>
						</view>
					</view>
					<view class="info_item">
						<view class="name">
							年龄：
							<text>{{infoList.patient.age}}</text>
						</view>
					</view>
					<view class="info_item">
						<view class="name">
							类别：
							<text>{{infoList.category}}</text>
						</view>
					</view>
				</view>

				<view class="info">
					<view class="info_item">
						<view class="name">
							科室：
							<text>{{infoList.doctor.depart.name}}</text>
						</view>
					</view>
					<view class="info_item">
						<view class="name">
							电话：
							<text>{{infoList.patient.mobile}}</text>
						</view>
					</view>
				</view>

				<view class="info">
					<view class="info_item">
						<view class="names">
							诊断：
							<text>{{infoList.clinical_diagnose}}</text>
						</view>
					</view>
				</view>
			</view>

			<view class="bg">
				<!-- 药品 -->
				<view class="my_medical ">
					<view class="title">
						Rp
					</view>

					<block v-if="data.prescription_type==1 || data.prescription_type==3">
						<view class="items" v-for="(item,index) in infoList.repice" :key="item.id">
							<!--  v-for="(it,index) in item.content" :key="it.id" -->
							<view class="name">
								<view class="_name" v-for="(it,index) in item.content" :key="it.id">
									<view class="text">
										<text>{{ it.name}}</text>
										<text class="_abbr" v-if="it.order!=0">[{{useWay[it.order]}}]</text>
										<!-- <text class="_abbr">{{it.order==1&&'[先下]'||it.order==2&&'[后下]' || ''}}</text> -->
									</view>
									<text class="name_num">{{ it.number }}{{it.unit?it.unit.name:'g'}}</text>
								</view>
							</view>
							<view class="details">
								<view class="text">
									<text>用法：煎服，每天 {{item.consumption}} 次 ，</text>
									<text v-if="item.deployment==2">{{' 每次 '+item.volume+' ml '}} ， </text>
									<text> 共 {{item.dosage}} 剂</text>
								</view>
							</view>
						</view>
					</block>

					<block v-if="data.prescription_type==2||data.prescription_type == 5||data.prescription_type == 7">
						<view class="item" v-for="(it,index) in infoList.repice" :key="item.id">
							<!--  v-for="(it,index) in item.content" :key="it.id" -->
							<view class="name" style="justify-content: space-between;">
								<view class="yp_name">
									<text>{{ it.content.drug_name}} </text>
									<text
										style="font-size: 24rpx;margin-left: 10rpx;">{{ it.content.specification }}</text>
								</view>
								<text>x{{ it.number}}</text>
							</view>
							<view class="details" v-if="data.prescription_type==2">
								<text>用法：{{ it.instruction }}</text>
							</view>
						</view>
					</block>

				</view>


				<!-- 医嘱 -->
				<view class="doctor_order">
					<view class="yz">
						<text class="order_info_left">医嘱:</text>
						<view class="order_info">
							<view class="infoed" v-for="(item ,index) in data.doctor_order" :key="index">
								{{item}}
							</view>
						</view>
					</view>
					<view class="titles">
						处方开具已完毕
					</view>
				</view>

			</view>
			<!-- 医生 -->
			<view class="my_doctor">
				<view class="doctor_info">
					<view class="info">
						<text>医师</text>
						<!-- <text class="name">{{infoList.doctor.name || ''}}</text> -->
						<image :src="checkImageUrl(data.doctor_sign_image)" mode="aspectFit"></image>
						<image v-if="data.doctor_second_sign == 1" :src="checkImageUrl(data.doctor_sign_image)" mode="aspectFit"></image>
					</view>
					<view class="info">
						<text>审核药师</text>
						<image :src="checkImageUrl(data.Pharmacist_sign_image)" mode="aspectFit"></image>
						<!-- <text class="name">{{rpList.name || ' '}}</text> -->
					</view>
					<view class="info">
						<text>发药人</text>
						<!-- <text class="name">{{rpList.name || ' '}}</text> -->
						<image :src="checkImageUrl(data.Pharmacist_sign_image)" mode="aspectFit"></image>
					</view>
					<view class="info">
						<text>核对人</text>
						<image :src="checkImageUrl(data.Pharmacist_sign_image)" mode="aspectFit"></image>
					</view>
					<view class="info">
						<text>调配人</text>
						<image :src="checkImageUrl(data.Pharmacist_sign_image)" mode="aspectFit"></image>
					</view>
					<!-- <view class="info">
						<text>复审药师</text>
						<text class="name">{{rpList.again_view || ' '}}</text>
					</view> -->
				</view>

				<view class="price">
					价格 ￥{{infoList.total_pay_price}}
				</view>
			</view>

			<!-- 须知 -->
			<u-popup v-model="show" :safe-area-inset-bottom="true" mode="bottom" height="68%" border-radius="20"
				:closeable="true">
				<view class="agreen">
					<u-parse :html="content"></u-parse>
				</view>
			</u-popup>

			<!-- 温馨提示 -->
			<view class="my_prompt">
				<view class="titles">
					{{status==1&&'温馨提示，请遵医嘱服药！处方'+data.valid_hours+'小时内有效！'|| status==3&&'温馨提示，请遵医嘱服药！你的处方已过48小时' || status==4&&'本处方为产品服务包'}}
				</view>
				<image src="/static/group/sx.png" class="image" v-if="status==3"></image>

			</view>

			<!-- 状态 -->
			<view class="my_state" v-if="(status==1||status==4)&&data.is_pay==0&&data.cancel_status==0">
				<view class="btn" @click="toAppion">
					预约购药
				</view>
			</view>
		</view>

		<view class="none" v-if="status==0||status==2||status==3">
			<!-- 处方 -->
			<view class="head">
				<view class="head_record_top">
					<view class="record">
						处方编号：{{infoList.prescription_no}}
					</view>
					<view class="record_state">
						{{data.type==1 ? '普通':'常用'}}
					</view>
				</view>
			</view>

			<!-- 信息 -->
			<view class="info">
				<view class="name">
					<text>姓名：</text>
					{{infoList.patient.name}}
				</view>
				<view class="name">
					<text>性别：</text>
					{{(infoList.patient.sex)%2==0?'女':'男'}}
				</view>
				<view class="name">
					<text>年龄：</text>
					{{infoList.patient.age}}
				</view>
				<view class="name">
					<text>科室：</text>
					{{infoList.doctor.depart.name}}
				</view>
				<view class="name">
					<text>电话：</text>
					{{infoList.patient.mobile}}
				</view>
				<view class="name">
					<text>开具日期：</text>
					{{infoList.created_at}}
				</view>
				<view class="name">
					<text>处方开立医师：</text>
					{{infoList.doctor.name}} &nbsp; {{infoList.doctor.title.name}}
				</view>
			</view>

			<!-- 医嘱 -->
			<view class="order_status" v-if="status==0" style="color: #E88F16;">
				您的处方正在审核中
			</view>
			<view class="order_status" v-if="status>=2" style="color: #FC3636;">
				{{status==2&&'您的处方未通过审核，该处方为无效处方'||status==3&&'您的处方已失效，该处方为无效处方'}}
			</view>
			<!-- 	<view class="order_status">
				{{status==0&&'您的处方正在审核中' || status==2&&'您的处方未通过审核'}}
			</view> -->


			<!-- 温馨提示 -->
			<view class="my_prompt">
				<view class="title">
					{{status==0&&'温馨提示，请遵医嘱服药！处方'+data.valid_hours+'小时内有效！' || status==2&&'温馨提示，请遵医嘱服药！您的处方未通过审核。'}}
				</view>
			</view>

			<!-- 状态 -->
			<view class="my_state" v-if="(status==0||status==4)&&data.is_pay==0&&data.cancel_status==0">
				<view class="btn" @click="toAppions">
					预约购药
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getPrescriptInfo,
		getUseWay
	} from '../../request/api/api'
  import { checkImageUrl } from '../../utils/utils'

	export default {
		data() {
			return {
				statusName: {
					0: '待审核',
					1: '已通过',
					2: '未通过',
					3: '待使用',
					// 4: '已使用',
					4: '无需审核',
					5: '未使用',
					6: '已失效',
					7: '已初审'
				},
				status: "", // 处方状态
				id: "",
				infoList: [],
				num: 1,
				rpList: [],
				form: {
					check: true
				},
				p_id: "", // 处方id
				no: "", // 处方编号
				data: '',
				show: false,
				useWay: [],
			}
		},
		onLoad(e) {
			// console.log(e, 'detail');
			this.p_id = e.id
			this.no = e.no
		},
		methods: {
      checkImageUrl,
			// 数量
			getnum(obj) {
				let list = obj
				let num = 0
				list.map((it) => {
					num += it.number
				})
				return num
			},
			getWay() {
				getUseWay({
					method: "post",
					data: {
						store_id: uni.getStorageSync('store_id') || '11001'
					}
				}).then((res) => {
					if (res.data.errcode == 0) {
						const useWay = ["无", ...(res.data.data.map(it => it.name))]
						this.useWay = useWay
					}
				})
			},
			// 预约购药
			toAppion() {
				// if (this.form['check']) {
				// 	uni.showToast({
				// 		icon: "error",
				// 		title: '请勾选协议'
				// 	})
				// 	return
				// }

				// setTimeout(() => {
				// 	uni.navigateTo({
				// 		url: "/subPackages/my/record-pay?id=" + this.p_id
				// 	})
				// }, 200)

				uni.navigateTo({
					url: "/subPackages/my/record-pay?id=" + this.data.id
				})
			},
			toAppions() {
				uni.navigateTo({
					url: "/subPackages/my/record-pay?id=" + this.data.id
				})
			},
			getInfo() {
				getPrescriptInfo({
					method: "post",
					data: {
						store_id: uni.getStorageSync('store_id') || '11001',
						prescription_no: this.no
					}
				}).then((res) => {
					// console.log(res, 'deta');

					if (res.data.errcode === 0) {
						this.infoList = res.data.data.content
						this.rpList = res.data.data.pharmacistInfo
						this.status = res.data.data.status
						this.data = res.data.data
						// uni.setStorageSync('p_id',res.data.data.id)
						// console.log(this.rpList, 'info');
					}
				})
			},
		},
		mounted() {
			this.getWay()
		},
		onShow() {
			this.getInfo()
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 750rpx;
		min-height: 100vh;
		max-height: 100%;
		padding-bottom: env(safe-area-inset-bottom);

		.bg {
			min-height: calc(100vh - 800rpx);
		}

		.agreen {
			padding: 60rpx 50rpx 20rpx;
			// color: #6C7380;
			// letter-spacing: 2rpx;

			.top {
				margin: 0 0 20rpx 0;
				font-family: PingFang SC-Regular, PingFang SC;
				text-align: center;
				font-size: 32rpx;
				font-weight: 500;
				color: #222;
			}
		}

		.head {
			.head_record_top {
				width: 710rpx;
				margin: 14rpx auto;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.record {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #6C7380;
				}

				.record_state {
					width: 80rpx;
					height: 42rpx;
					line-height: 42rpx;
					text-align: center;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #A7ABB0;
					border: 1rpx solid #C4C7CC;
				}

			}

			.head_record {
				display: flex;
				align-items: center;
				justify-content: center;
				position: relative;

				image {
					width: 165rpx;
					height: 150rpx;
					position: absolute;
					left: 40%;
					top: -28rpx;
				}

				.record_yard {
					text-align: center;

					.yard {
						font-size: 48rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #31353D;
						line-height: 56rpx;
					}

					.state {
						height: 44rpx;
						font-size: 32rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #31353D;
						line-height: 38rpx;
					}
				}
			}

			.head_record_time {
				text-align: right;
				width: 750rpx;
				padding-right: 32rpx;
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #6C7380;
			}
		}

		// 信息
		.my_info {
			width: 710rpx;
			margin: 4rpx auto;
			border-top: 1rpx solid #31353D;
			border-bottom: 1rpx solid #31353D;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			padding: 4rpx 4rpx;

			.info {
				width: 710rpx;
				display: flex;
				align-items: center;

				.info_item {

					.names {
						display: flex;
						align-items: center;
						justify-content: space-around;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #6C7380;

						text {
							flex: 1;
							display: block;
							height: 40rpx;
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #31353D;
							line-height: 40rpx;
							margin: 0 0rpx 0 8rpx;
							// flex-wrap: nowrap;
							// display: -webkit-box;
							// -webkit-line-clamp: 1;
							// -webkit-box-orient: vertical;
							// text-overflow: ellipsis;
							// overflow: hidden;
						}
					}

					.name {
						display: flex;
						align-items: center;
						justify-content: space-around;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #6C7380;

						text {
							flex: 1;
							display: block;
							height: 40rpx;
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #31353D;
							line-height: 40rpx;
							margin: 0 20rpx 0 8rpx;
						}
					}
				}
			}
		}

		// 药品
		.my_medical {
			width: 710rpx;
			margin: 6rpx auto;

			.title {
				height: 44rpx;
				font-size: 32rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #31353D;
				line-height: 44rpx;
			}

			.items {
				width: 710rpx;
				padding: 1rpx 0;

				.name {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #31353D;
					display: flex;
					// justify-content: space-between;
					flex-wrap: wrap;

					._name {
						display: flex;
						justify-content: space-between;
						margin: 2rpx 80rpx 2rpx 0;

						.text {
							margin-right: 26rpx;
							display: flex;
							flex-direction: column;

							._abbr {
								color: #A7ABB0;
								font-size: 20rpx;
								margin-top: 2rpx;
							}
						}
					}
				}

				.details {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #6C7380;
					display: flex;
					flex-direction: column;
					justify-content: space-around;

					.text {

						text {
							word-spacing: 1rpx;
						}
					}
				}
			}

			.item {
				width: 710rpx;
				padding-top: 2rpx;

				.name {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #31353D;
					display: flex;
					justify-content: space-between;
					align-items: center;
				}

				.details {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #6C7380;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
				}
			}

			.item:last-child {
				border: 0;
			}
		}

		// 医嘱
		.doctor_order {
			width: 710rpx;
			margin: 0rpx auto;
			word-spacing: 2rpx;

			.yz {
				display: flex;
				color: #6C7380;

				.order_info_left {
					margin-right: 4rpx;
				}

				.order_info {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					line-height: 40rpx;
					margin-bottom: 2rpx;

					.infoed {
						flex: 1;
					}
				}
			}


			.titles {
				width: 710rpx;
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #A7ABB0;
				margin: 8rpx 0 20rpx;
			}
		}

		// 医生
		.my_doctor {
			width: 710rpx;
			margin: 4rpx auto;
			border-top: 1rpx solid #31353D;
			border-bottom: 1rpx solid #31353D;
			padding: 2rpx 4rpx;

			.doctor_info {
				width: 710rpx;
				display: flex;
				align-items: center;
				margin-bottom: 4rpx;
				flex-wrap: wrap;

				.info {
					width: 222rpx;
					max-width: 400rpx;
					margin: 5rpx 0 8rpx;

					text {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #31353D;
					}

					image {
						width: 82rpx;
						height: 62rpx;
						vertical-align: middle;
					}

					.name {
						width: 106rpx;
						font-size: 32rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #31353D;
						line-height: 38rpx;
						border-bottom: 2rpx solid #000000;
						margin-left: 16rpx;
					}
				}

			}

			.price {
				width: 710rpx;
				height: 44rpx;
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #31353D;
				line-height: 44rpx;
			}
		}

		// 温馨提示
		.my_prompt {
			width: 710rpx;
			// height: 324rpx;
			margin: 0 auto 180rpx;
			padding: 20rpx 14rpx;
			position: relative;

			.titles {
				// width: 710rpx;
				height: 60rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #A7ABB0;
				line-height: 60rpx;
				margin: 32rpx 0;
			}

			.image {
				width: 159rpx;
				height: 100rpx;
				position: absolute;
				left: 60%;
				top: 0%;
			}

			// .prompt {
			// 	width: 710rpx;
			// 	height: 240rpx;

			// 	text {
			// 		font-size: 28rpx;
			// 		font-family: PingFang SC-Regular, PingFang SC;
			// 		font-weight: 400;
			// 		color: #A7ABB0;
			// 	}

			// 	ol {
			// 		padding: 0 0 0 32rpx;

			// 		li {
			// 			font-size: 28rpx;
			// 			font-family: PingFang SC-Regular, PingFang SC;
			// 			font-weight: 400;
			// 			color: #A7ABB0;
			// 			margin: 4rpx 0;
			// 		}
			// 	}
			// }
		}

		// 状态
		.my_state {
			width: 710rpx;
			margin: 0rpx auto;
			position: fixed;
			bottom: env(safe-area-inset-bottom);
			left: 3%;
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #232323;

			// .check {
			// 	display: flex;
			// 	justify-content: center;
			// 	align-items: center;
			// 	margin-bottom: 20rpx;

			// 	.agreement {
			// 		margin-left: 16rpx;

			// 		text {
			// 			color: #536DFE;
			// 		}
			// 	}
			// }

			.btn {
				width: 690rpx;
				height: 84rpx;
				line-height: 84rpx;
				background: #536DFE;
				border-radius: 64rpx;
				color: #FFFFFF;
				text-align: center;
			}
		}

		.none {
			width: 750rpx;
			min-height: 100vh;
			max-height: 100%;
			padding-bottom: env(safe-area-inset-bottom);

			.head {
				.head_record_top {
					width: 710rpx;
					height: 42rpx;
					margin: 34rpx auto;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.record {
						height: 40rpx;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #6C7380;
						line-height: 33rpx;
					}

					.record_state {
						width: 80rpx;
						height: 42rpx;
						line-height: 42rpx;
						text-align: center;
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #A7ABB0;
						border: 1rpx solid #C4C7CC;
					}

				}
			}

			// 信息
			.info {
				width: 710rpx;
				margin: 8rpx auto;
				border-bottom: 1rpx solid #bac9e7;
				display: flex;
				flex-direction: column;
				padding: 16rpx 4rpx;


				.name {
					width: 710rpx;
					height: 60rpx;
					line-height: 60rpx;
					display: flex;
					height: 60rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #232323;

					text {
						display: block;
						width: 196rpx;
						margin-right: 30rpx;
						color: #666;
					}
				}

			}

			// 医嘱
			.order_status {
				width: 710rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				margin: 16rpx auto;
				font-size: 28rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #232323;
			}

			// 温馨提示
			.my_prompt {
				width: 710rpx;
				// height: 304rpx;
				margin: 0 auto 30rpx;
				padding: 20rpx 14rpx;

				.title {
					// width: 710rpx;
					height: 40rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #A7ABB0;
					line-height: 40rpx;
					margin: 0 auto;
				}

				// .prompt {
				// 	width: 710rpx;
				// 	height: 200rpx;

				// 	text {
				// 		font-size: 28rpx;
				// 		font-family: PingFang SC-Regular, PingFang SC;
				// 		font-weight: 400;
				// 		color: #A7ABB0;
				// 	}

				// 	ol {
				// 		padding: 0 0 0 32rpx;

				// 		li {
				// 			font-size: 28rpx;
				// 			font-family: PingFang SC-Regular, PingFang SC;
				// 			font-weight: 400;
				// 			color: #A7ABB0;
				// 			margin: 4rpx 0;
				// 		}
				// 	}
				// }
			}

			// 状态
			.my_state {
				width: 710rpx;
				margin: 0rpx auto;
				position: fixed;
				bottom: env(safe-area-inset-bottom);
				left: 3%;
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #232323;

				// .check {
				// 	display: flex;
				// 	justify-content: center;
				// 	align-items: center;
				// 	margin-bottom: 20rpx;

				// 	.agreement {
				// 		margin-left: 16rpx;

				// 		text {
				// 			color: #536DFE;
				// 		}
				// 	}
				// }

				.btn {
					width: 690rpx;
					height: 84rpx;
					line-height: 84rpx;
					background: #536DFE;
					border-radius: 64rpx;
					color: #FFFFFF;
					text-align: center;
				}
			}
		}
	}
</style>
