2021-10-12 16:53:59 +08:00
< template >
< div style = "line-height: 32px;" >
2021-10-18 17:40:21 +08:00
< div class = "search-detail-box" :class = "[selectValue[item.key].length?'select-dropdown':'',detailSearchListCopy[key].dropShow?'show-my-dropdpwn':'']" v-for = "(item,key) in detailSearchListCopy" :key='key' v-show="item.children.length" >
2021-10-13 11:12:26 +08:00
< span v-if = "item.type === 'checkBox'" >
2021-10-12 16:53:59 +08:00
< el-dropdown
2021-10-18 17:40:21 +08:00
: placement = "'bottom-start'"
2021-10-13 11:12:26 +08:00
class = "detail-dropdown"
2021-10-12 16:53:59 +08:00
type = "primary"
: trigger = "'click'"
: hide - on - click = "false"
2021-10-14 14:14:25 +08:00
@ visible - change = "(val)=>{showDropDown(val, key)}"
2021-10-12 16:53:59 +08:00
>
2021-10-18 17:40:21 +08:00
< div style = "padding-left: 10px;" >
< span class = "search-detail-title" v-if = "!selectValue[item.key].length" > {{ item.label }} : < / span >
2021-10-13 11:12:26 +08:00
< div class = "detail-top-search" v-if = "selectValue[item.key].length" >
< span v-for = "(item2,index2) in selectValue[item.key]" :key="item2" class="search-value" >
{ { item . oldChildren . find ( dc => dc . id == item2 ) . name } } < span v-if = "index2+1 !== selectValue[item.key].length" > , < / span >
2021-10-12 16:53:59 +08:00
< / span >
< / div >
2021-10-13 11:12:26 +08:00
< div class = "detail-top-search" style = "text-align: center" v-else >
All
< / div >
2021-10-12 16:53:59 +08:00
< i class = "nz-icon nz-icon-arrow-down search-value" / >
< / div >
2021-10-18 16:34:37 +08:00
< el-dropdown-menu slot = "dropdown" class = "right-public-box-select-top right-public-box-dropdown-top detail-top-search-dropdown" >
2021-10-13 18:24:09 +08:00
< div style = "text-align: center;" > < el-input style = "width: calc(100% - 40px)" size = "small" v-model = "searchStr" @input="(val)=>{searchStrChange(val,key)}" suffix-icon="el-icon-search" /> < / div >
2021-10-13 11:12:26 +08:00
< el-checkbox-group v-model = "selectValue[item.key]" >
2021-10-12 16:53:59 +08:00
< el-dropdown-item v-for = "(item3,index3) in item.children" :key="index3" :title="item3.name" >
< el-checkbox :label = "item3.id" > { { item3 . name } } < / el-checkbox >
< / el-dropdown-item >
< / el-checkbox-group >
< / el-dropdown-menu >
< / el-dropdown >
< / span >
2021-10-15 15:59:46 +08:00
< span v-else-if = "item.type === 'dropdownCheckBox'&& key !== 'assetLabel'" >
2021-10-13 11:12:26 +08:00
< el-dropdown
2021-10-18 17:40:21 +08:00
: placement = "'bottom-start'"
2021-10-13 11:12:26 +08:00
class = "detail-dropdown"
type = "primary"
: trigger = "'click'"
: hide - on - click = "false"
@ visible - change = "searchStr = detailSearchListCopy[key].searchStr"
>
2021-10-18 17:40:21 +08:00
< div style = "padding-left: 10px;" >
< span class = "search-detail-title" v-if = "!selectValue[item.key].length" > {{ item.label }} : < / span >
2021-10-13 11:12:26 +08:00
< div class = "detail-top-search" v-if = "selectValue[item.key].length" >
< span v-for = "(item2,index2) in selectValue[item.key]" :key="item2" class="search-value" >
{ { getSearchStr ( item . oldChildren , item2 ) } } < span v-if = "index2+1 !== selectValue[item.key].length" > , < / span >
< / span >
< / div >
< div class = "detail-top-search" style = "text-align: center" v-else >
All
< / div >
< i class = "nz-icon nz-icon-arrow-down search-value" / >
< / div >
2021-10-18 16:34:37 +08:00
< el-dropdown-menu slot = "dropdown" class = "right-public-box-select-top right-public-box-dropdown-top detail-top-search-dropdown" >
2021-10-13 18:24:09 +08:00
< div style = "text-align: center;" > < el-input style = "width: calc(100% - 40px)" size = "small" v-model = "searchStr" @input="(val)=>{searchStrChange(val,key)}" suffix-icon="el-icon-search" /> < / div >
2021-10-13 11:12:26 +08:00
< el-checkbox-group v-model = "selectValue[item.key]" >
2021-10-13 14:44:34 +08:00
< el-dropdown-item v-for = "(item3,index3) in item.children" :key="index3" >
2021-10-15 10:22:02 +08:00
<!-- < span :title = "item3.name" class = "children-title-name" > { { item3 . name } } < / span > -- >
< el-checkbox :label = "item3.id+'-'+item4.id" :key = "index4" v-for = "(item4,index4) in item3.children" :title="item3.name+'/'+item4.name" > {{ item3.name + ' / ' + item4.name }} < / el -checkbox >
2021-10-13 11:12:26 +08:00
< / el-dropdown-item >
< / el-checkbox-group >
< / el-dropdown-menu >
< / el-dropdown >
< / span >
2021-10-15 15:59:46 +08:00
< span v-else-if = "item.type === 'dropdownCheckBox'&& key === 'assetLabel'" >
< el-dropdown
2021-10-18 17:40:21 +08:00
: placement = "'bottom-start'"
2021-10-15 15:59:46 +08:00
class = "detail-dropdown"
type = "primary"
: trigger = "'click'"
: hide - on - click = "false"
@ visible - change = "searchStr = detailSearchListCopy[key].searchStr"
>
2021-10-18 17:40:21 +08:00
< div style = "padding-left: 10px;" >
< span class = "search-detail-title" v-if = "!selectValue[item.key].length" > {{ item.label }} : < / span >
2021-10-15 15:59:46 +08:00
< div class = "detail-top-search" v-if = "selectValue[item.key].length" >
< span v-for = "(item2,index2) in selectValue[item.key]" :key="item2" class="search-value" >
{ { getSearchStr ( item . oldChildren , item2 , key ) } } < span v-if = "index2+1 !== selectValue[item.key].length" > , < / span >
< / span >
< / div >
< div class = "detail-top-search" style = "text-align: center" v-else >
All
< / div >
< i class = "nz-icon nz-icon-arrow-down search-value" / >
< / div >
2021-10-18 16:34:37 +08:00
< el-dropdown-menu slot = "dropdown" class = "right-public-box-select-top right-public-box-dropdown-top detail-top-search-dropdown" >
2021-10-15 15:59:46 +08:00
< div style = "text-align: center;" > < el-input style = "width: calc(100% - 40px)" size = "small" v-model = "searchStr" @input="(val)=>{searchStrChange(val,key)}" suffix-icon="el-icon-search" /> < / div >
< el-checkbox-group v-model = "selectValue[item.key]" >
< el-dropdown-item v-for = "(item3,index3) in item.children" :key="index3" >
< span :title = "item3.name" class = "children-title-name" > { { item3 . name } } < / span >
< el-checkbox :label = "item3.id+'-'+item4.id" :key = "index4" v-for = "(item4,index4) in item3.children" :title="item4.name" > {{ item4.name }} < / el -checkbox >
< / el-dropdown-item >
< / el-checkbox-group >
< / el-dropdown-menu >
< / el-dropdown >
< / span >
2021-10-12 16:53:59 +08:00
< / div >
< / div >
< / template >
< script >
export default {
name : 'detailViewTopSearch' ,
props : {
detailSearchList : {
/ *
* project : {
label : 'Project' , // 显示的label
key : 'projectIds' , // 搜索使用的key
type : 'checkBox' , // 类型
children : [ ] // 需要展示的子集
showMore : false , // 是否需要显示更多
index : 最大宽度的个数 , // 是否需要显示更多
} ,
* * /
type : Object ,
default ( ) {
return {
project : {
label : 'Project' , // 显示的label
key : 'projectIds' , // 搜索使用的key
type : 'checkBox' , // 类型
children : [ ] , // 需要展示的子集
show : false ,
showMore : false ,
index : 10 // 是否需要显示更多
}
}
}
} ,
2021-10-13 11:12:26 +08:00
selectValue : {
2021-10-12 16:53:59 +08:00
type : Object
}
} ,
2021-10-13 11:12:26 +08:00
computed : {
} ,
2021-10-12 16:53:59 +08:00
data ( ) {
return {
2021-10-13 11:12:26 +08:00
detailSearchListCopy : { } ,
searchStr : ''
}
} ,
methods : {
searchStrChange ( val , key ) {
2021-10-13 18:24:09 +08:00
if ( this . detailSearchListCopy [ key ] . type === 'checkBox' ) {
this . detailSearchListCopy [ key ] . searchStr = val
this . detailSearchListCopy [ key ] . children = this . detailSearchListCopy [ key ] . oldChildren . filter ( children => children . name . indexOf ( val ) !== - 1 )
} else {
this . detailSearchListCopy [ key ] . searchStr = val
const arr = [ ]
this . detailSearchListCopy [ key ] . oldChildren . forEach ( item => {
const children = item . children . filter ( children => children . name . indexOf ( val ) !== - 1 )
if ( children && children . length ) {
arr . push ( { ... item , children : children } )
}
} )
this . detailSearchListCopy [ key ] . children = arr
}
2021-10-13 11:12:26 +08:00
} ,
2021-10-15 15:59:46 +08:00
getSearchStr ( oldChildren , label , key ) {
2021-10-13 11:12:26 +08:00
const arr = label . split ( '-' )
const obj = oldChildren . find ( item => item . id == arr [ 0 ] )
const children = obj . children . find ( item => item . id == arr [ 1 ] )
2021-10-15 15:59:46 +08:00
if ( key !== 'assetLabel' ) {
return obj . name + '/' + children . name
} else {
return children . name
}
2021-10-14 14:14:25 +08:00
} ,
showDropDown ( val , key ) {
this . searchStr = this . detailSearchListCopy [ key ] . searchStr
this . detailSearchListCopy [ key ] . dropShow = val
2021-10-12 16:53:59 +08:00
}
} ,
watch : {
detailSearchList : {
immediate : true ,
deep : true ,
handler ( n ) {
this . detailSearchListCopy = JSON . parse ( JSON . stringify ( n ) )
2021-10-13 11:12:26 +08:00
Object . keys ( this . detailSearchListCopy ) . forEach ( key => {
this . detailSearchListCopy [ key ] . searchStr = ''
this . detailSearchListCopy [ key ] . oldChildren = JSON . parse ( JSON . stringify ( this . detailSearchListCopy [ key ] . children ) )
} )
2021-10-12 16:53:59 +08:00
}
} ,
2021-10-13 11:12:26 +08:00
selectValue : {
2021-10-12 16:53:59 +08:00
deep : true ,
handler ( n ) {
this . $emit ( 'reload' , n )
}
}
}
}
< / script >
2021-10-14 14:14:25 +08:00
< style scoped lang = "scss" >
. search - detail - box {
display : inline - block ;
margin - right : 20 px ;
transition : background - color .1 s ease - out ;
border - radius : 2 px ;
}
. search - detail - box : hover {
2021-10-15 10:22:02 +08:00
background : # F9F9F9 ;
2021-10-14 14:14:25 +08:00
}
. search - detail - box . select - dropdown {
2021-10-15 10:22:02 +08:00
background : # F9F9F9 ;
2021-10-14 14:14:25 +08:00
}
2021-10-15 10:22:02 +08:00
/*.search-detail-box.show-my-dropdpwn{*/
/* background-color: #344563;*/
/* color: #fff;*/
/* .search-detail-title{*/
/* color: #fff;*/
/* }*/
/* .detail-top-search{*/
/* color: #fff;*/
/* }*/
/* .search-value{*/
/* color: #fff;*/
/* }*/
/*}*/
2021-10-13 11:12:26 +08:00
. detail - dropdown {
padding : 0 10 px ;
height : 30 px ;
line - height : 30 px ;
border - radius : 2 px ;
}
. search - detail - title {
2021-10-12 16:53:59 +08:00
font - size : 14 px ;
color : # 333333 ;
letter - spacing : 0 ;
line - height : 14 px ;
font - weight : 600 ;
2021-10-18 17:40:21 +08:00
margin - right : 10 px ;
2021-10-12 16:53:59 +08:00
}
. search - value {
font - size : 14 px ;
color : # 666666 ;
letter - spacing : 0 ;
line - height : 14 px ;
font - weight : 400 ;
}
. detail - top - search {
display : inline - block ;
vertical - align : bottom ;
overflow : hidden ;
text - overflow : ellipsis ;
white - space : nowrap ;
2021-10-14 14:14:25 +08:00
max - width : 100 px ;
2021-10-12 16:53:59 +08:00
}
< / style >
< style lang = "scss" >
. detail - top - search - dropdown {
max - height : 300 px ;
overflow - y : auto ;
. el - dropdown - menu _ _item {
2021-10-13 18:24:09 +08:00
background : # fff ! important ;
2021-10-12 16:53:59 +08:00
padding : 0 ;
max - width : 200 px ;
overflow : hidden ;
text - overflow : ellipsis ;
white - space : nowrap ;
. el - checkbox {
width : calc ( 100 % - 20 px ) ;
height : 36 px ;
padding : 0 0 0 20 px ;
display : flex ;
align - items : center ;
. el - checkbox _ _label {
flex : 1 ;
overflow : hidden ;
text - overflow : ellipsis ;
white - space : nowrap ;
}
}
2021-10-13 18:24:09 +08:00
. el - checkbox : hover {
color : # fa901c ;
background - color : # fafafa ! important ;
}
. children - title - name {
width : calc ( 100 % - 20 px ) ;
height : 36 px ;
padding - left : 20 px ;
font - size : 12 px ;
color : # 909399 ;
line - height : 30 px ;
}
}
. el - dropdown - menu _ _item : not ( . is - disabled ) : hover {
color : # 606266 ;
background : # fff ! important ;
2021-10-12 16:53:59 +08:00
}
}
. clear - all - select {
padding : 0 20 px ;
2021-10-12 17:09:59 +08:00
padding - left : 42 px ;
2021-10-12 16:53:59 +08:00
color : # 0052 cc ;
font - size : 12 px ;
}
. clear - all - select : hover {
text - decoration : underline ;
}
< / style >