<template>
	<view class="content">
		<view class="box" @click="chooseAddress">
			<view class="box-left">
				常用地址
			</view>
			<view class="box-right">
				<!-- <input type="text" value="请选择常用地址" class="box-input"/>
				 -->
				<view class="box-input">
					{{addressDetail||'请选择常用地址'}}
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getcomAddress
	} from '@/api/index.js';
	export default {
		data() {
			return {
				addressDetail: '',
				addressData: {
					name: '',
					mobile: '',
					latitude: 0, //纬度
					longitude: 0, //经度
					address: {
						province: '',
						city: '',
						district: '',
						detail: '',
					},
					area: '',
					default: false
				},
			}
		},
		onLoad(option){
			console.log('传过来的值',option.add)
			if (option.add == 'null'){
				this.addressDetail = '请选择常用地址'
			} else {
				this.addressDetail = option.add
			}
			// this.addressDetail = option.add
		},
		methods: {
			chooseAddress() {
				console.log('233')
				let obj = this;
				uni.chooseLocation({
					success: function(res) {
						console.log(res)
						obj.addressData.area = res.name;
						// console.log('位置名称：' + res.name);
						// console.log('详细地址：' + res.address);
						// console.log('经度：' + res.longitude);
						// console.log('纬度：' + res.latitude);
						obj.addressData.latitude = res.latitude;
						obj.addressData.longitude = res.longitude;
						obj.addressDetail = res.address;
						console.log('common_address',obj.addressDetail )
						console.log('latitude',obj.addressData.latitude )
						console.log('longitude',obj.addressData.longitude )
						getcomAddress({
							common_address: obj.addressDetail,
							longitude: obj.addressData.longitude,
							latitude: obj.addressData.latitude
						}).then(data => {
							console.log(333)
							console.log(data);
							if (data.status == 200) {
								obj.$api.msg('保存成功')
							}
						})
					}
				});







			}
		}
	}
</script>

<style lang="scss">
	.content {
		.box {
			margin-top: 24rpx;
			padding: 34rpx 32rpx;
			background-color: #FFFFFF;
			font-size: 28rpx;
			display: flex;

			.box-right {
				margin-left: 34rpx;

				.box-input {

					.input-placeholder {
						height: 70rpx;
						color: #FF9797;
					}
				}

			}
		}
	}
</style>
