<!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">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/select2.min.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.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">
    <!-- ztree css -->
    <link rel="stylesheet"
          href="plugins/ztree/css/metroStyle/metroStyle.css" type="text/css"/>
    <!--fileinput css-->
    <link rel="stylesheet" href="plugins/bootstrap-fileinput/bootstrap-fileinput.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]-->
</head>
<!-- END HEAD -->
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">
        <div id="treeSelect"></div>
        <div id="f7"></div>
        <section class="content-header">
            <h1>
                人员管理
                <small>人员信息</small>
            </h1>
            <!--             <ol class="breadcrumb"> -->
            <!--                 <li><a href="#"><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 role="form" id="myForm">
                            <input name="id" value="$!{data.id}" hidden="true"/>
                            <input name="accountsId" value="$!{accountId}" hidden="true"/>
                            <input id="tagIds" name="tagIds" value="$!{data.tagIds}" hidden="true"/>
                            <input id="gender" name="gender" value="$!{data.gender}" hidden="true"/>
                            <input id="isVer" name="isVer" value="$!{data.isVer}" hidden="true"/>
                            <input id="role" name="role" value="$!{data.role}" hidden="true"/>
                            <div class="box-body">
                                <div class="form-group form-md-line-input col-md-4">
                                    <label>所属组织</label>
                                    <div class="input-group">
                                        <input type="text" id="orgId" name="orgId" value="$!{data.orgId}"
                                               class="form-control" style="display: none">
                                        <input type="text" id="orgName" name="orgName" value="$!{orgName}" required="required"
                                               class="form-control" disabled>
                                        <span class="input-group-btn">
                                            <button type="button" id="orgSelect"
                                                    class="btn btn-info btn-flat">选择</button>
                                         </span>
                                    </div>
                                </div>
                                <div class="form-group form-md-line-input col-md-4">
                                    <label for="name">人员名称</label>
                                    <input type="text"
                                           class="form-control" name="name" id="name"
                                           maxlength="50" placeholder="人员名称" required="required"
                                           value="$!{data.name}">
                                </div>
                                <div class="form-group form-md-line-input col-md-4">
                                    <label for="mobile">手机号</label>
                                    <input type="text"
                                           class="form-control" name="mobile" id="mobile"
                                           maxlength="50" placeholder="手机号" required="required"
                                           value="$!{data.mobile}">
                                </div>
                                <div class="form-group form-md-line-input col-md-4">
                                    <label for="mobile">登录账号</label>
                                    <input type="text"
                                           class="form-control" name="loginNameQyUser" id="loginNameQyUser"
                                           maxlength="50" placeholder="登录账号"
                                           value="$!{data.loginName}">
                                </div>


                                <input type="text" style="display: none" name="_csrf" value="${_csrf.token}"/>
                                <input type="text" style="display: none" name="_csrf_header"
                                       value="${_csrf.headerName}"/>
                                <div class="form-group form-md-line-input col-md-4">
                                    <label for="passwordQyUser">密码</label>
                                    <input type="password" class="form-control" name="passwordQyUser"
                                           id="passwordQyUser"
                                           placeholder="请输入密码" maxlength="50" minlength="3">
                                </div>
                                <div class="form-group form-md-line-input col-md-4">
                                    <label for="email">EMAIL</label>
                                    <input type="text"
                                           class="form-control" name="email" id="email"
                                           maxlength="50" placeholder="email"
                                           value="$!{data.email}">
                                </div>

                                <div class="form-group form-md-line-input col-md-4">
                                    <label>职业</label>
                                    <select name="userType" class="form-control pull-right">
                                        <option label="其他" value="0">其他</option>
                                        <option label="药师" value="1" #if($data.userType == '1') selected #end>药师</option>
                                        <option label="客服" value="2" #if($data.userType == '2') selected #end>客服</option>
                                        <option label="医生" value="3" #if($data.userType == '3') selected #end>医生</option>
                                        <option label="订单员" value="4" #if($data.userType == '4') selected #end>订单员</option>
                                    </select>
                                </div>
                                <!--<div class="form-group form-md-line-input col-md-4">-->
                                    <!--<label for="description">部门</label>-->
                                    <!--<input type="text"-->
                                           <!--class="form-control" name="description" id="description"-->
                                           <!--maxlength="50" placeholder="部门"-->
                                           <!--value="$!{data.description}">-->
                                <!--</div>-->
                                <!--<div class="form-group form-md-line-input col-md-4" style="display:none">-->
                                    <!--<label>职位</label>-->
                                    <!--<div class="input-group">-->
                                        <!--<input type="text" id="positionId" name="positionId" value="$!{data.positionId}"-->
                                               <!--class="form-control" style="display: none">-->
                                        <!--<input type="text" id="positionName" name="positionName"-->
                                               <!--value="$!{positionName}"-->
                                               <!--class="form-control" disabled>-->
                                        <!--<span class="input-group-btn">-->
                                            <!--<button type="button" id="positionSelect"-->
                                                    <!--class="btn btn-info btn-flat">选择</button>-->
                                         <!--</span>-->
                                    <!--</div>-->
                                <!--</div>-->
                               <!--<div class="form-group form-md-line-input col-md-4">
                                    <label for="storeName">门店</label>
                                    <div class="input-group">
                                        <input type="text" id="storeId" name="storeId" value="$!{data.storeId}"
                                               class="form-control" style="display: none">
                                        <input type="text" id="storeName" name="storeName"
                                               value="$!{storeName}"
                                               class="form-control required" disabled>
                                        <span class="input-group-btn">
                                            <button type="button" id="storeSelect"
                                                    class="btn btn-info btn-flat">选择</button>
                                         </span>
                                    </div>
                                </div>-->
                                <div class="form-group form-md-line-input col-md-4">
                                    <label>性别</label>
                                    <div class="switch">
                                        <input type="checkbox" name="sex"/>
                                    </div>
                                </div>
                               <!-- <div class="form-group form-md-line-input col-md-4">
                                    <label>是否可核销</label>
                                    <div class="switch">
                                        <input type="checkbox" name="isVers"/>
                                    </div>
                                </div>-->

                                <!--<div class="form-group form-md-line-input col-md-4" style="display:none">
                                    <label>门店角色</label>
                                    <select class="form-control select2" name="roleselect"
                                            id="roleselect" style="width: 100%;">
                                        <option value="0">待分配</option>
                                        <option value="1">店长</option>
                                        <option value="2">导购</option>
                                    </select>

                                </div>-->
                            </div>

                            <div class="box-footer">
                                #if($shiro.hasPermission("sys:qyuser:edit"))
                                <input class="btn btn-primary" id="save" value="保存" type="submit">
                                #end
                                <a href="#springUrl('/a/qyuser/list')" 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>
<!-- 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>
<!-- Select2 -->
<script src="plugins/select2/select2.full.min.js"></script>
<!-- ztree -->
<script src="plugins/ztree/js/jquery.ztree.all.min.js"
        type="text/javascript"></script>
<!--fileinput js-->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/lang/zh-cn/zh-cn.js"></script>
<!-- Switch -->
<script src="plugins/bootstrap-switch/bootstrap-switch.min.js"></script>
<script src="common/js/cfapp.js"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    $().ready(function () {
        Cfapp.init();
        formAdd.init();

        if ($("#loginNameQyUser").val() == null || $("#loginNameQyUser").val() == "") {
            $("#loginNameQyUser").val("");
        }
        if ($("#passwordQyUser").val() == null || $("#passwordQyUser").val() == "") {
            $("#passwordQyUser").val("");
        }
    });


    var formAdd = function () {

        var sSource = "#springUrl('/a/orgunit/treeDataNoAuth')";
        var positonTreeDataUri = "#springUrl('/a/position/treeData')";
        var tagids = $('#tagIds').val();
        var tagArr = [];
        if (tagids && tagids != '') {
            tagArr = tagids.split(',');
        }
        var initForm = function () {
            var initFormCtrl = function () {
                //getTagList();
                bindEvent();
            };
            var bindEvent = function () {

                var roleselect = $('#roleselect').select2({
                    placeholder: '选择分类'
                });

                var roleObj = $('#role');
                var roleValue = roleObj.val();
                if (roleValue && roleValue != '') {
                    roleselect.val(roleValue).trigger("change");
                } else {
                    roleselect.val('0').trigger("change");
                    roleObj.val('0');
                }

                var genderVal = $('#gender').val();
                var state = true;
                if (!genderVal || genderVal == '' || genderVal == undefined) {

                } else {
                    if (genderVal == '男') {
                        state = true;
                    } else {
                        state = false;
                    }
                }

                $('#myForm input[name="sex"]').bootstrapSwitch({
                    onText: '男',
                    offText: '女',
                    state: state

                });

                var isVerVal = $('#isVer').val();
                var isVerState = true;
                if (!isVerVal || isVerVal == '' || isVerVal == undefined) {

                } else {
                    if (isVerVal == '0') {
                        isVerState = true;
                    } else {
                        isVerState = false;
                    }
                }

                $('#myForm input[name="isVers"]').bootstrapSwitch({
                    onText: '是',
                    offText: '否',
                    state: isVerState

                });

                $(".select2").select2();
                $('#orgSelect').on('click',
                    function () {
                        Cfapp.treeSingleSelect({
                            title: '所属组织选择',
                            url: sSource,
                            displayFields: 'orgName',
                            storeFields: 'orgId',
                            success: function () {
                                console.log('success');
                            },
                            cancel: function () {
                                console.log('cancel');
                            }
                        })
                    });
                $('#positionSelect').on('click',
                    function () {
                        Cfapp.treeSingleSelect({
                            title: '所属职位选择',
                            url: positonTreeDataUri,
                            displayFields: 'positionName',
                            storeFields: 'positionId',
                            success: function () {
                                console.log('success');
                            },
                            cancel: function () {
                                console.log('cancel');
                            }
                        });
                    });


                $('#storeSelect').on('click', function () {
                    var storeURL = "#springUrl('/a/store/listData')";
                    Cfapp.f7({
                        dataUrl: storeURL,
                        checkType: 'single', // 多选为multi
                        title: "选择门店",
                        btnoktext: "确定",
                        btncanceltext: "取消",
                        columns: ['选择', '门店名称'],
                        isSearch: '0',
                        searchColumns: ["name"],//搜索的字段名称
                        searchColumnsRemarks: ['门店名称'],//搜索的字段备注
                        aoColumns: [{
                            "mData": "id"
                        }, {
                            "mData": "name"
                        }],
                        aoColumnDefs: [{
                            "aTargets": [0],
                            "mData": "id",
                            "mRender": function (a, b, c, d) {
                                return '<input type="radio" id="' + c.id + '" name="sel" data-value="' + c.id + '" data-name="' + c.name + '">';
                            }
                        }],
                        success: function () {

                        },
                        cancel: function () {

                        },
                        storeFields: 'storeId', // 储存的字段
                        displayFields: 'storeName'
                    })
                });

                $("#myForm").validate({
                    rules: {
                        name: {
                            required: true,
                            htmlescape: true
                        },
                        orgName: {
                            required: true,
                            htmlescape: true
                        },
                        mobile: {
                            required: true,
                            htmlescape: true
                        },
//                        positionName: {
//                            required: true,
//                            htmlescape: true
//                        },
//                        wxuserId: {
//                            required: true,
//                            htmlescape: true
//                        },
//                        storeName: {
//                            required: true
//                        }
                    },
                    messages: {
                        name: {
                            required: "请输入人员名称!",
                            htmlescape: "请您不要输入特殊字符!"
                        },
                        orgName: {
                            required: "请选择所属组织!",
                            htmlescape: "请您不要输入特殊字符!"
                        },
                        mobile: {
                            required: "请输入手机号!",
                            htmlescape: "请您不要输入特殊字符!"
                        },
//                        positionName: {
//                            required: "请选择职位!",
//                            htmlescape: "请您不要输入特殊字符!"
//                        },
//                        wxuserId: {
//                            required: "请输入微信USERID!",
//                            htmlescape: "请您不要输入特殊字符!"
//                        },
//                        storeName: {
//                            required: "请选择门店"
//                        }
                    },
                    submitHandler: function (form) {

                        if ($("#loginNameQyUser").val() == null || $("#loginNameQyUser").val() == "") {
                            $("#loginNameQyUser").after("<label  class='error'>请输入登录账号</label>");
                            return;
                        }

                        if ($("#orgName").val() == null || $("#orgName").val() == "") {
                            //$("#orgName").after("<label  class='error'>请选择所属组织</label>");
                            alert("请选择所属组织");
                            return;
                        }

                        $("#save").attr("disabled", true);
                        if ($('.select2').val()) {
                            $('#tagIds').val($('.select2').val().toString());
                        } else {
                            $('#tagIds').val('');
                        }
                        var gender = $('#myForm input[name="sex"]').bootstrapSwitch('state');
                        if (gender) {
                            $('#gender').val('男');
                        } else {
                            $('#gender').val('女');
                        }

                        var isVer = $('#myForm input[name="isVers"]').bootstrapSwitch('state');
                        if (isVer) {
                            $('#isVer').val('0');
                        } else {
                            $('#isVer').val('1');
                        }

                        if ($("#passwordQyUser").val() != null && $("#passwordQyUser").val() != "") {
                            var password = sha256_digest($("#passwordQyUser").val());
                            $("#passwordQyUser").val(password);
                        }
                        $.post("#springUrl('/a/qyuser/formData')", $("#myForm").serialize(), function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/qyuser/form')";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/qyuser/list')";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/qyuser/list')";
                                    }
                                });
                            } else if (returnobj.errorNo == 3) {
                                Cfapp.alert({
                                    message: "账号重复",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/qyuser/list')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/qyuser/list')";
                                    }
                                });
                            }
                        });
                    }
                })
            };
//            var getTagList = function () {
//                console.log(tagids);
//                var tagList = "#springUrl('/a/qytag/listData')";
//                var formdata = {
//                    iDisplayStart: 0,
//                    iDisplayLength: 0
//                };
//                $.getJSON(tagList, formdata, function (retData) {
//                    var htmlStr = '';
//                    if (retData.aaData && retData.aaData.length > 0) {
//
//                        for (var i = 0, j = retData.aaData.length; i < j; i++) {
//
//                            var tagObj = retData.aaData[i];
//                            htmlStr += '<option value="' + tagObj.id + '">' + tagObj.name + '</option>';
//
//                        }
//
//
//                    }
//                    ;
//                    $('#taglist').html(htmlStr);
//                    $(".select2").val(tagArr).trigger('change');
//                });
//            };
            initFormCtrl();
        };
        return {

            //main function to initiate the module
            init: function () {
                initForm();
            }

        };
    }();
</script>
</body>
<!-- END BODY -->
</html>