You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

249 lines
7.4 KiB

  1. //Author:fuhc
  2. //Date:20160927
  3. var hotel_id='';
  4. var room_name='';
  5. var room_type='';
  6. var start_date=''
  7. var end_date='';
  8. var hotel_name='';
  9. window.onload=function(){
  10. hotel_id=getPar('hotel_id');
  11. start_date=getPar('start_date');
  12. room_name=getPar('room_name' );
  13. room_type=getPar('room_type');
  14. hotel_name=getPar('hotel_name');
  15. end_date=getDateByDay(7,start_date);
  16. $('.start_date_all,.start_date').val(start_date);
  17. $('.end_date_all,.end_date').val(end_date);
  18. $('.room').children().eq(0).text(room_name);
  19. $('.room').attr('data-room-type',room_type);
  20. }
  21. // 添加行
  22. var $tempTR=null;
  23. function addrow(selfOBJ)
  24. {
  25. var $selfOBJ=$(selfOBJ);
  26. var $tr_parent=$selfOBJ.closest('tr');
  27. var new_tr=document.createElement('tr');
  28. var new_tr_className=$tr_parent.attr('class')+$tr_parent.data('room-type');
  29. new_tr.className=new_tr_className;
  30. $tempTR=$('.'+new_tr_className.split(' ')[1]+':last');
  31. var newHTML='';
  32. var tempHTML=$('.room_child').prop('outerHTML');
  33. if(!$tempTR.html()){
  34. $tr_parent.after(new_tr);
  35. }else{
  36. $tempTR.after(new_tr);
  37. }
  38. // tempHTML=tempHTML.replace('[start_value]','');
  39. // tempHTML=tempHTML.replace('[end_value]','');
  40. tempHTML=tempHTML.replace('[start_value]',$('.start_date_all').val());
  41. tempHTML=tempHTML.replace('[end_value]',$('.end_date_all').val());
  42. new_tr.innerHTML=tempHTML;
  43. }
  44. // 删除行
  45. function delrow(selfOBJ){
  46. var $selfOBJ=$(selfOBJ);
  47. var $tr_parent=$selfOBJ.closest('tr');
  48. $tr_parent.prop('outerHTML','');
  49. }
  50. // 星期 的点击事件
  51. function aceClick(selfOBJ){
  52. var className=$(selfOBJ).attr('class');
  53. ZZLog(className);
  54. var flag=selfOBJ.checked;
  55. if(className.indexOf('allweekall')>=0){
  56. $('.ace').prop('checked',flag);
  57. $('.ace').attr('checked',flag);
  58. }else if(className.indexOf('week1all')>=0){
  59. $('.week1').prop('checked',flag);
  60. $('.week1').attr('checked',flag);
  61. }else if(className.indexOf('week2all')>=0){
  62. $('.week2').prop('checked',flag);
  63. $('.week2').attr('checked',flag);
  64. }else if(className.indexOf('week3all')>=0){
  65. $('.week3').prop('checked',flag);
  66. $('.week3').attr('checked',flag);
  67. }else if(className.indexOf('week4all')>=0){
  68. $('.week4').prop('checked',flag);
  69. $('.week4').attr('checked',flag);
  70. }else if(className.indexOf('week5all')>=0){
  71. $('.week5').prop('checked',flag);
  72. $('.week5').attr('checked',flag);
  73. }else if(className.indexOf('week6all')>=0){
  74. $('.week6').prop('checked',flag);
  75. $('.week6').attr('checked',flag);
  76. }else if(className.indexOf('week7all')>=0){
  77. $('.week7').prop('checked',flag);
  78. $('.week7').attr('checked',flag);
  79. }else if(className.indexOf('allweek')>=0){
  80. $(selfOBJ).closest('td').find('input').prop('checked',flag);
  81. $(selfOBJ).closest('td').find('input').attr('checked',flag);
  82. }else if(className.indexOf('week')>=0){
  83. var newName=className.split(' ')[1];
  84. var tCol=[];
  85. $('.'+newName).each(function(i,dom){
  86. tCol.push(dom.checked);
  87. })
  88. if(tCol.indexOf(false)!=-1){
  89. $('.'+newName+'all').attr('checked',false);
  90. $('.'+newName+'all').prop('checked',false);
  91. }else{
  92. $('.'+newName+'all').attr('checked',true);
  93. $('.'+newName+'all').prop('checked',true);
  94. }
  95. }
  96. var tAll=[];
  97. updateFirstCheck();
  98. function updateFirstCheck(){
  99. $('.ace:gt(0)').each(function(i,dom){
  100. tAll.push(dom.checked);
  101. });
  102. if(tAll.indexOf(false)!=-1){
  103. $('.allweekall').attr('checked',false);
  104. $('.allweekall').prop('checked',false);
  105. }else{
  106. $('.allweekall').attr('checked',true);
  107. $('.allweekall').prop('checked',true);
  108. }
  109. }
  110. }
  111. // 批量改日期的日期选择改变事件
  112. function changeStartDateAll(){
  113. var curdate=$('.start_date_all').val();
  114. $('.start_date').val(curdate);
  115. $('.end_date_all').focus();
  116. }
  117. function changeEndDateAll(){
  118. var curdate=$('.end_date_all').val();
  119. $('.end_date').val(curdate);
  120. }
  121. // 批量改库存
  122. $(document).ready(function () {
  123. $(".maiduan_count_all").bind('input', function () {
  124. $('.maiduan_count').val($(this).val());
  125. })
  126. $(".baoliu_count_all").bind('input', function () {
  127. $('.baoliu_count').val($(this).val());
  128. })
  129. $(".xianxun_count_all").bind('input', function () {
  130. $('.xianxun_count').val($(this).val());
  131. })
  132. })
  133. $(document).ready(function () {
  134. $('#btnSave').bind('click', function () {
  135. clickSave();
  136. });
  137. document.onkeydown = function (e) {
  138. var ev = document.all ? window.event : e;
  139. if (ev.keyCode == 13) {
  140. clickSave();
  141. }
  142. }
  143. })
  144. function clickSave() {
  145. var cstr = '';
  146. var flag = true;
  147. for (var i = 0, m = $('.real_tr').length; i < m; i++) {
  148. var room_type = $('.real_tr').eq(0).attr('data-room-type');
  149. var start_date = $('.real_tr').eq(i).find('.start_date').val();
  150. var end_date = $('.real_tr').eq(i).find('.end_date').val();
  151. var weekDay = '';
  152. $('.real_tr').eq(i).find('.aday').each(function (index, domEle) {
  153. if (domEle.checked) {
  154. weekDay += $(this).val();
  155. }
  156. });
  157. //买断
  158. var maiduan_count = $('.real_tr').eq(i).find('.maiduan_count').val();
  159. var baoliu_count = $('.real_tr').eq(i).find('.baoliu_count').val();
  160. var xianxun_count = $('.real_tr').eq(i).find('.xianxun_count').val();
  161. if(room_type==''||start_date==''||end_date==''){
  162. ZZAlertInfo('请输入完整!');
  163. return;
  164. }
  165. var baoliu_cstr = "{" + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + '230' + "," + baoliu_count + "}";
  166. var maiduan_cstr = "{" + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + '228' + "," + maiduan_count + "}";
  167. var xianxun_cstr = "{" + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + '229' + "," + xianxun_count + "}";
  168. baoliu_cstr = baoliu_count == '' ? '' : baoliu_cstr;
  169. maiduan_cstr = maiduan_count == '' ? '' : maiduan_cstr;
  170. xianxun_cstr = xianxun_count == '' ? '' : xianxun_cstr;
  171. //最终数组
  172. cstr += baoliu_cstr + maiduan_cstr + xianxun_cstr;
  173. flag = true;
  174. }
  175. if (flag) {
  176. if ($('#btnSave').text() == '保存中') {
  177. return;
  178. }
  179. $('#btnSave').text('保存中');
  180. $('#btnSave').css('background', 'darkgray');
  181. var urlapi = base_api;
  182. var param = {
  183. type: "room_base_SetBaseRoom",
  184. op: "AddBaseRoom",
  185. hotel_id: hotel_id,
  186. room_info: cstr
  187. };
  188. ZZLog(urlapi + JSON.stringify(param));
  189. $.ajax({
  190. url: urlapi,
  191. data: param,
  192. type: "post",
  193. dataType: "json",
  194. success: function (res_data) {
  195. ZZLog(res_data);
  196. if (res_data['code'] != "0") {
  197. alert(res_data['info']);
  198. $('#btnSave').text('保存');
  199. $('#btnSave').css('background', '#428bca!important');
  200. } else {
  201. // history.go(-1);
  202. window.location.href = "room_info.html?hotel_id=" + hotel_id + "&hotel_name=" + hotel_name;
  203. }
  204. },
  205. error: function (msg) {
  206. }
  207. })
  208. }
  209. }
  210. function isEmpty(str){
  211. if(str.trim()==""){
  212. return true;
  213. }else{
  214. return false;
  215. }
  216. }
  217. function isEmptyByArr(varArr){
  218. var arr=[];
  219. for(var i=0;i<varArr.length;i++){
  220. if(varArr[i]){
  221. if(varArr[i].trim()==""){
  222. return true;
  223. }else{
  224. arr.push(false);
  225. }
  226. }else{
  227. arr.push(false);
  228. }
  229. }
  230. if(arr.indexOf(false)!=-1){
  231. return false;
  232. }
  233. }