<template>
	<view class="content">
		<view class="content-top">
			<view class='hs-box'>  
				<view class='hs-row hs-row-mid'>
					<view class='hs-row-hd'>
						姓名
					</view>
					<view class='hs-row-bd'>
						<input class='hs-input' placeholder='请填写姓名' v-model="realname" ></input>
					</view>
				</view>
				<view class='hs-row hs-row-mid'>
					<view class='hs-row-hd'>
						手机号
					</view>
					<view class='hs-row-bd'>
						<input class='hs-input' placeholder='请填写手机号' v-model="mobile" ></input>
					</view>
				</view> 
				<view class='hs-row hs-row-mid'>
					<view class='hs-row-hd'>
				   		回收区域
				   	</view>
					<view class='hs-row-bd'>
				   		<input type="text" class='hs-input' placeholder='请选择位置' v-model="address" @click="getLocation"></input>
				   	</view>
				</view>
			</view>
		</view>
		<view class="button-bottom">
			<button class="btn btn-success"   @click="submitHandler()" :disabled='submitStatus'
			 :loading='submitStatus'>保存</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return { 
				realname: "",
				address: "",
				longitude: "",
				latitude: "",
				mobile: '', 
			}
		}, 
		methods: {  
			getdata(){
				var _this = this;
				let data = { 
				}
				this.$api.userInfo(data,res=>{ 
					if(res.code == '1'){ 
						_this.realname = res.data.person.realname
						_this.address = res.data.person.address
						_this.longitude = res.data.person.longitude
						_this.latitude = res.data.person.latitude
						_this.mobile = res.data.person.mobile
						 
					}else{ 
						uni.showToast({ title: res.msg , icon: 'none' }) 
						uni.navigateBack({
						  delta: 1
						})
						return false 
					}
				})
			}, 
			getLocation(){
				uni.chooseLocation({
					success: (e) => { 
						this.address = e.name; 
						this.longitude = e.longitude
						this.latitude = e.latitude  
					},
					fail:(e)=>{
						uni.showToast({
							title:'右上角三个点设置位置授权',
							icon:'none',
						})
					}
				})
			}, 
			// 保存资料
			submitHandler() {
				this.submitStatus = true; 
					this.$api.editperson({ 
						realname: this.realname,
						address: this.address,
						longitude: this.longitude,
						latitude: this.latitude,
						mobile: this.mobile
					}, res => {
						if(res.code == '1'){
							uni.showModal({
								title: '温馨提示',
								content: res.msg 
							})  
						} else {
							uni.showToast({ title: res.msg , icon: 'none' }) ;
						}
					}, res => {
						this.submitStatus = false;
					});
				 
			}
		},
		onLoad: function() {  
			this.getdata()
		}
	}
</script>

<style>  
	.hs-row-bd {
		color: #666;
		font-size: 26upx;
	}

	.hs-row-hd {
		width: 160rpx;
	} 
</style>
