<!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-repair-finish" th:object="${amsRepairOrder}">
            <input name="repairId" th:field="*{repairId}" type="hidden">
            <!-- 隐藏或只读展示开始时间，用来做比较 -->
            <input id="repairStartTimeStr" type="hidden" th:value="${#dates.format(amsRepairOrder.repairStartTime, 'yyyy-MM-dd')}">

            <div class="form-group">
                <label class="col-sm-3 control-label">维修开始时间：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" th:value="${#dates.format(amsRepairOrder.repairStartTime, 'yyyy-MM-dd')}" readonly>
                </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 id="repairFinishTime" name="repairFinishTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <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">
                    <input name="repairCost" class="form-control" type="number" min="0" step="0.01" placeholder="请填写非负的维修金额" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">维修结果：</label>
                <div class="col-sm-8">
                    <textarea name="repairResult" maxlength="500" class="form-control" rows="3" required placeholder="请详细描述维修成果、更换了哪些部件等..."></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 + "asset/repair";

        $("#form-repair-finish").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var startTimeStr = $("#repairStartTimeStr").val();
                var finishTimeStr = $("#repairFinishTime").val();

                if (startTimeStr && finishTimeStr) {
                    var startTime = new Date(startTimeStr.replace(/-/g, "/"));
                    var finishTime = new Date(finishTimeStr.replace(/-/g, "/"));
                    if (finishTime < startTime) {
                        $.modal.alertWarning("完成时间不能早于开始时间（" + startTimeStr + "）");
                        return;
                    }
                }

                $.operate.save(prefix + "/finish", $('#form-repair-finish').serialize());
            }
        }

        $("input[name='repairFinishTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            todayBtn: true,
            autoclose: true
        });
    </script>
</body>
</html>
