<!DOCTYPE HTML>
<html>
<head>
    {% set title = contractId?"修改合同":"添加合同" %}
    {% set disabled = result?"disabled":"" %}
    <meta charset="utf-8">
    <title>{{title}}</title>
</head>
<body>
    <h2 class="title">{{title}}</h2>
    <form action="" method="POST" enctype="multipart/form-data" class="form-inline">
        <div class="row">
            <div class="col-md-10">
                <!-- Nav tabs -->
                <ul class="nav nav-tabs" role="tablist">
                    <li role="presentation" class="active"><a href="#info" aria-controls="info" role="tab" data-toggle="tab">合同信息</a></li>
                    <li role="presentation"><a href="#soInfo" aria-controls="soInfo" role="tab" data-toggle="tab">业主/买方信息</a></li>
                    <li role="presentation" style="display: none;"><a id="houseInfo" data-toggle="tab">房源信息</a></li>
                    <li role="presentation" style="display: none;"><a id="customerInfo" data-toggle="tab">客源信息</a></li>
                </ul>

                <!-- Tab panes -->
                <div class="tab-content">
                    <div role="tabpanel" class="tab-pane active" id="info">
                        <br />
                        <div class="row">
                            <div class="col-md-6" class="form-control">
                                <label for="business">业务：</label>
                                <select name="business" id="business" {{disabled}}>
                                    <option value="-1">请选择</option>
                                    <option value="0">新房</option>
                                    <option value="1">二手房</option>
                                    <option value="2">租房</option>
                                </select>
                            </div>
                            {% if result.contractId %}
                            <div class="col-md-6" class="form-control">
                                <label>合同编号：</label>
                                <label>{{result.contractId}}</label>
                            </div>
                            {% endif %}
                        </div>
                        <br />
                        <div class="row">
                            <div class="col-md-6">
                                <label for="houseNumber">房源编号：</label>
                                <input name="houseNumber" id="houseNumber" type="text" value="{{result.houseNumber}}" class="form-control" disabled>
                            </div>
                            <div class="col-md-6">
                                <label for="address">房源地址：</label>
                                <input id="address" type="text" value="{{result.address}}" class="form-control"  style="width:60%;" disabled>
                                <input type="button" id="select_house" value="选择" data-toggle="modal" data-target="#myModal" class="form-control" {{disabled}}>
                            </div>
                        </div>
                        <br />
                        <div class="row">
                            <div class="col-md-6">
                                <label for="customerNumber">客源编号：</label>
                                <input id="customerNumber" name="customerNumber" type="text" value="{{result.customerNumber}}" class="form-control"  style="width:60%;" disabled>
                                <input type="button" id="select_customer" value="选择" data-toggle="modal" data-target="#addCustomer" class="form-control" {{disabled}}>
                            </div>
                            <div class="col-md-6">
                                <label for="signedDate">签约日：</label>
                                <input name="signedDate" id="signedDate" type="date" value="{{result.signedDate}}" class="form-control" {{disabled}}>
                            </div>
                        </div>
                        <br />
                        <div class="row">
                            <div class="col-md-6">
                                <label for="permitNumber">产证：</label>
                                <input name="permitNumber" id="permitNumber" type="text" value="{{result.permitNumber}}" class="form-control">
                            </div>
                            <div class="col-md-6">
                                <label for="area">面积：</label>
                                <input id="area" type="text" value="{{result.area}}" class="form-control">平方米
                            </div>
                        </div>
                        <br />
                        <div class="row">
                            <div class="col-md-6">
                                <label for="price">合同金额：</label>
                                <input name="price" id="price" type="text" value="{{result.price}}" class="form-control" {{disabled}}>
                            </div>
                            <div class="col-md-6">
                                <label for="managerId">主管：</label>
                                <select name="managerId" id="managerId" class="form-control" {{disabled}}>
                                    {% for item in managers %}
                                        <option value="{{item.ID}}">{{item.display_name}}</option>
                                    {% endfor%}
                                </select>
                            </div>
                        </div>
                        <br />
                        <div class="row">
                            <div class="col-md-6">
                                <label for="paymentMethod">付款方式：</label>
                                <textarea name="paymentMethod" id="paymentMethod" rows="8" class="form-control" style="width:80%;">{{result.paymentMethod}}</textarea>
                            </div>
                            <div class="col-md-6">
                                <label for="codicil">附加条款：</label>
                                <textarea name="codicil" id="codicil" rows="8" class="form-control" style="width:80%;">{{result.codicil}}</textarea>
                            </div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="soInfo">
                        <br />
                        <div class="row">
                            <div class="col-md-6">
                                <h4>业主信息</h4>
                                <p>
                                    <label for="oName">业主姓名：</label>
                                    <input name="oName" id="oName" type="text" value="{{result.oName}}" class="form-control">
                                </p>
                                <p>
                                    <label for="oPhone">手机：</label>
                                    <input name="oPhone" id="oPhone" type="text" value="{{result.oPhone}}" class="form-control">
                                </p>
                                <p>
                                    <label for="oID">身份证：</label>
                                    <input name="oID" id="oID" type="text" value="{{result.oID}}" class="form-control">
                                </p>
                                <p>
                                    <label for="oCommission">佣金：</label>
                                    <input name="oCommission" id="oCommission" type="text" value="{{result.oCommission}}" class="form-control">
                                </p>
                                <p>
                                    <label for="oAddress">地址：</label>
                                    <input name="oAddress" id="oAddress" type="text" value="{{result.oAddress}}" class="form-control">
                                </p>
                                <h4>贷款</h4>
                                <p>
                                    <label for="oPayBack">偿还形式：</label>
                                    <input name="oPayBack" id="oPayBack" type="text" value="{{result.oPayBack}}" class="form-control">
                                </p>
                                <p>
                                    <label for="oMoney">偿还金额：</label>
                                    <input name="oMoney" id="oMoney" type="text" value="{{result.oMoney}}" class="form-control">
                                </p>
                            </div>
                            <div class="col-md-6">
                                <h4>买方信息</h4>
                                <p>
                                    <label for="cName">买方姓名：</label>
                                    <input name="cName" id="cName" type="text" value="{{result.cName}}" class="form-control">
                                </p>
                                <p>
                                    <label for="cPhone">手机：</label>
                                    <input name="cPhone" id="cPhone" type="text" value="{{result.cPhone}}" class="form-control">
                                </p>
                                <p>
                                    <label for="cID">身份证：</label>
                                    <input name="cID" id="cID" type="text" value="{{result.cID}}" class="form-control">
                                </p>
                                <p>
                                    <label for="cCommission">佣金：</label>
                                    <input name="cCommission" id="cCommission" type="text" value="{{result.cCommission}}" class="form-control">
                                </p>
                                <p>
                                    <label for="cAddress">地址：</label>
                                    <input name="cAddress" id="cAddress" type="text" value="{{result.cAddress}}" class="form-control">
                                </p>
                                <h4>贷款</h4>
                                <p>
                                    <label for="cPayBack">偿还形式：</label>
                                    <input name="cPayBack" id="cPayBack" type="text" value="{{result.cPayBack}}" class="form-control">
                                </p>
                                <p>
                                    <label for="cMoney">偿还金额：</label>
                                    <input name="cMoney" id="cMoney" type="text" value="{{result.cMoney}}" class="form-control">
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div  class="col-md-2">
                <input type="text" name="type" value="1" hidden="hidden">
                <input type="text" name="houseId" hidden="hidden">
                <input type="submit" id="submit" class="button action" style="position: fixed;">
            </div>
        </div>

    </form>
<script>
(function($){
    $(document).ready(function(){
        {% if result %}
            $("#business").val({{result.business}});
        {% endif %}
        $("#select_house").click(function(){
            init_modal_houseList(selectHouse,$("#business").val());
        });
        $("#select_customer").click(function(){
            init_modal_addCustomer(selectCustomer);
        });

    });

    function selectCustomer(data){
        $("#customerNumber").val(data.id);
        $("#customerInfo").parent().show();
        $("#customerInfo").unbind().click(function(){
            window.open("{{adminUrl}}admin.php?page=customer&edit=true&id="+data.id);
        });
        close_modal_addCustomer();
    }

    function selectHouse(data){
        $("#address").val(data.address);
        $("#houseNumber").val(data.house_number);
        $("#houseId").val(data.id);
        var houseType = $("#business").val();
        if(houseType != -1){
            $("#houseInfo").parent().show();
            switch(houseType){
                case "0":
                    houseType = "newHouse";
                    break;
                case "1":
                    houseType = "secHandHouse";
                    break;
                case "2":
                    houseType = "rentHouse";
                    break;
            }
            $("#houseInfo").unbind().click(function(){
                window.open("{{adminUrl}}admin.php?page="+houseType+"&edit=true&id="+data.id);
            });
        }

        close_modal_houseList();
    }
})(jQuery);
</script>
{% include 'recommendHouse.html' %}
{{ block('recommendHouse') }}
{% include 'addCustomer.html' %}
{{ block('addCustomer') }}
</body>
</html>