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.
 
 
 
 

1005 lines
33 KiB

  1. /**
  2. * Created by luocj on 2016/10/26.
  3. */
  4. var input_time = '';
  5. var baseHTML = '';
  6. var childHTML = '';
  7. var firstDate = '';
  8. var d1 = "";
  9. var d2 = "";
  10. var d3 = "";
  11. var d4 = "";
  12. var d5 = "";
  13. var d6 = "";
  14. var d7 = "";
  15. var w1 = "";
  16. var w2 = "";
  17. var w3 = "";
  18. var w4 = "";
  19. var w5 = "";
  20. var w6 = "";
  21. var w7 = "";
  22. var check_distrib_id = '';
  23. // 房型售卖状态
  24. var room_sale_status = "-1";
  25. var hotel_id = '';
  26. var room_type_id = '';
  27. var room_type_name = '';
  28. var parent_room_type = '';
  29. var hotel_name = '';
  30. var tr_sale_rule_str = ''; //获取需要替换的所有代码
  31. var page_size = '10';
  32. var current = '1';
  33. window.onload = function () {
  34. hotel_id = getPar('hotel_id');
  35. room_type_id = getPar('room_type_id');
  36. room_type_name = getPar('room_type_name');
  37. parent_room_type = getPar('parent_room_type');
  38. document.getElementById("room_name").innerHTML = room_type_name;
  39. tr_sale_rule_str = $('.base').prop('outerHTML');
  40. setTbTopTd();
  41. addEvent();
  42. batchAddEvent();
  43. showDialog();
  44. current = '1';
  45. getSaleRuleInfo();
  46. // 点击蒙板
  47. $('#mask').bind('click', function () {
  48. clickMask();
  49. })
  50. to_fenxiao_lingshou();
  51. playPermission();
  52. }
  53. function replace(num) {
  54. if (num == 0) {
  55. // tempDict
  56. tempHtml = tempHtml.replace('[分销商名称]', '');
  57. tempHtml = tempHtml.replace('已售[' + 1 + '00]', "");
  58. tempHtml = tempHtml.replace('剩余[' + 1, "]");
  59. tempHtml = tempHtml.replace('分销价:[' + 1 + '00]', "");
  60. }
  61. var array1 = null;
  62. var nums1 = []; //保存第一个表格按,拆分后的所有值
  63. if (tempDict["date" + num] == "" || tempDict["date" + num] == null) {
  64. tempHtml = tempHtml.replace("[is_need_delete" + num + "]", "");
  65. }
  66. if (tempDict["date" + num] != null) {
  67. array1 = tempDict["date" + num].split(","); //第一个表格数据
  68. for (var j = 0; j < array1.length; j++) {
  69. if (array1[j] != "") {
  70. nums1.push(array1[j]);
  71. }
  72. }
  73. }
  74. var status = tempDict["authority_status"];
  75. if (status == "0") {
  76. tempHtml = tempHtml.replace('isopen="1"', 'isopen="0"');
  77. tempHtml = tempHtml.replace('images/OnSwitch.png', 'images/OffSwitch.png');
  78. } else if (status == "1") {
  79. tempHtml = tempHtml.replace('isopen="0"', 'isopen="1"');
  80. tempHtml = tempHtml.replace('images/OffSwitch.png"', 'images/OnSwitch.png"');
  81. } else { //当没有取到的时候,默认是没有授权
  82. tempHtml = tempHtml.replace('isopen="1"', 'isopen="0"');
  83. tempHtml = tempHtml.replace('images/OnSwitch.png', 'images/OffSwitch.png');
  84. }
  85. tempHtml = tempHtml.replace('[room-type]', tempDict['distrib_id']);
  86. tempHtml = tempHtml.replace('[distrib_id]', tempDict['distrib_id']);
  87. tempHtml = tempHtml.replace('[distrib_type]', tempDict['sale_type']);
  88. tempHtml = tempHtml.replace('[分销商名称]', tempDict['distrib_name']);
  89. $("#table :checkbox").prop("checked", false);
  90. //是否超卖
  91. var sellStatus = '';
  92. if (nums1[4] == '329') {
  93. sellStatus = '<span class="remaining" style="float: right;">关房</span>'
  94. }
  95. // ZZLog(nums1);
  96. tempHtml = tempHtml.replace("已售[" + num + "00]", "已售" + nums1[0] + sellStatus);
  97. //是否超卖
  98. var overSell = '';
  99. if (nums1[2] == 1) {
  100. overSell = '<span class="overSell" style="float:right;">&nbsp;</span>'
  101. }
  102. tempHtml = tempHtml.replace("剩余[" + num + "]", "剩余" + nums1[1] + overSell);
  103. tempHtml = tempHtml.replace("[" + num + "00]", nums1[3]);
  104. ZZLog(nums1[nums1.length - 1]);
  105. if (tempDict['sale_type'] == '312') {//312为直营 1772为分销
  106. tempHtml = tempHtml.replace("[分销价" + num + "]", "零售价");
  107. } else if (tempDict['sale_type'] == '177') {
  108. tempHtml = tempHtml.replace("[分销价" + num + "]", "分销价");
  109. }
  110. // if (tempDict['price_remark']=='2'){
  111. //
  112. // }else if(tempDict['price_remark']=='1'){
  113. // tempHtml = tempHtml.replace("分销价:[" + num + "00]", "零售价:" + nums1[nums1.length - 1]);
  114. // }
  115. // ZZLog(nums1);
  116. // ZZLog('当前状态值:' + nums1[0] + ' ' + nums1[1]);
  117. // if (nums1[0] == '326') {
  118. // tempHtml = tempHtml.replace('[images/img_gongxiang.png]', "images/img_baoliu.png");
  119. // } else if (nums1[0] == '327') {
  120. // tempHtml = tempHtml.replace('[images/img_gongxiang.png]', "images/img_gongxiang.png");
  121. // } else if (nums1[0] == '329') {
  122. // tempHtml = tempHtml.replace('[images/img_gongxiang.png]', "images/img_manfang.png");
  123. // } else if (nums1[0] == '328') {
  124. // tempHtml = tempHtml.replace('[images/img_gongxiang.png]', "images/229.png");
  125. // } else {
  126. // tempHtml = tempHtml.replace('[images/img_gongxiang.png]', "images/aa.png");
  127. // }
  128. }
  129. var tempDict;
  130. var tempHtml;
  131. var distrib_id_array = [];
  132. function getSaleRuleInfo() {
  133. var para_distrib_name = $('#div_name').val();
  134. var para_start_date = $('#input_time').val();
  135. if (para_start_date == '') {
  136. para_start_date = getDateTime(0);
  137. }
  138. var apiurl = base_api;
  139. var param = {
  140. type: "hotel_SaleRuleInfo",
  141. para_hotel_id: hotel_id,
  142. para_base_room_type: parent_room_type,
  143. para_room_type: room_type_id,
  144. para_distrib_name: para_distrib_name,
  145. para_start_date: para_start_date,
  146. op: "getSaleRule",
  147. current: current,
  148. page_size: page_size
  149. };
  150. ZZLog(param);
  151. $.ajaxSetup({
  152. async: false
  153. });
  154. loading();
  155. $.ajax({
  156. type: "post",
  157. url: apiurl,
  158. data: param,
  159. dataType: "json",
  160. success: function (res_data) {
  161. ZZLog(res_data);
  162. var areaHtml = '';
  163. var sale_list = res_data['result'];
  164. if (sale_list.length != 0) {
  165. $('#room_list').css('visibility', 'visible');
  166. }
  167. if (sale_list.length == 0) {
  168. replace(0);
  169. }
  170. for (var i = 0, m = sale_list.length; i < m; i++) {
  171. tempDict = sale_list[i]; //获取到每一个对象
  172. tempHtml = tr_sale_rule_str;
  173. var distrib_id = tempDict['distrib_id'];
  174. distrib_id_array[distrib_id_array.length] = distrib_id;
  175. for (var k = 1; k < 8; k++) {
  176. replace(k);
  177. }
  178. areaHtml += tempHtml;
  179. }
  180. $('#room_list').html(areaHtml);
  181. if (res_data['total'] < 1) {
  182. $('.pageDiv').hide();
  183. } else {
  184. $(".pageDiv").createPage({
  185. pageCount: res_data['total_page'],//总页数
  186. current: current,//当前页
  187. turndown: 'true',//是否显示跳转框,显示为true,不现实为false,一定记得加上引号...
  188. backFn: function (p) {
  189. current = p;
  190. getSaleRuleInfo();
  191. }
  192. });
  193. $('.pageDiv').show();
  194. }
  195. $('.change').each(function (index, domEle) {
  196. if ($(this).attr('is_need_delete') == "") {
  197. $(this).css('background', '');
  198. $(this).css('text-align', 'center');
  199. $(this).css('vertical-align', 'middle');
  200. $(this).html('暂无');
  201. }
  202. });
  203. cdayAddEvent();
  204. closeLoading();
  205. }, error: function (error) {
  206. ZZLog(error);
  207. closeLoading();
  208. }
  209. });
  210. $.ajaxSetup({
  211. async: true
  212. });
  213. }
  214. function showDialog() {
  215. $('#updateAll').unbind('click');
  216. $('#updateAll').bind('click', function () {
  217. input_time = $('#input_time').val();
  218. $('#start_date_update').val(input_time);
  219. $('#end_date_update').val(getDateByDay(6, input_time));
  220. if (check_distrib_id.length == 0) { //没有选中的情况,弹出提示框
  221. alert('请选中需要批量修改的渠道商!');
  222. return;
  223. }
  224. //$('#one').css('display','block');
  225. $('#mask').css('background', 'white');
  226. $('#mask').css('opacity', '0.5');
  227. $("#authorized_stock_num_many").val('');
  228. $("#distribution_price_many").val('');
  229. $("#retail_price_many").val('');
  230. showCenterView('#one');
  231. });
  232. }
  233. // 将目标节点居中显示
  234. var $tempShowView = null;
  235. function showCenterView(classOrIdName) {
  236. $('#mask').css('display', 'block');
  237. $('#mask').css('z-index', '15');
  238. $showView = $(classOrIdName);
  239. $tempShowView = $showView;
  240. $showView.css('display', 'block');
  241. $showView.css('position', 'absolute');
  242. $showView.css('top', '50%');
  243. $showView.css('left', '50%');
  244. $showView.css('z-index', '20');
  245. $showView.css('background', 'white');
  246. var w = $showView.css('width');
  247. var h = $showView.css('height');
  248. w = w.substr(0, w.length - 2);
  249. h = h.substr(0, h.length - 2);
  250. $showView.css('margin-top', '-' + h / 2 + 'px');
  251. $showView.css('margin-left', '-' + w / 2 + 'px');
  252. }
  253. // 点击蒙板
  254. function clickMask() {
  255. if ($temp_cday) {
  256. $('#up_base_room').css('display', 'none');
  257. $temp_cday.css('background', '');
  258. }
  259. $('#mask').css('display', 'none');
  260. }
  261. function doclick_close() {
  262. $('#one').css('display', 'none');
  263. clickMask();
  264. }
  265. function doclick_save() {
  266. var startDate = $('#start_date_update').val();
  267. var endDate = $('#end_date_update').val();
  268. var checkList = $('.checkbox_date');
  269. var allCheckString = ""; //para_week_day,存储过程中的参数
  270. var authorizedStock = $('#authorized_stock_many').val();
  271. var authorizedStockNum = $('#authorized_stock_num_many').val();
  272. var distributionPrice = $('#distribution_price_many').val();
  273. //alert('distributionPrice:'+distributionPrice);
  274. var retailPrice = $('#retail_price_many').val();
  275. var overSaleBatch = $("input[name='overSaleBatch']:checked").val();
  276. for (var i = 2; i < checkList.length + 2; i++) {
  277. //alert(checkList[i-2].checked);
  278. if (checkList[i - 2].checked) { //如果满足条件
  279. if (i == checkList.length + 1) {
  280. allCheckString += 1;
  281. } else {
  282. allCheckString += i;
  283. }
  284. }
  285. }
  286. if (startDate == "" || endDate == "" || allCheckString == "" || authorizedStock == "" || authorizedStockNum == "" || distributionPrice == "" || retailPrice == "") {
  287. alert('您还有未输入的选项!');
  288. // alert('startDate:'+startDate);
  289. // alert('endDate:'+endDate);
  290. // alert('allCheckString:'+allCheckString);
  291. // alert('authorizedStock:'+authorizedStock);
  292. // alert('authorizedStockNum:'+authorizedStockNum);
  293. // alert('distributionPrice:'+distributionPrice);
  294. // alert('retailPrice:'+retailPrice);
  295. return;
  296. }
  297. if (isNaN(authorizedStockNum) || isNaN(distributionPrice) || isNaN(retailPrice)) {
  298. ZZAlertInfo('数据格式不正确');
  299. return;
  300. }
  301. // in para_user_id int, in para_hotel_id int, in para_base_room_type int, in para_room_type int, in para_distrib_list varchar(2000),in para_start_date varchar(20), in para_end_date varchar(20), in para_week_day varchar(10), in para_stock_type int, in para_stock_num int, in para_prod_price decimal(10,2), in para_cus_price decimal(10,2)
  302. var urlapi = base_api;
  303. var param = {
  304. type: "hotel_SaleRuleInfo",
  305. op: "updateAuthorizeInfo",
  306. para_user_id: 1,
  307. para_hotel_id: hotel_id,
  308. para_base_room_type: parent_room_type,
  309. para_room_type: room_type_id,
  310. para_distrib_list: check_distrib_id,
  311. para_start_date: startDate,
  312. para_end_date: endDate,
  313. para_week_day: allCheckString,
  314. para_stock_type: authorizedStock,
  315. para_stock_num: authorizedStockNum,
  316. para_prod_price: distributionPrice,
  317. para_cus_price: retailPrice,
  318. para_over_sale: overSaleBatch
  319. };
  320. ZZLog(urlapi + JSON.stringify(param));
  321. $("#batch_save").html('保存中');
  322. $('#batch_save').css('background-color', 'darkgray');
  323. loading();
  324. $.ajax({
  325. url: urlapi,
  326. data: param,
  327. type: "post",
  328. dataType: "json",
  329. success: function (res_data) {
  330. closeLoading();
  331. ZZLog(res_data);
  332. if (res_data['code'] != "0") {
  333. ZZAlertInfo(res_data['info']);
  334. } else {
  335. //alert('成功了!');
  336. //重新加载页面
  337. getSaleRuleInfo();
  338. }
  339. $("#batch_save").val('保存');
  340. $('#batch_save').css('background', '#428bca');
  341. },
  342. error: function (msg) {
  343. $("#batch_save").val('保存');
  344. $('#batch_save').css('background', '#428bca');
  345. closeLoading();
  346. }
  347. })
  348. $('#one').css('display', 'none');
  349. clickMask();
  350. }
  351. var $temp_cday = null;
  352. var number = null;
  353. var distrib_id_checkd = null;
  354. var distrib_type = null;
  355. function cdayAddEvent(obj) {
  356. distrib_id_checkd = $(obj).parent().attr('data-distrib-id');
  357. distrib_type = $(obj).parent().attr('data-distrib-type');
  358. var num = $(obj).attr('date_num'); //当前点击的是第几天
  359. var stock = $(obj).children().children().children('.has_sell').text().trim();
  360. var sell = $(obj).children().children().children('.remaining').text().trim();
  361. var price = $(obj).children().children().children('.distribution_price').text().trim();
  362. stock = stock.substr(2);
  363. sell = sell.substr(2);
  364. var price_type = price.substr(0, 3);
  365. price = price.substr(4);
  366. $('#authorized_stock_num').val(parseInt(stock) + parseInt(sell));
  367. if (distrib_type == '177') {
  368. $('#distribution_price').val(parseFloat(price));
  369. $('#retail_price').val('0');
  370. $('#lingshou_name').hide();
  371. $('#lingshou_price').hide();
  372. $('#fenxiao_name').show();
  373. $('#fenxiao_price').show();
  374. } else if (distrib_type == '277' || distrib_type == '312') {
  375. $('#retail_price').val(parseFloat(price));
  376. $('#distribution_price').val('0');
  377. $('#lingshou_name').show();
  378. $('#lingshou_price').show();
  379. $('#fenxiao_name').hide();
  380. $('#fenxiao_price').hide();
  381. }
  382. number = num;
  383. $('.change').bind('click', function () {
  384. //需要获取最大间数提示
  385. var _td_date = $('.tb_title').children().eq(number).attr('f_date'); //当前点击的日期
  386. //alert(_td_date);return;
  387. var startDate = _td_date;
  388. var endDate = _td_date;
  389. var urlapi = base_api;
  390. var param = {
  391. type: "hotel_SaleRuleInfo",
  392. op: "getMaxStockNumber",
  393. para_hotel_id: hotel_id,
  394. para_base_room_type: parent_room_type,
  395. para_room_type: room_type_id,
  396. para_start_date: startDate,
  397. para_end_date: endDate,
  398. para_distrib_list: distrib_id_checkd
  399. };
  400. // alert(urlapi + JSON.stringify(param));
  401. ZZLog(urlapi + JSON.stringify(param));
  402. //alert('333');
  403. $.ajax({
  404. url: urlapi,
  405. data: param,
  406. type: "post",
  407. dataType: "json",
  408. success: function (res_data) {
  409. $("#max_stock").html(res_data)
  410. },
  411. error: function (msg) {
  412. }
  413. })
  414. if ($(this).attr('is_need_delete') == "") {
  415. return;
  416. }
  417. $('#mask').css('display', 'block');
  418. $('#mask').css('background', 'white');
  419. $('#mask').css('opacity', '0');
  420. if ($temp_cday != null) {
  421. $temp_cday.css('background', '');
  422. }
  423. // 得到鼠标的位置
  424. var mouseLeft = $(this).offset().left;
  425. var mouseTop = $(this).offset().top;
  426. var td_height = parseInt($(this).css('height').replace('px', ''));
  427. $(this).css('background', '#ddd');
  428. $('#up_base_room').css('top', mouseTop + td_height + 'px');
  429. $('#up_base_room').css('display', 'block');
  430. $('#up_base_room').attr('')
  431. //
  432. $temp_cday = $(this);
  433. })
  434. }
  435. function todayOnclick() {
  436. d1 = getDateTime(0);
  437. setTbTopTd();
  438. current = '1'
  439. getSaleRuleInfo();
  440. }
  441. function beforeOnclick() {
  442. d1 = getDateByDay(-7, d1);
  443. setTbTopTd();
  444. current = '1'
  445. getSaleRuleInfo();
  446. }
  447. function afterOnclick() {
  448. d1 = getDateByDay(7, d1);
  449. setTbTopTd();
  450. current = '1'
  451. getSaleRuleInfo();
  452. }
  453. // 将目标节点居中显示
  454. var $tempShowView = null;
  455. function showCenterView(classOrIdName) {
  456. $('#mask').css('display', 'block');
  457. $('#mask').css('z-index', '15');
  458. $showView = $(classOrIdName);
  459. $tempShowView = $showView;
  460. $showView.css('display', 'block');
  461. $showView.css('position', 'absolute');
  462. $showView.css('top', $(window).height() / 2.2);
  463. $showView.css('left', '50%');
  464. $showView.css('z-index', '20');
  465. $showView.css('background', 'white');
  466. var w = $showView.css('width');
  467. var h = $showView.css('height');
  468. w = w.substr(0, w.length - 2);
  469. h = h.substr(0, h.length - 2);
  470. $showView.css('margin-top', '-' + h / 2 + 'px');
  471. $showView.css('margin-left', '-' + w / 2 + 'px');
  472. }
  473. // 点击蒙板
  474. function clickMask() {
  475. if ($temp_cday) {
  476. $('#up_base_room').css('display', 'none');
  477. $temp_cday.css('background', '');
  478. }
  479. if ($tempShowView) {
  480. $('.main_style').css('display', 'none');
  481. $tempShowView.css('background', '');
  482. }
  483. $('#mask').css('display', 'none');
  484. $("#one").hide();
  485. }
  486. // 设置表格头部的td
  487. function setTbTopTd() {
  488. // 设置标题的日期和星期
  489. var today = getDateTime(0);
  490. if (d1 == "") {
  491. d1 = today;
  492. }
  493. $('#input_time').val(d1);
  494. d2 = after(d1);
  495. d3 = after(d2);
  496. d4 = after(d3);
  497. d5 = after(d4);
  498. d6 = after(d5);
  499. d7 = after(d6);
  500. w1 = getWeekDay(d1);
  501. w2 = getWeekDay(d2);
  502. w3 = getWeekDay(d3);
  503. w4 = getWeekDay(d4);
  504. w5 = getWeekDay(d5);
  505. w6 = getWeekDay(d6);
  506. w7 = getWeekDay(d7);
  507. //alert(d1+" "+d2+" "+d3+" "+d4+" "+d5+" "+d6+""+d7);
  508. $('#day1').attr('date_num', d1);
  509. $('#day2').attr('date_num', d2);
  510. $('#day3').attr('date_num', d3);
  511. $('#day4').attr('date_num', d4);
  512. $('#day5').attr('date_num', d5);
  513. $('#day6').attr('date_num', d6);
  514. $('#day7').attr('date_num', d7);
  515. $('#f_date1').attr('f_date', d1);
  516. $('#f_date2').attr('f_date', d2);
  517. $('#f_date3').attr('f_date', d3);
  518. $('#f_date4').attr('f_date', d4);
  519. $('#f_date5').attr('f_date', d5);
  520. $('#f_date6').attr('f_date', d6);
  521. $('#f_date7').attr('f_date', d7);
  522. var td1 = d1.substring(5);
  523. var td2 = d2.substring(5);
  524. var td3 = d3.substring(5);
  525. var td4 = d4.substring(5);
  526. var td5 = d5.substring(5);
  527. var td6 = d6.substring(5);
  528. var td7 = d7.substring(5);
  529. $('#f_date1').html(td1 + "</br>" + w1);
  530. $('#f_date2').html(td2 + "</br>" + w2);
  531. $('#f_date3').html(td3 + "</br>" + w3);
  532. $('#f_date4').html(td4 + "</br>" + w4);
  533. $('#f_date5').html(td5 + "</br>" + w5);
  534. $('#f_date6').html(td6 + "</br>" + w6);
  535. $('#f_date7').html(td7 + "</br>" + w7);
  536. // 将日期为今天的星期设置为今天
  537. $('th[f_date=' + getDateTime(0) + ']').html(getDateTime(0).substring(5) + '</br>今天');
  538. }
  539. var true_count = 0;
  540. // 复选框事件
  541. function select_checked(index, selfOBJ) {
  542. $selfOBJ = $(selfOBJ);
  543. //index=0最上面的全选 index=1表示的是下面所有的
  544. var cur_check = $('.ace')[0];
  545. var checkList = $('.ace');
  546. var checkCount = checkList.length - 1;
  547. if (index == '0') {
  548. if (selfOBJ.checked) {
  549. check_distrib_id.splice(0, check_distrib_id.length);
  550. for (var i = 0; i < distrib_id_array.length; i++) {
  551. check_distrib_id[check_distrib_id.length] = distrib_id_array[i];
  552. }
  553. true_count = checkList.length - 1;
  554. selfOBJ.checked = true;
  555. } else {
  556. check_distrib_id.splice(0, check_distrib_id.length);
  557. true_count = 0;
  558. selfOBJ.checked = false;
  559. }
  560. } else if (index == '1') {
  561. if (selfOBJ.checked) {
  562. true_count++;
  563. var $par_tr = $(selfOBJ).closest('tr');
  564. var distrib_id = $par_tr.attr('data-distrib-id');
  565. if (check_distrib_id.indexOf(distrib_id) == -1) {
  566. check_distrib_id[check_distrib_id.length] = distrib_id;
  567. }
  568. } else {
  569. // 当前的base为选中
  570. true_count--;
  571. var par_tr = $(selfOBJ).closest('tr');
  572. var distrib_id = par_tr.attr('data-distrib-id');
  573. check_distrib_id.remove(distrib_id);
  574. }
  575. //alert(true_count);
  576. }
  577. //alert(check_distrib_id);
  578. for (var i = 1, m = checkList.length; i < m; i++) {
  579. if (index == '0') {
  580. checkList[i].checked = cur_check.checked;
  581. }
  582. }
  583. //alert(true_count);
  584. if (checkCount == true_count) {
  585. cur_check.checked = true;
  586. } else {
  587. cur_check.checked = false;
  588. }
  589. }
  590. Array.prototype.indexOf = function (val) {
  591. for (var i = 0; i < this.length; i++) {
  592. if (this[i] == val) return i;
  593. }
  594. return -1;
  595. };
  596. Array.prototype.remove = function (val) {
  597. var index = this.indexOf(val);
  598. if (index > -1) {
  599. this.splice(index, 1);
  600. }
  601. };
  602. //更换图片
  603. function image_onclick(obj) {
  604. var $par_tr = $(obj).closest('tr');
  605. var distrib_id = $par_tr.attr('data-distrib-id');
  606. if ($(obj).attr('isopen') == "0") { //变成打开授权状态
  607. $(obj).attr('isopen', "1");
  608. $(obj).attr('src', "images/OnSwitch.png");
  609. //alert("distrib_id:"+distrib_id+" hotel_id:"+hotel_id+" parent_room_type"+parent_room_type+" room_type_id"+room_type_id);
  610. var apiurl = base_api + "?type=hotel_SaleRuleInfo&authorize_status=" + 1 + "&hotel_id=" + hotel_id + "&parent_room_type=" + parent_room_type + "&room_type=" + room_type_id + "&op=updateAuthorizeStatus&distrib_id_string=" + distrib_id;
  611. ZZLog(apiurl);
  612. //alert('123');
  613. $.getJSON(apiurl, function (res_data) {
  614. //alert("awefawfawefwaf");
  615. //console.log("数据:"+res_data);
  616. }).error(function (msg) {
  617. })
  618. } else {
  619. $(obj).attr('isopen', "0");
  620. $(obj).attr('src', "images/OffSwitch.png");
  621. var apiurl = base_api + "?type=hotel_SaleRuleInfo&authorize_status=" + 0 + "&hotel_id=" + hotel_id + "&parent_room_type=" + parent_room_type + "&room_type=" + room_type_id + "&op=updateAuthorizeStatus&distrib_id_string=" + distrib_id;
  622. ZZLog(apiurl);
  623. //alert('345');
  624. $.getJSON(apiurl, function (res_data) {
  625. //alert("awefawfawefwaf");
  626. ZZLog("数据:" + res_data);
  627. })
  628. }
  629. //
  630. // if(document.getElementById("image").getAttribute("src") == "images/OffSwitch.png") {
  631. // document.getElementById("image").src = "images/On Switch.png";
  632. // } else {
  633. // document.getElementById("image").src = "images/OffSwitch.png";
  634. // }
  635. }
  636. //同时更改所有选中的分销商授权状态
  637. function openStatus() {
  638. if (check_distrib_id.length == 0) { //没有选中的情况,弹出提示框
  639. alert('请选中需要开启授权的项!');
  640. return;
  641. }
  642. var distrib_id_string = unionBySeprator(check_distrib_id);
  643. var apiurl = base_api + "?type=hotel_SaleRuleInfo&authorize_status=" + 1 + "&hotel_id=" + hotel_id + "&parent_room_type=" + parent_room_type + "&room_type=" + room_type_id + "&op=updateAuthorizeStatus&distrib_id_string=" + distrib_id_string;
  644. ZZLog(apiurl);
  645. loading();
  646. $.getJSON(apiurl, function (res_data) {
  647. //alert("awefawfawefwaf");
  648. //console.log("数据:"+res_data);
  649. getSaleRuleInfo();
  650. closeLoading();
  651. })
  652. }
  653. //把数组的所有元素以逗号分隔,返回该字符串
  654. function unionBySeprator(check_distrib_id) {
  655. if (check_distrib_id.length == 0) {
  656. return "";
  657. }
  658. var result_string = "";
  659. for (var i = 0; i < check_distrib_id.length; i++) {
  660. result_string += ',';
  661. result_string += check_distrib_id[i];
  662. }
  663. return result_string.substr(1, result_string.length);
  664. }
  665. function closeStatus() {
  666. if (check_distrib_id.length == 0) { //没有选中的情况,弹出提示框
  667. alert('请选中需要关闭授权的项!');
  668. return;
  669. }
  670. var distrib_id_string = unionBySeprator(check_distrib_id);
  671. var apiurl = base_api + "?type=hotel_SaleRuleInfo&authorize_status=" + 0 + "&hotel_id=" + hotel_id + "&parent_room_type=" + parent_room_type + "&room_type=" + room_type_id + "&op=updateAuthorizeStatus&distrib_id_string=" + distrib_id_string;
  672. ZZLog(apiurl);
  673. loading();
  674. $.getJSON(apiurl, function (res_data) {
  675. //alert("awefawfawefwaf");
  676. //console.log("数据:"+res_data);
  677. getSaleRuleInfo();
  678. closeLoading();
  679. })
  680. }
  681. //以下3个方法是确保输入框只能输入数字和1个逗号
  682. function check(event) {
  683. var e = window.event || event;
  684. var target = e.srcElement || e.target;
  685. var k = e.keyCode;
  686. if (isFunKey(k)) {
  687. return true;
  688. }
  689. var c = getChar(k);
  690. if (target.value.length == '' && (c == '-' || c == '+')) {
  691. return true;
  692. }
  693. if (isNaN(target.value + getChar(k))) {
  694. return false;
  695. }
  696. return true;
  697. }
  698. function isFunKey(code) {
  699. // 8 --> Backspace
  700. // 35 --> End
  701. // 36 --> Home
  702. // 37 --> Left Arrow
  703. // 39 --> Right Arrow
  704. // 46 --> Delete
  705. // 112~123 --> F1~F12
  706. var funKeys = [8, 35, 36, 37, 39, 46];
  707. for (var i = 112; i <= 123; i++) {
  708. funKeys.push(i);
  709. }
  710. for (var i = 0; i < funKeys.length; i++) {
  711. if (funKeys[i] == code) {
  712. return true;
  713. }
  714. }
  715. return false;
  716. }
  717. function getChar(k) {
  718. if (k >= 48 && k <= 57) {
  719. return String.fromCharCode(k);
  720. }
  721. if (k >= 96 && k <= 105) {
  722. return String.fromCharCode(k - 48);
  723. }
  724. if (k == 110 || k == 190) {
  725. return ".";
  726. }
  727. if (k == 109 || k == 189) {
  728. return "-";
  729. }
  730. if (k == 107 || k == 187) {
  731. return "+";
  732. }
  733. return "#";
  734. }
  735. //点击搜索,重新查找匹配条件的数据
  736. function searchOnclick() {
  737. d1 = $('#input_time').val();
  738. setTbTopTd();
  739. //alert('2222');
  740. showDialog();
  741. //alert('awef');
  742. current = '1'
  743. getSaleRuleInfo();
  744. }
  745. function cancelUpdate() {
  746. clickMask();
  747. }
  748. //点击弹出层的提交按钮事件
  749. function saveUpdate() {
  750. //alert(new Date(d1).getDay()); //当前页面上第一天是星期几
  751. //当前点击的是第number个日期,可以获取到具体的日期
  752. //alert(number);
  753. var _td_date = $('.tb_title').children().eq(number).attr('f_date'); //当前点击的日期
  754. //alert(_td_date);return;
  755. var startDate = _td_date;
  756. var endDate = _td_date;
  757. var allCheckString = "2345671"; //para_week_day,存储过程中的参数
  758. var authorizedStock = $('#base_stock_type').val();
  759. var authorizedStockNum = $('#authorized_stock_num').val();
  760. var distributionPrice = $('#distribution_price').val() == '' ? 0 : $('#distribution_price').val();
  761. var retailPrice = $('#retail_price').val() == '' ? 0 : $('#retail_price').val();
  762. var overSaleOne = $("input[name='overSale']:checked").val();
  763. if (startDate == "" || endDate == "" || allCheckString == "" || authorizedStock == "" || authorizedStockNum == "") {
  764. alert('您还有未输入的选项!');
  765. return;
  766. }
  767. if (distributionPrice == "" && retailPrice == "") {
  768. alert('您还有未输入的选项!');
  769. // alert('startDate:'+startDate);
  770. // alert('endDate:'+endDate);
  771. // alert('allCheckString:'+allCheckString);
  772. // alert('authorizedStock:'+authorizedStock);
  773. // alert('authorizedStockNum:'+authorizedStockNum);
  774. // alert('distributionPrice:'+distributionPrice);
  775. // alert('retailPrice:'+retailPrice);
  776. return;
  777. }
  778. if (isNaN(retailPrice)) {
  779. ZZAlertInfo('金额格式不正确');
  780. return;
  781. }
  782. //alert('222');
  783. // in para_user_id int, in para_hotel_id int, in para_base_room_type int, in para_room_type int, in para_distrib_list varchar(2000),in para_start_date varchar(20), in para_end_date varchar(20), in para_week_day varchar(10), in para_stock_type int, in para_stock_num int, in para_prod_price decimal(10,2), in para_cus_price decimal(10,2)
  784. var urlapi = base_api;
  785. var param = {
  786. type: "hotel_SaleRuleInfo",
  787. op: "updateAuthorizeInfo",
  788. para_user_id: 1,
  789. para_hotel_id: hotel_id,
  790. para_base_room_type: parent_room_type,
  791. para_room_type: room_type_id,
  792. para_distrib_list: distrib_id_checkd,
  793. para_start_date: startDate,
  794. para_end_date: endDate,
  795. para_week_day: allCheckString,
  796. para_stock_type: authorizedStock,
  797. para_stock_num: authorizedStockNum,
  798. para_prod_price: distributionPrice,
  799. para_cus_price: retailPrice,
  800. para_over_sale: overSaleOne
  801. };
  802. // alert(urlapi + JSON.stringify(param));
  803. ZZLog(urlapi + JSON.stringify(param));
  804. $("#one_save").html('保存中');
  805. $('#one_save').css('background', 'darkgray');
  806. loading();
  807. $.ajax({
  808. url: urlapi,
  809. data: param,
  810. type: "post",
  811. dataType: "json",
  812. success: function (res_data) {
  813. closeLoading();
  814. ZZLog(res_data);
  815. if (res_data['code'] != "0") {
  816. ZZAlertInfo(res_data['info']);
  817. } else {
  818. //alert(res_data);
  819. getSaleRuleInfo();
  820. ZZAlertInfo('修改成功');
  821. }
  822. $("#one_save").html('保存');
  823. $('#one_save').css('background', '#428bca');
  824. },
  825. error: function (msg) {
  826. $("#one_save").html('保存');
  827. $('#one_save').css('background', '#428bca');
  828. closeLoading();
  829. }
  830. })
  831. $('#one').css('display', 'none');
  832. clickMask();
  833. }
  834. function cannot_input_fenxiao() {
  835. if ($('#distribution_price') != '') {
  836. $('#retail_price').val('0');
  837. }
  838. }
  839. function cannot_input_lingshou() {
  840. if ($('#retail_price') != '') {
  841. $('#distribution_price').val('0');
  842. }
  843. }
  844. function cannot_input_fenxiao_many() {
  845. if ($('#distribution_price_many') != '') {
  846. //$('#retail_price_many').val('0');
  847. }
  848. }
  849. function cannot_input_lingshou_many() {
  850. if ($('#retail_price_many') != '') {
  851. //$('#distribution_price_many').val('0');
  852. }
  853. }
  854. //选择共享库存则间数变0且不能修改
  855. function addEvent() {
  856. $('#base_stock_type').on('change', function () {
  857. if ($(this).val() == '327') {//共享库存
  858. $('#count_input').css("visibility", "hidden");
  859. $('#authorized_stock_num').val('0');
  860. } else if ($(this).val() == '328') {//人工确认
  861. $('#count_input').css("visibility", "hidden");
  862. $('#authorized_stock_num').val('999');
  863. } else if ($(this).val() == '329') {//人工确认
  864. $('#count_input').css("visibility", "hidden");
  865. $('#authorized_stock_num').val('0');
  866. } else {
  867. $('.authorized_stock_num').val('0');
  868. $('#count_input').css("visibility", "visible");
  869. }
  870. })
  871. }
  872. function batchAddEvent() {
  873. $('#authorized_stock_many').on('change', function () {
  874. if ($(this).val() == '327') {//共享库存
  875. $('.second_style_next_data').hide();
  876. $('#authorized_stock_num_many').val('0');
  877. } else if ($(this).val() == '328') {//人工确认
  878. $('.second_style_next_data').hide();
  879. $('#authorized_stock_num_many').val('999');
  880. } else if ($(this).val() == '329') {//满房
  881. $('.second_style_next_data').hide();
  882. $('#authorized_stock_num_many').val('0');
  883. } else {
  884. $('#authorized_stock_num_many').val('0');
  885. $('.second_style_next_data').show();
  886. }
  887. })
  888. }
  889. //提示分销价与零售价适用于哪些渠道
  890. function to_fenxiao_lingshou() {
  891. $('#updateAll').bind('click', function () {
  892. var sum_fenxiao_arr = [];
  893. var sum_fenxiao_str = '';
  894. var sum_lingshou_arr = [];
  895. var sum_lingshou_str = '';
  896. $("input[name='mybox']").each(function () {
  897. if ($(this).is(':checked')) {
  898. if ($(this).closest('tr').attr('data-distrib-type') == 177) {
  899. sum_fenxiao_arr.push($(this).closest('tr').find('td:first').html());
  900. } else {
  901. sum_lingshou_arr.push($(this).closest('tr').find('td:first').html());
  902. }
  903. }
  904. });
  905. sum_fenxiao_str = sum_fenxiao_arr.join(",");
  906. sum_lingshou_str = sum_lingshou_arr.join(",");
  907. ZZLog(sum_fenxiao_str, sum_lingshou_str);
  908. $('#to_fenxiao').text('将应用于' + sum_fenxiao_str);
  909. $('#to_lingshou').text('将应用于' + sum_lingshou_str);
  910. });
  911. }
  912. //全选或全不选
  913. $("#all").click(function () {
  914. if (this.checked) {
  915. var valArr = new Array;
  916. $("#table :checkbox").prop("checked", true);
  917. $('input[type="checkbox"][name="mybox"]:checked').each(function (i) {
  918. valArr[i] = $(this).val();
  919. });
  920. var vals = valArr.join(',');
  921. check_distrib_id = vals;
  922. } else {
  923. $("#table :checkbox").prop("checked", false);
  924. }
  925. });
  926. function selectAll() {
  927. var valArr = new Array;
  928. $('input[type="checkbox"][name="mybox"]:checked').each(function (i) {
  929. valArr[i] = $(this).val();
  930. });
  931. var vals = valArr.join(',');
  932. check_distrib_id = vals;
  933. }