123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <template>
- <div class="organ-tree">
- <div>
- <el-input v-model="filterText" placeholder="请输入关键字" suffix-icon="el-icon-search"></el-input>
- </div>
- <div class="tree-style-box no-scrollbar" v-if="organList">
- <el-tree
- class="tree-style"
- :data="organList"
- ref="tree"
- node-key="id"
- :highlight-current="true"
- :props="defaultProps"
- :expand-on-click-node="false"
- @node-click="treeClick"
- @check="clickCheckTree"
- :default-expand-all="defaultExpandAllTree"
- :filter-node-method="filterNode"
- :show-checkbox="showCheckboxTree"
- :accordion="accordion"
- >
- </el-tree>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'buildingTree',
- props: {
- buildingType: { type: String, default: 'buildingType' },
- showCheckboxTree: {
- //显示多选框
- type: Boolean,
- default: false
- },
- defaultExpandAllTree: {
- //是否默认展开所有节点
- type: Boolean,
- default: true
- },
- accordion: {
- //房间展开手风琴
- type: Boolean,
- default: false
- },
- accordionPeople: {
- //人员展开手风琴
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- filterText: '',
- organList: [],
- defaultProps: {
- children: 'children',
- label: 'name'
- }
- };
- },
- watch: {
- filterText(val) {
- this.$refs.tree.filter(val);
- }
- },
- computed: {},
- methods: {
- dimension(arr) {
- arr.map((item, index) => {
- if (!!item.children && item.type !== 'unit' && item.type !== 'building') {
- this.dimension(item.children);
- } else {
- if (item.type === 'unit') {
- item.name = this.CheckChinese(item.name, '单元');
- } else if (item.type === 'building') {
- item.name = this.CheckChinese(item.name, '楼栋');
- }
- }
- });
- },
- getOrgTreeList() {
- this.$http
- .get('/sc-community/assets/tree/community/find', { buildingType: this.buildingType })
- .then(({ status, data, msg }) => {
- if (status === 0 && data) {
- this.organList = data;
- this.dimension(data);
- this.$nextTick().then(() => {
- const firstNode = document.querySelector('.el-tree-node');
- firstNode.click();
- });
- }
- });
- },
- filterNode(value, data) {
- if (!value) return true;
- return data.name.indexOf(value) !== -1;
- },
- filterNodePeople(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- treeClick(e) {
- if (e.value == 0) return;
- let onData = '';
- let newValueIds = e.id.split('-');
- let thisE = this.$refs.tree.getNode(e);
- if (e.type == 'building') {
- onData = {
- communityId: thisE.parent.data.value,
- buildingId: e.value,
- unitId: '',
- roomId: ''
- };
- this.$emit('buildingInformation', onData);
- } else if (e.type == 'unit') {
- onData = {
- communityId: thisE.parent.parent.data.value,
- buildingId: thisE.parent.data.value,
- unitId: e.value,
- roomId: ''
- };
- this.$emit('buildingInformation', onData);
- } else if (e.type == 'room') {
- onData = {
- communityId: newValueIds.length == 4 ? thisE.parent.parent.parent.data.value : thisE.parent.parent.data.value,
- buildingId: newValueIds.length == 4 ? thisE.parent.parent.data.value : thisE.parent.data.value,
- unitId: newValueIds.length == 4 ? thisE.parent.data.value : '',
- roomId: e.value
- };
- this.$emit('buildingInformation', onData);
- } else {
- this.$emit('buildingInformation', e);
- }
- },
- CheckChinese(val, name) {
- var reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
- let newVal = val;
- if (!reg.test(val)) {
- newVal = val + name;
- }
- return newVal;
- }
- },
- created() {
- this.getOrgTreeList();
- }
- };
- </script>
- <style lang="scss" scoped>
- .organ-tree {
- width: 260px;
- background: #ffffff;
- padding: 20px;
- box-sizing: border-box;
- float: left;
- height: 100%;
- overflow: auto;
- &::before {
- clear: both;
- }
- .tree-style-box {
- margin-top: 20px;
- max-height: calc(100vh - 200px);
- overflow: scroll;
- }
- }
- </style>
|