|
- /**
- * 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('<td>[子房型]</td>', '<td>' + dict['room_name'] + '</td>');
- 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());
- 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 () {
- $(".maiduan_price_all").bind('input', function () {
- $('.maiduan_price').val($(this).val());
- })
- $(".baoliu_price_all").bind('input', function () {
- $('.baoliu_price').val($(this).val());
- })
- $(".xianxun_price_all").bind('input', function () {
- $('.xianxun_price').val($(this).val());
- })
- });
-
- function clickSave() {
- var cstr = '';
- var user_id = '1';
- var flag = true;
- var para_flag = '2';//批量改房价标志
- ZZLog($('.real_tr'));
- 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 maiduan_price = $('.real_tr').eq(i).find('.maiduan_price').val()?$('.real_tr').eq(i).find('.maiduan_price').val():'-1';
- var baoliu_price = $('.real_tr').eq(i).find('.baoliu_price').val()?$('.real_tr').eq(i).find('.baoliu_price').val():'-1';
- var xianxun_price = $('.real_tr').eq(i).find('.xianxun_price').val()?$('.real_tr').eq(i).find('.xianxun_price').val():'-1';
- if(parent_room_type==''||room_type==''||start_date==''||end_date==''){
- ZZAlertInfo('请输入完整!');
- return;
- }
- cstr += "{" + parent_room_type + "," + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + maiduan_price + "," + baoliu_price + "," + xianxun_price + "}";
- //最终数组
- flag = true;
- }
- 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 = [];
- ZZLog(varArr);
- 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;
- }
- }
|