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.

batch_modify_hotel_price.js 9.3 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. new_tr.innerHTML = newHTML;
  159. // method 2
  160. // $tempTR = tr_parent;
  161. // $tempTR.after(new_tr);
  162. // new_tr.innerHTML = newHTML;
  163. // $tempTR = $(new_tr);
  164. }
  165. // 删除行
  166. function delrow(selfOBJ) {
  167. var $selfOBJ = $(selfOBJ);
  168. var $tr_parent = $selfOBJ.closest('tr');
  169. $tr_parent.prop('outerHTML', '');
  170. }
  171. //修改采购价
  172. $(document).ready(function () {
  173. $(".maiduan_price_all").bind('input', function () {
  174. $('.maiduan_price').val($(this).val());
  175. })
  176. $(".baoliu_price_all").bind('input', function () {
  177. $('.baoliu_price').val($(this).val());
  178. })
  179. $(".xianxun_price_all").bind('input', function () {
  180. $('.xianxun_price').val($(this).val());
  181. })
  182. });
  183. function clickSave() {
  184. var cstr = '';
  185. var user_id = '1';
  186. var flag = true;
  187. var para_flag = '2';//批量改房价标志
  188. ZZLog($('.real_tr'));
  189. for (var i = 0, m = $('.real_tr').length; i < m; i++) {
  190. var parent_room_type = $('.real_tr').eq(i).attr('data-parent-room-type');
  191. var room_type = $('.real_tr').eq(i).attr('data-room-type');
  192. var start_date = $('.real_tr').eq(i).find('.start_date').val();
  193. var end_date = $('.real_tr').eq(i).find('.end_date').val();
  194. var weekDay = '';
  195. $('.real_tr').eq(i).find('.aday').each(function (index, domEle) {
  196. if (domEle.checked) {
  197. weekDay += $(this).val();
  198. }
  199. });
  200. //买断
  201. var maiduan_price = $('.real_tr').eq(i).find('.maiduan_price').val()?$('.real_tr').eq(i).find('.maiduan_price').val():'-1';
  202. var baoliu_price = $('.real_tr').eq(i).find('.baoliu_price').val()?$('.real_tr').eq(i).find('.baoliu_price').val():'-1';
  203. var xianxun_price = $('.real_tr').eq(i).find('.xianxun_price').val()?$('.real_tr').eq(i).find('.xianxun_price').val():'-1';
  204. if(parent_room_type==''||room_type==''||start_date==''||end_date==''){
  205. ZZAlertInfo('请输入完整!');
  206. return;
  207. }
  208. cstr += "{" + parent_room_type + "," + room_type + ",\"" + start_date + "\",\"" + end_date + "\"," + weekDay + "," + maiduan_price + "," + baoliu_price + "," + xianxun_price + "}";
  209. //最终数组
  210. flag = true;
  211. }
  212. if (flag) {
  213. if ($('#btnSave').text() == '保存中') {
  214. return;
  215. }
  216. $('#btnSave').text('保存中');
  217. $('#btnSave').css('background', 'darkgray');
  218. var urlapi = base_api;
  219. var param = {
  220. type: "room_HTModifyPrice",
  221. op: "up_base_price",
  222. user_id: user_id,
  223. hotel_id: hotel_id,
  224. para_flag: para_flag,
  225. hotel_info: cstr
  226. };
  227. ZZLog(urlapi + JSON.stringify(param));
  228. $.ajax({
  229. url: urlapi,
  230. data: param,
  231. type: "post",
  232. dataType: "json",
  233. success: function (res_data) {
  234. ZZLog(res_data);
  235. if (res_data['code'] != "0") {
  236. alert(res_data['info']);
  237. $('#btnSave').text('保存');
  238. $('#btnSave').css('background', '#428bca!important');
  239. } else {
  240. // history.go(-1);
  241. //把日期带上,是否重设日期标识
  242. window.location.href = "room_info.html?hotel_id=" + hotel_id + "&hotel_name=" + hotel_name+ "&start_date="+ getPar('start_date')+ "&date_flag=1";
  243. }
  244. }
  245. })
  246. }
  247. }
  248. function isEmpty(str) {
  249. if (str.trim() == "") {
  250. return true;
  251. } else {
  252. return false;
  253. }
  254. }
  255. function isEmptyByArr(varArr) {
  256. var arr = [];
  257. ZZLog(varArr);
  258. for (var i = 0; i < varArr.length; i++) {
  259. if (varArr[i].trim() == "") {
  260. return true;
  261. } else {
  262. arr.push(false);
  263. }
  264. }
  265. if (arr.indexOf(false) != -1) {
  266. return false;
  267. }
  268. }