<template>
	<view class="app">
		<view class="code">
			<view class="title">
				签约时出示二维码
			</view>
			<image src="@/static/ma2x.png" mode=""></image>
		</view>
		<view class="item">
			<view class="lefttext">
				姓名：
			</view>
			<view class="righttext">
				{{currentInfo.patientName}}
			</view>
		</view>
		<view class="item">
			<view class="lefttext">
				手机号：
			</view>
			<view class="righttext" v-if="currentInfo.phone">
				{{currentInfo.phone.substring(0,3)}}****{{currentInfo.phone.substring(7,11)}}
			</view>
		</view>
		<view class="item">
			<view class="lefttext">
				身份证号：
			</view>
			<view class="righttext" v-if="currentInfo.cardNo">
				{{currentInfo.cardNo.substring(0,4)}}************{{currentInfo.cardNo.substring(16,18)}}
			</view>
		</view>
		<view class="btn" @tap="show = true">
			解除绑定家庭成员
		</view>
		<u-modal v-model="show" :title="title" closeOnClickOverlay :content='content' showCancelButton @confirm='confirmbtn' @close='closebtn'
			@cancel='cancelbtn'></u-modal>
	</view>
</template>

<script>
	import {getInfo,delFamilyItem} from '@/api/pagesB/familymemberdetail/familymemberdetail.js'
	export default {
		data() {
			return {
				currentInfo: '',
				show: false,
				title: '提示',
				content: '确定要解除绑定吗？',
				userinfo:{},
				patientCode:'',

			};
		},
		onLoad(options) {
			// console.log(options)
			this.patientCode=options.patientCode
		},
		onShow() {
			this.userinfo=uni.getStorageSync('userinfo')
			console.log(this.userinfo)
			getInfo(this.patientCode).then(res => {
				this.currentInfo=res.data
				})
		},
		methods: {
			closebtn() {
				this.show = false;
			},
			confirmbtn() {
				console.log(this.currentInfo.cardNo,this.userinfo.cardNo)
				delFamilyItem(this.currentInfo.patientCode).then(res => {
					if(res.code == 200) {
						if(this.currentInfo.cardNo==this.userinfo.cardNo){
							uni.showToast({
								title: '解除成功',
								duration: 1000
							});
							uni.removeStorageSync('patientId');
							uni.removeStorageSync('openid');
							uni.removeStorageSync('phone');
							uni.removeStorageSync('userinfo');
							setTimeout(function() {
								uni.navigateBack({
									delta: 2
								})
							}, 1000);


						}else{
							uni.showToast({
								title: '解除成功',
								duration: 1000
							});
							setTimeout(function() {
								uni.navigateBack({
									delta: 1
								})
							}, 1000);

						}

					}
				})
				this.show = false;
			},
			cancelbtn() {
				this.show = false;
			}
		}
	}
</script>

<style lang="scss">
.app {
		background-color: #fff;
		width: 96%;
		margin: 20rpx auto 0;
		height: calc(100vh - 20rpx);
		box-shadow: 0rpx 9rpx 31rpx 9rpx rgba(0, 0, 0, 0.03);
		padding-top: 24rpx;

		.btn {
			position: fixed;
			bottom: 50rpx;
			left: 50%;
			transform: translateX(-50%);
			width: 500rpx;
			height: 70rpx;
			background: #26A888;
			line-height: 70rpx;
			border-radius: 10rpx;
			font-size: 31rpx;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
		}

		.item {
			width: 94%;
			margin: 0 auto;
			height: 120rpx;
			font-size: 34rpx;
			color: #333333;
			position: relative;
			border-bottom: 2rpx solid #E6E6E6;

			.lefttext,
			.righttext {
				position: absolute;
				top: 50%;
				left: 4%;
				transform: translateY(-50%);
			}

			.righttext {
				right: 3% !important;
				text-align: right;
			}
		}

		.code {
			width: 96%;
			height: 400rpx;
			margin: 0 auto 40rpx;
			border: 2rpx solid #26A888;
			border-radius: 5rpx;

			.title {
				margin: 50rpx 0 40rpx;
				font-size: 32rpx;
				color: #26A888;
				text-align: center;
			}

			image {
				margin-left: 50%;
				transform: translateX(-50%);
				width: 220rpx;
				height: 220rpx;
			}
		}
	}
</style>
