<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增人员离职')" />
    <th:block th:include="include :: select2-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-leave-add" th:object="${addleave}">
            <input name="userId" type="hidden" th:value="*{userId}" id="userId"/>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">人员姓名：</label>
                <div class="col-sm-8">
                    <input disabled name="userName" id="username" class="form-control" th:value="*{userName}" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">地区：</label>
                <div class="col-sm-8">
                    <input name="areaname" placeholder="请输入地区"  class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">离职原因：</label>
                <div class="col-sm-8">
                    <textarea name="leavereason" placeholder="请输入离职原因" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">所属单位：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="depart" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择单位" class="form-control" >
                        <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 is-required">离职时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="leavedate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">工作交接：</label>
                <div class="col-sm-8">
                    <select name="workstate" required class="form-control m-b"  th:with="type=${@dict.getType('sys_user_work')}">
                        <option value="">---请选择---</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/leave"
        $("#form-leave-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-leave-add").serializeArray();
                var username = $("input[id='username']").val()
                data.push({"name": "userName", "value": username});
                $.operate.save(prefix + "/add",data);
            }
        }
        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/user/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
        $("input[name='leavedate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='examinedate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        $(function() {
           var deptId =  [[${addleave.deptId}]];
            var deptName =  [[${addleave.dept.deptName}]];
            $("#treeId").val(deptId);
            $("#treeName").val(deptName);

        });
    </script>
</body>
</html>
