<template>
    <div class="userWhiteList flex-display">

        <template>
        <div class="head">
            <div class="text">
                <div class="head-item">
                    <el-input v-model="params.uid" placeholder="请输入内容" clearable>
                        <template slot="prepend">用户id</template>
                    </el-input>
                </div>
            </div>

            <div class="action">
                <el-button plain type="primary" icon="el-icon-search" @click="getWhiteList">搜索</el-button>
                <el-button plain type="success" icon="el-icon-edit" @click="addWhiteList">增加</el-button>
            </div>
        </div>
        </template>

        <div class="list">
            <el-table :data="whiteList" border stripe :fit="false" height="100%">
                <el-table-column label="白名单id" prop="id" width="150" show-overflow-tooltip/>
                <el-table-column label="用户id" prop="uid" width="150" show-overflow-tooltip/>
                <el-table-column label="创建时间" prop="createTime" width="150" show-overflow-tooltip/>
                <el-table-column label="操作" width="180">
                    <template slot-scope="scope">
                        <div class="headrow">
                                <el-button size="mini" @click="relieveUser(scope.row.id)">解除白名单</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="page">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    layout="total, sizes, prev, pager, next, jumper"
                    :page-size="page.size"
                    :pager-count="11"
                    :total="page.total"
            ></el-pagination>
        </div>

    </div>
</template>

<script>
    import logInfoApi from '@/api/logInfo'

    export default {
        name: "userWhiteList",
        data(){
            return{
                whiteList:[],
                params:{},
                page: {},
            }
        },
        mounted(){
            this.getWhiteList();
        },
        methods: {
            getWhiteList(){
                logInfoApi.getWhiteList(this.params).then(res =>{
                    this.whiteList = res.rows;
                    this.page = res.page;
                })
            },
            addWhiteList(){
                logInfoApi.addWhiteList(this.params).then(this.getWhiteList)
            },
            relieveUser(id){
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    logInfoApi.deleteWhiteList(id).then(res => {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.getWhiteList()
                    });

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            handleSizeChange(val) {
                this.$log.debug(val);
                this.params.size = val;
                this.getWhiteList()
            },
            handleCurrentChange(val) {
                this.params.cur = val;
                this.getWhiteList()
            },
        }
    }
</script>

<style lang="less" scoped>

</style>
