<template>
	<view class="warpper">
		<view class="qn-form-item">
			<view class="label"><text class="label__text">收货人</text></view>
			<view class="value">
				<qn-easyinput :maxlength="20" @blur="showCompany" v-model="form.name" :inputBorder="false" text="left" placeholder="请填写收货人姓名"></qn-easyinput>
			</view>
		</view>
		<view class="qn-form-item">
			<view class="label"><text class="label__text">手机号</text></view>
			<view class="value">
				<qn-easyinput :maxlength="11" type="number" v-model="form.contactMobile" :inputBorder="false" text="left" placeholder="请填写收货人手机号"></qn-easyinput>
			</view>
		</view>
		<view class="qn-form-item">
		 <view class="label"><text class="label__text">所在地区</text></view>
			<view class="value">
				<!-- <qn-easyinput v-model="form.shortName" :inputBorder="false" text="right" placeholder="选择所在区域"></qn-easyinput> -->
				<qn-data-picker
					:readonly="hasSelected"
					text="left"
					:border="false"
					class="qn-picker"
					placeholder="点击选择"
					popup-title="请选择城市"
					:map="{ text: 'name', value: 'id' }"
					@change="onAreaChange"
					:clear-icon="true"
					:localdata="items"
				>
					<text v-if="form.locDistrictId">{{ `${form.locProvinceName || ''}/${form.locCityName || ''}/${form.locDistrictName || ''}/${form.locStreetName || ''}` }}</text>
				</qn-data-picker>
			</view>
		</view>
		<view class="qn-form-item">
			<view class="label"><text class="label__text">详细地址</text></view>
			<view class="value">
				<qn-easyinput :maxlength="120" @blur="showCompany" v-model="form.name" :inputBorder="false" text="left" placeholder="街道/门牌号/小区/乡镇/村等"></qn-easyinput>
			</view>
		</view>
		<uGap></uGap>
		<view class="default-address">
			<view class="">
				<view class="title">设置为默认地址</view>
				<view class="tip">提醒：每次下单会默认使用该地址</view>
			</view>
			<view class="">
				  <switch checked style="transform:scale(0.8)"/>
			</view>
		</view>
		<qn-footer fixed height="120rpx">
			<view class="button-area">
				<!-- <view class="button button__cancel" @click="back">
		  <text class="text">取消</text>
		</view> -->
				<view class="button button__submit" @click="addTap"><text class="text" style="color: white">保存</text></view>
			</view>
		</qn-footer>
	</view>
</template>

<script>
import uGap from '@/components/u-gap/u-gap.vue'
import { getArea } from '@/apis/commonApi.js'
import qnFooter from '@/components/qn-footer/qn-footer.vue'
import qnDataPicker from '@/components/qn-data-picker/qn-data-picker.vue'
export default {
	components: { uGap, qnFooter, qnDataPicker },
	data() {
		return {
			form: {
				name: null,
				contactMobile: null,
				locProvinceId: null,
				locCityId: null,
				locDistrictId: null,
				locProvinceName: null,
				locCityName: null,
				locDistrictName: null
			},
			hasSelected: false,
			items: []
		}
	},
	mounted() {
		getArea().then(res => {
			if (res) {
				this.items = res
			}
		})
	},
	onLoad() {},
	methods: {
		onAreaChange(e) {
			if (e.detail.value && e.detail.value.length > 0) {
				const [province, city, district, street] = e.detail.value
				this.form.locProvinceId = province.value
				this.form.locProvinceName = province.text
				this.form.locCityId = city.value
				this.form.locCityName = city.text
				this.form.locDistrictId = district.value
				this.form.locDistrictName = district.text
				this.form.locStreetId = street.value
				this.form.locStreetName = street.text
			} else {
				this.form.locProvinceId = null
			 this.form.locProvinceName = null
				this.form.locCityId = null
				this.form.locCityName = null
				this.form.locDistrictId = null
				this.form.locDistrictName = null
				this.form.locStreetId = null
				this.form.locStreetName = null
			}
		},
		showCompany() {},
		// 保存
		addTap() {}
	}
}
</script>

<style lang="scss" scoped>
.warpper {
	.qn-form-item {
		width: 750rpx;
		padding: 0rpx 32rpx;
		background-color: #fff;
		display: flex;
		flex-direction: row;
		align-items: center;
		// justify-content: space-between;
		border-bottom: 2rpx solid #d8d8d8;
		min-height: 88rpx;
		.label {
		 flex-grow: 0;
			flex-shrink: 0;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: flex-start;
			margin-right: 20rpx;
			.label__text {
				font-size: 28rpx;
				color: #000000;
			}
		}
		.value {
			flex-grow: 1;
			flex-shrink: 1;
			text-align: right;
		}
	}
	.default-address {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding: 0rpx 32rpx;
		height: 133rpx;
		background: #ffffff;
		.title {
			font-size: 30rpx;
			color: #333333;
			letter-spacing: 0;
			font-weight: 400;
		}
		.tip {
			padding-top: 10rpx;
			font-size: 24rpx;
			color: #888888;
			letter-spacing: 0;
			font-weight: 400;
		}
	}
	.button-area {
		width: 750rpx;
		padding: 0 32rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		// justify-content: space-between;
		.button {
			flex-grow: 0;
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 10rpx;
			.text {
				font-size: 30rpx;
				font-weight: 500;
				text-align: center;
			}
		}
		.button__cancel {
			width: 270rpx;
			height: 88rpx;
			border: 2rpx solid #979797;
		}
		.button__submit {
			width: 100%;
			height: 88rpx;
			background: #007aff;
		}
	}
}
</style>
