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.

hotel_modify_order.js 29 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /**
  2. * Created by luocj on 2016/9/29.
  3. */
  4. var tbodyHTML = '';
  5. var order_detail;
  6. var tr = $('.tr_str').prop('outerHTML');
  7. var hotel_name = getPar('hotel_name');
  8. var product_name = getPar('product_name');
  9. var hotel_id = getPar('hotel_id');
  10. var room_type = getPar('room_type');
  11. var parent_room_type = getPar('parent_room_type'); //基础房型
  12. var start_date = '';
  13. var end_date = '';
  14. var org_id = getPar('org_id');
  15. var org_list = '';
  16. var order_list = '';
  17. var order_id = getPar('order_id');
  18. var org_name = getPar('org_name');
  19. var all_order_detail = '';
  20. var all_money_sum = '';
  21. var benefit_sum = '';
  22. //总佣金,总结算,总利润
  23. var all_yongj = 0;
  24. var all_jiesuan = 0;
  25. var all_profit = 0;
  26. var _old_data = {
  27. org_id: '',
  28. org_num: '',
  29. contact: '',
  30. mobile: '',
  31. start_date: '',
  32. // end_date: '',
  33. total: '',
  34. memo: '',
  35. amount: 0
  36. };
  37. //原订单日期对应库存类型及其数量
  38. var _old_stock = [];
  39. var load_detail_finished = false,
  40. load_finished = false;
  41. window.onload = function () {
  42. tbodyHTML = $('#make_order_list').html();
  43. start_date = $('#start_date').val();
  44. end_date = $('#end_date').val();
  45. getOrgList();
  46. getOrderDetail();
  47. //可选库存具体数量,需要等待原订单库存的数据,再加上
  48. getOrderStatus();
  49. };
  50. // 获取渠道
  51. function getOrgList() {
  52. var url = base_api + "?type=order_MakeHTOrder&op=org_list";
  53. ZZLog(url);
  54. load_finished = false;
  55. $.getJSON(url, function (data) {
  56. ZZLog(data);
  57. if (data['code'] != "0") {
  58. alert(data['info']);
  59. } else {
  60. var outHTML = '<option id=0 value="-1" style=font-size: 12px;>请选择</option>';
  61. org_list = data['org_list'];
  62. for (var i = 0; i < org_list.length; i++) {
  63. var HTML = '<option id=0>请选择</option>';
  64. var dict = org_list[i];
  65. HTML = HTML.replace('请选择', dict['org_name']);
  66. if (dict['org_id'] == org_id) {
  67. HTML = HTML.replace("id=0", "id=" + dict['org_id'] + " value=" + dict['org_id'] + " selected=selected");
  68. } else {
  69. HTML = HTML.replace("id=0", "id=" + dict['org_id'] + " value=" + dict['org_id']);
  70. }
  71. outHTML += HTML
  72. }
  73. $('#org_id').html(outHTML);
  74. $('.select_line').comboSelect();
  75. }
  76. load_finished = true;
  77. })
  78. }
  79. var refuse_flag = '';
  80. //获取订单详情
  81. function getOrderDetail() {
  82. load_detail_finished = false;
  83. start_date = $('#start_date').val();
  84. end_date = $('#end_date').val();
  85. var url = base_api + "?type=order_ModifyHTOrder&op=order_list&start_date=" + start_date + "&end_date=" + end_date + "&hotel_id=" + hotel_id + "&room_type=" + room_type + "&org_id=" + org_id + "&order_id=" + order_id;
  86. ZZLog(url);
  87. $.getJSON(url, function (data) {
  88. ZZLog(data);
  89. all_order_detail = data;
  90. order_detail = data;
  91. initOldData(data);
  92. //对
  93. $.each(data['hotel_child_order_detail'], function (key, item) {
  94. _old_stock.push({'date': item['run_date'], 'stock_type': item['stock_type'], 'stock_count': item['total']})
  95. })
  96. var main_order = data['hotel_order_detail'][0];
  97. var hotel_name = main_order['hotel_name'];
  98. refuse_flag = main_order['refuse_flag'];
  99. var product_name = main_order['product_name'];
  100. var order_status = main_order['order_status'];
  101. var customer_name = main_order['customer_name'];
  102. var customer_mobile = main_order['customer_mobile'];
  103. var customer_memo = main_order['customer_memo'];
  104. var checkin_time = data['hotel_child_order_detail'][0]['checkin_time'];
  105. var org_id = getPar('org_id');
  106. var start_date = data['hotel_child_order_detail'][0]['run_date'];
  107. var end_date = getDateByDay(1, data['hotel_child_order_detail'][data['hotel_child_order_detail'].length - 1]['run_date']);
  108. $('#start_date').val(start_date);
  109. $('#end_date').val(end_date);
  110. $('#hotel_name').html(hotel_name);
  111. $('#product_name').html(product_name);
  112. $('#org_name').html('订单渠道: ' + org_name);
  113. $('#order_id').html('订 单 号: ' + order_id);
  114. if (order_status == 145) {
  115. $('#order_status').html('待支付');
  116. } else if (order_status == 313) {
  117. $('#order_status').html('待发单');
  118. } else if (order_status == 198) {
  119. $('#order_status').html('待确认');
  120. } else if (order_status == 314) {
  121. $('#order_status').html('已安排');
  122. } else if (order_status == 147) {
  123. $('#order_status').html('已完成');
  124. } else if (order_status == 148) {
  125. $('#order_status').html('已取消');
  126. } else if (order_status == 382) {
  127. $('#order_status').html('异常处理待发单');
  128. }
  129. //下方
  130. $('#org_num').val(main_order['outside_order_no']);
  131. $('#org_id').val(org_id);
  132. $('#contacts').val(customer_name);
  133. $('#phone').val(customer_mobile);
  134. var notes = customer_memo.split('||');
  135. var user_org_id = getCookie('user_org_id');
  136. $.each(notes, function (key, item) {
  137. if (item != '') {
  138. var tmp = item.split('|');
  139. var note = '<div style="margin-top: 20px" class="note"><span style="width: 80px;display: inline-block"></span>';
  140. //不同用户登录,显示不同内容
  141. var display = 'none';
  142. if (user_org_id == 0) {
  143. display = 'inline-block';
  144. }
  145. var selected = '';
  146. if (tmp[2] == 1)
  147. selected = 'selected';
  148. note += ' <select disabled name="note[type][]" style="display: ' + display + ';"><option value="0">公共备注</option><option ' + selected + ' value="1">内部备注</option></select>';
  149. // }
  150. note += ' <input name="note[text][]" type="text" style="width: 300px;height: 30px;font-size: 13px;color: inherit" placeholder="填写备注" disabled value="' + tmp[3] +
  151. '"/><input type="hidden" name="edit_user_id" value="' + tmp[0] + '" /><input type="hidden" name="edit_time" value="' + tmp[1] + '" /> ';
  152. var user_id = getCookie('user_id');
  153. if ($.inArray(parseInt(user_id), [1, 35, 160]) >= 0)
  154. note += ' <a href="javascript:;" onclick="removeNote(this, true)" >删除</a>';
  155. note += '</div>';
  156. if (user_org_id == 0 || tmp[2] == 0)
  157. $(".note:last").after(note);
  158. }
  159. })
  160. $('#more').val(customer_memo);
  161. lastchecktime();
  162. $('#time').val(checkin_time);
  163. timeDiff();
  164. //获取订单列表
  165. //getOrderList()
  166. load_detail_finished = true;
  167. })
  168. }
  169. //获取可下库存
  170. function getRoomStock() {
  171. var url = base_api + "?type=order_ModifyHTOrder&op=stock_list&hotel_id=" + hotel_id + "&parent_room_type=" + parent_room_type + "&room_type=" + room_type
  172. + "&org_id=" + org_id + "&start_date=" + start_date + "&end_date=" + end_date;
  173. // ZZLog(url);
  174. $.getJSON(url, function (data) {
  175. ZZLog(data);
  176. if (data['code'] != 0) {
  177. ZZAlertInfo(data['info'], function () {
  178. return;
  179. });
  180. } else {
  181. setDataHTML(data)
  182. updateStock();
  183. }
  184. }).error(function (data) {
  185. })
  186. }
  187. //页面数据替换
  188. function setDataHTML(data) {
  189. var sumHTML = '';
  190. for (var i = 0; i < data['order_list'][0].length; i++) {
  191. var dict = data['order_list'][0][i];
  192. var HTML = tr;
  193. //替换入住日期
  194. HTML = HTML.replace('[入住日期]', dict['run_date']);
  195. //end 替换入住日期
  196. //替换数量
  197. //得到替换数量,逻辑:先判断超售oversell_flag,1为可以超售,如果可以超售则取data['order_list'][1]中的该天所有库存,超了不能下单。
  198. var count = 0;
  199. if (dict['oversell_flag'] == 1 && dict['remaining_count'] != -1) {
  200. for (var j = 0; j < data['order_list'][1].length; j++) {
  201. var dict1 = data['order_list'][1][j];
  202. if (dict['run_date'] == dict1['run_date']) {
  203. count += parseInt(dict1['remaining_count']);
  204. // ZZLog(dict1);
  205. //将调用超售库存的信息放入data-json-baoliu,maiduan,xianxun
  206. if (dict1['stock_type'] == '228') {//买断
  207. HTML = HTML.replace('[data-json-maiduan]', setJsonHtml(dict1))
  208. } else if (dict1['stock_type'] == '229') {//现询
  209. HTML = HTML.replace('[data-json-xianxun]', setJsonHtml(dict1))
  210. } else if (dict1['stock_type'] == '230') {//保留
  211. HTML = HTML.replace('[data-json-baoliu]', setJsonHtml(dict1))
  212. } else {
  213. ZZAlertInfo('没有该库存类型');
  214. }
  215. }
  216. }
  217. } else {
  218. for (var j = 0; j < data['order_list'][1].length; j++) {
  219. var dict1 = data['order_list'][1][j];
  220. if (dict['run_date'] == dict1['run_date']) {
  221. // ZZLog(dict1);
  222. //将调用超售库存的信息放入data-json-baoliu,maiduan,xianxun
  223. if (dict1['stock_type'] == '228') {//买断
  224. count += parseInt(dict1['remaining_count']);
  225. HTML = HTML.replace('[data-json-maiduan]', setJsonHtml(dict1))
  226. } else if (dict1['stock_type'] == '229') {//现询
  227. HTML = HTML.replace('[data-json-xianxun]', setJsonHtml(dict1))
  228. } else if (dict1['stock_type'] == '230') {//保留
  229. count += parseInt(dict1['remaining_count']);
  230. HTML = HTML.replace('[data-json-baoliu]', setJsonHtml(dict1))
  231. } else {
  232. ZZAlertInfo('没有该库存类型');
  233. }
  234. }
  235. }
  236. count = parseInt(dict['remaining_count'] == -1 ? 0 : dict['remaining_count'])
  237. }
  238. // ZZLog(count);
  239. //end 得到替换数量
  240. //循环替换数量
  241. var selHTML = '<select onchange="changeCount(this)" class="prod_count" style="width: 40px">';
  242. for (var m = 0; m <= count; m++) {
  243. if (m > 20) {
  244. break;
  245. }
  246. var temp = "<option value='" + m + "'>" + m + "</option>";
  247. selHTML += temp;
  248. }
  249. selHTML += '</select>';
  250. HTML = HTML.replace('[数量]', selHTML);
  251. //end 替换数量
  252. //结算价替换
  253. HTML = HTML.replace('[结算价]', '<input type="text" oninput="changeCount(this)" class="prod_price" style="width: 60px" value="' + dict['price'] + '">')
  254. //end 结算价替换
  255. //佣金规则
  256. var ling = 0;
  257. var ling1 = ling.toFixed(2);
  258. if (dict['commision_flag'] == 0) {//为0不返佣,为1返佣
  259. HTML = HTML.replace('[佣金]', '-');
  260. } else {
  261. HTML = HTML.replace('[佣金]', ling1);
  262. }
  263. //end 佣金规则
  264. HTML = HTML.replace('[结算价总额]', ling1);
  265. HTML = HTML.replace('[销售利润]', ling1);
  266. //将非超卖库存存入data-json
  267. HTML = HTML.replace('[data-json]', setJsonHtml(dict));
  268. sumHTML += HTML
  269. }
  270. $('#make_order_list').html(sumHTML);
  271. if (sumHTML) {
  272. $('#make_table').show();
  273. } else {
  274. $('#make_table').hide();
  275. }
  276. var data_detail = order_detail;
  277. $.each($("#make_order_list tr"), function (key, tr) {
  278. for (var n = 0; n < data_detail['hotel_child_order_detail'].length; n++) {
  279. if (data_detail['hotel_child_order_detail'][n]['run_date'] == $(tr).find("td:first").text()) {
  280. $(tr).find(".prod_price").val(data_detail['hotel_child_order_detail'][n]['order_price']);
  281. }
  282. }
  283. });
  284. //刷新总计
  285. all_sum();
  286. }
  287. //获取时差并获取相应时间的订单
  288. function timeDiff() {
  289. var start = $("#start_date").val();
  290. var end = $("#end_date").val();
  291. start = start.replace(/-/g, "/");
  292. var startdate = new Date(start);
  293. end = end.replace(/-/g, "/");
  294. var enddate = new Date(end);
  295. var time = enddate.getTime() - startdate.getTime();
  296. var days = parseInt(time / (1000 * 60 * 60 * 24));
  297. $('#datediff').html('共 ' + days + ' 晚');
  298. // alert(days);
  299. start_date = $('#start_date').val();
  300. end_date = $('#end_date').val();
  301. org_id = $('#org_id').val();
  302. getRoomStock();
  303. }
  304. var yongj = '';
  305. //改变产品数量与结算价
  306. function changeCount(obj) {
  307. // 房间数量
  308. var room_count = $(obj).closest('tr').find('.prod_count').val();
  309. // 结算单价
  310. var room_price = $(obj).closest('tr').find('.prod_price').val();
  311. // 佣金规则
  312. var dict = getJsonHtml($(obj).closest('tr').attr('data-json'));
  313. var dict_maiduan = getJsonHtml($(obj).closest('tr').attr('data-json-maiduan'));
  314. var dict_baoliu = getJsonHtml($(obj).closest('tr').attr('data-json-baoliu'));
  315. var dict_xianxun = getJsonHtml($(obj).closest('tr').attr('data-json-xianxun'));
  316. var commision_price = 0;
  317. if (dict['commision_flag'] == '1') {//有佣金规则
  318. if (dict['back_commision_method'] == '309') {//308 按销售金额309 按结算金额
  319. commision_price = dict['back_value']
  320. } else if (dict['back_commision_method'] == '308') {
  321. commision_price = room_count * room_price * parseFloat(dict['back_percent']) / 100;
  322. }
  323. } else {//无佣金规则
  324. commision_price = 0;
  325. }
  326. //end 佣金规则
  327. //结算总价
  328. var jiesuan_price = room_count * room_price;
  329. //end 结算总价
  330. //库存类型与成本
  331. var maiduan_count = dict_maiduan['remaining_count'] == undefined ? 0 : dict_maiduan['remaining_count'];
  332. var baoliu_count = dict_baoliu['remaining_count'] == undefined ? 0 : dict_baoliu['remaining_count'];
  333. var xianxun_count = dict_xianxun['remaining_count'] == undefined ? 0 : dict_xianxun['remaining_count'];
  334. var maiduan_price = dict_maiduan['cost_price'] == undefined ? 0 : dict_maiduan['cost_price'];
  335. var baoliu_price = dict_baoliu['cost_price'] == undefined ? 0 : dict_baoliu['cost_price'];
  336. var xianxun_price = dict_xianxun['cost_price'] == undefined ? 0 : dict_xianxun['cost_price'];
  337. //end 库存类型与成本
  338. //销售利润
  339. var profit = 0;
  340. if (parseInt(room_count) <= parseInt(maiduan_count)) {//所选房间数小于等于买断数
  341. profit = jiesuan_price - commision_price - maiduan_price * room_count
  342. } else if (parseInt(room_count) > parseInt(maiduan_count) && parseInt(room_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count))) { //所选房间数大于买断数,小于等于保留数+买断数
  343. profit = jiesuan_price - commision_price - maiduan_price * maiduan_count - baoliu_price * (room_count - maiduan_count)
  344. } else if (parseInt(room_count) > (parseInt(maiduan_count) + parseInt(baoliu_count)) && parseInt(room_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count) + parseInt(xianxun_count))) {
  345. profit = jiesuan_price - commision_price - maiduan_price * maiduan_count - baoliu_price * baoliu_count - xianxun_price * (room_count - maiduan_count - baoliu_count)
  346. }
  347. //end 销售利润
  348. //佣金显示
  349. var commision_price1 = parseFloat(commision_price).toFixed(2);
  350. if (dict['commision_flag'] == 1) {
  351. $(obj).closest('tr').find('.yongj_sum').text(commision_price1);
  352. } else {
  353. $(obj).closest('tr').find('.yongj_sum').text('-');
  354. }
  355. //结算总价显示
  356. var jiesuan_price1 = parseFloat(jiesuan_price).toFixed(2);
  357. if (jiesuan_price1) {
  358. $(obj).closest('tr').children().eq(4).text(jiesuan_price1);
  359. }
  360. //销售利润显示
  361. var profit1 = parseFloat(profit).toFixed(2);
  362. if (profit1) {
  363. $(obj).closest('tr').children().eq(5).text(profit1);
  364. }
  365. //总计
  366. all_sum();
  367. }
  368. //获取最晚到店时间
  369. function lastchecktime() {
  370. var sumHTML = '';
  371. for (var i = 1; i <= 23; i++) {
  372. var HTML = '<option>24:00</option>';
  373. HTML = HTML.replace('<option>24:00</option>', '<option value="' + i + ':00">' + i + ':00</option>')
  374. sumHTML += HTML;
  375. }
  376. $('#time').html(sumHTML);
  377. }
  378. //获取上方状态栏
  379. function getOrderStatus() {
  380. var url = base_api;
  381. var param = {
  382. type: "order_ModifyHTOrder",
  383. op: "order_status",
  384. order_id: order_id
  385. }
  386. $.ajax({
  387. url: url,
  388. type: "post",
  389. dataType: "json",
  390. data: param,
  391. success: function (res_data) {
  392. ZZLog(res_data);
  393. for (var i = 0; i < res_data['order_status'].length; i++) {
  394. var dict = res_data['order_status'][i];
  395. var temp_date = dict['create_time'].split(" ");
  396. var date = temp_date[0];
  397. var time = temp_date[1];
  398. if (dict['order_status_name'] == "待支付") {
  399. $('li[data-target="#step1"]').addClass('active');
  400. $('li[data-target="#step2"]').addClass('active');
  401. $('#create_date').text(date);
  402. $('#create_time').text(time);
  403. $('#pay_date').text(date);
  404. $('#pay_time').text(time);
  405. } else if (dict['order_status_name'] == "待发单") {
  406. $('li[data-target="#step1"]').addClass('active');
  407. $('li[data-target="#step2"]').addClass('active');
  408. $('#create_date').text(date);
  409. $('#create_time').text(time);
  410. $('#pay_date').text(date);
  411. $('#pay_time').text(time);
  412. } else if (dict['order_status_name'] == "待确认") {
  413. $('li[data-target="#step3"]').addClass('active');
  414. $('#send_date').text(date);
  415. $('#send_time').text(time);
  416. } else if (dict['order_status_name'] == "已安排") {
  417. $('li[data-target="#step4"]').addClass('active');
  418. $('#arr_date').text(date);
  419. $('#arr_time').text(time);
  420. } else if (dict['order_status_name'] == "已完成") {
  421. $('li[data-target="#step5"]').addClass('active');
  422. $('#finish_date').text(date);
  423. $('#finish_time').text(time);
  424. } else {
  425. }
  426. }
  427. }
  428. })
  429. }
  430. //提交
  431. function commit() {
  432. if ($('#button').text() == '保存中') {
  433. return;
  434. }
  435. $('#button').text('保存中');
  436. $('#button').css('background', 'darkgray');
  437. //获取联系人,联系方式,备注
  438. var contacts = $('#contacts').val().replace(/\,/g, ' ').trim();
  439. var phone = $('#phone').val();
  440. var more = '',
  441. total = 0;
  442. //拒单标识0为不能拒单,1为可以拒单
  443. var if_cancel = 0;
  444. //备注要拼接字符串
  445. $.each($("[name^='note[type]']"), function (key, item) {
  446. var text = $(item).next().val().replace(/[\|,]/g, ' ').trim();
  447. if (text != '') {
  448. if (more != '')
  449. more += '||';
  450. var user_id = $(item).closest('div').find('input[name="edit_user_id"]');
  451. more += (user_id.length > 0 ? user_id.val() : getCookie('user_id')) + '|' + parseInt(Date.now() / 1000) + '|' + item.value + '|' + text;
  452. }
  453. });
  454. //end 备注要拼接字符串
  455. var cus_list = "{" + contacts + "," + phone + "," + more + "}";
  456. //end 获取联系人,联系方式,备注
  457. //获取最晚到店时间
  458. var checkin_time = $('#time').val().toString();
  459. //渠道订单号
  460. var org_num = $('#org_num').val();
  461. //渠道id
  462. var org_id = $('#org_id').val();
  463. //获取房型列表
  464. var room_list = '';
  465. $('.tr_str').each(function () {
  466. var start_date = $(this).find('td').eq(0).text();
  467. var all_count = $(this).find('.prod_count').val();
  468. if (all_count == 0) {
  469. /*$('#button').text("保存");
  470. $('#button').attr('disabled',"false");*/
  471. ZZAlertInfo('请选择库存', function () {
  472. return;
  473. })
  474. }
  475. var dan_jiesuan = $(this).find('.prod_price').val();
  476. if ($(this).find('.yongj_sum').text() == '-') {
  477. var dan_yongj = 0
  478. } else {
  479. var dan_yongj = parseFloat($(this).find('.yongj_sum').text()) / parseInt(all_count);
  480. }
  481. //获得买断,保留,现询的价格与库存
  482. var dict_maiduan = getJsonHtml($(this).attr('data-json-maiduan'));
  483. var dict_baoliu = getJsonHtml($(this).attr('data-json-baoliu'));
  484. var dict_xianxun = getJsonHtml($(this).attr('data-json-xianxun'));
  485. //库存类型与成本
  486. var maiduan_count = dict_maiduan == 0 ? 0 : dict_maiduan['remaining_count'];
  487. var baoliu_count = dict_baoliu == 0 ? 0 : dict_baoliu['remaining_count'];
  488. var xianxun_count = dict_xianxun == 0 ? 0 : dict_xianxun['remaining_count'];
  489. var maiduan_price = dict_maiduan == 0 ? 0 : dict_maiduan['cost_price'];
  490. var baoliu_price = dict_baoliu == 0 ? 0 : dict_baoliu['cost_price'];
  491. var xianxun_price = dict_xianxun == 0 ? 0 : dict_xianxun['cost_price'];
  492. if (maiduan_price == 0 && baoliu_price == 0 && xianxun_price == 0) {
  493. /* $('#button').text("保存");
  494. $('#button').attr('disabled',"false");*/
  495. ZZAlertInfo('存在成本价为零,请至对应房型列表确认', function () {
  496. return;
  497. })
  498. }
  499. //end 库存类型与成本
  500. //end 获得买断,保留,现询的价格与库存
  501. //判断库存
  502. var maiduan_field = '';
  503. var baoliu_field = '';
  504. var xianxun_field = '';
  505. var sum_field = '';
  506. if (parseInt(all_count) <= parseInt(maiduan_count)) {//小于等于买断库存228
  507. sum_field = '228' + ',' + all_count + ',' + maiduan_price
  508. } else if (parseInt(all_count) > parseInt(maiduan_count) && parseInt(all_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count))) {
  509. maiduan_field = '228' + ',' + maiduan_count + ',' + maiduan_price;
  510. baoliu_field = '230' + ',' + (all_count - maiduan_count) + ',' + baoliu_price;
  511. sum_field = maiduan_field + '|' + baoliu_field
  512. } else if (parseInt(all_count) > (parseInt(maiduan_count) + parseInt(baoliu_count)) && parseInt(all_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count) + parseInt(xianxun_count))) {
  513. if_cancel = 1;
  514. maiduan_field = '228' + ',' + maiduan_count + ',' + maiduan_price;
  515. baoliu_field = '230' + ',' + baoliu_count + ',' + baoliu_price;
  516. xianxun_field = '229' + ',' + (all_count - baoliu_count - maiduan_count) + ',' + xianxun_price;
  517. sum_field = maiduan_field + '|' + baoliu_field + '|' + xianxun_field
  518. } else {
  519. // alert('出错了,不可能!!');
  520. return;
  521. }
  522. // ZZLog(sum_field);
  523. room_list += '{\'\'' + start_date + '\'\',' + all_count + ',' + dan_jiesuan + ',' + dan_yongj + '}';
  524. total += all_count;
  525. //end 判断库存
  526. });
  527. //end 获取房型列表
  528. var param = {
  529. type: "order_ModifyHTOrder",
  530. op: "modify_order",
  531. hotel_id: hotel_id,
  532. room_type: room_type,
  533. org_id: org_id,
  534. org_num: org_num,
  535. room_list: room_list,
  536. cus_list: cus_list,
  537. contact: contacts,
  538. mobile: phone,
  539. start_date: start_date,
  540. memo: more,
  541. total: total,
  542. checkin_time: checkin_time,
  543. if_cancel: if_cancel,
  544. order_id: order_id,
  545. total_commission: all_yongj,
  546. benefit: all_profit,
  547. };
  548. param.logList = compareOldData(param);
  549. //最晚到店不为空,联系人不为空,订单渠道不为空,渠道订单号不为空,入住日期得连续,库存不问空
  550. if (hotel_id == '' || room_type == '' || org_id == '' || room_list == '' || checkin_time == '' || if_cancel === '' || contacts === '') {
  551. $('#button').text('保存');
  552. $('#button').css('background', '#428bca!important');
  553. ZZAlertInfo('请完整填写数据', function () {
  554. })
  555. return false;
  556. } else {
  557. loading();
  558. $.ajax({
  559. url: base_api,
  560. type: 'post',
  561. dataTye: 'json',
  562. data: param,
  563. success: function (res_data) {
  564. closeLoading();
  565. res_data = JSON.parse(res_data);
  566. if (res_data['code'] != "0") {
  567. $('#button').text('保存');
  568. $('#button').css('background', '#428bca!important');
  569. ZZAlertInfo('修改失败', function () {
  570. })
  571. } else {
  572. $('#button').text('保存');
  573. $('#button').css('background', '#428bca!important');
  574. ZZAlertInfo('修改成功!', function () {
  575. window.location.href = "./hotel_order_list.html";
  576. });
  577. }
  578. },
  579. error: function (msg) {
  580. closeLoading();
  581. }
  582. })
  583. }
  584. }
  585. //添加备注
  586. function addNote(e) {
  587. ZZConfirm('确认添加备注?', function () {
  588. var note = '<div style="margin-top: 20px" class="note"><span style="width: 80px;display: inline-block"></span>';
  589. //不同用户登录,显示不同内容
  590. var display = 'none';
  591. var user_org_id = getCookie('user_org_id');
  592. if (user_org_id == 0) {
  593. display = 'inline-block';
  594. }
  595. note += ' <select name="note[type][]" style="display: ' + display + ';"><option value="0">公共备注</option><option value="1">内部备注</option></select>';
  596. // }
  597. note += ' <input name="note[text][]" type="text" style="width: 300px;height: 30px;font-size: 13px;color: inherit" placeholder="填写备注" /> ';
  598. note += ' <a href="javascript:;" onclick="removeNote(this, false)" >删除</a>';
  599. note += '</div>';
  600. $(".note:last").after(note);
  601. })
  602. }
  603. //更新库存
  604. function updateStock() {
  605. if (load_detail_finished && load_finished) {
  606. var trList = $("#make_order_list tr td.checkin_date").closest('tr');
  607. $.each(_old_stock, function (key, item) {
  608. $.each(trList, function (key, tr) {
  609. if ($($(tr).find('td')[0]).html() == item['date']) {
  610. //根据不同类型,选择不同库存
  611. var json_type = '';
  612. if (item['stock_type'] == '228') {//买断
  613. json_type = 'data-json-maiduan';
  614. } else if (item['stock_type'] == '229') {//现询
  615. json_type = 'data-json-xianxun';
  616. } else if (item['stock_type'] == '230') {//保留
  617. json_type = 'data-json-baoliu';
  618. } else {
  619. }
  620. var tr_json_data = $(tr).attr(json_type);
  621. if (tr_json_data != '' && tr_json_data.indexOf('[data-json') == -1) {
  622. var tmp_data = JSON.parse(tr_json_data);
  623. tmp_data['remaining_count'] = parseInt(tmp_data['remaining_count']) + parseInt(item['stock_count']);
  624. var json_str = JSON.stringify(tmp_data);
  625. $(tr).attr(json_type, json_str);
  626. }
  627. var count = parseInt($(tr).find('.prod_count option:last').html());
  628. var new_count = count + parseInt(item['stock_count'])
  629. for (var i = count + 1; i <= new_count && i < 20; i++) {
  630. $(tr).find('.prod_count option:last').after('<option value="' + i + '">' + i + '</option>');
  631. }
  632. $(tr).find('.prod_count').val(item['stock_count']).change();
  633. }
  634. })
  635. })
  636. }
  637. }
  638. //获取总计
  639. function all_sum() {
  640. all_yongj = 0;
  641. all_jiesuan = 0;
  642. all_profit = 0;
  643. var all_yongj1 = 0;
  644. var all_jiesuan1 = 0;
  645. var all_profit1 = 0;
  646. $('.yongj_sum').each(function () {
  647. all_yongj += parseFloat($(this).text())
  648. });
  649. if (isNaN(all_yongj)) {
  650. all_yongj = 0
  651. }
  652. $('.jiesuan_sum').each(function () {
  653. all_jiesuan += parseFloat($(this).text())
  654. });
  655. if (isNaN(all_jiesuan)) {
  656. all_jiesuan = 0
  657. }
  658. $('.benefit_sum').each(function () {
  659. all_profit += parseFloat($(this).text())
  660. });
  661. if (isNaN(all_profit)) {
  662. all_profit = 0
  663. }
  664. all_yongj1 = all_yongj.toFixed(2);
  665. all_jiesuan1 = all_jiesuan.toFixed(2);
  666. all_profit1 = all_profit.toFixed(2);
  667. $('#all_yongj').text(all_yongj1 + '元');
  668. $('#all_jiesuan').text(all_jiesuan1 + '元');
  669. $('#all_profit').text(all_profit1 + '元');
  670. }