<template>
	<view class="operaBefore" :style="{background:title !== '屈光手术安全核查表' ? '#002648' : '#fff'}">
		<template v-if="title !== '屈光手术安全核查表'">
			<uni-nav-bar dark :fixed="true" :border="false" background-color="#002648" status-bar left-icon="left"
				title="麻醉实施前" @clickLeft="back">
			</uni-nav-bar>
		</template>
		<view class="operaBefore-content">
			<template v-if="title !== '屈光手术安全核查表'">
				<view class="checkComplete">
					<icon type="success" size="40" />
					<view class="checkComplete-text-one">核查完成</view>
					<view class="checkComplete-text-two">核查完成后请填写相应表单</view>
				</view>
			</template>
			<view class="patientinfo-father">
				<view class="patientInfo flex-1">
					<text class="patient-text">
						<text>PID：</text>
						{{formListValue.patientId ? formListValue.patientId : '-'}}
					</text>
					<text class="patient-text">
						<text>姓名：</text>
						{{formListValue.patientName ? formListValue.patientName : '-'}}
					</text>
					<text class="patient-text">
						<text>性别：</text>
						{{formListValue.patientSex ? formListValue.patientSex : '-'}}
					</text>
				</view>
				<view class="patientInfo flex-2 margin-top-10 ">
					<text class="font-w">手术方式：</text>
					<view>
						<view v-show="formListValue.nsOuOperaBieM">OU：{{formListValue.nsOuOperaBieM}}</view>
						<view v-show="formListValue.nsOdOperaBieM">OD：{{formListValue.nsOdOperaBieM}}</view>
						<view v-show="formListValue.nsOsOperaBieM">OS：{{formListValue.nsOsOperaBieM}}</view>
					</view>
				</view>
			</view>
			<view class="operaBefore-form">
				<view class="form-nameAgeSure form">
					<text>姓名/性别/年龄/PID等正确:</text>
					<radio-group @change="radioChange('beforeXm',$event)" class="radio-group">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList" :key="index">
							<view>
								<radio :value="item.name" :checked="item.name === formListValue.beforeXm"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-surgicalMethod form">
					<text>手术方式确认:</text>
					<radio-group @change="radioChange('beforeSsfs',$event)" class="radio-group">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList" :key="index">
							<view>
								<radio :value="item.name" :checked="item.name === formListValue.beforeSsfs"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-positionBS form">
					<text>手术部位与标识正确:</text>
					<radio-group @change="radioChange('beforeSsbwBs',$event)" class="radio-group">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList" :key="index">
							<view>
								<radio :value="item.name" :checked="item.name === formListValue.beforeSsbwBs"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-informedConsent form">
					<text>手术知情同意:</text>
					<radio-group @change="radioChange('beforeSszqty',$event)" class="radio-group">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList" :key="index">
							<view>
								<radio :value="item.name" :checked="item.name === formListValue.beforeSszqty"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-skinComplete form">
					<text>皮肤是否完整:</text>
					<radio-group @change="radioChange('beforePfsfwc',$event)" class="radio-group">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList" :key="index">
							<view>
								<radio :value="item.name" :checked="item.name === formListValue.beforePfsfwc"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-SySkinReadySure form">
					<text>术野皮肤准备正确:</text>
					<radio-group @change="radioChange('beforeSypfzb',$event)" class="radio-group">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList" :key="index">
							<view>
								<radio :value="item.name" :checked="item.name === formListValue.beforeSypfzb"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-other-father">
					<view class="form-other form">
						<text>患者是否有过敏史:</text>
						<radio-group @change="radioChange('beforeSfgm',$event)" class="radio-group">
							<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList"
								:key="index">
								<view>
									<radio :value="item.name" :checked="item.name === formListValue.beforeSfgm"
										color="#1989FA" style="transform:scale(0.8)" />
								</view>
								<view>{{item.name}}</view>
							</label>
						</radio-group>
					</view>
					<view v-if="formListValue.beforeSfgm==='是'">
						<checkbox-group @change="checkboxChange('beforeSfgmCheck',$event)">
							<label class="form-doctor-label" v-for="(item,index) in gmsList" :key="index">
								<checkbox :value="item.name" class="gmcheck"
									:checked="formListValue.beforeSfgmCheck.indexOf(item.name)!=-1 ">{{item.name}}
								</checkbox>
							</label>
						</checkbox-group>
						<input class="gminput" type="text" :value="formListValue.beforeSfgmInput"
							placeholder="请输内容" @input="inputHandle('beforeSfgmInput',$event)" />
					</view>
				</view>
				<view class="form-Zlbdj form">
					<text>治疗绷带镜确认:</text>
					<radio-group @change="radioChange('beforeZlbdj',$event)" class="radio-group">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList" :key="index">
							<view>
								<radio :value="item.name" :checked="item.name === formListValue.beforeZlbdj"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-other-father">
					<view class="form-other form">
						<text>其它</text>
						<radio-group @change="radioChange('beforeQtOrder',$event)" class="radio-group">
							<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in radioList"
								:key="index">
								<view>
									<radio :value="item.name" :checked="item.name === formListValue.beforeQtOrder"
										color="#1989FA" style="transform:scale(0.8)" />
								</view>
								<view>{{item.name}}</view>
							</label>
						</radio-group>
					</view>
					<input v-if="formListValue.beforeQtOrder==='是'" type="text" :value="formListValue.beforeQtInput"
						placeholder="请输内容" @input="inputHandle('beforeQtInput',$event)" />
				</view>
			</view>
			<view class="content-sign">
				<view class="operaDoctorSign operaSign">
					<text>手术医生签字:</text>
					<view class="sign" :style="{ background: formListValue.beforeYsSign ? '#fff' : '#E8F5FF'}">
						<text class="sign-text" v-if="!formListValue.beforeYsSign" @click="getYsSign">获取签字</text>
						<view class="image-father" v-if="formListValue.beforeYsSign">
							<icon type="clear" size="14" class="image-clear" @click="imageClearClick('beforeYsSign')" />
							<img v-if="formListValue.beforeYsSign" mode="widthFix" :src="formListValue.beforeYsSign"
								alt="" class="img-class">
						</view>
					</view>
				</view>
				<view class="zhuShouSign operaSign">
					<text>技师签字:</text>
					<view class="sign" :style="{ background: formListValue.beforeJsSign ? '#fff' : '#E8F5FF'}">
						<text class="sign-text" v-if="!formListValue.beforeJsSign"
							@click="geLoginSign('beforeJsSign')">获取签字</text>
						<view class="image-father" v-if="formListValue.beforeJsSign">
							<icon type="clear" size="14" class="image-clear" @click="imageClearClick('beforeJsSign')" />
							<image v-if="formListValue.beforeJsSign" mode="widthFix" :src="formListValue.beforeJsSign"
								alt="" class="img-class">
						</view>
					</view>
				</view>
				<view class="nurseSign operaSign">
					<text>手术室护士签字:</text>
					<view class="sign" :style="{ background: formListValue.beforeHsSign ? '#fff' : '#E8F5FF'}">
						<text class="sign-text" v-if="!formListValue.beforeHsSign"
							@click="geLoginSign('beforeHsSign')">获取签字</text>
						<view class="image-father" v-if="formListValue.beforeHsSign">
							<icon type="clear" size="14" class="image-clear" @click="imageClearClick('beforeHsSign')" />
							<image v-if="formListValue.beforeHsSign" mode="widthFix" :src="formListValue.beforeHsSign"
								alt="" class="img-class">
						</view>
					</view>
				</view>
			</view>
			<view class="form-time form">
				<text>时间:</text>
				<text style="color: #1c76fd;">{{formListValue.beforeTime ? formListValue.beforeTime : '空'}}</text>
			</view>
		</view>
		<template v-if="title !== '屈光手术安全核查表'">
			<view class="button-father">
				<view class="buttons buttonsOne" @click="jumpHandle">跳过</view>
				<view class="buttons buttonsTwo" @click="sureHandle">保存</view>
			</view>
		</template>
	</view>
</template>

<script>
	import Signature from '@/components/sin-signature/sin-signature.vue'
	import {
		formatDate
	} from '@/utils/util.js'
	export default {
		data() {
			return {
				formListValue: {
					formName: '屈光手术安全核查表',
					patientName: '',
					patientId: '',
					patientSex: '',
					patientAge: '',
					// 拟施手术名称
					nsOuOperaName: '',
					nsOdOperaName: '',
					nsOsOperaName: '',
					// 拟施手术别名
					nsOuOperaBieM: '',
					nsOdOperaBieM: '',
					nsOsOperaBieM: '',
					// 确认患者姓名
					beforeXm: '是',
					// 手术方式
					beforeSsfs: '是',
					// 手术部位与标识确认
					beforeSsbwBs: '是',
					// 手术知情同意
					beforeSszqty: '是',
					// 皮肤是否完整
					beforePfsfwc: '是',
					// 术野皮肤准备正确
					beforeSypfzb: '是',
					// 患者是否有过敏史
					beforeSfgm: '否',
					beforeSfgmCheck:[],
					beforeSfgmInput: '',
					// 治疗绷带镜确认
					beforeZlbdj: '是',
					// 其他单选
					beforeQtOrder: '否',
					// 其他输入
					beforeQtInput: '',
					// 医生签字
					beforeYsSign: '',
					// 技师签字
					beforeJsSign: '',
					// 护士签字
					beforeHsSign: '',
					// 时间
					beforeTime: ''
				},
				radioList: [{
					name: '是',
				}, {
					name: '否',
				}],
				gmsList:[{
					name:'青霉素'
				},{
					name:'头孢'
				},{
					name:'破伤风'
				},{
					name:'酒精'
				},{
					name:'碘'
				}],
				optionList: {},
				openFormSaveDate:''
			}
		},
		props: {
			title: {
				type: String,
				default: ''
			}
		},
		components: {
			Signature
		},
		onLoad(options) {
			console.log('operaBefore', options);
			this.optionList = options
			// 获取表单保存信息
			this.getInfo()
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			init(options) {
				console.log('init-operaBefore', options);
				this.optionList = options
				// 获取表单保存信息
				this.getInfo()
			},
			// 单选框改变时
			radioChange(text, val) {
				this.formListValue[text] = val.target.value
			},
			checkboxChange(text, val) {
				this.formListValue[text] = val.target.value
			},
			// 输入框改变时
			inputHandle(text, val) {
				this.formListValue[text] = val.target.value
			},
			// 跳过
			jumpHandle() {
				uni.navigateTo({
					url: '/pages/patientList/index'
				})
			},
			// 获取表单信息
			async getInfo() {
				const res = await this.$baseAPI.request(this.$portAdress.getSafetyCheckBeforeInfo, {
					operaId: this.optionList.operaId,
					patientIdNumber: this.optionList.patientIdNumber,
				})
				if (res.code === 0) {
					this.openFormSaveDate = res.data.createDate
					Object.keys(res.data).forEach((item) => {
						// console.log(res.data)
						// 如果data中没有定义这个字段，就自动加进去
						this.formListValue[item] || typeof this.formListValue[item] == 'boolean' ? '' : this
							.formListValue[item] = ''
						// 如果不为空就赋值上去
						if ((res.data[item] && res.data[item] !== 'false' && res.data[item] !== 'true') ||
							typeof res.data[item] === 'number') {
							this.formListValue[item] = res.data[item]
						}
						if (res.data[item] && typeof res.data[item] !== 'number') {
							res.data[item].includes('[') || res.data[item] === 'false' || res.data[item] ===
								'true' ? this.formListValue[item] = JSON.parse(res.data[item]) : ''
						}
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
				setTimeout(() => {
					// 获取手术状态时间
					this.getOperaStatusTime()
				}, 500)
			},
			// 获取手术状态时间
			async getOperaStatusTime() {
				const res = await this.$baseAPI.request(this.$portAdress.getOperaStatusTime, {
					operaId: this.optionList.operaId,
				})
				if (res.code === 0) {
					res.data.forEach(item => {
						console.log('时间', item);
						// 0:等待呼叫，1:呼叫中，2:术前准备，3:手术中，4、手术完成
						if (item.status === 3) {
							this.formListValue.beforeTime = item.signDate
						}
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			},
			// 获取主刀医生签字
			async getYsSign() {
				const res = await this.$baseAPI.request(this.$portAdress.getMainDoctorSign, {
					operaPatientId: this.optionList.operaId
				})
				if (res.code === 0) {
					this.formListValue.beforeYsSign = res.data.signImgBase
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			// 获取登录签名
			geLoginSign(text) {
				let userInfo = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : ''
				console.log(userInfo);
				this.formListValue[text] = userInfo.signImgBase
				console.log(this.formListValue[text]);
			},
			// 删除登录签名
			imageClearClick(textOne) {
				this.formListValue[textOne] = ''
			}
		}
	}
</script>

<style lang="less" scoped>
	.operaBefore {
		background-color: #002648;
		width: 100vw;
		.patientinfo-father {
			background-color: #e8f5ff;
			padding: 10px;
		}
		.patientInfo {
			.patient-text {
				padding-right: 20rpx;

				text {
					font-weight: 700;
				}
			}
		}

		.operaBefore-content {
			background-color: #fff;
			border-top-left-radius: 40rpx;
			border-top-right-radius: 40rpx;
			padding: 0 30rpx;
		}

		.checkComplete {
			text-align: center;
			padding: 50rpx 0;

			.checkComplete-text-one {
				font-weight: 700;
				margin-top: 20rpx;
				font-size: 36rpx;
			}

			.checkComplete-text-two {
				padding: 20rpx 0;
				color: #999999;
				font-size: 34rpx;
			}
		}

		.form {
			padding: 20rpx 0;
			background-color: #fff;
			border-bottom: 1rpx solid #F2F2F2;
			display: flex;
			justify-content: space-between;

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

			.radio-group {
				display: flex;
				flex-wrap: wrap;
			}
		}
		.gminput {
			margin-top:20rpx;
		}
		.form-other-father {
			border-bottom: 1rpx solid #F2F2F2;
		}

		.form-other {
			margin-bottom: 20rpx;
			border-bottom: none;
		}

		.content-sign {
			background-color: #fff;

			.img-class {
				width: 80px;
			}

			.operaSign {
				padding: 20rpx 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 1rpx solid #F2F2F2;
			}

			.sign {
				color: #aeb8bf;
				font-size: 48rpx;
				width: 240rpx;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				border: 1px dashed #6EB1FF;
				border-radius: 12px;
				position: relative;
			}

			.image-father {
				.image-clear {
					position: absolute;
					right: 4px;
					top: -2px;
				}
			}

			.sign-text,
			.signature {
				position: absolute;
				left: 0;
				bottom: 0;
				width: 240rpx;
				height: 96rpx;
				text-align: center;
			}
		}

		.button-father {
			background-color: #fff;
			display: flex;
			padding: 50rpx 0;
		}

		.buttonsOne {
			background-color: #fff;
			color: #4f4f4f;
			border: 1px solid #e7e7e7;
		}

		.buttonsTwo {
			background-color: #1c76fd;
			border: 1px solid #1c76fd;
			color: #fff;
		}

		.buttons {
			width: 45%;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			margin: 0 auto;
			border-radius: 12rpx;
		}
	}
</style>
<style lang="less">
	.operaBefore {
		.signature-wrap .img-wrap {
			min-height: 100% !important;
		}

		.signature-wrap .img-wrap,
		.signature-wrap .img-wrap image {
			width: 240rpx;
			height: 96rpx;
		}
		.gmcheck{
			margin-right: 12rpx;
			margin-bottom:12rpx;
		}
	}
</style>
