|
<template>
|
<div class="tabs-nav-container">
|
<template v-for="(tab, index) in currentTabNavList">
|
<template v-if="tab.type==='checkbox'">
|
<el-checkbox-group :key="'rg_'+index" v-model="tab.value" size="mini" class="tabs-nav" @change="checkBoxGroupChange">
|
<el-checkbox-button v-for="(item, itemIndex) in tab.items.filter((li, _index)=>{return _index < tab.showCount})" :key="itemIndex" :label="item.label">{{ item.label }}</el-checkbox-button>
|
</el-checkbox-group>
|
<el-dropdown v-if="tab.items.length>tab.showCount" :key="'dd_'+index" size="mini">
|
<el-button type="text" size="mini">
|
更多
|
<i class="el-icon-arrow-down el-icon--right"></i>
|
</el-button>
|
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-item v-for="(item, itemIndex) in tab.items.filter((li, _index)=>{return _index >= tab.showCount})" :key="itemIndex" :class="{'active':activeMenuItem(tab, item)}" @click.native="menuItemClick(tab, item)">{{ item.label }}</el-dropdown-item>
|
</el-dropdown-menu>
|
</el-dropdown>
|
</template>
|
<template v-else-if="tab.type==='radio'">
|
<el-radio-group :key="'rg_'+index" v-model="tab._value" size="mini" class="tabs-nav">
|
<el-radio-button v-for="(item, itemIndex) in tab.items.filter((li, _index)=>{return _index < tab.showCount})" :key="itemIndex" :label="item.label" @click.native="radioGroupChange(tab, item)">{{ item.label }}</el-radio-button>
|
</el-radio-group>
|
<el-dropdown v-if="tab.items.length>tab.showCount" :key="'dd_'+index" size="mini">
|
<el-button type="text" size="mini">
|
更多
|
<i class="el-icon-arrow-down el-icon--right"></i>
|
</el-button>
|
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-item v-for="(item, itemIndex) in tab.items.filter((li, _index)=>{return _index >= tab.showCount})" :key="itemIndex" :class="{'active':activeMenuItem(tab, item)}" @click.native="menuItemClick(tab, item)">{{ item.label }}</el-dropdown-item>
|
</el-dropdown-menu>
|
</el-dropdown>
|
</template>
|
</template>
|
</div>
|
</template>
|
|
<script>
|
export default {
|
props: {
|
// tab导航数据结构
|
tabNavList: {
|
type: Array,
|
default: () => {
|
return [];
|
}
|
}
|
},
|
data() {
|
return {};
|
},
|
computed: {
|
currentTabNavList: {
|
get: function() {
|
return this.tabNavList;
|
}
|
}
|
},
|
watch: {
|
currentTabNavList: {
|
handler(val) {},
|
deep: true
|
}
|
},
|
methods: {
|
// 复选组改变
|
checkBoxGroupChange(tab, item) {
|
this.getWhere();
|
},
|
// 单选组改变
|
radioGroupChange(tab, item) {
|
tab.value = item.label;
|
this.getWhere();
|
},
|
// 菜单项选择
|
menuItemClick(tab, item) {
|
if (tab.type === "checkbox") {
|
var index = tab.value.findIndex(s => {
|
return s === item.label;
|
});
|
if (index >= 0) {
|
tab.value.splice(index, 1);
|
} else {
|
tab.value.push(item.label);
|
}
|
} else {
|
tab.value = item.label;
|
tab._value = null;
|
}
|
this.getWhere();
|
},
|
// 是否选中
|
activeMenuItem(tab, item) {
|
if (tab.type === "checkbox") {
|
var index = tab.value.findIndex(s => {
|
return s === item.label;
|
});
|
return index >= 0;
|
} else {
|
return tab.value === item.label;
|
}
|
},
|
// 获得条件
|
getWhere() {
|
var where = [];
|
this.currentTabNavList.forEach(item => {
|
if (item.type === "checkbox") {
|
if (item.value.length) {
|
where.push({
|
prop: item.field,
|
value: item.value
|
});
|
}
|
} else {
|
if (item.value) {
|
where.push({
|
prop: item.field,
|
value: item.value
|
});
|
}
|
}
|
});
|
this.$emit("on-tabs-nav-change", where);
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.tabs-nav-container {
|
.tabs-nav {
|
display: inline-block;
|
}
|
.el-dropdown {
|
top: 3px;
|
margin-right: 20px;
|
}
|
}
|
.el-dropdown-menu {
|
.active {
|
background-color: #409eff;
|
color: white;
|
}
|
}
|
</style>
|