<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>手机号：</label>
                            <input type="number" name="phone"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
<!--                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i-->
<!--                                    class="fa fa-refresh"></i>&nbsp;重置</a>-->
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    let dialog = `<div class="dialog" style="height:200px;width:500px;display: flex;flex-direction: column;justify-content: space-around;align-items: center;">
        <div class="title">请输入拉黑原因</div>
        <textarea name="" id="" cols="50" rows="10"></textarea>
    </div>`
    var detailFlag = [[${@permission.hasPermi('smile:performances:detail')}]];
    var smilePrefix = ctx + "smile/user";
    console.log(smilePrefix);

    //     // createUrl: prefix + "/add",
    //     // updateUrl: prefix + "/edit/{id}",
    //     // removeUrl: prefix + "/remove",
    //     // exportUrl: prefix + "/export",
    //     // modalName: "订单",
    $(function() {
        var options = {
            updateUrl: smilePrefix + "/smileDetail",
            url: smilePrefix + "/list",
            columns: [{
                checkbox: true
            },
                {
                    field: 'uid',
                    title: '用户id'
                },
                {
                    field: 'img',
                    title: '生活照',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value,"300", "300");
                    }
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function(value, row, index) {
                        if (value == 1) {
                            return '男';
                        } else {
                            return '女';
                        }
                    }
                },
                {
                    field: 'birthday',
                    title: '生日'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'identity',
                    title: '身份',
                    formatter: function(value, row, index) {
                        if (value == 1) {
                            return '在校学生';
                        } else {
                            return '已毕业';
                        }
                    }
                },
                {
                    field: 'schoolName',
                    title: '学校/公司名称'
                },
                {
                    field: 'province',
                    title: '地区'
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function(value, row, index) {
                        if (value === 1) {
                            return '总代';
                        } else if(value === 2){
                            return '普代';
                        }else{
                            return '特邀代理'
                        }
                    }
                },
                {
                    field: 'state',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if (value === 0) {
                            return '正常';
                        } else {
                            return '黑名单';
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="goDetail(\''+row.type+'\',\''+row.uid+'\')"><i class="fa fa-edit"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="updateUserStateById(\'' + row.uid + '\',\'' + 1 + '\')"><i class="fa fa-edit"></i>加入黑名单</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        console.log(options)
    });
    function goDetail (type,id) {
        if(type === '5'){
            let url = ctx+'local/specialDetail?id=' + id;
            $.modal.openTab("特邀用户详情", url);
        }else{
            let url = ctx+'local/smileDetail?id=' + id;
            $.modal.openTab("用户详情", url);
        }
    }

    /*加入黑名单*/
    function updateUserStateById(uid,state) {
        $.modal.confirm(dialog,() =>{
            let str = $('textarea').val()
            let postData = {
                uid: uid,
                state: state,
                reason:str
            }
            $.ajax({
                type: 'post',
                url: ctx + 'smile/user/updateUserStateByUid',
                headers: {"Content-Type": "application/json;charset=UTF-8"},
                data: JSON.stringify(postData),
                success: function (e) {
                    // alert(e.msg)
                    location.reload();
                }
            });
        });
    }
    // var updateFlag = [[${@permission.hasPermi('sweet:integralActivity:create')}]];
    // var isOnlineFlag = [[${@permission.hasPermi('sweet:integralActivity:isOnline')}]];
    // var drawListFlag = [[${@permission.hasPermi('sweet:integralActivityDraw:list')}]];
    // var exportExcelFlag = [[${@permission.hasPermi('sweet:integralActivityDraw:exportExcel')}]];

    // var prefix = ctx + "sweet/integralActivity";

</script>
</body>
</html>