whychdw
2019-12-09 064c6d5b84fd6ddbbe4c20c41d139f7371460985
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>
    <square-box minHeight="300px" title="电池充电记录" icon="md-battery-charging">
        <div class="collapse-content" style="height: 300px; margin-left: -12px; margin-right: -12px;">
            <Collapse theme="dark">
                <Panel v-for="(obj, key) in data" :key="key">
                    {{obj.name}}
                    <Badge
                    show-zero
                    :count="obj.items.length"></Badge>
                    <div slot="content">
                        <ul v-if="obj.items.length" class="item-content">
                            <li
                            v-for="(item, item_key) in obj.items" 
                            :key="item_key"
                            @click="handleClick(item, key, item_key)">
                                <a>{{item.txt}}</a>
                            </li>
                        </ul>
                        <div v-else class="no-item item-content">暂无{{obj.name}}</div>
                    </div>
                </Panel>
            </Collapse>
        </div>
    </square-box>
</template>
<script>
import SquareBox from './SquareBox'
import HList from './HList'
import $ from 'jquery'
export default {
    components: {
        SquareBox
    },
    props:{
        data: {
            type: Array,
            default() {
                return []
            }
        },
        max: {
            type: Number,
            default: 99
        }
    },
    data() {
        return {
            initData: this.data,
        }
    },
    watch: {
        initData: {
            handler: function() {
                var root = $(this.$el);
                var $lis = root.find('.item-content').find('li');
                $lis.removeClass('item-active');
            },
            deep: true
        }
    },
    methods: {
        getItemsLen: function(items) {
            var len, result = items;
            if(len > this.max) {
                result = this.max+'+';
            }
            return result;
        },
        handleClick: function(data, key, item_key) {
            var root = $(this.$el);
            var $allLis = root.find('.item-content').find('li');
            var $lis = root.find('.item-content').eq(key).find('li');
            // 根据key和item_key定位道点击的元素
            var $li = $lis.eq(item_key);
            if(!$li.hasClass('item-active')) {
                $allLis.removeClass('item-active');
                $li.addClass('item-active');
                this.$emit('on-select-change', data)
            }
            
        },
    },
    mounted() {
        
    },
}
</script>
<style scoped>
    .collapse-content {
        padding: 0 8px;
        overflow-y: auto;
    }
    .ivu-badge {
        position: absolute;
        top: 10px;
        right: 16px;
    }
    .no-item {
        font-weight: bold;
        text-align: center;
    }
    .item-content li {
        list-style: none;
    }
    .item-content li:hover {
        background-color: #DDDDDD;
    }
    .item-content li.item-active {
        background-color: #2db7f5;
    }
    .item-content a{
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        display: block;
        text-indent: .5em;
        line-height: 32px;
        color: #000000;
    }
</style>