2021-12-10 16:47:42 +08:00
|
|
|
<template>
|
|
|
|
|
<section class="AiAreaPicker">
|
2021-12-29 11:50:04 +08:00
|
|
|
<ai-search-popup mode="bottom" ref="areaSelector" length="85%">
|
2021-12-10 16:47:42 +08:00
|
|
|
<div slot="btn" @tap="handleInit">
|
2021-12-15 14:37:20 +08:00
|
|
|
<slot v-if="$slots.default"/>
|
2021-12-10 16:47:42 +08:00
|
|
|
<div v-else class="areaSelector">
|
2021-12-20 17:29:52 +08:00
|
|
|
<image :src="locationIcon" class="location"/>
|
2022-01-13 16:47:34 +08:00
|
|
|
<div v-text="selected.name || currentArea.name"/>
|
2021-12-10 16:47:42 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="areaSelector">
|
|
|
|
|
<div class="fixedTop">
|
2021-12-29 11:50:04 +08:00
|
|
|
<b>选择地区</b>
|
|
|
|
|
<em>选择区域</em>
|
|
|
|
|
<div class="selectedArea" v-if="hasSelected">
|
|
|
|
|
<p v-for="area in fullArea" :key="area.id" v-text="area.name"/>
|
2021-12-30 16:55:43 +08:00
|
|
|
<p v-if="selected.type==5" v-text="selected.name"/>
|
2021-12-29 11:50:04 +08:00
|
|
|
</div>
|
|
|
|
|
<div/>
|
2021-12-30 16:55:43 +08:00
|
|
|
<span v-if="all" v-text="`省`" @click="selectNode({}, -1)"/>
|
|
|
|
|
<span v-for="(area,i) in fullArea" :key="area.id" v-text="area.levelLabel"
|
|
|
|
|
@click="selectNode(area, i)"/>
|
2021-12-10 16:47:42 +08:00
|
|
|
</div>
|
2021-12-29 11:50:04 +08:00
|
|
|
<!--用来作为占位的-->
|
2022-01-13 18:42:15 +08:00
|
|
|
<div class="fixedPlaceholder" style="line-height: 60px;" v-if="false">
|
2021-12-29 11:50:04 +08:00
|
|
|
<b>选择地区</b>
|
|
|
|
|
<em>选择区域</em>
|
|
|
|
|
<div class="selectedArea" v-if="hasSelected"/>
|
2022-01-13 18:42:15 +08:00
|
|
|
<span v-text="'行政区域'"/>
|
2021-12-29 11:50:04 +08:00
|
|
|
</div>
|
|
|
|
|
<!--end-->
|
|
|
|
|
</div>
|
2022-01-13 18:42:15 +08:00
|
|
|
<scroll-view class="fill pendingList" scroll-y :style="{height: height}">
|
2022-01-13 16:47:34 +08:00
|
|
|
<div class="pendingItem flexRow" flex v-for="op in pending" :key="op.id" @tap="getChild(op)">
|
|
|
|
|
<div class="fill" :class="{ self: index == op.id }" v-html="op.name"/>
|
|
|
|
|
<u-icon v-if="index == op.id" name="checkbox-mark" color="#4181FF"/>
|
|
|
|
|
</div>
|
2022-01-13 18:42:15 +08:00
|
|
|
</scroll-view>
|
2021-12-29 11:50:04 +08:00
|
|
|
<div class="bottomBtns">
|
|
|
|
|
<div @click="closePopup">取消</div>
|
2021-12-30 16:55:43 +08:00
|
|
|
<div class="primary fill" @click="handleSelect">确定</div>
|
2021-12-10 16:47:42 +08:00
|
|
|
</div>
|
|
|
|
|
</ai-search-popup>
|
|
|
|
|
</section>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import AiSearchPopup from './AiSearchPopup'
|
|
|
|
|
import AiCell from './AiCell.vue'
|
2021-12-15 14:37:20 +08:00
|
|
|
import {mapState} from 'vuex'
|
2021-12-10 16:47:42 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'AiAreaPicker',
|
2021-12-15 14:37:20 +08:00
|
|
|
components: {AiCell, AiSearchPopup},
|
2021-12-10 16:47:42 +08:00
|
|
|
props: {
|
2021-12-15 14:37:20 +08:00
|
|
|
areaId: {default: ''},
|
|
|
|
|
name: {default: ''},
|
2022-01-13 16:47:34 +08:00
|
|
|
value: String,
|
2021-12-10 16:47:42 +08:00
|
|
|
all: Boolean,
|
2021-12-20 17:29:52 +08:00
|
|
|
icon: {default: "location.svg"}
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
...mapState(['user']),
|
|
|
|
|
dataRange() {
|
|
|
|
|
let rules = [10, 8, 6, 3, 0],
|
2021-12-15 14:37:20 +08:00
|
|
|
level = 0
|
2021-12-10 16:47:42 +08:00
|
|
|
if (this.all) return (level = 0)
|
|
|
|
|
rules.some((e, i) => {
|
|
|
|
|
let reg = new RegExp(`0{${e}}`, 'g')
|
|
|
|
|
if (reg.test(this.areaId || this.user.areaId || this.$areaId)) {
|
|
|
|
|
return (level = i)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return level
|
|
|
|
|
},
|
2022-01-13 16:47:34 +08:00
|
|
|
currentArea() {
|
2021-12-10 16:47:42 +08:00
|
|
|
return this.fullArea?.slice(-1)?.[0] || {}
|
|
|
|
|
},
|
2021-12-20 17:29:52 +08:00
|
|
|
locationIcon() {
|
|
|
|
|
return this.$cdn + this.icon
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
2021-12-29 11:50:04 +08:00
|
|
|
pending() {
|
|
|
|
|
return this.list.map(e => ({...e, levelLabel: this.levelLabels[e.type]}))
|
|
|
|
|
},
|
|
|
|
|
hasSelected() {
|
|
|
|
|
return this.fullArea?.length > 0
|
|
|
|
|
}
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2021-12-29 11:50:04 +08:00
|
|
|
fullArea: [],
|
2021-12-10 16:47:42 +08:00
|
|
|
index: '',
|
|
|
|
|
list: [],
|
2021-12-30 16:55:43 +08:00
|
|
|
levelLabels: ["省", "市", "县/区", "镇/街道", "村/社区"],
|
2022-01-13 18:42:15 +08:00
|
|
|
selected: {},
|
|
|
|
|
height: '500px'
|
2021-12-10 16:47:42 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
2022-01-13 16:47:34 +08:00
|
|
|
areaId(v) {
|
|
|
|
|
v && (this.getFullArea())
|
2021-12-30 17:36:27 +08:00
|
|
|
}
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
2022-01-13 16:47:34 +08:00
|
|
|
mounted () {
|
|
|
|
|
this.handleInit()
|
|
|
|
|
},
|
2021-12-10 16:47:42 +08:00
|
|
|
methods: {
|
2022-01-13 16:47:34 +08:00
|
|
|
show() {
|
|
|
|
|
this.handleInit()
|
|
|
|
|
this.$refs.areaSelector.showPopup()
|
|
|
|
|
},
|
2022-01-13 18:42:15 +08:00
|
|
|
scrollHeight () {
|
|
|
|
|
return this.height = `calc(100% - ${document.querySelector('.areaSelector').offsetHeight}px)`
|
|
|
|
|
},
|
2021-12-10 16:47:42 +08:00
|
|
|
getFullArea() {
|
2022-01-13 16:47:34 +08:00
|
|
|
let areaId = this.areaId || (this.all ? '' : this.$areaId)
|
|
|
|
|
return this.$http.post('/admin/area/getAllParentAreaId', null, {
|
2021-12-15 14:37:20 +08:00
|
|
|
withoutToken: true,
|
|
|
|
|
params: {areaId},
|
2021-12-29 11:50:04 +08:00
|
|
|
}).then((res) => {
|
2021-12-15 14:37:20 +08:00
|
|
|
if (res?.data) {
|
2022-01-13 16:47:34 +08:00
|
|
|
res.data.forEach((e) => {
|
|
|
|
|
e && (e.levelLabel = this.levelLabels[e.type])
|
2021-12-29 11:50:04 +08:00
|
|
|
})
|
2021-12-15 14:37:20 +08:00
|
|
|
if (res.data.length > 1) {
|
2022-01-13 16:47:34 +08:00
|
|
|
this.fullArea = res.data.reverse().slice(this.dataRange)
|
2021-12-15 14:37:20 +08:00
|
|
|
} else {
|
|
|
|
|
this.fullArea = res.data
|
|
|
|
|
}
|
2021-12-29 11:50:04 +08:00
|
|
|
return this.fullArea
|
2021-12-15 14:37:20 +08:00
|
|
|
}
|
2022-01-13 16:47:34 +08:00
|
|
|
})
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
|
|
|
|
getChildAreas(id) {
|
2021-12-29 11:50:04 +08:00
|
|
|
id && this.$http.post('/admin/area/queryAreaByParentId', null, {
|
2021-12-15 14:37:20 +08:00
|
|
|
withoutToken: true,
|
|
|
|
|
params: {id},
|
2021-12-29 11:50:04 +08:00
|
|
|
}).then((res) => {
|
2022-01-13 16:47:34 +08:00
|
|
|
if (res.data.length) {
|
2021-12-15 14:37:20 +08:00
|
|
|
this.list = res.data
|
2022-01-13 16:47:34 +08:00
|
|
|
let self = this.fullArea.find((e) => e.id == this.areaId)
|
|
|
|
|
if (self.id) {
|
|
|
|
|
this.list.unshift(self)
|
|
|
|
|
}
|
2022-01-13 18:42:15 +08:00
|
|
|
this.scrollHeight()
|
2021-12-15 14:37:20 +08:00
|
|
|
}
|
|
|
|
|
})
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
2022-01-13 16:47:34 +08:00
|
|
|
|
2021-12-10 16:47:42 +08:00
|
|
|
getProvinces() {
|
2021-12-15 14:37:20 +08:00
|
|
|
this.$http.post('/admin/area/queryProvinceList', null, {withoutToken: true}).then((res) => {
|
2021-12-10 16:47:42 +08:00
|
|
|
if (res?.data) {
|
|
|
|
|
this.list = res.data
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2021-12-30 16:55:43 +08:00
|
|
|
handleSelect() {
|
|
|
|
|
this.$emit('select', this.index)
|
2022-01-13 16:47:34 +08:00
|
|
|
let fullName = ''
|
|
|
|
|
this.fullArea.forEach(v => {
|
|
|
|
|
fullName = fullName + v.name
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (this.selected.type == 5) {
|
|
|
|
|
fullName = fullName + this.selected.name
|
|
|
|
|
}
|
|
|
|
|
this.$emit('update:fullName', fullName)
|
2021-12-30 16:55:43 +08:00
|
|
|
this.$emit('update:name', this.selected.name)
|
2021-12-29 11:50:04 +08:00
|
|
|
this.closePopup()
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
|
|
|
|
getChild(op) {
|
2021-12-29 11:50:04 +08:00
|
|
|
if (op.id != this.index) {
|
2021-12-30 16:55:43 +08:00
|
|
|
if (op.type < 5 && (/0{3}$/g.test(this.index) || !this.index)) {
|
2021-12-29 11:50:04 +08:00
|
|
|
this.fullArea.push(op)
|
|
|
|
|
this.getChildAreas(op.id)
|
|
|
|
|
}
|
2021-12-30 16:55:43 +08:00
|
|
|
this.selected = op
|
2021-12-29 11:50:04 +08:00
|
|
|
this.index = op.id
|
|
|
|
|
}
|
2022-01-13 18:42:15 +08:00
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
|
|
|
|
this.scrollHeight()
|
|
|
|
|
})
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
|
|
|
|
selectNode(area, i) {
|
|
|
|
|
this.fullArea.splice(i + 1, this.fullArea.length - i)
|
|
|
|
|
if (this.all && !area.id) {
|
|
|
|
|
this.index = ''
|
|
|
|
|
this.getProvinces()
|
|
|
|
|
} else {
|
|
|
|
|
this.index = area.id
|
|
|
|
|
this.getChildAreas(area.id)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handleInit() {
|
2021-12-30 17:36:27 +08:00
|
|
|
this.index = this.value || this.areaId
|
2022-01-13 16:47:34 +08:00
|
|
|
|
|
|
|
|
if (this.all && !this.areaId && !this.currentArea.id) {
|
|
|
|
|
this.getProvinces()
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
console.log(this.index)
|
2021-12-29 11:50:04 +08:00
|
|
|
this.getFullArea().then(() => {
|
2022-01-13 16:47:34 +08:00
|
|
|
this.getChildAreas(this.currentArea.id || this.areaId)
|
2021-12-29 11:50:04 +08:00
|
|
|
})
|
2021-12-10 16:47:42 +08:00
|
|
|
},
|
2021-12-29 11:50:04 +08:00
|
|
|
closePopup() {
|
|
|
|
|
this.$refs.areaSelector?.handleSelect()
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-10 16:47:42 +08:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.AiAreaPicker {
|
|
|
|
|
::v-deep .areaSelector {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
|
|
span {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
color: #333;
|
2021-12-29 11:50:04 +08:00
|
|
|
font-weight: bold;
|
|
|
|
|
line-height: 112px;
|
2021-12-31 10:16:43 +08:00
|
|
|
margin-right: 72px;
|
2021-12-29 11:50:04 +08:00
|
|
|
position: relative;
|
2021-12-10 16:47:42 +08:00
|
|
|
|
2021-12-29 11:50:04 +08:00
|
|
|
&:last-of-type {
|
|
|
|
|
margin-right: 0;
|
2021-12-10 16:47:42 +08:00
|
|
|
|
2021-12-29 11:50:04 +08:00
|
|
|
&:after {
|
|
|
|
|
content: " ";
|
|
|
|
|
display: block;
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: -26px;
|
|
|
|
|
left: 50%;
|
|
|
|
|
transform: translate(-50%, 100%);
|
|
|
|
|
width: 40px;
|
|
|
|
|
height: 8px;
|
|
|
|
|
background: #4181FF;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
}
|
2021-12-10 16:47:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 11:50:04 +08:00
|
|
|
b {
|
|
|
|
|
display: block;
|
|
|
|
|
width: 100%;
|
|
|
|
|
line-height: 96px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
em {
|
|
|
|
|
font-style: normal;
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
color: #999999;
|
|
|
|
|
line-height: 34px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.selectedArea {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
width: fit-content;
|
2021-12-30 16:55:43 +08:00
|
|
|
max-width: calc(100vw - 128px);
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
2021-12-29 11:50:04 +08:00
|
|
|
padding: 0 32px;
|
|
|
|
|
height: 80px;
|
|
|
|
|
background: #ECF2FF;
|
|
|
|
|
border-radius: 40px;
|
|
|
|
|
font-size: 32px;
|
|
|
|
|
font-family: PingFangSC-Medium, PingFang SC;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
color: #4181FF !important;
|
|
|
|
|
margin: 16px 0 32px;
|
2021-12-30 16:55:43 +08:00
|
|
|
white-space: nowrap;
|
2021-12-10 16:47:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.fixedTop {
|
2022-01-13 18:42:15 +08:00
|
|
|
// position: fixed;
|
2021-12-10 16:47:42 +08:00
|
|
|
top: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
left: 0;
|
|
|
|
|
background: #fff;
|
|
|
|
|
border-bottom: 4px solid #f5f5f5;
|
|
|
|
|
z-index: 1;
|
|
|
|
|
text-align: start;
|
2021-12-29 11:50:04 +08:00
|
|
|
padding: 0 32px;
|
|
|
|
|
box-sizing: border-box;
|
2021-12-10 16:47:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::v-deep.u-drawer-content {
|
|
|
|
|
|
|
|
|
|
.areaSelector {
|
|
|
|
|
box-sizing: border-box;
|
2022-01-13 18:20:53 +08:00
|
|
|
// border-bottom: 1px solid #f5f5f5;
|
2021-12-10 16:47:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 16:47:34 +08:00
|
|
|
::v-deep .pendingList {
|
2022-01-13 18:42:15 +08:00
|
|
|
height: 500px;
|
|
|
|
|
overflow-y: auto;
|
2022-01-13 16:47:34 +08:00
|
|
|
padding: 0 32px 120px;
|
2022-01-13 18:42:15 +08:00
|
|
|
box-sizing: border-box;
|
2021-12-10 16:47:42 +08:00
|
|
|
|
2022-01-13 16:47:34 +08:00
|
|
|
.pendingItem {
|
|
|
|
|
color: #333;
|
2022-01-13 17:23:33 +08:00
|
|
|
height: 84px;
|
2022-01-13 16:47:34 +08:00
|
|
|
text-align: start;
|
|
|
|
|
|
|
|
|
|
.self {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
2021-12-10 16:47:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 11:50:04 +08:00
|
|
|
::v-deep.bottomBtns {
|
|
|
|
|
position: fixed;
|
|
|
|
|
left: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
width: 100vw;
|
|
|
|
|
display: flex;
|
2021-12-31 10:16:43 +08:00
|
|
|
align-items: center;
|
2021-12-29 11:50:04 +08:00
|
|
|
text-align: center;
|
2021-12-31 10:16:43 +08:00
|
|
|
height: 120px;
|
2021-12-29 11:50:04 +08:00
|
|
|
font-size: 34px;
|
|
|
|
|
font-family: PingFangSC-Medium, PingFang SC;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
color: #3671EE;
|
|
|
|
|
background: #fff;
|
2021-12-31 10:16:43 +08:00
|
|
|
padding: 0 32px;
|
|
|
|
|
box-sizing: border-box;
|
2021-12-29 11:50:04 +08:00
|
|
|
|
|
|
|
|
& > div {
|
|
|
|
|
padding: 0 92px;
|
2021-12-31 10:16:43 +08:00
|
|
|
line-height: 88px;
|
|
|
|
|
height: 88px;
|
|
|
|
|
border: 1px solid #A0C0FF;
|
|
|
|
|
border-radius: 16px;
|
2021-12-29 11:50:04 +08:00
|
|
|
|
|
|
|
|
&.primary {
|
|
|
|
|
color: #fff;
|
|
|
|
|
background: #4181FF;
|
|
|
|
|
border-color: #4181FF;
|
|
|
|
|
}
|
2021-12-31 10:16:43 +08:00
|
|
|
|
|
|
|
|
& + div {
|
|
|
|
|
margin-left: 32px;
|
|
|
|
|
}
|
2021-12-29 11:50:04 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 16:47:42 +08:00
|
|
|
.location {
|
|
|
|
|
width: 28px;
|
|
|
|
|
height: 80px;
|
|
|
|
|
margin-right: 12px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|