This commit is contained in:
杰 朱
2021-10-20 19:42:28 +08:00
parent 9f2c936f8f
commit 8df04ff12e
2 changed files with 121 additions and 115 deletions

View File

@@ -1,20 +1,8 @@
<template>
<div>
<Table
border
:data="filters"
:columns="tableColumnsFilters"
>
</Table>
<Table border :data="filters" :columns="tableColumnsFilters"></Table>
<Table
:show-header=false
border
:data="data"
:columns="columns"
>
</Table>
<Table :show-header="false" border :data="data" :columns="columns"></Table>
</div>
</template>
@@ -27,12 +15,14 @@
},
data() {
return {
filters: [{
title: ''
}],
tableColumnsFilters: [],
search: {},//过滤条件保存的对象,就是保存Input框和Select中值
filters: [
{
title: ""
}
],
tableColumnsFilters: [],
search: {} //过滤条件保存的对象,就是保存Input框和Select中值
};
},
created() {
for (let index in this.columns) {
@@ -42,11 +32,11 @@
* 数据表隐藏表头,只显示数据,渲染的数据是传入的columns中的key值
*/
//将传入的列描述数据对象(columns) 的title和width 复制给 过滤表的列描述数据对象(tableColumnsFilters)
this.$set(filter, 'title', this.columns[index].title);
this.$set(filter, "title", this.columns[index].title);
if (this.columns[index].width) {
this.$set(filter, 'width', this.columns[index].width);
this.$set(filter, "width", this.columns[index].width);
}
let render = (h) => {};
let render = h => {};
/**
* 需要有搜索的列, 只要在 列描述数据对象columns中配置 filter属性就行如下:
{
@@ -68,15 +58,20 @@
//如果存在 过滤选项
if (this.columns[index].filter) {
//过滤为 下拉选择框
if (this.columns[index].filter.type && this.columns[index].filter.type === 'Select') {
render = (h) => {
return h(this.columns[index].filter.type, {
if (
this.columns[index].filter.type &&
this.columns[index].filter.type != "Input"
) {
render = h => {
return h(
this.columns[index].filter.type,
{
props: {
value: 0, //Select选项列表一般 0 为全部
transfer: true,
transfer: true
},
on: {
'on-change': (val) => {
"on-change": val => {
if (val === 0) {
//当选项是全部的时候删除 search中该字段的过滤条件
this.$delete(this.search, this.columns[index].key);
@@ -88,11 +83,14 @@
this.load();
}
}
}, this.createOptionsRender(index, h));
},
this.createOptionsRender(index, h)
);
};
}
} else {
else {
//如果是输入框
render = (h) => {
render = h => {
//获取输入框的值,为了减少数据库的压力,我这里是
//通过回车和点击搜索按钮才进行数据过滤查询,如果
//要输入框变化就进行过滤,把 this.load()放到
@@ -100,8 +98,9 @@
let inputValue = {};
return h(this.columns[index].filter.type, {
props: {
placeholder: '输入' + this.columns[index].title,
icon: 'ios-search-strong'
placeholder: "输入" + this.columns[index].title,
icon: "ios-search-strong",
transfer: false
},
on: {
input: val => {
@@ -111,18 +110,18 @@
}
},
//input框后面的搜索按钮的点击事件
'on-click': () => {
"on-click": () => {
this.validInputValue(index, inputValue);
},
'on-enter': () => {
"on-change": () => {
this.validInputValue(index, inputValue);
}
}
})
});
};
}
}
this.$set(filter, 'render', render);
this.$set(filter, "render", render);
this.tableColumnsFilters.push(filter);
}
},
@@ -133,11 +132,17 @@
if (this.columns[index].filter.option) {
let option = this.columns[index].filter.option;
for (let i in option) {
optionRender.push(h('Option', {
optionRender.push(
h(
"Option",
{
props: {
value: option[i].value
}
}, option[i].name))
},
option[i].name
)
);
}
}
return optionRender;
@@ -145,7 +150,7 @@
//重新加载数据
load() {
//会执行一个load的事件
this.$emit('on-search',this.search);
this.$emit("on-search", this.search);
},
//验证输入框的值
validInputValue(index, inputValue) {
@@ -158,7 +163,7 @@
this.load();
}
}
}
};
</script>
<style scoped>

View File

@@ -159,7 +159,7 @@ export default {
return <div> {dateFormat(params.row.dDate)} </div>;
},
filter: {
type: "Input"
type: "DatePicker"
}
},
{
@@ -386,6 +386,7 @@ export default {
console.log(search);
let _filert = {
abc:"123",
c_cus_abb_name: search.cCusAbbName,
d_date: search.dDate,
c_so_code: search.cSOCode,