//Author:fuhc
//Date:20160909
//酒店产品列表
//
// //param
// var area_id = '';
// var hotel_name = '';
// var hotel_status = '1';
// var page_size = 10; //每页条数
// var current = 1;
//
//
// window.onload = function () {
//
// current = 1;
// havePageData();
// chooseProvince();
// chooseCity();
// }
// function havePageData() {
// var url = base_api + "?type=hotel_HotelProductList&area_id=" + area_id + "&hotel_name=" + hotel_name + "&hotel_status=" + hotel_status + "¤t=" + current + "&page_size=" + page_size;
// ZZLog(url);
// $.getJSON(url, function (res_data) {
// ZZLog(res_data);
// if (res_data['code'] != "0") {
// alert(res_data['info']);
// } else {
// var hotel_list = res_data['hotel_list'];
// setHotelList(hotel_list);
// if (res_data['total'] <= 0) {
// $('.pageDiv').hide();
// } else {
//
// $(".pageDiv").createPage({
// pageCount: res_data['total_page'],//总页数
// current: current,//当前页
// turndown: 'true',//是否显示跳转框,显示为true,不现实为false,一定记得加上引号...
// backFn: function (p) {
// current = p;
// havePageData();
// }
// });
// $('.pageDiv').show();
// }
// }
// })
// }
// function setHotelList(hotel_list) {
// //酒店列表
// var HTHTML = '';
// for (var i = 0, m = hotel_list.length; i < m; i++) {
// var tempDict = hotel_list[i];
// var tempHTML = hotelHTML;
// tempHTML = tempHTML.replace(/\[hotel-id]/g, tempDict['hotel_id']);
// tempHTML = tempHTML.replace('[酒店名称]', tempDict['hotel_name']);
// tempHTML = tempHTML.replace('[城市]', tempDict['area_name'] != "" ? tempDict['area_name'] : "-");
// tempHTML = tempHTML.replace('[供应商]', tempDict['supplier_name'] != "" ? tempDict['supplier_name'] : "-");
// tempHTML = tempHTML.replace('[采购负责人]', tempDict['cai_people'] != "" ? tempDict['cai_people'] : "-");
// tempHTML = tempHTML.replace('[售卖状态]', tempDict['hotel_status_str']);
// var cstr = '房型'
// + '修改';
// tempHTML = tempHTML.replace('[操作]', cstr);
// HTHTML += tempHTML;
// }
// if (HTHTML) {
// $('#hotel_list').html(HTHTML);
// linkToUpdate();
// } else {
// $('#hotel_list').html("");
// }
// }
// function linkToUpdate() {
// //跳到修改酒店产品页面
// $('.update_hotel_product').bind('click', function () {
// var hotel_id = $(this).closest('tr').attr('hotel-id');
// var hotel_name = $(this).closest('tr').children().eq(1).text();
// var listURL = "update_hotel_product.html?hotel_id=" + hotel_id + "&hotel_name=" + hotel_name;
// listURL = encodeURI(listURL);
// window.location.href = listURL;
// })
// }
// $(document).ready(function () {
// $('#search').bind('click', function () {
// //获取条件信息
// var province = $('#province').val();
// var city = $('#city').val();
// var hotel_name = $('#hotel_name').val();
// var hotel_status = $('#hotel_status').val();
// var area_id = city != 0 ? city : province;
// if (hotel_status == "") {
// alert('请选择售卖状态!');
// return;
// }
// var url = base_api + "?type=hotel_HotelProductList&area_id=" + area_id + "&hotel_name=" + hotel_name + "&hotel_status=" + hotel_status + "¤t=1&page_size=" + page_size;
// ZZLog(url);
// $.getJSON(url, function (res_data) {
// ZZLog(res_data);
// if (res_data['code'] != "0") {
// alert(res_data['info']);
// } else {
// var hotel_list = res_data['hotel_list'];
// setHotelList(hotel_list);
// }
// });
// })
// // 添加酒店跳转链接
// $('#add').bind('click', function () {
// var listURL = "add_hotel_product.html";
// listURL = encodeURI(listURL);
// window.open(listURL);
// })
//
//
// });
var provinceHTML = ''; //省HTML
var cityHTML = ''; //市HTML
var hotelHTML = ''; //酒店列表HTML
var area_id = '';
var hotel_name = '';
var hotel_status = '';
var current = '1';
var page_size = '15';
window.onload = function () {
provinceHTML = $('#province').html();
cityHTML = $('#city').html();
hotelHTML = $('#hotel_list').html();
chooseProvince();
chooseCity();
current = '1';
getHotelList();
addNewHP();
search();
checkBox();
}
//选择省
function chooseProvince() {
provinceHTML = $('#province').html();
cityHTML = $('#city').html();
var apiurl = base_api + "?type=hotel_AddHotelProduct&op=provinceCity &area_id=";
ZZLog(apiurl);
$.getJSON(apiurl, function (res_data) {
ZZLog(res_data);
if (res_data['code'] != "0") {
alert(res_data['info']);
} else {
//地区
var area_list = res_data['area_list'];
var areaHTML = '';
for (var i = 0, m = area_list.length; i < m; i++) {
var tempDict = area_list[i];
var tempHTML = provinceHTML;
tempHTML = tempHTML.replace('选择省', tempDict['area_name']);
tempHTML = tempHTML.replace('0', tempDict['area_id']);
areaHTML += tempHTML;
}
if (areaHTML) {
$('#province').html(areaHTML);
$('#province')[0].selectedIndex = 0;
}
}
})
}
//选择市
function chooseCity() {
$('#province').bind('change', function () {
var area_id = $(this).val();
if (area_id == "0" || area_id == "") {
$('#city').html(cityHTML);
return;
}
var url = base_api + "?type=hotel_AddHotelProduct&op=provinceCity&area_id=" + area_id;
ZZLog(url);
$.getJSON(url, function (res_data) {
ZZLog(res_data);
if (res_data['code'] != "0") {
alert(res_data['info']);
} else {
//地区
var area_list = res_data['area_list'];
var areaHTML = '';
for (var i = 0, m = area_list.length; i < m; i++) {
var tempDict = area_list[i];
var tempHTML = cityHTML;
tempHTML = tempHTML.replace('选择市', tempDict['area_name']);
tempHTML = tempHTML.replace('0', tempDict['area_id']);
areaHTML += tempHTML;
}
if (areaHTML) {
$('#city').html(areaHTML);
$('#city')[0].selectedIndex = 0;
}
}
})
});
}
//得酒店信息
function getHotelList() {
var url = base_api + "?type=hotel_HotelProductList&area_id=" + area_id + "&hotel_name=" + hotel_name + "&hotel_status=" + hotel_status + "¤t=" + current + "&page_size=" + page_size;
ZZLog(url);
$.getJSON(url, function (res_data) {
ZZLog(res_data);
if (res_data['code'] != "0") {
alert(res_data['info']);
} else {
//酒店列表
var HTHTML = '';
for (var i = 0; i < res_data['hotel_list'].length; i++) {
var tempDict = res_data['hotel_list'][i];
var tempHTML = hotelHTML;
tempHTML = tempHTML.replace(/\[hotel-id]/g, tempDict['hotel_id']);
tempHTML = tempHTML.replace('[酒店名称]', tempDict['hotel_name']);
tempHTML = tempHTML.replace('[城市]', tempDict['area_name'] != "" ? tempDict['parent_area_name']+tempDict['area_name'] : "-");
tempHTML = tempHTML.replace('[供应商]', tempDict['supplier_name'] !== null ? tempDict['supplier_name'] : "-");
tempHTML = tempHTML.replace('[采购负责人]', tempDict['purchaser_name'] !== null ? tempDict['purchaser_name'] : "-");
tempHTML = tempHTML.replace('[售卖状态]', tempDict['hotel_status'] == "0" ? '停售' : '在售');
//需求修改上下架不需要房型
//'房型'
var cstr = '修改';
tempHTML = tempHTML.replace('[操作]', cstr);
HTHTML += tempHTML;
}
$('#hotel_list').html(HTHTML);
$('#hotel_list').show();
if (res_data['total'] <= 0) {
$('.pageDiv').hide();
} else {
$(".pageDiv").createPage({
pageCount: res_data['total_page'],//总页数
current: current,//当前页
turndown: 'true',//是否显示跳转框,显示为true,不现实为false,一定记得加上引号...
backFn: function (p) {
current = p;
getHotelList();
}
});
$('.pageDiv').show();
}
}
}).error(function(jqXHR, textStatus, errorThrown) {
console.log("error " + textStatus);
console.log("incoming Text " + jqXHR.responseText);
})
}
function search() {
$('#search').bind('click', function () {
//获取条件信息
var province = $('#province').val();
var city = $('#city').val();
hotel_name = $('#hotel_name').val();
hotel_status = $('#hotel_status').val();
area_id = city != 0 ? city : province;
if (hotel_status == "") {
alert('请选择售卖状态!');
return;
}
if (area_id == '0') {
area_id = '';
}
current = 1;
getHotelList()
});
}
function addNewHP() {
// 添加酒店跳转链接
$('#add').bind('click', function () {
var listURL = "add_hotel_product.html";
listURL = encodeURI(listURL);
// window.open(listURL);
$.cookie("path_url",cookie_path+"zz-jd/"+listURL,{domain:domain_path,path:"/"});
window.open(system_path);
})
}
function linkToUpdate() {
//跳到修改酒店产品页面
$('.update_hotel_product').bind('click', function () {
var hotel_id = $(this).closest('tr').attr('hotel-id');
var hotel_name = $(this).closest('tr').children().eq(1).text();
var listURL = "update_hotel_product.html?hotel_id=" + hotel_id + "&hotel_name=" + hotel_name;
listURL = encodeURI(listURL);
window.location.href = listURL;
})
}
//批量将在售改为停售
function batch_change_status(value) {
var check_value = [];
$('input[name="check_box_child"]:checked').each(function () {
check_value.push($(this).closest('tr').attr('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 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);
}
})
}