<template>
	<div class="ptint-reserve">
		<select-patient-date :show-code="false"
												 :days="0"
												 :show-navbar="false"
												 :show-date="false"></select-patient-date>
		<div style="margin: 5px;">
			<van-form ref="formRef"
								error-message-align="right">
				<van-cell-group title=""
												insert>
					<van-field v-model="form.zyNum"
										 label="住院号"
										 is-link
										 readonly
										 required
										 placeholder="点击选择住院记录"
										 @click="state.ispShow = true"
										 :rules="[{required: true, message: '请选择住院记录', trigger: 'onSubmit'}]"></van-field>
					<van-field v-model="form.diagnose"
										 label="诊断"
										 readonly
										 :placeholder="form.zyNum? '': '选择住院记录'"></van-field>
					<van-field v-model="form.applyName"
										 label="病人姓名"
										 readonly
										 required
										 placeholder="选择住院记录"></van-field>
					<van-field v-model="form.deptName"
										 label="出院科室"
										 required
										 placeholder="选择住院记录"></van-field>
					<van-field v-model="form.showCardNo"
										 required
										 readonly
										 label="身份证"
										 placeholder="身份证号"
										 :rules="[{required: true, message: '请输入身份证号', trigger: 'onSubmit'}]"></van-field>
					<van-field v-model="form.phone"
										 type="tel"
										 required
										 label="联系电话"
										 placeholder="联系电话"
										 :rules="[{required: true, message: '请输入联系电话', trigger: 'onSubmit'}]"></van-field>
					<van-field v-model="form.useWay"
										 readonly
										 required
										 is-link
										 label="用途"
										 placeholder="点击选择翻拍用途"
										 @click="state.templateShow = true"></van-field>
				</van-cell-group>
				<van-cell-group title=""
												insert
												style="margin-top: 5px;">
					<div class="img_item">
						<div class="img_item_label">
							<section>
								<span style="color: red;">*</span>本人身份证正面照片
							</section>
						</div>
						<div class="img_item_upload">
							<van-uploader v-model="state.img.idCardFront"
														style="width: 100%;height: 100%;"
														:max-count="1"
														:before-read="onBeforeRead"
														:after-read="(file) => afterRead(file, 'idCardFront')">
								<div style="height: 100%;display: flex;flex-direction: column;align-items: center;justify-content: center;">
									<svg t="1685244688694"
											 class="icon"
											 viewBox="0 0 1507 1024"
											 version="1.1"
											 xmlns="http://www.w3.org/2000/svg"
											 p-id="5693"
											 width="64"
											 height="64">
										<path d="M1404.827485 1023.962307v-19.562798h83.245546v-82.77438H1507.730061v102.337178h-102.902576zM1488.073031 19.638184H1404.827485V0.075387H1507.730061V102.337178h-19.65703V19.638184z m-73.363632 61.86719a55.829988 55.829988 0 0 1 16.597595 39.841767v768.533988c-0.012564 31.084368-25.361276 56.288589-56.640393 56.313718H123.483092c-31.272834-0.043975-56.608982-25.235632-56.640393-56.313718V121.347141c0.043975-31.071804 25.380123-56.244613 56.640393-56.282307h1251.208638c15.071018 0 29.281374 5.82989 40.017669 16.44054z m-39.986258 8.4747H123.483092v0.018846c-17.426847 0.018847-31.549252 14.053301-31.568098 31.37335v768.533988c0 17.288638 14.16638 31.398479 31.568098 31.398478h1251.183509c17.401718 0 31.593227-14.084712 31.593227-31.398478V121.347141c0-8.374184-3.285595-16.27092-9.247411-22.201325a32.026699 32.026699 0 0 0-22.289276-9.165742z m-462.326577 647.431852c1.030282-49.158282 10.133202-133.050896 59.354307-175.73222l67.766184 0.615656 63.462871 104.058503 11.961326-77.811436-8.650602-14.10984 0.647068-14.499337a280.846135 280.846135 0 0 1 37.712098 0.050257l0.703607 14.499338-8.625472 14.103558 12.011583 78.439656 49.290208-105.226994 74.965595-2.538012c38.74238 36.405399 63.588515 122.188957 57.494773 178.150871h-418.093546z m315.216099-288.680049c-5.163975 18.337767-11.201178 35.331141-19.85178 49.57919-9.881914 16.446822-22.948908 29.09919-41.418601 35.909105-8.254822 2.965202-29.337914 4.384982-49.623165 4.033178-19.556515-0.245006-39.213546-2.186209-47.034896-5.779632-16.798626-7.65173-28.609178-20.580515-37.511068-36.650405-7.670577-13.732908-13.110969-29.727411-17.904294-46.62027-7.846479-4.083436-13.73919-11.03784-17.728393-20.530258-4.334724-10.315387-6.31362-23.872393-6.062331-39.942282l0.075386-5.484368 4.586013-3.040589c1.155926-0.772712 2.330699-1.520294 3.511754-2.186209-5.163975-63.142479-3.210209-86.487166 20.385767-113.173987 46.004613-37.429399 151.464049-36.103853 198.046626-2.173644 31.744 29.802798 33.949055 63.192736 24.199067 114.719411 1.526577 0.873227 3.028025 1.796712 4.560884 2.814429l4.586012 3.065718 0.05654 5.459239c0.270135 15.743215-1.633374 29.080344-5.792196 39.370601-3.838429 9.391902-9.479853 16.396564-17.081325 20.630773z m-0.571681-54.718037a14.329718 14.329718 0 0 0-5.440393-0.822969l-9.354209 0.59681-1.727607-9.146896a119.035288 119.035288 0 0 0-9.706012-29.652024c-29.834209 5.811043-74.186601 10.89335-109.241325-8.738552-13.513031-7.551215-33.25173 7.921865-49.440982 6.326184a121.623558 121.623558 0 0 0-10.931043 32.064392l-1.809276 9.492417-9.580368-0.917202a14.612417 14.612417 0 0 0-5.584884 0.672196 26.385276 26.385276 0 0 0-2.58827 1.024c0.22616 10.510135 1.702479 19.204712 4.466651 25.738209 2.406086 5.729374 5.741939 9.44216 10.108073 10.811681l5.610013 1.746454 1.551705 5.60373c4.717939 17.269791 9.932172 33.641227 17.357743 46.915534 6.866454 12.313129 15.667828 22.151067 27.773644 27.685693 5.12 2.336982 21.416049 3.637399 38.440834 3.888687 18.099043 0.251288 36.128982-0.672196 42.09708-2.870969 13.412515-4.906405 23.093399-14.44908 30.588073-26.9067 8.02238-13.381104 13.764319-30.374479 18.802651-49.013791l1.457472-5.352442 5.314749-1.846969c4.20908-1.470037 7.494675-5.308466 9.875632-11.088098 2.607117-6.426699 4.03946-15.001914 4.315877-25.28589a16.06989 16.06989 0 0 0-2.355828-0.923485zM332.642945 457.049521h288.887362v49.309056H332.642945v-49.309056z m0-122.741791h288.887362v49.315337H332.642945v-49.315337z m0-122.735509h288.887362v49.309055H332.642945v-49.309055zM201.41389 457.049521h95.929325v49.309056h-95.929325v-49.309056z m0-122.741791h95.929325v49.315337h-95.929325v-49.315337z m0-122.735509h95.929325v49.309055h-95.929325v-49.309055z m254.712147 615.863754H201.41389v-49.334184h254.712147v49.334184z m464.248932 0H485.909988v-49.334184h434.464981v49.334184zM19.68216 102.337178H0V0.075387h102.927706v19.562797H19.68216V102.337178z m0 902.062331h83.245546v19.562798H0v-102.337178h19.68216v82.77438z"
													p-id="5694"
													fill="#dcdfe6"></path>
									</svg>
									<span>点击选择照片或拍照</span>
								</div>
							</van-uploader>
						</div>
						<div v-if="state.imgBlankError.idCardFront"
								 class="img__blank_error">请上传本人身份证正面照片</div>
					</div>

					<div class="img_item">
						<div class="img_item_label">
							<section>
								<span style="color: red;">*</span>本人身份证背面照片
							</section>
						</div>
						<div class="img_item_upload">
							<van-uploader v-model="state.img.idCardBack"
														style="width: 100%;height: 100%;"
														:max-count="1"
														:after-read="(file) => afterRead(file, 'idCardBack')">
								<div style="height: 100%;display: flex;flex-direction: column;align-items: center;justify-content: center;">
									<svg t="1685244916978"
											 class="icon"
											 viewBox="0 0 1499 1024"
											 version="1.1"
											 xmlns="http://www.w3.org/2000/svg"
											 p-id="9485"
											 width="64"
											 height="64">
										<path d="M1396.224 1024v-19.456h82.432V921.6h19.456v102.4h-101.888zM1479.168 19.456h-82.432V0h102.4v102.4H1479.68V19.456zM1405.952 81.92c10.24 10.24 16.384 24.576 16.384 39.424v769.024c0 30.72-25.088 55.808-55.808 55.808H122.88c-30.72 0-55.808-25.088-55.808-55.808V121.344c0-30.72 25.088-55.808 55.808-55.808h1243.648c14.336 0 28.672 5.632 39.424 16.384z m-39.424 7.168H122.88c-17.408 0-31.744 14.336-31.744 31.744v768.512c0 17.408 14.336 31.744 31.744 31.744h1243.648c16.384 0 30.208-12.8 31.744-29.184V121.344c0-8.192-3.584-16.384-9.216-22.528-6.144-6.144-14.336-9.728-22.528-9.728zM465.92 677.888h737.28v49.152H465.92v-49.152z m143.36-253.952h593.408v49.152H609.28v-49.152z m0-122.88h593.408v49.152H609.28v-49.152z m0-123.904h593.408v49.152H609.28v-49.152zM485.376 423.936h95.232v49.152H485.376v-49.152z m0-122.88h95.232v49.152H485.376v-49.152z m0-122.88h95.232v49.152H485.376v-49.152zM384 409.6l20.48 38.4c-9.216-6.656-20.992-8.192-31.232-3.584-10.752 7.168-18.944 17.92-23.04 30.72l-16.384-25.088v12.8h-107.52v-12.8l-14.848 25.088c-4.096-12.288-12.288-23.04-23.04-30.72-15.36-8.192-31.744 6.656-31.744 6.656l22.016-41.472c-49.152-54.784-46.08-138.752 7.168-189.44 53.248-51.2 137.216-51.2 190.464 0 53.248 51.2 56.32 134.656 7.168 189.44 0-1.024 0.512 0 0.512 0zM216.064 282.624l-3.584-9.728-5.12 8.704h-8.192l7.68 6.656v9.728l8.192-5.12 8.192 5.12-4.608-8.704 7.68-6.656h-10.24z m-2.048 117.76h140.8l-14.336-22.528h-112.64c0 0.512-13.824 22.528-13.824 22.528z m93.696-22.528l-4.608-14.848h-39.424l-5.12 14.848h49.152zM238.592 308.224l7.68 6.656v9.728l8.192-5.12 8.192 5.12-4.608-8.704 8.192-6.656h-10.752l-3.584-11.264-3.584 10.24h-9.728z m51.2-53.248L281.6 233.984l-8.192 20.992H250.88l16.896 14.848-5.12 22.528 18.944-12.288 18.944 12.288-5.12-22.528 16.896-14.848h-22.528z m35.328 54.784l-4.096-11.264-3.584 10.24h-10.24l7.68 6.656v9.728l8.192-5.12 8.192 5.12-6.656-8.704 7.68-6.656h-7.168z m31.744-32.256l-3.584-10.24-3.584 9.728h-10.24l7.68 6.656v9.728l8.192-5.12 8.192 5.12-4.608-9.728 7.68-6.656c0.512 0.512-9.728 0.512-9.728 0.512zM417.28 727.04H200.192v-49.152h217.088v49.152z m0 96.768H200.192v-49.152h217.088v49.152z m785.408 0H465.92v-49.152h736.768v49.152zM19.456 102.4H0V0h102.4v19.456H19.456V102.4z m0 902.144H102.4v19.456H0v-102.4h19.456v82.944z"
													p-id="9486"
													fill="#dcdfe6"></path>
									</svg>
									<span>点击选择照片或拍照</span>
								</div>
							</van-uploader>
						</div>
						<div v-if="state.imgBlankError.idCardBack"
								 class="img__blank_error">请上传本人身份证背面照片</div>
					</div>

					<div class="img_item">
						<div class="img_item_label">
							<section style="width: 60px;">
								<span style="color: red;">*</span>住院证
							</section>
						</div>
						<div class="img_item_upload">
							<van-uploader v-model="state.img.inHospProve"
														style="width: 100%;height: 100%;"
														:max-count="1"
														:after-read="(file) => afterRead(file, 'inHospProve')">
								<div style="height: 100%; display: flex;flex-direction: column;align-items: center;justify-content: center;">
									<svg t="1692324646345"
											 class="icon"
											 viewBox="0 0 1024 1024"
											 version="1.1"
											 xmlns="http://www.w3.org/2000/svg"
											 p-id="3545"
											 id="mx_n_1692324646346"
											 width="64"
											 height="64">
										<path d="M950.8864 146.3296c21.2992 0 38.8096 6.8608 52.5312 20.5824C1017.1392 180.5312 1024 198.0416 1024 219.4432l0 585.1136c0 21.4016-6.8608 38.8096-20.5824 52.5312C989.696 870.8096 972.1856 877.6704 950.8864 877.6704L73.1136 877.6704c-21.2992 0-38.8096-6.8608-52.5312-20.5824C6.8608 843.4688 0 825.9584 0 804.5568L0 219.4432c0-21.2992 6.8608-38.912 20.5824-52.5312 13.7216-13.7216 31.232-20.5824 52.5312-20.5824l365.6704 0 0-128C438.8864 6.144 444.928 0 457.1136 0l109.6704 0c12.1856 0 18.3296 6.144 18.3296 18.3296l0 128L950.8864 146.3296zM987.4432 219.4432c0-24.3712-12.1856-36.5568-36.5568-36.5568L585.1136 182.8864l0 54.8864c0 12.288-6.144 18.3296-18.3296 18.3296L457.1136 256.1024c-12.1856 0-18.3296-6.0416-18.3296-18.3296L438.784 182.8864 73.1136 182.8864c-24.3712 0-36.5568 12.288-36.5568 36.5568l0 585.1136c0 24.3712 12.1856 36.5568 36.5568 36.5568l877.6704 0c24.3712 0 36.5568-12.1856 36.5568-36.5568L987.3408 219.4432zM438.8864 676.5568c0-35.0208-12.5952-65.1264-37.6832-90.3168S345.9072 548.5568 310.8864 548.5568 245.76 561.152 220.5696 586.24 182.8864 641.536 182.8864 676.5568c0 12.288-6.144 18.3296-18.3296 18.3296S146.3296 688.8448 146.3296 676.5568c0-45.6704 15.9744-84.5824 48.0256-116.5312C226.304 527.9744 265.1136 512 310.8864 512c45.6704 0 84.5824 15.9744 116.5312 48.0256 31.9488 31.9488 48.0256 70.8608 48.0256 116.5312 0 12.288-6.144 18.3296-18.3296 18.3296S438.8864 688.8448 438.8864 676.5568zM374.8864 484.5568C356.5568 502.8864 335.2576 512 310.8864 512S265.1136 502.8864 246.8864 484.5568 219.4432 444.928 219.4432 420.5568c0-24.3712 9.1136-45.6704 27.4432-64s39.6288-27.4432 64-27.4432 45.6704 9.1136 64 27.4432S402.3296 396.288 402.3296 420.5568C402.3296 444.928 393.1136 466.3296 374.8864 484.5568zM349.696 381.7472C339.0464 371.0976 326.144 365.6704 310.8864 365.6704c-15.2576 0-28.16 5.4272-38.8096 15.9744C261.3248 392.3968 256 405.4016 256 420.5568c0 15.2576 5.3248 28.2624 15.9744 38.8096C282.624 470.1184 295.6288 475.4432 310.8864 475.4432c15.2576 0 28.16-5.3248 38.8096-15.9744 10.6496-10.6496 15.9744-23.6544 15.9744-38.8096C365.6704 405.4016 360.3456 392.3968 349.696 381.7472zM475.4432 219.4432l73.1136 0L548.5568 36.5568 475.4432 36.5568 475.4432 219.4432zM859.4432 365.6704l-256 0c-12.1856 0-18.3296-6.0416-18.3296-18.3296 0-12.1856 6.144-18.3296 18.3296-18.3296l256 0c12.1856 0 18.3296 6.144 18.3296 18.3296C877.6704 359.6288 871.6288 365.6704 859.4432 365.6704zM859.4432 475.4432l-256 0c-12.1856 0-18.3296-6.0416-18.3296-18.3296 0-12.1856 6.144-18.3296 18.3296-18.3296l256 0c12.1856 0 18.3296 6.144 18.3296 18.3296C877.6704 469.4016 871.6288 475.4432 859.4432 475.4432zM859.4432 585.1136l-256 0c-12.1856 0-18.3296-6.0416-18.3296-18.3296 0-12.1856 6.144-18.3296 18.3296-18.3296l256 0c12.1856 0 18.3296 6.144 18.3296 18.3296C877.6704 579.072 871.6288 585.1136 859.4432 585.1136zM859.4432 694.8864l-256 0c-12.1856 0-18.3296-6.0416-18.3296-18.3296 0-12.1856 6.144-18.3296 18.3296-18.3296l256 0c12.1856 0 18.3296 6.144 18.3296 18.3296C877.6704 688.8448 871.6288 694.8864 859.4432 694.8864z"
													p-id="3546"
													fill="#DBDBDB"></path>
									</svg>
									<span>点击选择照片或拍照</span>
								</div>
							</van-uploader>
						</div>
						<div v-if="state.imgBlankError.inHospProve"
								 class="img__blank_error">请上传住院证照片</div>
					</div>
				</van-cell-group>

				<div class="footer">
					<van-button type="primary"
											block
											icon="sign"
											round
											@click="onSubmit">提&emsp;交</van-button>
				</div>
			</van-form>
		</div>

		<!-- 住院记录 -->
		<van-popup v-model:show="state.ispShow"
							 position="bottom">
			<div class="treat">
				<div class="head">
					<div class="head_cancel"
							 @click="state.ispShow = false">取 消</div>
					<div class="head_title">选择住院记录</div>
					<div class="head_confirm"
							 @click="onIspConfirm">确 定</div>
				</div>
				<div class="treat_cont">
					<template v-if="state.treatRecord.length > 0">
						<section v-for="item in state.treatRecord"
										 :key="item.zyNum">
							<div class="cont_item"
									 :class="[state.currTreat.zyNum === item.zyNum ? 'border_click' : 'border_default']"
									 @click="state.currTreat = item">
								<div><span>患者姓名：</span><span>{{ item.patientName }}</span></div>
								<div><span>住院编号：</span><span>{{ item.zyNum }}</span></div>
								<div><span>出院科室：</span><span>{{ item.leaveCategory }}</span></div>
								<div><span>诊&emsp;&emsp;断：</span><span>{{ item.diagnose }}</span></div>
								<div style="width: 100%;height: 24px;padding: 0px;display: flex;flex-direction: row;justify-content: space-between;align-items: center;">
									<div style=";display: flex;">
										<svg t="1692242897447"
												 class="icon"
												 viewBox="0 0 1024 1024"
												 version="1.1"
												 xmlns="http://www.w3.org/2000/svg"
												 p-id="1020"
												 width="18"
												 height="18">
											<path d="M511.81568 61.99808c-248.42752 0-449.8176 201.39008-449.8176 449.8176s201.39008 449.8176 449.8176 449.8176 449.8176-201.39008 449.8176-449.8176-201.39008-449.8176-449.8176-449.8176z m0 854.656c-223.58528 0-404.83328-181.25312-404.83328-404.83328 0-223.58528 181.25312-404.8384 404.83328-404.8384s404.83328 181.25312 404.83328 404.83328-181.248 404.8384-404.83328 404.8384z"
														p-id="1021"
														fill="#d81e06"></path>
											<path d="M400.128 240.69632l37.57056-26.75712c42.50112 26.18368 89.18016 93.35808 140.03712 201.51296 70.9632 155.21792 148.00384 249.9072 231.12192 284.0576l-39.84896 50.09408c-83.10784-49.34144-159.95904-153.3184-230.54848-311.95136a1766.00576 1766.00576 0 0 0-16.78848-36.43392c-44.02688 150.85056-125.90592 268.11904-245.63712 351.80032a310.35392 310.35392 0 0 0-34.72384-42.69568C364.45184 632.72448 447.37536 509.952 490.07104 342.02112c-29.79328-49.71008-59.776-83.48672-89.94304-101.3248z"
														p-id="1022"
														fill="#d81e06"></path>
										</svg>
										<span>{{ item.inHospitalDate.substring(0, 10) }}</span>
									</div>
									<div style="color: var(--text-c);">--{{ item.hospitalDays }}天--</div>
									<div style=";display: flex;">
										<svg t="1692243113528"
												 class="icon"
												 viewBox="0 0 1024 1024"
												 version="1.1"
												 xmlns="http://www.w3.org/2000/svg"
												 p-id="1081"
												 width="18"
												 height="18">
											<path d="M0 512A512 512 0 1 0 512 0 512.672 512.672 0 0 0 0 512z m70.4 0A441.6 441.6 0 1 1 512 953.6 442.08 442.08 0 0 1 70.4 512z m685.12-24.96V239.68h-53.12v176.64h-164.48V182.08h-54.4v234.24h-162.56V239.68H267.84v224.32h215.68v245.12h-179.2v-178.24H251.2v225.6h469.76v22.4h52.8v-248h-52.8v178.24h-183.04V464h164.48v23.04h53.12z"
														fill="#67c23a"
														p-id="1082"></path>
										</svg>
										<span>{{ item.outHospitalDate.substring(0, 10) }}</span>
									</div>
								</div>
								<div class="item_checked"
										 v-if="state.currTreat.zyNum === item.zyNum">
									<van-icon name="passed"
														color="var(--color-primary)"
														size="20" />
								</div>
							</div>
						</section>
					</template>
					<van-empty v-else
										 image-size="100"
										 description="暂无住院记录" />
				</div>
			</div>
		</van-popup>

		<!-- 模板 -->
		<van-popup v-model:show="state.templateShow"
							 round
							 lock-scroll
							 position="bottom">
			<!-- :columns-field-names="{text: 'templatename'}" -->
			<van-picker title="用 途"
									:columns="state.templateList"
									value-key="templateno"
									@confirm="onTemplateConfirm"
									@cancel="state.templateShow = false">
				<template #option="option">
					<div style="margin: 5px 0;overflow: hidden">
						<div style="text-align: center;padding:8px 0 0;">{{ option }}</div>
					</div>
				</template>
			</van-picker>
		</van-popup>
	</div>
</template>

<script>
import { reactive, ref, watch } from 'vue';
import { axios } from 'axios'
import { store } from 'vue-helper'
import ImageUtil from '@/utils/image-util.mjs'
import { Back, GoBind } from '@/utils/common-util.mjs'
export default {
	name: 'ptint-reserve',
	components: {
		'select-patient-date': VueConfig.vueLoader('@/components/patient/select-patient-date.vue')
	},
	setup(props, context) {
		const formRef = ref(null)
		const state = reactive({
			ispShow: false,             // 住院记录弹框
			treatRecord: [],            // 住院记录
			currTreat: '',							// 当前选中的住院记录
			imgBlankError: {            // 照片
				idCardFront: false,
				idCardBack: false,
				inHospProve: false
			},
			img: {
				idCardFront: [],             // 本人身份证正面照片
				idCardBack: [],              // 本人身份证背面照片
				inHospProve: [],						 // 住院证明照片
			},
			templateShow: false,					 // 模板弹框
			templateList: ['慢性病办理', '保险', '出生证', '伤残鉴定', '临床就诊', '其他'],					// 模板列表
		})

		const creatForm = () => ({
			zyNum: '',              		// 住院号
			diagnose: '',               // 诊断名称
			patientId: '',              // 病人ID
			applyName: '',          		// 病人姓名
			deptCode: '',             	// 出院科室ID
			deptName: '',        				// 出院科室
			idCardNo: '',            		// 身份证
			phone: '',              		// 联系电话（邮寄时也填这个）
			idCardFront: '',        		// 本人身份证正面照片
			idCardBack: '',         		// 本人身份证背面照片
			useWay: '',             		// 用途
			inHospProve: '',						// 住院证明照片
			showCardNo: '',							// 加密身份证号码
		})
		const form = reactive(creatForm())

		const formLabel = reactive({
			getWayLabel: ''
		})

		const user = store.getters.getPatient
		setTimeout(() => {
			if (!user || !user.patientId) {
				onTipBand({
					onCancel: () => Back(false),
					onConfirm: () => GoBind(),
					showCancelButton: true,
					showCancelText: '退出'
				})
			}
		}, 100);

		/**
		 * 未绑定就诊人
		 * @param {*} param0 
		 */
		function onTipBand({ onCancel, onConfirm, title = '您还未绑定就诊人，请前往绑定！', showCancelButton, showCancelText }) {
			vant.Dialog.alert({
				title: '提示',
				message: '您还未绑定就诊人，请前往绑定！',
				showCancelButton: showCancelButton,
				confirmButtonText: '前往绑定',
				cancelButtonText: showCancelText
			}).then(() => {
				onConfirm()
			}).catch(() => {
				onCancel()
			})
		}

		/**
		 * 判断照片是否上传
		 */
		function isImgBlank() {
			let checked = 0
			Object.keys(state.imgBlankError).forEach(key => {
				if (form[key] === '') {
					checked++
					state.imgBlankError[key] = true
				} else if (form[key] !== '' && state.imgBlankError[key]) {
					state.imgBlankError[key] = false
				}
			})
			return checked !== 0
		}

		/**
		 * 提交预约
		 */
		function onSubmit() {
			patient.value = store.getters.getPatient
			if (!user || !user.patientId) {
				return onTipBand({
					onCancel: () => Back(false),
					onConfirm: () => GoBind(),
					showCancelButton: true,
					showCancelText: '退出'
				})
			}
			formRef.value.validate().then(() => {
				if (isImgBlank()) {
					return vant.Toast.fail('提交内容出现错误，请检查！')
				}
				vant.Dialog.confirm({
					title: '提示',
					message: '确定提交打印预约申请？'
				}).then(() => {
					const params = {
						applyName: patient.value.name,
						idcard: patient.value.idCardNo,
						patientId: patient.value.patientId,
						openId: patient.value.openid,
						idcardFront: form.idCardFront,
						idcardBack: form.idCardBack,
						treatId: form.zyNum,
						inHospProve: form.inHospProve,
						use: form.useWay,
						phone: form.phone,
					}
					axios.post('wx/record/upload', params).then(response => {
						if (response.code === 200) {
							vant.Toast.success('预约成功')
							resetForm()
						} else {
							vant.Toast.fail(response.message)
						}
					})
				}).catch(() => { })
			}).catch(error => {
				console.log('error', error)
				vant.Toast.fail('提交内容出现错误，请检查！')
			})

		}

		/**
		 * 选择住院记录
		 * @param {Object} value 住院记录
		 */
		function onIspConfirm() {
			state.ispShow = false
			if (state.currTreat) {
				form.zyNum = state.currTreat.zyNum
				form.diagnose = state.currTreat.diagnose
				form.deptCode = state.currTreat.leaveCategoryCode
				form.deptName = state.currTreat.leaveCategory
				form.applyName = state.currTreat.patientName

				form.patientId = patient.value.patientId
				form.idCardNo = patient.value.idCardNo
				form.showCardNo = patient.value.showCardNo
			}
		}

		const patient = ref(null)
		/**
		 * 获取住院记录
		 */
		function getMedicalRecordList() {
			patient.value = store.getters.getPatient
			const idCard = patient.value.idCardNo
			patient.value.showCardNo = idCard.length === 18 ? idCard.substring(0, 3) + '********' + idCard.substring(idCard.length - 4) : idCard
			if (!patient.value || (patient.value && !patient.value.patientId)) return vant.Toast.fail('患者参数缺失，无法查询住院记录！')
			axios.RGet('wx/inHosp/getHospListByPatientId', {
				patientId: patient.value.patientId
			}).then(response => {
				if (response.code === 200) {
					state.treatRecord = response.data
				}
			})
		}
		getMedicalRecordList()

		watch(() => state.ispShow, (newVal) => {
			if (newVal && !form.zyNum) {
				state.currTreat = ''
			}
		})

		watch(() => store.getters.getPatient, () => {
			getMedicalRecordList()
			resetForm()
		})

		function onTemplateConfirm(value) {
			state.templateShow = false
			form.useWay = value
		}

		/**
		 * 图片压缩
		 * @param {File} file 图片
		 * @param {*} state 参数名
		 */
		function onBeforeRead(file) {
			return ImageUtil.compressImage(file)
		}
		function afterRead(file, state) {
			form[state] = file.content
		}

		function resetForm() {
			Object.assign(form, creatForm())
			state.img.idCardFront = []
			state.img.idCardBack = []
			state.img.inHospProve = []
		}

		return {
			state,
			formRef,
			form,
			formLabel,
			onSubmit,
			onIspConfirm,
			afterRead,
			onTemplateConfirm,
			onBeforeRead
		}
	},
}
</script>
<style scoped>
.ptint-reserve {
}
.img_item {
	border-bottom: 1px solid var(--border-c);
}
.img_item_label {
	line-height: 25px;
	padding: 5px 16px;
	color: #646566;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
}
.img_item_upload {
	height: 150px;
	margin: 5px;
	border: 1px solid var(--border-d);
	border-radius: 5px;
}
.img_item_upload span {
	line-height: 30px;
	color: var(--text-c);
}

.img_item_upload >>> .van-uploader__wrapper,
.img_item_upload >>> .van-uploader__input-wrapper {
	width: 100%;
	height: 100%;
}
.img_item_upload >>> .van-uploader__preview,
.img_item_upload >>> .van-uploader__preview-image {
	width: 100%;
	height: 100%;
	margin: auto;
}
.img_item_upload >>> .van-uploader__preview-image img {
	object-fit: contain !important;
}
.img__blank_error {
	color: red;
	font-size: 12px;
	text-align: right;
	padding: 0px 10px 5px;
}
.ptint-reserve >>> .van-field__control {
	text-align: right;
}

.print-reserve >>> .van-field__value .van-field__error-message {
	text-align: right;
}
.footer {
	margin: 10px 5px;
}
.treat {
	width: 100%;
	height: 65vh;
	box-sizing: border-box;
	background-color: #fff;
	border-radius: 8px 8px 0 0;
	padding: 8px 5px;
}

.treat .head {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	padding: 5px 10px;
}

.head_cancel {
	color: var(--text-c);
}

.head_title {
	text-align: center;
}

.head_confirm {
	color: var(--color-primary);
}

.treat_cont {
	height: calc(100% - 40px);
	overflow: auto;
	padding: 8px;
}

.cont_item {
	padding: 8px 5px 5px;
	margin-bottom: 5px;
	border-radius: 5px;
	font-size: 13px;
	line-height: 20px;
	position: relative;
	overflow: hidden;
}

.cont_item div {
	padding: 3px 0px;
}
.cont_item div span:nth-child(1) {
	color: var(--text-c);
}

.cont_item div span:nth-child(2) {
	color: var(--text-a);
}

.border_default {
	border: #e2e2e2 solid 1px;
}

.border_click {
	border: var(--color-primary) solid 1px;
}

.item_checked {
	position: absolute;
	top: 8px;
	right: 10px;
	width: 20px;
	height: 20px;
}

.treat_filed >>> .van-field__control {
	text-align: right;
}

.ptint-reserve >>> .van-popup .van-picker .van-picker-column__item {
	/* height: 50px !important; */
}
</style>