<template>
	<view class="content">
		<view class="content1" v-if="!isShowMap">
			<view class="top">
				编辑地址
			</view>
			<!-- 		<view class="row flex">
				<u-radio-group placement="row" class="select-type">
					<u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1" :key="index"
						:label="item.name" :name="item.name" @change="radioChange">
					</u-radio>
				</u-radio-group>
			</view> -->
			<view class="">
				<u--form labelPosition="left" :model="addressInfo" :rules="rules" ref="form1" labelWidth='100'>
					<u-form-item label="所属区域" ref="item1" borderBottom>
						<view @click='toMap'>
							{{addressInfo.area?(addressInfo.province+addressInfo.city+addressInfo.area):'选择所属区域 '}}
						</view>
					</u-form-item>
					<u-form-item label="详细地址" prop="addressInfo.detailedAddress" ref="item1" borderBottom>
						<u--input v-model="addressInfo.detailedAddress" border="none" placeholder="详细地址"></u--input>
					</u-form-item>
					<u-form-item label="联系人" prop="addressInfo.contacts" ref="item1" borderBottom>
						<u--input v-model="addressInfo.contacts" border="none" placeholder="联系人">></u--input>
					</u-form-item>
					<u-form-item label="联系电话" prop="addressInfo.contactPhone" ref="item1">
						<u--input v-model="addressInfo.contactPhone" border="none" placeholder="联系电话">></u--input>
					</u-form-item>
				</u--form>
			</view>
		</view>
		<u-modal :show="isShowAlert" :title="alertTitle" :closeOnClickOverlay='true' :showCancelButton='true'
			confirmColor='#2772FB' @confirm="confirmClick" @close="cancelClick" @cancel="cancelClick"></u-modal>
		<view class="submit" @click="submit">提交</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				isShowAlert: false,
				alertTitle: '确定提交地址信息？',
				isShowMap: false,
				addressInfo: {
					commonId: "",
					province: "",
					city: "",
					area: "",
					detailedAddress: "",
					contacts: "",
					contactPhone: "",
					longitude: "",
					latitude: ""
				},
				rules: {
					// 'addressInfo.name': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写姓名',
					// 	trigger: ['blur', 'change']
					// },
				},

			};
		},
		onLoad(options) {
			console.log(options)
			this.addressInfo = options
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			confirmClick() {
				this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/editCargoOwnerAddress', this.addressInfo)
					.then(
						res => {
							if (res.code == 200) {
								this.$refs.uToast.show({
									type: 'success',
									message: "提交成功",
									complete() {
										// uni.$u.route('/pages/release/selectAddress');
										uni.navigateBack({
											delta:1
										})
									}
								})

							}

						})
					.catch(res => {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						})
					});
				this.isShowAlert = false
			},
			cancelClick() {
				this.isShowAlert = false
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			toMap() {
				let that = this
				// this.isShowMap = true
				uni.chooseLocation({
					success: function(res) {
						console.log(res);

						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
						let _address = that.$helper.formatLocation(res.address)
						console.log(_address)
						that.addressInfo.latitude = res.latitude
						that.addressInfo.longitude = res.longitude
						that.addressInfo.detailedAddress = _address.village
						that.addressInfo.province = _address.province
						that.addressInfo.city = _address.city
						that.addressInfo.area = _address.county
						that.addressInfo.commonId = that.userInfo.id

					}
				});
				// console.log(123)
				// uni.$u.route('/pages/release/map', {
				// 	id: 1,
				// });
			},
			submit() {
				this.isShowAlert = true

			},
		}
	}
</script>

<style lang="scss" scoped>
	.select-color{
		color: #C6CBD5;
	}
	.content{
		background: white;
		height: calc(100vh - 90rpx);
	}
	.content1 {
		padding: 40rpx;
		.top {
			font-size: 42rpx;
			font-weight: 700;
			color: rgba(0, 0, 0, 0.85);
		}
	}
	.submit{
		position: absolute;
		bottom: 40rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 80%;
		font-size: 36rpx;
		color: #FFFFFF;
		background: #2772FB;
		border-radius: 50rpx;
		padding: 20rpx 0;
		left: 0;
		right: 0;
		margin: auto;
	}
</style>

