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