<template>
	<view class="content">
		<view class="inner">
			<view class="form-box">
				<text class="form-title">基本信息</text>
				<view class="form-item justify-between">
					<text class="label">头像</text>
					<view class="right">
						<image :src="maleurl" class="w90 h90"></image>
						<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
						<!-- <button class="wx-head" type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
						</button> -->
					</view>
				</view>
				<view class="form-item">
					<text class="label">性别</text>
					<view class="sex-box">
						<view :class="form.sex===1?'sex-item active':'sex-item'"  @click="sexChange(1)" >
							<u-icon name="man" :color="form.sex===1?'#FF5030':'#898E91'" size="20"></u-icon>
							<text>男</text>
						</view>
						<view :class="form.sex===2?'sex-item active':'sex-item'"  @click="sexChange(2)" >
							<u-icon name="woman" :color="form.sex===2?'#FF5030':'#898E91'" size="20"></u-icon>
							<text>女</text>
						</view>
					</view>
				</view>
				<view class="form-item">
					<text class="label">出生年月</text>
					<picker class="birth-picker" mode="date"   @change="bindDateChange">
						<view class="right-box">
							<view class="input-box">
								<input type="text" :value="form.birthday" placeholder="请选择出生年月" placeholder-class="form-input" disabled="disabled" />
							</view>
							<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
						</view>
					</picker>
				</view>
				<view class="form-item">
					<text class="label">手机号</text>
					<input maxlength="11" class="input-width" type="idcard" v-model="form.idCard" placeholder="请输入手机号" placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">身份证号</text>
					<input maxlength="18" class="input-width" type="idcard" v-model="form.idCard" placeholder="请如实填写身份证号" placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">退休前工作单位</text>
					<input class="input-width" type="text" v-model="form.userName" placeholder="请输入工作单位"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">可支配收入</text>
					<input  class="input-width" type="text" v-model="form.userName" placeholder="请输入支配收入"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">实际消费</text>
					<input class="input-width" type="text" v-model="form.userName" placeholder="请输入实际消费"
						placeholder-class="form-input" />
				</view>
			</view>
			<view class="form-box">
				<text class="form-title">家庭地址及居住情况</text>
				
				<view class="form-item">
					<text class="label">市区</text>
					<picker class="birth-picker" mode="region"   @change="bindDateChange">
						<view class="right-box">
							<view class="input-box">
								<input type="text" :value="form.birthday" placeholder="请选择市区" placeholder-class="form-input" disabled="disabled" />
							</view>
							<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
						</view>
					</picker>
					
				</view>
				<view class="form-item">
					<text class="label">小区名称</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入小区名称"
						placeholder-class="form-input" />
				
				</view>
				<view class="form-item">
					<text class="label">门牌</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入门牌号"
						placeholder-class="form-input" />
				
				</view>
				
				
				<view class="form-item">
					<text class="label">面积</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入面积"
						placeholder-class="form-input" />
				</view>
				
                 <view class="form-item">
					<text class="label">楼层</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入楼层"
						placeholder-class="form-input" />
				</view>
			</view>
			<view class="form-box">
				<text class="form-title">家庭情况</text>
				<view class="form-item">
					<text class="label">伴侣</text>
					<input class="input-width" type="text" v-model="form.userName" placeholder="请输入伴侣姓名"
						placeholder-class="form-input" />
				
				</view>
				<view class="form-item">
					<text class="label">伴侣年龄</text>
					<input class="input-width" type="text" v-model="form.userName" placeholder="请输入伴侣年龄"
						placeholder-class="form-input" />
				
				</view>
				
				
				<view class="form-item">
					<text class="label">子辈单位</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入子辈工作单位"
						placeholder-class="form-input" />
				</view>
				
				 <view class="form-item">
					<text class="label">孙辈学校</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入所在学校"
						placeholder-class="form-input" />
				</view>
			</view>
			<view class="form-box">
				<text class="form-title">会员情况</text>
				<view class="form-item">
					<text class="label">是否是会员</text>
				<picker class="birth-picker" mode="selector"  @change="bindDateChange" :range="array">
					<view class="right-box">
						<view class="input-box">
							<input type="text" :value="form.birthday" placeholder="请选择是否是会员" placeholder-class="form-input" disabled="disabled" />
						</view>
						<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
					</view>
				</picker>
				
				</view>
				<view class="form-item">
					<text class="label">会员分类</text>
					<picker class="birth-picker" mode="date"   @change="bindDateChange">
						<view class="right-box">
							<view class="input-box">
								<input type="text" :value="form.birthday" placeholder="请选择会员分类" placeholder-class="form-input" disabled="disabled" />
							</view>
							<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
						</view>
					</picker>
				
				</view>
				
				
				<view class="form-item">
					<text class="label">加入时间</text>
					<picker class="birth-picker" mode="date"   @change="bindDateChange">
						<view class="right-box">
							<view class="input-box">
								<input type="text" :value="form.birthday" placeholder="请选择加入时间" placeholder-class="form-input" disabled="disabled" />
							</view>
							<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
						</view>
					</picker>
				</view>
				
				 <view class="form-item">
					<text class="label">到期时间</text>
					<picker class="birth-picker" mode="date"   @change="bindDateChange">
						<view class="right-box">
							<view class="input-box">
								<input type="text" :value="form.birthday" placeholder="请选择到期时间" placeholder-class="form-input" disabled="disabled" />
							</view>
							<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
						</view>
					</picker>
				</view>
				<view class="form-item">
					<text class="label">管理月份</text>
					<picker class="birth-picker" mode="date" fields="month" @change="bindDateChange">
						<view class="right-box">
							<view class="input-box">
								<input type="text" :value="form.birthday" placeholder="请选择管理月份" placeholder-class="form-input" disabled="disabled" />
							</view>
							<image class="w48 h48" src="/static/images/health/right_arrow_right_icon24.png"></image>
						</view>
					</picker>
				</view>
			</view>
			<view class="form-box">
				<text class="form-title">特殊情况</text>
				<view class="form-item">
					<text class="label">职位</text>
					<input class="input-width" type="text" v-model="form.userName" placeholder="请输入职位"
						placeholder-class="form-input" />
				
				</view>
				<view class="form-item">
					<text class="label">癖好</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入癖好"
						placeholder-class="form-input" />
				
				</view>
				
				
				<view class="form-item">
					<text class="label">平日喜好</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入平日喜好"
						placeholder-class="form-input" />
				</view>
				
				 <view class="form-item">
					<text class="label">信仰</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入信仰"
						placeholder-class="form-input" />
				</view>
				<view class="form-item">
					<text class="label">担忧</text>
					<input maxlength="10" class="input-width" type="text" v-model="form.userName" placeholder="请输入信仰"
						placeholder-class="form-input" />
				</view>
			</view>
			<view class="form-box">
				<text class="form-title">其他</text>
				<view class="form-item">
				<!-- 	<text class="label">备注</text> -->
					<textarea maxlength="200" class="form-textarea" v-model="form.remark" placeholder="请输入用户想解决的问题"   />
				</view>
				<view class="form-item">
					<!-- <text class="label">备注</text> -->
					<textarea maxlength="200" class="form-textarea" v-model="form.remark" placeholder="请输入健康管理师对用户的建议"   />
				</view>
			</view>
		
		</view>
		<view class="btn-box">
			<view class="sub-btn" @click="submit()">保存</view>
		</view>
	</view>
</template>

<script>
	import {
		getDocDetails,
		addDoc,
		editDoc
	} from '@/api/doc.js'
	export default {
		data() {
			return {
				type: null,
				patientId: null,
				famaleurl:"/static/images/health/female_profile.png",
				maleurl:"/static/images/health/my_heads.png",
				checked:1,
				array:['是','否'],
				tags: [{
					name: '心脏病',
					checked:true,
					id: 1
				},
				{
					name: '脑梗死',
						checked:false,
					id: 2
				},{
					name: '肾病',
						checked:false,
					id: 3
				},{
					name: '脂肪肝',
						checked:false,
					id: 4
				}],
				form: {
					userName: null,
					idCard: null,
					sex: null,
					birthday: null,
					remark: null,
				}
			};
		},
		onLoad(option) {
			this.type = option.type;
			console.log(this.type)
			if (this.type == 'edit') {
				this.docId = option.docId;
				// this.getDocDetails();
			}
		},
		methods: {
			sexChange(type) {
				this.form.sex = type
			},
			radioClick(item) {
			        this.checked=item.id
			      },
			getDocDetails() {
				var data = {
					docId: this.docId
				};
				getDocDetails(data).then(
					res => {
						if (res.code == 200) {
							this.form = res.data;

						} else {
							uni.showToast({
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			onChooseAvatar(e){
				let {
					avatarUrl
				} = e.detail;
				uni.uploadFile({
					url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例，非真实的接口地址
					filePath: avatarUrl,
					name: 'file',
					formData: {
						'user': 'test'  // 上传附带参数
					},
					success: (uploadFileRes) => {
						this.user.avatar =JSON.parse(uploadFileRes.data).url
					}
				});
			},
			submit() {
				// if (this.form.userName == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "姓名不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.idCard == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "身份证号不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.sex == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "性别不能为空",
				// 	});
				// 	return;
				// }
				// if (this.form.birthday == null) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: "出生年月不能为空",
				// 	});
				// 	return;
				// }
				// if (this.type == "add") {
				// 	this.addDoc()
				// } else if (this.type == "edit") {
				// 	this.editDoc()
				// }
                uni.navigateTo({
                	url: '/pages_health/doc?type=edit&docId='
                })
			},
			editDoc() {
				editDoc(this.form).then(
					res => {
						if (res.code == 200) {
							uni.showToast({
								icon: 'success',
								title: "操作成功",
							});
							setTimeout(function() {
								uni.$emit('refreshDoc');
								uni.navigateBack({
									delta: 1
								})
							}, 500);
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			addDoc() {
				addDoc(this.form).then(
					res => {
						if (res.code == 200) {
							uni.showToast({
								icon: 'success',
								title: "操作成功",
							});
							setTimeout(function() {
								uni.$emit('refreshDoc');
								uni.navigateBack({
									delta: 1
								})
							}, 500);
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg,
							});
						}
					},
					rej => {}
				);
			},
			// 出生日期选择
			bindDateChange: function(e) {
				this.form.birthday = e.target.value
			},
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.content {
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.inner {
			// height: calc(100% - 120upx);
			padding: 20upx;

			.form-box {
				padding: 0 30upx;
				background: #FFFFFF;
				border-radius: 16upx;
				margin-bottom: 20upx;

				.form-title {
					font-family: PingFang SC;
					font-weight: 600;
					font-size: 40rpx;
					color: #222426;
					text-align: left;
					padding: 30rpx 0;
					display: block;
				}

				.form-item {
					padding: 30upx 0;
					display: flex;
					align-items: flex-start;
					border-bottom: 1px solid #F1F1F1;

					&:last-child {
						border-bottom: none;
					}
        
					.label {
						width: 300upx;
						text-align: left;
						font-size: 32upx;
						line-height: 44upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #222222;
						flex-shrink: 0;
					}

					input {
						text-align: right;
					}
               
					.form-input {
						font-size: 30upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						text-align: right;
					}

					.form-item-tag{
						margin-right: 16rpx;
						.tag{
							border-radius: 8rpx 8rpx 8rpx 8rpx;
							border: 2rpx solid #ECECEC;
							display: flex;
							align-items: center;
							padding: 24rpx;
							font-family: PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							&.active{
								background: #F0FAFF;
								border: 2rpx solid #008FD3;
								color: #008FD3;
							}
						}
						
						
						
					}
					.right{
						display: flex;
						align-items: center;
					}
					.sex-box{
						flex:1;
						display: flex;
						align-items: center;
						justify-content: flex-end;
						.sex-item{
							width: 146rpx;
							height: 64rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							background: #F5F7FA;
							border-radius: 32rpx 32rpx 32rpx 32rpx;
							margin-left: 16rpx;
							.u-icon__icon{
								margin: 0;
							}
							text{
								// font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 28rpx;
								color: #898E91;
								margin-left: 12rpx;
							}
							&.active{
								background: #FCF0E7;
								text{
									color:#FF5030
								}
							}
						}
					}
					.form-textarea{
						font-size: 30upx;
						color: #999999;
						height: 100upx;
						padding: 4upx 0;
					}
					 
					.birth-picker {
						flex: 1;
						display: flex;
						align-items: center;
						
						.right-box{
							width: 100%;
							display: flex;
							align-items: center;
							.input-box{
								// width: 470upx;
							}
							.arrow{
								width: 13upx;
								height: 23upx;
								margin-left: 20upx;
							}
						}
					}
				}
			}
		}

		.btn-box {
			height: 120upx;
			padding: 0 30upx;
			display: flex;
			align-items: center;
			justify-content: center;

			// position: fixed;
			// width: 90%;
			// bottom: 0;
			// left: 50%;
			// transform: translate(-50%,-50%);
			// background: #FFFFFF;
			.sub-btn {
				width: 100%;
				height: 88upx;
				line-height: 88upx;
				text-align: center;
				font-size: 32upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
				background: #008FD3 ;
				border-radius: 44upx;
				margin-bottom: 40upx;
			}
		}
	}
</style>