<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增职员基础信息')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-employeeinfo-add">
            <input name="deptId" type="hidden" id="treeId"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label">职员ID：</label>
                <div class="col-sm-8">
                    <input name="empId" id="empId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">职员名称：</label>
                <div class="col-sm-8">
                    <input name="empName" id="empName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">职员卡号：</label>
                <div class="col-sm-8">
                    <input name="carNo" id="carNo" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">所属部门：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="deptId" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">职位：</label>
                <div class="col-sm-8">
                    <select name="postid" id="postid" class="form-control ">
                        <option value="">--请选择职位类型--</option>
                        <option name="cbPostInfo" th:each="postid:${cbPostInfo}" th:value="${postid.postId}" th:text="${postid.postName}" th:disabled="${postid.status == '1'}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">职员状态：</label>
                <div class="col-sm-8">
                    <select name="empStateId" id="empStateId" class="form-control m-b" th:with="type=${@dict.getType('sys_empstate_info')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" id="remark" class="form-control" type="text">
                </div>
            </div>


        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "baseinfo/employeeinfo"
        $("#form-employeeinfo-add").validate({
            focusCleanup: true
        });
        /*设备台账管理-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
        function submitHandler() {
            if ($.validate.form()) {
                saveEmployeeInfo();
                // $.operate.save(prefix + "/add", $('#form-employeeinfo-add').serialize());
            }
        }
        function saveEmployeeInfo() {
            var formData = new FormData();
            formData.append('empId', $("#empId").val());
            formData.append('empName', $("#empName").val());
            formData.append('carNo', $("#carNo").val());
            formData.append('deptId', $("#treeId").val());
            formData.append('empStateId', $.form.selectSelects("empStateId"));
            formData.append('postId', $.form.selectSelects("postid"));
            formData.append('remark', $("#remark").val());
            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    </script>
</body>
</html>