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.
 
 
 
 
 
 

775 lines
29 KiB

  1. var order_id = $('#hidden_order_id').attr('value');
  2. var docking_type = $('#hidden_order_id').attr('docking-type');
  3. var payment_status = $('#hidden_order_id').attr('payment_status');
  4. var gathering_status = $('#hidden_order_id').attr('gathering_status');
  5. var hotel_id = $('#hidden_order_id').attr('hotel_id');
  6. var room_type = $('#hidden_order_id').attr('room_type');
  7. var room_id = $('#hidden_order_id').attr('room-id');
  8. var create_user_id = $('#hidden_order_id').attr('create_user_id');
  9. var parent_room_type = $('#hidden_order_id').attr('base_room_type');
  10. var channel_id = $('#hidden_order_id').attr('channel_id');
  11. var customer_memo = $('#hidden_order_id').attr('customer-memo');
  12. var channel_order_id = $('#hidden_order_id').attr('outside-order');
  13. var hotel_room_id = $('#hotel_room_id').val();
  14. var checkin_date = $('#hidden_order_id').attr('checkin-date');
  15. var checkout_date = $('#hidden_order_id').attr('checkout-date');
  16. var old_num = $('#total_room_count').html();
  17. var delayTs = 800;
  18. var save_info = '保存';
  19. var save_update_info = '保存并生成修改单';
  20. var infoApiError = "服务器开小差了,请联系技术部相关人员";
  21. var temp_docking_type = '';
  22. var temp_order_status = $('#hidden_order_id').attr('order-status');
  23. var temp_channel_order_status = $('#hidden_order_id').attr('channel_order_status');
  24. var checkin_copy = '';
  25. var status_arr1 = ['313']; //待发单
  26. var status_arr2 = ["198", "382"]; //待安排 退改中
  27. var status_arr3 = ['313', '198', '382']; //待发单 待安排 退改中
  28. //渠道状态为已拒绝,取消被拒
  29. var channel_status_arr1 = ['552', '554'];
  30. var delay = (function () {
  31. var timer = 0;
  32. return function (callback, time) {
  33. clearTimeout(timer);
  34. timer = setTimeout(callback, time);
  35. };
  36. })();
  37. $(document).ready(function () {
  38. showThreeButton();
  39. })
  40. // 修改按钮的显示
  41. function showThreeButton() {
  42. if ('556' == docking_type) {
  43. $('#btn-rz-update-xsj').addClass('hide_f');
  44. $('#btn-rz-update-xq').addClass('hide_f');
  45. if (payment_status > 1)
  46. $('#btn-rz-update-cgj').addClass('hide_f');
  47. if ($.inArray(temp_order_status, status_arr3) == -1 || ($.inArray(temp_channel_order_status, channel_status_arr1) >= 0)) {
  48. $('#btn-rz-update-xq').addClass('hide_f');
  49. $('#btn-rz-update-cgj').addClass('hide_f');
  50. $('#btn-rz-update-cancel').addClass('hide_f');
  51. //客人信息
  52. $('#update-customer-info').addClass('hide_f');
  53. $('.comment-type1').addClass('hide_f');
  54. }
  55. }
  56. if ("557" == docking_type) {
  57. //1.5.2
  58. //录入的订单 应收:gathering_status > 1 则不显示销售价,应付:payment_status > 1 则不显示采购价
  59. if (gathering_status > 1) {
  60. $('#btn-rz-update-xsj').addClass('hide_f');
  61. }
  62. if (payment_status > 1) {
  63. $('#btn-rz-update-cgj').addClass('hide_f');
  64. }
  65. if ($.inArray(temp_order_status, status_arr3) == -1) {
  66. //三个按钮
  67. $('#btn-rz-update-xq').addClass('hide_f');
  68. $('#btn-rz-update-xsj').addClass('hide_f');
  69. $('#btn-rz-update-cgj').addClass('hide_f');
  70. $('#btn-rz-update-cancel').addClass('hide_f');
  71. //客人信息
  72. $('#update-customer-info').addClass('hide_f');
  73. $('.comment-type1').addClass('hide_f');
  74. }
  75. }
  76. }
  77. // 修改订单入口
  78. function updateOrderInfo() {
  79. var room_count = $('#min_room_count').val();
  80. var org_num = $('#ordermain-outside_order_no').val();
  81. var org_id = $('#ordermain-outside_sale_org_id').val();
  82. var customer_name = $('#ordermain-customer_name').val();
  83. var customer_mobile = $('#ordermain-customer_mobile').val();
  84. var room_list = '';
  85. var start_date = $('#start_date_txt').html();
  86. var end_date = $('#end_date_txt').html();
  87. $('.tr_line').each(function (index, dom) {
  88. var run_date = $(this).find('.room_run_date').html();
  89. var sale_single_price_txt = $(this).find('.sale_single_price').html();
  90. room_list += '{\'' + run_date + '\',' + sale_single_price_txt + '}';
  91. });
  92. // 修改订单参数
  93. var param = {
  94. "order_id": order_id,
  95. "user_id": create_user_id,
  96. "hotel_id": hotel_id,
  97. "room_id": room_id,
  98. "room_count": room_count,
  99. "org_id": org_id,
  100. "org_num": org_num,
  101. "room_list": room_list,
  102. "start_date": start_date,
  103. "end_date": end_date,
  104. "customer_name": customer_name,
  105. "customer_mobile": customer_mobile,
  106. "customer_memo": customer_memo
  107. };
  108. $.ajax({
  109. type: "post",
  110. url: '/hotel/ordermain/update-check-in',
  111. data: param,
  112. async: false,
  113. dataType: "json",
  114. success: function (res_data) {
  115. // ZZLog(res_data);
  116. if (res_data['code'] != "0") {
  117. ZZAlertInfo(res_data['info'], function () {
  118. closeLoading();
  119. });
  120. } else {
  121. ZZAlertInfo('修改成功', function () {
  122. document.location.reload();
  123. closeLoading();
  124. });
  125. }
  126. },
  127. error: function () {
  128. ZZAlertInfo(infoApiError, function () {
  129. closeLoading();
  130. });
  131. }
  132. });
  133. }
  134. // 顶部tab
  135. function searchOrderTab($order_id, $type) {
  136. }
  137. //入住间数改变不改变入住日期和销售单价
  138. $('#min_room_count').change(function () {
  139. changeStartEndDate(channel_id);
  140. });
  141. //修改取消按钮
  142. $('#btn-rz-cancel').on('click', function () {
  143. //data-main-status 1:修改入住需求 2:修改销售价 3:修改采购价
  144. var btn_main_status = $(this).attr('data-main-status') ? $(this).attr('data-main-status') : "1";
  145. if ('1' == btn_main_status) {
  146. //修改入住需求
  147. // ZZLog('入住需求取消-修改入住需求');
  148. $('#btn-rz-update-xq').html('修改入住需求');
  149. $('#btn-rz-update-xq').attr('data-btn-status', '1');
  150. }
  151. if ('2' == btn_main_status) {
  152. //修改销售价
  153. // ZZLog('入住需求取消-修改销售价');
  154. $('#btn-rz-update-xsj').html('修改销售价');
  155. $('#btn-rz-update-xsj').attr('data-btn-status', '1');
  156. }
  157. if ('3' == btn_main_status) {
  158. //修改采购价
  159. // ZZLog('入住需求取消-修改采购价');
  160. $('#btn-rz-update-cgj').html('修改采购价');
  161. $('#btn-rz-update-cgj').attr('data-btn-status', '1');
  162. }
  163. $('#stroke_tbody').html(checkin_copy);
  164. $(this).addClass('hide_f');
  165. $('#btn-rz-update-xq').removeClass('hide_f');
  166. $('#btn-rz-update-xsj').removeClass('hide_f');
  167. $('#btn-rz-update-cgj').removeClass('hide_f');
  168. showThreeButton();
  169. $('.update1_s').css('display', 'inherit');
  170. $('.update1_rz').css('display', 'none');
  171. $('.update2_s').removeClass('hide_f');
  172. $('.update2_h').addClass('hide_f');
  173. $('.update3_s').removeClass('hide_f');
  174. $('.update3_h').addClass('hide_f');
  175. // 日期修改
  176. $('#start_date').find('input').val(checkin_date);
  177. $('#end_date').find('input').val(checkout_date);
  178. $('#start_date_txt').html(checkin_date);
  179. $('#end_date_txt').html(checkout_date);
  180. $('#ordermain-outside_order_no').val(channel_order_id);
  181. $('#total_room_count').html(old_num);
  182. });
  183. //入住时间
  184. $('#start_date').on('changeDate', function (e) {
  185. changeStartEndDate(channel_id)
  186. })
  187. //离店时间
  188. $('#end_date').on('changeDate', function (e) {
  189. changeStartEndDate(channel_id);
  190. })
  191. // 订单渠道修改
  192. $('#ordermain-outside_sale_org_id').change(function () {
  193. changeStartEndDate($(this).val());
  194. })
  195. // 修改采购价
  196. $('.cai_base_price').keyup(function (event) {
  197. var parent = $(this).closest('tr');
  198. tr_change(parent);
  199. });
  200. // 修改销售价
  201. $('.tr_single_price').keyup(function () {
  202. var parent = $(this).closest('tr');
  203. var room_count = $('#total_room_count').html();
  204. var order_price = parent.find('.tr_single_price').val();
  205. var tr_base_price = parent.find('.cai_base_price_txt').html(); // 采购总价
  206. var dict = JSON.parse(parent.attr('data-json'));
  207. var all_price = room_count * order_price; // 单个总价
  208. var tr_mid_commission = parent.find('.tr_mid_price').html();
  209. // 佣金计算
  210. var tr_commission = getCommision(room_count, order_price, dict);
  211. //利润计算
  212. var tr_profit = all_price - tr_base_price * room_count - tr_mid_commission - tr_commission;
  213. parent.find('.tr_all_price').html(Number(all_price).toFixed(2));
  214. parent.find('.tr_all_commission').html(Number(tr_commission).toFixed(2));
  215. parent.find('.tr_profit_value').html(Number(tr_profit).toFixed(2));
  216. sum_price();
  217. });
  218. // 修改列,修改采购价
  219. function tr_change(parent) {
  220. var room_count = $('#total_room_count').html();
  221. var order_price = parent.find('.sale_single_price').html();
  222. var base_price = parent.find('.cai_base_price').val();
  223. var tr_mid_commission = parent.find('.tr_mid_price').html();
  224. var tr_commission = parent.find('.tr_all_commission').html();
  225. var all_price = parent.find('.tr_all_price').html();
  226. var tr_profit = all_price - base_price * room_count - tr_mid_commission - tr_commission;
  227. parent.find('.tr_profit_value').html(Number(tr_profit).toFixed(2));
  228. sum_price();
  229. }
  230. function keyup_price() {
  231. var all_1 = 0,
  232. all_2 = 0,
  233. all_3 = 0,
  234. all_4 = 0;
  235. $('.tr_all_price').each(function (index, dom) {
  236. var tr_all_1 = $(this).html();
  237. all_1 += tr_all_1 - 0;
  238. });
  239. $('.tr_mid_price').each(function (index, dom) {
  240. var tr_all_2 = $(this).html();
  241. all_2 += tr_all_2 - 0;
  242. });
  243. $('.tr_profit_value').each(function (index, dom) {
  244. var tr_all_3 = $(this).html();
  245. all_3 += tr_all_3 - 0;
  246. });
  247. $('.tr_all_commission').each(function (index, dom) {
  248. var tr_all_4 = $(this).html();
  249. all_4 += tr_all_4 - 0;
  250. });
  251. if (isNaN(all_1)) all_1 = 0;
  252. if (isNaN(all_2)) all_2 = 0;
  253. if (isNaN(all_3)) all_3 = 0;
  254. if (isNaN(all_4)) all_3 = 0;
  255. $('#all_price').html(all_1.toFixed(2) + '元');
  256. $('#all_price').attr('data-value', all_1.toFixed(2));
  257. $('#all_commission').html(all_2.toFixed(2) + '元');
  258. $('#all_commission').attr('data-value', all_2.toFixed(2));
  259. $('#profit_value').html(all_3.toFixed(2) + '元');
  260. $('#profit_value').attr('data-value', all_3.toFixed(2));
  261. $('#mid_all_commission').html(all_4.toFixed(2) + '元');
  262. $('#mid_all_commission').attr('data-value', all_4.toFixed(2));
  263. }
  264. function sum_price() {
  265. var all_1 = 0,
  266. all_2 = 0,
  267. all_3 = 0,
  268. all_4 = 0;
  269. $('.tr_all_price').each(function (index, dom) {
  270. var tr_all_1 = $(this).html();
  271. all_1 += tr_all_1 - 0;
  272. });
  273. $('.tr_mid_price').each(function (index, dom) {
  274. var tr_all_2 = $(this).html();
  275. all_2 += tr_all_2 - 0;
  276. });
  277. $('.tr_profit_value').each(function (index, dom) {
  278. var tr_all_3 = $(this).html();
  279. all_3 += tr_all_3 - 0;
  280. });
  281. $('.tr_all_commission').each(function (index, dom) {
  282. var tr_all_4 = $(this).html();
  283. all_4 += tr_all_4 - 0;
  284. });
  285. if (isNaN(all_1)) all_1 = 0;
  286. if (isNaN(all_2)) all_2 = 0;
  287. if (isNaN(all_3)) all_3 = 0;
  288. if (isNaN(all_4)) all_3 = 0;
  289. $('#all_price').html(all_1.toFixed(2) + '元');
  290. $('#all_price').attr('data-value', all_1.toFixed(2));
  291. $('#all_commission').html(all_4.toFixed(2) + '元');
  292. $('#all_commission').attr('data-value', all_4.toFixed(2));
  293. $('#profit_value').html(all_3.toFixed(2) + '元');
  294. $('#profit_value').attr('data-value', all_3.toFixed(2));
  295. $('#mid_all_commission').html(all_2.toFixed(2) + '元');
  296. $('#mid_all_commission').attr('data-value', all_2.toFixed(2));
  297. }
  298. $('.comment-type').click(function () {
  299. $(this).addClass('btn-default').siblings('div').removeClass('btn-default');
  300. });
  301. $('#btn-order-remark-save-update-d').click(function () {
  302. var comment_type = $('#comment-type-val').val();
  303. var comment_txt = $('#comment-txt').val().trim(' ');
  304. if (comment_txt == null || comment_txt == 0) {
  305. z.pjaxFinish('warning', '备注内容不能为空');
  306. return false;
  307. }
  308. $.pjax.reload({
  309. container: '#comment-table',
  310. url: '/hotel/ordermain/comment',
  311. data: {order_id: order_id, comment_type: comment_type, comment_txt: comment_txt},
  312. replace: false,
  313. timeout: false
  314. })
  315. });
  316. $('.remove-item').click(function () {
  317. var comment_id = $(this).attr('data-value');
  318. $.pjax.reload({
  319. container: '#comment-table',
  320. url: '/hotel/ordermain/del-comment',
  321. data: {order_id: order_id, comment_id: comment_id},
  322. replace: false,
  323. timeout: false
  324. })
  325. });
  326. /*修改入住需求 end*/
  327. $('#btn-rz-update-xq').on('click', function () {
  328. //1:修改入住需求 2:保存并生成修改单 3:保存
  329. var btn_status = $(this).attr('data-btn-status') ? $(this).attr('data-btn-status') : "1";
  330. if ('1' == btn_status) {
  331. checkin_copy = $("#stroke_tbody").children().clone();
  332. var room_num = $('#total_room_count').html();
  333. // ZZLog('修改入住需求');
  334. $('#btn-rz-cancel').attr('data-main-status', '1');
  335. $('#btn-rz-cancel').removeClass('hide_f');
  336. $('#btn-rz-update-xsj').addClass('hide_f');
  337. $('#btn-rz-update-cgj').addClass('hide_f');
  338. //切换编辑状态
  339. // $('.update1_h').removeClass('hide_f');
  340. $('.update1_rz').css('display', 'inherit');
  341. $('.update1_s').css('display', 'none');
  342. // $('.update1_s').addClass('hide_f');
  343. $(this).attr('data-btn-status', '2');
  344. $(this).html(save_update_info);
  345. // 获取库存数量
  346. var param = {"RoomID": hotel_room_id, "DistribID": channel_id, "CheckIn": checkin_date, "CheckOut": checkout_date};
  347. $.post('/hotel/api/get-stock', param, function (data) {
  348. var info = JSON.parse(data);
  349. // 处理库存返回结果
  350. if (info.code == 0) {
  351. var option = '<option value="0">0</option>';
  352. for (var i = 1; i <= info.data; i++) {
  353. option += '<option value="' + i + '">' + i + '</option>';
  354. }
  355. $('#min_room_count').html(option);
  356. $('#min_room_count').val(room_num);
  357. }
  358. }, 'json');
  359. }
  360. if ('2' == btn_status || "3" == btn_status) {
  361. // ZZLog('保存入住需求');
  362. updateOrderInfo();
  363. }
  364. })
  365. //修改销售价
  366. $('#btn-rz-update-xsj').click(function () {
  367. //1:修改销售价 2:保存销售价
  368. var btn_status = $(this).attr('data-btn-status') ? $(this).attr('data-btn-status') : "1";
  369. if ('1' == btn_status) {
  370. // ZZLog('修改销售价');
  371. checkin_copy = $("#stroke_tbody").children().clone();
  372. $('#btn-rz-cancel').attr('data-main-status', '2');
  373. $('#btn-rz-cancel').removeClass('hide_f');
  374. $('#btn-rz-update-xq').addClass('hide_f');
  375. $('#btn-rz-update-cgj').addClass('hide_f');
  376. $(this).attr('data-btn-status', '2');
  377. $(this).html(save_info);
  378. //切换编辑状态
  379. $('.update2_h').removeClass('hide_f');
  380. $('.update2_s').addClass('hide_f');
  381. // changeStartEndDateXSJ();
  382. }
  383. if ('2' == btn_status) {
  384. // ZZLog('保存销售价');
  385. //在这里写保存的操作
  386. $('#btn-rz-cancel').addClass('hide_f');
  387. $('#btn-rz-update-xq').removeClass('hide_f');
  388. $('#btn-rz-update-cgj').removeClass('hide_f');
  389. $(this).attr('data-btn-status', '1');
  390. $(this).html('修改销售价');
  391. //浏览状态
  392. $('.update2_h').addClass('hide_f');
  393. $('.update2_s').removeClass('hide_f');
  394. loading();
  395. var cus_list = [];
  396. $('.tr_line').each(function () {
  397. var run_date = $(this).children('td').find('.room_run_date').html();//.children().val(); //.children('input').val();
  398. var sale_price = $(this).children('td').find('.tr_single_price').val();
  399. var obj = {run_date: run_date, sale_price: sale_price};
  400. cus_list.push(obj);
  401. });
  402. var data = JSON.stringify(cus_list);
  403. $.post('/hotel/ordermain/update-sale-price', {data: data, order_id: order_id}, function (data) {
  404. if (data.code != 0) {
  405. ZZAlertInfo(data.info, function () {
  406. closeLoading();
  407. });
  408. } else {
  409. document.location.reload();
  410. }
  411. }, 'json');
  412. }
  413. })
  414. //修改采购价
  415. $('#btn-rz-update-cgj').click(function () {
  416. //1:修改采购价 2:保存并生成修改单 3:保存采购价
  417. var btn_status = $(this).attr('data-btn-status') ? $(this).attr('data-btn-status') : "1";
  418. if ('1' == btn_status) {
  419. // ZZLog('修改采购价');
  420. checkin_copy = $("#stroke_tbody").children().clone();
  421. $('#btn-rz-cancel').attr('data-main-status', '3');
  422. $('#btn-rz-cancel').removeClass('hide_f');
  423. $('#btn-rz-update-xq').addClass('hide_f');
  424. $('#btn-rz-update-xsj').addClass('hide_f');
  425. //切换编辑状态
  426. $('.update3_h').removeClass('hide_f');
  427. $('.update3_s').addClass('hide_f');
  428. $(this).attr('data-btn-status', '3');
  429. $(this).html(save_info);
  430. // click_three_btn($(this));
  431. }
  432. if ('2' == btn_status || "3" == btn_status) {
  433. loading();
  434. $('#btn-rz-cancel').addClass('hide_f');
  435. $('#btn-rz-update-xq').removeClass('hide_f');
  436. $('#btn-rz-update-xsj').removeClass('hide_f');
  437. $(this).attr('data-btn-status', '1');
  438. $(this).html('修改采购价');
  439. //浏览状态
  440. $('.update3_h').addClass('hide_f');
  441. $('.update3_s').removeClass('hide_f');
  442. var cus_list = [];
  443. var tr = $('.tr_line');
  444. tr.each(function () {
  445. var run_date = $(this).children('td').find('.room_run_date').html();//.children().val(); //.children('input').val();
  446. var base_price = $(this).children('td').find('.cai_base_price').val();
  447. var obj = {run_date: run_date, base_price: base_price};
  448. cus_list.push(obj);
  449. });
  450. var data = JSON.stringify(cus_list);
  451. $.post('/hotel/ordermain/update-purchase-price', {data: data, order_id: order_id}, function (data) {
  452. if (data.code == 0) {
  453. document.location.reload();
  454. closeLoading();
  455. } else {
  456. // todo 弹框提示修改失败
  457. console.log(data);
  458. closeLoading();
  459. }
  460. }, 'json');
  461. }
  462. })
  463. function getRoomPriceList() {
  464. var days = DateDiff(start_date, end_date);
  465. $('#datediff').html(`共${days}晚`);
  466. }
  467. //计算天数差的函数,通用
  468. function DateDiff(sDate1, sDate2) { //sDate1和sDate2是2002-12-18格式
  469. var aDate, oDate1, oDate2, iDays
  470. aDate = sDate1.split("-")
  471. oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为12-18-2002格式
  472. aDate = sDate2.split("-")
  473. oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
  474. iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数
  475. return iDays
  476. }
  477. function changeStartEndDate(org_id) {
  478. var start_date = $('#start_date').find('input').val();
  479. var end_date = $('#end_date').find('input').val();
  480. $('#start_date_txt').html(start_date);
  481. $('#end_date_txt').html(end_date);
  482. var room_num = $('#min_room_count').val();
  483. if (room_num != 0) {
  484. $('#total_room_count').html(room_num);
  485. } else {
  486. room_num = $('#total_room_count').html();
  487. }
  488. var channel_num = org_id || channel_id;
  489. var days = DateDiff(start_date, end_date);
  490. $('#datediff').html("共" + days + "晚");
  491. var flag = false;
  492. var param = {"RoomID": hotel_room_id, "DistribID": channel_num, "CheckIn": start_date, "CheckOut": end_date};
  493. $.ajax({
  494. type: "POST",
  495. url: "/hotel/api/get-stock",
  496. data: param,
  497. async: false,
  498. dataType: 'json',
  499. success: function (data) {
  500. var info = JSON.parse(data);
  501. // 处理库存返回结果
  502. if (info.code == 0) {
  503. var option = '<option value="0">0</option>';
  504. for (var i = 1; i <= info.data; i++) {
  505. option += '<option value="' + i + '">' + i + '</option>';
  506. }
  507. $('#min_room_count').html(option);
  508. $('#min_room_count').val(room_num);
  509. }
  510. if (info.data == 0) {
  511. flag = true;
  512. }
  513. }
  514. });
  515. if (flag) return false;
  516. // ZZLog(JSON.stringify(data));
  517. // loading();
  518. var param = {
  519. "RoomNum": room_num,
  520. "RoomID": hotel_room_id,
  521. "DistribID": channel_num,
  522. "CheckIn": start_date,
  523. "CheckOut": end_date
  524. };
  525. $.ajax({
  526. type: "post",
  527. url: '/hotel/ordermain/get-price-list',
  528. async: true,
  529. data: param,
  530. dataType: "json",
  531. success: function (res_data) {
  532. // ZZLog(res_data);
  533. // data = JSON.parse(res_data);
  534. if (res_data.code != "0") {
  535. ZZAlertInfo(res_data.info, function () {
  536. closeLoading();
  537. });
  538. }
  539. else {
  540. loadStockHtml(res_data.data);
  541. closeLoading();
  542. }
  543. },
  544. error: function () {
  545. ZZAlertInfo(infoApiError, function () {
  546. closeLoading();
  547. });
  548. }
  549. });
  550. }
  551. function loadStockHtml(stock_list) {
  552. var room_count = $('#min_room_count').val();
  553. var checin_copy = $('#stroke_tbody').children().clone();
  554. var sumHTML = '';
  555. stock_list.forEach(function (v, i) {
  556. var HTML = `<tr class="tr_line" height="30" data-json=[data-json] data-json-maiduan=[data-json-maiduan] data-json-baoliu=[data-json-baoliu] data-json-xianxun=[data-json-xianxun]>
  557. <td><span class="room_run_date">[入住日期]</span></td>
  558. <td>
  559. <span class="update2_s sale_single_price">[销售单价]</span>
  560. <span class="hide_f update2_h">
  561. <input name="OrderMain[ORDER_PRICE]" data-price="[销售单价]" type="text" class="form-control tr_single_price" style="width: 80px;" value="[销售单价]">
  562. </span>
  563. </td>
  564. <td>
  565. <span class="update3_s cai_base_price_txt">[采购成本价]</span>
  566. <span class="hide_f update3_h">
  567. <input name="OrderMain[BASE_PRICE]" data-price="[采购成本价1]" type="text" class="form-control cai_base_price" style="width: 80px;" value="[采购成本价1]">
  568. </span>
  569. </td>
  570. <td class="tr_all_price">[销售总价]</th>
  571. <td class="tr_mid_price" data-commission=0.00>0.00</th>
  572. <td class="tr_all_commission" data-commission=[渠道佣金]>[渠道佣金]</th>
  573. <td class="tr_profit_value">[利润]</th>
  574. </tr>`;
  575. var order_price = (v['CUS_PRICE'] == 0) ? v['PROD_PRICE'] : v['CUS_PRICE'];
  576. var total_order_price = (order_price * room_count).toFixed(2);
  577. HTML = HTML.replace('[入住日期]', v['RUN_DATE']);
  578. HTML = HTML.replace('[间数1]', room_count);
  579. HTML = HTML.replace('[销售单价]', order_price);
  580. HTML = HTML.replace(/\[销售单价]/g, order_price);
  581. HTML = HTML.replace('[销售总价]', total_order_price);
  582. HTML = HTML.replace('[data-json]', v);
  583. //计算佣金
  584. var commsion_price = getCommision(room_count, order_price, v).toFixed(2);
  585. // HTML = HTML.replace('[渠道佣金]', commsion_price);
  586. HTML = HTML.replace(/\[渠道佣金]/g, commsion_price);
  587. // HTML = HTML.replace('[销售单价]', order_price * );
  588. //得到替换数量,逻辑:先判断超售oversell_flag,1为可以超售,如果可以超售则取data['order_list'][1]中的该天所有库存,超了不能下单。
  589. var base_price_str = 0;
  590. var base_price = 0;
  591. if (parseInt(room_count) <= parseInt(v['BUYOUT'])) {
  592. base_price = v['BASE_PRICE_BUYOUT'];
  593. base_price_str = room_count + '*' + v['BASE_PRICE_BUYOUT'] + '/' + room_count;
  594. } else if (parseInt(room_count) <= parseInt(v['BUYOUT']) + parseInt(v['RETAIN'])) {
  595. base_price = (v['BUYOUT'] * v['BASE_PRICE_BUYOUT'] + (room_count - v['BUYOUT']) * v['BASE_PRICE_RESERVE']) / room_count;
  596. base_price_str = '(' + v['BUYOUT'] + '*' + v['BASE_PRICE_BUYOUT'] + '+ (' + room_count + '-' + v['BUYOUT'] + ') *' + v['BASE_PRICE_RESERVE'] + ')/' + room_count;
  597. }
  598. else if (parseInt(room_count) <= parseInt(v['BUYOUT']) + parseInt(v['RETAIN']) + parseInt(v['INQUIRY'])) {
  599. base_price = (v['BUYOUT'] * v['BASE_PRICE_BUYOUT'] + v['RETAIN'] * v['BASE_PRICE_RESERVE'] + (room_count - v['BUYOUT'] - v['RETAIN']) * v['BASE_PRICE_INQUIRY'] ) / room_count;
  600. base_price_str = '(' + v['BUYOUT'] + '*' + v['BASE_PRICE_BUYOUT'] + '+' + v['RETAIN'] + '*' + v['BASE_PRICE_RESERVE'] + '+(' + room_count + '-' + v['BUYOUT'] + '-' + v['RETAIN'] + ') *' + v['BASE_PRICE_INQUIRY'] + ')/' + room_count;
  601. }
  602. base_price = Number(base_price).toFixed(2);
  603. // HTML = HTML.replace('[采购成本价]', base_price+'(' + base_price_str + ')');
  604. HTML = HTML.replace('[采购成本价]', base_price);
  605. HTML = HTML.replace(/\[采购成本价1]/g, base_price);
  606. var unit_profit = ((order_price - base_price) * room_count).toFixed(2); // 销售总利润
  607. HTML = HTML.replace('[利润]', unit_profit);
  608. sumHTML += HTML;
  609. });
  610. sumHTML += `<tr>
  611. <th class="" colspan="3"> 小计</th>
  612. <th style="text-align: right" class="th_footer"><span id="all_price"></span></th>
  613. <th style="text-align: right" class="th_footer"><span id="mid_all_commission"></span></th>
  614. <th style="text-align: right" class="th_footer"><span id="all_commission"></span></th>
  615. <th style="text-align: right" class="th_footer"><span id="profit_value"></span></th>
  616. </tr>`;
  617. $('#stroke_tbody').html(sumHTML);
  618. sum_price();
  619. }
  620. $('#update-customer-info').click(function () {
  621. $(this).addClass('hide_f');
  622. $('.border-style').css('border-width', '1');
  623. $('.update-customer-info').removeClass('hide_f');
  624. });
  625. $('#btn-customer-cancel').click(function () {
  626. $('.update-customer-info').addClass('hide_f');
  627. $('.border-style').css('border-width', '0');
  628. $('#update-customer-info').removeClass('hide_f');
  629. $('#customer').find('input').focus().blur();
  630. });
  631. // 佣金规则计算
  632. function getCommision(room_count, room_price, dict) {
  633. // 佣金规则
  634. var commision_price = 0;
  635. if (dict['COMMISION_FLAG'] == '1') { //有佣金规则
  636. if (dict['BACK_COMMISION_METHOD'] == '309') { //308 按销售金额309 按结算金额
  637. commision_price = room_count * dict['BACK_VALUE'];
  638. } else if (dict['BACK_COMMISION_METHOD'] == '308') {
  639. commision_price = room_count * room_price * parseFloat(dict['BACK_PERCENT']) / 100;
  640. }
  641. } else { //无佣金规则
  642. commision_price = 0;
  643. }
  644. return commision_price;
  645. }
  646. // getProductInfo();
  647. $("#datetimeStart").datetimepicker({
  648. format: 'yyyy-mm-dd',
  649. minView: 'month',
  650. language: 'zh-CN',
  651. autoclose: true,
  652. todayHighlight: true
  653. }).on("click", function () {
  654. $("#datetimeStart").datetimepicker("setEndDate", $("#datetimeEnd").val())
  655. });
  656. $("#datetimeEnd").datetimepicker({
  657. format: 'yyyy-mm-dd',
  658. minView: 'month',
  659. language: 'zh-CN',
  660. autoclose: true,
  661. todayHighlight: true
  662. }).on("click", function () {
  663. $("#datetimeEnd").datetimepicker("setStartDate", addDate($("#datetimeStart").val(), 1))
  664. });
  665. function minusDate(date, days) {
  666. if (days == undefined || days == '') {
  667. days = 1;
  668. }
  669. var date = new Date(date);
  670. date.setDate(date.getDate() - days);
  671. var month = date.getMonth() + 1;
  672. var day = date.getDate();
  673. return date.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day);
  674. }
  675. function addDate(date, days) {
  676. if (days == undefined || days == '') {
  677. days = 1;
  678. }
  679. var date = new Date(date);
  680. date.setDate(date.getDate() + days);
  681. var month = date.getMonth() + 1;
  682. var day = date.getDate();
  683. return date.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day);
  684. }
  685. // 日期月份/天的显示,如果是1位数,则在前面加上'0'
  686. function getFormatDate(arg) {
  687. if (arg == undefined || arg == '') {
  688. return '';
  689. }
  690. var re = arg + '';
  691. if (re.length < 2) {
  692. re = '0' + re;
  693. }
  694. return re;
  695. }
  696. $('.comment-type').click(function () {
  697. var type = $(this).attr('data-value');
  698. $('#comment-type-val').val(type);
  699. });