<!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-order-add">
            <div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div  class="panel-heading" style="margin-bottom: 20px">
                        <h4 class="form-header h4 panel-title">
                            <a data-toggle="collapse"
                               href="#collapseOne">
                                基本信息
                            </a>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse in">
                        <input name="customerId" type="hidden" id="customerId" />
                        <div class="form-group">
                            <label class="col-sm-3 control-label is-required">主题：</label>
                            <div class="col-sm-8">
                                <input name="orderName" 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">
                                    <input name="customerName" onclick="selectCustomer()" 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">成交总额：</label>
                            <div class="col-sm-8">
                                <input name="totalPrice" class="form-control" type="text" placeholder="保存后添加产品自动计算" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">总成本：</label>
                            <div class="col-sm-8">
                                <input name="costPrice" class="form-control" type="text" placeholder="保存后添加产品自动计算" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">成交/签约时间：</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="orderDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                </div>
                            </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="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input name="validStart" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">有效期结束时间：</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="validEnd" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">订单状态：</label>
                            <div class="col-sm-8">
                                <select name="orderStatus" class="form-control m-b" th:with="type=${@dict.getType('order_status')}">
                                    <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">合同ID：</label>
                            <div class="col-sm-8">
                                <input name="contractId" class="form-control" type="text">
                            </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>
                </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/order"
        $("#form-order-add").validate({
            focusCleanup: true
        });

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

        $("input[name='orderDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        $("input[name='validStart']").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='validEnd']").datetimepicker('setStartDate', startTime);
    	});
    	
    	$("input[name='validEnd']").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='validStart']").datetimepicker('setEndDate', endTime);
    	});
        
        /* 订单管理-修改-选择客户  */
	    function selectCustomer() {
	    	var url = ctx + "crm/customer/selectCustomer";
	   		$.modal.open("选择客户", url);
		}
    </script>
</body>
</html>