BaseTable.vue 5.5 KB
Newer Older
L
lin-xin 已提交
1 2 3 4
<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
L
lin-xin 已提交
5
                <el-breadcrumb-item><i class="el-icon-tickets"></i> 表格</el-breadcrumb-item>
L
lin-xin 已提交
6 7 8
                <el-breadcrumb-item>基础表格</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
L
lin-xin 已提交
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
        <div class="container">
            <div class="handle-box">
                <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button>
                <el-select v-model="select_cate" placeholder="筛选省份" class="handle-select mr10">
                    <el-option key="1" label="广东省" value="广东省"></el-option>
                    <el-option key="2" label="湖南省" value="湖南省"></el-option>
                </el-select>
                <el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="search" @click="search">搜索</el-button>
            </div>
            <el-table :data="data" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column prop="date" label="日期" sortable width="150">
                </el-table-column>
                <el-table-column prop="name" label="姓名" width="120">
                </el-table-column>
                <el-table-column prop="address" label="地址" :formatter="formatter">
                </el-table-column>
                <el-table-column label="操作" width="180">
                    <template slot-scope="scope">
                        <el-button size="small"
                                @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button size="small" type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        @current-change ="handleCurrentChange"
                        layout="prev, pager, next"
                        :total="1000">
                </el-pagination>
            </div>
L
lin-xin 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                url: './static/vuetable.json',
                tableData: [],
                cur_page: 1,
                multipleSelection: [],
                select_cate: '',
                select_word: '',
                del_list: [],
                is_search: false
            }
        },
        created(){
            this.getData();
        },
        computed: {
            data(){
L
lin-xin 已提交
66
                return this.tableData.filter((d) => {
L
lin-xin 已提交
67
                    let is_del = false;
L
lin-xin 已提交
68 69
                    for (let i = 0; i < this.del_list.length; i++) {
                        if(d.name === this.del_list[i].name){
L
lin-xin 已提交
70 71 72 73 74
                            is_del = true;
                            break;
                        }
                    }
                    if(!is_del){
L
lin-xin 已提交
75 76 77
                        if(d.address.indexOf(this.select_cate) > -1 && 
                            (d.name.indexOf(this.select_word) > -1 ||
                            d.address.indexOf(this.select_word) > -1)
L
lin-xin 已提交
78 79 80 81 82 83 84 85
                        ){
                            return d;
                        }
                    }
                })
            }
        },
        methods: {
L
lin-xin 已提交
86
            // 分页导航
L
lin-xin 已提交
87 88 89 90
            handleCurrentChange(val){
                this.cur_page = val;
                this.getData();
            },
L
lin-xin 已提交
91
            // 获取 easy-mock 的模拟数据
L
lin-xin 已提交
92
            getData(){
L
lin-xin 已提交
93
                // 开发环境使用 easy-mock 数据,正式环境使用 json 文件
L
lin-xin 已提交
94
                if(process.env.NODE_ENV === 'development'){
L
lin-xin 已提交
95
                    this.url = '/ms/table/list';
L
lin-xin 已提交
96
                };
L
lin-xin 已提交
97 98
                this.$axios.post(this.url, {page:this.cur_page}).then((res) => {
                    this.tableData = res.data.list;
L
lin-xin 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
                })
            },
            search(){
                this.is_search = true;
            },
            formatter(row, column) {
                return row.address;
            },
            filterTag(value, row) {
                return row.tag === value;
            },
            handleEdit(index, row) {
                this.$message('编辑第'+(index+1)+'');
            },
            handleDelete(index, row) {
                this.$message.error('删除第'+(index+1)+'');
            },
            delAll(){
L
lin-xin 已提交
117
                const length = this.multipleSelection.length;
L
lin-xin 已提交
118
                let str = '';
L
lin-xin 已提交
119
                this.del_list = this.del_list.concat(this.multipleSelection);
L
lin-xin 已提交
120
                for (let i = 0; i < length; i++) {
L
lin-xin 已提交
121
                    str += this.multipleSelection[i].name + ' ';
L
lin-xin 已提交
122
                }
L
lin-xin 已提交
123 124
                this.$message.error('删除了'+str);
                this.multipleSelection = [];
L
lin-xin 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style scoped>
.handle-box{
    margin-bottom: 20px;
}
.handle-select{
    width: 120px;
}
.handle-input{
    width: 300px;
    display: inline-block;
}
L
lin-xin 已提交
144
</style>