function getweek (){ var week = "week="; for(var i = 1;i<$(".weeklist input").length;i++){ if($(".weeklist input").eq(i).is(":checked")){week+=i} } return week } function getalltime(){ var allstation = "allstation="; for(var i = 0;i<$(".replace-lineinfo tr").length;i++){ if(i==$(".replace-lineinfo tr").length-1){var lian = ""}else{var lian = "&"} var astation = ["'"]; var atime = parseInt($(".replace-lineinfo tr").eq(i).children("td:eq(0)").children(".hour").val())*60+parseInt($(".replace-lineinfo tr").eq(i).children("td:eq(0)").children(".minute").val()); var astationid = $(".replace-lineinfo tr").eq(i).children("td:eq(1)").attr("alineid"); var aupdowntype = $(".replace-lineinfo tr").eq(i).children("td:eq(2)").children("select").val(); var amouth = $(".replace-lineinfo tr").eq(i).children("td:eq(3)").children("select").val(); astation.push("atime:",atime,","); astation.push("astationid:",astationid,","); astation.push("aupdowntype:",aupdowntype,","); astation.push("amouth:",amouth,"'",lian) allstation+=astation.join("") } return allstation } function getallcar(){ var allcar = "allcar="; for(var i = 0;i<$(".car-select").length;i++){ if(i==$(".car-select").length-1){var lian = ""}else{var lian = "&"} var acar = ["'"]; var acartype = $(".car-select").children(".car-item").val(); var acarnum = $(".car-select").children("input").val(); var acarseat = $(".car-select").children(".ifseat").val(); acar.push("acartypeid:",acartype,","); acar.push("acarnum:",acarnum,","); acar.push("acarseat:",acarseat,"'",lian); allcar+=acar.join(""); } return allcar } function gettickettype(){ var allticket = "allticket=" for(var i = 0;i<$(".ticket_sel").length;i++){ if($(".ticket_sel").eq(i).is(":checked")){ var aticket=["'"]; var aticketid = $(".ticket_sel").eq(i).val(); var aticketnum = $(".ticket_sel").eq(i).parent().parent().children("td:eq(5)").children("input").val(); aticket.push("aticketid:",aticketid,","); aticket.push("aticketnum:",aticketnum,"'","&"); allticket+=aticket.join(""); } } allticket= allticket.substring(0,allticket.length-1); return allticket } function sellday(){} $(document).ready(function(){ var ticket1 = $(".adult").outerHTML(); $(".adult").remove(); var ticket2 = $(".noble").outerHTML(); var addcar = $(".car-select").outerHTML(); $(".car-select").remove(); console.log($(".add-line").length) $(".storage").on("click",function(){ var lineid = getval(".add-line","lineid"); var startime = getval(".startime","val"); var endtime = getval(".endtime","val"); var week = getweek (); var alltime = getalltime(); var allcar = getallcar(); var allticket=gettickettype(); var sellday = getval(".sellday","val") var all = getdata(lineid,startime,endtime,week,alltime,allcar,allticket,sellday) console.log(all) }) $('.add-line').on('keyup',function(ev){ var val = this.value; if(/[a-zA-Z]+/.test(val)){ $.getJSON("json/"+val+".html?rand="+Math.random(),function(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("lineid",$(this).attr("lineid")); // console.log($(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; var alltypeid = [108,109,110,114] if(type==108){typeid="上"} else if(type==109){typeid="上下"} else if(type==110){typeid="下"} else if(type==114){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("") } function getdata(){ var val = []; Array.prototype.push.apply(val,arguments); return val.join(";"); } function getval(dom,value){ var val = null; if(value=="val"||value=="value"){val =$(dom).eq(0).val()} else if(value == "html"){val = $(dom).eq(0).html()} else {val = $(dom).eq(0).attr(value);var name = value;return name + "=" +val;} var name = $(dom).eq(0).attr("name"); return name + "=" +val }