<template>
	<view class="content">
		<view class="inner">
			<view  v-for="(item,index) in patient" :key="index" @click.stop="selectPatient(item)" class="peop-item">
				<view class="info" >
					<view class="name">{{item.patientName}}</view>
					<view class="detail">
						<text class="text" v-if="item.sex==1">男</text>
						<text class="text" v-if="item.sex==2">女</text>
						<text class="text">{{$getAge(item.birthday)}}岁</text>
						<text class="text">{{$parseIdCard(item.idCard)}}</text>
					</view>
				</view>
				<view class="operat-box">
					<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/del.png" mode="" @click.stop="delPatient(item)" ></image>
					<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/edit.png" mode="" @click.stop="editPatient(item)"></image>
				</view>
			</view>
			<view v-if="patient.length == 0" class="no-data-box" @click="getPatientList()">
				<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/empty_icon.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:[],
			}
		},
		onLoad() {
			this.getPatientList()
			uni.$on('refreshPatient', () => {
				this.getPatientList()
			})
		},
		onUnload() {
			uni.$off('refreshPatient')
		},
		methods: {
			selectPatient(item){
				uni.$emit('refreshOrderPatient',item);
				uni.navigateBack({
			  		delta: 1
				})
			},
			editPatient(item){
				uni.navigateTo({
					url: './addEditPatient?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: './addEditPatient?type=add'
				})
			}
			 
		}
	}
</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;
				.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{
						padding: 15rpx;
						width: 30upx;
						height: 30upx;
						margin-left: 10upx;
						&: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: #2583EB;
				border-radius: 44upx;
			}
		}
		 
	}
</style>
