選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

312 行
10 KiB

  1. var httpData;
  2. var page_size = 10;
  3. var mUrl = "./select_ticket.html";
  4. if (window.ActiveXObject) {
  5. var myreq = new ActiveXObject("Microsoft.XMLHTTP");
  6. } else {
  7. var myreq = new XMLHttpRequest();
  8. }
  9. var tableText = '';
  10. var seatText = '';
  11. var crowdText = '';
  12. var priceText = '';
  13. var stockText = '';
  14. var orderText = '';
  15. window.onload = function() {
  16. $('#id-date-picker-1').val(getDateTime(0));
  17. tableText = document.getElementById("tableTicket").innerHTML;
  18. seatText = document.getElementById("st").innerHTML;
  19. // crowdText = document.getElementById("crowd").innerHTML;
  20. priceText = document.getElementById("price").innerHTML;
  21. stockText = document.getElementById("stock").innerHTML;
  22. orderText = document.getElementById("order").innerHTML;
  23. var currpage = getPar('currpage');
  24. //var startTime = getPar("startTime");
  25. //var endTime = getPar("endTime");
  26. var seat = getPar("seat") ? getPar("seat") : '';
  27. if (currpage) {
  28. var user_id = getPar("user_id");
  29. var start_area = getPar("start_area");
  30. var end_area = getPar("end_area");
  31. var run_date = getPar("run_date");
  32. var run_line = getPar("run_line");
  33. $('#startArea').val(start_area);
  34. $('#endArea').val(end_area);
  35. $('#id-date-picker-1').val(run_date);
  36. $('#run_line').val(run_line);
  37. var tnowtime = getDateTime(4);
  38. var myURL = "./st-xm/Api/createOrderContrill.php?method=choiceKicket&tt=" + tnowtime + "&currpage=" + currpage + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat+"&run_line="+run_line;
  39. var myURL2 = "./select_ticket.html?tt=" + tnowtime + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat+"&run_line="+run_line;
  40. method(myURL, myURL2);
  41. }else{
  42. query()
  43. }
  44. }
  45. function before() {
  46. var d = document.getElementById("id-date-picker-1").value;
  47. d = new Date(d);
  48. d = +d - 1000*60*60*24;
  49. d = new Date(d);
  50. //return d;
  51. //格式化
  52. var year = ";" + d.getFullYear() + ";";
  53. var month = ";" + (d.getMonth()+0+1) + ";";
  54. var day = ";" + d.getDate() + ";";
  55. if(year.length < 4) {
  56. year = "0" + year;
  57. }
  58. if(month.length < 4) {
  59. month = "0" + month;
  60. }
  61. if(day.length < 4) {
  62. day = "0" + day;
  63. }
  64. var datestr = year + "-" + month + "-" + day;
  65. datestr = datestr.replace(/;/g, "");
  66. $('#id-date-picker-1').val(datestr);
  67. query();
  68. }
  69. function after() {
  70. var d = document.getElementById("id-date-picker-1").value;
  71. d = new Date(d);
  72. d = +d + 1000*60*60*24;
  73. d = new Date(d);
  74. //return d;
  75. //格式化
  76. var year = ";" + d.getFullYear() + ";";
  77. var month = ";" + (d.getMonth()+0+1) + ";";
  78. var day = ";" + d.getDate() + ";";
  79. if(year.length < 4) {
  80. year = "0" + year;
  81. }
  82. if(month.length < 4) {
  83. month = "0" + month;
  84. }
  85. if(day.length < 4) {
  86. day = "0" + day;
  87. }
  88. var datestr = year + "-" + month + "-" + day;
  89. datestr = datestr.replace(/;/g, "");
  90. $('#id-date-picker-1').val(datestr);
  91. query();
  92. }
  93. function ConvertDateFromString(dateString) {
  94. if (dateString) {
  95. var sdate = dateString.split('-');
  96. var date = new Date(sdate[0], sdate[1], sdate[2]);
  97. return date;
  98. }
  99. }
  100. function query() {
  101. var user_id = getPar("user_id");
  102. var start_area = document.getElementById("startArea").value;
  103. var end_area = document.getElementById("endArea").value;
  104. var run_date = document.getElementById("id-date-picker-1").value;
  105. //var startTime = document.getElementById("timepicker1").value;
  106. //var endTime = document.getElementById("timepicker2").value;
  107. var seat = $('#seat').val() ? $('#seat').val() : '';
  108. var run_line=$('#run_line').val();
  109. var currpage = getPar("currpage");
  110. if (!currpage) {
  111. currpage = 1;
  112. }
  113. // if (!start_area) {
  114. // alert("请输入出发地");
  115. // return;
  116. // }
  117. // if (!end_area) {
  118. // alert("请输入目的地");
  119. // return;
  120. // }
  121. if (!run_date) {
  122. alert("请选择出发日期");
  123. return;
  124. } else {}
  125. var tnowtime = getDateTime(4);
  126. // var myURL = "./st-xm/Api/createOrderContrill.php?method=choiceKicket&tt=" + tnowtime + "&currpage=" + currpage + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat;
  127. // var myURL2 = "./select_ticket.html?tt=" + tnowtime + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat;
  128. var myURL = "./st-xm/Api/createOrderContrill.php?method=choiceKicket&tt=" + tnowtime + "&currpage=" + currpage + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat+"&run_line="+run_line;
  129. var myURL2 = "./select_ticket.html?tt=" + tnowtime + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat+"&run_line="+run_line;
  130. method(myURL, myURL2);
  131. }
  132. /**
  133. *
  134. * @param {Object} myURL 返回数据URL接口
  135. * @param {Object} myURL2 当前的URL
  136. */
  137. function method(myURL, myURL2) {
  138. //alert(myURL);
  139. $.getJSON(myURL, function(res_data) {
  140. httpData = res_data;
  141. console.log('api_url====' + myURL);
  142. console.log(httpData);
  143. var code = httpData.code;
  144. if(code!="0"){
  145. alert(httpData['info']);
  146. return;
  147. }
  148. //表格
  149. var ticketSource = document.getElementById("tableTicket");
  150. var newHtml = ""
  151. for (var i = 0; i < httpData.ticket.length; i++) {
  152. var source = tableText;
  153. source = source.replace('出发地', httpData.ticket[i].start_area);
  154. source = source.replace('目的地', httpData.ticket[i].end_area);
  155. source = source.replace('线路', httpData.ticket[i].property);
  156. source = source.replace('area', "(" + httpData.ticket[i].prod_name + ")");
  157. source = source.replace('出发日期', httpData.ticket[i].run_date);
  158. source = source.replace('出发时间', httpData.ticket[i].start_time);
  159. source = source.replace('到达时间', httpData.ticket[i].end_time);
  160. var seat = '';
  161. var crowd = '';
  162. var price = '';
  163. var stock = '';
  164. var order = '';
  165. for (var j = 0; j < 1; j++) {
  166. var st = seatText;
  167. var cd = crowdText;
  168. var pe = priceText;
  169. var sk = stockText;
  170. var or = orderText;
  171. // if(httpData.ticket[i].tickets[j].stock > 0){
  172. st = st.replace('CCCCCC', '333333');
  173. cd = cd.replace('CCCCCC', '333333');
  174. pe = pe.replace('CCCCCC', '333333');
  175. sk = sk.replace('CCCCCC', '333333');
  176. or = or.replace('style="color: #CCCCCC;"', '');
  177. or = or.replace('true', 'false');
  178. or = or.replace('book(0)', 'book(' + httpData.ticket[i].run_id + ',\'' + httpData.ticket[i].property + '\')');
  179. if(httpData.ticket[i].outside == '0'){
  180. var html = "create_order";
  181. }else if(httpData.ticket[i].outside == '-1'){
  182. var html = "create_order_dzbs";
  183. }else{
  184. var html = "create_order_outside";
  185. }
  186. or = or.replace('[html]', html);
  187. or = or.replace('[id]', httpData.ticket[i].run_id);
  188. or = or.replace('[run_id]', httpData.ticket[i].run_id);
  189. or = or.replace('[run_date]', httpData.ticket[i].run_date);
  190. seat = seat + st.replace('[seat]', httpData.ticket[i].seat);
  191. crowd = crowd + cd.replace('[crowd]', httpData.ticket[i].crowd);
  192. price = price + pe.replace('[price]', httpData.ticket[i].price);
  193. stock = stock + sk.replace('[stock]', httpData.ticket[i].stock);
  194. order = order + or;
  195. }
  196. source = source.replace(seatText, seat);
  197. // source = source.replace(crowdText, crowd);
  198. source = source.replace(priceText, price);
  199. source = source.replace(stockText, stock);
  200. source = source.replace(orderText, order);
  201. newHtml += source;
  202. }
  203. if (newHtml) {
  204. document.getElementById("ticketTable").style.display = "table";
  205. ticketSource.innerHTML = newHtml;
  206. var currpage = httpData.currpage;
  207. if (currpage) {} else {
  208. currpage = 1;
  209. }
  210. var sum = httpData.total;
  211. var length = page_size;
  212. var tag = "page";
  213. var s = getPager(myURL2, sum, currpage, length, tag,'currpage');
  214. }else{
  215. ticketSource.innerHTML = "";
  216. }
  217. });
  218. }
  219. function book(id, line) {
  220. // if (id != 0) {
  221. // var listURL = "./create_order.html?id=1&run_id=" + id;
  222. // // 跳转前将URL编码
  223. // listURL = encodeURI(listURL);
  224. // window.location.href = listURL;
  225. // } else {
  226. // alert("该票种不能预定");
  227. // }
  228. }
  229. function getDateTime(nTypeFlag) {
  230. var tNowTime = new Date();
  231. var myYear = ';' + tNowTime.getFullYear() + ';';
  232. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  233. var myDay = ';' + tNowTime.getDate() + ';';
  234. var myHour = ';' + tNowTime.getHours() + ';';
  235. var myMinu = ';' + tNowTime.getMinutes() + ';';
  236. var mySecond = ';' + tNowTime.getSeconds() + ';';
  237. if (myMonth.length < 4) myMonth = '0' + myMonth;
  238. if (myDay.length < 4) myDay = '0' + myDay;
  239. if (myHour.length < 4) myHour = '0' + myHour;
  240. if (myMinu.length < 4) myMinu = '0' + myMinu;
  241. if (mySecond.length < 4) mySecond = '0' + mySecond;
  242. var cNewTimeStr;
  243. //alert(tNowTime);
  244. switch (nTypeFlag + 1 - 1) {
  245. case 0:
  246. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  247. break;
  248. case 1:
  249. cNewTimeStr = myYear + myMonth + myDay;
  250. break;
  251. case 2:
  252. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  253. break;
  254. case 3:
  255. cNewTimeStr = myHour + myMinu + mySecond;
  256. break;
  257. case 4:
  258. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  259. break;
  260. case 5:
  261. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  262. break;
  263. case 6:
  264. cNewTimeStr = myYear;
  265. break;
  266. case 7:
  267. cNewTimeStr = myYear + '-' + myMonth;
  268. break;
  269. default:
  270. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  271. break;
  272. }
  273. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  274. return cNewTimeStr;
  275. }
  276. function getPar(par) {
  277. //获取当前URL
  278. var local_url = document.location.href;
  279. local_url = decodeURI(local_url);
  280. //获取要取得的get参数位置
  281. var get = local_url.indexOf(par + "=");
  282. if (get == -1) {
  283. return "";
  284. }
  285. //截取字符串
  286. var get_par = local_url.slice(par.length + get + 1);
  287. //判断截取后的字符串是否还有其他get参数
  288. var nextPar = get_par.indexOf("&");
  289. if (nextPar != -1) {
  290. get_par = get_par.slice(0, nextPar);
  291. }
  292. return get_par;
  293. }