<template>
	<view class="app">
		<u-mask :show="usershow" class='mask'>
			<view class="information">
				<image src="../../static/information.png" mode=""></image>
				<view class="title">
					请完善个人信息
				</view>
				<view class="cancel">
					取消
				</view>
				<view class="determine">
					去完善
				</view>
			</view>
		</u-mask>
		<view class="" style="background-color: #F4F5F7;height: 20rpx;width:100%">
		</view>
		<view class="userinfo info">
			<view class="item">
				<span>姓名:</span>
				<u-input v-model="query.patientName" type="text" placeholder='' maxlength='5' />
			</view>
			<view class="item">
				<span>电话:</span>
				<u-input v-model="query.phone" maxlength='11' type="text" placeholder='' />
			</view>
			<view class="item">
				<span>身份证号:</span>
				<u-input v-model="query.cardNo" type="text" placeholder='' maxlength='18' />
			</view>
			<view class="item" @tap='areashow=true'>
				<span>所属区域:</span>
				<view>{{address}}</view>
			</view>
			<view class="item">
				<span>详细地址:</span>
				<u-input v-model="query.address" type="text" placeholder='' />
			</view>
			<view class="item" @tap='getAddress()'>
				<span>所在位置:</span>
				<view></view>
				<!-- <u-input type="text" placeholder='' /> -->
			</view>
		</view>
		<u-select v-model="areashow" mode="mutil-column-auto" label-name='areaName' value-name='areaCode'
			:list="arealist" @confirm="areaconfirm"></u-select>
		<view class="info">
			<view class="service">
				<view class="title">
					所属服务
				</view>
				<view class="Multiplechoice">
					<view :class="query.nurseTypeIdList.find(e => e == item.id)?'choices':'choice'"
						v-for="(item,index) in getNurseTypelist" :key="item.id" @tap="addnurseType(item)">
						{{item.nurseTypeName}}
					</view>
					<view @tap="godisease()" :class="query.diseaseInfoList.length>0?'choices':'choice'"
						v-for="(item,index) in medicalcarelist" :key="item.id">
						{{item.nurseTypeName}}
					</view>
				</view>
			</view>
			<u-button type="primary" style='width:30%;float: right;margin-top: 50rpx;' @tap='informationinfo'>提交
			</u-button>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getRegionAndStreetInfo,
		getNurseType,
		information
	} from '@/api/information/index.js'
	export default {
		data() {
			return {
				usershow: false, //完善信息开关
				arealist: [], //区街道list
				areashow: false, //经纬度开关
				getNurseTypelist: [], //护理类型数组
				medicalcarelist: [], //医疗护理数组
				address: '', //页面所属区域
				query: { //信息请求数组
					patientName: "",
					cardNo: "",
					phone: "",
					address: "",
					areaCode: "",
					nurseTypeIdList: [],
					diseaseInfoList: [],
				}
			};
		},
		methods: {
			//提交信息
			informationinfo() {
				information(this.query).then(res => {
					if (res.code == 200) {
						this.$refs.uToast.show({
							title: '完善信息成功',
							type: 'success',
							url: '',
							duration: '1500'
						})
						setInterval(() => {
							//TODO 
							uni.switchTab({
								url: '/pages/homepage/homepage',
							})
						}, 1500);
					} else if (res.code == 500) {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
							url: ''
						})
					}
				})
			},
			//获取所在位置
			getAddress() {
				uni.chooseLocation({
					success: function(res) {
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
					}
				});
			},
			//护理类型请求
			getNurseTypeInfo() {
				getNurseType().then(res => {
					this.medicalcarelist = res.data.filter(e => e.nurseTypeName == '医疗护理')
					this.getNurseTypelist = res.data.filter(e => e.nurseTypeName != '医疗护理')
				})
			},
			//区街道
			areaInfo() {
				getRegionAndStreetInfo().then(res => {
					//区下无街道添加一个空街道
					res.data.forEach(e => {
						if (e.children.length == 0) {
							e.children.push({
								areaCode: "",
								areaName: "暂无街道",
								children: null,
								id: '',
							})
						}
					})
					this.arealist = res.data;
				})
			},
			//区街道选择
			areaconfirm(e) {
				this.query.areaCode = e[e.length - 1].value
				this.address = e[0].label + '-' + e[1].label
			},
			//点击所需服务
			addnurseType(item) {
				if (this.query.nurseTypeIdList.findIndex(e => e == item.id) == -1) {
					this.query.nurseTypeIdList.push(item.id)
				} else {
					this.query.nurseTypeIdList = this.query.nurseTypeIdList.filter(e => e != item.id)
				}
			},
			godisease() {
				uni.navigateTo({
					url: `/pages/disease/disease?diseaseInfoList=${JSON.stringify(this.query.diseaseInfoList)}`
				})
			},
		},
		//进入界面加载
		onLoad() {
			this.areaInfo()
			this.getNurseTypeInfo();
		},
		//带参返回
		onShow() {
			let that = this
			uni.$on('disease', function(data) {
				that.query.diseaseInfoList = JSON.parse(data.disease)
				if (that.query.diseaseInfoList.length > 0) {
					that.medicalcarelist.forEach(e => {
						if (that.query.nurseTypeIdList.findIndex(el => el == e.id) == -1) {
							that.query.nurseTypeIdList.push(e.id)
						} else {
							that.query.nurseTypeIdList = that.query.nurseTypeIdList.filter(ele => ele != e
								.id)
						}
					})
				}
			})
		}
	}
</script>
<style lang="scss">
	.app {
		.service {
			width: 90%;
			margin: 0 auto;
			padding-bottom: 15rpx;

			.Multiplechoice {
				font-size: 32rpx;
				color: #FFFFFF;
				width: 100%;

				.choices {
					background: #4C7BC9;
					display: inline-block;
					text-align: center;
					line-height: 70rpx;
					width: 190rpx;
					height: 70rpx;
					border-radius: 26rpx;
					margin: 30rpx 30rpx 0 0;
				}

				.choice {
					display: inline-block;
					text-align: center;
					line-height: 70rpx;
					width: 190rpx;
					height: 70rpx;
					background: #BFBFBF;
					border-radius: 26rpx;
					margin: 30rpx 30rpx 0 0;
				}
			}

			.title {
				font-size: 36rpx;
				padding-top: 36rpx;
			}
		}

		.info {
			width: 94%;
			margin: 0 auto 20rpx;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			padding-bottom: 5rpx;
			box-shadow: 0px 9rpx 31rpx 9rpx rgba(0, 0, 0, 0.03);
		}


		.userinfo {
			.item {
				width: 90%;
				margin: 0 auto;
				height: 120rpx;
				line-height: 120rpx;
				border-bottom: 1rpx solid #D8D4D4;
				display: flex;

				view {
					height: 120rpx;
					font-size: 32rpx;
					line-height: 120rpx;
				}

				span {
					display: inline-block;
					line-height: 120rpx;
					height: 120rpx;
					width: 30%;
					font-size: 32rpx;
				}

				::v-deep .u-input__input {
					height: 120rpx;
					font-size: 32rpx;
				}

				::v-deep .uni-input-wrapper {
					height: 120rpx;
					line-height: 120rpx;
				}

				::v-deep .u-input {
					width: 70%;
					height: 120rpx;
					line-height: 120rpx;
				}
			}

			.item:nth-child(6) {
				border: 0;
			}
		}

		.mask {
			.information {
				width: 70%;
				height: 400rpx;
				margin: 50% auto;
				background: #FFFFFF;
				border-radius: 30rpx;
				text-align: center;
				color: #FFFFFF;
				position: relative;

				.determine,
				.cancel {
					width: 200rpx;
					height: 70rpx;
					border-radius: 26rpx;
					font-size: 34rpx;
					line-height: 70rpx;
					position: absolute;
					top: 74%;
				}

				.determine {
					background: #4C7BC9;
					right: 36rpx;
				}

				.cancel {
					background: #C5BFBF;
					left: 36rpx;
				}

				.title {
					font-size: 42rpx;
					margin-top: 40rpx;
					color: #000000;
				}

				image {
					width: 100rpx;
					height: 100rpx;
					margin: 10% 0 0 0;
				}
			}
		}
	}
</style>
