|
@@ -1,9 +1,9 @@
|
|
<template>
|
|
<template>
|
|
<div>
|
|
<div>
|
|
|
|
+ <cityCascadeSelect v-if="showCitySelect" @inputChange="inputChange"></cityCascadeSelect>
|
|
<div class="d-flex" style="flex-wrap: wrap;">
|
|
<div class="d-flex" style="flex-wrap: wrap;">
|
|
<template v-for="item in list" :key="item.key">
|
|
<template v-for="item in list" :key="item.key">
|
|
<component
|
|
<component
|
|
- v-if="!item.hide"
|
|
|
|
:is="item.path"
|
|
:is="item.path"
|
|
:idName="item.key"
|
|
:idName="item.key"
|
|
:title="item.title"
|
|
:title="item.title"
|
|
@@ -21,7 +21,7 @@
|
|
</div>
|
|
</div>
|
|
<div v-if="showSelectList?.length">
|
|
<div v-if="showSelectList?.length">
|
|
<div style="margin-top: 20px; border-top: 1px solid #eee;">
|
|
<div style="margin-top: 20px; border-top: 1px solid #eee;">
|
|
- <div v-for="item in showSelectList" :key="item.key" style="margin: 4px 8px 4px 0px;" :style="`display: ${item.key.includes('cityId_') ? 'inline-block' : 'block'};`">
|
|
|
|
|
|
+ <div v-for="item in showSelectList" :key="item.key" style="margin: 4px 8px 4px 0px;">
|
|
<template v-if="item.checkedItems?.length">
|
|
<template v-if="item.checkedItems?.length">
|
|
<span style="color: #999;">{{ item.title }}:</span>
|
|
<span style="color: #999;">{{ item.title }}:</span>
|
|
<v-btn
|
|
<v-btn
|
|
@@ -45,9 +45,9 @@
|
|
</template>
|
|
</template>
|
|
<script setup>
|
|
<script setup>
|
|
import { useRoute } from 'vue-router'; const route = useRoute()
|
|
import { useRoute } from 'vue-router'; const route = useRoute()
|
|
-import { watch, ref, shallowRef, nextTick } from 'vue'
|
|
|
|
|
|
+import { watch, ref, shallowRef } from 'vue'
|
|
import { filterList, getItemObj } from './dict'
|
|
import { filterList, getItemObj } from './dict'
|
|
-import { getDict } from '@/hooks/web/useDictionaries'
|
|
|
|
|
|
+import cityCascadeSelect from './conditionFilter/cityCascadeSelect.vue'
|
|
defineOptions({name: 'retrieval-components-conditionFilter'})
|
|
defineOptions({name: 'retrieval-components-conditionFilter'})
|
|
const emits = defineEmits(['change', 'reset'])
|
|
const emits = defineEmits(['change', 'reset'])
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
@@ -55,59 +55,21 @@ const props = defineProps({
|
|
type: [Array, String],
|
|
type: [Array, String],
|
|
default: ''
|
|
default: ''
|
|
},
|
|
},
|
|
|
|
+ showCitySelect: { // 城市级联筛选
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false
|
|
|
|
+ },
|
|
})
|
|
})
|
|
|
|
+
|
|
const list = shallowRef(props.showFilterList === 'all' ? filterList : props.showFilterList?.length? props.showFilterList.map(e => {
|
|
const list = shallowRef(props.showFilterList === 'all' ? filterList : props.showFilterList?.length? props.showFilterList.map(e => {
|
|
const item = filterList.find(i => i.key === e.key)
|
|
const item = filterList.find(i => i.key === e.key)
|
|
return item ? { ...item, ...e } : ''
|
|
return item ? { ...item, ...e } : ''
|
|
}).filter(Boolean) : [])
|
|
}).filter(Boolean) : [])
|
|
|
|
|
|
-// 城市处理
|
|
|
|
-const cityDelete = (cityLevel) => {
|
|
|
|
- list.value.forEach(e => {
|
|
|
|
- if (e.key.includes('cityId_') && e.cityLevel > cityLevel) {
|
|
|
|
- emits('change', e.key, '')
|
|
|
|
- e.del = true
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- list.value = list.value.filter(e => !e.del)
|
|
|
|
-}
|
|
|
|
-// 城市处理
|
|
|
|
-const cityDeal = (str, key, clickItem) => {
|
|
|
|
- if (str === '10000') { // 全国
|
|
|
|
- cityDelete(1)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- const i = list.value.findIndex(e => e.key === key)
|
|
|
|
- if (i !== -1) {
|
|
|
|
- cityDelete(list.value[i].cityLevel) // 去掉当前选中层级后面的市区
|
|
|
|
- if (str && clickItem?.children?.length) { // 选中-添加下级
|
|
|
|
- let noProvince = false
|
|
|
|
- if (clickItem.children[0][list.value[i].itemText] === clickItem[list.value[i].itemText] && clickItem.children[0].children?.length) { // 直辖市
|
|
|
|
- clickItem = clickItem.children[0]
|
|
|
|
- noProvince = true
|
|
|
|
- }
|
|
|
|
- const obj = {
|
|
|
|
- ...list.value[i], // 复制其他属性
|
|
|
|
- toFilterDictName: null, toFilterApiType: null, displayDictName: null, displayApiType: null,
|
|
|
|
- isSingle: Boolean(clickItem.children[0]?.children?.length),
|
|
|
|
- provideData: clickItem.children, // 赋值下拉数据
|
|
|
|
- toFilterDictDataList: clickItem.children // 回显使用
|
|
|
|
- }
|
|
|
|
- obj.cityLevel++ // 层级
|
|
|
|
- if (noProvince) obj.cityLevel++ // 直辖市
|
|
|
|
- obj.key = 'cityId_' + obj.cityLevel
|
|
|
|
- obj.title = obj.cityLevel === 2 ? '市' : '区'
|
|
|
|
- nextTick(() => {
|
|
|
|
- list.value.splice(i+1, 0, obj)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
|
|
-const inputChange = ({ idName: key, values, clickItem }) => {
|
|
|
|
|
|
+const inputChange = ({ idName: key, values }) => {
|
|
const str = values.length ? values.join('_') : ''
|
|
const str = values.length ? values.join('_') : ''
|
|
if (!key) return
|
|
if (!key) return
|
|
- if (key.includes('cityId_')) cityDeal(str, key, clickItem) // 城市处理
|
|
|
|
//
|
|
//
|
|
emits('change', key, str)
|
|
emits('change', key, str)
|
|
}
|
|
}
|
|
@@ -120,43 +82,8 @@ const deleteChip = (item, val) => { // 删除某个标签-更新路由 val结构
|
|
inputChange({ idName: item.key, values: ids })
|
|
inputChange({ idName: item.key, values: ids })
|
|
}
|
|
}
|
|
|
|
|
|
-let cityLevel2 = []
|
|
|
|
const showSelectList = ref([])
|
|
const showSelectList = ref([])
|
|
-const assembleList = async ({ key, idsStr, isRefresh = false }) => {
|
|
|
|
- if (isRefresh && key === 'cityId_1') {
|
|
|
|
- const res = await getDict('areaTreeData', null, 'areaTreeData')
|
|
|
|
- const data = res?.data?.length ? res.data : []
|
|
|
|
- const item = data.find(e => e.id === idsStr)
|
|
|
|
- if (item) {
|
|
|
|
- cityLevel2 = item.children?.length? item.children : []
|
|
|
|
- cityDeal(idsStr, key, item)
|
|
|
|
- nextTick(() => {
|
|
|
|
- assembleList({ key, idsStr })
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (isRefresh && key === 'cityId_2') {
|
|
|
|
- nextTick(async () => {
|
|
|
|
- const item = cityLevel2.find(e => String(e.id) === String(idsStr))
|
|
|
|
- if (item) {
|
|
|
|
- nextTick(() => {
|
|
|
|
- cityDeal(idsStr, key, item)
|
|
|
|
- nextTick(() => {
|
|
|
|
- assembleList({ key, idsStr })
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- if (isRefresh && key === 'cityId_3') {
|
|
|
|
- nextTick(() => {
|
|
|
|
- nextTick(() => {
|
|
|
|
- nextTick(() => {
|
|
|
|
- assembleList({ key, idsStr })
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+const assembleList = async ({ key, idsStr }) => {
|
|
// 添加
|
|
// 添加
|
|
const ids = typeof idsStr === 'string' ? idsStr.split('_') : []
|
|
const ids = typeof idsStr === 'string' ? idsStr.split('_') : []
|
|
const obj = getItemObj({ key, ids, dictArr: list.value })
|
|
const obj = getItemObj({ key, ids, dictArr: list.value })
|
|
@@ -164,11 +91,6 @@ const assembleList = async ({ key, idsStr, isRefresh = false }) => {
|
|
const index = showSelectList.value.findIndex(i => i.key === key)
|
|
const index = showSelectList.value.findIndex(i => i.key === key)
|
|
if (index === -1) showSelectList.value.push(obj)
|
|
if (index === -1) showSelectList.value.push(obj)
|
|
else showSelectList.value[index] = obj
|
|
else showSelectList.value[index] = obj
|
|
- //
|
|
|
|
- showSelectList.value = [ // 城市放在一起展示
|
|
|
|
- ...showSelectList.value.filter(item => item.key.includes('cityId_')),
|
|
|
|
- ...showSelectList.value.filter(item => !item.key.includes('cityId_')),
|
|
|
|
- ]
|
|
|
|
}
|
|
}
|
|
|
|
|
|
watch(
|
|
watch(
|
|
@@ -176,20 +98,16 @@ watch(
|
|
(newVal = {}, oldVal = {}) => {
|
|
(newVal = {}, oldVal = {}) => {
|
|
// console.log('1oldVal', oldVal)
|
|
// console.log('1oldVal', oldVal)
|
|
// console.log('2newVal', newVal)
|
|
// console.log('2newVal', newVal)
|
|
- const arr = Object.keys(newVal).length ? [...Object.keys(newVal)] : null
|
|
|
|
- const newKeyList = arr ? [ // 城市放在一起展示
|
|
|
|
- ...arr.filter(key => key.includes('cityId_')),
|
|
|
|
- ...arr.filter(key => !key.includes('cityId_')),
|
|
|
|
- ] : ''
|
|
|
|
|
|
+ const newKeyList = Object.keys(newVal).length ? [...Object.keys(newVal)] : null
|
|
|
|
+
|
|
// 回显已选筛选-标签
|
|
// 回显已选筛选-标签
|
|
-
|
|
|
|
if (!newKeyList) { // 路由没有参数
|
|
if (!newKeyList) { // 路由没有参数
|
|
showSelectList.value = []
|
|
showSelectList.value = []
|
|
list.value = list.value.filter(e => !(e.cityLevel && e.cityLevel > 1))
|
|
list.value = list.value.filter(e => !(e.cityLevel && e.cityLevel > 1))
|
|
}
|
|
}
|
|
else if (!Object.keys(oldVal).length && newKeyList) { // 只有新加参数
|
|
else if (!Object.keys(oldVal).length && newKeyList) { // 只有新加参数
|
|
newKeyList.forEach(key => {
|
|
newKeyList.forEach(key => {
|
|
- assembleList({ key, idsStr: newVal[key], isRefresh: true })
|
|
|
|
|
|
+ assembleList({ key, idsStr: newVal[key] })
|
|
})
|
|
})
|
|
}
|
|
}
|
|
else { // 路由参数更新
|
|
else { // 路由参数更新
|