<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=360, user-scalable=0"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title></title>
    <style></style>
    <link rel="stylesheet" type="text/css" href="{{ theme }}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="{{ theme }}/css/bookingList.css">
    <script type="text/javascript" src="{{ theme }}/js/iscroll.js"></script>
    <script type="text/javascript" src="{{ theme }}/js/jquery.min.js"></script>
    <script type="text/javascript" src="{{ theme }}/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="{{ theme }}/js/jquery.mobile.custom.min.js"></script>
</head>
<body>
{% if result %}
<div id="wrapper">
    <div id="scroller">
        {% for item in result %}
        <ul class="list-unstyled">
            <li>
                <p>楼盘名：{{ item.name }}</p>
                <p>预约时间：{{ item.date }} {{ item.time }}</p>
            {% if item.user_id %}
                {% if item.handle==0 %}
                <p class="accept">
                    <button type="button" class="btn" data-name="handle" data-id="{{ item.id }}">接受</button>
                </p>
                {% endif %}
            {% endif %}
            </li>
        </ul>
        {% endfor %}
    </div>
</div>
{% else %}
<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-booking">
        <div class="modal-content text-center">
            <h3>您还未预约过看房信息。<br>马上去预约看房！</h3>
            <ul class="list-unstyled">
                <li>新房</li>
                <li>二手房</li>
                <li>租房</li>
            </ul>
        </div>
    </div>
</div>
{% endif %}
<script>
    $(document).ready(function () {
        {% if result %}
            var myScroll = new IScroll('#wrapper',{
                click: true
            });
            $('[data-name=handle]').tap(function () {
                var self = $(this);
                var id = self.data('id');
                $.ajax({
                    type: 'POST',
                    url: '{{ url }}/wp-admin/admin-ajax.php/',
                    data: 'action=handle_view_house&id=' + id,
                    success: function (data) {
                        if (data.code == 2000) {
                            self.parent().remove();
                            alert('接受成功');
                        } else {
                            alert('接受失败');
                        }
                    }
                });
            });
        {% else %}
            var myModal = $('#myModal');
            myModal.modal('show');
            myModal.find('li').tap(function(){
                var index = $(this).index();
                window.location.href = '{{ url }}/?houseType=' + index;
            });
        {% endif %}
    });
</script>
</body>
</html>