淡定的国际酒店查询脚本

room_detail_cutover = {};
WUI.loadModule([ "cutover", 'dialog' ], function() {
    room_detail_cutover = new WUI.Cutover(function() {
        this.toggle();
        if (this.css('display') == 'block') {
            this.css('display', '');
        }
    }, function() {
        this.hide();
    });
});
var opts = {
    CountryCode : $.query.get('CountryCode'),
    CityCode : $.query.get('CityCode'),
    HotelName : $.query.get('HotelName'),
    StartDate : $.query.get('StartDate'),
    EndDate : $.query.get('EndDate'),
    NumAdults : $.query.get('NumAdults'),
    NumChildren : $.query.get('NumChildren'),
    NumRooms : $.query.get('NumRooms'),
    sort : 1,
    l : $.query.get('l') && $.query.get('l') == 'EN' ? $.query.get('l') : ''
}
var hotels_room_types = [];
var hotel_facilitys = [];
var URL = {
    facilitys : '/international/hotelList' + opts.l + '!GetHotelFacility.do',// 获取酒店设施
    roomtypes : '/international/hotelList' + opts.l + '!getRoomtypes.do',// 获取房型基础信息
    currency : '/international/hotelList' + opts.l + '!getCurrency.do',// 获取汇率
    room_list : '/international/hotelList' + opts.l + '!getRoomList.do',// 获取房型列表
    areas : '/international/hotelList' + opts.l + '!geoArea.do',// 获取区域
    hotels : '/international/hotelList' + opts.l + '!getHotelCity.do',// 获取酒店
    hotel_detail : '/international/hotelList' + opts.l + '!getHotelInfo.do',// 获取酒店详情
    all_country : '/international/hotelList' + opts.l + '!geoCountry.do',// 获取所有的国家
    city : '/international/hotelList' + opts.l + '!geoCity.do',// 根据国家获取城市
    pre_order : '/international/hotelOrder' + opts.l + '!orderDetail.do'// 填写订单信息
}
var hotel_query_list = [];
var currency = {};
var page_size = 3;
var hotel_list = [];
var area_list = [];
var pager = {};
var load = {};
var city_list = {};
var country_list = {};
$(function() {
    load = new WUI.Dialog($("#loadding")[0]);
    load.show();// 开启遮罩
    // 初始化查询信息
    $('#StartDate').val(opts.StartDate);// 入住时间
    $('#EndDate').val(opts.EndDate);// 退房时间
    $('#HotelName').val(opts.HotelName);// 酒店名称
    var BeginTime = new Date(Date.parse(opts.StartDate.replace(/-/g, "/")));
    var EndTime = new Date(Date.parse(opts.EndDate.replace(/-/g, "/")));
    var DestineRoomNum = (EndTime.getTime() - BeginTime.getTime()) / (1000 * 60 * 60 * 24);
    $('#DestineRoomNum').text(DestineRoomNum);// 入住天数
    // 加载汇率
    $.getJSON(URL.currency, function(slt_currency) {
        currency = slt_currency;
        // 加载区域
        $.getJSON(URL.areas, {
            id : opts.CityCode
        }, function(areas) {
            var slt_areas = $('#slt_area');
            slt_areas.empty();
            var def_opt = $('<option>');
            def_opt.val(0);
            def_opt.text('All');
            slt_areas.append(def_opt);
            $.each(areas, function() {
                var opt = $('<option>');
                opt.val(this.area_id);
                opt.text(this.area_name);
                slt_areas.append(opt);
                area_list[this.area_id] = this;
            })
            // 加载酒店
            $.getJSON(URL.hotels, {
                id : opts.CityCode
            }, function(hotels) {
                hotel_list = hotels;
                query1();
                load.close();// 关闭遮罩
            })
        })
    })

    // 获取所有的国家
    $.getJSON(URL.all_country, function(country) {
        var slt_country = $('#international_slt_countrys');
        slt_country.empty();
        var def_opt = $('<option>');
        def_opt.val(0);
        def_opt.text('-choose country-');
        slt_country.append(def_opt);
        $.each(country, function(i, item) {
            var opt = $('<option>');
            opt.val(this.country_id);
            opt.text(this.country_name);
            slt_country.append(opt);

            if (this.country_id == opts.CountryCode) {
                $("#international_slt_countrys option[value='" + item.country_id + "']").attr("selected", true);
                var countryCode = this.country_id;
                $.getJSON(URL.city, {
                    id : countryCode
                }, function(city) {
                    var slt_city = $('#international_slt_citys');
                    slt_city.empty();
                    var def_opt = $('<option>');
                    def_opt.val(0);
                    def_opt.text('-choose city-');
                    slt_city.append(def_opt);
                    $.each(city, function(i, item) {
                        var opt = $('<option>');
                        opt.val(this.city_id);
                        opt.text(this.city_name);
                        slt_city.append(opt);
                        if (this.city_id == opts.CityCode) {
                            $("#international_slt_citys option[value='" + item.city_id + "']").attr("selected", true)
                        }
                        city_list[this.city_id] = this;
                    })
                })
            }
            country_list[this.country_id] = this;
        })
    })

    // 根据国家获取所有的城市
    $("#international_slt_countrys").change(function() {
        var countryCode = $(this).val();
        $.getJSON(URL.city, {
            id : countryCode
        }, function(city) {
            var slt_city = $('#international_slt_citys');
            slt_city.empty();
            var def_opt = $('<option>');
            def_opt.val(0);
            def_opt.text('-choose city-');
            slt_city.append(def_opt);
            $.each(city, function(i, item) {
                var opt = $('<option>');
                opt.val(this.city_id);
                opt.text(this.city_name);
                slt_city.append(opt);
                if (this.city_id == opts.CityCode) {
                    $("#international_slt_citys option[value='" + item.city_id + "']").attr("selected", true)
                }
                city_list[this.city_id] = this;
            })
        })
    });

    $("#international_form").submit(function() {
        var country = $('#international_slt_countrys').val();
        if (country == 0) {
            alert("请选择国家!");
            return false;
        } else {
            var city = $("#international_slt_citys").val();
            if (city == 0) {
                alert("请选择城市!");
                return false;
            }
        }
    });
})
// 排序
function sortfunction(i, j) {
    if (opts.sort == 1) {
        return j.star_rating - i.star_rating;
    } else {
        return i.pricefrom - j.pricefrom;
    }
}
// 查询按钮
function btn_slt() {
    query1({
        area_id : $('#slt_area').val(),
        sort : $('#slt_order').val()
    });
}
// 检索
function query1(q_opts) {
    $.extend(opts, q_opts || {});
    hotel_query_list = [];

    for ( var i = 0; i < hotel_list.length; i++) {
        if (hotel_list[i] != null) {
            if (!hotel_list[i].pricefrom) {
                continue;// 过滤0价格的酒店
            } else if (opts.HotelName && opts.HotelName != true && hotel_list[i].hotel_name.indexOf(opts.HotelName) == -1) {
                continue;
            }
            if (opts.area_id && opts.area_id != 0 && opts.area_id != hotel_list[i].area_id) {
                continue;
            } else {
                hotel_query_list.push(hotel_list[i]);
            }
        }
    }
    hotel_query_list.sort(sortfunction);// 排序
    $('#HotelCount').text(hotel_query_list.length);// 酒店数
    pager = new nav(hotel_query_list.length, page_size, 1, 'pager', 'pager', function(pagesize, page) {
        showPage(page);
    });
    pager.setpage();
    pager.gotopage(1);
}
// 显示到页面
function showPage(page) {
    var hotels = getByPage(page);
    var div_hotels = $('#div_hotels');
    div_hotels.empty();
    // -- 酒店详情URL
    var detailUrl = '/international/hotelDetail!detail.do?countryCode=' + opts.CountryCode // --
                                                                                            // 国家代码
            + '&cityCode=' + opts.CityCode // -- 城市代码
            + '&hotelName=' + opts.HotelName // -- 酒店名称
            + '&startDate=' + opts.StartDate // -- 房间入住时间
            + "&endDate=" + opts.EndDate // -- 房间退房时间
            + "&numAdults=" + opts.NumAdults // -- 成 人
            + "&numChildren=" + opts.NumChildren // -- 儿 童
            + "&numRooms=" + opts.NumRooms // -- 房 数
            + "&hotelId="; // -- 酒店代码
    $.each(hotels, function() {
        var div_wrap = $('<div class="hotel_box bxbox">');// 酒店包围
        var div_hotel_info = $('<div class="hotel_info">');// 酒店信息
        var info_pic = $('<div class="pic"><a><img/></a><i class="dark_red"></i></div>');// 酒店价格
        info_pic.find('a').attr('href', detailUrl + this.hotel_id);// 图片的连接
        info_pic.find('i').text('RMB ' + conversionCNY(this.pricefrom * 1.95));// 酒店价格
        info_pic.find('img').attr('src', 'http://img.agoda.net/hotels/' + this.hotel_id + '/Main/' + this.hotel_id + '.jpg');// 图片
        div_hotel_info.append(info_pic);// 添加到容器
        var info_tit = $('<div class="tit"><h3><a></a></h3><ul class="pfxt pfxt_v2"></ul><i class="tip_cx_v2"></i></div>');
        info_tit.find('a').text(substring(this.hotel_name, 30));// 酒店名
        info_tit.find('a').attr('href', detailUrl + this.hotel_id);// 酒店连接
        // 设置酒店星级
        for ( var i = 0; i < this.star_rating; i++) {
            info_tit.find('ul').append('<li class="on"></li>');
        }
        div_hotel_info.append(info_tit);// 添加到容器
        var info_area_map = $('<p>位置:<i></i></p>');
        info_area_map.find('i').text(area_list[this.area_id].area_name);// 区域名
        // info_area_map.find('a').attr('href',this.hotel_id);//电子地图连接
        div_hotel_info.append(info_area_map);// 添加到容器
        // 详情
        var info_detail = $('<p class="hack_v2"><span class="c_666"></span><a>查看详情</a></p>');
        var detail_div_id = 'hotel_detail_' + this.hotel_id;
        info_detail.find('span').attr('id', info_detail);
        info_detail.find('span').text('loading...');
        loadDetail(this.hotel_id, info_detail);
        info_detail.find('a').attr('href', this.hotel_id);// 查看详情连接
        div_hotel_info.append(info_detail);// 添加到容器

        div_wrap.append(div_hotel_info);

        var hotel_wrap_id = 'hotel_wrap_' + this.hotel_id;
        div_wrap.attr('id', hotel_wrap_id);

        // 加载房价
        loadRoomList(this.hotel_id, div_wrap);

        div_hotels.append(div_wrap);
    })
}

// 加载房价
function loadRoomList(id, div_wrap) {
    var div_loading = $('<table border="0" class="table_b"><thead><tr><th>room list loading...</th></tr></thead></table>');
    div_wrap.append(div_loading);
    // 创建容器
    $.getJSON(URL.room_list, {
        'serviceMethod' : 'B2BXmlPartnerSearchService',
        'getRoomListParameter.CityCode' : opts.CityCode,
        'getRoomListParameter.HotelCode' : id,
        'getRoomListParameter.StartDate' : opts.StartDate,
        'getRoomListParameter.EndDate' : opts.EndDate,
        'getRoomListParameter.NumAdults' : opts.NumAdults,
        'getRoomListParameter.NumChildren' : opts.NumChildren,
        'getRoomListParameter.NumRooms' : opts.NumRooms
    }, function(rs) {
        div_loading.empty();
        if (rs && rs.hotel && rs.hotel.roomStays && rs.hotel.roomStays.length > 0) {
            var room_tb = $('<table border="0" class="table_b"></table>');
            room_tb.append('<thead><tr><th width="250">房型</th><th width="100">门市价</th><th width="100">网上支付</th><th width="100"></th></tr></thead>');
            room_tb.append('<tbody></tbody>');
            var count = 0;
            var room_trs = [];
            $.each(rs.hotel.roomStays, function(i, item) {
                var room_tr_id = 'room_' + id + '_' + this.TPA_Extensions.resultID;
                var room_tr = $('<tr>');
                room_tr.attr('id', room_tr_id);// 设置唯一标识
                var td_name = $('<td class="txtL"><a class="ico1"></a><a href="javascript:void(0)"></a></td>');
                var room_info = this;// {occupancy : this.occupancy ,
                                        // roomCode : this.roomCode};
                td_name.find('a').last().click(function() {
                    showRoomDetail(id, room_info, room_tr_id);
                });
                td_name.find('a').last().text(this.roomName);// 房型名
                room_tr.append(td_name);// 插入到房型信息
                room_tr.append('<td>RMB ' + conversionCNY(this.total.amountAfterTax * 1.95) + '</td>');// 插入门市价
                room_tr.append('<td class="dark_red" name="woyopay">RMB ' + conversionCNY(this.total.amountAfterTax) + '</td>');// 插入网上支付价
                // 插入礼盒
                if (this.promotion) {
                    room_tr.find('.dark_red').append('<a class="woyo_pay" title="' + this.promotion + '"></a>');
                }
                var btn_destine = $('<td class="txtR"><input type="button"  class="btn_destine"></td>');
                var room_ = this;
                btn_destine.find('input').click(
                        function() {
                            var url = URL.pre_order + '?finalRateParameter.SearchID=' + rs.TPA_Extensions.searchID + '&finalRateParameter.ResultID=' + item.TPA_Extensions.resultID
                                    + "&getRoomListParameter.StartDate=" + opts.StartDate + "&getRoomListParameter.EndDate=" + opts.EndDate + "&getRoomListParameter.NumRooms=" + opts.NumRooms
                                    + "&getRoomListParameter.NumAdults=" + opts.NumAdults + "&getRoomListParameter.NumChildren=" + opts.NumChildren;
                            window.open(url);
                            // window.location = ('#s_id=' +
                            // rs.TPA_Extensions.searchID + '#r_id=' +
                            // this.TPA_Extensions.resultID);
                        });
                room_tr.append(btn_destine);// 插入预定按钮
                count++;// 计数器
                if (count > 3) {
                    room_trs[count] = room_tr;
                    room_tr.hide();
                }
                room_tb.find('tbody').append(room_tr);// 添加到TBODY
            })
            div_wrap.append(room_tb);
            // 更多按钮
            if (count > 3) {
                var all_div = $('<div class="change_btn"><a href="javascript:void(0)">所有房型 <i class="ico4"></i></a></div>');
                all_div.find('a').click(function() {
                    var i = $(this).find('i');
                    if (i.attr('class') == 'ico4') {
                        $.each(room_trs, function() {
                            if (this != window) {
                                this.css('display', '');
                            }
                        })
                        i.attr('class', 'ico3');
                    } else {
                        $.each(room_trs, function() {
                            if (this != window) {
                                this.hide();
                            }
                        })
                        room_detail_cutover.on(0);
                        i.attr('class', 'ico4');
                    }
                });
                div_wrap.append(all_div);
            }
        }
    })

}
// 加载房型详细信息
function showRoomDetail(hotel_id, room, room_tr_id) {
    var room_detail_tr_id = 'room_detail_' + hotel_id + '_' + room.TPA_Extensions.resultID;
    var room_detail_tr = $('#' + room_detail_tr_id);
    if (room_detail_tr.length == 0) {
        createRoomDetail(hotel_id, room, room_tr_id, room_detail_tr_id);
        room_detail_cutover.on(room_detail_tr_id);
    } else {
        room_detail_cutover.on(room_detail_tr_id);
    }
    return room_detail_tr_id;
}
// 创建详细信息
function createRoomDetail(hotel_id, room, room_tr_id, room_detail_tr_id) {
    var room_detail = $('<tr>');
    room_detail.attr('id', room_detail_tr_id);
    room_detail.append('<td class="drop_down" colspan="4">');
    var sidebar = $('<div class="sidebar">');
    var drop_info_box = $('<div class="drop_info_box clearfix">');
    var pic = $('<div class="pic"><img/></div>');
    pic.find('img').attr('src', 'http://img.agoda.net/hotels/' + hotel_id + '/RoomType/Room_' + hotel_id + '_' + room.roomCode + '.jpg');
    drop_info_box.append(pic);
    var drop_info = $('<ul class="drop_info drop_info_v2"><li class="t"><strong>房间面积:</strong><em></em></li><li class="t"><strong>酒店设施:</strong><em>以下设施将出现在此房间</em></li></ul>');
    var room_size = drop_info.find('em').first();
    // 加载房型面积
    loadRoomSize(hotel_id, room.roomCode, room_size);
    drop_info_box.append(drop_info);
    var facilitys_ul = $('<ul class="drop_info drop_info_v2">');
    loadFacilitys(hotel_id, facilitys_ul);// 加载设施
    drop_info_box.append(facilitys_ul);
    sidebar.append(drop_info_box);
    var hide_div = $('<div class="hide">隐藏</div>');
    hide_div.click(function() {
        room_detail_cutover.on(room_detail_tr_id);
    });
    sidebar.append(hide_div);// 添加隐藏按钮
    room_detail.find('td').append(sidebar);
    room_detail.hide();
    $('#' + room_tr_id).after(room_detail);
    room_detail_cutover.push(room_detail_tr_id);
}
//加载房型面积
function loadRoomSize(hotel_id, room_id, room_size) {
    hotel_room_types = hotels_room_types[hotel_id];
    if (!hotel_room_types) {
        room_size.text('loading...');
        $.getJSON(URL.roomtypes, {
            id : hotel_id
        }, function(hotel_room_types) {
            hotels_room_types[hotel_id] = hotel_room_types;
            loadRoomSize(hotel_id, room_id, room_size);
        });
    } else {
        var hotel_room_type = null;
        for ( var i = 0; i < hotel_room_types.length; i++) {
            if (hotel_room_types[i].hotel_room_type_id == room_id) {
                hotel_room_type = hotel_room_types[i];
                break;
            }
        }
        if (hotel_room_type && hotel_room_type.size_of_room) {
            room_size.text(hotel_room_type.size_of_room + ' 平方米');
        } else {
            room_size.parent().remove();
        }
    }
}
//加载设施
function loadFacilitys(hotel_id, facilitys_ul) {
    var facilitys = hotel_facilitys[hotel_id];
    facilitys_ul.empty();
    if (!facilitys) {
        facilitys_ul.append('<li>loading...</li>');
        $.getJSON(URL.facilitys, {
            id : hotel_id
        }, function(facilitys) {
            hotel_facilitys[hotel_id] = facilitys;
            loadFacilitys(hotel_id, facilitys_ul);
        });
    } else {
        $.each(facilitys, function() {
            if (this.facility_group_name = 'Room Facilities') {
                facilitys_ul.append('<li>' + this.facility_name + '</li>');
            }
        })
    }
}
//CNY转换
function conversionCNY(USD) {
    return Math.ceil(currency.currency_exchange * USD);
}
//加载详情
function loadDetail(id, info_detail) {
    $.getJSON(URL.hotel_detail, {
        id : id
    }, function(hotel_detail) {
        if (hotel_detail == null) {
            info_detail.text("没有适合的房型");
        } else {
            var description = hotel_detail.hotel_description;
            info_detail.text(substring(description, 130));
        }
    })
}
//总页数
function getPageTotal() {
    var page_total = (hotel_query_list.length / page_size) + (hotel_query_list.length % page_size > 0 ? 1 : 0);
    return page_total;
}
//字段省略
function substring(text, size) {
    return text.length > size ? (text.substring(0, size) + '...') : text;
}
//分页
function getByPage(page) {
    var _hotels = [];
    if (page <= getPageTotal() && page > 0) {
        var begin = (page - 1) * page_size;
        var end = begin + page_size;
        for ( var i = begin; i < end; i++) {
            if (i < hotel_query_list.length) {
                _hotels.push(hotel_query_list[i]);
            } else {
                break;
            }
        }
    }
    return _hotels;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值