/** * Created by luocj on 2016/10/24. */ var hotel_id = ''; var room_id = ''; var trHTML = ''; var trinnerHTML = ''; var start_date = ''; var end_date = ''; var hotel_name = ''; window.onload = function () { hotel_id = getPar('hotel_id'); hotel_name = getPar('hotel_name'); room_type = getPar('ids'); start_date = getPar('start_date'); end_date = getDateByDay(6, start_date); trHTML = $('.real_tr').prop('outerHTML'); $('.room_child').show(); trinnerHTML = $('.room_child').html(); $('.room_child').hide(); $('#start_date_all').val(start_date); $('#end_date_all').val(end_date); getRoomList() }; //获取子房型 function getRoomList() { var param = { op: 'getRoom', type: 'room_HTModifyPrice', hotel_id: hotel_id, room_type: room_type } $.ajax({ url: base_api, type: 'post', dataType: 'json', data: param, success: function (res_data) { ZZLog(res_data); if (res_data['code'] != "0") { alert(res_data['info']); } var all_info = res_data; roomList(all_info) }, error: function () { ZZLog('出错'); } } ) } //显示列表 function roomList(data) { var sumHTML = ''; var tr = trHTML; for (var i = 0; i < data['room_list'].length; i++) { var dict = data['room_list'][i]; var HTML = tr; HTML = HTML.replace('[子房型]', '' + dict['room_name'] + ''); HTML = HTML.replace('data-room-type=""', 'data-room-type="' + dict['room_type'] + '"'); HTML = HTML.replace('data-parent-room-type=""', 'data-parent-room-type="' + dict['parent_room_type'] + '"') HTML = HTML.replace('[start_value]', $('.start_date_all').val()); HTML = HTML.replace('[end_value]', $('.end_date_all').val()); sumHTML += HTML; } $('#tbody').html(sumHTML); } // 批量改日期的日期选择改变事件 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); } // 星期 的点击事件 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); } } } // 添加行 var $tempTR = null; function addrow(obj) { var tr_parent = $(obj).closest('tr'); var new_tr = document.createElement('tr'); var new_tr_className = $(tr_parent).attr('class') + $(tr_parent).attr('data-room-type'); new_tr.className = new_tr_className; $(new_tr).attr('data-room-type', $(tr_parent).attr('data-room-type')); $(new_tr).attr('data-parent-room-type', $(tr_parent).attr('data-parent-room-type')); // method 1 $tempTR = $('.' + new_tr_className.split(' ')[1] + ':last'); if (!$tempTR.html()) { tr_parent.after(new_tr); } else { $tempTR.after(new_tr); } var newHTML = trinnerHTML; newHTML = newHTML.replace('[start_value]', $('.start_date_all').val()); newHTML = newHTML.replace('[end_value]', $('.end_date_all').val()); newHTML = newHTML.replace('class="image_class_temp"','class="image_class"') new_tr.innerHTML = newHTML; // method 2 // $tempTR = tr_parent; // $tempTR.after(new_tr); // new_tr.innerHTML = newHTML; // $tempTR = $(new_tr); } // 删除行 function delrow(selfOBJ) { var $selfOBJ = $(selfOBJ); var $tr_parent = $selfOBJ.closest('tr'); $tr_parent.prop('outerHTML', ''); } //修改采购价 $(document).ready(function () { $(".base_price_all").bind('input', function () { $('.base_price').val($(this).val()); }) }) function clickSave() { var cstr = ''; var user_id = '1'; var flag = true; var para_flag = '1';//批量改房态标志 for (var i = 0, m = $('.real_tr').length; i < m; i++) { var parent_room_type = $('.real_tr').eq(i).attr('data-parent-room-type'); var room_type = $('.real_tr').eq(i).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 is_open = $('.real_tr').eq(i).find('.image_class').attr('isopen'); var flag = isEmptyByArr([parent_room_type,room_type, start_date, end_date, weekDay,is_open]); if (flag) { alert('请选择完整'); flag = false; break; } else { cstr += "{" + parent_room_type + ",\"" + room_type + "\",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + is_open +"}"; flag = true; } } ZZLog(cstr); if (flag) { if ($('#btnSave').text() == '保存中') { return; } $('#btnSave').text('保存中'); $('#btnSave').css('background', 'darkgray'); var urlapi = base_api; var param = { type: "room_HTModifyPrice", op: "up_base_price", user_id: user_id, hotel_id: hotel_id, para_flag: para_flag, hotel_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+ "&start_date="+ getPar('start_date')+ "&date_flag=1"; } } }) } } function isEmpty(str) { if (str.trim() == "") { return true; } else { return false; } } function isEmptyByArr(varArr) { var arr = []; for (var i = 0; i < varArr.length; i++) { if (varArr[i].trim() == "") { return true; } else { arr.push(false); } } if (arr.indexOf(false) != -1) { return false; } } //批量开关按钮 function image_onclick_all(obj) { var is_open_all = $('.image_class_all').attr('isopen'); is_open_all = is_open_all == 0 ? 1 : 0; if (is_open_all == "0") { $('.image_class').attr('src', 'images/OffSwitch.png'); $('.image_class').attr('isopen', 0); $('.image_class_all').attr('src', 'images/OffSwitch.png'); } else { $('.image_class').attr('src', 'images/OnSwitch.png'); $('.image_class').attr('isopen', 1); $('.image_class_all').attr('src', 'images/OnSwitch.png'); } $('.image_class_all').attr('isopen', is_open_all); } //单个开关按钮 function image_onclick(obj) { var is_open = $(obj).attr("isopen"); is_open = is_open == 0 ? 1 : 0; if(is_open =="0"){ $(obj).attr('src','images/OffSwitch.png'); }else { $(obj).attr('src','images/OnSwitch.png'); } $(obj).attr("isopen",is_open); //批量改状态 var arr=[]; var arr1=[]; var count=$('.image_class').length; $('.image_class').each(function (index,dom) { var is_open = $(this).attr('isopen'); if(is_open==0){ arr.push(is_open); }else if (is_open ==1){ arr1.push(is_open); } }); if(arr.length==count){ $('.image_class_all').attr('src', 'images/OffSwitch.png'); $('.image_class_all').attr('isopen',0) }else if(arr1.length==count) { $('.image_class_all').attr('src', 'images/OnSwitch.png'); $('.image_class_all').attr('isopen',1) } }