<template>
    <div>
        <div class="filters-container">
            <el-input placeholder="用户名" size="small" v-model="filter1" clearable class="filter-item"></el-input>
            <el-button @click="getData"  size="small" icon="el-icon-search" class="filter-item">搜索
            </el-button>
            <el-button @click="${esc.d}router.push('/user')" type="primary" size="small" icon="el-icon-edit"
                       class="filter-item">新建
            </el-button>

        </div>
        <el-table
                :data="tableData"
                :height="tableHeight"
                row-key="id"
                ref="table">

            <el-table-column
                    type="index"
                    min-width="50"
                    align="center">
            </el-table-column>
            #foreach($field in $model.fields)
                #if($field.showInList)
                    <el-table-column
                            prop="$field.modelName"
                            label="$display.alt($field.remark,$field.modelName)"
                            min-width="300">
                    </el-table-column>
                #end
            #end
            <el-table-column
                    label="操作"
                    align="center"
                    fixed="right">
                <template slot-scope="scope">
                    <el-button @click="editRow(scope.row)" type="primary" size="mini" plain>编辑</el-button>
                    <el-button @click="delRow(scope.row)" type="danger" size="mini" plain>删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination-wrapper">

            <el-pagination
                    background
                    @size-change="pageSizeChange"
                    @current-change="currentPageChange"
                    :current-page="currentPage"
                    :page-sizes="[10, 20, 30, 40, 50]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalNumber">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    import {mapState} from 'vuex'
    export default {
        created() {
            // this.getData();
        },
        data() {
            return {
                totalNumber: 0,
                totalPage: 10,
                currentPage: 1,
                pageSize: 20,
                tableData: [],
                filter1: '',
            }
        },
        computed: {
            ...mapState(['tableHeight']),
            selection() {
                return this.${esc.d}refs.table.selection.map(i => i.id);
            }
        },
        methods: {
            pageSizeChange(size) {
                this.pageSize = size;
                this.getData();
            },
            currentPageChange(page) {
                this.currentPage = page;
                this.getData();
            },
            getData() {
                this.${esc.d}http.get({
                    url: '/admin/activity/list',
                    data: {
                        page: this.currentPage,
                        per_page: this.pageSize
                    }
                }).then(res => {
                    if (res.success) {
                        this.totalNumber = res.data.page.totalNumber;
                        this.tableData = res.data.items;
                    }
                })
            },
            editRow(row) {
                this.${esc.d}router.push({
                    path: '/user',
                    query: {
                        id: row.id
                    }
                })
            },
            delRow(row){
                this.${esc.d}confirm('确定要删除该数据吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                }).catch(() => {

                });
            }
        }
    }
</script>
<style lang="less" scoped>

</style>
