<!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-edit" th:object="${financePay}">
            <input name="payId" th:field="*{payId}" type="hidden">
            <input name="customerId" type="hidden" id="customerId"  th:field="*{customerId}"/>
            <input name="orderId" th:field="*{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()" th:field="*{customer.customerName}" class="form-control" type="text" placeholder="请选择所属客户 " id="customerName" 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"  id="orderName" onclick="selectOrder()"  th:field="*{order.orderName}" class="form-control" type="text" placeholder="请选择成交订单 " 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" th:value="${#dates.format(financePay.payDate, 'yyyy-MM-dd HH:mm')}" 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}" th:field="*{payTimes}"></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" th:field="*{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}" th:field="*{payType}"></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:field="*{isInvoice}">
                        <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" th:field="*{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-edit").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 + "/edit", $('#form-pay-edit').serialize());
						}
					},
					error : function(e) {
					}
				});                
            }
        }

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