<template>
	<view class="life">
		<uni-nav-bar dark :fixed="true" :border="false" background-color="#002648" status-bar left-icon="left"
			title="生命体征录入" @clickLeft="back">
		</uni-nav-bar>
		<view class="patientinfo-father">
			<view class="patientInfo flex-1">
				<text class="patient-text">
					<text>PID：</text>
					{{patientInfo.patientId ? patientInfo.patientId : '-'}}
				</text>
				<text class="patient-text">
					<text>姓名：</text>
					{{patientInfo.patientName ? patientInfo.patientName : '-'}}
				</text>
				<text class="patient-text">
					<text>性别：</text>
					{{patientInfo.patientSex ? patientInfo.patientSex : '-'}}
				</text>
			</view>
			<view class="patientInfo1 flex-2 margin-top-10">
				<text class="font-w">手术方式：</text>
				<view>
					<view v-for="(item,index) in patientInfo.operaTypeList" :key="index">
						<view v-show="item.eyeType==='OU' && item.operaEntityList.length>0">
							OU：<text v-for="(iten,i) in item.operaEntityList" :key="i">{{iten.bieMing}}</text>
						</view>
						<view v-show="item.eyeType==='OD' && item.operaEntityList.length>0">
							OD：<text v-for="(iten,i) in item.operaEntityList" :key="i">{{iten.bieMing}}</text>
						</view>
						<view v-show="item.eyeType==='OS' && item.operaEntityList.length>0">
							OS：<text v-for="(iten,i) in item.operaEntityList" :key="i">{{iten.bieMing}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="patientInfo2 flex-1 margin-top-10">
				<text class="patient-text">
					<text>主刀医生：</text>
					{{patientInfo.mainDoctorName ? patientInfo.mainDoctorName : '-'}}
				</text>
			</view>
		</view>
		<wuc-tab :tab-list="tabList" :tabCur.sync="TabCur" @change="tabChange"></wuc-tab>
		<view class="content">
			<view class="flex-2">
				<view class="form-tw form" v-if="TabCur===0">
					<text class="form-text">体温:</text>
					<view class="input-view tw">
						<input :value="formListValue.temperature" type="number" placeholder="体温"
							@input="inputHandle('temperature',$event)" @blur="blurInput('temperature',42,34,$event)" />
						<text class="text-dw">℃</text>
					</view>
				</view>
				<view class="form-xy form">
					<text class="form-text">血压:</text>
					<view class="input-view xy">
						<input class="xy-input" type="number" :value="formListValue.highBloodPressure" placeholder="高压"
							@input="inputHandle('highBloodPressure',$event)"
							@blur="blurInput('highBloodPressure',300,0,$event)" /> /
						<input class="xy-input" type="number" :value="formListValue.lowBloodPressure" placeholder="低压"
							@input="inputHandle('lowBloodPressure',$event)"
							@blur="blurInput('lowBloodPressure',150,0,$event)" />
						<text class="text-dw">mmHg</text>
					</view>
				</view>
			</view>
			<view class="flex-2">
				<view class="form-mb form">
					<text class="form-text">脉搏:</text>
					<view class="input-view mb">
						<input class="xia-input"  type="number" :value="formListValue.pulse" placeholder="脉搏"
							@input="inputHandle('pulse',$event)" @blur="blurInput('pulse',150,0,$event)" />
						<text class="text-dw">次/分</text>
					</view>
				</view>
				<view class="form-hx form">
					<text class="form-text">呼吸:</text>
					<view class="input-view hx">
						<input class="xia-input" type="number" :value="formListValue.breathe" placeholder="呼吸"
							@input="inputHandle('breathe',$event)" @blur="blurInput('breathe',60,0,$event)" />
						<text class="text-dw">次/分</text>
					</view>
				</view>
			</view>
			<view class="creatinfo margin-top-10">
				<view>操作人：{{formListValue.createName ? formListValue.createName : '-'}}</view>
				<view class="margin-top-10">操作时间：{{formListValue.createDate ? formListValue.createDate : '-'}}</view>
			</view>
		</view>
		<view class="buttons" @click="funsureStatus">保存</view>
	</view>
</template>

<script>
	import WucTab from '@/components/wuc-tab/wuc-tab.vue';
	export default {
		data() {
			return {
				tabList: [{
					name: '手术前'
				}, {
					name: '手术后'
				}],
				formListValue: {
					// 体温
					temperature: '',
					// 高压-血压
					highBloodPressure: '',
					// 低压-血压
					lowBloodPressure: '',
					// 脉搏
					pulse: '',
					// 呼吸
					breathe: '',
					// 手术id
					operaPatientId: '',
					// 类型1:术前，2:术后
					type: 1,
				},
				typeList: [{
					name: '手术前'
				}, {
					name: '手术后'
				}],
				TabCur: 0,
				paramsList: {},
				patientInfo: {},
				status: true
			}
		},
		components: {
			WucTab
		},
		onLoad(options) {
			console.log(options);
			this.formListValue.operaPatientId = options.operaId
			this.paramsList = options
			this.getLife()
			this.getPatientInfo()
		},
		methods: {
			tabChange(index) {
				console.log(index);
				this.TabCur = index;
				this.formListValue.type = index + 1;
				this.getLife(this.formListValue.type)
			},
			// 获取患者信息
			async getPatientInfo() {
				// 0:等待呼叫，1:呼叫中，2:术前准备，3:手术中，4、手术完成
				const res = await this.$baseAPI.request(`${this.$portAdress.pda}/${this.paramsList.patientId}`)
				if (res.code === 0) {
					this.patientInfo = res.data
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			},
			// 获取生命体征
			async getLife(type) {
				const res = await this.$baseAPI.request(this.$portAdress.getLife, {
					operaPatientId: this.formListValue.operaPatientId,
					// 1:术前，2:术后
					type: this.formListValue.type,
				})
				if (res.code === 0) {
					// 如果生命体征获取过来有值,相当于修改,不更新状态,如果生命体征返回null,说明没录入过,需要更新状态
					this.status = res.data.status
					this.formListValue = res.data.data ? res.data.data : {
						// 体温
						temperature: '',
						// 高压-血压
						highBloodPressure: '',
						// 低压-血压
						lowBloodPressure: '',
						// 脉搏
						pulse: '',
						// 呼吸
						breathe: '',
						// 手术id
						operaPatientId: this.paramsList.operaId,
						// 类型 1:术前，2:术后
						type: type ? type : 1,
					}

				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 输入框改变时
			inputHandle(text, val) {
				this.formListValue[text] = val.target.value
			},
			// 失去焦点时
			blurInput(text, upNumber, downNunber, e) {
				const value = Number(e.target.value)
				if (value >= upNumber) {
					uni.showToast({
						title: `此项最高上限必须小于${upNumber}，请您从新输入`,
						icon: 'none'
					})
					this.formListValue[text] = ''
				}
				if (value <= downNunber) {
					uni.showToast({
						title: `此项最低下限必须大于${downNunber}，请您从新输入`,
						icon: 'none'
					})
					this.formListValue[text] = ''
				}
			},
			// sureStartHandle() {
			// 	// 0:等待呼叫，1:呼叫中，2:术前准备，3:手术中，4、手术完成
			// 	if (this.TabCur == 0) {
			// 		if (this.status <= 2) {
			// 			this.funsureStatus()
			// 		} else {
			// 			uni.showToast({
			// 				title: '暂时不能保存，请按照顺序操作',
			// 				icon: 'none'
			// 			})
			// 		}
			// 	} else if (this.TabCur == 1) {
			// 		if (this.status >= 4) {
			// 			this.funsureStatus()
			// 		} else {
			// 			uni.showToast({
			// 				title: '暂时不能保存，请按照顺序操作',
			// 				icon: 'none'
			// 			})
			// 		}
			// 	}

			// },
			async funsureStatus() {
				let userInfo = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : ''
				let formListValue1 = JSON.parse(JSON.stringify(this.formListValue))
				formListValue1.createName ? '' : formListValue1.createName = userInfo.realName
				formListValue1.createCode ? '' : formListValue1.createCode = userInfo.employeeId
				const res = await this.$baseAPI.request(this.$portAdress.saveInfo, formListValue1, 'post')
				if (res.code === 0) {
					uni.redirectTo({
						url: '/pages/patientList/index'
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.life {
		.content {
			padding: 20rpx;
		}
		.patientinfo-father {
			background-color: #e8f5ff;
			padding: 10px;
			margin: 10px;
		}
		.patientInfo,.patientInfo1,.patientInfo2 {
			.patient-text {
				padding-right: 20rpx;

				text {
					font-weight: 700;
				}
			}
		}
		.form-tw,.form-mb {
			margin-right: 20rpx;
		}
		.form {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1rpx solid #F2F2F2;

			.form-text {
				display: inline-block;
				width: 90rpx;
			}

			input {
				text-align: right;
				padding-right: 14rpx;
				width: 105rpx;
			}

			.uni-list-cell {
				display: flex;
				align-items: center;
				margin-left: 32rpx;
			}

			.xia-input {
				width: 140rpx;
			}

			.tw,
			.xy,
			.mb,
			.hx {
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		}

		.buttons {
			width: 90%;
			height: 88rpx;
			line-height: 88rpx;
			background-color: #1e79ff;
			color: #fff;
			text-align: center;
			position: fixed;
			bottom: 30rpx;
			left: 50%;
			border-radius: 20rpx;
			transform: translateX(-50%);
		}
	}
</style>
