|
- var httpData;
- var page_size = 10;
- var mUrl = "./select_ticket.html";
- if (window.ActiveXObject) {
- var myreq = new ActiveXObject("Microsoft.XMLHTTP");
- } else {
- var myreq = new XMLHttpRequest();
- }
- var tableText = '';
- var seatText = '';
- var crowdText = '';
- var priceText = '';
- var stockText = '';
- var orderText = '';
- window.onload = function() {
- $('#id-date-picker-1').val(getDateTime(0));
- tableText = document.getElementById("tableTicket").innerHTML;
- seatText = document.getElementById("st").innerHTML;
- // crowdText = document.getElementById("crowd").innerHTML;
- priceText = document.getElementById("price").innerHTML;
- stockText = document.getElementById("stock").innerHTML;
- orderText = document.getElementById("order").innerHTML;
-
- var currpage = getPar('currpage');
- //var startTime = getPar("startTime");
- //var endTime = getPar("endTime");
- var seat = getPar("seat") ? getPar("seat") : '';
- if (currpage) {
- var user_id = getPar("user_id");
- var start_area = getPar("start_area");
- var end_area = getPar("end_area");
- var run_date = getPar("run_date");
- var run_line = getPar("run_line");
- $('#startArea').val(start_area);
- $('#endArea').val(end_area);
- $('#id-date-picker-1').val(run_date);
- $('#run_line').val(run_line);
-
- var tnowtime = getDateTime(4);
- 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;
- 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;
- method(myURL, myURL2);
- }else{
- query()
- }
-
- }
-
- function before() {
- var d = document.getElementById("id-date-picker-1").value;
- d = new Date(d);
- d = +d - 1000*60*60*24;
- d = new Date(d);
- //return d;
- //格式化
- var year = ";" + d.getFullYear() + ";";
- var month = ";" + (d.getMonth()+0+1) + ";";
- var day = ";" + d.getDate() + ";";
- if(year.length < 4) {
- year = "0" + year;
- }
- if(month.length < 4) {
- month = "0" + month;
- }
- if(day.length < 4) {
- day = "0" + day;
- }
- var datestr = year + "-" + month + "-" + day;
- datestr = datestr.replace(/;/g, "");
- $('#id-date-picker-1').val(datestr);
- query();
-
-
- }
-
- function after() {
- var d = document.getElementById("id-date-picker-1").value;
- d = new Date(d);
- d = +d + 1000*60*60*24;
- d = new Date(d);
- //return d;
- //格式化
- var year = ";" + d.getFullYear() + ";";
- var month = ";" + (d.getMonth()+0+1) + ";";
- var day = ";" + d.getDate() + ";";
- if(year.length < 4) {
- year = "0" + year;
- }
- if(month.length < 4) {
- month = "0" + month;
- }
- if(day.length < 4) {
- day = "0" + day;
- }
- var datestr = year + "-" + month + "-" + day;
- datestr = datestr.replace(/;/g, "");
- $('#id-date-picker-1').val(datestr);
- query();
-
- }
-
- function ConvertDateFromString(dateString) {
- if (dateString) {
- var sdate = dateString.split('-');
- var date = new Date(sdate[0], sdate[1], sdate[2]);
- return date;
- }
- }
-
- function query() {
- var user_id = getPar("user_id");
- var start_area = document.getElementById("startArea").value;
- var end_area = document.getElementById("endArea").value;
- var run_date = document.getElementById("id-date-picker-1").value;
- //var startTime = document.getElementById("timepicker1").value;
- //var endTime = document.getElementById("timepicker2").value;
- var seat = $('#seat').val() ? $('#seat').val() : '';
- var run_line=$('#run_line').val();
- var currpage = getPar("currpage");
- if (!currpage) {
- currpage = 1;
- }
- // if (!start_area) {
- // alert("请输入出发地");
- // return;
- // }
- // if (!end_area) {
- // alert("请输入目的地");
- // return;
- // }
- if (!run_date) {
- alert("请选择出发日期");
- return;
- } else {}
- var tnowtime = getDateTime(4);
- // 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;
- // var myURL2 = "./select_ticket.html?tt=" + tnowtime + "&start_area=" + start_area + "&end_area=" + end_area + "&run_date=" + run_date + "&seat=" + seat;
- 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;
- 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;
- method(myURL, myURL2);
- }
- /**
- *
- * @param {Object} myURL 返回数据URL接口
- * @param {Object} myURL2 当前的URL
- */
- function method(myURL, myURL2) {
- //alert(myURL);
- $.getJSON(myURL, function(res_data) {
- httpData = res_data;
- console.log('api_url====' + myURL);
- console.log(httpData);
- var code = httpData.code;
- if(code!="0"){
- alert(httpData['info']);
- return;
- }
- //表格
- var ticketSource = document.getElementById("tableTicket");
- var newHtml = ""
- for (var i = 0; i < httpData.ticket.length; i++) {
- var source = tableText;
- source = source.replace('出发地', httpData.ticket[i].start_area);
- source = source.replace('目的地', httpData.ticket[i].end_area);
- source = source.replace('线路', httpData.ticket[i].property);
- source = source.replace('area', "(" + httpData.ticket[i].prod_name + ")");
- source = source.replace('出发日期', httpData.ticket[i].run_date);
- source = source.replace('出发时间', httpData.ticket[i].start_time);
- source = source.replace('到达时间', httpData.ticket[i].end_time);
- var seat = '';
- var crowd = '';
- var price = '';
- var stock = '';
- var order = '';
- for (var j = 0; j < 1; j++) {
- var st = seatText;
- var cd = crowdText;
- var pe = priceText;
- var sk = stockText;
- var or = orderText;
- // if(httpData.ticket[i].tickets[j].stock > 0){
- st = st.replace('CCCCCC', '333333');
- cd = cd.replace('CCCCCC', '333333');
- pe = pe.replace('CCCCCC', '333333');
- sk = sk.replace('CCCCCC', '333333');
- or = or.replace('style="color: #CCCCCC;"', '');
- or = or.replace('true', 'false');
- or = or.replace('book(0)', 'book(' + httpData.ticket[i].run_id + ',\'' + httpData.ticket[i].property + '\')');
- if(httpData.ticket[i].outside == '0'){
- var html = "create_order";
- }else if(httpData.ticket[i].outside == '-1'){
- var html = "create_order_dzbs";
- }else{
- var html = "create_order_outside";
- }
- or = or.replace('[html]', html);
- or = or.replace('[id]', httpData.ticket[i].run_id);
- or = or.replace('[run_id]', httpData.ticket[i].run_id);
- or = or.replace('[run_date]', httpData.ticket[i].run_date);
-
- seat = seat + st.replace('[seat]', httpData.ticket[i].seat);
- crowd = crowd + cd.replace('[crowd]', httpData.ticket[i].crowd);
- price = price + pe.replace('[price]', httpData.ticket[i].price);
- stock = stock + sk.replace('[stock]', httpData.ticket[i].stock);
- order = order + or;
- }
- source = source.replace(seatText, seat);
- // source = source.replace(crowdText, crowd);
- source = source.replace(priceText, price);
- source = source.replace(stockText, stock);
- source = source.replace(orderText, order);
- newHtml += source;
- }
- if (newHtml) {
- document.getElementById("ticketTable").style.display = "table";
- ticketSource.innerHTML = newHtml;
- var currpage = httpData.currpage;
- if (currpage) {} else {
- currpage = 1;
- }
- var sum = httpData.total;
- var length = page_size;
- var tag = "page";
- var s = getPager(myURL2, sum, currpage, length, tag,'currpage');
- }else{
- ticketSource.innerHTML = "";
- }
- });
- }
-
- function book(id, line) {
- // if (id != 0) {
- // var listURL = "./create_order.html?id=1&run_id=" + id;
- // // 跳转前将URL编码
- // listURL = encodeURI(listURL);
- // window.location.href = listURL;
- // } else {
- // alert("该票种不能预定");
- // }
- }
-
- function getDateTime(nTypeFlag) {
- var tNowTime = new Date();
- var myYear = ';' + tNowTime.getFullYear() + ';';
- var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
- var myDay = ';' + tNowTime.getDate() + ';';
- var myHour = ';' + tNowTime.getHours() + ';';
- var myMinu = ';' + tNowTime.getMinutes() + ';';
- var mySecond = ';' + tNowTime.getSeconds() + ';';
-
- if (myMonth.length < 4) myMonth = '0' + myMonth;
- if (myDay.length < 4) myDay = '0' + myDay;
- if (myHour.length < 4) myHour = '0' + myHour;
- if (myMinu.length < 4) myMinu = '0' + myMinu;
- if (mySecond.length < 4) mySecond = '0' + mySecond;
-
- var cNewTimeStr;
- //alert(tNowTime);
- switch (nTypeFlag + 1 - 1) {
- case 0:
- cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
- break;
- case 1:
- cNewTimeStr = myYear + myMonth + myDay;
- break;
- case 2:
- cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
- break;
- case 3:
- cNewTimeStr = myHour + myMinu + mySecond;
- break;
- case 4:
- cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
- break;
- case 5:
- cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
- break;
- case 6:
- cNewTimeStr = myYear;
- break;
- case 7:
- cNewTimeStr = myYear + '-' + myMonth;
- break;
- default:
- cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
- break;
- }
-
- cNewTimeStr = cNewTimeStr.replace(/;/g, "");
-
- return cNewTimeStr;
-
- }
-
- function getPar(par) {
- //获取当前URL
- var local_url = document.location.href;
- local_url = decodeURI(local_url);
- //获取要取得的get参数位置
- var get = local_url.indexOf(par + "=");
- if (get == -1) {
- return "";
- }
- //截取字符串
- var get_par = local_url.slice(par.length + get + 1);
- //判断截取后的字符串是否还有其他get参数
- var nextPar = get_par.indexOf("&");
- if (nextPar != -1) {
- get_par = get_par.slice(0, nextPar);
- }
- return get_par;
- }
|