| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <template>
- <div>
- <div class="head-container">
- <el-input
- v-model="deptName"
- placeholder="请输入机构名称"
- clearable
- size="small"
- prefix-icon="el-icon-search"
- style="margin-bottom: 20px"/>
- </div>
- <div class="tree-container">
- <div style="margin-bottom: 10px;">
- <el-checkbox v-model="checkSub" @change="changeCheckBox">是否关联上级</el-checkbox>
- </div>
- <el-tree
- :data="treeList"
- :props="defaultProps"
- :expand-on-click-node="false"
- :filter-node-method="filterNode"
- ref="tree"
- node-key="id"
- :default-expanded-keys="defaultKeys"
- :default-checked-keys="defaultKeys"
- @node-click="handleNodeClick"
- />
- </div>
- </div>
- </template>
- <script>
- import tableListMixins from "@/mixins/tableList";
- import {deptTreeSelect,handsheDeptTreeSelect} from "@/api/system/public";
- export default {
- name: "k-orgTree",
- mixins:[tableListMixins],
- data(){
- return {
- //过滤信息
- deptName:'',
- //是否关联下级
- checked: false,
- // 机构树列表
- treeList: [],
- //默认选中节点
- defaultKeys:[],
- //自定义取值
- defaultProps: {
- children: "children",
- label: "shortname"
- },
- checkSub:true,
- defaultKey:null,
- }
- },
- props:{
- hangsheTree:{
- type:Boolean,
- default: false,
- }
- },
- watch: {
- // 根据名称筛选机构树
- deptName(val) {
- this.$refs.tree.filter(val);
- }
- },
- created() {
- this.getDeptTree();
- },
- methods:{
- /** 下穿状态改变*/
- changeCheckBox(state){
- this.$emit('checkChange',state);
- },
- /** 查询机构下拉树结构 */
- getDeptTree() {
- let method=deptTreeSelect;
- if(this.hangsheTree){
- method=handsheDeptTreeSelect
- }
- method().then(response => {
- this.treeList = response.data;
- this.defaultKeys.push(response.data[0].id);
- this.$emit('defaultKey',response.data[0].id);
- this.defaultKey = response.data[0].id;
- });
- },
- // 筛选节点
- filterNode(value, data) {
- if (!value) return true;
- return data.name.indexOf(value) !== -1;
- },
- // 节点单击事件
- handleNodeClick(data) {
- this.$emit('click',data);
- },
- },
- }
- </script>
- <style scoped>
- </style>
|