<template>
	<view class="container">
		<view class="page">
			<view class="housing">
				<view class="steps">
					<view class="item active">
						<view class="uni-icons"><uni-icons type="home-filled" size="20" color="#6A59F2"></uni-icons>
						</view>
						<view class="name">房屋信息</view>
					</view>
					<view class="dotted dottedActive"></view>
					<view class="item active">
						<view class="uni-icons"><uni-icons type="person-filled" size="20" color="#6A59F2"></uni-icons>
						</view>
						<view class="name">住户信息</view>
					</view>
					<view class="dotted"></view>
					<view class="item">
						<view class="uni-icons"><uni-icons type="auth-filled" size="20" color="#B5B8ED"></uni-icons>
						</view>
						<view class="name">物业审核</view>
					</view>
					<view class="dotted"></view>
					<view class="item">
						<view class="uni-icons"><uni-icons type="checkbox-filled" size="20" color="#B5B8ED"></uni-icons>
						</view>
						<view class="name">认证成功</view>
					</view>
				</view>
				<view class="form">
					<uni-forms>
						<view class="form-item">
							<view class="form-item-fl">
								<view class="asterisk">*</view>与业主关系
							</view>
							<view class="form-item-fr">
								<picker @change="e=>bindPickerChange(e, 'relationShip')" range-key="label" :value="formData.relationShip" :range="relationShipList" class="form-item-tit">
									<view class="uni-input">{{relationShipList[Number(formData.relationShip)].label || '请选择与业主关系'}}</view>
								</picker>
								<uni-icons type="forward" color="#E4E4EA"></uni-icons>
							</view>
						</view>
						<view class="form-item">
							<view class="form-item-fl">
								<view class="asterisk">*</view>{{formData.relationShip === '1' ? '业主' : '住户'}}姓名
							</view>
							<view class="form-item-fr">
								<input class="form-item-tit" readonly v-model="formData.residentName" focus placeholder="请输入姓名" />
							</view>
						</view>
						<view class="form-item">
							<view class="form-item-fl">
								<view class="asterisk">*</view>联系方式
							</view>
							<view class="form-item-fr">
								<input class="form-item-tit" v-model="formData.residentPhone" focus placeholder="请输入手机号码" />
							</view>
						</view>
						<view class="form-item">
							<view class="form-item-fl">
								<view class="asterisk"></view>证件类型
							</view>
							<view class="form-item-fr">
								<picker @change="e=>bindPickerChange(e, 'certificate')" range-key="label" :value="formData.certificateType" :range="certificateList" class="form-item-tit">
									<view class="uni-input">{{certificateList[formData.certificateType].label || '请选择证件类型'}}</view>
								</picker>
								<uni-icons type="forward" color="#E4E4EA"></uni-icons>
							</view>
						</view>
						<view class="form-item">
							<view class="form-item-fl">
								<view class="asterisk"></view>证件号码
							</view>
							<view class="form-item-fr">
								<input class="form-item-tit" v-model="formData.certificateNo" focus placeholder="请输入证件号码" />
							</view>
						</view>
						<view class="form-item">
							<view class="form-item-fl">
								<view class="asterisk"></view>住户性别
							</view>
							<view class="form-item-fr">
								<uni-data-checkbox v-model="formData.sex" :localdata="sexs" class="form-item-tit" />
							</view>
						</view>
					</uni-forms>
				</view>

				<view class="form-submit" @click="toAudit()">提交审核</view>
			</view>
		</view>
	</view>
</template>

<script>
import {
	postcommunityOwnerAddApi
} from '@/config/api.js'
export default {
	data() {
		return {
			formData: {
				relationShip: '1',
				residentName: '',
				residentPhone: '',
				sex: '',
				certificateType: '',
				certificateNo: ''
			},
			sexs: [{
				text: '男',
				value: 0
			}, {
				text: '女',
				value: 1
			}],
			
			relationShipList: [
				{label: '本人', value: '1'},
				{label: '租户', value: '2'},
				{label: '亲人', value: '3'},
				{label: '朋友', value: '4'}
			],
			certificateList: [
				{label: '身份证', value: '1'},
				{label: '港澳通行证', value: '2'},
				{label: '护照', value: '3'}
			]
		}
	},
	methods: {
		bindPickerChange(e, type) {
			if(type === 'certificate') {
				this.formData.certificateType = e.detail.value
			} else {
				this.formData.relationShip = e.detail.value
			}
		},
		toAudit() {
			let data = getApp().globalData.registerInfo
			postcommunityOwnerAddApi({ ...data, ...this.formData}).then(res=> {
				getApp().globalData.registerInfo = { ...data, ...this.formData}
				console.log(getApp().globalData.registerInfo)
				uni.showToast({
					icon: "none",
					title: res.message
				})
				setTimeout(()=> {
					uni.navigateTo({
						url: '/pages/housingAudit/index',
					});
				}, 1500)
			})
		}
	},
	onLoad() {
		this.formData.residentPhone = uni.getStorageSync('user_phone')
	},
	onShow() {

	}
}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.page {
		padding: 30rpx;
	}

	.housing {
		.steps {
			display: flex;
			justify-content: space-between;
			background-color: #ffffff;
			border-radius: 16rpx;
			padding: 30rpx;
			margin-bottom: 30rpx;

			.item {
				display: flex;
				flex-wrap: wrap;
				justify-content: center;

				.uni-icons {
					text-align: center;
					width: 60rpx;
					height: 60rpx;
					border-radius: 60rpx;
					border: 1px solid #B5B8ED;
					line-height: 60rpx;
				}

				.name {
					margin-top: 10rpx;
					font-size: 28rpx;
					color: #9D9CA6;
				}

			}

			.active {
				.uni-icons {
					border: 1px solid #6A59F2;
				}

				.name {
					color: #373737;
				}
			}

			.dotted {
				margin-top: 28rpx;
				width: 40px;
				height: 1px;
				border-bottom: 1px dashed #B5B8ED;
			}

			.dottedActive {
				border-bottom: 1px solid #6A59F2;
			}
		}

		.form {
			background-color: #ffffff;
			border-radius: 16rpx;
			padding: 30rpx;
			margin-bottom: 30rpx;

			.form-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 84rpx;
				line-height: 84rpx;
				border-bottom: 1px solid #F8F6F9;
				overflow: hidden;
			}

			.form-item-fl {
				font-size: 28rpx;
				color: #373737;
				display: flex;

				.asterisk {
					color: #F42E2E;
					width: 10rpx;
					margin-right: 6rpx;
				}

			}

			.form-item-fr {
				display: flex;
				flex: 2;
				align-items: center;
				justify-content: flex-end;
				margin-left: 20rpx;
			}

			.form-item-tit {
				font-size: 28rpx;
				color: #666;
				margin-right: 20rpx;
				text-align: right;
			}
		}
	}

	.form-submit {
		height: 80rpx;
		line-height: 80rpx;
		background-color: #6A59F2;
		border-radius: 80rpx;
		width: 100%;
		text-align: center;
		font-size: 28rpx;
		color: #FFFFFF;
	}
</style>