<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改工时')"/>
    <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-cost-edit" th:object="${tblProjectCost}">
        <input name="id" th:field="*{id}" type="hidden">

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">成员：</label>
            <div class="col-sm-8">
                <input name="userName" th:field="*{userName}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">起始日期：</label>
            <div class="col-sm-8">
                <input name="startDate" id="sd" th:value="${#dates.format(tblProjectCost.startDate, 'yyyy-MM-dd')}"
                       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">
                <input name="endDate" id="ed" th:value="${#dates.format(tblProjectCost.endDate, 'yyyy-MM-dd')}"
                       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">
                <select id="projectId" name="projectId" class="form-control m-b" onchange="selectProject(this)">
                    <option th:each="project:${projectList}" th:value="${project.id}"
                            th:text="${project.name}"></option>
                </select>
                <input id="projectName" name="projectName" th:field="*{projectName}" class="form-control" type="hidden">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">人时：</label>
            <div class="col-sm-8">
                <input name="costDay" id="costDay" th:field="*{costDay}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required\">内容：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control" required>[[*{remark}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "system/cost";
    var pCost = [[${tblProjectCost}]];
    $("#form-cost-edit").validate({
        focusCleanup: true,
        rules: {
            costDay: {
                required: true,
                number: true
            }
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-cost-edit').serialize());
        }
    }

    $("#sd").datetimepicker({
        format: 'yyyy-mm-dd',
        minView: "month",
        todayBtn: true,
        autoclose: true,
        weekStart: 1,
        endDate: new Date(),
        daysOfWeekDisabled: [0, 1, 2, 3, 4, 5]
    }).on('changeDate', function (event) {
        event.preventDefault();
        event.stopPropagation();
        resetTime0();
    });

    $("#ed").datetimepicker({
        format: 'yyyy-mm-dd',
        minView: "month",
        todayBtn: true,
        yesterdayBtn: true,
        autoclose: true,
        weekStart: 1,
        startDate: [[${#dates.format(tblProjectCost.startDate, 'yyyy-MM-dd')}]],
        endDate: new Date(),
        daysOfWeekDisabled: [0, 1, 2, 3, 4, 6]
    }).on('changeDate', function (event) {
        event.preventDefault();
        event.stopPropagation();
        resetTime0();
    });

    function resetTime0() {
        $('#ed').datetimepicker('setStartDate', $("#sd").val());
        $("#sd").datetimepicker('setEndDate', $("#ed").val());
    }

    function selectProject(e) {
        var opt = $(e.options[e.selectedIndex]);
        var proName = opt.text();
        $("#projectName").val(proName);
    }

</script>
</body>
</html>