<!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 :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-employeeinfo-edit" th:object="${baseEmployeeInfo}">
            <input name="objid" th:field="*{objid}" type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" 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" th:field="*{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" th:field="*{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" th:field="*{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 class="form-control" type="text" name="deptName" onclick="selectDeptTree()" id="treeName" th:field="*{dept.deptName}" 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" th:id="postId" class="form-control m-b">
                        <option name="cbEditPostInfo" th:each="postId:${cbEditPostInfo}" th:value="${postId.postId}" th:text="${postId.postName}" th:selected="${postId.flag}"  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}" th:field="*{empStateId}"></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" th:field="*{remark}" 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="radio-box" th:each="dict : ${@dict.getType('sys_status_info')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var prefix = ctx + "baseinfo/employeeinfo";
        $("#form-employeeinfo-edit").validate({
            focusCleanup: true
        });
        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#treeId").val()) ? "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()) {
                editSaveEmployeeInfo();
                // $.operate.save(prefix + "/edit", $('#form-employeeinfo-edit').serialize());
            }
        }
        function editSaveEmployeeInfo() {
            var formData = new FormData();
            formData.append('objid',$("#objid").val());
            formData.append('empId',$("#empId").val());
            formData.append('empName',$("#empName").val());
            formData.append('carNo',$("#carNo").val());
            formData.append('deptId', $("#treeId").val());
            formData.append('postId', $.form.selectSelects("postId"));
            formData.append('empStateId', $.form.selectSelects("empStateId"));
            formData.append('remark', $("#remark").val());
            formData.append('status', $('input:radio:checked').val());
            $.ajax({
                url: prefix + "/edit",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        };
    </script>
</body>
</html>