//var val =null; $(document).ready(function(){ var ticket1 = $(".adult").outerHTML(); $(".adult").remove(); var ticket2 = $(".noble").outerHTML(); var addcar = $(".car-select").outerHTML(); $(".car-select").remove(); //var cansell_ticket = // var hour = $(".hour").html(), // minute = $(".minute").html(), // place = $(".place").html(), // entry = $(".entry").html(), // mouth = $(".mouth").html(); //console.log(hour) //$(".replace-lineinfo").hide() $('.add-line').on('keyup',function(ev){ var val = this.value; if(/[a-zA-Z]+/.test(val)){ //console.log(1) $.getJSON("json/"+val+".html?rand="+Math.random(),function(data){ //console.log(2); //console.log(data); var html = []; $.each(data,function(i,v){ html.push('
  • '+v.name+'
  • ') }); //console.log(this) $(".line-item").html(html.join("")); $(".line-item>li").on("click",function(){ var val = $(this).html().replace(/[^a-zA-Z]+/,''); $('.add-line').val($(this).html()).attr("dataid",$(this).attr("dataid")); $(".line-item").html(""); // $.getJSON('json/'+val+'.html?rand='+Math.random(),function(data){ // var linehtml = []; // //console.log(1); // //console.log(lineInfoFormat); // var tickethtml = []; // $.each(data,function(i,v){ // // console.log(v.lineId); // if(typeof v.lineId=="undefined"){ // var td1= addTd(addTime(v.time)); // var td2= addTd(v.site); // if(i==0){var td3= addTd('')} // else{var td3=addTd(addUpdownType(v.type))}; // var td4 = addTd(addMouth(v.maxcheck,v.check)); // linehtml.push(addItem("tr","aline",td1.concat(td2,td3,td4))) // }else{ // var line = v.line.split("-"), // ticket11= ticket1.replace("出发地",line[0]).replace("目的地",line[1]), // ticket22 = ticket2, // arr = [], // ticket=null, // judge=false; // $.each(v,function(key,value){ // if(key=="child"){ // var child=["child","","儿童"]; // Array.prototype.push.apply(child,value.split(",")); // arr.push(child); // }; // if(key=="noble"){ // var noble=["noble","贵宾","成人"]; // Array.prototype.push.apply(noble,value.split(",")); // arr.push(noble); // }; // if(key=="adult"){ // var adult=["adult","普通","成人"]; // Array.prototype.push.apply(adult,value.split(",")); // arr.push(adult); // }; // }); // //var myticket1 = ticket1.replace("出发地",line[0]).replace("目的地",line[1]); // for(var i = 0;i23){addvalue-=24}{ // $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addvalue).attr("selected","true") // hourinfo[t][1]=addvalue; // } // } // } // } // } // hourinfo[index][1]=dangvalue; // }) // $(".minute").on("change",function(){ // var index = $(this).parent().parent().index(); // var max = $(".minute").length; // var dangvalue = parseInt($(this).val()); // for(var i = 0;i=60){addvalue-=60; var addhour = parseInt(hourinfo[t][1])+1;} // if(typeof addhour=="undefined"){ // $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true") // minuteinfo[t][1]=addvalue; // }else{ // $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true") // minuteinfo[t][1]=addvalue; // $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addhour).attr("selected","true"); // hourinfo[t][1]=addhour; // } // } // } // } // } // minuteinfo[index][1]=dangvalue; // }) // }) $.getJSON('json/'+val+'.html?rand='+Math.random(),function(data){ var linehtml = []; //console.log(1); //console.log(lineInfoFormat); var tickethtml = []; $(".add-cartype").on("click",function(){ var cartype = []; $.each(data.addcartype,function(i,v){ var acar = additemall("option",v.cartype,{"value":v.id}) cartype.push(acar) }) var acartype = addcar.replace("cartype",cartype.join()); $(".car-type").append(acartype); $(".car-select .del").unbind(); $(".car-select .del").on("click",function(){ $(this).parent().remove(); }); }) $.each(data.station,function(i,v){ var td1= addTd(addTime(v.DATE_TIME)); var td2= additemall("td",v.SITES,{alineid:v.RES_ID}); // //console.log(td2) if(i==0){var td3= addTd('')} else{var td3=addTd(addUpdownType(v.UP_DOWN_TYPE))}; var td4 = addTd(addMouth(v.TICKET_GATE,v.CHECKPORT)); linehtml.push(addItem("tr","aline",td1.concat(td2,td3,td4))) }) $.each(data.ticket,function(i,v){ //var html = []; if(i==0){ var atciket = ticket1.replace(/START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID/g,function(match){ switch(match){ case "START_AREA": return v.START_AREA; case "END_AREA": return v.END_AREA; case "SEAT": return v.SEAT; case "CROWD": return v.CROWD; case "MAX_COUNT": return v.MAX_COUNT; case "PROD_ID": return v.PROD_ID; case "PRICE": return v.PRICE; } }) tickethtml.push(atciket) //console.log(html) }else{ var atciket = ticket1.replace(/START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID/g,function(match){ switch(match){ case "START_AREA": return ""; case "END_AREA": return ""; case "SEAT": return v.SEAT; case "CROWD": return v.CROWD; case "MAX_COUNT": return v.MAX_COUNT; case "PROD_ID": return v.PROD_ID; case "PRICE": return v.PRICE; } }) tickethtml.push(atciket) } }) $(".replace-lineinfo").html(linehtml).attr("lineid",data.station[1].PROD_ID); console.log(tickethtml) console.log(ticket1) $(".able-ticket").html(tickethtml.join()) var hourinfo = []; $.each($('.hour'),function(i,v){ var val = $('.hour').eq(i).val() var arr = [i,val] hourinfo.push(arr) }) var minuteinfo = []; $.each($('.minute'),function(i,v){ var val = $('.minute').eq(i).val() var arr = [i,val] minuteinfo.push(arr) }) $(".hour").on("change",function(){ var index = $(this).parent().parent().index(); var max = $(".hour").length; var dangvalue = $(this).val(); for(var i = 0;i23){addvalue-=24}{ $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addvalue).attr("selected","true") hourinfo[t][1]=addvalue; } } } } } hourinfo[index][1]=dangvalue; }) $(".minute").on("change",function(){ var index = $(this).parent().parent().index(); var max = $(".minute").length; var dangvalue = parseInt($(this).val()); for(var i = 0;i=60){addvalue-=60; var addhour = parseInt(hourinfo[t][1])+1;} if(typeof addhour=="undefined"){ $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true") minuteinfo[t][1]=addvalue; }else{ $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true") minuteinfo[t][1]=addvalue; $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addhour).attr("selected","true"); hourinfo[t][1]=addhour; } } } } } minuteinfo[index][1]=dangvalue; }) }) }) }) } }); // $(".add-cartype").on("click",function(){ // $.getJSON("json/cartype.html?rand="+Math.random(),function(data){ // var car = []; // $.each(data,function(i,v){ // car.push(''); // }); // car = addItem('select','car-item',car.join("")); // var carnumoption = []; // for(var i = 1;i<=data[0].count;i++){ // carnumoption.push('') // } // var carnum = addItem('select','car-num',carnumoption.join("")); // var ifseat = []; // if(data[0].ifSeat==0){ // ifseat.push(''); // }else if(data[0].ifSeat==1){ // ifseat.push(''); // }else if(data[0].ifSeat==2){ // ifseat.push(''); // } // ifseat=addItem("select","ifseat",ifseat.join("")) // var del = addItem('span','del','删除') // var all = car.concat(carnum,ifseat,del); // var div = addItem('div','car-select',all); // $(".car-type").append(div); // $(".del").on("click",function(){ // $(this).parent().remove(); // }) // $(".car-item").on("change",function(){ // var count = null; // var ifseat = null; // var val = this.value; // $.each(data,function(i,v){ // if(val==v.id){ // count=v.count; // ifseat=v.ifSeat // } // }); // var selnum = []; // for(var i = 1;i<=count;i++){ // selnum.push('') // } // $(this).parent().find(".car-num").html(selnum.join("")).removeAttr("disabled"); // if(ifseat==0){ // $(this).parent().find(".if-seat").html('').removeAttr("disabled"); // } // else if(ifseat==1){ // $(this).parent().find(".if-seat").html('').removeAttr("disabled"); // } // else if(ifseat==1){ // $(this).parent().find(".if-seat").html('').removeAttr("disabled"); // } // }) // }) // }) $('.date-picker').datepicker({autoclose:true}).next().on('click', function(){ $(this).prev().focus(); }); $('.allweek').on('change',function(){ if($(this).is(":checked")){ for(var i=0;i<$(".week").length;i++){ $(".week").eq(i).click() } }else{ for(var i=0;i<$(".week").length;i++){ $(".week").eq(i).removeAttr("checked"); } } }) $(".storage").on("click",function(){ var lineid = 'lineid='+$(".add-line").attr('dataid'); var time = 'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val(); var pass = []; (function(){ var line =[]; for(var i = 0;i<$(".aline").length;i++){ var aline = []; aline.push("time="+$(".aline").eq(i).find(".hour").val()+":"+$(".aline").eq(i).find(".minute").val()); aline.push("site="+$(".aline").find("td").eq(1).html()); aline.push("updown="+$(".aline").find(".updown").val()); aline.push("mouth="+$(".aline").find(".mouth").val()); line.push(aline.join("")); } })() url = 'lineid='+$(".add-line").attr('dataid')+'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val() }) }) function addItem(label,classname,cent){ var html = ['<'+label+' class='+classname+'>']; html.push(cent); html.push(''); return html.join("") } function addLi(html){ var li = ['
  • ']; li.push(html); li.push('
  • '); li = li.join(""); return li } function addTime(time){ var time = time.split(":"); var newHour = parseInt(time[0]), newMinute = parseInt(time[1]); var html = [':'); html = html.join("") return html } function addUpdownType(type){ var typeid= null if(type==108){typeid="上"} else if(type==109){typeid="上下"} else if(type==110){typeid="下"} var html = [''); html = html.join("") return html } function addMouth(maxNum,num){ var html = ['"); html = html.join("") return html; } function addTd(html){ var td = ['']; td.push(html); td.push(''); td = td.join("") return td; } function addTr(html){ var tr = ['']; tr.push(html) tr.push(''); tr = tr.join("") return tr; } jQuery.fn.outerHTML = function(s) { return (s) ? this.before(s).remove() : $("").append(this.eq(0).clone()).html(); } function additemall(lable,cen,attr){ var html = ['<'+lable+ ' ' + (function(attr){if(typeof(attr)=="undefined"){return ""}else{var arr=[];for(i in attr){arr.push(i+'="'+attr[i]+'"')};return arr.join(" ")}})(attr) +'>']; html.push(cen); html.push(''); console.log(html) return html.join("") }