vxe-grid的树重新push进去值不展开的解决办法--setTreeExpand(row,true)
<el-row ref="tableList">
<vxe-grid ref="xGrid" id="dataTable" :print-config="{}" :import-config="{}" :export-config="{}"
:toolbar-config="formDisable?null:tableToolbar" :columns="tableColumn" :data="tableData" :height="tableHeight"
:loading="loading" :seq-config="{startIndex:0}" @toolbar-button-click="toolbarButtonClickEvent"
:cell-class-name="cellClassName">
<template #goodsName_show="{ row }">
<table width="100%">
<tr>
<td width="80%">{{row.goodsNameCn}}</td>
<td width="20%" rowspan="2">
<i @click="findGood(row)" class="fa fa-search-plus col-geekblue fr fa-lg"></i>
</td>
</tr>
<tr>
<td>{{row.goodsNameEn}}</td>
</tr>
</table>
</template>
</vxe-grid>
</el-row>
<el-row class='editpage-footer-button' v-if="!formDisable">
<div class="show-item">
<el-button type="primary" @click="handleAddInquiry">
<i class="fa fa-plus"></i>
添加待询价
</el-button>
<el-select v-model="supplierCode" placeholder="请选择供应商" clearable style="width: 120px;margin-left:15px;"
@change="selectSupplier">
<el-option v-for="item in supplierList" :key="item.value" :label="item.label" :value="item">
<span class="fl">{{ item.value }}</span>
<span class="fr">{{ item.label }}</span>
</el-option>
</el-select>
<el-input style="width:120px;" v-model="supplierName" placeholder="选择供应商自动带出" :disabled="true" clearable />
</div>
</el-row>
<vxe-grid :tree-config="tableTreeConfig" @current-change="currentChange" :row-config="{isCurrent: true, isHover: true}" resizable ref="xGrid1" :data="targetTableData" :height="targetTableHeight" :columns="targetTableColumn" :edit-config="{ trigger: 'click', enabled: !this.formDisable, mode: 'row', showStatus: true, }"> <template #goodsName_show="{ row }"> <table width="100%"> <tr> <td width="80%">{{row.goodsNameCn}}</td> </tr> <tr> <td>{{row.goodsNameEn}}</td> </tr> </table> </template> <template #remark_edit="{ row }"> <vxe-input v-model="row.remark"></vxe-input> </template> </vxe-grid>
<script> export default { name: "aa", data() { return {
supplierList: [],
formDisable: false,
tableHeight: 300, // 表格高度
loading: false,
tableData: [],
tableToolbar: {
buttons: [
{
code: "myInsert",
name: "添加商品",
icon: "fa fa-plus",
status: "primary"
},
{
code: "myDel",
name: "删除",
icon: "fa fa-trash"
},
{
code: "import",
name: "导入",
icon: "fa fa-upload"
},
{
code: "translate",
name: "拆行",
icon: "fa fa-arrow-circle-o-right"
}
]
},
tableColumn: [
{
type: "checkbox",
width: 30,
align: "center"
},
{
type: "seq",
title: "序号",
showOverflow: true,
width: 40,
align: "center"
},
{
field: "goodsCode",
title: "商品编码",
showOverflow: true,
width: 100,
align: "center",
sortable: true
},
{
field: "",
title: "商品名",
showOverflow: true,
width: 200,
slots: { default: "goodsName_show" }
},
{
field: "specification",
title: "规格",
showOverflow: true,
width: 80,
sortable: true
},
{
field: "unit",
title: "单位",
showOverflow: true,
width: 80,
align: "center"
},
{
field: "count",
title: "数量",
showOverflow: true,
width: 80,
align: "right",
sortable: true
},
{
field: "stockCount",
title: "库存数量",
showOverflow: true,
width: 80,
align: "right"
},
{
field: "stockMachine",
title: "库存价格",
showOverflow: true,
width: 80,
align: "right",
formatter: "myCount"
},
{
field: "noticePrice",
title: "账本价格",
showOverflow: true,
width: 80,
align: "right",
formatter: "myCount"
},
{
field: "unitPrice",
title: "单价",
showOverflow: true,
width: 80,
align: "right",
sortable: true
},
{
field: "amount",
title: "金额",
showOverflow: true,
width: 80,
align: "right",
sortable: true
},
{
field: "privder",
title: "默认供应商",
showOverflow: true,
width: 100,
align: "center",
cellRender: {
name: "VXETabelCellLink",
events: { click: this.defaultLinkEvent }
}
},
{
field: "referenceUnit",
title: "参考单价",
showOverflow: true,
width: 80,
align: "right"
},
{
field: "remark",
title: "备注",
showOverflow: true,
width: 180
}
],
targetTableHeight: 300, // 表格高度
targetTableData: [],
targetTableColumn: [
{
type: "checkbox",
showOverflow: true,
width: 40,
align: "center"
},
{
field: "supplierName",
title: "供应商",
showOverflow: true,
width: 120,
align: "center"
},
{
field: "goodsCode",
title: "商品编码",
showOverflow: true,
width: 100,
align: "center",
sortable: true
},
{
field: "goodsName",
title: "商品名",
showOverflow: true,
width: 150,
slots: { default: "goodsName_show" }
},
{
field: "spesc",
title: "规格",
showOverflow: true,
width: 80,
sortable: true
},
{
field: "unit",
title: "单位",
showOverflow: true,
width: 80
},
{
field: "count",
title: "数量",
showOverflow: true,
width: 80,
align: "right",
sortable: true
},
{
field: "remark",
title: "询价备注",
showOverflow: true,
width: 140,
editRender: { autofocus: ".vxe-input--inner" },
slots: { edit: "remark_edit" }
}
],
tableTreeConfig: {
children: "children",
accordion: false, // 一层只允许展开一个节点
expandAll: true, // 默认是否全部展开
},
supplierCode: null,
supplierName: null,
};
},
created() {
// 供应商
this.getsupplierList();
this.loadData();
},
methods: {
// 供应商列表
getsupplierList() {
this.request({
url: "/common/supplierSelect",
method: "get",
data: {}
}).then((res) => {
this.supplierList = res.data;
console.log(res);
});
},
// 供应商选择
selectSupplier(e) {
this.supplierCode = e.value;
this.supplierName = e.label;
},
loadData() {
this.request({
url: "/inquiry/inquiryAddGoodsListShow",
method: "post",
data: {}
}).then((res) => {
this.tableData = res.data;
});
},
// 数组去重 dedupe(array) { return Array.from(new Set(array)); }, // 添加待询价 handleAddInquiry() { let that = this; const $grid = that.$refs.xGrid; const rows = $grid.getCheckboxRecords(); if (rows.length == 0) { that.commonMessage.message("E000027", "待询价商品"); return; } else if (that.supplierCode == null || that.supplierCode == "") { that.commonMessage.message("E000027", "供应商"); } else { let flag = true; rows.forEach((item, index) => { if (item.isUseStorage) { that.commonMessage.message("E000029", item.goodsCode + "使用库存"); flag = false; } else if (item.isUseBookPrice) { that.commonMessage.message("E000029", item.goodsCode + "账本价格"); flag = false; } }); if (flag) { let obj = { supplierCode: that.supplierCode, supplierName: that.supplierName, children: rows }; if (that.targetTableData.length == 0) { that.targetTableData.push(obj); } else { let targetTableData = that.targetTableData; // 存在同名的组 if ( targetTableData.find((item) => { return item.supplierCode == obj.supplierCode; }) ) { targetTableData.forEach((val, idx) => { if (val.supplierCode == obj.supplierCode) { let childrenData = targetTableData[idx].children; let contactData = childrenData.concat(rows); let newData = that.dedupe(contactData); that.targetTableData[idx].children = newData; } }); } else { // 不存在同名的组 that.targetTableData.push(obj); this.$refs["xGrid1"].setTreeExpand(obj, true); // vxe的树首次加载会展开,重新push值不会展开,这是需要加入展开这一行的代码 console.log(that.targetTableData); } } } } },
} }; </script>