<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/select2.min.css">

    <!--validate css-->
    <link rel="stylesheet" href="plugins/jquery-validation/css/validate.css">
    <!-- Switch -->
    <link rel="stylesheet" href="plugins/bootstrap-switch/bootstrap-switch.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <style>
        .switch {
            width: 35%;
            display: inline-block;
        }

        .delAccounts {
            display: inline-block;
        }

        .bootstrap-switch-container{display: -webkit-box;
            white-space: nowrap;}
    </style>
</head>

<body class="hold-transition skin-blue sidebar-mini">
<!-- END HEAD -->
<div id="f7"></div>
<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">

        <section class="content-header">
            <h1>
                用户管理
                <small>账号信息</small>
            </h1>
<!--             <ol class="breadcrumb"> -->
<!--                 <li><a href="#springUrl('/page/user/showstatics')"><i class="fa fa-dashboard"></i>首页</a></li> -->
<!--                 <li><a class="active">用户修改</a></li> -->
<!--             </ol> -->
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <!-- general form elements disabled -->
                    <div class="box box-primary">
                        <form id="roleform" role="form">
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="username">用户名</label>
                                    <input type="text" class="form-control htmlescape" id="username" value="${user.username}"
                                           maxlength="20" placeholder="请输入用户名" onfocus="this.removeAttribute('readonly');">

                                </div>
                                <div class="form-group">
                                    <label for="password">密码</label>
                                    <input type="password" class="form-control htmlescape" name="password" id="password"
                                           placeholder="请输入密码" maxlength="50" minlength="3" onfocus="this.removeAttribute('readonly');">
                                </div>


                                <div class="form-group">
                                    <label for="password">请确认密码</label>
                                    <input type="password" class="form-control htmlescape" name="confirmNewPassword"
                                           id="confirmNewPassword" placeholder="请再次输入密码" maxlength="50" minlength="3"
                                           equalTo="#password" onfocus="this.removeAttribute('readonly');">
                                </div>

                                <div class="form-group">
                                    <label for="password">描述</label>
                                    <input type="text" class="form-control htmlescape" maxlength="100" value="$!{user.description}"
                                           name="description" id="description" placeholder="请填写描述">
                                </div>

                                <div class="form-group">
                                    <label for="password">邮箱</label>
                                    <input type="email" class="form-control htmlescape" name="email" value="$!{user.email}"
                                           id="email" placeholder="请填写邮箱">
                                </div>
                                <div class="form-group" style="display:none">
                                    <label for="password">经销商编码</label>
                                    <input type="text" class="form-control" name="empid" id="empid"
                                           value="$!{user.empid}" placeholder="请填写经销商编码">
                                </div>
                                
                                 <!--<div class="form-group form-md-line-input">-->
                                    <!--<label>SA人员绑定</label>-->
                                    <!--<div class="input-group">-->
                                        <!--<input type="text" id="userid" name="userid" -->
                                               <!--class="form-control" style="display: none" value="$!{user.userid}">-->
                                        <!--<input type="text" id="wxUserName" name="wxUserName"  value="$!{user.wxUserName}"-->
                                               <!--class="form-control" disabled> -->
                                        <!--<span class="input-group-btn"> -->
                                            <!--<button type="button" id="orgtypeSelect"-->
                                                    <!--class="btn btn-info btn-flat">选择</button>-->
                                         <!--</span>-->
                                    <!--</div>-->
                                <!--</div>-->

                                <!--<div class="form-group" style="display:none">-->

                                    <!--<select class="form-control select2 qyaccount" style="display:none"-->
                                            <!--data-placeholder="请选择企业号">-->
                                        <!--#foreach( $account in $qyaccounts )-->
                                        <!--<option value="${account.id}">${account.description}</option>-->
                                        <!--#end-->
                                    <!--</select>-->
                                    <!--$qyUserRoles, $roles-->
                                    <!--<select class="form-control select2 qyrole" style="width:100%;display:none"-->
                                            <!--multiple="multiple" data-placeholder="请选择角色">-->
                                        <!--#foreach( $role in $roles )-->
                                        <!--<option value="${role.id}" data-attr="${role.roleSign}">${role.roleName}-->
                                        <!--</option>-->
                                        <!--#end-->
                                    <!--</select>-->
                                <!--</div>-->
                                <!--<div class="form-group">-->
                                    <!--<table id="qytable" class="table">-->
                                        <!--<thead>-->
                                        <!--<tr>-->
                                            <!--<th style="width:15%;"><label>企业号</label></th>-->
                                            <!--<th style="width:45%;"><label>角色</label></th>-->
                                            <!--<th style="width:30%;"></th>-->
                                        <!--</tr>-->
                                        <!--</thead>-->
                                        <!--<tbody>-->

                                        <!--</tbody>-->
                                    <!--</table>-->
                                <!--</div>-->
                                <!--<button type="button" class="btn btn-info" id="addQyAccounts" >添加企业号</button>-->

                                <div class="form-group" style="display:none">
                                    <select class="form-control select2 account" style="display:none"
                                            data-placeholder="请选择公众号">
                                        #foreach( $account in $accounts )
                                        <option value="${account.id}">${account.description}</option>
                                        #end
                                    </select>
                                    <select class="form-control select2 role" style="width:100%;display:none"
                                            multiple="multiple" data-placeholder="请选择角色">
                                        #foreach( $role in $roles )
                                        <option value="${role.id}" data-attr="${role.roleSign}">${role.roleName}
                                        </option>
                                        #end
                                    </select>
                                </div>
                                <div class="form-group">
                                    <table id="table" class="table">
                                        <thead>
                                        <tr>
                                            <!--<th style="width:15%;"><label>公众号</label></th>-->
                                            <th style="width:45%;"><label>角色</label></th>
                                            <th style="width:30%;"></th>
                                        </tr>
                                        </thead>
                                        <tbody>

                                        </tbody>
                                    </table>
                                </div>
                                <!--<button type="button" class="btn btn-info" id="addAccounts">添加公众号</button>-->
                            </div>
                            <div class="box-footer">
                                <input class="btn btn-primary" id="save" type="submit" value="保存">
                                <a href="#springUrl('/a/manageuser/userlist')" class="btn btn-default">取消</a>


                            </div>


                        </form>
                        <!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->

    <!-- Add the sidebar's background. This div must be placed immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- Select2 -->
<script src="plugins/select2/select2.full.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<!-- Switch -->
<script src="https://cdn.bootcss.com/bootstrap-switch/4.0.0-alpha.1/js/bootstrap-switch.min.js"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="plugins/jquery-validation/js/localization/messages_zh.js"></script>
<script>
    var csrfheader = {name:'_csrf_header',value:'${_csrf.headerName}'};
    var csrftoken  = {name:'_csrf',value:'${_csrf.token}'};
</script>

<script src="common/js/cfapp.js"></script>

<script src="pages/scripts/usermanager/useradd.js"></script>


<!-- END PAGE LEVEL PLUGINS -->
<script>
    function formSubmit(data) {
        data.id = '${user.id}';


        data._csrf_header=csrfheader.value;
        data._csrf=csrftoken.value;
        $.post("#springUrl('/a/manageuser/userupdate')", data, function (returnobj) {
            if (returnobj.errorNo == '1') {
                if (returnobj.errorNo == '1') {
                    Cfapp.alert({
                        message: "更新用户成功",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/manageuser/userlist')";
                        }
                    })
                }
            }
        });
    };

    var bindSwitch = function () {
        $('#roleform input[type="radio"]').bootstrapSwitch({
            onText: '默认',
            offText: '否',
            state: false
        });
    };

    var userRoles = eval(${userRoles});

    var qyUserRoles = eval(${qyUserRoles});

    //var defaultAccid = "${user.defaultAccId}";

    if (userRoles.length ==0) {
        var rolehtml = $(".role").html();
        var html = "";
        html += "<tr class='trEle'>";
//            html += "<td>";
//            html += "<select class='form-control select2 account'   data-placeholder='请选择公众号'>" + accounthtml;
//            html += "</select></td>";
        html += "<td>";
        html += "<select  class='form-control select2 role' style='width:100%;' multiple='multiple'  data-placeholder='请选择角色'>";
        html += rolehtml;
        html += '</select></td>' +
            '<td>' +
//                '<div class="switch">' +
//                '<input type="radio" name="isdefault"/>' +
//                '</div>' +
//                '<button type="button" class="btn btn-danger delAccounts">删除</button>' +
            '</td></tr>';
        $("#table tbody").append(html);



        $(".select2").select2();
    } else {
        for (var i = 0; i < userRoles.length; i++) {
            var accounthtml = $(".account").html();
            var rolehtml = $(".role").html();
            var html = "";
            html += "<tr class='trEle'>";
//        html += "<td>";
//        html += "<select class='form-control select2 account'   data-placeholder='请选择公众号'>" + accounthtml;
//        html += "</select></td>";
            html += "<td>";
            html += "<select  class='form-control select2 role' style='width:100%;' multiple='multiple'  data-placeholder='请选择角色'>";
            html += rolehtml;
            html += '</select></td>' +
                '<td>' +
//            '<div class="switch">' +
//            '<input type="radio" id="' + userRoles[i]['accountsId'] + '-sel" name="isdefault"/>' +
//            '</div>' +
//            '<button type="button" class="btn btn-danger delAccounts">删除</button>' +
                '</td></tr>';
            $("#table tbody").append(html);
            $("#table tbody tr:last select:first option").each(function (k, val) {
                if ($(this).val() == userRoles[i]['accountsId']) {
                    $(this).attr("selected", true);
                }
            })
            $("#table tbody tr:last select:last option").each(function (k, val) {
                if (userRoles[i]['roles'].indexOf("," + $(this).val() + ",") >= 0) {
                    $(this).attr("selected", true);
                }
            })
            $(".select2").select2();
        }
    }



//    for (var i = 0; i < qyUserRoles.length; i++) {
//        var accounthtml = $(".qyaccount").html();
//        var rolehtml = $(".qyrole").html();
//        var html = "";
//        html += "<tr class='trEle'>";
//        html += "<td>";
//        html += "<select class='form-control select2 qyaccount'   data-placeholder='请选择公众号'>" + accounthtml;
//        html += "</select></td>";
//        html += "<td>";
//        html += "<select  class='form-control select2 qyrole' style='width:100%;' multiple='multiple'  data-placeholder='请选择角色'>";
//        html += rolehtml;
//        html += '</select></td>' +
//            '<td>' +
//            '<div class="switch">' +
//            '<input type="radio" id="' + qyUserRoles[i]['accountsId'] + '-sel"  name="isdefault"/>' +
//            '</div>' +
//            '<button type="button" class="btn btn-danger delAccounts">删除</button>' +
//            '</td></tr>';
//        $("#qytable tbody").append(html);
//        $("#qytable tbody tr:last select:first option").each(function (k, val) {
//            if ($(this).val() == qyUserRoles[i]['accountsId']) {
//                $(this).attr("selected", true);
//            }
//        })
//        $("#qytable tbody tr:last select:last option").each(function (k, val) {
//            if (qyUserRoles[i]['roles'].indexOf("," + $(this).val() + ",") >= 0) {
//                $(this).attr("selected", true);
//            }
//        })
//        $(".select2").select2();
//    }
    bindSwitch();

    //$('#' + defaultAccid + '-sel').bootstrapSwitch('toggleState');


    jQuery(document).ready(function () {


        Cfapp.init();
        UserAdd.init();

        $("#roleform").on("click", ".delAccounts", function () {
            if ( $('#roleform').find(".trEle").length == 1) {
                Cfapp.alert({
                    message: "至少绑定一个微信平台!",
                    btntext: "确认",
                    success: function () {}
                });
                return;
            }
            $(this).parent().parent().remove();
        });

        $("#addAccounts").click(function () {
            var accounthtml = $(".account").html();
            var rolehtml = $(".role").html();
            var html = "";
            html += "<tr class='trEle'>";
//            html += "<td>";
//            html += "<select class='form-control select2 account'   data-placeholder='请选择公众号'>" + accounthtml;
//            html += "</select></td>";
            html += "<td>";
            html += "<select  class='form-control select2 role' style='width:100%;' multiple='multiple'  data-placeholder='请选择角色'>";
            html += rolehtml;
            html += '</select></td>' +
                '<td>' +
//                '<div class="switch">' +
//                '<input type="radio" name="isdefault"/>' +
//                '</div>' +
//                '<button type="button" class="btn btn-danger delAccounts">删除</button>' +
                '</td></tr>';
            $("#table tbody").append(html);
            bindSwitch();
            $(".select2").select2();
        });

//        $("#addQyAccounts").click(function () {
//            var accounthtml = $(".qyaccount").html();
//            var rolehtml = $(".qyrole").html();
//            var html = "";
//            html += "<tr class='trEle'>";
//            html += "<td>";
//            html += "<select class='form-control select2 qyaccount'   data-placeholder='请选择企业号'>" + accounthtml;
//            html += "</select></td>";
//            html += "<td>";
//            html += "<select  class='form-control select2 qyrole' style='width:100%;' multiple='multiple'  data-placeholder='请选择角色'>";
//            html += rolehtml;
//            html += '</select></td>' +
//                '<td>' +
//                '<div class="switch">' +
//                '<input type="radio" name="isdefault"/>' +
//                '</div>' +
//                '<button type="button" class="btn btn-danger delAccounts">删除</button>' +
//                '</td></tr>';
//            $("#qytable tbody").append(html);
//            bindSwitch();
//            $(".select2").select2();
//        })
        
        var sQyUserSource = "#springUrl('/a/qyuser/listData')"; 
        $('#orgtypeSelect').on('click',
                function () {
                    Cfapp.f7({
                        dataUrl: sQyUserSource,  //导入的action Url
                        checkType: 'single', // 多选为multi
                        title: "绑定SA人员",
                        btnoktext: "确定",
                        btncanceltext: "取消",
                        columns: ['选择', '头像', '姓名','手机号码','职位','所属组织'],
                        aoColumns: [{
                            "mData": "id"
                        }, {
                            "mData": "avatar"
                        }, {
                            "mData": "name"
                        }, {
                            "mData": "mobile"
                        }, {
                            "mData": "positionName"
                        }, {
                            "mData": "orgName"
                        }], 
                        aoColumnDefs: [{
                            "aTargets": [0],
                            "mData": "id",
                            "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                            	return '<input type="radio" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.name + '">';
                            }
                        }, {
                            "aTargets": [1],
                            "mData": "avatar",
                            "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                                if (a && a != '') {
                                    return '<img src="' + a + '" width="60px" height="60px">';
                                } else {
                                    return '';
                                }
                            }
                        }],
                        success: function () {

                        },   //确定处理
                        cancel: function () {

                        },    // 取消的处理
                        displayFields: 'wxUserName',  //显示的字段
                        storeFields: 'userid' // 储存的字段
                    })
                }); 


        // console.log("${user.roles}".replace(/\'/g, "")) ;
        $(".select2").select2();
    });
</script>

</body>


<!-- END BODY -->
</html>