|
@@ -0,0 +1,170 @@
|
|
|
+<template>
|
|
|
+ <el-button text @click="dialogVisible = true"
|
|
|
+ >{{title}}</el-button
|
|
|
+ >
|
|
|
+ <el-dialog
|
|
|
+ v-model="dialogVisible"
|
|
|
+ title="行政区划选取"
|
|
|
+ width="30%"
|
|
|
+ :before-close="handleClose"
|
|
|
+ >
|
|
|
+ <el-scrollbar wrapClass="scroll-wrap">
|
|
|
+ <el-tree
|
|
|
+ node-key="code"
|
|
|
+ :props="defaultProps"
|
|
|
+ :default-expanded-keys="expands"
|
|
|
+ :expand-on-click-node="false"
|
|
|
+ lazy
|
|
|
+ :load="loadNode"
|
|
|
+ ref="tree"
|
|
|
+ :check-strictly="true"
|
|
|
+ highlight-current
|
|
|
+ @check="checkGroupNode"
|
|
|
+ @node-click="handleNodeClick"
|
|
|
+ />
|
|
|
+ </el-scrollbar>
|
|
|
+ <template #footer>
|
|
|
+ <span class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="dialogVisible = false"
|
|
|
+ >关闭</el-button
|
|
|
+ >
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import {defineComponent} from "vue";
|
|
|
+import { ElMessageBox } from 'element-plus'
|
|
|
+import {gettreedata} from "@/api/home";
|
|
|
+import {mapState} from 'vuex'
|
|
|
+export default defineComponent({
|
|
|
+ props:{
|
|
|
+ //是否只显示吉林的数据 true显示吉林省的数据, false显示全国的数据
|
|
|
+ title:{
|
|
|
+ type:String,
|
|
|
+ default:"qubau",
|
|
|
+ },
|
|
|
+ isJl:{
|
|
|
+ type:Boolean,
|
|
|
+ default:true,
|
|
|
+ },
|
|
|
+ isLoad:{
|
|
|
+ type:Boolean,
|
|
|
+ default:true,
|
|
|
+ },
|
|
|
+
|
|
|
+ },
|
|
|
+ data(){
|
|
|
+ return{
|
|
|
+ dialogVisible:false,
|
|
|
+ defaultProps: {
|
|
|
+ childre: 'children',
|
|
|
+ label: 'label',
|
|
|
+ isLeaf: 'leaf',
|
|
|
+ },
|
|
|
+ expands:[],
|
|
|
+ treenode:[],
|
|
|
+ resolve:{},
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ },
|
|
|
+ methods:{
|
|
|
+ updatetree()
|
|
|
+ {
|
|
|
+ if (this.treenode) {
|
|
|
+ this.treenode.childNodes = [] // 清空子节点
|
|
|
+ this.loadNode(this.treenode, this.resolve) // 再次执行 load 的方法
|
|
|
+ }
|
|
|
+ },
|
|
|
+ treeClear(){
|
|
|
+ console.log('重置了');
|
|
|
+ this.$refs.tree.setCheckedKeys([]);
|
|
|
+ },
|
|
|
+ check (data, checked, indeterminate) {
|
|
|
+ this.$refs.tree.setCheckedKeys([data.id])
|
|
|
+ },
|
|
|
+ handleNodeClick(data,node,root) {
|
|
|
+ let retdata=[];
|
|
|
+ retdata.push(node.data);
|
|
|
+ let pp=node.parent;
|
|
|
+ while (pp)
|
|
|
+ {
|
|
|
+ retdata.push(pp.data);
|
|
|
+ pp=pp.parent;
|
|
|
+ }
|
|
|
+ this.$emit('handleNodeClick',retdata);
|
|
|
+ this.dialogVisible = false;
|
|
|
+ },
|
|
|
+ checkGroupNode(a, b){
|
|
|
+ if (b.checkedKeys.length > 0) {
|
|
|
+ this.$refs.tree.setCheckedKeys([a.id]);
|
|
|
+ this.$emit('handleNodeClick',a)
|
|
|
+ }else {
|
|
|
+ this.$emit('handleNodeClick',{code:null})
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async getdata(level, cs2, cs3, resolve) {
|
|
|
+
|
|
|
+ var para = {};
|
|
|
+ para.dictType = "xzqhall";
|
|
|
+ para.outType = '0';
|
|
|
+ para.para1 = level;
|
|
|
+ para.para2 = cs2;
|
|
|
+ para.para3 = cs3;
|
|
|
+ let data = await gettreedata(para);
|
|
|
+ var treedata = [];
|
|
|
+ if (data.code == 200) {
|
|
|
+ for (let i = 0; i < data.data[0].recordCount; i++) {
|
|
|
+ treedata[i] = {};
|
|
|
+ for (let j = 0; j < data.data[0].columnLabelList.length; j++) {
|
|
|
+ treedata[i][data.data[0].columnLabelList[j].toLowerCase()] = data.data[0].rowList[i][j];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ treedata.forEach((item) => {
|
|
|
+ item.isleaf == '0' ? (item.leaf = false) : (item.leaf = true)
|
|
|
+ })
|
|
|
+ resolve(treedata);
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async loadNode(node, resolve) {
|
|
|
+
|
|
|
+ if (node.level === 0) {
|
|
|
+ this.treenode=node;
|
|
|
+ this.resolve=resolve;
|
|
|
+ // if (this.isLoad==false) return ;
|
|
|
+ return this.getdata(node.level, 'sj', '', resolve);
|
|
|
+ } else if (node.level >= 1) {
|
|
|
+ // if (this.isLoad==false) return ;
|
|
|
+ return this.getdata(node.level, node.data.nextlevel, node.data.id, resolve);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // handleNodeClick(data) {
|
|
|
+ // this.$emit('handleNodeClick',data)
|
|
|
+ // },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ isLoad(newVal) {
|
|
|
+ this.updatetree();
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ,
|
|
|
+
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.dialog-footer button:first-child {
|
|
|
+ margin-right: 10px;
|
|
|
+}
|
|
|
+::v-deep .scroll-wrap{
|
|
|
+ height: 62vh;
|
|
|
+ padding-right: 10px;
|
|
|
+}
|
|
|
+</style>
|