移动端地址选择组件

<template>
	<u-popup :show="showPopup" @close="closeRegion" round="12" :closeable="true">
		<view class="m-2 pb-4" style="height: 80vh;">
			<view class="pl-2 d-flex">
				<view v-for="(cu,c) in emitObj" :key="c" @click="backList(c)" class="mr-2 region-text"
					:style="{'color': cu ? '#2979ff' : '#909399'}">{{ cu ? cu.label : '请选择' }}</view>
			</view>
			<view v-for="(reg,r) in showList" :key="r">
				<view class="drop-item" @click="clickReg(r)">
					{{reg.classificationName}}
					<u-icon v-if="reg.children" name="arrow-right" size="15" color="#909399" class="ml-8">
					</u-icon>
					<u-icon v-if="emitObj[current] && reg.id === emitObj[current].id" name="checkbox-mark" size="15"
						color="#2979ff" style="position: absolute;right: 50rpx;"></u-icon>
				</view>
				<u-line></u-line>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		props: {
			showPopup: {
				type: Boolean,
				default: false
			},
			editNew: {
				type: Boolean,
				default: false
			},
			editRegion: {
				type: String,
				default: '11'
			}
		},
		data() {
			return {
				clickList: [],
				current: 0,
				regionList: this.$regionData,
				province: [],
				city: [],
				area: [],
				showList: [],
				emitObj: []
			}
		},
		methods: {
			init() {
				this.showList = this.regionList
				if (this.editNew) {
					this.current = 0
					this.emitObj.push(null)
				} else {
					let rel = this.showList
					this.$func.install.filtRegion(this.editRegion).split('-').map((reg, r) => {
						this.$set(this.emitObj, r, {
							label: reg,
							id: this.editRegion.split(',')[r]
						})
						rel.map((item, index) => {
							if (item.id === this.editRegion.split(',')[r] && item.children) {
								rel = item.children
								this.setCHil(r, item.children)
							}
						})
						this.backList(r)
					})
				}
			},
			setCHil(index, arr) {
				if (index === 0) {
					this.city = arr
				} else if (index === 1) {
					this.area = arr
				}
			},
			clickReg(r) {
				let sets = {
					label: this.showList[r].classificationName,
					id: this.showList[r].id
				}
				this.$set(this.emitObj, this.current, sets)
				if (this.showList[r].children) {
					this.setCHil(this.current, this.showList[r].children)
					this.current = this.current + 1
					if (this.emitObj[this.current]) {
						this.$set(this.emitObj, this.current, null)
					}
					if (this.emitObj[this.current + 1]) {
						this.emitObj.splice(this.current + 1, 1)
					}
					this.showList = this.showList[r].children
				} else {
					let regString = ''
					this.emitObj.map((item, index) => {
						regString = index === 0 ? item.id : regString + ',' + item.id
					})
					this.cleanData()
					this.$emit('confirm', regString)
				}
			},
			backList(c) {
				if (c === 1) {
					this.showList = this.city
				} else if (c === 2) {
					this.showList = this.area
				} else {
					this.showList = this.regionList
				}
				this.current = c
			},
			closeRegion() {
				this.cleanData()
				this.$emit('close')
			},
			cleanData() {
				this.showList = []
				this.clickList = []
				this.current = 0
				this.city = []
				this.area = []
				this.showList = []
				this.emitObj = []
			}
		}
	}
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值