<template>
	<view class="content">
		<view class="inner">
			<view v-for="(item,index) in docs" :key="index" class="item" @click="showDetail(item)">
				<view class="user-info">
					<view class="name">{{item.userName}}</view>
					<text class="gray-tag" v-if="item.sex==1">男</text>
					<text class="gray-tag" v-if="item.sex==2">女</text>
					<view class="gray-tag">{{utils.getAge(item.birthday)}}岁</view>
					<view class="blue-tag">标签</view>
				</view>
			<!-- 	<view class="stage-box">
					<text class="stage">阶段1：</text>
					<text class="stage-text">药物治疗胰岛素降糖，洛氟沙星抗感染治疗中治疗中治疗中治疗中</text>
				</view>
				<view class="progress-box">
					<progress :percent="80" activeColor="#4BC9B1" border-radius="5" stroke-width="5" />
				</view> -->
				<view class="period">建档时间 {{item.createTime}}</view>
				<view class="period">备注 {{item.remark!=null?item.remark:''}}</view>
			</view>
			<view v-if="docs.length == 0" class="no-data-box" @click="getMyDocList()">
				<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="addDoc">创建健康档案</view>
		</view>
	</view>
</template>

<script>
	import {getMyDocList,delDoc} from '@/api/doc.js'
	export default {
		data() {
			return {
				docs:[],
			}
		},
		onLoad() {
			this.getMyDocList()
			uni.$on('refreshDoc', () => {
				this.getMyDocList()
			})
		},
		methods: {
			showDetail(item){
				uni.navigateTo({
					url: './docDetail?docId='+item.docId
				})
			},
			editDoc(item){
				uni.navigateTo({
					url: './addDoc?type=edit&docId='+item.docId
				})
			},
			delDoc(item){
				uni.showModal({
					title:"提示",
					content:"确认删除吗?",
					showCancel:true,
					cancelText:'取消',
					confirmText:'确定',
					success:res=>{
						if(res.confirm){
							// 用户点击确定
							var data={docId:item.docId}
							delDoc(data).then(
								res => {
									if(res.code==200){
										 uni.showToast({
										 	icon:'success',
										 	title: "操作成功",
										 });
										 this.getMyDocList()
									}else{
										uni.showToast({
											icon:'none',
											title: "请求失败",
										});
									}
								},
								rej => {}
							);
														
						}else{
							// 否则点击了取消  
						}
					}
				})
			},
			getMyDocList(){
				uni.showLoading({
					title:"正在加载中"
				})
				getMyDocList().then(
					res => {
						uni.hideLoading()
						if(res.code==200){
							this.docs=res.data;
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			addDoc() {
				uni.navigateTo({
					url: './addDoc?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;
			.item{
				background: #FFFFFF;
				border-radius: 20upx;
				margin-bottom: 20upx;
				padding: 40upx 30upx;
				&:last-child{
					margin-bottom: 0;
				}
				.user-info{
					display: flex;
					align-items: center;
					.name{
						font-size: 36upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #111111;
						line-height: 1;
						margin-right: 20upx;
					}
					.gray-tag{
						height: 46upx;
						line-height: 46upx;
						padding: 0 16upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #333333;
						background: #F7F7F7;
						border-radius: 8upx;
						margin-right: 10upx;
					}
					.blue-tag{
						height: 46upx;
						line-height: 46upx;
						padding: 0 16upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #4BC9B1;
						background: #E2F6F2;
						border-radius: 8upx;
					}
				}
				.stage-box{
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					margin-top: 34upx;
					.stage{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #111111;
						line-height: 1;
					}
					.stage-text{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						line-height: 1;
					}
				}
				.progress-box{
					margin-top: 18upx;
				}
				.period{
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 1;
					margin-top: 40upx;
				}
			}
			 
		}
		.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: #0bb3f2;
				border-radius: 44upx;
			}
		}
		 
	}
</style>
