<template>
	<view class="container safe-area-inset-bottom">
		<!-- 处方 -->
		<view class="head">
			<view class="head_record_top">
				<view class="record">
					处方编号：{{infoList.prescription_no}}
				</view>
				<view class="record_state">
					{{lists.type==1 ? '普通':'常用'}}
				</view>
			</view>
			<!-- 医院 -->
			<view class="head_record">
				<image src="@/static/image/hlwyy.png" mode=""></image>
				<view class="record_yard">
					<view class="yard">
						银川慧疗互联网医院
					</view>
					<view class="state">
						处方笺
					</view>
				</view>
			</view>
			<!-- 时间 -->
			<view class="head_record_time">
				<text style="text-align: right;">开具日期：{{infoList.created_at}}</text>
			</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="lists.prescription_type==1||lists.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">[{{useWay[it.order]}}]</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="lists.prescription_type==2">
					<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">
							<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="info" v-for="(item ,index) in lists.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>
				</view>
				<view class="info">
					<text>初审药师</text>
					<text class="name">{{infoList.first_view||''}}</text>
				</view>
				<view class="info">
					<text>复审药师</text>
					<text class="name">{{infoList.again_view||''}}</text>
				</view>
			</view>

			<view class="price">
				价格:￥{{ infoList.total_pay_price }}
			</view>
		</view>
		<!-- 温馨提示 -->
		<view class="my_prompt">
			<view class="title">
				温馨提示：请遵医嘱服药！处方{{lists.valid_hours}}小时有效！
			</view>
			<image src="/static/group/img-yzf.png" mode="" v-if="status==2"></image>
		</view>
		<view v-if="notice_id" class="rotation" @click.stop="rotation">转 方</view>
		<!-- 状态 -->

	</view>
</template>

<script>
	import {
		rotationApi,
		prescripDetail,
		getUseWay
	} from "@/api/all.js";
	export default {
		data() {
			return {
				statusName: {
					0: '待审核',
					1: '已通过',
					2: '未通过',
					3: '待使用',
					4: '已使用',
					5: '未使用',
					6: '已失效',
					7: '已初审'
				},
				// status:flase,
				status: true,
				// status: "", // 处方状态
				status: "", // 处方状态
				id: "",
				infoList: [],
				num: 1,
				rpList: [],
				order_id: "",
				lists: [],
				useWay: [],
				notice_id: ''
			}
		},
		onLoad(e) {
			// console.log('12')
			// console.log(e, "id");
			this.id = e.id
			this.notice_id = e.notice_id
			this.getInfo()
			getUseWay({
				store_id: uni.getStorageSync('store_id') || 11001,
			}).then((res) => {
				if (res.errcode == 0) {
					const useWay = ["无", ...(res.data.map(it => it.name))]
					uni.setStorageSync('useWay', JSON.stringify(useWay))
					this.useWay = useWay
				}
			})
		},
		methods: {
			async rotation() {
				rotationApi({
					notice_id: this.notice_id,
					store_id: uni.getStorageSync('store_id') || '11001'
				}).then(res => {
					uni.showToast({
						title: '转方成功',
						icon: 'success',
						mask: true
					})
					setTimeout(() => {
						uni.navigateBack({ delta: 1 })
					}, 1500)
				})
			},
			// 数量
			getnum(obj) {
				let list = obj
				let num = 0
				list.map((it) => {
					num += it.number
				})
				return num
			},
			getInfo() {
				prescripDetail({
					store_id: uni.getStorageSync('store_id') || '11001',
					prescription_id: this.id
				}).then((res) => {
					// console.log(res, 'deta');
					if (res.errcode == 0) {
						this.infoList = res.data.content
						this.rpList = res.data.pharmacistInfo
						this.lists = res.data
						this.status = res.data.status

						// console.log(this.rpList, 'info');


					}
				})
			},
			// getDrug(obj) {
			// 	console.log(obj, 'obj')
			// 	if (!obj) {
			// 		return
			// 	}
			// 	let list = (obj.chinese.length > 0 ? obj.chinese : obj.west) || []
			// 	let drugs = []
			// 	// console.log(list);
			// 	for (let i = 0; i < list.length; i++) {
			// 		if (obj.chinese.length > 0) {
			// 			for (let j = 0; j < JSON.parse(list[i].content).length; j++) {
			// 				drugs.push(JSON.parse(list[i].content)[j]['name'])
			// 			}
			// 		} else {
			// 			drugs.push(JSON.parse(list[i].content)['name'])
			// 		}
			// 	}
			// 	return drugs.join()
			// },
		},
		mounted() {
			// 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 - 600rpx);
		}

		.head {
			.head_record_top {
				width: 710rpx;
				margin: 14rpx auto 0;
				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_time {
				text-align: right;
				width: 750rpx;
				padding: 0 32rpx;
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #6C7380;
			}

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

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

				.record_yard {
					text-align: center;

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

					.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;
				margin-top: 20rpx;
				width: 750rpx;
				padding-right: 32rpx;
				height: 34rpx;
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #6C7380;
				line-height: 28rpx;
			}
		}

		// 信息
		.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 26rpx 0 6rpx;
						}
					}
				}
			}
		}

		// 药品
		.my_medical {
			width: 710rpx;
			margin: 4rpx auto;
			padding: 1rpx 10rpx;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				color: #31353D;
				margin-bottom: 2rpx;
			}

			.item {
				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: 16rpx;
							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;
						}
					}
				}
			}

			.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;
						}
					}
				}
			}
		}

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

			.yz {
				display: flex;
				width: 100%;
				color: #6C7380;

				.order_info_left {
					margin-right: 3rpx;
				}

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

					.info {
						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: 2rpx 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 {
					min-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;
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #31353D;
			}
		}

		// 温馨提示
		.my_prompt {
			width: 710rpx;
			height: 304rpx;
			margin: 0 auto;
			padding: 0 4rpx;
			position: relative;

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

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

			.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;
			height: 40rpx;
			margin: 12rpx auto;
			padding-bottom: 110rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #F44336;
			line-height: 40rpx;
		}

		.line {
			border-bottom: 2rpx solid #31353D;
		}
	}
	.rotation {
		position: fixed;
		bottom: 30rpx;
		right: 24rpx;
		left: 24rpx;
		height: 80rpx;
		display: flex;
		font-size: 30rpx;
		align-items: center;
		justify-content: center;
		background: #5792f9;
		color: #fff;
		border-radius: 12rpx;
	}
</style>