修复组件
This commit is contained in:
@@ -1,92 +0,0 @@
|
|||||||
<template>
|
|
||||||
<section class="AiSearchPopup">
|
|
||||||
<u-popup v-model="show" :length="length" closeable :mode="mode" border-radius="32" z-index="202203181717" safe-area-inset-bottom>
|
|
||||||
<slot v-if="$slots.default"/>
|
|
||||||
<div class="searchPane" v-else>
|
|
||||||
<div class="title">{{ title }}</div>
|
|
||||||
<u-search v-model="search" :placeholder="placeholder" :show-action="false" @search="getList()" :focus="show"/>
|
|
||||||
<div class="result">
|
|
||||||
<div class="option" v-for="(op,i) in list" :key="i" @tap="handleSelect(op)">{{ op[ops.label] }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</u-popup>
|
|
||||||
<div @tap="show= !disabled&&true">
|
|
||||||
<slot name="btn"/>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: "AiSearchPopup",
|
|
||||||
props: {
|
|
||||||
title: {default: "搜索"},
|
|
||||||
placeholder: {default: "请搜索"},
|
|
||||||
ops: {default: () => ({label: 'label', search: 'name'})},
|
|
||||||
url: String,
|
|
||||||
mode: {default: "right"},
|
|
||||||
length: {default: "100%"},
|
|
||||||
disabled: Boolean
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
show: false,
|
|
||||||
search: "",
|
|
||||||
list: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
show(v) {
|
|
||||||
!v && this.$emit('close')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
getList() {
|
|
||||||
this.url && this.$instance.post(this.url, null, {
|
|
||||||
params: {[this.ops.search]: this.search}
|
|
||||||
}).then(res => {
|
|
||||||
if (res?.data) {
|
|
||||||
this.list = res.data
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
handleSelect(op) {
|
|
||||||
this.$emit('select', op)
|
|
||||||
this.show = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.AiSearchPopup {
|
|
||||||
::v-deep .searchPane {
|
|
||||||
padding: 0 16px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
.title {
|
|
||||||
width: 100%;
|
|
||||||
height: 100px;
|
|
||||||
text-align: center;
|
|
||||||
line-height: 100px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.result {
|
|
||||||
flex: 1;
|
|
||||||
min-height: 0;
|
|
||||||
overflow-y: auto;
|
|
||||||
padding-bottom: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.option {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
height: 80px;
|
|
||||||
border-bottom: 1px solid #eee;
|
|
||||||
font-size: 32px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -9,8 +9,8 @@
|
|||||||
<p v-else>请选择</p>
|
<p v-else>请选择</p>
|
||||||
</div>
|
</div>
|
||||||
<div/>
|
<div/>
|
||||||
<span v-if="all" v-text="`省`" @click="selectNode({}, -1)"/>
|
<span v-if="urlParams.all" v-text="`省`" @click="selectNode({}, -1)"/>
|
||||||
<span v-for="(area,i) in fullArea.filter(e=>e.type<valueLevel)" :key="area.id"
|
<span v-for="(area,i) in typeLabels" :key="area.id"
|
||||||
v-text="area.levelLabel" @click="selectNode(area, i)"/>
|
v-text="area.levelLabel" @click="selectNode(area, i)"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -37,11 +37,11 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState(['user']),
|
...mapState(['user']),
|
||||||
dataRange() {
|
dataRange() {
|
||||||
if (this.all || this.disabled) return 0
|
console.log(this.urlParams.all, this.urlParams.disabled)
|
||||||
return this.getAreaType(this.root)
|
return this.urlParams.all || this.urlParams.disabled ? 0 : this.getAreaType(this.root)
|
||||||
},
|
},
|
||||||
root() {
|
root() {
|
||||||
return this.areaId || this.user.areaId || this.$areaId
|
return this.urlParams.areaId || this.user.areaId || this.$areaId
|
||||||
},
|
},
|
||||||
pending() {
|
pending() {
|
||||||
return this.list?.map(e => ({...e, levelLabel: this.levelLabels[e.type]})) || []
|
return this.list?.map(e => ({...e, levelLabel: this.levelLabels[e.type]})) || []
|
||||||
@@ -50,8 +50,11 @@ export default {
|
|||||||
return this.fullArea?.length > 0
|
return this.fullArea?.length > 0
|
||||||
},
|
},
|
||||||
hasLastLevelValue() {
|
hasLastLevelValue() {
|
||||||
return this.fullArea.some(e => e.type >= this.valueLevel)
|
return this.fullArea.some(e => e.type >= this.urlParams.valueLevel)
|
||||||
},
|
},
|
||||||
|
typeLabels() {
|
||||||
|
return this.fullArea.filter(e => e.type < this.urlParams.valueLevel)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -99,7 +102,7 @@ export default {
|
|||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res?.data) {
|
if (res?.data) {
|
||||||
this.list = res.data
|
this.list = res.data
|
||||||
if (this.selectRoot) {
|
if (this.urlParams.selectRoot) {
|
||||||
if (this.hasLastLevelValue) {
|
if (this.hasLastLevelValue) {
|
||||||
let parent = JSON.parse(JSON.stringify(this.fullArea?.slice(-2)?.[0]))
|
let parent = JSON.parse(JSON.stringify(this.fullArea?.slice(-2)?.[0]))
|
||||||
this.list.unshift(parent)
|
this.list.unshift(parent)
|
||||||
@@ -127,13 +130,14 @@ export default {
|
|||||||
if (op.id != this.index) {
|
if (op.id != this.index) {
|
||||||
this.selected = op
|
this.selected = op
|
||||||
this.index = op.id
|
this.index = op.id
|
||||||
if (op.type == this.valueLevel) {
|
let {length} = this.fullArea
|
||||||
|
if (op.type == this.urlParams.valueLevel) {
|
||||||
if (this.hasLastLevelValue) {
|
if (this.hasLastLevelValue) {
|
||||||
this.fullArea.splice(this.fullArea.length - 1, 1, op)
|
this.fullArea.splice(length - 1, 1, op)
|
||||||
} else this.fullArea.push(op)
|
} else this.fullArea.push(op)
|
||||||
} else if (op.type < this.valueLevel) {
|
} else if (op.type < this.urlParams.valueLevel) {
|
||||||
if (this.hasLastLevelValue) {
|
if (this.hasLastLevelValue) {
|
||||||
this.fullArea.splice(this.fullArea.length - 1, 1)
|
this.fullArea.splice(length - 1, 1)
|
||||||
} else {
|
} else {
|
||||||
this.fullArea.push(op)
|
this.fullArea.push(op)
|
||||||
this.getChildAreas(op.id)
|
this.getChildAreas(op.id)
|
||||||
@@ -146,7 +150,7 @@ export default {
|
|||||||
if (deleteCount > 0) {
|
if (deleteCount > 0) {
|
||||||
this.fullArea.splice(i + 1, deleteCount)
|
this.fullArea.splice(i + 1, deleteCount)
|
||||||
}
|
}
|
||||||
if (this.all && !area.id) {
|
if (this.urlParams.all && !area.id) {
|
||||||
this.index = ''
|
this.index = ''
|
||||||
this.getProvinces()
|
this.getProvinces()
|
||||||
} else {
|
} else {
|
||||||
@@ -156,18 +160,18 @@ export default {
|
|||||||
},
|
},
|
||||||
handleInit() {
|
handleInit() {
|
||||||
//初始化
|
//初始化
|
||||||
this.index = this.value || this.root
|
this.index = this.urlParams.value || this.root
|
||||||
if (!this.disabled) {
|
if (!this.urlParams.disabled) {
|
||||||
if (this.value) {
|
if (this.urlParams.value) {
|
||||||
this.getFullArea(this.value).then(() => {
|
this.getFullArea(this.urlParams.value).then(() => {
|
||||||
let area = this.fullArea.find(e => e.id == this.value) || {}
|
let area = this.fullArea.find(e => e.id == this.urlParams.value) || {}
|
||||||
//当前选择列表必须是可选范围内的值
|
//当前选择列表必须是可选范围内的值
|
||||||
let top = area.type == this.valueLevel ? area.parentId : area.id
|
let top = area.type == this.urlParams.valueLevel ? area.parentId : area.id
|
||||||
if (this.getAreaType(top) >= this.dataRange) {
|
if (this.getAreaType(top) >= this.dataRange) {
|
||||||
this.getChildAreas(top)
|
this.getChildAreas(top)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (this.all) {
|
} else if (this.urlParams.all) {
|
||||||
this.getProvinces()
|
this.getProvinces()
|
||||||
} else {
|
} else {
|
||||||
this.getFullArea(this.root).then(() => {
|
this.getFullArea(this.root).then(() => {
|
||||||
@@ -194,7 +198,7 @@ export default {
|
|||||||
},
|
},
|
||||||
onLoad(params) {
|
onLoad(params) {
|
||||||
Object.keys(params).map(k => {
|
Object.keys(params).map(k => {
|
||||||
this[k] = params[k] == "false" ? false : params[k]
|
this.$set(this.urlParams, k, params[k] == "false" ? false : params[k])
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|||||||
Reference in New Issue
Block a user