<template>
	<view class="operaCheck" :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="operaCheck-content">
			<view class="checkComplete" v-if="title !== '屈光手术安全核查表'">
				<icon type="success" size="40" />
				<view class="checkComplete-text-one">核查完成</view>
				<view class="checkComplete-text-two">核查完成后请填写相应表单</view>
			</view>
			<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="operaCheck-form">
				<view class="form-nameAgeSure form">
					<text>姓名/性别/年龄/PID等正确:</text>
					<radio-group @change="radioChange('centerXm',$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.centerXm"
									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('centerSsfs',$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.centerSsfs"
									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('centerSsbwBs',$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.centerSsbwBs"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-Zlbdj form">
					<text>治疗绷带镜确认:</text>
					<radio-group @change="radioChange('centerZlbdj',$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.centerZlbdj"
									color="#1989FA" style="transform:scale(0.8)" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</radio-group>
				</view>
				<view class="form-doctor-father">
					<view class="form-doctor-father-text">手术医师陈述:</view>
					<view class="form-doctor form">
						<view>
							<view>是否需要相关检查资料</view>
							<view>(包括Pamtacan/OCT等检查)</view>
						</view>
						<radio-group @change="radioChange('centerYscsOrder',$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.centerYscsOrder"
										color="#1989FA" style="transform:scale(0.8)" />
								</view>
								<view>{{item.name}}</view>
							</label>
						</radio-group>
					</view>
					<checkbox-group @change="checkboxChange('centerYscsCheck',$event)">
						<label class="form-doctor-label" v-for="(item,index) in checkList" :key="index">
							<checkbox :value="item.name"
								:checked="formListValue.centerYscsCheck.indexOf(item.name)!=-1 ">{{item.name}}
							</checkbox>
						</label>
					</checkbox-group>
				</view>
				<view class="form-nurse-father">
					<view class="form-nurse-father-text">手术室护士陈述:</view>
					<view class="form-nurseMieJun form">
						<text>仪器设备物品灭菌合格:</text>
						<radio-group @change="radioChange('centerHscsMjhg',$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.centerHscsMjhg"
										color="#1989FA" style="transform:scale(0.8)" />
								</view>
								<view>{{item.name}}</view>
							</label>
						</radio-group>
					</view>
					<view class="form-nurseMedication form">
						<text>术前术中用药:</text>
						<radio-group @change="radioChange('centerHscsSqSzYy',$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.centerHscsSqSzYy"
										color="#1989FA" style="transform:scale(0.8)" />
								</view>
								<view>{{item.name}}</view>
							</label>
						</radio-group>
					</view>
					<view class="form-nurseOrderOther form">
						<text>其它:</text>
						<radio-group @change="radioChange('centerHscsQtOrder',$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.centerHscsQtOrder"
										color="#1989FA" style="transform:scale(0.8)" />
								</view>
								<view>{{item.name}}</view>
							</label>
						</radio-group>
					</view>
					<input v-if="formListValue.centerHscsQtOrder==='是'" type="text"
						:value="formListValue.centerHscsQtInput" placeholder="请输入内容"
						@input="inputHandle('centerHscsQtInput',$event)" />
				</view>
			</view>
			<view class="content-sign">
				<view class="operaDoctorSign operaSign">
					<text>手术医生签字:</text>
					<view class="sign" :style="{ background: formListValue.centerYsSign ? '#fff' : '#E8F5FF'}">
						<text class="sign-text" v-if="!formListValue.centerYsSign" @click="getYsSign">获取签字</text>
						<view class="image-father" v-if="formListValue.centerYsSign">
							<icon type="clear" size="14" class="image-clear" @click="imageClearClick('centerYsSign')" />
							<image v-if="formListValue.centerYsSign" mode="widthFix" :src="formListValue.centerYsSign"
								alt="" class="img-class">
						</view>
					</view>
				</view>
				<view class="zhuShouSign operaSign">
					<text>技师签字:</text>
					<view class="sign" :style="{ background: formListValue.centerJsSign ? '#fff' : '#E8F5FF'}">
						<text class="sign-text" v-if="!formListValue.centerJsSign"
							@click="geLoginSign('centerJsSign')">获取签字</text>
						<view class="image-father" v-if="formListValue.centerJsSign">
							<icon type="clear" size="14" class="image-clear" @click="imageClearClick('centerJsSign')" />
							<image v-if="formListValue.centerJsSign" mode="widthFix" :src="formListValue.centerJsSign"
								alt="" class="img-class">
						</view>
					</view>
				</view>
				<view class="nurseSign operaSign">
					<text>手术室护士签字:</text>
					<view class="sign" :style="{ background: formListValue.centerHsSign ? '#fff' : '#E8F5FF'}">
						<text class="sign-text" v-if="!formListValue.centerHsSign"
							@click="geLoginSign('centerHsSign')">获取签字</text>
						<view class="image-father" v-if="formListValue.centerHsSign">
							<icon type="clear" size="14" class="image-clear" @click="imageClearClick('centerHsSign')" />
							<image v-if="formListValue.centerHsSign" mode="widthFix" :src="formListValue.centerHsSign"
								alt="" class="img-class">
						</view>
					</view>
				</view>
			</view>
			<view class="form-time form">
				<text>时间:</text>
				<text style="color: #1c76fd;">{{formListValue.centerTime ? formListValue.centerTime : '空'}}</text>
			</view>
		</view>
		<view class="button-father" v-if="title !== '屈光手术安全核查表'">
			<view class="buttons buttonsOne" @click="jumpHandle">跳过</view>
			<view class="buttons buttonsTwo" @click="sureHandle">保存</view>
		</view>

	</view>
</template>

<script>
	import logout from '@/components/logout.vue'
	import Signature from '@/components/sin-signature/sin-signature.vue'
	export default {
		props: {
			title: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				formListValue: {
					formName:'屈光手术安全核查表',
					patientName:'',
					patientId:'',
					patientSex:'',
					patientAge:'',
					// 拟施手术名称
					nsOuOperaName: '',
					nsOdOperaName: '',
					nsOsOperaName: '',
					// 拟施手术别名
					nsOuOperaBieM: '',
					nsOdOperaBieM: '',
					nsOsOperaBieM: '',
					// 确认患者姓名
					centerXm: '是',
					// 手术方式
					centerSsfs: '是',
					// 手术部位与标识确认
					centerSsbwBs: '是',
					// 治疗绷带镜确认
					centerZlbdj: '是',
					// 手术医师陈述order
					centerYscsOrder: '是',
					// 手术医师陈述check
					centerYscsCheck: ['预计手术时间', '手术关注点'],
					// 护士陈述灭菌合格
					centerHscsMjhg: '是',
					// 护士陈述术前术中用药
					centerHscsSqSzYy: '是',
					// 护士陈述Order其他
					centerHscsQtOrder: '否',
					// 护士陈述input其他
					centerHscsQtInput: '',
					// 医生签字
					centerYsSign: '',
					// 技师签字
					centerJsSign: '',
					// 护士签字
					centerHsSign: '',
					// 时间
					centerTime: ''
				},
				radioList: [{
					name: '是',
				}, {
					name: '否',
				}],
				checkList: [{
					name: '预计手术时间',
				}, {
					name: '手术关注点',
				}],
				optionList: {}
			}
		},
		components: {
			Signature,
			logout
		},
		onLoad(options) {
			console.log('operaCheck', options);
			this.optionList = options
			// 获取表单保存信息
			this.getInfo()
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			init(options) {
				console.log('init-operaCheck', 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.getSafetyCheckCentreInfo, {
					operaId: this.optionList.operaId,
					patientIdNumber: this.optionList.patientIdNumber,
				})
				if (res.code === 0) {
					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);
						if (item.status === 3) {
							this.formListValue.centerTime = 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.centerYsSign = 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
			},
			// 删除登录签名
			imageClearClick(textOne) {
				this.formListValue[textOne] = ''
			}
		}
	}
</script>

<style lang="less" scoped>
	.operaCheck {
		background-color: #002648;
		width: 100vw;
		.patientinfo-father {
			background-color: #e8f5ff;
			padding: 10px;
		}
		.patientInfo {
			.patient-text {
				padding-right: 20rpx;
		
				text {
					font-weight: 700;
				}
			}
		}
		.operaCheck-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;
			align-items: center;

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

			.radio-group {
				display: flex;
				flex-wrap: wrap;
			}
		}

		.form-doctor-label {
			checkbox:nth-child(1) {
				margin-right: 20rpx;
			}
		}

		.form-riskWarn-father,
		.form-doctor-father,
		.form-nurse-father {
			border-bottom: 1rpx solid #F2F2F2;
			padding-bottom: 20rpx;
		}

		.form-other,
		.form-riskWarn,
		.form-doctor,
		.form-nurse {
			margin-bottom: 20rpx;
			border-bottom: none;
		}

		.form-doctor-father-text,
		.form-nurse-father-text {
			margin-top: 20rpx;
			font-weight: 700;
		}

		.form-nurse-father {
			.form {
				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">
	.operaCheck {
		.signature-wrap .img-wrap {
			min-height: 100% !important;
		}

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