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.
 
 
 
 

534 lines
17 KiB

  1. // 总计
  2. var tr_finalStr='';
  3. //html_str
  4. var tr_oneHTML='';
  5. var select_room_HTML_str='';
  6. var http_data_length=0;
  7. //分销商还是自营
  8. var fen_xiao_type='';
  9. //得到产品名称
  10. var base_url="./st-xm/Api/ht_get_place_order_info.php"
  11. //var base_url="http://127.0.0.1/%E8%9C%98%E8%9B%9B2.0%E8%83%BD%E5%86%99PHP/st-xm/Api/ht_get_place_order_info.php"
  12. //var base_url_my_add_order="http://192.168.6.108:8082/st-xm/Api/hotel_submit_order.php";
  13. var base_url_my_add_order="./st-xm/Api/hotel_submit_order.php";
  14. //var base_url_my_add_order="./st-xm/Api/txt_form.php";
  15. //页面加载的时候调用
  16. window.onload=function(){
  17. tr_oneHTML=$('#tr_one').prop('outerHTML');
  18. tr_oneHTML=tr_oneHTML.replace('none','table-row');
  19. tr_finalStr=$('#tr_final').html();
  20. tr_finalStr=tr_finalStr.replace('none','table-row');
  21. select_room_HTML_str=$('#select_room').html();
  22. //入住时间初始值
  23. $('#id-date-picker-1').val(getDateTime(0));
  24. var prod_id=getPar('prod_id');
  25. if (!prod_id) {
  26. alert('缺少参数');
  27. return;
  28. }
  29. $("input[name='prod_id']").val(prod_id);
  30. //调用 函数
  31. var url=base_url+"?method=getProdName&prod_id="+prod_id;
  32. get_http_data_by_url(url);
  33. }
  34. // 请求方法,传入URL
  35. function get_http_data_by_url(myURL){
  36. var tnowtime = getDateTime(4);
  37. if (myURL.indexOf('?')>=0) {
  38. myURL+='&tt='+tnowtime;
  39. }else{
  40. myURL+='?tt='+tnowtime;
  41. }
  42. $.getJSON(myURL,function(res_data){
  43. if(res_data['code']!="0"){
  44. alert(res_data['info']);
  45. return;
  46. }
  47. $('#hotel_room').html(res_data['prod_name']);
  48. $('#prod_name').val(res_data['prod_name']);
  49. });
  50. }
  51. //选择是自营还是分销
  52. function sel_type(value){
  53. var list_base_url="./st-xm/Api/ht_get_order_list.php";
  54. if (value=="177") {
  55. fen_xiao_type="177";
  56. $('#fen').css('display','table');
  57. // $('#distributors').removeAttr('readonly');
  58. $('#order_no').removeAttr('readonly');
  59. var url=list_base_url+"?method=getChannelList&channel_type="+value;
  60. var tnowtime=getDateTime(4);
  61. if (url.indexOf('?') >= 0) {
  62. url += '&tt=' + tnowtime;
  63. } else {
  64. url += '?tt=' + tnowtime;
  65. }
  66. $.getJSON(url,function(res_data){
  67. if(res_data['code']!="0"){alert(res_data['info']);return;}
  68. var distributors=$('#distributors');
  69. var list=res_data['channelList'];
  70. var HTML='';
  71. for (var i=0,m=list.length;i<m;i++) {
  72. var tempHTML='<option value="'+list[i]['org_id']+'">'+list[i]['org_name']+'</option>'
  73. HTML+=tempHTML;
  74. }
  75. distributors.html(HTML);
  76. });
  77. }else if(value=="176"){
  78. fen_xiao_type="177";
  79. $('#fen').css('display','table');
  80. // $('#distributors').removeAttr('readonly');
  81. $('#order_no').removeAttr('readonly');
  82. var url=list_base_url+"?method=getChannelList&channel_type="+value;
  83. var tnowtime=getDateTime(4);
  84. if (url.indexOf('?') >= 0) {
  85. url += '&tt=' + tnowtime;
  86. } else {
  87. url += '?tt=' + tnowtime;
  88. }
  89. $.getJSON(url,function(res_data){
  90. if(res_data['code']!="0"){alert(res_data['info']);return;}
  91. var distributors=$('#distributors');
  92. var list=res_data['channelList'];
  93. var HTML='';
  94. for (var i=0,m=list.length;i<m;i++) {
  95. var tempHTML='<option value="'+list[i]['org_id']+'">'+list[i]['org_name']+'</option>'
  96. HTML+=tempHTML;
  97. }
  98. distributors.html(HTML);
  99. });
  100. }
  101. else{
  102. fen_xiao_type=value;
  103. $('#fen').css('display','none');
  104. $('#order_no').attr('readonly','true');
  105. $('#order_no').val('');
  106. }
  107. }
  108. //选择入住时间
  109. function sel_time_hour(innerHTML){
  110. }
  111. //选择日期
  112. function date_choose_picker(type){
  113. //开始日期
  114. var start_date = $('#id-date-picker-1').val();
  115. if (start_date.trim().length <= 0) {
  116. return;
  117. }
  118. //结束日期
  119. var end_date = $('#id-date-picker-2').val();
  120. if (end_date.trim().length < 0) {
  121. return;
  122. }
  123. // 判断日期是否合理
  124. var date1 = new Date(start_date.replace(/\-/g, '/'));
  125. var date2 = new Date(end_date.replace(/\-/g, '/'));
  126. if (date1>date2) {
  127. alert('结束日期必须大于开始日期!!!');
  128. $('#all_days').html('共 0 晚');
  129. $('#hotelList').html('');
  130. if(type==1){
  131. $('#id-date-picker-1').val('');
  132. }else{
  133. $('#id-date-picker-2').val('');
  134. }
  135. return;
  136. }
  137. // var date1=new Date(start_date.replace(/-/,'/'));
  138. // var date2=new Date(end_date.replace(/-/,'/'));
  139. // var date3=date2-date1;
  140. // //计算出相差天数
  141. // var days=Math.floor(date3/(24*3600*1000));
  142. // $('#all_days').html('共 '+days+' 晚');
  143. var prod_id=getPar('prod_id');
  144. if(!prod_id){alert('缺少参数');return;};
  145. var tnowtime = getDateTime(4);
  146. var url=base_url+"?method=getPlaceOrderInfo&prod_id="+prod_id+"&check_in_date="+start_date+"&check_out_date="+end_date+"&tt="+tnowtime;
  147. $.getJSON(url,function(res_data){
  148. var arr_rooms=new Array();
  149. var hotelListOBJ=$('#hotelList');
  150. var arr_placeOrder=res_data['place_order_info'];
  151. //先保存数据的长度
  152. http_data_length=arr_placeOrder.length;
  153. $('#all_days').html('共 '+arr_placeOrder.length+' 晚');
  154. $("input[name='maxcount']").val(arr_placeOrder.length);
  155. var newHTML=''
  156. for (var i=0;i<arr_placeOrder.length;i++) {
  157. var tempDict=arr_placeOrder[i];
  158. var tempHTML=tr_oneHTML;
  159. //关于一些事件和参数的替换
  160. tempHTML=tempHTML.replace('tr_one','tr_one_'+i);
  161. tempHTML=tempHTML.replace('check_in_date','check_in_date_'+i);
  162. tempHTML=tempHTML.replace('run_id','run_id_'+i);
  163. tempHTML=tempHTML.replace('select_room','select_room_'+i);
  164. tempHTML=tempHTML.replace('room_count','room_count_'+i);
  165. tempHTML=tempHTML.replace('[base]',i);
  166. tempHTML=tempHTML.replace('[mid]',i);
  167. tempHTML=tempHTML.replace('[order]',i);
  168. tempHTML=tempHTML.replace('[cai_blur]',i);
  169. tempHTML=tempHTML.replace('[jie_blur]',i);
  170. tempHTML=tempHTML.replace('[zero_blur]',i);
  171. tempHTML=tempHTML.replace('[index]',i);
  172. tempHTML=tempHTML.replace('[cai1]',i);
  173. tempHTML=tempHTML.replace('[jie1]',i);
  174. tempHTML=tempHTML.replace('[zero1]',i);
  175. tempHTML=tempHTML.replace('[cai2]',i);
  176. tempHTML=tempHTML.replace('[jie2]',i);
  177. tempHTML=tempHTML.replace('[lirun]',i);
  178. //关于一些事件和参数的替换
  179. tempHTML=tempHTML.replace('[入住日期]',tempDict['run_date']);
  180. tempHTML=tempHTML.replace('checkIn:Value',tempDict['run_date']);
  181. tempHTML=tempHTML.replace('[run_id:Value]',tempDict['run_id']);
  182. tempHTML=tempHTML.replace('[库存]',tempDict['total_count']);
  183. arr_rooms.push(tempDict['total_count']);
  184. tempHTML=tempHTML.replace('[采购价]',parseInt(tempDict['base_price']));
  185. tempHTML=tempHTML.replace('[结算价]',parseInt(tempDict['mid_price']));
  186. tempHTML=tempHTML.replace('[零售价]',parseInt(tempDict['order_price']));
  187. newHTML+=tempHTML;
  188. }
  189. for (var i=0;i<arr_placeOrder.length;i++) {
  190. var tempDict=arr_placeOrder[i];
  191. update_show(i,1,tempDict['base_price'],tempDict['mid_price'])
  192. }
  193. hotelListOBJ.html(newHTML);
  194. //加载之后第一次计算
  195. var all_order=0;
  196. var all_cai=0;
  197. var all_jie=0;
  198. var all_profits=0;//利润
  199. for (var i=0;i<arr_placeOrder.length;i++) {
  200. var tempDict=arr_placeOrder[i];
  201. update_show(i,1,tempDict['base_price'],tempDict['mid_price']);
  202. all_order+=parseInt(tempDict['order_price']);
  203. all_cai+=parseInt(tempDict['base_price']);
  204. all_jie+=parseInt(tempDict['mid_price']);
  205. all_profits+=all_jie-all_cai;
  206. }
  207. //计算完了再加载 总计的HTML
  208. var all_HTML=$('#hotelList').html();
  209. var tempHTML=tr_finalStr;
  210. tempHTML=tempHTML.replace('[总零售价]',all_order);
  211. tempHTML=tempHTML.replace('[采购价金额]',all_cai);
  212. tempHTML=tempHTML.replace('[结算价金额]',all_jie);
  213. tempHTML=tempHTML.replace('[销售利润]',all_profits);
  214. all_HTML+=tempHTML;
  215. $('#hotelList').html(all_HTML);
  216. for (var i=0;i<arr_rooms.length;i++) {
  217. var count=arr_rooms[i];
  218. var sel_room_all_HTML='';
  219. for (var j=0;j<count;j++) {
  220. var tempHT=select_room_HTML_str;
  221. tempHT=tempHT.replace('[value:i]',j+1);
  222. tempHT=tempHT.replace('[html:i]',j+1);
  223. sel_room_all_HTML+=tempHT;
  224. }
  225. $('#select_room_'+i).html(sel_room_all_HTML);
  226. }
  227. });
  228. }
  229. //选择房间数
  230. function select_room(index,count){
  231. //拿到采购价和结算价
  232. var cai_price=$('#cai_price_'+index).val();
  233. var jie_price=$('#jie_price_'+index).val();
  234. //计算
  235. update_show(index,count,cai_price,jie_price);
  236. //总计
  237. all_total_show()
  238. }
  239. //采购价value发生改变
  240. function cai_change(index,value){
  241. //拿到房间数
  242. var rooms=$('#select_room_'+index).find("option:selected").val();
  243. //拿到结算价
  244. var jie_price=$('#jie_price_'+index).val();
  245. //计算
  246. update_show(index,rooms,value,jie_price);
  247. //总计
  248. all_total_show();
  249. }
  250. //结算价value发生改变
  251. function jie_change(index,value){
  252. if (value.trim().length<=0) {
  253. value=0;
  254. }
  255. //拿到房间数
  256. var rooms=$('#select_room_'+index).find("option:selected").val();
  257. //拿到采购价
  258. var cai_price=$('#cai_price_'+index).val();
  259. //计算
  260. update_show(index,rooms,cai_price,value);
  261. //总计
  262. all_total_show();
  263. }
  264. //零售价value发生改变
  265. function zero_change(index,value){
  266. if (value.trim().length<=0) {
  267. value=0;
  268. }
  269. //拿到房间数
  270. var rooms=$('#select_room_'+index).find("option:selected").val();
  271. //拿到采购价
  272. var cai_price=$('#cai_price_'+index).val();
  273. //计算
  274. //update_show(index,rooms,cai_price,value);
  275. //总计
  276. all_total_show();
  277. }
  278. //计算和显示
  279. function update_show(index,room_count,cai_price,jie_price){
  280. //计算
  281. var all_cai=cai_price*room_count;
  282. var all_jie=jie_price*room_count;
  283. //改变页面
  284. //利润
  285. var profits=all_jie-all_cai;
  286. //改变页面的效果
  287. $('#cai_price_balance_'+index).html(all_cai.toFixed(1));
  288. $('#jie_price_balance_'+index).html(all_jie.toFixed(1));
  289. $('#profits_'+index).html(profits.toFixed(1));
  290. }
  291. //总计
  292. function all_total_show(){
  293. var all_cai=0;
  294. var all_jie=0;
  295. var all_profits=0;//利润
  296. var all_order=0;//零售价
  297. for (var i=0;i<http_data_length;i++) {
  298. var ling=($('#zero_price_'+i).val())*($('#select_room_'+i).val());
  299. var cai=$('#cai_price_balance_'+i).html();
  300. var jie=$('#jie_price_balance_'+i).html();
  301. var profits=$('#profits_'+i).html();
  302. all_order+=parseInt(ling);
  303. all_cai+=parseInt(cai);
  304. all_jie+=parseInt(jie);
  305. all_profits=all_jie-all_cai;
  306. }
  307. var profits=all_jie-all_cai;
  308. $('#all_order').html(all_order.toFixed(1));
  309. $('#all_cai').html(all_cai.toFixed(1));
  310. $('#all_jie').html(all_jie.toFixed(1));
  311. $('#all_lirun').html(all_profits.toFixed(1));
  312. }
  313. // 点击提交按钮
  314. $(document).ready(function(){
  315. $('#btn_submit').click(function(){
  316. //type:预订信息
  317. if(fen_xiao_type=="177"){
  318. //分销商
  319. var distributorsStr=$('#distributors').val();
  320. if(distributorsStr.trim().length<=0){alert('请填写分销商名称 / 手机 / 登录名!!!');return;}
  321. //订单编号
  322. var order_no=$('#order_no').val();
  323. if(order_no.trim().length<=0){alert('请填写订单编号!!!');return;}
  324. }else if(fen_xiao_type.trim()==""){alert('请选择订单来源!!!');return;}
  325. else{}
  326. //入住日期的两个
  327. var start_date=$('#id-date-picker-1').val();
  328. var end_date=$('#id-date-picker-2').val();
  329. if(start_date.trim().length<=0){alert('请选择开始日期!!!');return;}
  330. if(end_date.trim().length<=0){alert('请选择结束日期!!!');return;}
  331. //type:客人信息
  332. //客人姓名
  333. var guest_name=$('#guest_name').val();
  334. var guest_phone=$('#guest_phone').val();
  335. if(guest_name.trim().length<=0){alert('请填写客人姓名!!!');return;}
  336. if(guest_phone.trim().length<=0){alert('请填写联系电话!!!');return;}
  337. if(!checkMobile(guest_phone)){alert('客人手机号输入不合法!!!');return;}
  338. //备注
  339. var order_remark=$('#order_remark').val();
  340. //判断结束日期不能小于开始日期
  341. var date1=new Date(start_date.replace(/\-/g,'/'));
  342. var date2=new Date(end_date.replace(/\-/g,'/'));
  343. if(date1>date2){alert('结束日期必须大于开始日期!!!');return;}
  344. //判断是否有房--判断是否有金额-目前低保障
  345. var isRoom=$('#all_cai').html();
  346. if(isRoom=="0" || isRoom<=0){alert('相关产品没有库存!!!');return;}
  347. document.myform.action=base_url_my_add_order;
  348. document.myform.submit();
  349. // var listURL = "hotelOrderList.html";
  350. // // 跳转前将URL编码
  351. // listURL = encodeURI(listURL);
  352. // window.location.href = listURL;
  353. });
  354. });
  355. //$(document).ready(function(){
  356. // $('#btn_shutdown').click(function(){
  357. // alert('点击了关闭');
  358. // });
  359. //});
  360. function getPar(par) {
  361. //获取当前URL
  362. var local_url = document.location.href;
  363. local_url = decodeURI(local_url);
  364. //获取要取得的get参数位置
  365. var get = local_url.indexOf(par + "=");
  366. if (get == -1) {
  367. return false;
  368. }
  369. //截取字符串
  370. var get_par = local_url.slice(par.length + get + 1);
  371. //判断截取后的字符串是否还有其他get参数
  372. var nextPar = get_par.indexOf("&");
  373. if (nextPar != -1) {
  374. get_par = get_par.slice(0, nextPar);
  375. }
  376. return get_par;
  377. }
  378. function checkMobile(str) {
  379. var re = /^1\d{10}$/;
  380. if (re.test(str)) {
  381. return true;
  382. } else {
  383. return false;
  384. }
  385. }
  386. function getDateTime(nTypeFlag) {
  387. var tNowTime = new Date();
  388. var myYear = ';' + tNowTime.getFullYear() + ';';
  389. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  390. var myDay = ';' + tNowTime.getDate() + ';';
  391. var myHour = ';' + tNowTime.getHours() + ';';
  392. var myMinu = ';' + tNowTime.getMinutes() + ';';
  393. var mySecond = ';' + tNowTime.getSeconds() + ';';
  394. if (myMonth.length < 4) myMonth = '0' + myMonth;
  395. if (myDay.length < 4) myDay = '0' + myDay;
  396. if (myHour.length < 4) myHour = '0' + myHour;
  397. if (myMinu.length < 4) myMinu = '0' + myMinu;
  398. if (mySecond.length < 4) mySecond = '0' + mySecond;
  399. var cNewTimeStr;
  400. //alert(tNowTime);
  401. switch (nTypeFlag + 1 - 1) {
  402. case 0:
  403. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  404. break;
  405. case 1:
  406. cNewTimeStr = myYear + myMonth + myDay;
  407. break;
  408. case 2:
  409. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  410. break;
  411. case 3:
  412. cNewTimeStr = myHour + myMinu + mySecond;
  413. break;
  414. case 4:
  415. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  416. break;
  417. case 5:
  418. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  419. break;
  420. case 6:
  421. cNewTimeStr = myYear;
  422. break;
  423. case 7:
  424. cNewTimeStr = myYear + '-' + myMonth;
  425. break;
  426. default:
  427. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  428. break;
  429. }
  430. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  431. return cNewTimeStr;
  432. }
  433. /*
  434. if (myreq.readyState==4) {
  435. var newstr=myreq.responseText;
  436. var httpData = JSON.parse(newstr);
  437. var hotelListOBJ=$('#hotelList');
  438. var arr_placeOrder=httpData['placeOrder'];
  439. //先保存数据的长度
  440. http_data_length=arr_placeOrder.length;
  441. var tr_oneHTML=$('#tr_one').prop('outerHTML');
  442. var newHTML=''
  443. for (var i=0;i<arr_placeOrder.length;i++) {
  444. var tempDict=arr_placeOrder[i];
  445. var tempHTML=tr_oneHTML;
  446. //关于一些事件和参数的替换
  447. tempHTML=tempHTML.replace('tr_one','tr_one_'+i);
  448. tempHTML=tempHTML.replace('select_room','select_room_'+i);
  449. tempHTML=tempHTML.replace('[cai_blur]',i);
  450. tempHTML=tempHTML.replace('[jie_blur]',i);
  451. tempHTML=tempHTML.replace('[zero_blur]',i);
  452. tempHTML=tempHTML.replace('[index]',i);
  453. tempHTML=tempHTML.replace('[cai1]',i);
  454. tempHTML=tempHTML.replace('[jie1]',i);
  455. tempHTML=tempHTML.replace('[zero1]',i);
  456. tempHTML=tempHTML.replace('[cai2]',i);
  457. tempHTML=tempHTML.replace('[jie2]',i);
  458. tempHTML=tempHTML.replace('[lirun]',i);
  459. //关于一些事件和参数的替换
  460. tempHTML=tempHTML.replace('[入住日期]',tempDict['start_date']);
  461. tempHTML=tempHTML.replace('[库存]',tempDict['inventory']);
  462. tempHTML=tempHTML.replace('[采购价]',tempDict['cai_price_balance']);
  463. tempHTML=tempHTML.replace('[结算价]',tempDict['jie_price_balance']);
  464. tempHTML=tempHTML.replace('[零售价]',tempDict['zero_sale_price']);
  465. newHTML+=tempHTML;
  466. }
  467. for (var i=0;i<arr_placeOrder.length;i++) {
  468. var tempDict=arr_placeOrder[i];
  469. update_show(i,1,tempDict['cai_price_balance'],tempDict['jie_price_balance'])
  470. }
  471. tr_finalStr=$('#tr_final').prop('outerHTML');
  472. hotelListOBJ.html(newHTML);
  473. //加载之后第一次计算
  474. var all_cai=0;
  475. var all_jie=0;
  476. var all_profits=0;//利润
  477. for (var i=0;i<arr_placeOrder.length;i++) {
  478. var tempDict=arr_placeOrder[i];
  479. update_show(i,1,tempDict['cai_price_balance'],tempDict['jie_price_balance']);
  480. all_cai+=parseInt(tempDict['cai_price_balance']);
  481. all_jie+=parseInt(tempDict['jie_price_balance']);
  482. all_profits+=all_jie-all_cai;
  483. }
  484. //计算完了再加载 总计的HTML
  485. var all_HTML=$('#hotelList').html();
  486. var tempHTML=tr_finalStr;
  487. tempHTML=tempHTML.replace('[采购价金额]',all_cai);
  488. tempHTML=tempHTML.replace('[结算价金额]',all_jie);
  489. tempHTML=tempHTML.replace('[销售利润]',all_profits);
  490. all_HTML+=tempHTML;
  491. $('#hotelList').html(all_HTML);
  492. }
  493. * */