<template>
	<view class="page-content">
		<u-loading-page :loading="loading" bg-color="#e8e8e8"></u-loading-page>
		<u--form labelWidth='auto' labelAlign="left" labelPosition="left" :model="detailform" :rules="rules"
			ref="form1">
			<u-form-item label="长者姓名" prop="name" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.name"></u--input>
			</u-form-item>
			<u-form-item label="性别" prop="sex" borderBottom @click="showSex = true; hideKeyboard()" ref="item1">
				<u--input v-model="detailform.sex" inputAlign='center' disabled disabledColor="#ffffff"
					placeholder="请选择性别" border="none">
				</u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="身份证号码" prop="idNumber" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.idNumber"></u--input>
			</u-form-item>
			<u-form-item label="年龄(由身份证自动计算)" prop="age" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="GetAgeByIdCard(detailform.idNumber)"></u--text>
			</u-form-item>
			<u-form-item label="联系电话" prop="phone" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.phone"></u--input>
			</u-form-item>
			<u-form-item label="居住状况" prop="livingStatus" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.livingStatus"></u--input>
			</u-form-item>
			<u-form-item label="经济来源" prop="econSources" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.econSources"></u--input>
			</u-form-item>
			<u-line color="#2979ff"></u-line>
			<u-form-item label="户籍省名称" prop="householdProvince" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.householdProvince"></u--input>
			</u-form-item>
			<u-form-item label="户籍州市名称" prop="householdCity" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.householdCity"></u--input>
			</u-form-item>
			<u-form-item label="户籍区县名称" prop="householdDistrict" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.householdDistrict"></u--input>
			</u-form-item>
			<u-form-item label="户籍乡镇名称" prop="householdTown" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.householdTown"></u--input>
			</u-form-item>
			<u-form-item label="户籍村名称" prop="householdVillage" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.householdVillage"></u--input>
			</u-form-item>
			<u-form-item label="户籍街镇名称" prop="householdStreet" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.householdStreet"></u--input>
			</u-form-item>
			<u-form-item label="户籍地址" prop="householdRegisterAdd" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.householdRegisterAdd"></u--input>
			</u-form-item>
			<u-line color="#2979ff"></u-line>
			<u-form-item label="居住省名称" prop="permanentProvince" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.permanentProvince"></u--input>
			</u-form-item>
			<u-form-item label="居住州市名称" prop="permanentCity" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.permanentCity"></u--input>
			</u-form-item>

			<u-form-item label="居住区县名称" prop="permanentDistrict" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.permanentDistrict"></u--input>
			</u-form-item>
			<!-- 	<u-form-item label="居住乡镇名称" prop="permanentTown" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.permanentTown"></u--input>
			</u-form-item> -->
			<u-form-item label="居住街镇名称" prop="permanentStreet" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.permanentStreet"></u--input>
			</u-form-item>
			<u-form-item label="居住村名称" prop="permanentVillage" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.permanentVillage"></u--input>
			</u-form-item>
			<u-form-item label="居住地址" prop="permanentResidenceAdd" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.permanentResidenceAdd"></u--input>
			</u-form-item>
			<u-line color="#2979ff"></u-line>
			<u-form-item label="紧急联系人姓名" prop="emergencyContactName" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.emergencyContactName">
				</u--input>
			</u-form-item>
			<u-form-item label="紧急联系人电话" prop="emergencyContactPhone" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.emergencyContactPhone">
				</u--input>
			</u-form-item>
			<u-form-item label="紧急联系人与老年人关系" prop="emergencyContactKinship" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.emergencyContactKinship">
				</u--input>
			</u-form-item>
			<u-line color="#2979ff"></u-line>
			<u-form-item label="意识水平测评" prop="consciousnessLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.consciousnessLevel">
				</u--input>
			</u-form-item>
			<u-form-item label="沟通交流测评" prop="communicationLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.communicationLevel">
				</u--input>
			</u-form-item>
			<u-form-item label="视力测评" prop="eyesightLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.eyesightLevel">
				</u--input>
			</u-form-item>
			<u-form-item label="听力测评" prop="hearingLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.hearingLevel"></u--input>
			</u-form-item>
			<u-form-item label="认知功能测评" prop="acknowledgeLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.acknowledgeLevel">
				</u--input>
			</u-form-item>
			<u-form-item label="攻击行为测评" prop="attackLvel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.attackLvel"></u--input>
			</u-form-item>
			<u-form-item label="抑郁症状测评" prop="depressionLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.depressionLevel">
				</u--input>
			</u-form-item>
			<u-form-item label="工作能力测评" prop="workcapabilityLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.workcapabilityLevel">
				</u--input>
			</u-form-item>
			<u-form-item label="人物定向测评" prop="directionalLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.directionalLevel">
				</u--input>
			</u-form-item>
			<u-form-item label="社会交往能力测评" prop="relationshipLevel" borderBottom ref="item1">
				<u--input customStyle="font-weight: bold;margin: 5px;" inputAlign='center' shape='square' border="none"
					v-model="detailform.relationshipLevel">
				</u--input>
			</u-form-item>
		</u--form>
		<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" type="primary" size="small" @click="handel_submit_click" text="提交">
				</u-button>
			</u-col>
		</u-row>
		<u-action-sheet :show="showSex" :actions="actions" title="请选择性别" @close="showSex = false" @select="sexSelect">
		</u-action-sheet>

	</view>
</template>

<script>
	import {
		transformPostBody,
		transformRequestURL
	} from "@/utils/requestParams.js";
	import {
		QueryRTInfoList,
		addRTInfo,
		updateRTInfo,
		getRTInfo,
		delRTInfo,
		QueryRTInfoHistory
	} from "@/api/elder/RTInfo.js";
	import {
		GetAgeByIdCard
	} from "@/utils/stringFormat.js";

	export default {
		data() {
			return {
				GetAgeByIdCard: GetAgeByIdCard,
				detailform: { //需要验证的属性必须设置，不能为空
					name: '', //老人姓名
					sex: '', //性别
					idNumber: '', //身份证号码
				},
				loading: false, //加载中
				id: null,
				showSex: false,
				actions: [{
						name: '男',
					},
					{
						name: '女',
					},
				],
				rules: {
					name: {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					idNumber: {
						type: 'string',
						required: true,
						message: '请填写身份证号',
						trigger: ['blur', 'change']
					},
					sex: {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择男或女',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad: function() {},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.form1.setRules(this.rules)
		},
		computed: {},
		methods: {
			sexSelect(item) {
				this.detailform.sex = item.name
			},
			handel_submit_click() {
				this.$refs.form1.validate().then(res => {
					uni.$u.toast('正在提交...')
					//提交修改
					this.loading = true;
					addRTInfo(this.detailform).then((response) => {
						console.log("addRTInfo", response);
						if (response.code != 200) {
							uni.$u.toast(response.msg)
							this.loading = false;
						} else {
							this.loading = false;
							this.$tab.navigateBack();
						}
					});
				}).catch(errors => {
					uni.$u.toast('校验失败,请修改后再尝试提交')
				})
			}
		},
	}
</script>

<style lang="scss">
	page {
		background-color: white;
		display: flex;
		justify-content: center;
	}

	.page-content {
		width: 93%;
	}

	.custom-style {
		width: 80%;
		font-size: 20px;
		font-weight: bolder;
	}
</style>