|
@@ -1,23 +1,26 @@
|
|
<template>
|
|
<template>
|
|
<div>
|
|
<div>
|
|
- <div class="d-flex">
|
|
|
|
|
|
+ <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"
|
|
:isSingle="item.isSingle"
|
|
:isSingle="item.isSingle"
|
|
:isSlot="item.isSlot"
|
|
:isSlot="item.isSlot"
|
|
|
|
+ :itemKey="item.itemKey"
|
|
|
|
+ :itemText="item.itemText"
|
|
:displayDictName="item.displayDictName"
|
|
:displayDictName="item.displayDictName"
|
|
:provideData="item.provideData || []"
|
|
:provideData="item.provideData || []"
|
|
- :info="item"
|
|
|
|
|
|
+ btnClass="mt-1"
|
|
@inputChange="inputChange"
|
|
@inputChange="inputChange"
|
|
></component>
|
|
></component>
|
|
</template>
|
|
</template>
|
|
</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;">
|
|
|
|
|
|
+ <div v-for="item in showSelectList" :key="item.key" style="margin: 4px 8px 4px 0px;" :style="`display: ${item.key.includes('cityId_') ? 'inline-block' : 'block'};`">
|
|
<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
|
|
@@ -41,7 +44,7 @@
|
|
</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 } from 'vue'
|
|
|
|
|
|
+import { watch, ref, shallowRef, nextTick } from 'vue'
|
|
import { filterList, getItemObj } from './dict'
|
|
import { filterList, getItemObj } from './dict'
|
|
defineOptions({name: 'retrieval-components-conditionFilter'})
|
|
defineOptions({name: 'retrieval-components-conditionFilter'})
|
|
const emits = defineEmits(['change', 'reset'])
|
|
const emits = defineEmits(['change', 'reset'])
|
|
@@ -56,9 +59,54 @@ const list = shallowRef(props.showFilterList === 'all' ? filterList : props.show
|
|
return item ? { ...item, ...e } : ''
|
|
return item ? { ...item, ...e } : ''
|
|
}).filter(Boolean) : [])
|
|
}).filter(Boolean) : [])
|
|
|
|
|
|
-const inputChange = ({ idName: key, values }) => {
|
|
|
|
|
|
+// 城市处理
|
|
|
|
+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 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)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -74,7 +122,7 @@ const showSelectList = ref([])
|
|
// 添加
|
|
// 添加
|
|
const assembleList = ({ key, idsStr }) => {
|
|
const assembleList = ({ key, idsStr }) => {
|
|
const ids = idsStr.split('_') || []
|
|
const ids = idsStr.split('_') || []
|
|
- const obj = getItemObj({ key, ids })
|
|
|
|
|
|
+ const obj = getItemObj({ key, ids, dictArr: list.value })
|
|
if (!obj) return
|
|
if (!obj) return
|
|
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)
|
|
@@ -102,6 +150,10 @@ watch(
|
|
// showSelectList去掉newVal里面没有的key
|
|
// showSelectList去掉newVal里面没有的key
|
|
showSelectList.value = showSelectList.value.filter(item => Object.keys(newVal).includes(item.key))
|
|
showSelectList.value = showSelectList.value.filter(item => Object.keys(newVal).includes(item.key))
|
|
}
|
|
}
|
|
|
|
+ showSelectList.value = [ // 城市放在一起展示
|
|
|
|
+ ...showSelectList.value.filter(item => item.key.includes('cityId_')),
|
|
|
|
+ ...showSelectList.value.filter(item => !item.key.includes('cityId_')),
|
|
|
|
+ ]
|
|
},
|
|
},
|
|
{ immediate: true },
|
|
{ immediate: true },
|
|
{ deep: true }
|
|
{ deep: true }
|