guanqb
2022-10-28 bad2a73fd798991d64cbb22efef2dfd448450e3a
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
    <div class="container">
        <div class="header">
            <div class="bottomTitle">
                <div class="leftBor"></div>
                <div class="topName">警情动态</div>
                <div class="rightBor"></div>
            </div>
            <div class="timeTab">
                <span class="beforetime" :class="{choosed:timetype==0}" @click="timeTabClick(0)">近一周</span>
                <span>/</span>
                <span class="beforetime" :class="{choosed:timetype==1}" @click="timeTabClick(1)">近一月</span>
            </div>
        </div>
 
        <div class="body" ref="tableBox">
            <el-table
                :data="timetype == 0 ? pliceSituationWeekArr : pliceSituationMouthArr"
                style="width: 100%"
                :header-cell-style="{'text-align':'center','background-color':'#203c60','borderColor':'#324e75'}"
                :cell-style="{'text-align':'center','borderColor':'#324e75'}"
                :row-class-name="tableRowClassName"
                :height="currentTableHeight"
            >
                <el-table-column prop="num" label="序号"></el-table-column>
                <el-table-column prop="type" label="警情类别"></el-table-column>
                <el-table-column prop="comingPhone" label="报警电话"></el-table-column>
                <el-table-column prop="dealTime" label="接警时间"></el-table-column>
                <el-table-column prop="dealPolice" label="经办民警"></el-table-column>
                <el-table-column prop="callPeople" label="报警人"></el-table-column>
                <el-table-column prop="callPhone" label="报警人联系人"></el-table-column>
                <el-table-column prop="callContent" label="报警内容"></el-table-column>
            </el-table>
        </div>
    </div>
</template>
 
<script>
let interTime
 
export default {
    data () {
        return {
            timetype: 0,
            pliceSituationWeekArr: [
                { 'num': '1', 'type': '民事纠纷', 'comingPhone': '15511112222', 'dealTime': '12H', 'dealPolice': '刘警官', 'callPeople': '张某某', 'callPhone': '13466669999', 'callContent': '他先动的手' },
                { 'num': '2', 'type': '民事纠纷', 'comingPhone': '15511112222', 'dealTime': '12H', 'dealPolice': '刘警官', 'callPeople': '张某某', 'callPhone': '13466669999', 'callContent': '他先动的手' },
                { 'num': '3', 'type': '民事纠纷', 'comingPhone': '15511112222', 'dealTime': '12H', 'dealPolice': '刘警官', 'callPeople': '张某某', 'callPhone': '13466669999', 'callContent': '他先动的手' },
                { 'num': '4', 'type': '民事纠纷', 'comingPhone': '15511112222', 'dealTime': '12H', 'dealPolice': '刘警官', 'callPeople': '张某某', 'callPhone': '13466669999', 'callContent': '他先动的手' },
                { 'num': '5', 'type': '民事纠纷', 'comingPhone': '15511112222', 'dealTime': '12H', 'dealPolice': '刘警官', 'callPeople': '张某某', 'callPhone': '13466669999', 'callContent': '他先动的手' },
            ],
            pliceSituationMouthArr: [
                { 'num': '1', 'type': '聚众斗殴', 'comingPhone': '13466669999', 'dealTime': '15H', 'dealPolice': '王警官', 'callPeople': '张某三', 'callPhone': '15511112222', 'callContent': '他们先动的手' },
                { 'num': '2', 'type': '聚众斗殴', 'comingPhone': '13466669999', 'dealTime': '15H', 'dealPolice': '王警官', 'callPeople': '张某三', 'callPhone': '15511112222', 'callContent': '他们先动的手' },
                { 'num': '3', 'type': '聚众斗殴', 'comingPhone': '13466669999', 'dealTime': '15H', 'dealPolice': '王警官', 'callPeople': '张某三', 'callPhone': '15511112222', 'callContent': '他们先动的手' },
                { 'num': '4', 'type': '聚众斗殴', 'comingPhone': '13466669999', 'dealTime': '15H', 'dealPolice': '王警官', 'callPeople': '张某三', 'callPhone': '15511112222', 'callContent': '他们先动的手' },
                { 'num': '5', 'type': '聚众斗殴', 'comingPhone': '13466669999', 'dealTime': '15H', 'dealPolice': '王警官', 'callPeople': '张某三', 'callPhone': '15511112222', 'callContent': '他们先动的手' },
            ],
            currentTableHeight: 0,
 
        }
    },
 
    mounted () {
        this.$nextTick(() => {
            this.tableScroll()
            this.setDomStyle()
        })
 
        window.addEventListener('resize', this.setDomStyle)
    },
 
    methods: {
        timeTabClick (type) {
            this.timetype = type
        },
        setDomStyle () {
            this.currentTableHeight = this.$refs.tableBox.offsetHeight
        },
        tableScroll () {
            // 拿到表格挂载后的真实DOM
            const divData = this.$refs.tableBox.querySelector('.el-table__body-wrapper')
            // 拿到元素后,对元素进行定时增加距离顶部距离,实现滚动效果(此配置为每100毫秒移动1像素)
            interTime = setInterval(() => {
                // 元素自增距离顶部1像素
                divData.scrollTop += 1
                // 判断元素是否滚动到底部(可视高度+距离顶部=整个高度)
                if (divData.clientHeight + divData.scrollTop + 1 > divData.scrollHeight) {
                    // 重置table距离顶部距离
                    divData.scrollTop = 0
                }
            }, 100)
        },
    },
 
    destroyed () {
        window.addEventListener('resize', this.setDomStyle)
        clearInterval(interTime)
    }
}
</script>
 
<style scoped lang="scss">
.container {
    position: relative;
    height: 100%;
    width: 100%;
    .header {
        width: 100%;
        height: 36px;
 
        .bottomTitle {
            display: flex;
            float: left;
            width: 34%;
            margin-left: 33%;
            height: 36px;
            line-height: 36px;
            color: #fff;
            text-align: center;
 
            .leftBor {
                width: 0px;
                height: 0px;
                border: 18px solid #3366e2;
                border-bottom-color: transparent;
                border-left-color: transparent;
            }
 
            .rightBor {
                width: 0px;
                height: 0px;
                border: 18px solid #3366e2;
                border-bottom-color: transparent;
                border-right-color: transparent;
            }
 
            .topName {
                width: calc(100% - 48px);
                background-color: #3366e2;
                letter-spacing: 2px;
            }
        }
 
        .timeTab {
            float: right;
            width: 20%;
            height: 36px;
            line-height: 36px;
            .beforetime {
                color: rgb(98, 95, 95);
                cursor: pointer;
            }
            .beforetime:hover {
                text-decoration: underline;
            }
            .choosed {
                color: #fff;
            }
        }
    }
 
    .body {
        margin: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 56px);
 
        /* 解决自定义滚动条 x 轴显示问题 */
    }
}
</style>