<!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" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-contract-apply-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">
                    <input name="contractName" 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">
                    <input name="contractNo" 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">                    
                    <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">成交订单：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                    	<input name="orderName" onclick="selectOrder()" id="orderName" type="text" placeholder="请选择成交订单 " class="form-control" 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="radio-box" th:each="dict : ${@dict.getType('contract_type')}">
                        <input type="radio" th:id="${'contractType_' + dict.dictCode}" name="contractType" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                        <label th:for="${'contractType_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同金额：</label>
                <div class="col-sm-8">
                    <input id="totalMoney" name="totalMoney" class="form-control" type="number" 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">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="dateStart" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </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="dateEnd" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </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="signBy" onclick="selectUser()" id="signBy" 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-xs-3 control-label">合同内容：</label>
				<div class="col-xs-8">
					<input id=contractContent name="contractContent" type="hidden">
				    <div class="summernote"></div>
				</div>
			</div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "crm/contractApply";
        
        
        $('.summernote').summernote({
	    	placeholder: '请输入合同内容',
			height : 500,
			lang : 'zh-CN',
			followingToolbar: false,
			toolbar: [
	              [ 'style', [ 'style' ] ],
	              [ 'font', [ 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear'] ],
	              [ 'fontname', [ 'fontname' ] ],
	              [ 'fontsize', [ 'fontsize' ] ],
	              [ 'color', [ 'color' ] ],
	              [ 'para', [ 'ol', 'ul', 'paragraph', 'height' ] ],
	              [ 'table', [ 'table' ] ],
	              [ 'insert', [ 'link'] ],
	              [ 'view', [ 'undo', 'redo', 'fullscreen', 'codeview', 'help' ] ]
	          ]
		});
        
        
        $("#form-contract-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
            	var sHTML = $('.summernote').summernote('code');
    			$("#contractContent").val(sHTML);
                $.operate.saveTab(prefix + "/add", $('#form-contract-apply-add').serialize());
            }
        }
        
        $("input[name='dateStart']").datetimepicker({
    		format: 'yyyy-mm-dd',
    		minView: "month",
    	    todayBtn:  true,
    	    autoclose: true
    	}).on('changeDate', function(event) {
    		event.preventDefault();
    		event.stopPropagation();
    		var startTime = event.date;
    		$("input[name='dateEnd']").datetimepicker('setStartDate', startTime);
    	});
    	
    	$("input[name='dateEnd']").datetimepicker({
    		format: 'yyyy-mm-dd',
    		minView: "month",
    		todayBtn:  true,
    		autoclose: true
    	}).on('changeDate', function(event) {
    		event.preventDefault();
    		event.stopPropagation();
    		var endTime = event.date;
    		$("input[name='dateStart']").datetimepicker('setEndDate', endTime);
    	});
    	
    	$("input[name='signDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
    <script src="../static/crm/customer.js" th:src="@{/crm/common.js}"></script>
</body>
</html>