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.
 
 
 
 

312 lines
10 KiB

  1. /**
  2. * Created by luocj on 2016/10/24.
  3. */
  4. var hotel_id = '';
  5. var room_id = '';
  6. var trHTML = '';
  7. var trinnerHTML = '';
  8. var start_date = '';
  9. var end_date = '';
  10. var hotel_name = '';
  11. window.onload = function () {
  12. hotel_id = getPar('hotel_id');
  13. hotel_name = getPar('hotel_name');
  14. room_type = getPar('ids');
  15. start_date = getPar('start_date');
  16. end_date = getDateByDay(6, start_date);
  17. trHTML = $('.real_tr').prop('outerHTML');
  18. $('.room_child').show();
  19. trinnerHTML = $('.room_child').html();
  20. $('.room_child').hide();
  21. $('#start_date_all').val(start_date);
  22. $('#end_date_all').val(end_date);
  23. getRoomList()
  24. };
  25. //获取子房型
  26. function getRoomList() {
  27. var param = {
  28. op: 'getRoom',
  29. type: 'room_HTModifyPrice',
  30. hotel_id: hotel_id,
  31. room_type: room_type
  32. }
  33. $.ajax({
  34. url: base_api,
  35. type: 'post',
  36. dataType: 'json',
  37. data: param,
  38. success: function (res_data) {
  39. ZZLog(res_data);
  40. if (res_data['code'] != "0") {
  41. alert(res_data['info']);
  42. }
  43. var all_info = res_data;
  44. roomList(all_info)
  45. },
  46. error: function () {
  47. ZZLog('出错');
  48. }
  49. }
  50. )
  51. }
  52. //显示列表
  53. function roomList(data) {
  54. var sumHTML = '';
  55. var tr = trHTML;
  56. for (var i = 0; i < data['room_list'].length; i++) {
  57. var dict = data['room_list'][i];
  58. var HTML = tr;
  59. HTML = HTML.replace('<td>[子房型]</td>', '<td>' + dict['room_name'] + '</td>');
  60. HTML = HTML.replace('data-room-type=""', 'data-room-type="' + dict['room_type'] + '"');
  61. HTML = HTML.replace('data-parent-room-type=""', 'data-parent-room-type="' + dict['parent_room_type'] + '"')
  62. HTML = HTML.replace('[start_value]', $('.start_date_all').val());
  63. HTML = HTML.replace('[end_value]', $('.end_date_all').val());
  64. sumHTML += HTML;
  65. }
  66. $('#tbody').html(sumHTML);
  67. }
  68. // 批量改日期的日期选择改变事件
  69. function changeStartDateAll() {
  70. var curdate = $('.start_date_all').val();
  71. $('.start_date').val(curdate);
  72. $('.end_date_all').focus();
  73. }
  74. function changeEndDateAll() {
  75. var curdate = $('.end_date_all').val();
  76. $('.end_date').val(curdate);
  77. }
  78. // 星期 的点击事件
  79. function aceClick(selfOBJ) {
  80. var className = $(selfOBJ).attr('class');
  81. ZZLog(className);
  82. var flag = selfOBJ.checked;
  83. if (className.indexOf('allweekall') >= 0) {
  84. $('.ace').prop('checked', flag);
  85. $('.ace').attr('checked', flag);
  86. } else if (className.indexOf('week1all') >= 0) {
  87. $('.week1').prop('checked', flag);
  88. $('.week1').attr('checked', flag);
  89. } else if (className.indexOf('week2all') >= 0) {
  90. $('.week2').prop('checked', flag);
  91. $('.week2').attr('checked', flag);
  92. } else if (className.indexOf('week3all') >= 0) {
  93. $('.week3').prop('checked', flag);
  94. $('.week3').attr('checked', flag);
  95. } else if (className.indexOf('week4all') >= 0) {
  96. $('.week4').prop('checked', flag);
  97. $('.week4').attr('checked', flag);
  98. } else if (className.indexOf('week5all') >= 0) {
  99. $('.week5').prop('checked', flag);
  100. $('.week5').attr('checked', flag);
  101. } else if (className.indexOf('week6all') >= 0) {
  102. $('.week6').prop('checked', flag);
  103. $('.week6').attr('checked', flag);
  104. } else if (className.indexOf('week7all') >= 0) {
  105. $('.week7').prop('checked', flag);
  106. $('.week7').attr('checked', flag);
  107. } else if (className.indexOf('allweek') >= 0) {
  108. $(selfOBJ).closest('td').find('input').prop('checked', flag);
  109. $(selfOBJ).closest('td').find('input').attr('checked', flag);
  110. } else if (className.indexOf('week') >= 0) {
  111. var newName = className.split(' ')[1];
  112. var tCol = [];
  113. $('.' + newName).each(function (i, dom) {
  114. tCol.push(dom.checked);
  115. })
  116. if (tCol.indexOf(false) != -1) {
  117. $('.' + newName + 'all').attr('checked', false);
  118. $('.' + newName + 'all').prop('checked', false);
  119. } else {
  120. $('.' + newName + 'all').attr('checked', true);
  121. $('.' + newName + 'all').prop('checked', true);
  122. }
  123. }
  124. var tAll = [];
  125. updateFirstCheck();
  126. function updateFirstCheck() {
  127. $('.ace:gt(0)').each(function (i, dom) {
  128. tAll.push(dom.checked);
  129. });
  130. if (tAll.indexOf(false) != -1) {
  131. $('.allweekall').attr('checked', false);
  132. $('.allweekall').prop('checked', false);
  133. } else {
  134. $('.allweekall').attr('checked', true);
  135. $('.allweekall').prop('checked', true);
  136. }
  137. }
  138. }
  139. // 添加行
  140. var $tempTR = null;
  141. function addrow(obj) {
  142. var tr_parent = $(obj).closest('tr');
  143. var new_tr = document.createElement('tr');
  144. var new_tr_className = $(tr_parent).attr('class') + $(tr_parent).attr('data-room-type');
  145. new_tr.className = new_tr_className;
  146. $(new_tr).attr('data-room-type', $(tr_parent).attr('data-room-type'));
  147. $(new_tr).attr('data-parent-room-type', $(tr_parent).attr('data-parent-room-type'));
  148. // method 1
  149. $tempTR = $('.' + new_tr_className.split(' ')[1] + ':last');
  150. if (!$tempTR.html()) {
  151. tr_parent.after(new_tr);
  152. } else {
  153. $tempTR.after(new_tr);
  154. }
  155. var newHTML = trinnerHTML;
  156. newHTML = newHTML.replace('[start_value]', $('.start_date_all').val());
  157. newHTML = newHTML.replace('[end_value]', $('.end_date_all').val());
  158. newHTML = newHTML.replace('class="image_class_temp"','class="image_class"')
  159. new_tr.innerHTML = newHTML;
  160. // method 2
  161. // $tempTR = tr_parent;
  162. // $tempTR.after(new_tr);
  163. // new_tr.innerHTML = newHTML;
  164. // $tempTR = $(new_tr);
  165. }
  166. // 删除行
  167. function delrow(selfOBJ) {
  168. var $selfOBJ = $(selfOBJ);
  169. var $tr_parent = $selfOBJ.closest('tr');
  170. $tr_parent.prop('outerHTML', '');
  171. }
  172. //修改采购价
  173. $(document).ready(function () {
  174. $(".base_price_all").bind('input', function () {
  175. $('.base_price').val($(this).val());
  176. })
  177. })
  178. function clickSave() {
  179. var cstr = '';
  180. var user_id = '1';
  181. var flag = true;
  182. var para_flag = '1';//批量改房态标志
  183. for (var i = 0, m = $('.real_tr').length; i < m; i++) {
  184. var parent_room_type = $('.real_tr').eq(i).attr('data-parent-room-type');
  185. var room_type = $('.real_tr').eq(i).attr('data-room-type');
  186. var start_date = $('.real_tr').eq(i).find('.start_date').val();
  187. var end_date = $('.real_tr').eq(i).find('.end_date').val();
  188. var weekDay = '';
  189. $('.real_tr').eq(i).find('.aday').each(function (index, domEle) {
  190. if (domEle.checked) {
  191. weekDay += $(this).val();
  192. }
  193. });
  194. var is_open = $('.real_tr').eq(i).find('.image_class').attr('isopen');
  195. var flag = isEmptyByArr([parent_room_type,room_type, start_date, end_date, weekDay,is_open]);
  196. if (flag) {
  197. alert('请选择完整');
  198. flag = false;
  199. break;
  200. } else {
  201. cstr += "{" + parent_room_type + ",\"" + room_type + "\",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + is_open +"}";
  202. flag = true;
  203. }
  204. }
  205. ZZLog(cstr);
  206. if (flag) {
  207. if ($('#btnSave').text() == '保存中') {
  208. return;
  209. }
  210. $('#btnSave').text('保存中');
  211. $('#btnSave').css('background', 'darkgray');
  212. var urlapi = base_api;
  213. var param = {
  214. type: "room_HTModifyPrice",
  215. op: "up_base_price",
  216. user_id: user_id,
  217. hotel_id: hotel_id,
  218. para_flag: para_flag,
  219. hotel_info: cstr
  220. };
  221. ZZLog(urlapi + JSON.stringify(param));
  222. $.ajax({
  223. url: urlapi,
  224. data: param,
  225. type: "post",
  226. dataType: "json",
  227. success: function (res_data) {
  228. ZZLog(res_data);
  229. if (res_data['code'] != "0") {
  230. alert(res_data['info']);
  231. $('#btnSave').text('保存');
  232. $('#btnSave').css('background', '#428bca!important');
  233. } else {
  234. // history.go(-1);
  235. window.location.href = "room_info.html?hotel_id=" + hotel_id + "&hotel_name=" + hotel_name+ "&start_date="+ getPar('start_date')+ "&date_flag=1";
  236. }
  237. }
  238. })
  239. }
  240. }
  241. function isEmpty(str) {
  242. if (str.trim() == "") {
  243. return true;
  244. } else {
  245. return false;
  246. }
  247. }
  248. function isEmptyByArr(varArr) {
  249. var arr = [];
  250. for (var i = 0; i < varArr.length; i++) {
  251. if (varArr[i].trim() == "") {
  252. return true;
  253. } else {
  254. arr.push(false);
  255. }
  256. }
  257. if (arr.indexOf(false) != -1) {
  258. return false;
  259. }
  260. }
  261. //批量开关按钮
  262. function image_onclick_all(obj) {
  263. var is_open_all = $('.image_class_all').attr('isopen');
  264. is_open_all = is_open_all == 0 ? 1 : 0;
  265. if (is_open_all == "0") {
  266. $('.image_class').attr('src', 'images/OffSwitch.png');
  267. $('.image_class').attr('isopen', 0);
  268. $('.image_class_all').attr('src', 'images/OffSwitch.png');
  269. } else {
  270. $('.image_class').attr('src', 'images/OnSwitch.png');
  271. $('.image_class').attr('isopen', 1);
  272. $('.image_class_all').attr('src', 'images/OnSwitch.png');
  273. }
  274. $('.image_class_all').attr('isopen', is_open_all);
  275. }
  276. //单个开关按钮
  277. function image_onclick(obj) {
  278. var is_open = $(obj).attr("isopen");
  279. is_open = is_open == 0 ? 1 : 0;
  280. if(is_open =="0"){
  281. $(obj).attr('src','images/OffSwitch.png');
  282. }else {
  283. $(obj).attr('src','images/OnSwitch.png');
  284. }
  285. $(obj).attr("isopen",is_open);
  286. //批量改状态
  287. var arr=[];
  288. var arr1=[];
  289. var count=$('.image_class').length;
  290. $('.image_class').each(function (index,dom) {
  291. var is_open = $(this).attr('isopen');
  292. if(is_open==0){
  293. arr.push(is_open);
  294. }else if (is_open ==1){
  295. arr1.push(is_open);
  296. }
  297. });
  298. if(arr.length==count){
  299. $('.image_class_all').attr('src', 'images/OffSwitch.png');
  300. $('.image_class_all').attr('isopen',0)
  301. }else if(arr1.length==count) {
  302. $('.image_class_all').attr('src', 'images/OnSwitch.png');
  303. $('.image_class_all').attr('isopen',1)
  304. }
  305. }