<!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-contract-add">
        <input id="leader" name="leader" type="hidden" th:value="*{leader}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">合同名称：</label>
            <div class="col-sm-8">
                <input name="name" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">负责人：</label>
            <div class="col-sm-8">
                <select id="leaderId" name="leaderId" class="form-control m-b" onchange="selectLeader(this)">
                    <option value="">--请选择--</option>
                    <option th:each="leaders:${leaders}" th:value="${leaders.userId}" th:text="${leaders.userName}"
                            th:disabled="${leaders.status == '1'}" th:phone="${leaders.phonenumber}"
                            th:email="${leaders.email}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">甲方：</label>
            <div class="col-sm-8">
                <input name="buyers" 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">
                <input name="sellers" 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">
                <div class="input-group date">
                    <input name="signDate" 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">
                <div class="input-group date">
                    <input name="startDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required
                           style="float: left;width: 49%;">
                    <div style="float: left;width: 2%;">~</div>
                    <input name="endDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required
                           style="float: left;width: 49%;">
                    <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">
                <div class="radio-box" th:each="dict : ${@dict.getType('cnt_pay_mode')}">
                    <input type="radio" th:id="${dict.dictCode}" name="payMode" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">金额：</label>
            <div class="col-sm-8">
                <input id="amount" name="amount" class="form-control" type="text" style="width: 50%;float: left;">
                <p id="payUnit">元</p>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </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('cnt_status')}">
                    <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${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"/>
<script th:inline="javascript">
    var prefix = ctx + "system/contract"
    $("#form-contract-add").validate({
        focusCleanup: true
    });

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

    function selectLeader(e) {
        try {
            var opt = $(e.options[e.selectedIndex]);
            var leader = opt.text();
            if (!leader) {
                leader = ""
            }
            $('#leader').val(leader);
        } catch (e) {

        }
    }

    $("input[name='signDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='startDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='endDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    $(document).ready(function () {
        $("input[name='payMode']").on("ifChecked", function (event) { //ifCreated 事件应该在插件初始化之前绑定
            // alert(event.type + ' callback');
            changePayMode(event.currentTarget.value);
        });
        changeUnit($("input[name='payMode']:checked").val());
    });
    function changePayMode(v){
        changeUnit(v);
    }
    function changeUnit(v) {
        var unit = $("#payUnit");
        switch (v) {
            case "1":
            case "2":
                unit.html("元");
                break;
            case "3":
                unit.html("人/月");
                break;
            case "4":
            case "5":
                unit.html("%");
                break;
            default:
                unit.html("元");
                break;
        }
    }
</script>
</body>
</html>