whycwx
2021-08-06 11f794ee33771f9c1bab2d417247717d268896b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
    <div>
        <van-collapse v-model="activeNames" @change="changeList()">
            <van-collapse-item v-for="(item,i) in dataList" :key="i" :title="item.label" :name="i">
                <span>
                    <ul>
                        <li v-for="(element,i) in item.list" class="group_name" @click="toRouter(element)">{{ element.BattGroupName }}</li>
                    </ul>
                </span>
            </van-collapse-item>
        </van-collapse>
        <!-- <van-list
            :finished="finished"
            finished-text="没有更多了"
            @load="searchStation()"
            >
            <van-cell v-for="(item,i) in dataList" :key="i" :title="item.label" to="/functionList"/>
        </van-list> -->
    </div>
</template>
<script>
import { searchStation,searchBattInfo } from "@/assets/js/api";
export default {
    data(){
        return {
            finished: false,
            dataList:[],
            activeNames:[],
        }
    },
    mounted(){
        this.searchStation();
    },
    methods:{
        searchStation:function(){
            let self = this;
                searchStation({
                    StationName1:"",
                    StationName2:"",
                    StationName5:"",
                }).then((res)=>{
                    let rs = JSON.parse(res.data.result);
                    let data = [];
                    if(rs.code == 1) {
                        data = rs.data;
                        console.log(data)
                    }
                    // 格式化数据
                    this.formatData(data);
                });
        },
        formatData(data) {
            let self = this;
            let homeList = [];
            // 遍历数据构造树状
            data.forEach((item,i)=>{
                let tmp = {};
                tmp.label = item.StationName1+"-"+item.StationName2+"-"+item.StationName5+"-"+item.StationName3;
                tmp.key = item.FBSDeviceId+Math.random();
                tmp.id = item.FBSDeviceId;
                tmp.data = item;
                let index = this.checkValIsIn(tmp.label, homeList);
                if(index == -1) {
                    tmp.list = [];
                    homeList.push(tmp);
                }
            });
            self.dataList = homeList;
            self.finished = true;
        },
        checkValIsIn(val, arr) {
            for(let i=0; i<arr.length; i++) {
                if(arr[i].label == val) {
                    return i;
                }
            }
            return -1;
        },
        // 查询电池组
        changeList(){
            let self = this;
                self.$nextTick(()=>{
                    self.activeNames.forEach(item => {
                        let arr = self.dataList[item].list;
                        if(arr.length<1){
                            console.log(self.dataList[item])
                            let objs = self.dataList[item].data;
                            searchBattInfo({
                                StationName1:objs.StationName1,
                                StationName2:objs.StationName2,
                                StationName5:objs.StationName5,
                                StationName3:objs.StationName3
                            }).then(res=>{
                                let re = JSON.parse(res.data.result)
                                    re.data.forEach(element => {
                                        self.dataList[item].list.push(element);
                                    });
                            })
                        }
                    });
                })
            
        },
        // 跳转
        toRouter(element){
            let self = this;
                self.$router.push({
                    path: '/functionList',
                    query:element
                })
        }
    }
 
}
</script>
<style scoped>
    .group_name{
        margin-bottom: 14px;
        margin-left: 10px;
    }
</style>