Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

612 rindas
18 KiB

  1. //记录添加的信息
  2. var i = 0;
  3. //author:
  4. //update by : fuhc
  5. var order_from_id = "-1";
  6. var returnStartArea = ""
  7. var returnEndArea = "";
  8. //fancheng prod_id
  9. var back_prod_id = '';
  10. var back_run_id = ''; //返程run_id
  11. var checkedValue = ''; //是否是返程
  12. //
  13. var start_date = '';
  14. if(window.ActiveXObject) {
  15. var myreq = new ActiveXObject("Microsoft.XMLHTTP");
  16. } else {
  17. var myreq = new XMLHttpRequest();
  18. }
  19. var ticketArray = new Array();
  20. var m_runid = 0;
  21. function ZZLog(str){
  22. var isLog=true;
  23. if(isLog){
  24. console.log(str);
  25. }
  26. }
  27. $(document).ready(function(){
  28. id = getPar("id");
  29. var run_id = getPar("run_id");
  30. m_runid = run_id;
  31. start_date = getPar('run_date');
  32. $('#start_date').html(start_date);
  33. $('#id-date-picker-1').val(after(start_date));
  34. document.getElementById('tableInfo').innerHTML = '';
  35. var tnowtime = getDateTime(4);
  36. //var myURL = "./st-xm/Api/get_run_sale_ticket.php?tt=" + tnowtime + "&runid=" + run_id;
  37. $.ajax({
  38. url:'./st-xm/Api/get_run_sale_ticket_outside.php', //请求地址
  39. type: "get", //请求方式
  40. data:{
  41. tt: tnowtime,
  42. runid: run_id
  43. },
  44. async:false,
  45. dataType: "json",
  46. success: function (myJson){
  47. console.log(myJson);
  48. var myTicket = myJson.ticket_list;
  49. var num1 = myTicket.length;
  50. p_cirname = myTicket[0].circuitry_name;
  51. document.getElementById('line').innerHTML = p_cirname;
  52. for(var i = 0; i < num1; i++) {
  53. ticketArray[i] = new Array();
  54. ticketArray[i][0] = myTicket[i].prod_id;
  55. ticketArray[i][1] = myTicket[i].prod_name;
  56. ticketArray[i][2] = myTicket[i].start_station_res_id;
  57. ticketArray[i][3] = myTicket[i].start_station_res_name;
  58. ticketArray[i][4] = myTicket[i].end_station_res_id;
  59. ticketArray[i][5] = myTicket[i].end_station_res_name;
  60. ticketArray[i][6] = myTicket[i].prod_price;
  61. ticketArray[i][7] = myTicket[i].seat_type;
  62. ticketArray[i][8] = myTicket[i].seat_type_name;
  63. }
  64. var myOrg = myJson.sale_org;
  65. num1 = myOrg.length;
  66. var temp = '<li value="0" class="filter-item items" data-filter="请选择">请选择</li>';
  67. for (var i=0;i<myOrg.length;i++) {
  68. temp += '<li value="'+myOrg[i].org_id+'" class="filter-item items" data-filter="'+myOrg[i].soure+'">'+myOrg[i].soure+'</li>'
  69. }
  70. $("#orderSource").html(temp);
  71. $(".filter-item").click(function() {
  72. order_from_id = $(this).val();
  73. });
  74. show_start_station();
  75. }
  76. });
  77. })
  78. function show_start_station() {
  79. var num1 = ticketArray.length;
  80. var n_old_station_res_id = 0;
  81. var n_now_station_res_id = 0;
  82. var staArray = new Array();
  83. var num2 = 0;
  84. var nflag = 0;
  85. for(var i = 0; i < num1; i++) {
  86. n_now_station_res_id = ticketArray[i][2];
  87. nflag = 0;
  88. num2 = staArray.length;
  89. for(var j = 0; j < num2; j++) {
  90. n_old_station_res_id = staArray[j][0];
  91. if(n_old_station_res_id - n_now_station_res_id == 0) nflag = 1;
  92. }
  93. if(nflag == 0) {
  94. staArray[num2] = new Array();
  95. staArray[num2][0] = ticketArray[i][2];
  96. staArray[num2][1] = ticketArray[i][3];
  97. }
  98. }
  99. num1 = staArray.length;
  100. if(num1 > 0) {
  101. var obj1 = document.getElementById('startArea');
  102. obj1.length = 0;
  103. for(var i = 0; i < num1; i++) {
  104. var myOption = new Option(staArray[i][1], staArray[i][0]);
  105. obj1.options[obj1.options.length] = myOption;
  106. }
  107. obj1.options.selectedIndex = 0;
  108. show_end_station();
  109. }
  110. }
  111. function show_end_station() {
  112. var obj2 = document.getElementById('startArea');
  113. var start_res_id = obj2.options[obj2.options.selectedIndex].value;
  114. var num1 = ticketArray.length;
  115. var n_old_station_res_id = 0;
  116. var n_now_station_res_id = 0;
  117. var n_now_start_res_id = 0;
  118. var staArray = new Array();
  119. var num2 = 0;
  120. var nflag = 0;
  121. for(var i = 0; i < num1; i++) {
  122. n_now_station_res_id = ticketArray[i][4];
  123. n_now_start_res_id = ticketArray[i][2];
  124. if(n_now_start_res_id - start_res_id == 0) {
  125. nflag = 0;
  126. num2 = staArray.length;
  127. for(var j = 0; j < num2; j++) {
  128. n_old_station_res_id = staArray[j][0];
  129. if(n_old_station_res_id - n_now_station_res_id == 0) nflag = 1;
  130. }
  131. if(nflag == 0) {
  132. staArray[num2] = new Array();
  133. staArray[num2][0] = ticketArray[i][4];
  134. staArray[num2][1] = ticketArray[i][5];
  135. }
  136. }
  137. }
  138. num1 = staArray.length;
  139. if(num1 > 0) {
  140. var obj1 = document.getElementById('endArea');
  141. obj1.length = 0;
  142. for(var i = 0; i < num1; i++) {
  143. var myOption = new Option(staArray[i][1], staArray[i][0]);
  144. obj1.options[obj1.options.length] = myOption;
  145. }
  146. obj1.options.selectedIndex = 0;
  147. }
  148. show_ticket_list();
  149. }
  150. function show_ticket_list() {
  151. var obj1 = document.getElementById('startArea');
  152. var obj2 = document.getElementById('endArea');
  153. var obj3 = document.getElementById('tableInfo');
  154. obj3.innerHTML = '';
  155. var start_res_id = obj1.options[obj1.options.selectedIndex].value;
  156. var end_res_id = obj2.options[obj2.options.selectedIndex].value;
  157. var num1 = ticketArray.length;
  158. var cstr1 = '';
  159. for(var i = 0; i < num1; i++) {
  160. var now_start_res_id = ticketArray[i][2];
  161. var now_end_res_id = ticketArray[i][4];
  162. if((now_start_res_id - start_res_id == 0) && (now_end_res_id - end_res_id == 0)) {
  163. if(ticketArray[i][1].indexOf('往返') != -1) {
  164. cstr1 += '<tr id ="back_back">';
  165. } else {
  166. cstr1 += '<tr id ="go_go">';
  167. }
  168. cstr1 += '<td style="width:80px;">' + ticketArray[i][8] + '</td>';
  169. cstr1 += '<td id="back" style="width:90px;">' + ticketArray[i][1] + '</td>';
  170. cstr1 += '<td style="width:90px;">' + ticketArray[i][6] + '</td>';
  171. cstr1 += '<td style="width: 105px;"><select id="ticket_count_' + i + '" style="font-size: 12px; width: 60px;">';
  172. for(var j = 0; j <= 20; j++) {
  173. cstr1 += '<option value=' + j + '>' + j + '</option>';
  174. }
  175. cstr1 += '</select></td>';
  176. }
  177. }
  178. obj3.innerHTML = cstr1;
  179. var t_back_select = $('#ifback').val();
  180. if(t_back_select == 1) {
  181. var t_checked = true;
  182. } else {
  183. var t_checked = false;
  184. }
  185. ifbackSelected(t_checked);
  186. }
  187. //添加乘客人信息
  188. function addLine() {
  189. var addInfo = document.getElementById('addInfo');
  190. //tr
  191. var div = document.createElement("div");
  192. div.id = "newInfo" + i;
  193. // div.style({"width":'300px'},{"height":'100px'});
  194. div.style.height = '100px';
  195. div.style.width = '350px';
  196. var newInfo = $('#left').html();
  197. newInfo += newInfo.replace('delBtn', 'delBtn' + i);
  198. div.innerHTML = newInfo;
  199. addInfo.appendChild(div);
  200. i++;
  201. }
  202. //删除乘客人信息
  203. function delOneLine(sender) {
  204. $('#' + sender).parent().parent().remove();
  205. }
  206. //选中返回的日期date
  207. var end_list2=null;
  208. // function selectDate(value){
  209. // var obj1 = document.getElementById("startAreaback");
  210. // obj1.innerHTML = "";
  211. // var obj2 = document.getElementById("endAreaback");
  212. // obj2.innerHTML = "";
  213. // if(value == null) {
  214. // return;
  215. // }
  216. // // 判断日期是否合理
  217. // var date1 = new Date(start_date.replace(/\-/g, '/'));
  218. // var date2 = new Date(value.replace(/\-/g, '/'));
  219. // if(date2 < date1) {
  220. // $('#id-date-picker-1').val('');
  221. // return;
  222. // }
  223. // var url = "./st-xm/Api/returnInfoSee.php?method=get_run_back_station&cur_run_id=" + m_runid + "&date_f=" + value;
  224. // ZZLog(url);
  225. // var endArea_html = '<option value="0" style="font-size: 12px;">选择班次</option>'
  226. // $.getJSON(url, function(res_data) {
  227. // ZZLog(res_data);
  228. // if(res_data['code'] != "0") {
  229. // alert(res_data['info']);
  230. // return;
  231. // }
  232. // if(res_data['start_station_list'].length < 0) {
  233. // return;
  234. // }
  235. // back_run_id = res_data.start_station_list[0].run_id;
  236. // var start_list = res_data.start_station_list;
  237. // var end_list = res_data.end_station_list;
  238. // end_list2=end_list;
  239. // if(checkedValue != "1") {
  240. // return;
  241. // }
  242. // if(start_list.length == 0) {
  243. // $('#selected').val('无相关班次');
  244. // } else {
  245. // for(var i = 0, m = start_list.length; i < m; i++) {
  246. // var dict = start_list[i];
  247. // var myOption = new Option(dict.start_station_res_name + "-" + dict.start_time, dict.start_station_res_id);
  248. // obj1.options[obj1.options.length] = myOption;
  249. // }
  250. // obj1.options.selectedIndex = 0;
  251. // }
  252. // // 默认给第一个
  253. // show_f_station(end_list,start_list[0]['run_id']);
  254. // });
  255. // }
  256. // function show_f_station2(){
  257. // var start_f_index=document.getElementById("startAreaback").selectedIndex;
  258. // show_f_station(end_list2,end_list2[start_f_index]['run_id']);
  259. // }
  260. // // 显示返程的目的地站
  261. // function show_f_station(end_list,run_id){
  262. // back_run_id=run_id;
  263. // var obj2 = document.getElementById("endAreaback");
  264. // obj2.innerHTML = "";
  265. // for(var i = 0, m = end_list.length; i < m; i++) {
  266. // var dict = end_list[i];
  267. // if(dict['run_id']!=run_id){
  268. // continue;
  269. // }
  270. // var myOption = new Option(dict.end_station_res_name + "-" + dict.end_time, dict.end_station_res_id);
  271. // obj2.options[obj2.options.length] = myOption;
  272. // }
  273. // obj2.options.selectedIndex = 0;
  274. // choose_f_station();
  275. // }
  276. // //选中返回的时间time
  277. // function select_run_time(sender) {}
  278. // //选择返程的上下车站点
  279. // function choose_f_station() {
  280. // var start_f_res_id = $('#startAreaback').val();
  281. // var end_f_res_id = $('#endAreaback').val();
  282. // if(start_f_res_id=="" || start_f_res_id==null || start_f_res_id==undefined
  283. // || end_f_res_id=="" || end_f_res_id==null || end_f_res_id==null){
  284. // alert('出发站或目的地为空则不能下往返程订单');
  285. // return;
  286. // }
  287. // if(start_f_res_id==end_f_res_id){
  288. // alert('出发站与目的地不能相同!!!');
  289. // return;
  290. // }
  291. // var url = "./st-xm/Api/returnInfoSee.php?method=get_run_back_info&f_run_id=" + back_run_id + "&f_st_res_id=" + start_f_res_id + "&f_end_res_id=" + end_f_res_id;
  292. // ZZLog(url);
  293. // $.getJSON(url, function(res_data) {
  294. // ZZLog(res_data);
  295. // if(res_data['code'] != "0") {
  296. // alert(res_data['info']);
  297. // return;
  298. // }
  299. // back_prod_id = res_data['prod_id'];
  300. // if(back_prod_id==null || back_prod_id==undefined || back_prod_id==""){
  301. // alert('没有该返程的票种,不允许下往返程订单!!!');
  302. // return;
  303. // }
  304. // // back_run_id = res_data['run_id'];
  305. // });
  306. // }
  307. function submit_order() {
  308. if($("#usersubmit").html() == "保存中...") {
  309. return;
  310. }
  311. $("#usersubmit").removeClass("btn-info");
  312. $("#usersubmit").html("保存中...");
  313. var num1 = ticketArray.length;
  314. var num2 = 0;
  315. var cstr1 = ''; //单程的
  316. var u_prod = '';
  317. var u_price = '';
  318. for(var i = 0; i < num1; i++) {
  319. var obj1 = document.getElementById('ticket_count_' + i);
  320. if(obj1) {
  321. var num3 = obj1.options[obj1.options.selectedIndex].value;
  322. if(num3 - 0 > 0) {
  323. // 如果是往返就不添加到此参数中
  324. cstr1 += '{m' + ticketArray[i][0] + 'p' + num3 + '|r' + m_runid + '}';
  325. num2 += parseInt(num3);
  326. }
  327. }
  328. }
  329. if(num2 == 0) {
  330. alert('请选择购买票张数!');
  331. $("#usersubmit").addClass("btn-info");
  332. $("#usersubmit").html("提交");
  333. return;
  334. }
  335. var c_cusname = document.getElementById('username').value;
  336. var c_cusmobile = document.getElementById('usernum').value;
  337. var c_cusidno = document.getElementById('userid').value;
  338. var c_ordersource = order_from_id;
  339. var c_channelno = document.getElementById('channelNum').value;
  340. if(c_ordersource == "-1") {
  341. alert('请选择订单渠道!');
  342. $("#usersubmit").addClass("btn-info");
  343. $("#usersubmit").html("提交");
  344. return;
  345. }
  346. if(c_cusname == '') {
  347. alert('请输入联系人姓名!');
  348. $("#usersubmit").addClass("btn-info");
  349. $("#usersubmit").html("提交");
  350. return;
  351. }
  352. if(c_cusmobile == '') {
  353. alert('请输入联系人手机!');
  354. $("#usersubmit").addClass("btn-info");
  355. $("#usersubmit").html("提交");
  356. return;
  357. }
  358. if(checkPhone(c_cusmobile)==false){
  359. $("#usersubmit").addClass("btn-info");
  360. $("#usersubmit").html("提交");
  361. return;
  362. }
  363. if(isCardNo(c_cusidno) == false) {
  364. $("#usersubmit").addClass("btn-info");
  365. $("#usersubmit").html("提交");
  366. return;
  367. }
  368. //订单备注
  369. // $("#accuracy").val($("#accuracy").val().replace(/\ +/g,""));//去掉空格
  370. //$("#content").val($("#content").val().replace(/[ ]/g,"")); //去掉空格
  371. //$("#content").val($("#content").val().replace(/[\r\n]/g,""));//去掉回车换行
  372. var order_comment=$('#order_remark').val();
  373. // order_comment=order_comment.replace(/\ +/g,"");
  374. // order_comment=order_comment.replace(/[ ]/g,"");
  375. order_comment=order_comment.replace(/[\r\n]/g,"");
  376. if(order_comment.length>500){
  377. $("#usersubmit").addClass("btn-info");
  378. $("#usersubmit").html("提交");
  379. alert('订单备注超出字数限制,限500字');
  380. return;
  381. }
  382. // {prod_id,姓名 ,性别,手机 ,证件类型,证件号 ,地址,地址对应地区ID,邮编,备注}
  383. // var cstr2 = '{,' + c_cusname + ',1,' + c_cusmobile + ',150,' + c_cusidno + ',,0,,'+order_comment+'}';
  384. // 不用逗号连接 因为后端存储过程是以,分割获取参数
  385. // 决定用^
  386. var cstr2 = '{^' + c_cusname + '^1^' + c_cusmobile + '^150^' + c_cusidno + '^^0^^'+order_comment+'}';
  387. var tnowtime = getDateTime(4);
  388. var myURL = '';
  389. myURL = '/st-xm/Api/add_new_order_outside.php?prod=' + cstr1 + '&customer=' + cstr2 + '&order_from_org_id=' + c_ordersource + '&outside_order_id=' + c_channelno + '&tt=' + tnowtime;
  390. ZZLog(myURL);
  391. //得到返程的prod_id
  392. $.getJSON(myURL, function(date) {
  393. ZZLog(date);
  394. if(date.errcode != "0") {
  395. alert('订单提交失败!原因:' + date.errinfo);
  396. $("#usersubmit").addClass("btn-info");
  397. $("#usersubmit").html("提交");
  398. return;
  399. } else {
  400. alert('订单提交成功!订单号:' + date.order_id);
  401. location.href = '/order_list.html';
  402. }
  403. });
  404. // /st-xm/Api/add_new_order_outside.php?prod={mG1104106T1996p2|rG1104106T1996}&customer={^孵化场^1^18682645203^150^511621199502032173^^0^^fdafdas}&order_from_org_id=2&outside_order_id=43&tt=20160831154316
  405. }
  406. //返程信息选中
  407. function ifbackSelected(value) {
  408. if(value == true) {
  409. var yes = $('#ifback').val('1');
  410. $('#back_back').show();
  411. $('#go_go').hide();
  412. checkedValue = "1";
  413. selectDate($('#id-date-picker-1').val());
  414. var num1 = ticketArray.length;
  415. for(var i = 0; i < num1; i++) {
  416. var obj1 = document.getElementById('ticket_count_' + i);
  417. if(obj1) {
  418. var num3 = obj1.options[obj1.options.selectedIndex].value;
  419. if(num3 - 0 > 0) {
  420. obj1.selectedIndex=0;
  421. }
  422. }
  423. }
  424. } else {
  425. var no = $('#ifback').val('0');
  426. $('#back_back').hide();
  427. $('#go_go').show();
  428. checkedValue = "0";
  429. //selectDate(null);
  430. }
  431. }
  432. function isCardNo(card) {
  433. if(card) {
  434. // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
  435. var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  436. if(reg.test(card) === false) {
  437. alert("身份证输入不合法");
  438. return false;
  439. } else {
  440. return true;
  441. }
  442. }
  443. }
  444. //验证手机号
  445. function checkPhone(phone) {
  446. if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))) {
  447. alert("手机号码有误,请重填");
  448. return false;
  449. } else {
  450. return true;
  451. }
  452. }
  453. function after(d) {
  454. if(d) {
  455. d = new Date(d);
  456. d = +d + 1000*60*60*24;
  457. d = new Date(d);
  458. //return d;
  459. //格式化
  460. var year = ";" + d.getFullYear() + ";";
  461. var month = ";" + (d.getMonth()+0+1) + ";";
  462. var day = ";" + d.getDate() + ";";
  463. if(year.length < 4) {
  464. year = "0" + year;
  465. }
  466. if(month.length < 4) {
  467. month = "0" + month;
  468. }
  469. if(day.length < 4) {
  470. day = "0" + day;
  471. }
  472. var datestr = year + "-" + month + "-" + day;
  473. datestr = datestr.replace(/;/g, "");
  474. return datestr;
  475. } else {
  476. return "";
  477. }
  478. }
  479. function ConvertDateFromString(dateString) {
  480. if(dateString) {
  481. var sdate = dateString.split('-');
  482. var date = new Date(sdate[0], sdate[1], sdate[2]);
  483. return date;
  484. }
  485. }
  486. function getPar(par) {
  487. //获取当前URL
  488. var local_url = document.location.href;
  489. local_url = decodeURI(local_url);
  490. //获取要取得的get参数位置
  491. var get = local_url.indexOf(par + "=");
  492. if(get == -1) {
  493. return "";
  494. }
  495. //截取字符串
  496. var get_par = local_url.slice(par.length + get + 1);
  497. //判断截取后的字符串是否还有其他get参数
  498. var nextPar = get_par.indexOf("&");
  499. if(nextPar != -1) {
  500. get_par = get_par.slice(0, nextPar);
  501. }
  502. return get_par;
  503. }
  504. function getDateTime(nTypeFlag) {
  505. var tNowTime = new Date();
  506. var myYear = ';' + tNowTime.getFullYear() + ';';
  507. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  508. var myDay = ';' + tNowTime.getDate() + ';';
  509. var myHour = ';' + tNowTime.getHours() + ';';
  510. var myMinu = ';' + tNowTime.getMinutes() + ';';
  511. var mySecond = ';' + tNowTime.getSeconds() + ';';
  512. if(myMonth.length < 4) myMonth = '0' + myMonth;
  513. if(myDay.length < 4) myDay = '0' + myDay;
  514. if(myHour.length < 4) myHour = '0' + myHour;
  515. if(myMinu.length < 4) myMinu = '0' + myMinu;
  516. if(mySecond.length < 4) mySecond = '0' + mySecond;
  517. var cNewTimeStr;
  518. //alert(tNowTime);
  519. switch(nTypeFlag + 1 - 1) {
  520. case 0:
  521. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  522. break;
  523. case 1:
  524. cNewTimeStr = myYear + myMonth + myDay;
  525. break;
  526. case 2:
  527. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  528. break;
  529. case 3:
  530. cNewTimeStr = myHour + myMinu + mySecond;
  531. break;
  532. case 4:
  533. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  534. break;
  535. case 5:
  536. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  537. break;
  538. case 6:
  539. cNewTimeStr = myYear;
  540. break;
  541. case 7:
  542. cNewTimeStr = myYear + '-' + myMonth;
  543. break;
  544. default:
  545. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  546. break;
  547. }
  548. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  549. return cNewTimeStr;
  550. }
  551. //function update_order_price(order_id,price){
  552. // //修改价格信息
  553. // $.ajax({
  554. // url: './st-xm/Api/change_price.php', //请求地址
  555. // type: "post", //请求方式
  556. // data: {
  557. // ordid: order_id,
  558. // prod_list: price
  559. // }, //请求参数
  560. // async: false,
  561. // dataType: "json",
  562. // success: function(date) {
  563. // ZZLog('修改订单价格');
  564. // ZZLog(date);
  565. // },
  566. // fail: function(date) {
  567. // // 此处放失败后执行的代码
  568. // }
  569. // });
  570. //}