同步地区组件逻辑
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<section class="AiAreaPicker">
|
<section class="AiAreaPicker">
|
||||||
<ai-search-popup mode="bottom" ref="areaSelector" length="85%">
|
<ai-search-popup mode="bottom" ref="areaSelector" length="85%" :disabled="disabled">
|
||||||
<div slot="btn" @tap="handleInit">
|
<div slot="btn" @tap="handleInit">
|
||||||
<slot v-if="$slots.default"/>
|
<slot v-if="$slots.default"/>
|
||||||
<div v-else-if="isForm">
|
<div v-else-if="isForm">
|
||||||
<u-icon name="arrow-right" :label="areaName||'请选择'" label-pos="left" color="#ddd"/>
|
<ai-more v-model="areaName"/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="areaSelector">
|
<div v-else class="areaSelector">
|
||||||
<image :src="locationIcon" class="location"/>
|
<image :src="locationIcon" class="location"/>
|
||||||
<div v-text="areaName"/>
|
<div v-text="areaName"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="areaSelector" id="areaSelector">
|
<div class="areaSelector">
|
||||||
<div class="fixedTop">
|
<div class="fixedTop">
|
||||||
<b>选择地区</b>
|
<b>选择地区</b>
|
||||||
<em>选择区域</em>
|
<em>选择区域</em>
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div/>
|
<div/>
|
||||||
<span v-if="all" v-text="`省`" @click="selectNode({}, -1)"/>
|
<span v-if="all" v-text="`省`" @click="selectNode({}, -1)"/>
|
||||||
<span v-for="(area,i) in fullArea" :key="area.id" v-text="area.levelLabel"
|
<span v-for="(area,i) in fullArea.filter(e=>e.type<valueLevel)" :key="area.id"
|
||||||
@click="selectNode(area, i)"/>
|
v-text="area.levelLabel" @click="selectNode(area, i)"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<scroll-view class="fill pendingList" :style="{height: height}" scroll-y>
|
<scroll-view class="fill pendingList" :style="{height: height}" scroll-y>
|
||||||
@@ -32,8 +32,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
<div class="bottomBtns">
|
<div class="bottomBtns">
|
||||||
<div @click="closePopup">取消</div>
|
<div @click.stop="closePopup">取消</div>
|
||||||
<div class="primary fill" @click="handleSelect">确定</div>
|
<div class="primary fill" @click.stop="handleSelect">确定</div>
|
||||||
</div>
|
</div>
|
||||||
</ai-search-popup>
|
</ai-search-popup>
|
||||||
</section>
|
</section>
|
||||||
@@ -42,23 +42,22 @@
|
|||||||
<script>
|
<script>
|
||||||
import AiSearchPopup from './AiSearchPopup'
|
import AiSearchPopup from './AiSearchPopup'
|
||||||
import {mapState} from 'vuex'
|
import {mapState} from 'vuex'
|
||||||
|
import AiMore from "../AiMore/AiMore";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AiAreaPicker',
|
name: 'AiAreaPicker',
|
||||||
components: {AiSearchPopup},
|
components: {AiMore, AiSearchPopup},
|
||||||
props: {
|
props: {
|
||||||
areaId: {default: ''},
|
areaId: {default: ''},
|
||||||
name: {default: ''},
|
name: {default: ''},
|
||||||
value: String,
|
value: String,
|
||||||
all: Boolean,
|
all: Boolean,
|
||||||
icon: {default: "/dvpc/h5/location.svg"},
|
icon: {default: "location.svg"},
|
||||||
isHideTown: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
isForm: Boolean,
|
isForm: Boolean,
|
||||||
valueLevel: {default: 5},
|
valueLevel: {default: 5},
|
||||||
fullName: {default: ''}
|
fullName: {default: ''},
|
||||||
|
disabled: Boolean,
|
||||||
|
selectRoot: {default: true}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['user']),
|
...mapState(['user']),
|
||||||
@@ -68,14 +67,14 @@ export default {
|
|||||||
if (this.all) return (level = 0)
|
if (this.all) return (level = 0)
|
||||||
rules.some((e, i) => {
|
rules.some((e, i) => {
|
||||||
let reg = new RegExp(`0{${e}}`, 'g')
|
let reg = new RegExp(`0{${e}}`, 'g')
|
||||||
if (reg.test(this.areaId || this.user.areaId || this.$areaId)) {
|
if (reg.test(this.root)) {
|
||||||
return (level = i)
|
return (level = i)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return level
|
return level
|
||||||
},
|
},
|
||||||
currentArea() {
|
root() {
|
||||||
return this.fullArea?.slice(-1)?.[0] || {}
|
return this.areaId || this.user.areaId || this.$areaId
|
||||||
},
|
},
|
||||||
locationIcon() {
|
locationIcon() {
|
||||||
return this.$cdn + this.icon
|
return this.$cdn + this.icon
|
||||||
@@ -93,18 +92,20 @@ export default {
|
|||||||
index: '',
|
index: '',
|
||||||
areaName: '',
|
areaName: '',
|
||||||
list: [],
|
list: [],
|
||||||
height: '500px',
|
|
||||||
levelLabels: ["省", "市", "县/区", "镇/街道", "村/社区"],
|
levelLabels: ["省", "市", "县/区", "镇/街道", "村/社区"],
|
||||||
selected: {}
|
selected: {},
|
||||||
|
height: '500px'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
areaId(v) {
|
areaId(v) {
|
||||||
v && this.getFullArea()
|
v && (this.getFullArea(v))
|
||||||
},
|
},
|
||||||
value(v) {
|
value(v) {
|
||||||
if (this.list.length && v) {
|
if (v) {
|
||||||
this.areaName = this.list.find((e) => e.id == this.value).name
|
this.getFullArea(v).then(list => {
|
||||||
|
this.areaName = list?.reverse()?.[0]?.name
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fullArea: {
|
fullArea: {
|
||||||
@@ -131,9 +132,8 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getFullArea() {
|
getFullArea(areaId) {
|
||||||
let areaId = this.areaId || (this.all ? '' : this.$areaId)
|
return areaId && this.$http.post('/admin/area/getAllParentAreaId', null, {
|
||||||
return this.$instance.post('/admin/area/getAllParentAreaId', null, {
|
|
||||||
withoutToken: true,
|
withoutToken: true,
|
||||||
params: {areaId},
|
params: {areaId},
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
@@ -142,7 +142,7 @@ export default {
|
|||||||
e && (e.levelLabel = this.levelLabels[e.type])
|
e && (e.levelLabel = this.levelLabels[e.type])
|
||||||
})
|
})
|
||||||
if (res.data.length > 1) {
|
if (res.data.length > 1) {
|
||||||
this.fullArea = res.data.reverse().slice(this.dataRange - 1)
|
this.fullArea = res.data.reverse().slice(this.dataRange)
|
||||||
} else {
|
} else {
|
||||||
this.fullArea = res.data
|
this.fullArea = res.data
|
||||||
}
|
}
|
||||||
@@ -155,18 +155,13 @@ export default {
|
|||||||
withoutToken: true,
|
withoutToken: true,
|
||||||
params: {id},
|
params: {id},
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res.data.length) {
|
if (res?.data) {
|
||||||
this.list = res.data
|
this.list = res.data
|
||||||
let self = this.fullArea.find((e) => e.id == this.areaId)
|
if (this.selectRoot) {
|
||||||
if (this.value && !this.areaName && this.value !== this.areaId) {
|
let root = JSON.parse(JSON.stringify(this.fullArea?.[0]))
|
||||||
this.areaName = this.list.find((e) => e.id == this.value)?.name
|
this.list.unshift(root)
|
||||||
}
|
|
||||||
if (!this.areaName && this.value === this.areaId) {
|
|
||||||
this.areaName = self?.name
|
|
||||||
}
|
|
||||||
if (!!self?.id && !this.isHideTown) {
|
|
||||||
this.list.unshift(self)
|
|
||||||
}
|
}
|
||||||
|
this.scrollHeight()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -185,16 +180,16 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (this.selected.type == 5) {
|
if (this.selected.type == 5) {
|
||||||
fullName = fullName + this.selected.name
|
fullName = fullName + (this.selected.name || this.areaName)
|
||||||
}
|
}
|
||||||
this.areaName = this.selected.name || this.areaName
|
this.areaName = this.selected.name || this.areaName
|
||||||
this.$emit('update:fullName', fullName)
|
this.$emit('update:fullName', fullName)
|
||||||
this.$emit('update:name', this.selected.name)
|
this.$emit('update:name', (this.selected.name || this.areaName))
|
||||||
this.closePopup()
|
this.closePopup()
|
||||||
},
|
},
|
||||||
getChild(op) {
|
getChild(op) {
|
||||||
if (op.id != this.index) {
|
if (op.id != this.index) {
|
||||||
if (op.type <= this.valueLevel && op.type < 5 && (/0{3}$/g.test(this.index) || !this.index)) {
|
if (op.type < this.valueLevel && op.type < 5 && (/0{3}$/g.test(this.index) || !this.index)) {
|
||||||
this.fullArea.push(op)
|
this.fullArea.push(op)
|
||||||
this.getChildAreas(op.id)
|
this.getChildAreas(op.id)
|
||||||
}
|
}
|
||||||
@@ -216,16 +211,23 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleInit() {
|
handleInit() {
|
||||||
this.index = this.value || this.areaId
|
this.index = this.value || this.root
|
||||||
|
if (!this.disabled) {
|
||||||
if (this.all && !this.areaId && !this.currentArea.id) {
|
if (this.all) {
|
||||||
this.getProvinces()
|
this.getProvinces()
|
||||||
|
return false
|
||||||
return false
|
} else if (this.value) {
|
||||||
|
this.getFullArea(this.value).then(() => {
|
||||||
|
let area = this.fullArea?.[0]
|
||||||
|
if (area.type == this.valueLevel) this.getChildAreas(area.parentId)
|
||||||
|
else this.getChildAreas(area.id)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.getFullArea(this.root).then(() => {
|
||||||
|
this.getChildAreas(this.root)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.getFullArea().then(() => {
|
|
||||||
this.getChildAreas(this.currentArea.id || this.areaId)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
closePopup() {
|
closePopup() {
|
||||||
this.$refs.areaSelector?.handleSelect()
|
this.$refs.areaSelector?.handleSelect()
|
||||||
|
|||||||
32
src/components/AiMore/AiMore.vue
Normal file
32
src/components/AiMore/AiMore.vue
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<template>
|
||||||
|
<section class="AiMore">
|
||||||
|
<u-icon name="arrow-right" color="#ddd" :label="value||placeholder" label-pos="left" :label-color="labelColor" label-size="32"/>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "AiMore",
|
||||||
|
model: {
|
||||||
|
prop: "value",
|
||||||
|
event: "change"
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
placeholder: {default: "请选择"},
|
||||||
|
value: String
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
isEmpty() {
|
||||||
|
return !this.value
|
||||||
|
},
|
||||||
|
labelColor() {
|
||||||
|
return this.isEmpty ? "#999" : "#333"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.AiMore {
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user