Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

565 Zeilen
16 KiB

  1. var data = getStorJson("payOrderInfo");
  2. //记录出发地站点数组
  3. var start_station_list = '';
  4. //记录目的地站点数组
  5. var end_station_list = '';
  6. //记录返程出发地站点数组
  7. var back_start_station_list = '';
  8. //记录返程目的地站点数组
  9. var back_end_station_list = '';
  10. //记录是否选择返程状态
  11. var ifback = 0;
  12. //上弹框
  13. var wei_infoHTML = '';
  14. //返程的startid
  15. var back_start_id = ''
  16. //返程的end_id
  17. var back_end_id = ''
  18. //返程结果的html()
  19. var HTML = '';
  20. //返程的html()
  21. var backHTML = '';
  22. //总页面html
  23. var allHTML = '';
  24. //票种数量的html
  25. var count_html = '';
  26. //去程和往返的交集库存
  27. var stockCount = 0;
  28. //定义一个 只记录去程库存 一般取消返程选中时 重置去程库存
  29. var stockCountTemp = 0;
  30. //记录可选择的票种数量
  31. var ticketCount = 0;
  32. var newHTML='';
  33. var curpage = 1;
  34. var thisdataStrShow = '';
  35. //去程
  36. var run_id = '';
  37. var line_id = '';
  38. var ticket = '';
  39. //返程
  40. var back_run_id = '';
  41. var back_line_id = '';
  42. var back_ticket = '';
  43. $(document).ready(function() {
  44. // put all your jQuery goodness in here.
  45. });
  46. window.onload = function(){
  47. wei_infoHTML = $('#wei_info').html();
  48. HTML = $('#list_info').html();
  49. backHTML = $('#select_back_div').html();
  50. allHTML = $('#back_info').html();
  51. count_html = $('#seat_count_info').html();
  52. var run_id = data.run_id;
  53. var start_area_id = data.start_area_id;
  54. var end_area_id = data.end_area_id;
  55. //返程
  56. back_start_id = data.end_area_id;
  57. back_end_id = data.start_area_id;
  58. //展示去程信息
  59. showGoInfo(run_id,start_area_id,end_area_id);
  60. }
  61. //展示去程信息
  62. function showGoInfo(run_id,start_area_id,end_area_id){
  63. $.ajax({
  64. url:'./zz-fx/control.php',
  65. type: "post",
  66. data: {
  67. run_id:data.run_id,
  68. start_area_id:data.start_area_id,
  69. end_area_id:data.end_area_id,
  70. back:1,
  71. type:"retrieval_site"
  72. },
  73. dataType: "json",
  74. success: function (data) {
  75. if(data.code == 0){
  76. console.log(data);
  77. //去程信息的数据交互
  78. goInfoReloadData(data.list);
  79. }
  80. },
  81. fail: function (data) {
  82. // 此处放失败后执行的代码
  83. }
  84. });
  85. }
  86. //去程信息的数据交互
  87. function goInfoReloadData(data){
  88. var go_info_HTML = $('#go_info').html();
  89. var temp = go_info_HTML;
  90. temp = temp.replace('7月28日',data.date);
  91. temp = temp.replace('[出发地]',data.start_area_name);
  92. temp = temp.replace('[目的地]',data.end_area_name);
  93. $('#go_info').html(temp);
  94. start_station_list = data.start_order;
  95. end_station_list = data.end_order;
  96. // var start_station_html = '';
  97. // for (var i = 0 ; i < start_station_list.length; i ++) {
  98. // var tempHTML = wei_infoHTML;
  99. // tempHTML = tempHTML.replace('示例菜单',start_station_list[i].name);
  100. // tempHTML = tempHTML.replace('[id]',start_station_list[i].id);
  101. // start_station_html += tempHTML;
  102. // }
  103. // $('#wei_info').html(start_station_html);
  104. $('#up_station_time').html(start_station_list[0].name);
  105. $('#up_station_time').attr('valId',start_station_list[0].id);
  106. // var end_station_html = '';
  107. // for (var i = 0 ; i < end_station_list.length; i ++) {
  108. // var tempHTML1 = wei_infoHTML;
  109. // tempHTML1 = tempHTML1.replace('示例菜单',end_station_list[i].name);
  110. // tempHTML1 = tempHTML1.replace('[id]',end_station_list[i].id);
  111. // end_station_html += tempHTML1;
  112. // }
  113. // $('#wei_info').html(end_station_html);
  114. $('#down_station_time').html(end_station_list[0].name);
  115. $('#down_station_time').attr('valId',end_station_list[0].id);
  116. run_id = data.run_id;
  117. line_id = data.line_id;
  118. var start_id = $('#up_station_time').attr('valid');
  119. var end_id = $('#down_station_time').attr('valid');
  120. ticket = data.ticket;
  121. bus_type = data.bus_type;
  122. //犹豫异步加载的问题 所以只能在展示数据后 继续调用票种价格等相关信息
  123. $.ajax({
  124. url:'./zz-fx/control.php',
  125. type: "post",
  126. data: {
  127. run_id:run_id,
  128. line_id:line_id,
  129. start_id:start_id,
  130. end_id:end_id,
  131. tickets:ticket,
  132. back:1,
  133. type:"retrieval_tickets"
  134. },
  135. dataType: "json",
  136. success: function (data) {
  137. if(data.code == 0){
  138. console.log(data);
  139. //替换去程票种数量信息
  140. showCountInfoByGo(data.list);
  141. }
  142. },
  143. fail: function (data) {
  144. // 此处放失败后执行的代码
  145. }
  146. });
  147. }
  148. //替换去程票种数量信息
  149. function showCountInfoByGo(data){
  150. var html1 = '';
  151. var temp1 = count_html;
  152. temp1 = temp1.replace('普通座',data.site_type);
  153. temp1 = temp1.replace('50元',data.price);
  154. //数量
  155. var maxCount = data.num > 20 ? 20 : data.num;
  156. maxCount = maxCount>0 ? maxCount : 0;
  157. stockCount = maxCount;
  158. stockCountTemp = maxCount;
  159. html1 += temp1;
  160. $('#seat_count_info').html(html1);
  161. //
  162. // if (stockCount == 0) {
  163. // var count_replace = '';
  164. // $('#ifback').attr('disabled','disabled');
  165. // for (var i = 0 ; i <= stockCount; i ++) {
  166. // var tempHTML2 = '<option value="[0]">[-]</option>';
  167. // tempHTML2 = tempHTML2.replace('[0]',i);
  168. // tempHTML2 = tempHTML2.replace('[-]','无库存');
  169. // count_replace += tempHTML2;
  170. // }
  171. // $('#count_station').html(count_replace);
  172. // } else{
  173. // var count_replace = '';
  174. // for (var i = 0 ; i <= stockCount; i ++) {
  175. // var tempHTML2 = '<option value="[0]">[-]</option>';
  176. // tempHTML2 = tempHTML2.replace('[0]',i);
  177. // tempHTML2 = tempHTML2.replace('[-]',i);
  178. // count_replace += tempHTML2;
  179. // }
  180. // $('#count_station').html(count_replace);
  181. // }
  182. // var select_count = $('#count_station').val();
  183. // var totalPrice = parseFloat(select_count)*parseFloat(data.price);
  184. // $('#total').html(totalPrice);
  185. // ticket_id = data.ticket_id;
  186. // back_back_id = data.back_back_id;
  187. }
  188. //增加购买数量
  189. function addition(){
  190. if (ticketCount<stockCount) {
  191. ticketCount ++ ;
  192. $('#adult').val(ticketCount);
  193. }else{
  194. alert('无法购买更多!');
  195. }
  196. }
  197. //减法购买数量
  198. function subtraction(){
  199. if (ticketCount>0) {
  200. ticketCount --;
  201. $('#adult').val(ticketCount);
  202. }else{
  203. alert('请选择正确的票种数量!');
  204. }
  205. }
  206. //上弹框的内容封装
  207. function upDiv(data,select_id,goBack){
  208. var html = '';
  209. for (var i = 0 ; i < data.length; i ++) {
  210. var tempHTML = wei_infoHTML;
  211. tempHTML = tempHTML.replace('示例菜单',data[i].name);
  212. tempHTML = tempHTML.replace('[id]',data[i].id);
  213. html += tempHTML;
  214. }
  215. $('#wei_info').html(html);
  216. $('.weui_actionsheet_cell').click(function(){
  217. $('#'+select_id).html(this.innerHTML);
  218. $('#'+select_id).attr('valid',this.id);
  219. $('#mask').click();
  220. if (goBack == 'go') {
  221. var start_id = $('#up_station_time').attr('valid');
  222. var end_id = $('#down_station_time').attr('valid');
  223. $.ajax({
  224. url:'./zz-fx/control.php',
  225. type: "post",
  226. data: {
  227. run_id:run_id,
  228. line_id:line_id,
  229. start_id:start_id,
  230. end_id:end_id,
  231. tickets:ticket,
  232. back:1,
  233. type:"retrieval_tickets"
  234. },
  235. dataType: "json",
  236. success: function (data) {
  237. if(data.code == 0){
  238. console.log(data);
  239. //替换去程票种数量信息
  240. showCountInfoByGo(data.list);
  241. }
  242. },
  243. fail: function (data) {
  244. // 此处放失败后执行的代码
  245. }
  246. });
  247. } else{
  248. var back_start_station_id = $('#back_up_station_time').attr('valid');
  249. var back_end_station_id = $('#back_down_station_time').attr('valid');
  250. $.ajax({
  251. url:'./zz-fx/control.php',
  252. type: "post",
  253. data: {
  254. run_id:back_run_id,
  255. line_id:back_line_id,
  256. start_id:back_start_station_id,
  257. end_id:back_end_station_id,
  258. tickets:back_ticket,
  259. back:2,
  260. type:"retrieval_tickets"
  261. },
  262. dataType: "json",
  263. success: function (data) {
  264. if(data.code == 0){
  265. console.log(data);
  266. //替换去程票种数量信息
  267. showCountInfoByBack(data.list);
  268. }
  269. },
  270. fail: function (data) {
  271. // 此处放失败后执行的代码
  272. }
  273. });
  274. }
  275. })
  276. }
  277. //选择站点的下侧弹层
  278. $("#start_area").click(function(){
  279. upDiv(start_station_list,'up_station_time','go');
  280. $("#mask").css("display","block");
  281. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  282. })
  283. $("#end_area").click(function(){
  284. upDiv(end_station_list,'down_station_time','go');
  285. $("#mask").css("display","block");
  286. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  287. })
  288. $('#mask').click(function(){
  289. $("#mask").css("display","none");
  290. $("#weui_actionsheet").removeClass("weui_actionsheet_toggle");
  291. })
  292. //选择日期
  293. $(document).ready(function(){
  294. var tomonth = new Date();
  295. $("#ifback").on("click",function(){
  296. if (ifback == 1) {
  297. ifback = 0;
  298. $('#back_info').addClass('ui_hide');
  299. $('#ifandback').addClass('ui_hide');
  300. stockCount = stockCountTemp;
  301. }else{
  302. addmouth($(".month"),tomonth.getFullYear(),tomonth.getMonth());
  303. $(".month").show();
  304. $("#order_detail_info").hide();
  305. $("#back_info").removeClass('ui_hide');
  306. $('#ifandback').removeClass('ui_hide');
  307. selectDate();
  308. }
  309. });
  310. })
  311. //选中日期
  312. function selectDate(){
  313. $(".canday").on("click",function(){
  314. ifback = 1;
  315. if($(this).html()=="今天"){
  316. var seldate = new Date().getDate();
  317. }else{
  318. var seldate =$(this).html();
  319. }
  320. var yearmonth = $(".currentdate").html().split("年");
  321. if (yearmonth[1] != 10 || yearmonth[1] != 11 || yearmonth[1] != 12) {
  322. var show_yearmonth = '0'+yearmonth[1];
  323. }
  324. if (seldate<10) {
  325. var show_seldate = '0'+seldate;
  326. }else{
  327. var show_seldate = seldate;
  328. }
  329. //前台展示
  330. thisdataStrShow = yearmonth[1]+'月'+seldate+'日';
  331. //后台传参
  332. var thisdataStrSend = yearmonth[0]+"-"+show_yearmonth+"-"+show_seldate;
  333. //获取星期
  334. var thisdata = yearmonth[0]+"/"+yearmonth[1]+"/"+seldate;
  335. var select_week = getWeekDay(thisdata);
  336. // $("#nowdate").html(thisdataStrShow);
  337. // $('#nowdate').attr('sendStr',thisdataStrSend);
  338. // $('#nowWeek').html(select_week);
  339. // $(".month").hide();
  340. // $("#order_detail_info").show();
  341. //根据返程日期 调用数据
  342. reloadBackData(thisdataStrSend);
  343. })
  344. }
  345. //加载返程数据
  346. function reloadBackData(backtime){
  347. $.ajax({
  348. url:'./zz-fx/control.php', //请求地址
  349. type: "post", //请求方式
  350. // data: data, //请求参数
  351. data:{
  352. start_area : back_start_id,
  353. end_area : back_end_id,
  354. go_time : backtime,
  355. bus_type : data.bus_type,
  356. type:"retrieval_through",
  357. run_type:1,
  358. currpage:1,
  359. pagesize:data.pagesize
  360. },
  361. async:false,
  362. dataType: "json",
  363. success: function (data) {
  364. console.log(data);
  365. if(data.code == 0){
  366. var sum = data.totalnum;
  367. if (sum == 0) {
  368. alert('没有返程相关班次,请重新选择!')
  369. return;
  370. }else{
  371. $(".month").hide();
  372. $('#back_search_results').removeClass('ui_hide');
  373. $('#order_detail_info').addClass('ui_hide');
  374. //替换返程数据信息
  375. replaceBackInfo(data);
  376. }
  377. }
  378. },
  379. fail: function (date) {
  380. }
  381. });
  382. }
  383. //替换返程数据信息
  384. function replaceBackInfo(data){
  385. var list = data.list;
  386. $('#select_date_a').html(thisdataStrShow);
  387. for(var i=0;i<list.length;i++){
  388. var tempHTML=HTML;
  389. tempHTML=tempHTML.replace('[出发地]',list[i].start_area_name);
  390. tempHTML=tempHTML.replace('[目的地]',list[i].end_area_name);
  391. tempHTML=tempHTML.replace('[时间]',list[i].start_time);
  392. tempHTML=tempHTML.replace('[价格]',list[i].price);
  393. console.log(list[i].line_id);
  394. tempHTML=tempHTML.replace('[order_id]',list[i].run_id);
  395. tempHTML=tempHTML.replace('[order_idli]',list[i].run_id);
  396. tempHTML=tempHTML.replace('[start_id]',list[i].start_area_id);
  397. tempHTML=tempHTML.replace('[end_id]',list[i].end_area_id);
  398. tempHTML=tempHTML.replace('[start_name]','\''+list[i].start_area_name+'\'');
  399. tempHTML=tempHTML.replace('[end_name]','\''+list[i].end_area_name+'\'');
  400. newHTML+=tempHTML;
  401. }
  402. $('#list_info').html(newHTML);
  403. }
  404. //每个详情的点击事件
  405. function goPayInfo(id,start_id,end_id,start_name,end_name){
  406. $('#order_detail_info').removeClass('ui_hide');
  407. $('#order_detail_info').show();
  408. $('#back_search_results').addClass('ui_hide');
  409. var newhtml = '';
  410. var temp = allHTML;
  411. temp = temp.replace('7月28日',thisdataStrShow);
  412. temp = temp.replace('[出发地]',start_name);
  413. temp = temp.replace('[目的地]',end_name);
  414. $('#back_info').html(temp);
  415. $.ajax({
  416. url:'./zz-fx/control.php',
  417. type: "post",
  418. data: {
  419. run_id:id,
  420. start_area_id:start_id,
  421. end_area_id:end_id,
  422. back:2,
  423. type:"retrieval_site"
  424. },
  425. dataType: "json",
  426. success: function (data) {
  427. if(data.code == 0){
  428. console.log(data);
  429. //返程信息的数据交互
  430. backInfoReloadData(data.list);
  431. }
  432. },
  433. fail: function (data) {
  434. // 此处放失败后执行的代码
  435. }
  436. });
  437. }
  438. //返程站点信息的数据交互
  439. function backInfoReloadData(data){
  440. back_start_station_list = data.start_order;
  441. back_end_station_list = data.end_order;
  442. $('#back_up_station_time').html(back_start_station_list[0].name);
  443. $('#back_up_station_time').attr('valId',back_start_station_list[0].id);
  444. $('#back_down_station_time').html(back_end_station_list[0].name);
  445. $('#back_down_station_time').attr('valId',back_end_station_list[0].id);
  446. //选择站点的下侧弹层
  447. $("#back_up_station").click(function(){
  448. upDiv(back_start_station_list,'back_up_station_time','back');
  449. $("#mask").css("display","block");
  450. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  451. })
  452. $("#back_down_station").click(function(){
  453. upDiv(back_end_station_list,'back_down_station_time','back');
  454. $("#mask").css("display","block");
  455. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  456. })
  457. back_ticket = data.ticket;
  458. back_run_id = data.run_id;
  459. back_line_id = data.line_id;
  460. var back_start_station_id = $('#back_up_station_time').attr('valid');
  461. var back_end_station_id = $('#back_down_station_time').attr('valid');
  462. //犹豫异步加载的问题 所以只能在展示数据后 继续调用票种价格等相关信息
  463. $.ajax({
  464. url:'./zz-fx/control.php',
  465. type: "post",
  466. data: {
  467. run_id:back_run_id,
  468. line_id:back_line_id,
  469. start_id:back_start_station_id,
  470. end_id:back_end_station_id,
  471. tickets:back_ticket,
  472. back:2,
  473. type:"retrieval_tickets"
  474. },
  475. dataType: "json",
  476. success: function (data) {
  477. if(data.code == 0){
  478. console.log(data);
  479. //替换去程票种数量信息
  480. showCountInfoByBack(data.list);
  481. }
  482. },
  483. fail: function (data) {
  484. // 此处放失败后执行的代码
  485. }
  486. });
  487. }
  488. //返程票种数量相关信息
  489. function showCountInfoByBack(data){
  490. var html1 = '';
  491. var temp1 = count_html;
  492. temp1 = temp1.replace('[座位等级]',data.site_type);
  493. temp1 = temp1.replace('[价格]',parseFloat(data.price)*2);
  494. //数量
  495. var maxCount = data.num > 20 ? 20 : data.num;
  496. maxCount = maxCount>0 ? maxCount : 0;
  497. stockCount = maxCount < stockCount ? maxCount : stockCount;
  498. html1 += temp1;
  499. $('#seat_count_info').html(html1);
  500. }