<template>
	<view class="hzIndex">
		<hzHeader title="预订信息"></hzHeader>
		<view class="container hzContent">
			<view class="interviewee card-box">
				<view>
					<text class="input_left">姓名</text>
					<input type="text" :value="item.user_name" disabled="true" />
				</view>
				<view @click="callPhone(item.tel_number)">
					<text class="input_left">联系电话</text>
					<input type="text" :value="item.tel_number" disabled="true" />
				</view>
				<view>
					<text class="input_left">部门</text>
					<input type="text" :value="item.dept_name" disabled="true" />
				</view>
			</view>
			<view class="interviewee" v-if="item.status!=0">
				<view class="form-item">
					<text class="input_left">医师意见</text>
					<input v-if="item.status==1" type="text" disabled="true" :value="'通过'" />
					<textarea auto-height v-if="item.status==2" type="text" disabled="true" :value="item.reason" />
				</view>
				<view v-if="item.real_name" class="form-item">
					<text class="input_left">医师</text>
					<input type="text" disabled="true" :value="item.real_name+' '+item.mobile" />
				</view>
			</view>
			<view class="interviewee" v-for="(detail, index) in item.detailList" :key="index">
				<view class="form-item">
					<text class="input_left">药名</text>
					<input type="text" disabled="true" :value="detail.drugs_name" />
				</view>

				<view class="form-item">
					<text class="input_left">剂型</text>
					<input type="text" disabled="true" :value="medicalList[detail.drugs_type].name" />
				</view>
				<view class="form-item">
					<text class="input_left">剂量</text>
					<input disabled="true" :value="detail.drugs_dose" type="text" />
				</view>
				<view class="form-item">
					<text class="input_left">单位</text>
					<input disabled="true" :value="drugsUnitList[detail.drugs_unit].name" type="text"
						placeholder="请输入剂量" />
				</view>
				<view class="form-item">
					<text class="input_left">厂家</text>
					<input type="text" disabled="true" v-model="detail.drugs_factory" />
				</view>
				<view class="form-item">
					<text class="input_left">数量</text>
					<input type="text" disabled="true" v-model="detail.drugs_num" />
				</view>
				<view class="pic" v-if="detail.drugs_pic1 || detail.drugs_pic2">
					<image v-if="detail.drugs_pic1" :src="formatImgUrl(detail.drugs_pic1)" mode=""
						@click="vbPicture(new Array(formatImgUrl(detail.drugs_pic1)))"></image>
					<image v-if="detail.drugs_pic2" :src="formatImgUrl(detail.drugs_pic2)" mode=""
						@click="vbPicture(new Array(formatImgUrl(detail.drugs_pic2)))"></image>
				</view>
			</view>

			<view style="height: 180upx;"></view>
			<!-- <view class="footer-btn">
			<view class="btn btn-col" @click="submit()">审批</view>
		</view> -->
			<view v-if="item.status==0">
				<!-- uni-popup ref="butPopup" type="bottom" -->
				<view>
					<view class="footer-btn footer-btn-two batchBtn">
						<view class="no-btn" @click="circulation()">不通过</view>
						<view class="no-btn" @click="changeItem()">修改</view>
						<view class="s-btn" @click="submit(1)">通过</view>
					</view>
				</view>
			</view>
			<uni-popup ref="popup" type="center" style="">
				<view
					style="background: white;width: 80%;height: 540upx;width: 600upx;position: relative;border-radius: 10upx;padding: 14upx;">
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>医师意见：</text>
					</view>
					<view
						style="width: 100%;border: 1px solid #E5E5E5;margin-top: 20upx;padding: 20upx;height: 300upx;color: #666;border-radius: 10upx;">
						<textarea @blur="bindTextAreaBlur" v-model="reason" placeholder="请输入医师意见" />
					</view>
					<view class="footer-btn footer-btn-two" style="position: absolute;margin-bottom: 20upx;">
						<view class="btn btn-col"
							style="width:40%;margin-left:7%;margin-right: 6%;border-radius: 10upx;"
							@click="closeCirculation()">取消</view>
						<view class="btn btn-col1" style="width:40%;border-radius: 10upx" @click="submit(2)">确定</view>
					</view>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import {
		getDrugsApplyDetail,
		drugsApplyApproval
	} from '@/common/api.js';
	import {
		callbackRequest,
		alertTip,
		compare,
		vbPicture,
		getStorage,
		callPhone,
		formatImgUrl
	} from '@/common/util.js';
	import uniNumberBox from '@/components/uni-number-box/uni-number-box.vue';
	import tuiNumberbox from '@/components/numberbox/numberbox';
	import UniPopup from "@/components/uni-popup/uni-popup.vue"
	export default {
		components: {
			uniNumberBox,
			tuiNumberbox,
			UniPopup
		},
		data() {
			return {
				callPhone: callPhone,
				vbPicture: vbPicture,
				formatImgUrl: formatImgUrl,
				medicalList: [{
					name: '片剂'
				}, {
					name: '胶囊'
				}, {
					name: '颗粒'
				}, {
					name: '丸剂'
				}, {
					name: '口服液'
				}, {
					name: '乳膏'
				}, {
					name: '散剂'
				}, {
					name: '滴眼液'
				}, {
					name: '针剂'
				}, {
					name: '贴剂'
				}, {
					name: '喷剂'
				}, {
					name: '饮片'
				}], //{ name: '克' },{ name: '颗' },
				drugsUnitList: [{
					name: '盒'
				}, {
					name: '瓶'
				}, {
					name: '袋'
				}, {
					name: '支'
				}],
				currentClickIndex: 0,
				disable: true,
				id: 0,
				item: {},
				reason: '',
				userId: getStorage('userInfo').userId,
			};
		},
		onLoad(options) {
			this.id = options.id;
		},
		onShow() {
			this.getDrugsApplyDetail();
		},
		methods: {
			changeItem() {
				uni.navigateTo({
					url: `/pages/medical/drug-reserve-sl-detail?id=` + this.item.id
				});
			},
			bindTextAreaBlur: function(e) {
				console.log(e.detail.value)
			},
			circulation() {
				this.$refs.popup.open();
				//this.closeButPopup();
			},
			closeCirculation() {
				this.$refs.popup.close()
			},
			updY(index) {
				this.disable = false;
			},
			// 数字输入框
			unbChange(value, index) {
				this.item.detailList[index].drugs_num = value;
				console.log(this.item);
			},
			changeDosage(e, index) {
				//let cur = this;
				this.item.detailList[index].drugs_type = e.detail.value;
			},
			changeDrugsUnit(e, index) {
				this.item.detailList[index].drugs_unit = e.detail.value;
			},
			getDrugsApplyDetail() {
				let params = {
					method: getDrugsApplyDetail, // 申请的审批
					data: {
						id: this.id
					} //分三种情况
				};
				callbackRequest(params)
					.then(res => {
						if (res.data.returnCode == 1) {
							this.item = res.data.returnData[0];
						} else {
							alertTip(res.data.returnMsg);
						}
					})
			},

			submit(status) {
				var obj = this.item;
				let params = {
					method: drugsApplyApproval, // 申请的审批
					data: {
						id: obj.id,
						status: status,
						reason: this.reason,
						modifyBy: this.userId
					} //分三种情况
				};
				var self = this;
				if (status == 1) {
					uni.showModal({
						title: '提示',
						content: '是否确认通过',
						success: function(res) {
							if (res.confirm) {
								callbackRequest(params)
									.then(res => {
										alertTip(res.data.returnMsg);
										uni.redirectTo({
											url: `/pages/medical/drugsApproval`
										});
									})
							}
						}
					});
				} else {
					if (this.reason == '') {
						alertTip("请输入医师意见");
						return;
					} else {
						callbackRequest(params)
							.then(res => {
								alertTip(res.data.returnMsg);
								uni.redirectTo({
									url: `/pages/medical/drugsApproval`
								});
							})
					}
				}

			}
		}
	};
</script>

<style lang="scss">
	@import '@/static/css/common.scss';

	.batchBtn {
		position: absolute;
		height: 140upx;
		background: white;
		padding-top: 30upx;

		.btn1 {
			width: 40%;
			margin-left: 7%;
			margin-right: 6%;
			border-radius: 10upx;
		}

		.btn2 {
			width: 40%;
			border-radius: 10upx;
		}

		.btn3 {
			width: 28%;
			margin-left: 4%;
			border-radius: 10upx;
		}

		.btn4 {
			width: 28%;
			margin-left: 4%;
			border-radius: 10upx;
		}

		.btn5 {
			width: 28%;
			margin-left: 4%;
			border-radius: 10upx;
			background: #348CF2;
		}
	}

	.container {}

	.interviewee {
		padding: 0upx 24upx 0;
		background: #fff;
		margin: 24upx 24upx 0;
		border-radius: 20rpx;

		.input_left {
			width: 150rpx;
			color: #333333;
			font-size: 28rpx;
			font-weight: 400;
		}
	}

	.interviewee view {
		line-height: 40rpx;
		padding: 28rpx 0;
		font-size: 28upx;
		color: #555555;
		border-bottom: 1px solid #EBEFF7;
		display: flex;
		align-items: center;
		position: relative;
	}

	.interviewee view:last-child {
		border-bottom: 0px;
	}

	.interviewee view input {
		font-size: 28rpx;
		color: #999999;
		margin-left: 20rpx;
		width: 100%;
	}

	.visitor_2 view input {
		font-size: 28rpx;
		margin-left: 20rpx;
	}

	.visitor_2 view {
		line-height: 40rpx;
		padding: 20rpx 0;
		// color: #333333;
		font-size: 28rpx;
		border-bottom: 1px solid #eee;
		display: flex;
		align-items: center;
		position: relative;

		.comment-btn {
			font-size: 24upx;
			border-radius: 10upx;
			color: #fff;
			min-width: 100upx;
			height: 40upx;
			background-color: #2c8add;
			padding: 28upx 28upx;
			margin-left: auto;
		}
	}

	.visitor_2 {
		margin: 20rpx 30rpx 20rpx;
		background: #ffffff;
		border-radius: 10upx;
		padding: 30rpx 30rpx;

		.input_left {
			width: 150rpx;
			color: #333333;
			font-size: 28rpx;
			font-weight: bold;
		}

		.select {
			.arrow {
				float: right;
				width: 16upx;
				height: 29upx;
				margin-top: 10upx;
			}

			.picker {
				height: 50upx;
				line-height: 50upx;
				font-size: 26upx;
				color: #666;
			}
		}
	}

	.pic {
		padding-top: 20rpx;
	}

	.pic image {
		width: 180rpx;
		height: 180rpx;
		vertical-align: top;
		margin-right: 20rpx;
	}

	.form-box image {
		width: 180rpx;
		height: 180rpx;
		vertical-align: top;
		margin-right: 20rpx;
	}

	/* 已同意 */

	#result .ing {
		background: #ffffff;
		height: 2.2rem;
		line-height: 1.2rem;
		border-radius: 0.133333rem;
	}

	#result .ing i {
		width: 0.566667rem;
		height: 0.566667rem;
		border: 0.033333rem solid #00c277;
		display: inline-block;
		margin-left: 0.8rem;
		margin-right: 0.24rem;
		border-radius: 50%;
		margin-top: 0.9rem;
	}

	#result .ing text {
		color: #00c277;
		font-size: 0.745333rem;
	}

	.submit {
		width: 100%;
		position: fixed;
		bottom: 20upx;
		/* bottom: 0upx; */
		height: 80upx;
		display: inline;
		background-color: #00c277;
	}

	button {
		font-size: 38upx;
		font_weight: bold;
		height: 80upx;
	}

	.submit_button {
		width: 100%;
		color: #ffffff;
		background-color: #00c277;
		margin: 0;
	}

	.btn_refuse {
		width: 50%;
		color: #ffffff;
		background-color: red;
		margin: 0;
	}

	.btn_agree {
		width: 50%;
		color: #ffffff;
		background-color: #00c277;
		margin-left: 50%;
		margin-top: -80upx;
	}

	.form-box {
		padding: 20upx 30upx;
		background: #fff;
		margin: 28upx 28upx;
		border-radius: 10upx;

		.form-item {
			overflow: hidden;
			border-bottom: 1px solid #eee;
			padding: 20upx 0;

			.label {
				float: left;
				width: 150upx;
				font-size: 28upx;
				color: #333;
				font-weight: bold;
				line-height: 50upx;
			}

			input {
				font-size: 28upx;
			}

			.select {
				.arrow {
					float: right;
					width: 16upx;
					height: 29upx;
					margin-top: 10upx;
				}

				input {
					width: 70%;
				}
			}

			.tip-c {
				color: #929292;
				font-size: 25upx;
				margin-left: 20upx;
			}

			.jian {
				width: 50upx;
				height: 50upx;
				margin-left: 280upx;
			}

			.select {
				.arrow {
					float: right;
					width: 16upx;
					height: 29upx;
					margin-top: 10upx;
				}

				.picker {
					height: 50upx;
					line-height: 50upx;
					font-size: 26upx;
					color: #666;
				}
			}
		}

		.upload-box {
			.label {
				float: none;
			}

			.img-box {
				overflow: hidden;
				padding-top: 25upx;

				.img-item {
					float: left;
					width: 210upx;
					height: 210upx;
					border: 1px solid #ddd;
					margin: 0 20upx 20upx 0upx;
					position: relative;

					.img {
						display: block;
						width: 100%;
						height: 100%;
					}

					.remove-btn {
						position: absolute;
						top: -18upx;
						right: -18upx;
						width: 44upx;
						height: 44upx;
						z-index: 2;
					}
				}

				.upload-btn {
					.img {
						width: 60upx;
						height: 60upx;
						margin: 75upx auto 0;
					}
				}
			}
		}

		.sure-btn {
			width: 100%;
			height: 80upx;
			font-size: 28upx;
			color: #fff;
			text-align: center;
			line-height: 80upx;
			border-radius: 8upx;
			background: #0066cc;
			background: linear-gradient(to right, #ffc200, #ff9000);
			/*设置按钮为渐变颜色*/
			margin-top: 50upx;
		}
	}

	// .count-upd {
	// 	border-bottom: 1px solid #0055ff;

	// }
	.footer-btn {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-evenly;
		padding-top: unset;
	}

	.no-btn {
		width: 110*2upx;
		height: 44*2upx;
		background: #E0F6F5;
		border-radius: 22*2upx;
		font-size: 16*2upx;
		color: #00ADA6;
		line-height: 44*2upx;
		text-align: center;
	}

	.s-btn {
		width: 110*2upx;
		height: 44*2upx;
		background: linear-gradient(94deg, #5BCE9D 0%, #00ADA6 100%);
		border-radius: 22*2upx;
		font-size: 16*2upx;
		color: #FFFFFF;
		line-height: 44*2upx;
		text-align: center;
	}
</style>