123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <template>
- <el-scrollbar class="el-scrollbar-byself thisColor" style="width: 100%">
- <el-tree class="" :data="tenantsTree" @node-click="treeClick" node-key="value" :props="treedefaultProps" ref="tenantstree">
- </el-tree>
- </el-scrollbar>
- </template>
- <script>
- export default {
- props: ['params'],
- data() {
- return {
- tenantsTree: [],
- treedefaultProps: {
- children: 'children',
- label: 'name'
- },
- unitPa: {
- buildingName: '',
- buildingId: '',
- unitName: '',
- unitId: '',
- floor: '',
- floorId: '',
- roomName: '',
- roomId: '',
- type: '',
- ids: []
- }
- };
- },
- computed: {},
- mounted() {},
- methods: {
- submit() {
- this.params.callback && this.params.callback(this.unitPa);
- this.$emit('close');
- },
- treeClick(e, node, obj) {
- this.unitPa.type = e.type;
- this.unitPa.ids = JSON.parse(JSON.stringify(e.id)).split('-');
- if (e.type == 'building') {
- this.unitPa.buildingName = e.name;
- this.unitPa.buildingId = e.value;
- } else if (e.type == 'unit') {
- this.unitPa.buildingName = node.parent.data.name;
- this.unitPa.buildingId = node.parent.data.value;
- this.unitPa.unitName = e.name;
- this.unitPa.unitId = e.value;
- } else if (e.type == 'floor') {
- debugger;
- this.unitPa.buildingName = this.unitPa.ids.length == 4 ? node.parent.parent.data.name : node.parent.data.name;
- this.unitPa.buildingId = this.unitPa.ids.length == 4 ? node.parent.parent.data.value : node.parent.data.value;
- this.unitPa.unitName = this.unitPa.ids.length == 4 ? node.parent.data.name : '';
- this.unitPa.unitId = this.unitPa.ids.length == 4 ? node.parent.data.value : '';
- this.unitPa.floor = e.name;
- this.unitPa.floorId = e.value;
- } else if (e.type == 'room') {
- this.unitPa.buildingName = this.unitPa.ids.length == 4 ? node.parent.parent.data.name : node.parent.parent.parent.data.name;
- this.unitPa.buildingId = this.unitPa.ids.length == 4 ? node.parent.parent.data.value : node.parent.parent.parent.data.value;
- this.unitPa.unitName = this.unitPa.ids.length == 4 ? '' : node.parent.parent.data.name;
- this.unitPa.unitId = this.unitPa.ids.length == 4 ? '' : node.parent.parent.data.value;
- this.unitPa.floor = node.parent.data.name;
- this.unitPa.floorId = node.parent.data.value;
- this.unitPa.roomName = e.name;
- this.unitPa.roomId = e.value;
- }
- },
- dimension(arr) {
- arr.map((item, index) => {
- if (!!item.children) {
- this.dimension(item.children);
- if (item.type == 'unit') {
- item.name = this.CheckChinese(item.name, '单元');
- } else if (item.type == 'building') {
- item.name = this.CheckChinese(item.name, '楼栋');
- } else if (item.type == 'floor') {
- item.name = this.CheckChinese(item.name, '楼');
- }
- }
- });
- },
- CheckChinese(val, name) {
- var reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
- let newVal = val;
- if (!reg.test(val)) {
- newVal = val + name;
- }
- return newVal;
- },
- filterTreeData(trData) {
- trData.map((item, index) => {
- if (this.isNotEmpty(item.children)) {
- item.disabled = true;
- this.filterTreeData(item.children);
- } else {
- item.disabled = false;
- }
- });
- },
- isNotEmpty(arr) {
- return arr && Array.isArray(arr) && arr.length > 0;
- }
- },
- created() {
- this.dimension(this.params.tenantsTree);
- this.filterTreeData(this.params.tenantsTree);
- this.tenantsTree = this.params.tenantsTree;
- }
- };
- </script>
- <style lang="scss" scoped>
- // .thisColor /deep/ .el-tree .is-current {
- // color: #56c6ff;
- // }
- </style>
|