<template>
	<view class="container">
		<image 
			class="jkda_top_bg" 
			:src="baseUrl+'/images/healthRecords/integral_top_bg@2x.png'" 
			mode="widthFix"
			v-if="this.formType!='dietList' && this.formType!='sleepList'&&this.formType!='sportList'&& this.formType!='healthLife'"
		></image>
		<view class="container-body">
			<!-- 就诊人信息 -->
			<view class="userbox" v-if="this.formType!='dietList' && this.formType!='sleepList'&&this.formType!='sportList'&& this.formType!='healthLife'">
				<view class="userbox-left" style="opacity: 0.65;" @click="addPatient()" v-if="patient!=null">
					<view class="userbox-headimg">
						<image :src="defaultHeadimg" mode="aspectFill" style="width: 100%;height: 100%"></image>
					</view>
					<view class="userbox-info">
						<view class="userbox-name">
							<text>{{patient.patientName}}</text>
							<text class="userbox-idcard">{{$parseIdCard(patient.idCard)}}</text>
						</view>
						<view class="userbox-info-tag">
							<view v-if="patient.sex==1">男</view>
							<view v-if="patient.sex==2">女</view>
							<view>{{$getAge(patient.birthday)}}岁</view>
						</view>
					</view>
				</view>
				<view class="userbind" @click="addPatient()" v-if="patient==null">
					<image :src="baseUrl+'/images/healthRecords/upload_id_card_icon.png'" mode="aspectFill"></image>
					<text>绑定就诊人</text>
				</view>
			</view>
			<!-- 问卷 -->
			<view class="listbox multiplebox" v-for="(item,index) in list" :key="index">
				<view class="listbox-titlebox">
					<text>{{index + 1}}.</text>
					<view class="listbox-titletag" v-if="item.type == 2">多选</view>
					<text class="listbox-title">{{item.name}}</text>
				</view>
				<!-- 多选 -->
				<view class="listbox-option" v-if="item.type == 2">
					<view v-for="(option,i) in item.question" :key="i" class="listbox-option-flex">
						<view
							@click="handleMultiple(item,index,option)"
							:class="item.value.indexOf(option.name) === -1 ? 'listbox-option-item' : 'listbox-option-item option-active'">
							{{option.name}}
						</view>
						<view class="otherinput" v-if="option.isWrite == 1 && item.value.indexOf(option.name) !== -1" @click="handleEdit(index,i)">
							{{option.writeVal || '请输入相关描述'}}
						</view>
					</view>
				</view>
				<!-- 单选 -->
				<view style="margin-top: 20rpx;" v-if="item.type == 1">
					<view class="listbox-choose" v-for="(option,i) in item.question" :key="i" @click="handleChoose(item,option)">
						<image class="choose-icon" v-if="item.value == option.name" :src="baseUrl+'/images/healthRecords/choose_icon.png'" mode="aspectFill"></image>
						<image class="choose-icon" v-if="item.value != option.name" :src="baseUrl+'/images/healthRecords/choose_no_icon.png'" mode="aspectFill"></image>
						<text style="flex-shrink: 0;">{{option.name}}</text>
						<view class="choose-input" v-if="option.isWrite == 1 && item.value == option.name" @click.stop="handleEdit(index,i)">
							{{option.writeVal || '请输入相关描述'}}
						</view>
					</view>
				</view>
				<!-- 饮食调查 -->
				<view class="dietary-survey" v-if="item.type == 3">
					<view class="dietary-survey-item" v-for="(option,i) in item.question" :key="i"
						@click="handleChoose(item,option)">
						<view class="dietary-survey-iteml" v-if="option.name !== '每周多少次'">
							<view :class="item.value == option.name ? 'dietary-survey-active':''">{{i+1}}</view>
							<text>{{option.name}}</text>
						</view>
						<view class="dietary-survey-input" v-if="item.name == '平时应酬' && option.name === '每周多少次'">
							<text>每周</text>
							<input class="uni-input" type="number" maxlength="2"
								:value="option.writeVal" @input="clearInput($event,option)" />
							<text>次</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="show" @close="close"  >
			 <view class="popbox">
			 	<view class="popbox-title" v-if="list&&list.length>0">{{chooseIndex+1}}.{{list[chooseIndex].name}}</view>
			 	<view class="popbox-desc" v-if="list&&list.length>0">选项：{{list[chooseIndex].question[chooseItemIdx].name}}</view>
			 	<view class="uni-textarea-wrapper">
			 		<textarea class="textarea" placeholder-style="font-size: 28rpx;" :focus="focus" placeholder="请输入相关描述" :value="writeVal" @input="handleinput"/>
			 		<view class="popbox-confirm-btn" @click="popSubmit">确认</view>
			 	</view>
			 </view>
		</u-popup>
		 
		<!-- footer -->
		<view class="footer">
			<button class="footer-btn" :loading="btnLoading" :disabled="btnLoading" @click="handelSubmit">
				{{this.formType=='dietList' || this.formType=='sleepList'||this.formType=='sportList' ? '提交':'提交健康档案'}}
			</button>
		</view>
	</view>
</template>

<script>
	import {getUserInfo} from '@/api/user';
	import {
		myRecord,
		healthHistoryTempList,
		addRecord,
		addFsHealthLife,
		HealthLife,
	} from "@/api/healthRecords.js"
	export default {
		data() {
			return {
				isShare:null,
				baseUrl:uni.getStorageSync('requestPath'),
				show:false,
				patient:null,
				focus: false,
				chooseIndex: 0,
				chooseItemIdx: 0,
				writeVal: "",
				inputValue: "",
				btnLoading: false,
				formType: "",
				defaultHeadimg: uni.getStorageSync('requestPath')+"/images/healthRecords/my_heads_icon.png",
				title: "快速填写健康档案",
				user: {},
				defaultList: [
					{
						name: "目前是否有以下不适？",
						questionType: "symptomHistory",
						type: 2,
						value: "",
						required: true,
						question: [
							{
								name: "无",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},
							{
								name: "头晕",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},
							{
								name: "头痛",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "容易疲劳",
								value: 4,
								isWrite: 0,
								writeVal: ""
							},{
								name: "记忆力下降",
								value: 5,
								isWrite: 0,
								writeVal: ""
							},{
								name: "咳嗽",
								value: 6,
								isWrite: 0,
								writeVal: ""
							},{
								name: "咳痰",
								value: 7,
								isWrite: 0,
								writeVal: ""
							},{
								name: "呼吸困难",
								value: 8,
								isWrite: 0,
								writeVal: ""
							},{
								name: "胸痛",
								value: 9,
								isWrite: 0,
								writeVal: ""
							},{
								name: "心悸",
								value: 10,
								isWrite: 0,
								writeVal: ""
							},{
								name: "腹痛",
								value: 11,
								isWrite: 0,
								writeVal: ""
							},{
								name: "腹胀",
								value: 12,
								isWrite: 0,
								writeVal: ""
							},{
								name: "便秘",
								value: 13,
								isWrite: 0,
								writeVal: ""
							},{
								name: "腹泻",
								value: 14,
								isWrite: 0,
								writeVal: ""
							},{
								name: "食欲差",
								value: 15,
								isWrite: 0,
								writeVal: ""
							},{
								name: "骨痛",
								value: 16,
								isWrite: 0,
								writeVal: ""
							},{
								name: "尿频、尿急、尿不尽",
								value: 17,
								isWrite: 0,
								writeVal: ""
							},{
								name: "其它",
								value: 18,
								isWrite: 1,
								writeVal: ""
							},
						]
					},{
						name: "您父母或直系亲属是否有以下疾病？",
						questionType: "familyHistory",
						type: 2,
						value: "",
						required: true,
						question: [
							{
								name: "无",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "糖尿病",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "高血压",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "心脑血管病",
								value: 4,
								isWrite: 0,
								writeVal: ""
							},{
								name: "高脂血症",
								value: 5,
								isWrite: 0,
								writeVal: ""
							},{
								name: "肥胖",
								value: 6,
								isWrite: 0,
								writeVal: ""
							},{
								name: "其它",
								value: 7,
								isWrite: 1,
								writeVal: ""
							},
						],
					},
					{
						name: "目前是否在用其它疾病的药品？",
						questionType: "drugHistory",
						type: 1,
						value: "",
						required: false,
						question: [
							{
								name: "无",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "有",
								value: 2,
								isWrite: 1,
								writeVal: ""
							},
						],
					},{
						name: "用药是否出现了不良反应？",
						questionType: "drugHistory",
						type: 1,
						value: "",
						required: false,
						question: [
							{
								name: "无",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "有",
								value: 2,
								isWrite: 1,
								writeVal: ""
							},
						],
					},{
						name: "是否对药物或某些物质过敏？",
						questionType: "allergyHistory",
						type: 1,
						value: "",
						required: false,
						question: [
							{
								name: "无",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "有",
								value: 2,
								isWrite: 1,
								writeVal: ""
							},
						],
					}
				],
				list: [],
				// 饮食调查
				dietList: [
					{
						name: "三餐规律",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "非常规律",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "比较规律",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "没有规律",
								value: 3,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "就餐习惯",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "暴饮暴食",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "压力大经常进食",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "就外就餐多",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "夜宵",
								value: 4,
								isWrite: 0,
								writeVal: ""
							},{
								name: "不吃早餐",
								value: 5,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "进食速度",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "大约20-30分钟",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "大约10-20分钟",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "大约5-10分钟",
								value: 3,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "酒类",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "从不喝酒",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "每天",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "大于3次/周",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "小于3次/周",
								value: 4,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "平时应酬",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "多",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "一般",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "少",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "每周多少次",
								value: 3,
								isWrite: 1,
								writeVal: ""
							}
						],
					},{
						name: "喝水量",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "低于1000ml",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "1000ml-1500ml",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "1500ml-1700ml",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "1700ml以上",
								value: 4,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "您每天吃的食物种类多吗？",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "种类非常多，12种以上",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "一般6-10种",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "种类较少3-5种",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "种类比较固定",
								value: 4,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "您是否有抽烟习惯？",
						type: 3,
						value: "",
						questionType: "dietList",
						question: [
							{
								name: "是",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "无",
								value: 2,
								isWrite: 0,
								writeVal: ""
							}
						],
					},
				],
				sleepList: [
					{
						name: "睡眠状况",
						type: 3,
						value: "",
						questionType: "sleepList",
						question: [
							{
								name: "很差",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "差",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "一般",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "良好",
								value: 4,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "睡眠时间",
						type: 3,
						value: "",
						questionType: "sleepList",
						question: [
							{
								name: "＜6小时",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "6-8小时",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "9-10小时",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "＞10小时",
								value: 4,
								isWrite: 0,
								writeVal: ""
							}
						],
					},{
						name: "经常熬夜吗？",
						type: 3,
						value: "",
						questionType: "sleepList",
						question: [
							{
								name: "经常",
								value: 1,
								isWrite: 0,
								writeVal: ""
							},{
								name: "偶尔",
								value: 2,
								isWrite: 0,
								writeVal: ""
							},{
								name: "很少",
								value: 3,
								isWrite: 0,
								writeVal: ""
							},{
								name: "无",
								value: 4,
								isWrite: 0,
								writeVal: ""
							}
						],
					},
				],
				sportList: [
						{
							name: "日常运动量",
							type: 3,
							value: "",
							questionType: "sportList",
							question: [
								{
									name: "久坐不动",
									value: 1,
									isWrite: 0,
									writeVal: ""
								},{
									name: "轻度运动(3000-6000步)",
									value: 2,
									isWrite: 0,
									writeVal: ""
								},{
									name: "中度运动(6000-10000步)",
									value: 3,
									isWrite: 0,
									writeVal: ""
								},{
									name: "大量运动(一万步以上)",
									value: 4,
									isWrite: 0,
									writeVal: ""
								}
							],
						},{
							name: "日常是否有运动？",
							type: 2,
							value: "",
							questionType: "sportList",
							question: [
								{
									name: "无",
									value: 1,
									isWrite: 0,
									writeVal: ""
								},{
									name: "散步",
									value: 2,
									isWrite: 0,
									writeVal: ""
								},{
									name: "跑步",
									value: 3,
									isWrite: 0,
									writeVal: ""
								},{
									name: "自行车",
									value: 4,
									isWrite: 0,
									writeVal: ""
								},{
									name: "舞蹈或太极拳",
									value: 5,
									isWrite: 0,
									writeVal: ""
								},{
									name: "上下楼梯",
									value: 6,
									isWrite: 0,
									writeVal: ""
								},{
									name: "球类",
									value: 7,
									isWrite: 0,
									writeVal: ""
								},{
									name: "游泳",
									value: 8,
									isWrite: 0,
									writeVal: ""
								},{
									name: "其他",
									value: 9,
									isWrite: 1,
									writeVal: ""
								}
							],
						},{
							name: "您平均每周锻炼次数？",
							type: 3,
							value: "",
							questionType: "sportList",
							question: [
								{
									name: "≤2次",
									value: 1,
									isWrite: 0,
									writeVal: ""
								},{
									name: "3-5次",
									value: 2,
									isWrite: 0,
									writeVal: ""
								},{
									name: "≥5次",
									value: 3,
									isWrite: 0,
									writeVal: ""
								}
							],
						},{
							name: "平均每次锻炼时间是多少分钟？",
							type: 3,
							value: "",
							questionType: "sportList",
							question: [
								{
									name: "≤20",
									value: 1,
									isWrite: 0,
									writeVal: ""
								},{
									name: "20-40",
									value: 2,
									isWrite: 0,
									writeVal: ""
								},{
									name: "41-60",
									value: 3,
									isWrite: 0,
									writeVal: ""
								},{
									name: "＞60",
									value: 3,
									isWrite: 0,
									writeVal: ""
								}
							],
						}
					]
			}
		},
		
		onLoad(option) {
			this.formType = option.formType
			this.isShare = option.isShare
			if(this.formType=="dietList") {
				this.list = this.dietList
			}else if(this.formType=="sleepList") {
				this.list = this.sleepList
			}else if(this.formType=="sportList") {
				this.list = this.sportList
			}else if(this.formType=="healthLife") {
				this.list = [...this.dietList,...this.sleepList,...this.sportList]
			}else {
				this.list = this.defaultList
			}
			if(option.isShare!=null){
				this.companyId=option.companyId;
				this.companyUserId=option.companyUserId;
			}
			else{
				this.companyId=uni.getStorageSync('companyId');
				this.companyUserId=uni.getStorageSync('companyUserId');	
			}
			const formTypeOption = {
				"healthHistory": "填写疾病史",
				"symptomHistory": "填写症状史",
				"familyHistory": "填写家族史",
				"drugHistory": "填写用药史",
				"allergyHistory": "填写过敏史",
				"dietList": "饮食",
				"sleepList": "睡眠情况",
				"sportList": "运动",
				"healthLife": "生活习惯", // 包括 饮食、睡眠情况、运动
			}
			this.title = formTypeOption[this.formType] || ""
			uni.setNavigationBarTitle({
				title: this.title || "",
			});
			uni.$on('refreshOrderPatient', (res) => {
				this.patient=res
			})
		},
		onShow() {
			this.user = {}
			this.$isLogin().then(
				res => {
					if(res){
						this.getUserInfo();
						
					}
				},
				rej => {}
			);
		},
		onShareAppMessage(res) {
			//禁止二次转发--
			uni.showShareMenu({
				withShareTicket: true
			});
			wx.updateShareMenu({
				isPrivateMessage: true,
				withShareTicket: true,
				success(res) {
					console.log('updateShareMenu: ', res);
				},
				fail() {}
			}); 
			//禁止二次转发--end
			return {
				title: "健康档案",
				imageUrl: 'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/sharelogo.png',
				path: "/pages_user/healthRecords/add?isShare=1&formType="+this.formType+"&companyId="+this.companyId+"&companyUserId="+this.companyUserId,
			}
		},
		methods: {
			getUserInfo(){
				getUserInfo().then(
					res => {
						if(res.code==200){
							if(res.user!=null){
								this.user=res.user;
								if(this.formType!="dietList" && this.formType!="sleepList"&&this.formType!="sportList"&& this.formType!='healthLife') {
									this.getHealthHistoryTempList()
								}else {
									this.getHealthLife()
								}
								this.getMyRecord();
							}
						}else{
							uni.showToast({
								icon:'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			addPatient(){
				uni.navigateTo({
					url: '/pages_user/patient'
				})
			},
			handleEdit(index,i) {
				this.chooseIndex = index
				this.chooseItemIdx = i
				this.focus = true
				this.writeVal = this.list[index].question[i].writeVal
				this.show=true;
			},
			close() {
				this.focus = false
				this.show=false;
			},
			// 输入
			handleinput(e) {
				this.writeVal = e.detail.value
			},
			popSubmit() {
				this.list[this.chooseIndex].question[this.chooseItemIdx].writeVal = this.writeVal
				this.close()
			},
			// 每周喝多少次
			clearInput(event,option) {
				this.inputValue = event.detail.value;
				option.writeVal = this.inputValue
			},
			// 健康档案
			getMyRecord() {
				myRecord().then(res => {
						if (res.code == 200) {
							if(res.data) {
								if(this.isShare!=null){
									uni.showToast({
										icon:'none',
										title: "您已填写过档案",
									});
									setTimeout(function(){
										uni.redirectTo({
											url:"/pages_user/healthRecords/index"
										})
									},2000);
									
								}
							} else {
								 
							}
						} else {
							uni.showToast({
								icon:'none',
								title: res.msg,
							});
						}
						 
					},
					rej => {}
				)
			},
			// 健康生活
			getHealthLife() {
				const param = {
					userId: this.user.userId
				}
				HealthLife(param).then(res => {
						if (res.code == 200 && res.data) {
							
							this.dietList = res.data.eat ? JSON.parse(res.data.eat) : this.dietList
							this.sleepList = res.data.sleep ? JSON.parse(res.data.sleep) : this.sleepList
							this.sportList = res.data.sport ? JSON.parse(res.data.sport) : this.sportList
							
							if (this.formType == "healthLife") {
								this.list = [...this.dietList,...this.sleepList,...this.sportList]
							} else {
								this.list = this.formType == "dietList" ? this.dietList : this.formType == "sleepList" ? this.sleepList : this.formType == "sportList" ? this.sportList : []
							}
						}
					},
					rej => {}
				)
			},
			getHealthHistoryTempList() {
				healthHistoryTempList().then(res => {
						let list = []
						if (res.code == 200 && res.data && res.data.length > 0) {
							list = res.data.map(item => ({
							    ...item,
							    value: item.value || "",
								required: true,
							    question: JSON.parse(item.question).map((it, i) => ({
							        ...it,
							        writeVal: ""
							    }))
							}));
						}
						this.list = list.concat(this.defaultList)
					},
					rej => {}
				);
			},
			// 单选
			handleChoose(item,option) {
				if(this.patient==null&&this.formType!="dietList" && this.formType!="sleepList"&&this.formType!="sportList"&& this.formType!='healthLife'){
					uni.showToast({
						icon:'none',
						title: "请选择就诊人",
					});
					return;
				}
				if(item.name == '平时应酬' && option.name === '每周多少次') return
				item.value = option.name
			},
			// 多选
			handleMultiple(item,index,option) {
				if(this.patient==null&&this.formType!="dietList" && this.formType!="sleepList"&&this.formType!="sportList"&& this.formType!='healthLife'){
					uni.showToast({
						icon:'none',
						title: "请选择就诊人",
					});
					return;
				}
				const arry = item.value ? item.value.split(',') : []
				if(arry.indexOf(option.name) === -1) {
					arry.push(option.name)
					item.value = arry.join(',')
				} else {
					arry.splice(arry.indexOf(option.name),1)
					item.value = arry.join(',')
				}
			},
			// 提交健康档案
			handelSubmit() {
				if(this.patient==null && this.formType!="dietList" && this.formType!="sleepList"&&this.formType!="sportList"&& this.formType!='healthLife'){
					uni.showToast({
						icon:'none',
						title: "请选择就诊人",
					});
					return;
				}
				for (let i = 0; i < this.list.length; i++) {
				// 检查当前项的字段是否有值
				if (!this.list[i].value) {
					uni.showToast({
						title: "请检查健康档案是否填写完整",
						icon: "none"
					})
				  return
				}
			  }
			  const arry = this.list.map((item, index) => ({
			    id: index + 1,
			    name: item.name,
			    sort: item.sort,
			    type: item.type,
			    value: item.value,
			    questionType: item.questionType,
				question: item.question.map(it=>({
						...it,
						writeVal: item.value.indexOf(it.name) == -1 && item.name != '平时应酬' && it.name != '每周多少次' ? '' : it.writeVal    // 清空没有选中的选项输入的文字，（除了应酬次数）
					}))
			  }));
			
			  if(this.formType=="dietList" || this.formType=="sleepList" || this.formType=="sportList" || this.formType=='healthLife') {
			  	this.submitHealthLife(arry)
			  } else {
			  	this.addHealthForm(arry)
			  } 
			},
			// 新增修改生活习惯
			submitHealthLife(arry) {
				// 判断字符串为正整数
				const reg = /^[1-9]\d*$/
				if(this.inputValue && !reg.test(this.inputValue)) {
					uni.showToast({
						title: "请输入正确的平时应酬次数",
						icon: "none"
					})
					return
				}
				const filterByQuestionType = (questionType) => arry.filter(item => item.questionType && item.questionType === questionType);
				
				const eat = filterByQuestionType("dietList");
				const sleep = filterByQuestionType("sleepList");
				const sport = filterByQuestionType("sportList");
				
				const param = {
					eat: eat && eat.length > 0 ? JSON.stringify(eat) : JSON.stringify(this.dietList),
					sleep: sleep && sleep.length > 0 ? JSON.stringify(sleep) : JSON.stringify(this.sleepList),
					sport: sport && sport.length > 0 ? JSON.stringify(sport) : JSON.stringify(this.sportList),
				}
				addFsHealthLife(param).then(res => {
					this.btnLoading = false
						if (res.code == 200) {
							uni.showToast({
								title: "保存成功",
								icon: 'none',
								duration: 1000,
							});
							var timer = setTimeout(function() {
								uni.redirectTo({
									url: "/pages_user/healthRecords/index"
								});
								clearTimeout('timer')
							}, 1000)
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none"
							})
						}
					},
					rej => {
						this.btnLoading = false
					}
				).catch(()=>{
					this.btnLoading = false
				});
			},
			// 新增健康史
			addHealthForm(arry) {
				const filterByQuestionType = (questionType) => arry.filter(item => item.questionType && item.questionType === questionType);
				
				const symptomHistory = filterByQuestionType("symptomHistory");
				const drugHistory = filterByQuestionType("drugHistory");
				const allergyHistory = filterByQuestionType("allergyHistory");
				const familyHistory = filterByQuestionType("familyHistory");
				const healthHistory = arry.filter(item => !item.questionType);
				var companyUserId=this.companyUserId;
				var companyId=this.companyId;
				const param = {
				  companyId:companyId,
				  companyUserId:companyUserId,
				  name: this.patient.patientName,
				  sex: this.patient.sex, // this.patient.sex1男2女
			      age: this.$getAge(this.patient.birthday),
				  weight: undefined,
				  height: undefined,
				  bmi: undefined,
				  symptomHistory: JSON.stringify(symptomHistory), // 症状史
				  healthHistory: JSON.stringify(healthHistory), // 健康史
				  drugHistory: JSON.stringify(drugHistory), // 用药史
				  allergyHistory: JSON.stringify(allergyHistory), // 过敏史 
				  familyHistory: JSON.stringify(familyHistory) // 家族史
				};
				
				this.btnLoading = true
				addRecord(param).then(res => {
				   this.btnLoading = false
						if(res.code == 200) {
							uni.showToast({
								title: "提交健康档案成功",
								icon: 'none',
								duration: 1000,
							});
							var timer = setTimeout(function() {
								uni.redirectTo({
									url: "/pages_user/healthRecords/index"
								});
								clearTimeout('timer')
							}, 1000)
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none"
							})
						}
					},
					rej => {this.btnLoading = false}
				).catch(()=>{
					this.btnLoading = false
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	 
	.container {
		position: relative;
		font-family: PingFang SC, PingFang SC;
		.jkda_top_bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: auto;
		}
		&-body {
			position: relative;
			padding: 32rpx 24rpx;
			padding-bottom: calc(var(--window-bottom) + 152rpx);
		}
	}
	.userbox {
		padding: 32rpx;
		margin-bottom: 20rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		overflow: hidden;
		.userbind {
			width: 100%;
			padding: 8rpx 0;
			font-weight: 400;
			font-size: 34rpx;
			color: #FF5C03;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			image {
				width: 48rpx;
				height: 48rpx;
				margin-right: 16rpx;
			}
		}
		&-headimg {
			flex-shrink: 0;
			width: 140rpx;
			height: 140rpx;
		}
		&-left {
			flex-shrink: 0;
			flex: 1;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
		}
		&-name {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			flex-wrap: wrap;
			gap: 0 30rpx;
		}
		&-idcard {
			font-weight: 500;
			font-size: 28rpx;
		}
		&-info {
			margin-left: 24rpx;
			font-weight: 600;
			font-size: 32rpx;
			color: #222222;
			&-tag {
				margin-top: 30rpx;
				font-weight: 400;
				font-size: 22rpx;
				color: #FF5C03;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-start;
				view {
					min-width: 62rpx;
					height: 42rpx;
					padding: 0 20rpx;
					box-sizing: border-box;
					background: #FCF0E7;
					border-radius: 24rpx 24rpx 24rpx 24rpx;
					text-align: center;
					line-height: 42rpx;
					margin-right: 14rpx;
				}
			}
		}
	}
	.listbox {
		padding: 32rpx 24rpx;
		margin-bottom: 20rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #222222;
		&-titlebox {
			font-weight: 600;
			font-size: 34rpx;
			white-space: normal;
		}
		&-titletag {
			min-width: 80rpx;
			height: 40rpx;
			padding: 0 16rpx;
			margin: 0 12rpx;
			flex-shrink: 0;
			box-sizing: border-box;
			line-height: 40rpx;
			text-align: center;
			background: #FF5C03;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			font-weight: 400;
			font-size: 24rpx;
			color: #FFFFFF;
			display: inline-block;
		}
		&-option {
			margin-top: 34rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			flex-wrap: wrap;
			gap: 18rpx;
			&-flex {
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-start;
				gap: 18rpx;
			}
			&-item {
				display: inline-flex;
				min-width: 206rpx;
				min-height: 72rpx;
				padding: 16rpx;
				box-sizing: border-box;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				border: 2rpx solid #ECECEC;
				align-items: center;
				justify-content: center;
			}
		}
		.otherinput {
			width: 430rpx;
			height: 72rpx;
			overflow: hidden;
			padding: 16rpx 24rpx;
			box-sizing: border-box;
			background: #F5F7FA;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #999999;
			justify-content: flex-start;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
		.option-active{
			font-weight: 400;
			font-size: 28rpx;
			color: #FF5C03;
			background: #FCF0E7;
			border: 2rpx solid #FF5C03;
		}
		&-choose {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			min-height: 86rpx;
			image {
				flex-shrink: 0;
				width: 36rpx;
				height: 36rpx;
				margin-right: 18rpx;
			}
		}
		.choose-input {
			width: 430rpx;
			height: 72rpx;
			padding: 16rpx 24rpx;
			box-sizing: border-box;
			margin-left: 42rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			border: 2rpx solid #ECECEC;
			display: inline-flex;
			align-items: center;
			justify-content: flex-start;
			font-weight: 400;
			font-size: 28rpx;
			color: #999999;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
		.dietary-survey {
			display: flex;
			flex-direction: row;
			align-items: flex-start;
			justify-content: flex-start;
			flex-wrap: wrap;
			gap: 18rpx;
			margin-top: 36rpx;
		}
		.dietary-survey-iteml {
			width: 206rpx;
			display: inline-flex;
			flex-direction: column;
			align-items: center;
			font-weight: 400;
			font-size: 32rpx;
			view {
				width: 206rpx;
				height: 90rpx;
				background: #F5F7FA;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				border: 2rpx solid #ECECEC;
				box-sizing: border-box;
				margin-bottom: 20rpx;
				text-align: center;
				line-height: 90rpx;
			}
			
			text {
				font-size: 24rpx;
				color: #757575;
			}
		}
		.dietary-survey-item {
			display: inline-flex;
		}
		.dietary-survey-input {
			height: 90rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			display: inline-flex;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #757575;
			.uni-input {
				width: 100rpx;
				height: 72rpx;
				padding: 0 10rpx;
				text-align: center;
				box-sizing: border-box;
				margin: 0 10rpx;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				border: 2rpx solid #ECECEC;
			}
		}
		.dietary-survey-active {
			color: #fff !important;
			background: #FF5C03 !important;
			border: 2rpx solid #FF5C03 !important;
		}
	}
	.footer {
		width: 100%;
		height: 152rpx;
		padding: 20rpx 24rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		box-shadow: 0rpx -6rpx 8rpx 0rpx rgba(114,114,114,0.1);
		position: fixed;
		bottom: var(--window-bottom);
		left: 0;
		&-btn {
			height: 112rpx;
			background: #FF5C03;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			font-weight: 600;
			font-size: 34rpx;
			color: #FFFFFF;
			line-height: 112rpx;
			text-align: center;
			&::after {
				border: none;
			}
		}
	}
	.popbox {
		background: #fff;
		padding: 20rpx;
		font-family: PingFang SC, PingFang SC;
		color: #222222;
		font-weight: 400;
		font-size: 28rpx;
		&-title {
			font-weight: 600;
			font-size: 34rpx;
		}
		&-desc {
			margin: 20rpx 0;
		}
		.uni-textarea-wrapper {
			display: flex;
			flex-direction: row;
			align-items: flex-end;
			justify-content: space-between;
		}
		.textarea {
			flex: 1;
			max-height: 146rpx;
			padding: 15rpx 24rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			line-height: 36rpx;
			border: 2rpx solid #ECECEC;
			color: #222222;
			font-weight: 400;
			font-size: 28rpx;
		}
		.popbox-confirm-btn {
			flex-shrink: 0;
			width: 140rpx;
			height: 70rpx;
			margin-left: 10rpx;
			background: #FF5C03;
			border-radius: 16rpx;
			color: #fff;
			text-align: center;
			line-height: 70rpx;
		}
	}
</style>