<template> <el-dialog :visible.sync="dialogFormVisible" append-to-body custom-class="area-select-dialog" title="选择责任网格"> <el-scrollbar style="height: 400px"> <el-tree ref="tree" :expand-on-click-node="false" :props="defaultProps" :load="loadNode" node-key="id" lazy /> </el-scrollbar> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="confirmSelect">确定</el-button> <el-button @click="cancel">取消</el-button> </div> </el-dialog> </template> <script> import { getAreaTree } from '@/api/system/area' export default { name: 'AreaSelectTree', data() { return { dialogFormVisible: true, defaultProps: { label: 'name', children: 'children', isLeaf: 'leaf' }, listQuery: { pid: '' } } }, methods: { // 获取数据 // fetchData() { // return new Promise(function(resolve, reject) { // getAreaTree(this.roleId) // }) // }, initDialog() { this.dialogFormVisible = true }, loadNode(node, resolve) { if (node.data && node.data.id) { this.listQuery.pid = node.data.id } getAreaTree(this.listQuery).then(response => { const data = response.data resolve(data) }) }, // 选择后的操作 confirmSelect() { const node = this.$refs.tree.getCurrentNode() this.dialogFormVisible = false this.$emit('selectDone', node) }, cancel() { this.dialogFormVisible = false } } } </script> <style scoped> </style> <style lang="scss" scope> .area-select-dialog{ width: 400px; .el-scrollbar__wrap{ overflow-x: hidden !important; } } </style>