//Author:fuhc //Date:20160927 var hotel_id=''; var room_name=''; var room_type=''; var start_date='' var end_date=''; var hotel_name=''; window.onload=function(){ hotel_id=getPar('hotel_id'); start_date=getPar('start_date'); room_name=getPar('room_name' ); room_type=getPar('room_type'); hotel_name=getPar('hotel_name'); end_date=getDateByDay(7,start_date); $('.start_date_all,.start_date').val(start_date); $('.end_date_all,.end_date').val(end_date); $('.room').children().eq(0).text(room_name); $('.room').attr('data-room-type',room_type); } // 添加行 var $tempTR=null; function addrow(selfOBJ) { var $selfOBJ=$(selfOBJ); var $tr_parent=$selfOBJ.closest('tr'); var new_tr=document.createElement('tr'); var new_tr_className=$tr_parent.attr('class')+$tr_parent.data('room-type'); new_tr.className=new_tr_className; $tempTR=$('.'+new_tr_className.split(' ')[1]+':last'); var newHTML=''; var tempHTML=$('.room_child').prop('outerHTML'); if(!$tempTR.html()){ $tr_parent.after(new_tr); }else{ $tempTR.after(new_tr); } // tempHTML=tempHTML.replace('[start_value]',''); // tempHTML=tempHTML.replace('[end_value]',''); tempHTML=tempHTML.replace('[start_value]',$('.start_date_all').val()); tempHTML=tempHTML.replace('[end_value]',$('.end_date_all').val()); new_tr.innerHTML=tempHTML; } // 删除行 function delrow(selfOBJ){ var $selfOBJ=$(selfOBJ); var $tr_parent=$selfOBJ.closest('tr'); $tr_parent.prop('outerHTML',''); } // 星期 的点击事件 function aceClick(selfOBJ){ var className=$(selfOBJ).attr('class'); ZZLog(className); var flag=selfOBJ.checked; if(className.indexOf('allweekall')>=0){ $('.ace').prop('checked',flag); $('.ace').attr('checked',flag); }else if(className.indexOf('week1all')>=0){ $('.week1').prop('checked',flag); $('.week1').attr('checked',flag); }else if(className.indexOf('week2all')>=0){ $('.week2').prop('checked',flag); $('.week2').attr('checked',flag); }else if(className.indexOf('week3all')>=0){ $('.week3').prop('checked',flag); $('.week3').attr('checked',flag); }else if(className.indexOf('week4all')>=0){ $('.week4').prop('checked',flag); $('.week4').attr('checked',flag); }else if(className.indexOf('week5all')>=0){ $('.week5').prop('checked',flag); $('.week5').attr('checked',flag); }else if(className.indexOf('week6all')>=0){ $('.week6').prop('checked',flag); $('.week6').attr('checked',flag); }else if(className.indexOf('week7all')>=0){ $('.week7').prop('checked',flag); $('.week7').attr('checked',flag); }else if(className.indexOf('allweek')>=0){ $(selfOBJ).closest('td').find('input').prop('checked',flag); $(selfOBJ).closest('td').find('input').attr('checked',flag); }else if(className.indexOf('week')>=0){ var newName=className.split(' ')[1]; var tCol=[]; $('.'+newName).each(function(i,dom){ tCol.push(dom.checked); }) if(tCol.indexOf(false)!=-1){ $('.'+newName+'all').attr('checked',false); $('.'+newName+'all').prop('checked',false); }else{ $('.'+newName+'all').attr('checked',true); $('.'+newName+'all').prop('checked',true); } } var tAll=[]; updateFirstCheck(); function updateFirstCheck(){ $('.ace:gt(0)').each(function(i,dom){ tAll.push(dom.checked); }); if(tAll.indexOf(false)!=-1){ $('.allweekall').attr('checked',false); $('.allweekall').prop('checked',false); }else{ $('.allweekall').attr('checked',true); $('.allweekall').prop('checked',true); } } } // 批量改日期的日期选择改变事件 function changeStartDateAll(){ var curdate=$('.start_date_all').val(); $('.start_date').val(curdate); $('.end_date_all').focus(); } function changeEndDateAll(){ var curdate=$('.end_date_all').val(); $('.end_date').val(curdate); } // 批量改库存 $(document).ready(function () { $(".maiduan_count_all").bind('input', function () { $('.maiduan_count').val($(this).val()); }) $(".baoliu_count_all").bind('input', function () { $('.baoliu_count').val($(this).val()); }) $(".xianxun_count_all").bind('input', function () { $('.xianxun_count').val($(this).val()); }) }) $(document).ready(function () { $('#btnSave').bind('click', function () { clickSave(); }); document.onkeydown = function (e) { var ev = document.all ? window.event : e; if (ev.keyCode == 13) { clickSave(); } } }) function clickSave() { var cstr = ''; var flag = true; for (var i = 0, m = $('.real_tr').length; i < m; i++) { var room_type = $('.real_tr').eq(0).attr('data-room-type'); var start_date = $('.real_tr').eq(i).find('.start_date').val(); var end_date = $('.real_tr').eq(i).find('.end_date').val(); var weekDay = ''; $('.real_tr').eq(i).find('.aday').each(function (index, domEle) { if (domEle.checked) { weekDay += $(this).val(); } }); //买断 var maiduan_count = $('.real_tr').eq(i).find('.maiduan_count').val(); var baoliu_count = $('.real_tr').eq(i).find('.baoliu_count').val(); var xianxun_count = $('.real_tr').eq(i).find('.xianxun_count').val(); if(room_type==''||start_date==''||end_date==''){ ZZAlertInfo('请输入完整!'); return; } var baoliu_cstr = "{" + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + '230' + "," + baoliu_count + "}"; var maiduan_cstr = "{" + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + '228' + "," + maiduan_count + "}"; var xianxun_cstr = "{" + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + '229' + "," + xianxun_count + "}"; baoliu_cstr = baoliu_count == '' ? '' : baoliu_cstr; maiduan_cstr = maiduan_count == '' ? '' : maiduan_cstr; xianxun_cstr = xianxun_count == '' ? '' : xianxun_cstr; //最终数组 cstr += baoliu_cstr + maiduan_cstr + xianxun_cstr; flag = true; } if (flag) { if ($('#btnSave').text() == '保存中') { return; } $('#btnSave').text('保存中'); $('#btnSave').css('background', 'darkgray'); var urlapi = base_api; var param = { type: "room_base_SetBaseRoom", op: "AddBaseRoom", hotel_id: hotel_id, room_info: cstr }; ZZLog(urlapi + JSON.stringify(param)); $.ajax({ url: urlapi, data: param, type: "post", dataType: "json", success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']); $('#btnSave').text('保存'); $('#btnSave').css('background', '#428bca!important'); } else { // history.go(-1); window.location.href = "room_info.html?hotel_id=" + hotel_id + "&hotel_name=" + hotel_name; } }, error: function (msg) { } }) } } function isEmpty(str){ if(str.trim()==""){ return true; }else{ return false; } } function isEmptyByArr(varArr){ var arr=[]; for(var i=0;i