<template>
	<view class="mb-5">
		<view class="" v-if="userData.id">
			<view class="header p-3">
				<view class="centerY">
					<span class="fs-18 text-white font-bold">个人档案</span>
					<span class="p-3 d-inline-block ml-auto text-white1" @click="closet">退出</span>
				</view>
				<view class="centerY mt-2" @click="$mf.clickNavto('/pages/userinfo/userinfo')">
					<view class="w-15 userhead">
						<view class="picbox">
							<image v-if="userData.sex==1" src="@/static/img/defult/head1.png" mode="widthFix"
								class="picimg"></image>
							<image v-if="userData.sex==2" src="@/static/img/defult/head2.png" mode="widthFix"
								class="picimg"></image>
						</view>
					</view>
					<view class="w-85 ml-3">
						<view class="text-white fs-16 font-bold">
							{{userData.username||''}}
						</view>
						<view class="centerY" style="margin-top:10rpx;">
							<view
								:class="{'iconfont text-white fs-16 font-bold':true,' nv':userData.sex==2,'nanxing':userData.sex==1,} ">
							</view>
							<view class="py-1 pl-2 text-center centerY text-gry80 bg-white ml-auto"
								style="border-radius: 6rpx;">
								<view class="">
									基础资料
								</view>
								<view class="iconfont youla2 fs-12 font-bold">
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="content p-3 bg-white mx-3 my-3 box-border08">
				<view class="" style="display:flex;flex-wrap: wrap !important;">
					<view class="w-100 border-box">
						<view class=""
							style="background: linear-gradient(180deg, rgb(151,220,249) 0%, rgb(110,197,246) 100%);border-radius: 16rpx;">
							<view class="px-3 pt-2 pb-3 ">
								<view class="centerY ">
									<view class="bule_line"></view>
									<text class="fs-18 ml-2 font-bold" style="color: #1C90D7;">
										个人体征
									</text>
								</view>
								<view class="mt-2" style="color: #000;">
									<view class="font-bold" style="display:flex;flex-wrap: wrap !important;">
										<view class="w-50  border-box pr-1">
											<view class=" d-flex px-2 py-1"
												style="color: #55afdf;border-radius: 10rpx;background-color: rgba(255,255,255)">
												身高<span class="ml-auto ml-1">{{physical.height}} cm</span>
											</view>
										</view>
										<view class="w-50 border-box  pl-1">
											<view class=" d-flex px-2 py-1"
												style="color: #55afdf;border-radius: 10rpx;background-color: rgba(255,255,255)">
												体重<span class="ml-auto ml-1">{{physical.waist}} kg</span>
											</view>
										</view>
										<view class="w-50 border-box pr-1 mt-2">
											<view class=" d-flex px-2 py-1"
												style="color: #55afdf;border-radius: 10rpx;background-color: rgba(255,255,255)">
												BMI
												<span class="ml-auto ml-1">{{physical.bmi}} kg/m^2</span>
											</view>
										</view>
										<view class="w-50 border-box pl-1 mt-2">
											<view class=" d-flex px-2 py-1"
												style="color: #55afdf;border-radius: 10rpx;background-color: rgba(255,255,255)">
												血压<span class="ml-auto ml-1">{{physical.diastole}}/{{physical.shrink}}
													mmHg</span>
											</view>
										</view>
										<view class="w-50 border-box pr-1 mt-2">
											<view class=" d-flex px-2 py-1"
												style="color: #55afdf;border-radius: 10rpx;background-color: rgba(255,255,255)">
												心率<span class="ml-auto ml-1">{{physical.pulse}} bmp</span>
											</view>
										</view>
										<view class="w-50 border-box pl-1 mt-2">
											<view class=" d-flex px-2 py-1"
												style="color: #55afdf;border-radius: 10rpx;background-color: rgba(255,255,255)">
												腰围<span class="ml-auto ml-1">{{physical.weight}} cm</span>
											</view>
										</view>
									</view>

								</view>
							</view>
						</view>
					</view>
					<view class="w-50 pr-2 border-box mt-3">
						<image @click="$mf.clickNavto('/pages/medication/medication')" src="@/static/img/index/dqyy.png"
							mode="widthFix" class="w-100"></image>
					</view>
					<view class="w-50 pl-2 border-box mt-3">
						<image @click="$mf.clickNavto('/pages/health_report/health_report')"
							src="@/static/img/index/jkbg.png" mode="widthFix" class="w-100"></image>
					</view>
				</view>
				<view class="mt-2">
					<image @click="$mf.clickNavto('/pages/eye_ground/eye_ground')" src="@/static/img/index/ydjc.png"
						mode="widthFix" class="w-100"></image>
				</view>
				<view class="mt-2">
					<image @click="$mf.clickNavto('/pages/home_monitoring/home_monitoring')"
						src="@/static/img/index/jjjc.png" mode="widthFix" class="w-100"></image>
				</view>
			</view>

		</view>

		<view class="">
			<uni-popup ref="popup1" type="center" :mask-click="false">
				<view class="bg-white p-3 w-100" style="border-radius: 16rpx;">
					<view class="text-center mb-3 fs-14 font-bold py-2">
						查询
					</view>
					<view class=" centerY mb-3" style="border-radius: 14rpx;border: 1px solid #007aff;">
						<input type="text" v-model="valueId" class="p-1 px-2 fs-12" placeholder="请输入身份证号码"
							placeholder-class="fs-12">
						<button type="primary" class="d-inline-block fs-12 px-3 py-0 ml-auto mr-0"
							@click="search">搜索</button>
					</view>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userData: {},
				physical: {},
				valueId: '330222194512283184'
			}
		},
		mounted() {
			// console.log(this.$mf)
			// console.log(this.$httpApi)

			if (!uni.getStorageSync('idCard')) {
				console.log(this.$refs)
				this.$refs.popup1.open()
			} else {
				this.getuserinfo(uni.getStorageSync('idCard'))
			}
		},
		methods: {
			closet() {
				uni.clearStorage('idCard')
				uni.clearStorage('userData')
				this.valueId = '';
				this.userData = {};
				this.physical = {};
				this.$refs.popup1.open()
			},
			search() {
				this.getuserinfo(this.valueId)
				this.valueId = '';
				this.userData = {};
				this.physical = {};
			},
			async find_physical() {
				uni.showLoading({
					title: '加载中'
				});
				let idCard = uni.getStorageSync('idCard')
				let {
					data,
					code
				} = await this.$api.find_physical({
					idCard
				})
				if (code == 0) {
					this.physical = data || {}
					uni.hideLoading();
				} else {
					uni.hideLoading();
				}
				uni.stopPullDownRefresh()
			},
			async getuserinfo(idCard) { //330222194512283184
				uni.showLoading({
					title: '加载中'
				});
				let {
					data,
					code
				} = await this.$api.getUserInfo({
					idCard
				})
				if (code == 0) {
					uni.setStorageSync('userData', data || {});
					uni.setStorageSync('idCard', data && data.idCard || '')
					this.userData = data || {}
					console.log(this.userData)
					if (data && data.id) {
						this.$refs.popup1.close();
						this.find_physical()

					} else {
						uni.showToast({
							title: '未查询到患者',
							icon: 'error'
						})
					}

					uni.hideLoading();
				} else {
					uni.hideLoading();
					uni.stopPullDownRefresh()
				}
			}
		},
		onPullDownRefresh() {
			this.getuserinfo()
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F9FF;
	}

	.header {
		background: linear-gradient(180deg, #096DCB 0%, #6faae1 100%)
	}

	.userhead {
		border-radius: 50%;
		box-shadow: 1px 1px 10px 1px #096DCB;
	}

	.text-gry80 {
		color: #808080;
	}

	.box-border08 {
		border-radius: 16rpx;
	}
</style>
