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

        <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 class="head-item">
                    <el-input v-model="params.gameId" placeholder="请输入内容" clearable>
                        <template slot="prepend">游戏id</template>
                    </el-input>
                </div>
            </div>
            <div class="action">
                <el-button plain type="primary" icon="el-icon-search" @click="getLoginLogList">搜索</el-button>
            </div>
        </div>

        <div class="list">
            <el-table
                    :data="loginLogList"
                    style="width: 100%"
                    row-key="logId"
                    border
                    lazy
                    height="100%"
                    :load="load"
                    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column prop="uid" label="用户id" width="180"></el-table-column>
                <el-table-column prop="gameId" label="游戏id" width="180"></el-table-column>
                <el-table-column prop="adFlag" label="adFlag" width="180"></el-table-column>
                <el-table-column prop="ip" label="ip" width="180"></el-table-column>
                <el-table-column prop="imei" label="imei" width="180"></el-table-column>
                <el-table-column prop="logTime" label="登陆时间" width="180"></el-table-column>
                <el-table-column label="操作" width="180">
                    <template slot-scope="scope">
                        <div class="headrow">
                            <el-button type="danger" icon="el-icon-edit" size="mini" @click="banUser(scope.row.uid)" v-show="scope.row.hasChildren">封号</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: "loginLogList",
        data(){
            return{
                params:{},
                loginLogList:[],
                personLoginLogList:[],
                banPersonDto:{},
                page: {},
            }
        },
        mounted(){
            this.getLoginLogList()
        },
        methods:{
            getLoginLogList(){
                logInfoApi.getLoginLogList(this.params).then(res =>{
                    this.loginLogList = res.rows;
                    this.page = res.page;
                    this.loginLogList.map(m => m.hasChildren=true)
                })
            },
            banUser(id) {
                this.banPersonDto={
                    uid:id,
                    status:'1',
                };
                this.$confirm('此操作将永久封禁该用户, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    logInfoApi.banPerson(this.banPersonDto).then(res => {
                        this.$message({
                            type: 'success',
                            message: '封禁成功!'
                        });
                        this.getLoginLogList()
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消封禁'
                    });
                });
            },
            load(tree, treeNode, resolve) {
                console.log(tree);
                logInfoApi.getLoginLogByUid(tree).then(res => {
                    this.personLoginLogList = res;
                    console.log(res);
                    setTimeout(() => {
                        resolve(res)
                    }, 0)
                });
            },
            handleSizeChange(val) {
                this.$log.debug(val);
                this.params.size = val;
                this.getLoginLogList()
            },
            handleCurrentChange(val) {
                this.params.cur = val;
                this.getLoginLogList()
            },
        }
    }
</script>

<style lang="less" scoped>

</style>
