?
data() {
return {
tableData: [], //列表数据
maps:new Map(),//储存 子菜单信息
};
},
<el-table
:data="tableData"
style="width: 100%"
row-key="id"
border
lazy
:load="loadChild"
v-loading="loading"
ref="table"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
<el-table-column
prop="QC"
label="机构名称"
min-width="200">
</el-table-column>
<el-table-column
prop="BSM"
label="标识码"
min-width="200">
</el-table-column>
<el-table-column
prop="LXDH"
min-width="150"
label="联系电话">
</el-table-column>
<el-table-column
prop="CJSJ"
min-width="150"
label="创建时间">
</el-table-column>
<el-table-column label="操作"
width="350"
fixed="right"
align="center">
<template slot-scope="scope">
<el-button type="text"
icon="el-icon-delete"
:disabled="qxzt.sc == undefined ? true:!qxzt.sc"
:class="(qxzt.sc == undefined ? true:!qxzt.sc) ? '' : 'red' "
@click="handleDelete(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
// 删除操作
handleDelete(index, row) {
var that = this;
let delid=row.id;
let fuid='';
if(typeof delid == 'string'){
let index = delid.indexOf('_');//获取“_”首次出现的位置
fuid=row.id.substring(0,index);
delid = delid.substring( index + 1 );
}
// 二次确认删除
that.$confirm('确定要删除吗?', '提示', {
type: 'warning'
})
.then(() => {
axios
.ajax({
method: 'GET',
url: url.xtgl.deptremove,
params: {
deptId: delid
}
})
.then((res) => {
if (res.code == 200) {
// that.tableData.splice(index, 1);
this.$message.success(res.msg);
setTimeout(function() {
let allzjd=[]
that.tableData.forEach(function(v,i) {
if(v.ID==fuid){
allzjd=v.children
}
});
let delzjdsy=''
allzjd.forEach(function(k,w) {
if(k.ID == delid){
delzjdsy=w
}
});
allzjd.splice(delzjdsy, 1);
that.$set(that.$refs.table.store.states.lazyTreeNodeMap,fuid,allzjd)
},800)
} else {
that.$message.success(res.msg);
}
});
})
.catch(() => {
that.$message.success('取消删除');
});
},
//加载子菜单
loadChild(tree, treeNode, resolve) {
const pid = tree.id;
this.maps.set(pid,{tree,treeNode,resolve})
axios
.ajax({
method: 'get',
url: url.xtgl.deptlist,
params: {
FJBSM: tree.BSM
}
})
.then((res) => {
let resolvedata = res.data;
resolvedata.forEach(function(v, i) {
v.id = tree.id + '_' + v.ID;
v.zbm = false;
});
tree.children=resolvedata
resolve(resolvedata);
});
},
|