<!---->
<div id="centre" class="layout">
    <div class="centreInner ">
        <div class="mainInner radius5 "> 
            <!---->
            <div class="titleTabBox">
                <div class="titleTab">
                    <div class="titleTabB clearfix">
                        <dl class="list">
                            <dd class="item itemOn"> <a class="link" href="/house_demands/rent/"> 求租需求</a> </dd>
                            <dd class="item "> <a class="link" href="/house_demands/rent_matched/"> 已匹配需求 </a></dd>
                        </dl>
                    </div>
                </div>
            </div>
            <div class="forms "></div>
            <!---->
            <div class="fgTitleBox radius4">
                <table class="table">
                    <tr>
                        <td class="w260">房源位置</td>
                        <td class="w280">要求</td>
                        <td class="w210">备注</td>
                        <td>操作</td>
                    </tr>
                </table>
            </div>
            <!---->
            <?php
            if (is_array($demands_info) && !empty($demands_info)) {
                foreach ($demands_info as $key => $value) {
                    $param_arr = array();
                    $param_arr['want_id'] = $value['id'];
                    ?>
                    <form name='search_form' id ='search_form' method ='post' action =''>
                        <div class="itemInfoBach itemInfoBachAuto radius4">
                            <table class="table">
                                <tr>
                                    <td class="td second"><div class="itemTex itemTex3"><?php echo $value['address']; ?></div></td>
                                    <td class="td w280">
                                        <div class="itemTex3"><?php echo $value['infotype']; ?> 
                                            <span class="fg">|</span> <?php echo $value['buildarea1'];?>-<?php echo $value['buildarea2'];?>平
                                            <span class="fg">|</span> <?php echo $value['price1']; ?>-<?php echo $value['price2']; ?>元/月
                                            <span class="fg">|</span> <?php echo $value['renttype'];?>
                                        </div>
                                    </td>
                                    <td class="td w210"><div class="itemTex3"><?php if($value['remark'] != ''){echo $value['remark'];}else{echo '暂无备注信息';} ?></div></td>
                                    <td class="td" id="operate_<?php echo $value['id'];?>">
                                        <?php if (empty($matched_ids_arr) || (!in_array($value['id'], $matched_ids_arr))) { ?>
                                            <?php if ($value['totday_matched_num'] < $perday_matche_limit) { ?>
                                                <a href="javascript:void(0)" onClick='get_matching_house_list(1,<?php echo json_encode($param_arr); ?>)' class="link">匹配房源</a>
                                            <?php } else { ?>
                                                <div class="timeSata"><?php echo $value['next_match_time']; ?></div>
                                                <a style="display:none;" href="javascript:void(0)" onClick='get_matching_house_list(1,<?php echo json_encode($param_arr); ?>)' class="link">匹配房源</a>
                                            <?php } ?>
                                            <div style="display: none;" id="match_window_title_<?php echo $value['id'];?>">                    
                                                <dl class="list">
                                                    <dd class="t">需求详情：</dd>
                                                    <dd class="info" want_id = '<?php echo $value['id'];?>'>
                                                        <?php echo $value['address']; ?>
                                                        <span class="fg">/</span><?php echo $value['infotype'];?> 
                                                        <span class="fg">/</span><?php echo $value['buildarea1'];?>-<?php echo $value['buildarea2'];?>平
                                                        <span class="fg">/</span><?php echo $value['price1']; ?>-<?php echo $value['price2'];?>元/月
                                                        <span class="fg">/</span><?php echo $value['renttype'];?></dd>
                                                </dl>
                                                <dl class="list">
                                                    <dd class="t">发布时间：</dd>
                                                    <dd class="info"><?php echo date('Y-m-d', $value['creattime']); ?></dd>
                                                </dl>
                                            </div>
                                        <?php } else { ?>
                                            <span class="onPcolor">已匹配</span>
                                        <?php } ?>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    <?php } ?>
                    <script>
                        $(".timeSata").each(function() {
                            var x = $(this).html();
                            if (x.length) {
                                $(this).countdown({
                                    htmlTemplate: '<strong class="num">%h时</strong><strong class="num">%i分</strong><strong class="num">%s秒</strong><br>后可匹配',
                                    date: x,
                                    yearsText: '年',
                                    monthsText: '月',
                                    daysText: '天',
                                    hoursText: '时',
                                    minutesText: '分',
                                    secondsText: '秒',
                                    servertime: '<?php echo microtime(true) * 1000; ?>',
                                    onComplete: function(event)
                                    {
                                        $(this).hide();
                                        $(this).siblings('.link').show();
                                    }
                                });
                            }
                        });
                    </script>
                <?php } else { ?>
                    <div class="itemInfoBach itemInfoBach02 radius4">
                        <p style="text-align:center; line-height:64px;">暂无符合条件的求租记录！</p>	
                    </div>
                <?php } ?>

                <!--翻页-->
                <?php if (!empty($pagination)) { ?>
                    <div class="picPreviewPagBox pagBoxBorderTop">
                        <div class="picPreviewPag">
                            <?php echo $pagination; ?>
                        </div>
                        <input type='hidden' name='page' value='<?php echo $page; ?>'>
                    </div>
                <?php } ?>
            </form>
            <!---->
            <div class="itemInfoBach kindlyReminder radius4">
                <div class="hd">
                    <h4 class="h4">温馨提示：</h4>
                    <a href="#" class="more">查看详细说明&gt;&gt;</a></div>
                <div class="list">
                    <p>1、列表里面出现的均为租房用户发布求租信息。</p>
                    <p>2、当您有符合该求租条件的房源的时候，您就可以收到该求租需求。</p>
                    <p>3、每条求租需求，您只能匹配一次。</p>
                    <p>4、每条求租需求，每天只能有20个经纪人进行匹配，如果您没匹配到，说明您前面已经超过20个人进行匹配，请24小时之后再进行匹配。</p>
                    <p>5、匹配的房源内容必须与求租需求范围内，方可匹配成功。</p>
                    <p>6、匹配成功将扣除500房豆，房豆不够将无法匹配。</p>
                    <p>7、匹配成功之后，您将获得该用户的联系方式，方便您与其推荐房源。</p>
                </div>
            </div>
            <div class="clear">&nbsp;</div>
        </div>
    </div>
</div>
<!--主体 End-->


<div id="js_open_house" class="dialog dialogW650 radius5">
    <div class="hd">
        <h3 class="h3">匹配房源</h3>
        <p class="close close-win" title="关闭">关闭 </p>
    </div>
    <div class="mod">
        <div class="m_hose_box">
            <div class="house_title"></div>
            <div class="m_house_list js_m_house_list"></div>
            <!--翻页-->
            <div class="picPreviewPagBox">
                <div class="picPreviewPag"></div>
            </div>
        </div>
        <div class="winAskBtn winM_HouseBtn">
            <a href="javascript:void(0)" class="btn btnCon radius5" onclick="match_house_by_rowid()">确认</a>
            <a href="javascript:void(0)" class="btn btnCon radius5 close-win">取消</a>
        </div>
    </div>
</div>
<script>
//选择匹配房源
$(function() {
    
    $(".js_m_house_list .item").live("mouseenter mouseleave click", function(event) {
        if (event.type == "mouseenter")
        {
            $(this).addClass("itemHover");
        }
        else if (event.type == "mouseleave")
        {
            $(this).removeClass("itemHover");
        }
        else
        {
            $(".js_m_house_list .item").removeClass("itemSet");
            $(this).addClass("itemSet");
        }
    })
})

//获取符合条件的匹配房源列表
function get_matching_house_list(page, json_param)
{
    var want_id = json_param.want_id;
    
    //清空分页
    $("#js_open_house").find(".picPreviewPag").empty();
    $("#js_open_house").find(".house_title").html($("#match_window_title_" + want_id).html());
    
    //加载默认值
    var loading_str = '<div class="textCent"><img src ="<?= STATIC_SOURCE_URL ?>/zsb/images/v1.0/loading.gif">&nbsp;数据加载中……</div>';
    $("#js_open_house").find(".js_m_house_list").html(loading_str);

    $.ajax({
        type: 'get',
        url: '<?php echo GB_WO_URL; ?>/ajax/get_renthouselist_by_wantid/',
        data: {'page': page, 'want_id': want_id},
        dataType: 'json',
        success: function(data)
        {
            var match_str = '';

            if (data['house_info'].length > 0)
            {   
                match_str+='<dl class="list">';
                for (var i = 0; i < data['house_info'].length; i++)
                {
                    var order = i + 1;
                    match_str += '<dd class="item radius4" houseid=' + data['house_info'][i]["id"] + '>' + order + '、' + data['house_info'][i]["address"] + '<span class="fg">|</span>' + data['house_info'][i]["infotype_str"]
                            + '<span class="fg">|</span>' + data['house_info'][i]["buildarea"] + '平<span class="fg">|</span>' + data['house_info'][i]["price"]
                            + '元/月<span class="fg">|</span>' + data['house_info'][i]["renttype"] + '</dd>';
                }
                 match_str+='</dl>';
                //传递参数
                var param = JSON.stringify(json_param);
                var func_callback = 'get_matching_house_list';
                var total_page = data['total_page'];
                var page_str = ajax_page(page, total_page, func_callback, param);
                $("#js_open_house").find(".picPreviewPag").html(page_str);
            }
            else
            {
                var match_str = '<div class="textCent">无符合求租信息条件的房源</div>';
            }

            $("#js_open_house").find(".js_m_house_list").html(match_str);
        }
    });

    if (page <= 1)
    {
        openWin('js_open_house');
    }
}

//匹配房源
function match_house_by_rowid()
{
    //获取房源编号，判断房源是否已经选中了
    var rowid = $(".js_m_house_list .itemSet").attr("houseid");
    
    if (isNaN(rowid) || rowid <= 0)
    {
        alert('请选择你要匹配的房源');
        return false;
    }

    //获取求租信息编号，如果为空则提醒
    var want_id = $("#js_open_house .house_title").find(".info").attr('want_id');
    
    if (isNaN(want_id) || want_id <= 0)
    {
        alert('求租信息为空，刷新页面再试');
        return false;
    }
    
    $.ajax({
        type: 'get',
        url: '<?php echo GB_WO_URL; ?>/ajax/match_rent_demand_by_rowid/',
        data: {'rowid': rowid, 'want_id': want_id},
        success: function(data)
        {
            if( data == 'sucess')
            {	
                message = '恭喜您用500房豆成功兑换了一条求租信息，赶快联系客户吧！';
                $("#js_open_house").hide();
                $("#gTipsCoverjs_open_house").hide();
                $("#operate_"+want_id).html('<span class="onPcolor">已匹配</span>');
            }
            else if( data == 'type_error')
            {
                message = '匹配类型参数不一致，无法匹配房源。';
            }
            else if( data == 'my_limit_error')
            {	
                message = '您已经匹配过该求租信息，无法匹配房源。';
            }
            else if( data == 'info_error')
            {
                message = '您提交数据有误，请刷新重新提交。';
            }
            else if(data == 'credit_not_enough_error')
            {
                message = '您的房豆不足500，无法匹配房源。';
            }
            else if(data == 'key_error')
            {
                message = '参数不正确，请刷新重新提交。';
            }
            else if(data == 'total_limit_error')
            {
                message = '匹配总量已达上限，无法匹配房源。';
            }
            else if(data == 'day_limit_error')
            {	
                message = '该求租匹配本轮匹配量已达上限，无法匹配房源。';
            }
            else if(data == 'infotype_error')
            {
                message = '房源类型参数不一致，无法匹配房源。';
            }
            else if(data == 'street_error')
            {
                message = '板块信息参数不一致，无法匹配房源。';
            }
            else if(data == 'buildarea_error')
            {
                message = '面积参数不一致，无法匹配房源。';
            }
            else if(data == 'price_error')
            {
                message = '价格参数不一致，无法匹配房源。';
            }
            else if(data == 'renttype_error')
            {
                message = '租赁方式参数不一致，无法匹配房源。';
            }
            else if(data == 'buildyear_error')
            {
                message = '建筑年代参数不一致，无法匹配房源。';
            }
            else if(data == 'key_error')
            {
                message = '页面参数有错误，无法匹配房源。';
            }
            else
            {
                message = '匹配房源失败，请致电客服。';
            }

            show_error_message(message);
        }
    });
}

//消息处理函数
function show_error_message(message)
{	
    alert(message);
}
</script>