<!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-pay-add">
        	<input name="customerId" type="hidden" id="customerId" />
        	<input name="orderId" type="hidden" id="orderId" />
            <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="customerName" onclick="selectCustomer()" id="customerName" type="text" placeholder="请选择所属客户 " class="form-control" required readonly>
	                	<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">
                    	<input name="orderName" onclick="selectOrder()" id="orderName" type="text" placeholder="请选择成交订单 " class="form-control" required readonly>
                		<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">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="payDate" class="form-control" placeholder="yyyy-MM-dd HH:mm" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">期次：</label>
                <div class="col-sm-8">
                    <select name="payTimes" class="form-control m-b" th:with="type=${@dict.getType('pay_times')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></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="payMoney" id="payMoney" class="form-control" type="number" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">付款方式：</label>
                <div class="col-sm-8">
                    <select name="payType" class="form-control m-b" th:with="type=${@dict.getType('pay_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </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('is_invoice')}">
                        <input type="radio" th:id="${'isInvoice_' + dict.dictCode}" name="isInvoice" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'isInvoice_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
				<label class="col-xs-3 control-label">备注：</label>
				<div class="col-xs-8">
					<textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
				</div>
			</div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "crm/pay"
        var prefixOrder = ctx + "crm/order"
        $("#form-pay-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
            	$.ajax({
					type : "get",
					contentType : "json",
					url : prefixOrder + "/checkPaymentMoney",
					data : {
						"orderId" : $("#orderId").val(),
						"payMoney" : $("#payMoney").val()
					},
					success : function(response) {
						if (!response) {
							$.modal.alertError("回款金额不能大于成交金额！");
							return;
						} else {
							$.operate.save(prefix + "/add", $('#form-pay-add').serialize());
						}
					},
					error : function(e) {
					}
				});                
            }
        }

        $("input[name='payDate']").datetimepicker({
        });        
    </script>
    <script src="../static/crm/customer.js" th:src="@{/crm/common.js}"></script>
</body>
</html>