html部分
//查询字段
<el-form-item label="查询字段" prop="cxzd">
<el-select
size="mini"
v-model="value2"
multiple
collapse-tags
filterable
>
<el-option
v-for="(item, index) in options2"
:key="index"
:label="item.zdzwm"
:value="item.id"
/>
</el-select>
</el-form-item>
//列表
<el-table :height="tableHeight" :data="dataForm" style="width: 100%">
<el-table-column
v-for="(col, index) in cols"
:key="index"
:prop="col.prop"
:label="col.label"
/>
</el-table>
初始化部分
dataForm: [],
cols: [],
js部分
//控制表格高度
getHeight() {
this.tableHeight = window.innerHeight - 450 + "px";
},
//列表查询方法
loadTableData(type) {
if (type == "search") {
this.current = 1;
}
this.cols = [];
if (this.value2 == null || this.value2.length == 0) {
this.$alert("未选择查询字段", "提示", {
confirmButtonText: "确定",
});
return;
}
let cxzdIds = this.value2.join(",");
let cxtj = JSON.stringify(this.tjForm);
//如果this.showtj为true则传cxtj,否则传pxtj
let obj = {};
if (this.showtj) {
obj.cxtj = cxtj;
} else {
obj.pxtj = cxtj;
}
this.$http({
url: this.$Api.query,
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
data: this.$qs.stringify({
current: this.current,
size: this.size,
tjbid: this.tjbid,
cxzdIds: cxzdIds,
...obj,
}),
}).then((res) => {
if (res.data.code == "1") {
// 重置表单列表字段
//options2的数据是请求接口获取到的
for (let i = 0; i < this.value2.length; i++) {
for (let j = 0; j < this.options2.length; j++) {
if (this.value2[i] == this.options2[j].id) {
this.cols.push({
prop: this.options2[j].zdm,
label: this.options2[j].zdzwm,
});
}
}
}
//加载列表数据
this.dataForm = res.data.data.records;
this.size = parseInt(res.data.data.size);
this.total = parseInt(res.data.data.total);
} else {
this.$message.error(res.data.msg);
}
});
},
options2数据如下