123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <template>
- <el-scrollbar class="el-scrollbar-byself" style="width: 100%">
- <el-tree
- :data="tenantsTree"
- show-checkbox
- node-key="value"
- :props="treedefaultProps"
- :default-checked-keys="defaultcheckedkeys"
- ref="tenantstree"
- @check-change="checkChange"
- >
- </el-tree>
- </el-scrollbar>
- </template>
- <script>
- export default {
- props: ['params'],
- data() {
- return {
- tenantsTree: [],
- treedefaultProps: {
- children: 'children',
- label: 'name'
- },
- defaultcheckedkeys: []
- };
- },
- computed: {},
- mounted() {},
- methods: {
- submit() {
- let arrs = this.$refs.tenantstree.getCheckedNodes();
- let combination = [];
- arrs.forEach((item, index) => {
- let thisValue = this.$refs.tenantstree.getNode(item);
- let newValueIds = thisValue.data.id.split('-');
- let objArray = {};
- if (
- (item.children == null || item.children == undefined) &&
- !this.defaultcheckedkeys.includes(parseInt(thisValue.data.value))
- ) {
- if (thisValue.data.type === 'room') {
- objArray = {
- houseId: thisValue.data.value,
- buildingName: newValueIds.length === 4 ? thisValue.parent.parent.data.name : thisValue.parent.data.name,
- unitName: newValueIds.length === 4 ? thisValue.parent.data.name : '',
- roomNumber: thisValue.data.name
- };
- } else if (thisValue.data.type === 'parking') {
- objArray = {
- parkingId: thisValue.data.value,
- parkingNumber: thisValue.data.name,
- partitionName: newValueIds.length === 4 ? thisValue.parent.data.name : '',
- garageName: newValueIds.length === 4 ? thisValue.parent.parent.data.name : thisValue.parent.data.name
- };
- }
- combination.push(objArray);
- }
- });
- this.params.callback && this.params.callback(combination);
- this.$emit('close');
- },
- checkChange(data,checked){
- if(checked){
- }
- },
- filterTreeData(trData) {
- trData.map((item, index) => {
- if (this.isNotEmpty(item.children)) {
- item.disabled = true;
- this.filterTreeData(item.children);
- } else {
- item.disabled = false;
- }
- });
- // return trData.filter((item) => {
- // if (this.isNotEmpty(item.children)) {
- // item.disabled = false;
- // item.children = this.filterTreeData(item.children);
- // console.log(item.children);
- // } else {
- // item.disabled = true;
- // }
- // });
- },
- isNotEmpty(arr) {
- return arr && Array.isArray(arr) && arr.length > 0;
- }
- },
- created() {
- if (this.params.list.length !== 0) {
- this.params.list.forEach((item, index) => {
- if (this.params.num === 1) {
- this.defaultcheckedkeys.push(item.houseId);
- } else {
- this.defaultcheckedkeys.push(item.parkingId);
- }
- });
- }
- this.filterTreeData(this.params.tenantsTree);
- this.tenantsTree = this.params.tenantsTree;
- }
- };
- </script>
|