<template>
	<view class="content">
		<view class="inner">
			<view v-for="(item,index) in patient" :key="index" class="peop-item" @click="pickPatient(item)">
				<view :class="item.isAuth?'auth':'noauth'">{{item.isAuth?'已实名':'未实名'}}</view>
				<view class="info">
					<view class="name">{{item.patientName}}</view>
					<view class="detail">
						<text class="text" v-if="item.gender==1">男</text>
						<text class="text" v-if="item.gender==2">女</text>
						<text class="text">{{utils.getAge(item.birthday)}}岁</text>
						<text class="text">{{utils.parseIdCard(item.idCard)}}</text>
					</view>
				</view>
				<view class="operat-box">
					<image src="../../static/images/del1.png" mode="" @click="delPatient(item)" ></image>
					<image src="../../static/images/edit.png" mode="" @click="editPatient(item)"></image>
				</view>
			</view>
			<view v-if="patient.length == 0" class="no-data-box" @click="getPatientList()">
				<image src="../../static/images/no_data.png" mode="aspectFit"></image>
				<view class="empty-title">暂无数据</view>
			</view>
		</view>
		<view class="btn-box">
			<view class="sub-btn" @click="addPatient">创建档案</view>
		</view>
	</view>
</template>

<script>
	import {getPatientList,delPatient} from '@/api/patient'
	export default {
		data() {
			return {
				patient:[],
				isFromTest:false
			}
		},
		onLoad(option) {
			this.isFromTest=option.isFromTest;
			this.getPatientList();
			uni.$on('refreshPatient', () => {
				this.getPatientList()
			});
		},
		methods: {
			editPatient(item){
				uni.navigateTo({
					url: './addPatient?type=edit&patientId='+item.patientId
				})
			},
			delPatient(item){
				uni.showModal({
					title:"提示",
					content:"确认删除吗?",
					showCancel:true,
					cancelText:'取消',
					confirmText:'确定',
					success:res=>{
						if(res.confirm){
							// 用户点击确定
							var data={patientId:item.patientId}
							delPatient(data).then(
								res => {
									if(res.code==200){
										 uni.showToast({
										 	icon:'success',
										 	title: "操作成功",
										 });
										 this.getPatientList()
									}else{
										uni.showToast({
											icon:'none',
											title: "请求失败",
										});
									}
								},
								rej => {}
							);
														
						}else{
							// 否则点击了取消  
						}
					}
				})
			},
			getPatientList(){
				uni.showLoading({
					title:"正在加载中"
				})
				getPatientList().then(
					res => {
						uni.hideLoading()
						if(res.code==200){
							this.patient=res.data;
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			addPatient() {
				uni.navigateTo({
					url: './addPatient?type=add'
				})
			},
			pickPatient(item){
			  if(this.isFromTest){
				  uni.$emit('refreshOrderPatient',item);
				  uni.navigateBack({delta: 1 });
			  }
			}
			 
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.content{
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.inner{
			flex: 1;
			padding: 20upx 20upx 160upx;
			.peop-item{
				box-sizing: border-box;
				height: 184upx;
				background: #FFFFFF;
				border-radius: 16upx;
				padding: 50upx 40upx 50upx 30upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 20upx;
				position: relative;
				.auth{
					position: absolute;
					right: 0;
					top: 0;
					width: 90rpx;
					height: 36rpx;
					line-height: 36rpx;
					color: #fff;
					font-size: 24rpx;
					background-color: green;
					border-radius: 8upx;
					text-align: center;
				}
				.noauth{
					position: absolute;
					right: 0;
					top: 0;
					width: 90rpx;
					height: 36rpx;
					line-height: 36rpx;
					color: #fff;
					font-size: 24rpx;
					background-color: #ff0000;
					border-radius: 8upx;
					text-align: center;
				}
				.info{
					.name{
						font-size: 30upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #111111;
						line-height: 1;
					}
					.detail{
						display: flex;
						align-items: center;
						margin-top: 30upx;
						.text{
							font-size: 26upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							line-height: 1;
							margin-right: 30upx;
							&:last-child{
								margin-right: 0;
							}
						}
					}
				}
				.operat-box{
					display: flex;
					align-items: center;
					image{
						width: 30upx;
						height: 30upx;
						margin-left: 38upx;
						&:first-child{
							margin-left: 0;
						}
					}
				}
			}
		}
		.btn-box{
			z-index: 9999;
			width: 100%;
			padding: 30upx;
			position: fixed;
			bottom: 0;
			left: 0;
			box-sizing: border-box;
			background: #FFFFFF;
			.sub-btn{
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 30upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #018C39;
				border-radius: 44upx;
			}
		}
		 
	}
</style>
