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.
 
 
 
 

292 lines
10 KiB

  1. var httpData;
  2. var page_size = 10;
  3. var mUrl = "../supplement.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/supplement.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 = "./supplement.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 seat = $('#seat').val() ? $('#seat').val() : '';
  106. var run_line=$('#run_line').val();
  107. var currpage = getPar("currpage");
  108. if (!currpage) {
  109. currpage = 1;
  110. }
  111. if (!run_date) {
  112. alert("请选择出发日期");
  113. return;
  114. } else {}
  115. var tnowtime = getDateTime(4);
  116. var myURL = "./st-xm/Api/supplement.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;
  117. var myURL2 = "./supplement.html?tt=" + tnowtime + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat+"&run_line="+run_line;
  118. method(myURL, myURL2);
  119. }
  120. /**
  121. *
  122. * @param {Object} myURL 返回数据URL接口
  123. * @param {Object} myURL2 当前的URL
  124. */
  125. function method(myURL, myURL2) {
  126. //alert(myURL);
  127. $.getJSON(myURL, function(res_data) {
  128. httpData = res_data;
  129. console.log('api_url====' + myURL);
  130. console.log(httpData);
  131. var code = httpData.code;
  132. if(code!="0"){
  133. alert(httpData['info']);
  134. return;
  135. }
  136. //表格
  137. var ticketSource = document.getElementById("tableTicket");
  138. var newHtml = ""
  139. for (var i = 0; i < httpData.ticket.length; i++) {
  140. var source = tableText;
  141. source = source.replace('出发地', httpData.ticket[i].start_area);
  142. source = source.replace('目的地', httpData.ticket[i].end_area);
  143. source = source.replace('线路', httpData.ticket[i].property);
  144. source = source.replace('area', "(" + httpData.ticket[i].prod_name + ")");
  145. source = source.replace('出发日期', httpData.ticket[i].run_date);
  146. source = source.replace('出发时间', httpData.ticket[i].start_time);
  147. source = source.replace('到达时间', httpData.ticket[i].end_time);
  148. var seat = '';
  149. var crowd = '';
  150. var price = '';
  151. var stock = '';
  152. var order = '';
  153. for (var j = 0; j < 1; j++) {
  154. var st = seatText;
  155. var cd = crowdText;
  156. var pe = priceText;
  157. var sk = stockText;
  158. var or = orderText;
  159. st = st.replace('CCCCCC', '333333');
  160. cd = cd.replace('CCCCCC', '333333');
  161. pe = pe.replace('CCCCCC', '333333');
  162. sk = sk.replace('CCCCCC', '333333');
  163. or = or.replace('style="color: #CCCCCC;"', '');
  164. or = or.replace('true', 'false');
  165. or = or.replace('book(0)', 'book(' + httpData.ticket[i].run_id + ',\'' + httpData.ticket[i].property + '\')');
  166. or = or.replace('[id]', httpData.ticket[i].run_id);
  167. or = or.replace('[run_id]', httpData.ticket[i].run_id);
  168. or = or.replace('[run_date]', httpData.ticket[i].run_date);
  169. seat = seat + st.replace('seat', httpData.ticket[i].seat);
  170. crowd = crowd + cd.replace('crowd', httpData.ticket[i].crowd);
  171. price = price + pe.replace('price', httpData.ticket[i].price);
  172. stock = stock + sk.replace('stock', httpData.ticket[i].stock);
  173. order = order + or;
  174. }
  175. source = source.replace(seatText, seat);
  176. // source = source.replace(crowdText, crowd);
  177. source = source.replace(priceText, price);
  178. // source = source.replace(stockText, stock);
  179. source = source.replace(orderText, order);
  180. newHtml += source;
  181. }
  182. if (newHtml) {
  183. document.getElementById("ticketTable").style.display = "table";
  184. ticketSource.innerHTML = newHtml;
  185. var currpage = httpData.currpage;
  186. if (currpage) {} else {
  187. currpage = 1;
  188. }
  189. var sum = httpData.total;
  190. var length = page_size;
  191. var tag = "page";
  192. var s = getPager(myURL2, sum, currpage, length, tag);
  193. }else{
  194. ticketSource.innerHTML = "";
  195. }
  196. });
  197. }
  198. function book(id, line) {
  199. if (id != 0) {
  200. var listURL = "./create_order.html?id=1&run_id=" + id;
  201. // 跳转前将URL编码
  202. listURL = encodeURI(listURL);
  203. window.location.href = listURL;
  204. } else {
  205. alert("该票种不能预定");
  206. }
  207. }
  208. function getDateTime(nTypeFlag) {
  209. var tNowTime = new Date();
  210. var myYear = ';' + tNowTime.getFullYear() + ';';
  211. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  212. var myDay = ';' + tNowTime.getDate() + ';';
  213. var myHour = ';' + tNowTime.getHours() + ';';
  214. var myMinu = ';' + tNowTime.getMinutes() + ';';
  215. var mySecond = ';' + tNowTime.getSeconds() + ';';
  216. if (myMonth.length < 4) myMonth = '0' + myMonth;
  217. if (myDay.length < 4) myDay = '0' + myDay;
  218. if (myHour.length < 4) myHour = '0' + myHour;
  219. if (myMinu.length < 4) myMinu = '0' + myMinu;
  220. if (mySecond.length < 4) mySecond = '0' + mySecond;
  221. var cNewTimeStr;
  222. //alert(tNowTime);
  223. switch (nTypeFlag + 1 - 1) {
  224. case 0:
  225. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  226. break;
  227. case 1:
  228. cNewTimeStr = myYear + myMonth + myDay;
  229. break;
  230. case 2:
  231. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  232. break;
  233. case 3:
  234. cNewTimeStr = myHour + myMinu + mySecond;
  235. break;
  236. case 4:
  237. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  238. break;
  239. case 5:
  240. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  241. break;
  242. case 6:
  243. cNewTimeStr = myYear;
  244. break;
  245. case 7:
  246. cNewTimeStr = myYear + '-' + myMonth;
  247. break;
  248. default:
  249. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  250. break;
  251. }
  252. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  253. return cNewTimeStr;
  254. }
  255. function getPar(par) {
  256. //获取当前URL
  257. var local_url = document.location.href;
  258. local_url = decodeURI(local_url);
  259. //获取要取得的get参数位置
  260. var get = local_url.indexOf(par + "=");
  261. if (get == -1) {
  262. return "";
  263. }
  264. //截取字符串
  265. var get_par = local_url.slice(par.length + get + 1);
  266. //判断截取后的字符串是否还有其他get参数
  267. var nextPar = get_par.indexOf("&");
  268. if (nextPar != -1) {
  269. get_par = get_par.slice(0, nextPar);
  270. }
  271. return get_par;
  272. }