zhanghua
2022-11-16 cc9ddf2ecaf3ad935374f49c842227f7eb15779d
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<template>
    <div class="Table">
        <div class="datatable">
            <el-table ref="multipleTable" :data="tableData" style="width: 100%"
                :header-cell-style="{background:'#06122c','font-size':'12px',color:'#4b9bb7','font-weight':'650','line-height':'45px'}"
                :row-class-name="tableRowClassName">
                <el-table-column v-for="item in option.group" :key="item.prop" :label="item.label"
                    :prop="item.prop" :min-width="item['min-width'] ? item['item.min-width']:'10'">
                    <template slot-scope="scope">
                        <div v-if="item.type === 'text'">
                            {{scope.row[item.prop]}}
                        </div>
                        <slot v-else-if="item.type === 'operation'" name="operation" :info="scope">
                            
                        </slot>
                        <slot name="status" v-else-if="item.type === 'status'" :info="scope">
                        </slot>
                        <slot name='time' v-else-if="item.type === 'time'" :timeobj="scope"> 
 
                        </slot>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- tools -->
        <div class="tools" v-if="pageShow">
            <div class="funs">
                <div class="funsItem sp-item">
                    <el-checkbox v-model="all" @change="selectAll()">全选</el-checkbox>
                </div>
                <div class="funsItem sp-item">
                    <el-checkbox v-model="unsame" @change="disSame(tableData)">反选</el-checkbox>
                </div>
                <div class="funsItem">
                    <el-select v-model="myIdx" placeholder="批量操作" @change="selectChange">
                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"
                            :disabled="item.disabled">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="pagination">
                <el-pagination background :current-page="currentPage" layout="prev, pager, next" :total="myTotalNum"
                    :page-size="pageSize" @current-change="changeCurrentPage">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import { deepClone } from '@/utils/helper';
export default {
    data() {
        return {
            myTotalNum: null,
            pageSize: 2,
            currentPage: 1,
            all: false,
            unsame: false,
            myIdx: null,
            options: [
                {
                    value: 1,
                    label: '批量启用',
                },
                {
                    value: 2,
                    label: '批量禁用',
                },
                {
                    value: 3,
                    label: '批量删除',
                }
            ],
            tempList: []
        }
    },
    props: {
        // 表格数据
        tableData: {
            type: Array,
            dafault: () => [],
        },
        // 表头、prop、类型
        tableOption: {
            type: Object,
            default: () => { }
        },
        // 弹窗
        openDialog: {
            type: Function,
            default: () => { }
        },
        // 获取当前页
        getCurrentPage: {
            type: Function,
            default: () => { }
        },
        // 分页总数
        totalNum: {
            type: Number,
            default: 1
        },
        // 是否展示分页
        pageShow:{
            type: Boolean,
            default: false,
        }
    },
    created() {
        this.myTotalNum = JSON.parse(JSON.stringify(this.totalNum));
    },
    computed: {
        option() {
            return deepClone(this.tableOption);
        }
    },
    methods: {
        // 设置表格斑马纹
        tableRowClassName({ row, rowIndex }) {
            if ((rowIndex + 1) % 2 === 0) {
                return 'warning-row';
            } else {
                return 'success-row';
            }
        },
        // 当前页改变触发事件
        changeCurrentPage(page) {
            this.currentPage = page;
            this.$emit('getCurrentPage', page);
        },
        // 全选
        selectAll() {
            this.$refs.multipleTable.toggleAllSelection();
        },
        // 反选
        disSame(list) {
            list.forEach(row => {
                this.$refs.multipleTable.toggleRowSelection(row)
            })
        },
        // 分页下拉框批量操作
        async selectChange(list) {
            console.log(this.tempList);
            if (this.tempList.length !== 0) {
                if (list === 3) {
                    await this.handleDelete(this.tempList);
                } else if (list === 2) {
                    await this.mulUpdateStatus(this.tempList, 0);
                } else {
                    await this.mulUpdateStatus(this.tempList, 1);
                }
                this.myIdx = null;
            } else {
                this.myIdx = null;
                this.$message({
                    type: 'warning',
                    message: '您还没选中任何数据',
                })
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.Table {
    width: 100%;
 
    .el-table {
        color: #4b9bb7;
    }
 
    .tools {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 20px;
 
        .funs {
            display: flex;
 
            .sp-item {
                border: 1px solid #17324c;
            }
 
            .funsItem {
                line-height: 28px;
                display: flex;
                align-items: center;
                border-radius: 4px;
                font-size: 12px;
                margin-left: 10px;
 
                .el-checkbox {
                    width: 80px;
                    padding: 0 10px;
                }
 
                .el-select {
                    width: 120px;
                }
 
                &::v-deep .el-input__inner {
                    border: none;
                    background-color: #09152f;
                }
 
                &:hover .el-checkbox {
                    color: #4b9bb7;
                }
            }
 
        }
 
        .pagination {
            margin-top: 50px;
            display: flex;
            line-height: 50px;
            justify-content: center;
 
            .el-pagination {
 
                &::v-deep li,
                &::v-deep .btn-prev,
                &::v-deep .btn-next {
                    background-color: #071f39;
                    color: #4b9bb7;
                }
 
                &::v-deep .active {
                    background-color: #409eff;
                    color: #fff;
                }
            }
        }
    }
 
    &::v-deep .warning-row {
        background-color: #06122c;
    }
 
    &::v-deep .success-row {
        background-color: #071f39;
    }
 
    .operationBox {
        display: flex;
    }
 
    .el-divider {
        background-color: #4b9bb7;
    }
}
</style>