1,绑定 :load="load"
<el-table :data="list" :header-cell-style="{background:'#e9eff8'}"
row-key="dictId" lazy :row-style="{cursor:'pointer'}"
:load="load" border size="mini" v-loading="loading">
</el-table>
data数据
data() {
return {
list: [],
uploadData:{
tree:null,
treeNode:null,
resolve:null
}
}
},
2,把需要加载的下级数据传入resolve(data)
//搜索
getList() {
this.loading = true;
apiDictionarySearch(this.form).then(res => {
this.total = res.total;
res.data.forEach(item => {
item.hasChildren = [];
this.listArr.push(item)
})
this.list = res.data;
this.loading = false;
})
},
load(tree, treeNode, resolve) {
// tree为点击那一行的数据
this.uploadData.tree = tree;
this.uploadData.treeNode = treeNode;
this.uploadData.resolve = resolve;
let value = tree.dictValue;
apiCommonDictionAry(value).then(res => {
res.dicList.forEach(item => {
//判断是否有子节点
if (item.isParent > 0) {
item.hasChildren = []
}
this.listArr.push(item)
});
//传入res.dicList加载下一级
resolve(res.dicList);
if (res.dicList.length == 0) {
this.$message({
type: 'error',
message: '本节点以下暂无子节点!'
});
}
})
},
删除事件(可以及时看到删除后的数据)
//删除按钮事件
delateFunction(index,data) {
this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
apiDictionaryDelete(data.dictId).then(() => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
this.load(this.uploadData.tree,this.uploadData.treeNode,this.uploadData.resolve);
})
})
},
添加和修改方法后也调用一下load方法(可以及时看到修改或添加的内容)
<!-- 编辑&添加弹框组件 -->
<change-edit :caseProcessList="caseProcessList" :child="editObj.child" :list="list" :listArr="listArr"
:parent="editObj.parent" :uploadData="uploadData"
:show.sync="editObj.show" :title="editObj.title"
:type="editObj.editId" @getList="getList" :load="load"/>
组件内容
<template>
<div>
<el-dialog :close-on-click-modal='false' :title="title" :visible="show" @close="closeDialog" center
width="550px">
<el-form :model="form" :rules="rules" label-width="130px" ref="ruleForm" size="medium"
v-loading="loading">
<el-row>
自己的内容
</el-row>
</el-form>
<span class="dialog-footer" slot="footer">
<el-button @click="closeDialog" size="small" type="info">
<i class="lj_font icon_quxiaofanhui"></i>取 消
</el-button>
<el-button @click="submitForm('ruleForm')" size="small" type="primary">
<i class="lj_font icon_baocun"></i>确 定
</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {apiDictionaryAdd, apiDictionaryGet, apiDictionaryUpdate} from "../../../../api/system";
export default {
name: 'edit',
props: {
//证据类型数组listArr
list: {
type: Array,
default: []
},
listArr: {
type: Array,
default: []
},
caseProcessList: {
type: Array,
default: []
},
show: {
type: Boolean,
default: false
},
title: {
type: String,
default: '编辑'
},
type: {
type: String,
default: ''
},
child: {
type: Number,
default: ''
},
parent: {
type: Number,
default: ''
},
uploadData:{
type:Object,
default:{}
},
load: {
type: Function,
default: null
}
},
data() {
return {
loading: true,
wordvalue: '',
form: {},
}
},
methods: {
closeDialog() {
this.$emit('update:show', false)
},
submitForm() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
if (this.type) {
let tree = this.uploadData.tree;
let treeNode = this.uploadData.treeNode;
let resolve = this.uploadData.resolve;
if (!this.child) {
//编辑
this.loading = true;
apiDictionaryUpdate(this.form).then(res => {
this.$emit("getList");
this.load(tree,treeNode,resolve)
this.$message({
type: 'success',
message: '修改成功!'
});
this.loading = false;
this.closeDialog();
}).catch(res=>{
this.loading = false;
})
} else {
//添加子集
this.loading = true;
apiDictionaryAdd(this.form).then(res => {
this.$emit("getList");
this.load(tree,treeNode,resolve)
this.$message({
type: 'success',
message: '添加成功!'
});
this.loading = false;
this.closeDialog();
}).catch(res=>{
this.loading = false;
})
}
} else {
//添加父级
this.loading = true;
apiDictionaryAdd(this.form).then(res => {
this.$emit("getList");
this.$message({
type: 'success',
message: '字典添加成功!'
});
this.loading = false;
this.closeDialog();
}).catch(res=>{
this.loading = false;
})
}
}
});
},
//弹框弹出时获取data给form
initPage() {
if (this.type) {
//修改
if (!this.child) {
apiDictionaryGet(this.type).then(res => {
this.form = res.data;
this.form.isDisable = String(res.data.isDisable);
this.loading = false;
let parid = this.form.subDict;
let filtObj = this.listArr.find(item => {
return item.dictValue === parid
});
if (filtObj) {
this.form.parentName = filtObj.dictName
} else {
this.form.parentName = "根节点"
}
});
} else {
//新增子节点
this.loading = false;
apiDictionaryGet(this.type).then(res => {
this.form = res.data;
this.form.subDict = res.data.dictValue;
this.form.isDisable = '1';
this.form.parentName = this.form.dictName
this.form.dictName = '';
this.form.dictValue = '';
this.form.dictOrder = '';
this.form.isBase = 0;
});
}
} else {
//新增根节点
this.loading = false;
//根节点
this.form = {
dictName: '',
dictValue: '',
subDict: '',
isBase: '1',
// isSys:'',
isDisable: '',
dictOrder: ''
};
}
}
},
//监听,如果show为true,则执行initPage()
watch: {
show(value) {
if (value) {
this.initPage();
this.$nextTick(() => {
this.$refs.ruleForm.clearValidate();
})
}
},
},
}
</script>
<style lang='less' scoped>
</style>