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.
 
 
 
 
 
 

952 lines
27 KiB

  1. //Author:zhangsq
  2. //Date:2016-11-17
  3. //Description:填写订单
  4. //全局参数 往返程run_id
  5. var run_id = getPar('run_id');
  6. var start_area_id = getPar('start_area_id');
  7. var end_area_id = getPar('end_area_id');
  8. //是否返程
  9. var if_back = '0'; //0去程 1返程
  10. //去程--- 出发站点 目的站点数组
  11. var go_start_res_ary = '';
  12. var go_end_res_ary = '';
  13. //返程--- 触犯站点 目的站点数组
  14. var back_start_res_ary = '';
  15. var back_end_res_ary = '';
  16. //去程的优惠价格
  17. var go_discount_price = '';
  18. //返程的优惠价格
  19. var back_discount_price = '';
  20. //去程的ticket_id
  21. var go_ticket_id = '';
  22. var stock = '';
  23. //返程的ticket_id
  24. var back_ticket_id = '';
  25. //站点下弹框
  26. var resHTML = '';
  27. // 选中的上下车站点
  28. var selected_res_name = '';
  29. var selected_res_id = '';
  30. var selected_sel_id = '';
  31. //去程的run_date;
  32. var go_run_date = '';
  33. var back_run_date = '';
  34. window.onload = function() {
  35. //站点html 下弹框
  36. resHTML = $('#wei_info').html();
  37. var if_go = getPar('if_go');
  38. if(if_go == 'go') {
  39. $('#backinfo').hide();
  40. if_back = '0';
  41. //加载去程的信息
  42. reloadGoInfo();
  43. } else {
  44. if_back = '1';
  45. //加载返程的信息
  46. reloadBackInfo();
  47. }
  48. }
  49. //页面开始加载去程的信息
  50. function reloadGoInfo() {
  51. var go_data = getStorJson('CacheStationInfo_Go');
  52. if(go_data) {
  53. //替换去程信息
  54. replaceGoInfo(go_data);
  55. var data_str = setJsonHtml(go_data);
  56. $('#goinfo').attr('data_str', data_str);
  57. var sel_station = getStorJson('CacheInfo_custmer');
  58. if(sel_station) {
  59. //加载之前站点的选中信息
  60. // reloadHistoryStation(sel_station);
  61. $('#custmer').val(sel_station.custmer);
  62. $('#tel').val(sel_station.tel);
  63. $('.aticket').text(sel_station.count);
  64. }
  65. } else {
  66. //重新加载
  67. var urlstr = base_api + 'order/order/getRunDetail';
  68. var run_id = $('#goinfo').attr('run_id');
  69. if(!run_id) {
  70. run_id = getPar('run_id');
  71. }
  72. var data = {
  73. start_area_id: start_area_id,
  74. end_area_id: end_area_id,
  75. run_id: run_id
  76. }
  77. ZZLog(data);
  78. $.ajax({
  79. url: urlstr,
  80. data: data,
  81. async: false,
  82. type: 'post',
  83. dataType: 'json',
  84. success: function(data) {
  85. ZZLog(data);
  86. if(data.flag) {
  87. //替换去程数据
  88. var dataHTML = setJsonHtml(data.data);
  89. $('#goinfo').attr('data_str', dataHTML);
  90. replaceGoInfo(data.data);
  91. }
  92. },
  93. error: function(error) {
  94. ZZLog(error);
  95. }
  96. });
  97. }
  98. }
  99. //替换去程的数据
  100. function replaceGoInfo(data) {
  101. console.log(data);
  102. //替换时间信息
  103. $('#gotime').html(data.select_start_res.res_time);
  104. go_run_date = data.run_date;
  105. var year = getMonthAndDayByDate(go_run_date, 'year');
  106. var month = getMonthAndDayByDate(go_run_date, 'month');
  107. if(month < 10) {
  108. month = month.substring(1, month.length);
  109. }
  110. var day = getMonthAndDayByDate(go_run_date, 'day');
  111. var showday = month + '月' + day + '日';
  112. $('#go_day').html(showday);
  113. //判断是否是今天
  114. if(go_run_date == getDateTime(0)) {
  115. $('#go_week').html('今天');
  116. } else {
  117. var str = year + '/' + month + '/' + day;
  118. var week = getWeekDay(str);
  119. $('#go_week').html(week);
  120. }
  121. //run_id
  122. $('#goinfo').attr('run_id', data.run_id);
  123. $('#goinfo').attr('go_run_date', data.run_date);
  124. //替换选中站点信息
  125. var sel_start_info = data.select_start_res;
  126. var sel_end_info = data.select_end_res;
  127. //===站点信息
  128. $('#start_res_go').attr('startres_goid', sel_start_info.res_id);
  129. $('#start_res_go').html(sel_start_info.res_name + '(' + sel_start_info.res_time + ')');
  130. $('#end_res_go').attr('endres_goid', sel_end_info.res_id);
  131. $('#end_res_go').html(sel_end_info.res_name + '(' + sel_end_info.res_time + ')');
  132. //===poi信息
  133. $('#stare_area_id').html(data.start_area_name);
  134. $('#stare_area_id').attr('startarea_goid', data.start_area_id);
  135. $('#end_area_id').html(data.end_area_name);
  136. $('#end_area_id').attr('endarea_goid', data.end_area_id);
  137. //去程站点数据
  138. go_start_res_ary = data.start_res_arr;
  139. go_end_res_ary = data.end_res_arr;
  140. //替换票种 日程信息
  141. var ticket_info = data.ticket_info;
  142. $('#go_price').html(ticket_info.price);
  143. go_discount_price = ticket_info.discount_price;
  144. go_ticket_id = ticket_info.ticket_id;
  145. $('#distance_back').html('全程' + ticket_info.total_distance + '公里');
  146. $('#usetime_back').html('约' + ticket_info.total_time + '到达');
  147. if(go_discount_price > 0) {
  148. $('#discount').html('选择往返有优惠');
  149. } else {
  150. $('#discount').html('');
  151. }
  152. // $('#discount').html('选择往返有优惠');
  153. $('#goinfo').attr('discount_price', ticket_info.discount_price);
  154. $('#select_back').html('添加返程');
  155. $('#select_back').css('color', '#3d434f');
  156. $('#tupian').attr('src', 'images/ic_addback@2x.png');
  157. //库存
  158. stock = ticket_info.stock > 20 ? 20 : ticket_info.stock;
  159. stock = stock > 0 ? stock : 0;
  160. // stock = "10";
  161. countTotal();
  162. $("#loading_html").show();
  163. }
  164. //去程上车站点的选择
  165. function goStartAreaDidClicked() {
  166. $("#mask").css("display", "block");
  167. $('#res_div').css("display", "block");
  168. sel_res_div = 'startres_goid';
  169. upDiv(go_start_res_ary, 'start_res_go', 'go');
  170. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  171. }
  172. //切换去程的出发地站点信息
  173. function changeGoStartResInfo(id, time, name) {
  174. var start_res_id = $('#start_res_go').attr('startres_goid');
  175. var urlstr = base_api + 'order/order/getRunDetailByStart';
  176. var run_id = $('#goinfo').attr('run_id');
  177. $('#gotime').html(time);
  178. var data = {
  179. start_res_id: start_res_id,
  180. end_area_id: end_area_id,
  181. run_id: run_id
  182. }
  183. $.ajax({
  184. url: urlstr,
  185. data: data,
  186. async: false,
  187. type: 'post',
  188. dataType: 'json',
  189. success: function(data) {
  190. ZZLog(data);
  191. if(data.flag) {
  192. //选择去程的出发站点,修改详情数据
  193. showDetailInfoByChangeStartRes(data.data);
  194. //替换 html json 数据
  195. var data_str = $('#goinfo').attr('data_str');
  196. data_str = getJsonHtml(data_str);
  197. data_str.ticket_info = data.data.ticket_info;
  198. data_str.end_res_arr = data.data.end_res_arr;
  199. data_str.select_end_res = data.data.select_end_res;
  200. data_str.select_start_res.res_id = id;
  201. data_str.select_start_res.res_time = time;
  202. data_str.select_start_res.res_name = name;
  203. var data_str = setJsonHtml(data_str);
  204. $('#goinfo').attr('data_str', data_str);
  205. }
  206. },
  207. error: function(error) {
  208. ZZLog(error);
  209. }
  210. });
  211. }
  212. //选择去程的出发站点,修改详情数据
  213. function showDetailInfoByChangeStartRes(data) {
  214. //替换选中站点信息
  215. var sel_end_info = data.select_end_res;
  216. //===站点信息
  217. $('#end_res_go').attr('endres_goid', sel_end_info.res_id);
  218. $('#end_res_go').html(sel_end_info.res_name + '(' + sel_end_info.res_time + ')');
  219. //去程站点数据
  220. go_end_res_ary = data.end_res_arr;
  221. //替换票种 日程信息
  222. var ticket_info = data.ticket_info;
  223. $('#go_price').html(ticket_info.price);
  224. go_discount_price = ticket_info.discount_price;
  225. go_ticket_id = ticket_info.ticket_id;
  226. $('#distance_back').html('全程' + ticket_info.total_distance + '公里');
  227. $('#usetime_back').html('约' + ticket_info.total_time + '到达');
  228. if(go_discount_price > 0) {
  229. $('#discount').html('选择往返有优惠');
  230. } else {
  231. $('#discount').html('');
  232. }
  233. // $('#discount').html('选择往返有优惠');
  234. $('#goinfo').attr('discount_price', go_discount_price);
  235. //库存
  236. stock = ticket_info.stock > stock ? stock : ticket_info.stock;
  237. stock = stock > 0 ? stock : 0;
  238. countTotal();
  239. }
  240. //去程下车站点的选择
  241. function goEndAreaDidClicked() {
  242. $("#mask").css("display", "block");
  243. $('#res_div').css("display", "block");
  244. sel_res_div = 'endres_goid';
  245. upDiv(go_end_res_ary, 'end_res_go', 'go');
  246. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  247. }
  248. //切换去程的目的地站点信息
  249. function changeGoEndResInfo(id, time, name) {
  250. var start_res_id = $('#start_res_go').attr('startres_goid');
  251. var end_res_id = $('#end_res_go').attr('endres_goid');
  252. var urlstr = base_api + 'order/order/getRunDetailByEnd';
  253. var run_id = $('#goinfo').attr('run_id');
  254. var data = {
  255. start_res_id: start_res_id,
  256. end_res_id: end_res_id,
  257. run_id: run_id
  258. }
  259. $.ajax({
  260. url: urlstr,
  261. data: data,
  262. async: false,
  263. type: 'post',
  264. dataType: 'json',
  265. success: function(data) {
  266. ZZLog(data);
  267. if(data.flag) {
  268. //选择去程的目的站点,修改详情数据
  269. showDetailInfoByChangeEndRes(data.data);
  270. //替换 html json 数据
  271. var data_str = $('#goinfo').attr('data_str');
  272. data_str = getJsonHtml(data_str);
  273. data_str.ticket_info = data.data.ticket_info;
  274. data_str.select_end_res.res_id = id;
  275. data_str.select_end_res.res_name = name;
  276. data_str.select_end_res.res_time = time;
  277. var data_str = setJsonHtml(data_str);
  278. $('#goinfo').attr('data_str', data_str);
  279. }
  280. },
  281. error: function(error) {
  282. ZZLog(error);
  283. }
  284. });
  285. }
  286. //选择去程的目的站点,修改详情数据
  287. function showDetailInfoByChangeEndRes(data) {
  288. //替换票种 日程信息
  289. var ticket_info = data.ticket_info;
  290. $('#go_price').html(ticket_info.price);
  291. go_discount_price = ticket_info.discount_price;
  292. go_ticket_id = ticket_info.ticket_id;
  293. $('#distance_back').html('全程' + ticket_info.total_distance + '公里');
  294. $('#usetime_back').html('约' + ticket_info.total_time + '到达');
  295. // $('#discount').html('选择往返有优惠');
  296. $('#goinfo').attr('discount_price', go_discount_price);
  297. if(go_discount_price > 0) {
  298. $('#discount').html('选择往返有优惠');
  299. } else {
  300. $('#discount').html('');
  301. }
  302. //库存
  303. stock = ticket_info.stock > stock ? stock : ticket_info.stock;
  304. stock = stock > 0 ? stock : 0;
  305. countTotal();
  306. }
  307. //添加返程
  308. function selectBackInfo() {
  309. if(if_back == '0') {
  310. //缓存联系人信息
  311. cacheTheCustomerInfo();
  312. //缓存站点信息
  313. cacheTheStationInfo();
  314. if_back = '1';
  315. $('#select_back').html('取消返程');
  316. $('#select_back').css('color', '#999999');
  317. $('#tupian').attr('src', 'images/ic_sub.png');
  318. var start_area_id = $('#stare_area_id').attr('startarea_goid');
  319. var end_area_id = $('#end_area_id').attr('endarea_goid');
  320. var go_run_date = $('#goinfo').attr('go_run_date');
  321. window.location.href = './calendar.html?start_area_id=' + end_area_id + '&end_area_id=' + start_area_id + '&from=fill_order&if_go=go' + '&go_run_date=' + go_run_date;
  322. } else {
  323. cacheTheCustomerInfo();
  324. clearStorage('CacheStationInfo_Back');
  325. if_back = '0';
  326. $('#backinfo').hide();
  327. $('#select_back').html('添加返程');
  328. $('#tupian').attr('src', 'images/ic_addback@2x.png');
  329. var go_discount_price = $('#goinfo').attr('discount_price');
  330. // go_discount_price = 5;
  331. if(go_discount_price > 0) {
  332. $('#discount').html('选择往返有优惠');
  333. } else {
  334. $('#discount').html('');
  335. }
  336. // $('#discount').html('选择往返有优惠');
  337. $('#select_back').css('color', '#3d434f');
  338. countTotal();
  339. }
  340. }
  341. //加载返程的信息
  342. function reloadBackInfo() {
  343. var sel_station = getStorJson('CacheInfo_custmer');
  344. if(sel_station) {
  345. //加载之前站点的选中信息
  346. // reloadHistoryStation(sel_station);
  347. $('#custmer').val(sel_station.custmer);
  348. $('#tel').val(sel_station.tel);
  349. $('.aticket').text(sel_station.count);
  350. }
  351. var back_data = getStorage('CacheStationInfo_Back');
  352. if(back_data) {
  353. //替换去程信息
  354. replaceBackInfo(back_data);
  355. var data_str = setJsonHtml('back_data');
  356. $('#backinfo').attr('data_str', data_str);
  357. } else {
  358. var urlstr = base_api + 'order/order/getRunDetail';
  359. var data = {
  360. start_area_id: start_area_id,
  361. end_area_id: end_area_id,
  362. run_id: run_id
  363. }
  364. $.ajax({
  365. url: urlstr,
  366. data: data,
  367. async: false,
  368. type: 'post',
  369. dataType: 'json',
  370. success: function(data) {
  371. if(data.flag) {
  372. ZZLog(data);
  373. var dataHTML = setJsonHtml(data.data);
  374. $('#backinfo').attr('data_str', dataHTML);
  375. //替换返程数据
  376. replaceBackInfo(data.data);
  377. }
  378. },
  379. error: function(error) {
  380. ZZLog(error);
  381. }
  382. });
  383. }
  384. }
  385. //替换返程数据
  386. function replaceBackInfo(data) {
  387. //展示去程的数据
  388. var go_info = getStorJson('CacheStationInfo_Go');
  389. var data_str = setJsonHtml(go_info);
  390. $('#goinfo').attr('data_str', data_str);
  391. replaceGoInfo(go_info);
  392. console.log(go_info);
  393. $('#backinfo').removeClass('ui_hide');
  394. // 替换时间信息
  395. // $('#backtime').html(data.run_time);
  396. $('#backtime').html(data.select_start_res.res_time);
  397. back_run_date = data.run_date;
  398. var year = getMonthAndDayByDate(back_run_date, 'year');
  399. var month = getMonthAndDayByDate(back_run_date, 'month');
  400. // if (month < 10) {
  401. // month = month.substring(1,month.length-1);
  402. // }
  403. var day = getMonthAndDayByDate(back_run_date, 'day');
  404. var showday = month + '月' + day + '日';
  405. $('#back_day').html(showday);
  406. //判断是否是今天
  407. if(back_run_date == getDateTime(0)) {
  408. $('#back_week').html('今天');
  409. } else {
  410. var str = year + '/' + month + '/' + day;
  411. var week = getWeekDay(str);
  412. $('#back_week').html(week);
  413. }
  414. //run_id_back
  415. $('#backinfo').attr('run_id', data.run_id);
  416. //替换选中站点信息
  417. var sel_start_info = data.select_start_res;
  418. var sel_end_info = data.select_end_res;
  419. //===站点信息
  420. $('#start_res_back').attr('startres_backid', sel_start_info.res_id);
  421. $('#start_res_back').html(sel_start_info.res_name + '(' + sel_start_info.res_time + ')');
  422. $('#end_res_back').attr('endres_backid', sel_end_info.res_id);
  423. $('#end_res_back').html(sel_end_info.res_name + '(' + sel_end_info.res_time + ')');
  424. //===poi信息
  425. $('#back_stare_area_id').html(data.start_area_name);
  426. $('#back_stare_area_id').attr('startarea_backid', data.start_area_id);
  427. $('#back_end_area_id').html(data.end_area_name);
  428. $('#back_end_area_id').attr('endarea_backid', data.end_area_id);
  429. //返程站点数据
  430. back_start_res_ary = data.start_res_arr;
  431. back_end_res_ary = data.end_res_arr;
  432. //替换票种 日程信息
  433. var ticket_info = data.ticket_info;
  434. // $('#back_price').html(parseInt(ticket_info.price)-parseInt(ticket_info.discount_price)-parseInt(go_discount_price));
  435. $('#back_price').html(parseInt(ticket_info.price));
  436. back_discount_price = ticket_info.discount_price;
  437. back_ticket_id = ticket_info.ticket_id;
  438. // $('#distance_back').html('全程'+ticket_info.total_distance+'公里');
  439. // $('#usetime_back').html(ticket_info.total_time+'到达');
  440. var new_price = (parseInt(go_discount_price) + parseInt(back_discount_price));
  441. if(new_price > 0) {
  442. $('#discount').html('已优惠' + new_price + '元/人');
  443. } else {
  444. $('#discount').html('');
  445. }
  446. // $('#discount').html('已优惠'+(parseInt(go_discount_price)+parseInt(back_discount_price))+'元/人');
  447. $('#select_back').html('取消返程');
  448. $('#select_back').css('color', '#3d434f');
  449. $('#tupian').attr('src', 'images/ic_sub.png');
  450. $('#backinfo').attr('discount_price', back_discount_price);
  451. //库存
  452. stock = ticket_info.stock > stock ? stock : ticket_info.stock;
  453. stock = stock > 0 ? stock : 0;
  454. countTotal();
  455. }
  456. //返程上车站点的选择
  457. function goStartAreaDidClickedBack() {
  458. $("#mask").css("display", "block");
  459. $('#res_div').css("display", "block");
  460. sel_res_div = 'startres_backid';
  461. upDiv(back_start_res_ary, 'start_res_back', 'back');
  462. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  463. }
  464. //切换返程的出发地站点信息
  465. function changeBackStartResInfo(id, time, name) {
  466. var start_res_id = $('#start_res_back').attr('startres_backid');
  467. var urlstr = base_api + 'order/order/getRunDetailByStart';
  468. var data = {
  469. start_res_id: start_res_id,
  470. end_area_id: end_area_id,
  471. run_id: run_id
  472. }
  473. $.ajax({
  474. url: urlstr,
  475. data: data,
  476. async: false,
  477. type: 'post',
  478. dataType: 'json',
  479. success: function(data) {
  480. ZZLog(data);
  481. if(data.flag) {
  482. //选择返程的出发站点,修改详情数据
  483. showDetailInfoByChangeStartResBack(data.data);
  484. //替换 html json 数据
  485. var data_str = $('#backinfo').attr('data_str');
  486. data_str = getJsonHtml(data_str);
  487. data_str.ticket_info = data.data.ticket_info;
  488. data_str.end_res_arr = data.data.end_res_arr;
  489. data_str.select_end_res = data.data.select_end_res;
  490. data_str.select_start_res.res_id = id;
  491. data_str.select_start_res.res_time = time;
  492. data_str.select_start_res.res_name = name;
  493. var data_str = setJsonHtml(data_str);
  494. $('#backinfo').attr('data_str', data_str);
  495. }
  496. },
  497. error: function(error) {
  498. ZZLog(error);
  499. }
  500. });
  501. }
  502. //选择返程的出发站点,修改详情数据
  503. function showDetailInfoByChangeStartResBack(data) {
  504. //替换选中站点信息
  505. var sel_end_info = data.select_end_res;
  506. //===站点信息
  507. $('#end_res_back').attr('endres_backid', sel_end_info.res_id);
  508. $('#end_res_back').html(sel_end_info.res_name + '(' + sel_end_info.res_time + ')');
  509. //去程站点数据
  510. back_end_res_ary = data.end_res_arr;
  511. //替换票种 日程信息
  512. var ticket_info = data.ticket_info;
  513. // $('#back_price').html(parseInt(ticket_info.price)-parseInt(ticket_info.discount_price)-parseInt(go_discount_price));
  514. $('#back_price').html(parseInt(ticket_info.price));
  515. back_discount_price = ticket_info.discount_price;
  516. back_ticket_id = ticket_info.ticket_id;
  517. // $('#distance_back').html('全程'+ticket_info.total_distance+'公里');
  518. // $('#usetime_back').html(ticket_info.total_time+'到达');
  519. // $('#discount').html('选择往返有优惠');
  520. var new_price = (parseInt(go_discount_price) + parseInt(back_discount_price));
  521. if(new_price > 0) {
  522. $('#discount').html('已优惠' + new_price + '元/人');
  523. } else {
  524. $('#discount').html('');
  525. }
  526. // $('#discount').html('已优惠'+(parseInt(go_discount_price)+parseInt(back_discount_price))+'元/人');
  527. $('#backinfo').attr('discount_price', back_discount_price);
  528. //库存
  529. stock = ticket_info.stock > stock ? stock : ticket_info.stock;
  530. stock = stock > 0 ? stock : 0;
  531. countTotal();
  532. }
  533. //返程下车站点的选择
  534. function goEndAreaDidClickedBack() {
  535. $("#mask").css("display", "block");
  536. $('#res_div').css("display", "block");
  537. sel_res_div = 'endres_backid';
  538. upDiv(back_end_res_ary, 'end_res_back', 'back');
  539. $("#weui_actionsheet").addClass("weui_actionsheet_toggle");
  540. }
  541. //切换返程的目的地站点信息
  542. function changeBackEndResInfo(id, time, name) {
  543. var start_res_id = $('#start_res_back').attr('startres_backid');
  544. var end_res_id = $('#end_res_back').attr('endres_backid');
  545. var urlstr = base_api + 'order/order/getRunDetailByEnd';
  546. var data = {
  547. start_res_id: start_res_id,
  548. end_res_id: end_res_id,
  549. run_id: run_id
  550. }
  551. $.ajax({
  552. url: urlstr,
  553. data: data,
  554. async: false,
  555. type: 'post',
  556. dataType: 'json',
  557. success: function(data) {
  558. ZZLog(data);
  559. if(data.flag) {
  560. //选择去程的目的站点,修改详情数据
  561. showDetailInfoByChangeEndResBack(data.data);
  562. //替换 html json 数据
  563. var data_str = $('#backinfo').attr('data_str');
  564. data_str = getJsonHtml(data_str);
  565. data_str.ticket_info = data.data.ticket_info;
  566. data_str.select_end_res.res_id = id;
  567. data_str.select_end_res.res_name = name;
  568. data_str.select_end_res.res_time = time;
  569. var data_str = setJsonHtml(data_str);
  570. $('#backinfo').attr('data_str', data_str);
  571. }
  572. },
  573. error: function(error) {
  574. ZZLog(error);
  575. }
  576. });
  577. }
  578. //选择返程的目的站点,修改详情数据
  579. function showDetailInfoByChangeEndResBack(data) {
  580. //替换票种 日程信息
  581. var ticket_info = data.ticket_info;
  582. // $('#back_price').html(parseInt(ticket_info.price)-parseInt(ticket_info.discount_price)-parseInt(go_discount_price));
  583. $('#back_price').html(parseInt(ticket_info.price));
  584. back_discount_price = ticket_info.discount_price;
  585. back_ticket_id = ticket_info.ticket_id;
  586. // $('#distance_back').html('全程'+ticket_info.total_distance+'公里');
  587. // $('#usetime_back').html(ticket_info.total_time+'到达');
  588. // $('#discount').html('选择往返有优惠');
  589. var new_price = (parseInt(go_discount_price) + parseInt(back_discount_price));
  590. if(new_price > 0) {
  591. $('#discount').html('已优惠' + new_price + '元/人');
  592. } else {
  593. $('#discount').html('');
  594. }
  595. // $('#discount').html('已优惠'+(parseInt(go_discount_price)+parseInt(back_discount_price))+'元/人');
  596. $('#backinfo').attr('discount_price', back_discount_price);
  597. //库存
  598. stock = ticket_info.stock > stock ? stock : ticket_info.stock;
  599. stock = stock > 0 ? stock : 0;
  600. countTotal();
  601. }
  602. //缓存联系人信息
  603. function cacheTheCustomerInfo() {
  604. var custmer = $('#custmer').val();
  605. var tel = $('#tel').val();
  606. var count = $('.aticket').text();
  607. var info_data = {
  608. custmer: custmer,
  609. tel: tel,
  610. count: count
  611. };
  612. setStorJson('CacheInfo_custmer', info_data);
  613. }
  614. //缓存站点信息
  615. function cacheTheStationInfo() {
  616. if(if_back == '0') {
  617. //去程
  618. var data_str = $('#goinfo').attr('data_str');
  619. data_str = getJsonHtml(data_str);
  620. setStorJson('CacheStationInfo_Go', data_str);
  621. } else {
  622. //去程
  623. var data_str = $('#goinfo').attr('data_str');
  624. data_str = getJsonHtml(data_str);
  625. setStorJson('CacheStationInfo_Go', data_str);
  626. //返程
  627. var data_str_back = $('#backinfo').attr('data_str');
  628. data_str_back = getJsonHtml(data_str_back);
  629. setStorJson('CacheStationInfo_Back', data_str_back);
  630. }
  631. }
  632. //提交订单
  633. function payBtnDidClicked() {
  634. delay(makorder,300);
  635. function makorder() {
  636. var custmer = $('#custmer').val();
  637. var tel = $('#tel').val();
  638. var phoneRe = /^1[3|4|5|7|8]\d{9}$/;
  639. var custmer_count = $('.aticket').text();
  640. if(custmer == '' || tel == '') {
  641. alert('请填写联系人信息!')
  642. return;
  643. } else if(!phoneRe.test(tel)) {
  644. alert('请输入正确的手机号!')
  645. return;
  646. } else if(custmer_count == '0') {
  647. alert('请填写正确的票种数量!');
  648. return;
  649. }
  650. var customer_info = '{' + custmer + ',' + tel + ',' + " " + '}';
  651. var new_str = '';
  652. if(if_back == '0') {
  653. var go_run_id = $('#goinfo').attr('run_id');
  654. var go_discount = $('#goinfo').attr('discount_price');
  655. var go_price = parseInt($('#go_price').html());
  656. new_str = '{1' + ',' + go_run_id + ',' + go_ticket_id + ',' + go_price + ',' + custmer_count + '}';
  657. } else {
  658. var go_run_id = $('#goinfo').attr('run_id');
  659. var go_discount = $('#goinfo').attr('discount_price');
  660. var go_price = parseInt($('#go_price').html()) - parseInt(go_discount);
  661. new_str = '{1' + ',' + go_run_id + ',' + go_ticket_id + ',' + go_price + ',' + custmer_count + '}';
  662. var back_run_id = $('#backinfo').attr('run_id');
  663. var back_discount = $('#backinfo').attr('discount_price');
  664. var back_price = parseInt($('#back_price').html()) - parseInt(back_discount);
  665. new_str += '{2' + ',' + back_run_id + ',' + back_ticket_id + ',' + back_price + ',' + custmer_count + '}';
  666. }
  667. var data = {
  668. customer_info: customer_info,
  669. ticket_info: new_str
  670. };
  671. ZZLog(data);
  672. $("#loadingToast").show();
  673. $("#payBtn").removeAttr('onClick');
  674. $.ajax({
  675. url: base_api + 'order/order/submitOrder',
  676. data: data,
  677. async: false,
  678. type: 'post',
  679. dataType: 'json',
  680. success: function(data) {
  681. if(data.flag) {
  682. clearStorage('disney_tranship');
  683. $("#loadingToast").hide();
  684. $("#payBtn").attr('onClick', 'payBtnDidClicked();');
  685. window.location.href = data.url;
  686. } else {
  687. $("#loadingToast").hide();
  688. $("#payBtn").attr('onClick', 'payBtnDidClicked();');
  689. if (data.code != '10001') {
  690. alert(data.msg);
  691. } else{
  692. return;
  693. }
  694. }
  695. },
  696. error: function(error) {
  697. ZZLog(error);
  698. }
  699. });
  700. }
  701. }
  702. //上弹框的内容封装
  703. function upDiv(data, select_id, goBack) {
  704. var sel = $('#' + select_id).attr(sel_res_div);
  705. var html = '';
  706. for(var i = 0; i < data.length; i++) {
  707. var tempHTML = resHTML;
  708. tempHTML = tempHTML.replace('示例菜单', data[i].res_name);
  709. tempHTML = tempHTML.replace('[res_id]', data[i].res_id);
  710. tempHTML = tempHTML.replace('[showtime]', data[i].res_time);
  711. if(sel == data[i].res_id) {
  712. tempHTML = tempHTML.replace('images/a3/ic_select_nor.png', 'images/a3/ic_select_sel.png');
  713. } else {
  714. tempHTML = tempHTML.replace('images/a3/ic_select_nor.png', 'images/a3/ic_select_nor.png');
  715. }
  716. html += tempHTML;
  717. }
  718. $('#wei_info').html(html);
  719. $('#actionsheet_cancel').click(function() {
  720. $('#mask').click();
  721. })
  722. $('.weui_actionsheet_cell').parent().click(function() {
  723. console.log($(this).children().eq(0).attr('id'));
  724. selected_res_name = $(this).children().eq(0).text();
  725. selected_res_id = $(this).children().eq(0).attr('id');
  726. selected_sel_id = select_id;
  727. var seltime = $(this).children().eq(0).attr('showtime');
  728. $('#' + select_id).html($(this).children().eq(0).text() + '(' + seltime + ')');
  729. $('#' + select_id).attr(sel_res_div, $(this).children().eq(0).attr('id'));
  730. $('#mask').click();
  731. var id = $(this).children().eq(0).attr('id');
  732. var name = $(this).children().eq(0).text();
  733. var time = seltime;
  734. switch(select_id) {
  735. case 'start_res_go':
  736. //切换去程的出发地站点信息
  737. changeGoStartResInfo(id, time, name);
  738. break;
  739. case 'end_res_go':
  740. //切换去程的目的地站点信息
  741. changeGoEndResInfo(id, time, name);
  742. break;
  743. case 'start_res_back':
  744. //切换去程的出发地站点信息
  745. changeBackStartResInfo(id, time, name);
  746. break;
  747. case 'end_res_back':
  748. //切换去程的目的地站点信息
  749. changeBackEndResInfo(id, time, name);
  750. break;
  751. default:
  752. break;
  753. }
  754. })
  755. }
  756. //点击了蒙板
  757. $('#mask').click(function() {
  758. $("#mask").css("display", "none");
  759. $("#weui_actionsheet").removeClass("weui_actionsheet_toggle");
  760. // $('#res_div').hide();
  761. })
  762. //加
  763. $(".add").on("click", function() {
  764. var current = $('.aticket').text();
  765. var now_count = parseInt(current) + 1;
  766. if(now_count >= stock) {
  767. $('.aticket').text(stock);
  768. if(now_count > stock) {
  769. alert('没有更多的库存!')
  770. }
  771. $('.add').addClass('bor_right_c');
  772. $('.add').removeClass('bor_right');
  773. $('.cut').addClass('bor_left');
  774. $('.cut').removeClass('bor_left_c');
  775. } else {
  776. $('.aticket').text(now_count);
  777. $('.add').removeClass('bor_right_c');
  778. $('.add').addClass('bor_right');
  779. $('.cut').addClass('bor_left');
  780. $('.cut').removeClass('bor_left_c');
  781. }
  782. countTotal();
  783. });
  784. //减
  785. $(".cut").on("click", function() {
  786. var current = $('.aticket').text();
  787. var now_count = parseInt(current) - 1;
  788. if(now_count > 1 && now_count <= stock) {
  789. $('.aticket').text(now_count);
  790. $('.cut').addClass('bor_left');
  791. $('.cut').removeClass('bor_left_c');
  792. $('.add').removeClass('bor_right_c');
  793. $('.add').addClass('bor_right');
  794. } else {
  795. // alert('请选择正确的数量!');
  796. $('.aticket').text('1');
  797. $('.cut').removeClass('bor_left');
  798. $('.cut').addClass('bor_left_c');
  799. $('.add').removeClass('bor_right_c');
  800. $('.add').addClass('bor_right');
  801. }
  802. countTotal();
  803. })
  804. //计算价格信息
  805. function countTotal() {
  806. var count = $('.aticket').text();
  807. // $('#total_people').html('共'+count+'人');
  808. var price = '';
  809. var count_price = '';
  810. if(if_back == '0') {
  811. price = parseInt($('#go_price').html());
  812. // count_price = parseInt($('#goinfo').attr('discount_price'));
  813. // if (count_price > 0) {
  814. // $('#total_people').html('共'+count+'人'+'&nbsp;&nbsp;'+'优惠'+count_price*count+'元');
  815. // } else{
  816. $('#total_people').html('共' + count + '人');
  817. // }
  818. } else {
  819. price = parseInt($('#go_price').html()) + parseInt($('#back_price').html());
  820. count_price = parseInt($('#goinfo').attr('discount_price')) + parseInt($('#backinfo').attr('discount_price'));
  821. if(count_price > 0) {
  822. $('#total_people').html('共' + count + '人' + '&nbsp;&nbsp;' + '优惠' + count_price * count + '元');
  823. } else {
  824. $('#total_people').html('共' + count + '人');
  825. }
  826. }
  827. $('#count_price').html(count * price);
  828. }
  829. var delay = (function() {
  830. var timer = 0;
  831. return function(callback, time) {
  832. clearTimeout(timer);
  833. timer = setTimeout(callback, time);
  834. };
  835. })()