<!--2017-11-28推广服务弹框-->
<script>
    function checkPackageForm(){
        var package_type = $('input[name=package_type]').val();
        var isCheck = $('#rule'+package_type).is(':checked');
        if(!isCheck){
            $("#error_"+package_type).show();
            return false;
        }
        return true;
    }
    var packageInfo;
    function showKeywordDetail(keyword){
        var str = '';
        for(var p in packageInfo){
            if(packageInfo[p].package_type == 1 && packageInfo[p].package_keyword == keyword && packageInfo[p].package_desc && str == ''){
                var data = packageInfo[p].package_desc;
                var type = packageInfo[p].package_type;
                var i = 0;
                for (var x in data){
                    var id = type + '_' + keyword + '_' + x;
                    if(i == 0){
                        str += '<div class="popc poplil popcon">';
                        str += '<label  for="' + id +'" class="radiop radiopon">';
                        str += '<input name="day_'+ type +'" value="'+ data[x].day +'" id="' + id +'" type="radio" checked="checked" />';
                        $('#price_' + type).html(data[x].price + '元');
                    }else{
                        str += '<div class="popc poplil">';
                        str += '<label  for="' + id +'" class="radiop">';
                        str += '<input name="day_'+ type +'" value="'+ data[x].day +'" id="' + id +'" type="radio"/>';
                    }
                    str += '</label>';
                    str += '<label for="' + id +'"> '+ data[x].day +'天 <span class="red bold"  price="'+ data[x].price +'元">'+ data[x].price +'元</span></label></div>';
                    i++;
                }
            }
        }
        $('#indexDetail').html(str);
    }
    function showDetailByType(type){
        var str = '';
        var priceThis = 0;
        for(var p in packageInfo){
            if(packageInfo[p].package_type == type && packageInfo[p].package_desc && str == ''){
                var data = packageInfo[p].package_desc;
                var keyword = 0;
                var discount = '';
                var i = 0;
                for (var x in data){
                    var id = type + '_' + keyword + '_' + x;
                    if(type == 2 ){
                        var dayLabel = data[x].day +'天';
                    }
                    if(type == 3 ){
                        var dayLabel = data[x].day +'天（刷新' + data[x].day * 8 + '次）';
                    }

                    if(type == 5 ){
                        var dayLabel = '实勘';
                    }
                    if(typeof data[x].discount != 'undefined' && data[x].discount != 10 && data[x].discount != ''){
                        priceThis = (data[x].price * (data[x].discount*10)) / 100;
                    }else{
                        priceThis = data[x].price;
                    }

                    discount = '';
                    if(typeof data[x].discount != 'undefined' && data[x].discount != 10 && data[x].discount != '') {
                        discount = data[x].discount + '';
                        //折扣
                        discount = '('+discount+'折'+')';
                    }

                    if(i == 0){
                        str += '<div class="popc poplil popcon">';
                        str += '<label  for="' + id +'" class="radiop radiopon">';
                        str += '<input name="day_'+ type +'" value="'+ data[x].day +'" id="' + id +'" type="radio" checked="checked" />';

                        if(type == 5 ){
                            $('#price_' + type).html(priceThis + '元'+discount);
                        }else{
                            $('#price_' + type).html(priceThis + '元');
                        }
                    }else{
                        str += '<div class="popc poplil">';
                        str += '<label  for="' + id +'" class="radiop">';
                        str += '<input name="day_'+ type +'" value="'+ data[x].day +'" id="' + id +'" type="radio"/>';
                    }
                    str += '</label>';
                    str += '<label for="' + id +'"> '+ dayLabel +' <span class="red bold" price="'+ priceThis +'元">'+ priceThis +'元'+discount+'</span></label></div>';
                    i++;
                }
            }
        }
        $('#price_detail_'+type).html(str);
    }
    function showPop(name,tbl,id){
        $('.poplist').hide();
        $('.popkl').hide();
        $('.popt').hide();
        $('.popt.popon').attr('class','popt');
        $('.popkl.popklon').attr('class','popkl');
        if(name == 'extendPop'){
            var type = 'promote';
        }else if(name == 'survey'){
            var type = 'survey';
        }else{
            var type = 'refresh';
        }
        $.ajax({
            async:false,
            type: 'get',
            url : '/user/getPersonalHousePackage/'+ id + '/'+ tbl + '/'+ type,
            dataType:'json',
            success: function(data){
                packageInfo = data;
                if(data.length == 0){
                    $("#war-text").html("暂无符合条件的套餐");
                    openWin('warning');
                    return false;
                }
                var typeFlag = true;
                var keywordFlag = true;
                for(var p in packageInfo){
                    var type = packageInfo[p].package_type;
                    var keyword = packageInfo[p].package_keyword;
                    var package_id =  packageInfo[p].id;
                    $('#package_type_' + type).show();
                    if(typeFlag){
                        $('#package_type_' + type).attr('class','popt popon');
                        $('#package_type_' + type + '_div').show();
                        $('input[name=package_type]').val(type);
                        $('input[name=package_id]').val(package_id);
                        typeFlag = false;
                    }
                    if(type == 1 && keyword){
                        $('#package_keyword_' + keyword).show();
                        if(keywordFlag){
                            $('#package_keyword_' + keyword).attr('class','popkl popklon');
                            showKeywordDetail(keyword);
                            $('input[name=package_keyword]').val(keyword);
                            keywordFlag = false;
                        }
                    }
                    if(type == 2 || type == 3){
                        showDetailByType(type);
                    }
                    if(type == 4){
                        var data = packageInfo[p].package_desc;
                        for (var x in data){
                            $('#price_4').html(data[x].price + '元');
                        }
                    }
                    if(type == 5){
                        showDetailByType(type);
                        // $('#price_5').html(data[0].package_desc[0].price + '元');
                    }
                }
                $('input[name=house_id]').val(id);
                $('input[name=tbl]').val(tbl);
                var w_ws = $(window).width();
                var w_hs = $(window).height();
                var fix_w = $('.' + name + " .release-fail").width();
                var fix_h = 720;
                var mf_w = (w_ws - fix_w)/2;
                var mf_h = (w_hs - fix_h)/2;
                $(".release-failBack").css({"width": w_ws+"px", "height": w_hs+"px"});
                $(".release-fail").css({"top": mf_h+"px","left": mf_w+"px"});
                $('.' + name + " .release-failBack").show();
                $('.' + name + " .release-fail").show();
                //给链接赋值
                if(tbl == 'sell'){
                    $('#index_top_url').attr('href','<?php echo GB_HOUSE_PROMOTE_PIC,'#tab1';?>');
                    $('#list_top_url').attr('href','<?php echo GB_HOUSE_PROMOTE_PIC,'#tab2';?>');
                }
                if(tbl == 'rent'){
                    $('#index_top_url').attr('href','<?php echo GB_HOUSE_PROMOTE_PIC,'#tab3';?>');
                    $('#list_top_url').attr('href','<?php echo GB_HOUSE_PROMOTE_PIC,'#tab4';?>');
                }

                <?php if(GB_CITY== 'wh') {?>
                $('#list_top_url').attr('href','http://user.house365.com/images/liebiaotuijian.jpg');
                <?php }?>
            }
        });
    }
    $(function(){
        $(".popt").live("click",function(){
            if($(this).hasClass("popon")){

            }else{
                $(this).parents(".release-fail").find(".popt").removeClass("popon");
                $(this).addClass("popon");
                var package_type = $(this).attr('data-package-type');
                $('input[name=package_type]').val(package_type);
                if(package_type != 1){
                    for(var p in packageInfo){
                        if( packageInfo[p].package_type == package_type){
                            $('input[name=package_id]').val(packageInfo[p].id);
                        }
                    }
                }else{
                    var keyword = $('input[name=package_keyword]').val();
                    for(var p in packageInfo){
                        if( packageInfo[p].package_type == 1 && packageInfo[p].package_keyword == keyword){
                            $('input[name=package_id]').val(packageInfo[p].id);
                        }
                    }
                }
                $(this).parents(".release-fail").children(".poplist").hide();
                $(this).parents(".release-fail").children(".poplist").eq($(this).index()).show()
            }
        });

        $(".popkl").live("click",function(){
            if($(this).hasClass("popklon")){

            }else{
                $(".popkl").removeClass("popklon");
                $(this).addClass("popklon");
                var keyword = $(this).attr('data-keyword');
                $('input[name=package_keyword]').val(keyword);
                for(var p in packageInfo){
                    if( packageInfo[p].package_type == 1 && packageInfo[p].package_keyword == keyword){
                        $('input[name=package_id]').val(packageInfo[p].id);
                    }
                }
                showKeywordDetail(keyword);
            }
        });

        $(".poplil").live("click",function(){
            if($(this).hasClass("popcon")){

            }else{
                console.log($(this));
                $(this).siblings(".poplil").removeClass("popcon");
                $(this).siblings(".poplil").find("input").removeAttr("checked");
                $(this).addClass("popcon");
                $(this).find("input").attr("checked","checked" );
                var type = $('input[name=package_type]').val();
                $('#price_' + type).html($(this).find('span.red').attr('price'));
                $(this).children(".radiop").addClass("radiopon");
                $(this).siblings(".poplil").children(".radiop").removeClass("radiopon");
            }
        });

        $(".popli").live("click",function(){
            if($(this).hasClass("popcon")){

            }else{
                $(this).siblings(".popli").removeClass("popcon");
                $(this).siblings(".popli").find("input").attr("checked","" );
                $(this).addClass("popcon");
                $(this).find("input").attr("checked","checked" );

                $(this).children(".radiop").addClass("radiopon");
                $(this).siblings(".popli").children(".radiop").removeClass("radiopon");
            }
        });


        $(".source-manger02 .extend img").on("click",function(){
            $(this).parents(".extend").children(".proswap").hide();
        });

        $(".poprule").live("click",function(){
            if($(this).children(".radioc").hasClass("radiocon")){
                $(this).children("input").removeAttr("checked");
                $(this).children(".radioc").removeClass("radiocon");

            }else{$(this).children("input").attr("checked",true);
                $(this).children(".radioc").addClass("radiocon");

            }
        })
    })
</script>

<form method="post" action="<?php echo USER_CENTER.'user/pay'?>" onsubmit="return checkPackageForm();">
    <input type="hidden" name="package_type" value="">
    <input type="hidden" name="package_id" value="">
    <input type="hidden" name="package_keyword" value="">
    <input type="hidden" name="house_id" value="">
    <input type="hidden" name="tbl" value="">
    <input type="hidden" name="pay_type" value="wxpay">
    <div class="extendPop popw" >
        <div class="release-failBack" style="display:none;"></div>
        <div class="release-fail yz-pop" style="display:none;">
            <div class="tit">
                <span>推广服务</span>
                <div class="closes"  alt="0"></div>
            </div>
            <div class="poptab cf"  <?php if(GB_CITY == 'wh') echo 'style="display: none"';?>>
                <div class="popt" id="package_type_1" data-package-type="1">
                    首页推荐
                </div>
                <div class="popt" id="package_type_2" data-package-type="2">
                    优先展示
                </div>
            </div>
            <div class="poplist" id="package_type_1_div">
                <div class="popmemo">
                    首页个人房源推荐区域大图展示，海量曝光，效果提升5倍！<a id="index_top_url" href="" target="_blank">推广位置示意图</a>
                </div>
                <div class="cf popkey">
                    <label class="labeln">推广关键词：</label>
                    <div class="popk">
                        <div class="popkl" id="package_keyword_1" data-keyword="1">首选<img  src="http://user.house365.com/images/cor.png" /></div>
                        <div class="popkl" id="package_keyword_2" data-keyword="2">地铁<img  src="http://user.house365.com/images/cor.png" /></div>
                        <div class="popkl" id="package_keyword_3" data-keyword="3">学区<img  src="http://user.house365.com/images/cor.png" /></div>
                        <div class="popkl" id="package_keyword_4" data-keyword="4">公寓<img  src="http://user.house365.com/images/cor.png" /></div>
                        <div class="popkl" id="package_keyword_5" data-keyword="5">住宅<img  src="http://user.house365.com/images/cor.png" /></div>
                        <div class="popkl" id="package_keyword_6" data-keyword="6">商铺<img  src="http://user.house365.com/images/cor.png" /></div>
                        <div class="popkl" id="package_keyword_7" data-keyword="7">写字楼<img  src="http://user.house365.com/images/cor.png" /></div>
                    </div>
                </div>
                <div class="cf popkey">
                    <label class="labeln">推广时长：</label>
                    <div class="popcl" id="indexDetail">
                    </div>
                </div>
                <div class="poppay">
                    <div>需要支付：<span class="red" id="price_1"></span></div>
                    <img src="/images/wei.jpg" />
                </div>
                <div class="poprule">
                    <label class="radioc "></label>
                    <input id="rule1" type="checkbox" value='1'  />
                    <label>已阅读并同意 </label> <span class="blue">《<a href="<?php echo GB_HOUSE_PROMOTE_RULE;?>" target="_blank">365推广规则</a>》</span>
                    <span id="error_1" style="display: none;color: red;">请阅读并同意推广规则</span>
                </div>
                <div class="popbtn"><button>提交支付</button></div>
            </div>
            <div class="poplist" id="package_type_2_div">
                <div class="popmemo">
                    个人房源列表页带有“广告”字样靠前循环展示，关注度会大幅提升！<a id='list_top_url' href="" target="_blank">推广位置示意图</a>

                </div>
                <div class="cf popkey">
                    <label class="labeln">推广天数：</label>
                    <div class="popcl" id="price_detail_2">
                    </div>
                </div>
                <div class="poppay">
                    <div>需要支付：<span class="red" id="price_2"></span></div>
                    <img src="http://user.house365.com/images/wei.jpg" />
                </div>
                <div class="poprule">
                    <label class="radioc "></label>
                    <input id="rule2" type="checkbox" value='1' />
                    <label>已阅读并同意 </label> <span class="blue">《<a href="<?php echo GB_HOUSE_PROMOTE_RULE;?>" target="_blank">365推广规则</a>》</span>
                    <span id="error_2" style="display: none;color: red;">请阅读并同意推广规则</span>
                </div>
                <div class="popbtn"><button>提交支付</button></div>
            </div>
        </div>
    </div>

    <div class="refresh popw" >
        <div class="release-failBack" style="display:none;"></div>
        <div class="release-fail yz-pop" style="display:none;">
            <div class="tit">
                <span>刷新提示 </span><p>免费刷新次数已经用完，不享有免费刷新。</p>
                <div class="closes"  alt="0"></div>
            </div>
            <div class="poptab cf">
                <div class="popt" id="package_type_3" data-package-type="3">
                    智能刷新
                </div>
                <div class="popt" id="package_type_4" data-package-type="4">
                    立即刷新
                </div>
            </div>
            <div class="poplist" id="package_type_3_div">
                <div class="popmemo">
                    6:00-22:00间，房源每2小时自动刷新1次，获得更多曝光机会！
                </div>
                <div class="cf popkey">
                    <label class="labeln">刷新天数：</label>
                    <div class="popcl" id="price_detail_3">
                    </div>
                </div>
                <div class="poppay">
                    <div>需要支付：<span class="red" id="price_3"></span></div>
                    <img src="/images/wei.jpg" />
                </div>
                <div class="poprule">
                    <label class="radioc "></label>
                    <input id="rule3" type="checkbox" value='1'  />
                    <label >已阅读并同意 </label> <span class="blue">《<a href="<?php echo GB_HOUSE_PROMOTE_RULE;?>" target="_blank">365推广规则</a>》</span>
                    <span id="error_3" style="display: none;color: red;">请阅读并同意推广规则</span>
                </div>
                <div class="popbtn"><button>提交支付</button></div>
            </div>
            <div class="poplist" id="package_type_4_div">
                <div class="popmemo">
                    单次付费，购买后立即刷新，刷新后房源排名靠前，获得更多浏览机会！
                </div>
                <div class="poppay">
                    <div>需要支付：<span class="red" id="price_4"></span></div>
                    <img src="/images/wei.jpg" />
                </div>
                <div class="poprule">
                    <label class="radioc "></label>
                    <input id="rule4" type="checkbox" value='1'  />
                    <label >已阅读并同意</label> <span class="blue">《<a href="<?php echo GB_HOUSE_PROMOTE_RULE;?>" target="_blank">365推广规则</a>》</span>
                    <span id="error_4" style="display: none;color: red;">请阅读并同意推广规则</span>
                </div>
                <div class="popbtn"><button>提交支付</button></div>
            </div>
        </div>
    </div>

    <div class="survey popw" >
        <div class="release-failBack" style="display:none;"></div>
        <div class="release-fail yz-pop" style="display:none;width: 600px;height: auto">
            <div class="tit">
                <span>推广服务</span>
                <div class="closes"  alt="0"></div>
            </div>

            <div class="poplist" id="package_type_5_div">
                <div class="popmemo">
                    专业人员上门实拍，以VR全景形式展示户型结构及实景。<a href="https://beyond.3dnest.cn/house/?m=0b937c26_vzOZ_b6f9" target="_blank">vr实勘示意图</a>
                </div>

                <div class="cf popkey" style="display: none">
                    <label class="labeln">推广天数：</label>
                    <div class="popcl" id="price_detail_5">
                    </div>
                </div>

                <div class="poppay">
                    <div style="margin-bottom: 30px">需要支付：<span class="red" id="price_5" ></span></div>
                    <img src="/images/wei.jpg" />
                </div>
                <div class="poprule">
                    <label class="radioc "></label>
                    <input id="rule5" type="checkbox" value='1'  />
                    <label>已阅读并同意 </label> <span class="blue">《<a href="<?php echo GB_HOUSE_PROMOTE_RULE;?>" target="_blank">365推广规则</a>》</span>
                    <span id="error_5" style="display: none;color: red;">请阅读并同意推广规则</span>
                </div>
                <div class="popbtn"><button>提交支付</button></div>
            </div>
        </div>
    </div>

</form>
<!--2017-11-27 推广服务弹框 end-->
