/** * Created by luocj on 2016/9/28. */ var tr_list = ''; var current = '1'; var page_size = '25'; var key_word = ''; var url = ''; var room_name = ''; window.onload = function () { tr_list = $('.tr_list').prop('outerHTML');//获取tr中所有的字符串 url = base_api; ZZLog(url); getProductList() }; //得到产品列表 function getProductList() { loading(); ZZLog(url + JSON.stringify({ type: "order_ChooseProduct", key_word: key_word, room_name:room_name })); $.ajax({ url: url, type: "post", data: { type: "order_ChooseProduct", key_word: key_word, room_name: room_name, current: current, page_size: page_size }, dataType: "json", success: function (res_data) { ZZLog(res_data); //进行页面替换 setHTML(res_data); if (res_data['total_count'] < 1) { $('.pageDiv').hide(); } else { $(".pageDiv").createPage({ pageCount: res_data['total_page'],//总页数 current: current,//当前页 turndown: 'true',//是否显示跳转框,显示为true,不现实为false,一定记得加上引号... backFn: function (p) { current = p; //调用分页函数 havePageData(); } }); $('.pageDiv').show(); closeLoading(); } }, error: function (e) { ZZLog(e); } }) } //页面替换函数 function setHTML(data) { var product_list = data['product_list']; var sumHTML = ''; var firstHotelName = ''; if (product_list.length > 0) { firstHotelName = product_list[0]['hotel_name']; } for (var i = 0; i < product_list.length; i++) { var dict = product_list[i]; var HTML = tr_list; if (i == 0) { HTML = HTML.replace('[酒店名称]', dict['hotel_name']); HTML = HTML.replace('[最早入住时间]', dict['earliest_checkin_time'] ? dict['earliest_checkin_time'] : '不限'); HTML = HTML.replace('[供应商]', dict['supplier_name']); } else { if (firstHotelName != dict['hotel_name']) { HTML = HTML.replace('[酒店名称]', dict['hotel_name']); HTML = HTML.replace('[最早入住时间]', dict['earliest_checkin_time'] ? dict['earliest_checkin_time'] : '不限'); HTML = HTML.replace('[供应商]', dict['supplier_name']); } else { HTML = HTML.replace('[酒店名称]', ''); HTML = HTML.replace('[最早入住时间]', ''); HTML = HTML.replace('[供应商]',''); } } firstHotelName = dict['hotel_name']; HTML = HTML.replace('[产品名称]', dict['room_name']); HTML = HTML.replace('[预订]', '预订'); HTML = HTML.replace('[hotel_id]', dict['hotel_id']); HTML = HTML.replace('[hotel_name]', dict['hotel_name']); HTML = HTML.replace('[product_name]', dict['room_name']); HTML = HTML.replace('[room_type]', dict['room_type']); HTML = HTML.replace('[parent_room_type]', dict['parent_room_type']); sumHTML += HTML; } $('#product_list').html(sumHTML); $('#product_list').show(); } function searchProduct() { key_word = $('#key_word').val(); room_name = $('#room_name').val(); // url = base_api + "?type=order_ChooseProduct&key_word='" + key_word; current = 1; getProductList(); } function havePageData() { $.ajax({ url: url, type: "post", data: { type: "order_ChooseProduct", key_word: key_word, room_name:room_name, current: current, page_size: page_size }, dataType: "json", success: function (res_data) { ZZLog(res_data); setHTML(res_data); }, error: function (e) { ZZLog(e); } }) }