/** * Created by luocj on 2016/10/29. */ var data_tr = $('.data-tr').prop('outerHTML'); var current = '1'; var page_size = '15'; var hotel_name = ''; window.onload = function () { addNewHotel(); getHotelList(); checkBox(); }; function addNewHotel() { $('#add_new_hotel').bind('click', function () { window.location.href = 'add_new_hotel.html'; }) } function checkBox() { $('.check_box_main').bind('click', function () { if ($('.check_box_main').is(':checked')) { $("input[name='check_box_child']").prop("checked", true); } else { $("input[name='check_box_child']").removeAttr("checked", true); } //取值 $('.check_box').each(function () { var status = $(this).is(':checked') }) }); $('.check_box').bind('click', function () { if ($("input[name='check_box_child']").not("input:checked").size() <= 0) { $('.check_box_main').prop("checked", true); } else { $('.check_box_main').prop("checked", false); } }) } function getHotelList() { hotel_name = $('#hotel_name').val(); var param = { op: '1', type: 'hotel_HotelList', hotel_name: hotel_name, current: current, page_size: page_size }; $.ajax({ url: base_api, data: param, type: "post", dataType: "json", success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']); } setDataBody(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(); } }, error: function (error) { alert('system ajax http error'); ZZLog(error); } }) } function setDataBody(res_data) { var sumHTML = ''; for (var i = 0; i < res_data['hotel_list'].length; i++) { var dict = res_data['hotel_list'][i]; var HTML = data_tr; HTML = HTML.replace('', '') HTML = HTML.replace('[酒店名称]', dict['hotel_name']); if (null != dict['type_name']) { HTML = HTML.replace('[星级]', dict['type_name']); } else { HTML = HTML.replace('[星级]', '暂无'); } if (null != dict['area_name']) { HTML = HTML.replace('[城市]', dict['parent_area_name'] + dict['area_name']); } else { HTML = HTML.replace('[城市]', '暂无'); } if (null != dict['hotel_address']) { HTML = HTML.replace('[地址]', dict['hotel_address']); } else { HTML = HTML.replace('[地址]', '暂无'); } // if (1 == dict['hotel_status']) { // HTML = HTML.replace('[状态]', '在售'); // } else { // HTML = HTML.replace('[状态]', '停售'); // } HTML = HTML.replace('[操作]', '修改'); sumHTML += HTML; } $('#data-tbody').html(sumHTML); $('#data-tbody').show() } function change_hotel_status_ts(obj) { var data_hotel_id = $(obj).closest('tr').attr('data-hotel-id'); var param = { op: '2', type: 'hotel_HotelList', id: data_hotel_id } $.ajax({ data: param, url: base_api, dataType: 'json', type: 'post', success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']); } getHotelList() }, error: function (error) { alert('system ajax http error'); ZZLog(error); } }) } function change_hotel_status_zs(obj) { var data_hotel_id = $(obj).closest('tr').attr('data-hotel-id'); var param = { op: '3', type: 'hotel_HotelList', id: data_hotel_id } $.ajax({ data: param, url: base_api, dataType: 'json', type: 'post', success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']); } getHotelList() }, error: function (error) { alert('system ajax http error'); ZZLog(error); } }) } //批量将在售改为停售 function batch_change_status(value) { var check_value = []; $('input[name="check_box_child"]:checked').each(function () { check_value.push($(this).closest('tr').attr('data-hotel-id')); }); var check_hotel_id = check_value.join(","); var param = { op: value, type: 'hotel_HotelList', id: check_hotel_id } $.ajax({ type: 'post', dataType: 'json', data: param, url: base_api, success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']) } ; getHotelList(); }, error: function (error) { alert('system ajax http error'); ZZLog(error); } }) } //管理跳至修改酒店 function to_modifty(obj) { var hotel_id = $(obj).closest('tr').attr('data-hotel-id'); var hotel_name = $(obj).closest('tr').children().eq(1).text(); window.location.href = 'modify_hotel_info.html?hotel_id=' + hotel_id + '&hotel_name=' + hotel_name; } function havePageData() { var param = { op: '1', type: 'hotel_HotelList', hotel_name: hotel_name, current: current, page_size: page_size }; $.ajax({ data: param, dataType: 'json', type: 'post', url: base_api, success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']) } setDataBody(res_data); }, error: function (error) { alert('system ajax http error'); ZZLog(error); } }) }