|
- function getweek (){
- var week = "week=";
- var weeknum = '';
- for(var i = 1;i<$(".weeklist input").length;i++){
- if($(".weeklist input").eq(i).is(":checked")){weeknum+=$(".weeklist input").eq(i).val()}
- }
- if(weeknum==''){
- return false;
- }
- return week+=weeknum;
- }
- function getalltime(){
- var allstation = "allstation=";
- for(var i = 0;i<$(".replace-lineinfo tr").length;i++){
- var allattr = [];
- 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();
- if(amouth==null){amouth=0;}
- allattr.push(astationid);
- allattr.push(atime);
- allattr.push(aupdowntype);
- allattr.push(amouth);
- var astation = '{' +allattr.join() + '}'
- allstation+=astation;
- };
- return allstation;
- }
- function getallcar(){
- var allcar = "allcar=";
- for(var i = 0;i<$(".car-select").length;i++){
- var allattr = [];
- var acartype = $(".car-select").eq(i).children(".car-item").val();
- var acarnum = $(".car-select").eq(i).children("input").val();
- var acarseat = $(".car-select").eq(i).children(".ifseat").val();
-
- allattr.push(acartype);
- allattr.push(acarnum);
- allattr.push(acarseat);
- var acar = '{' +allattr.join() + '}'
- allcar+=acar;
- }
- return allcar;
- }
- function gettickettype(){
- var allticket = "allticket=";
- // var starareaid = $(".stararea").eq(0).attr("starareaid");
- // var endareaid = $(".endarea").eq(0).attr("endareaid");
-
- //console.log(starareaid)
- var judge = false;
- for(var i = 0;i<$(".ticket_sel").length;i++){
- if($(".ticket_sel").eq(i).is(":checked")){
- judge=true ;
- var index = $(".ticket_sel").eq(i).parent().parent().index();
-
- var allattr=[];
- var starareaid = $(".adult").eq(index).children(".stararea").attr("starareaid");
- var endareaid = $(".adult").eq(index).children(".endarea").attr("endareaid");
-
- var seatid = $(".adult").eq(index).children(".seatid").attr("seatid");
- var crowd = $(".adult").eq(index).children(".crowdid").attr("crowdid");
- if(!crowd){crowd=0;}
- var aticketnum = $(".adult").eq(index).children(".ticketnum").children("input").val();
-
-
- allattr.push(starareaid);
- allattr.push(endareaid);
- allattr.push(seatid);
- allattr.push(crowd);
- allattr.push(aticketnum);
-
- var aticket = '{' +allattr.join() + '}'
- allticket+=aticket;
- }
- }
- if(judge==false){
- return false;
- }
-
- return allticket
- }
- $(document).ready(function(){
-
- $(".startime").on("change",function(){
- if($(".startime").val()!=''||$(".endtime").val()!=''){
- $(".data-erro").html("");
- }
- })
- $(".endtime").on("change",function(){
- if($(".startime").val()!=''||$(".endtime").val()!=''){
- $(".data-erro").html("");
- }
- })
- $(".add-cartype").on("click",function(){
- $(".car-erro").html("")
- })
- // $(".ticket_sel").on("click",function(){
- // $(".ticket-erro").html("")
- // })
- $(".allweek").on("change",function(){
- if($(this)[0].checked){
- $(".aday").each(function(){this.checked=true;})
- }else{
- $(".aday").each(function(){this.checked=false;})
- }
- })
- $(".aday").on("change",function(){
- $(".allweek")[0].checked=false;
- $(".week-erro").html("")
- })
-
-
- $(".line-item").hide();
- var ticket1 = $(".adult").outerHTML();
- $(".adult").remove();
- var ticket2 = $(".noble").outerHTML();
- var addcar = $(".car-select").outerHTML();
- $(".car-select").remove();
-
-
- $(".storage").on("click",function(){
- var week = getweek ();
-
- if($(".add-line").val()==''){
- $(".addline-erro").html("必填项");
- return;
- };
-
- if($(".startime").val()==''||$(".endtime").val()==''){
- $(".data-erro").html("必填项")
-
- return;
- };
- if(week==false){
- $(".week-erro").html("必填项");
- return;
- };
- if($(".car-type").html()==''){
- $(".car-erro").html("必填项");
- return;
- }
- if(gettickettype()==false){
- $(".ticket-erro").html("必填项");
-
- return;
- };
-
- var lineid = getval(".add-line","lineid");
- var startime = getval(".startime","val");
- var endtime = getval(".endtime","val");
-
-
- 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);
-
-
- // if(/week=\s+/.test(week)){
- // console.log("weektrue");
- // }else{
- // alert("bitian") ;
- // return;
- // }
-
- //console.log(week);
- //console.log(startime);
- //console.log(endtime);
- //console.log($(".add-line").html());
- //console.log(allcar);
- //console.log(allticket);
-
-
- $.getJSON("st-xm/Api/run_bus_new_save.php?"+all,function(data){
- if(data.errcode==0){
- location.href="carList.html";
- }else{
- alert(data.errinfo);
- console.log(all)
- }
-
- })
-
-
-
- //location.href="st-xm/Api/run_bus_new_save.php?"+all;
-
- //$.getJSON("st-xm/Api/run_bus_new_save.php?"+all,function(){
- // console.log("st-xm/Api/run_bus_new_save.php?"+all)
- //})
-
-
- })
- $('.add-line').on('keyup',function(ev){
- var val = this.value;
-
-
- $.getJSON("st-xm/Api/addCarTime.php?method=searchline&word="+val,function(data){
-
- $(".line-item").show();
-
- var html = [];
- $.each(data,function(i,v){
- html.push('<li lineid='+v.lineid+'>'+v.name+'</li>')
- });
-
- $(".line-item").html(html.join(""));
- $(".line-item>li").on("click",function(){
- $(".addline-erro").html("")
- $(".add-cartype").unbind();
- var val = $(this).attr("lineid");
- $('.add-line').val($(this).html()).attr("lineid",$(this).attr("lineid"));
- $(".line-item").html("");
- $.getJSON("st-xm/Api/addCarTime.php?method=throughstation&lineid="+val,function(data){
-
- $(".car-type").html("")
- $(".line-item").hide();
- var linehtml = [];
- var tickethtml = [];
- $(".add-cartype").on("click",function(){
- $(".car-erro").html("")
-
- 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});
-
- if(i==0){var td3= addTd('<select style="width: 50px" disabled><option value="108">上</option></select>')}
- 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){
- if(v.SEAT=="普通座"){
- var seatid = 72;
- }else if(v.SEAT=="贵宾座"){
- var seatid = 73;
- }else if(v.SEAT=="儿童特票座"){
- var seatid = 74;
- };
- if(v.CROWD=="成人"){
- var crowdid = 159;
- }else if(v.CROWD=="儿童"){
- var crowdid = 160;
- }else if(v.CROWD=="老人"){
- var crowdid = 161;
- }else if(v.CROWD=="军残"){
- var crowdid = 162;
- }else{
- var crowdid=0;
- };
- // if(i==0){
- var atciket = ticket1.replace(/SID|EID|START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID|aseatid|acrowdid/g,function(match){
- switch(match){
- case "SID":
- return v.SID;
- case "EID":
- return v.EID;
- case "aseatid":
- return seatid;
- case "acrowdid":
- return crowdid;
- 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)
-
- // }else{
- // var atciket = ticket1.replace(/SID|EID|START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID|aseatid|acrowdid/g,function(match){
- // switch(match){
- // case "SID":
- // return v.SID;
- // case "EID":
- // return v.EID;
- // case "aseatid":
- // return seatid;
- // case "acrowdid":
- // return crowdid;
- // 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);
- $(".able-ticket").html(tickethtml.join());
-
- $(".ticket_sel").on("click",function(){
- $(".ticket-erro").html("");
- })
-
-
-
- var hourinfo = [];
- $.each($('.hour'),function(i,v){
- var val = $('.hour').eq(i).val()
- if(val<10){
- val="0"+val;
- }
- var arr = [i,val]
- hourinfo.push(arr)
- })
- var minuteinfo = [];
- $.each($('.minute'),function(i,v){
- var val = $('.minute').eq(i).val()
- if(val<10){
- val="0"+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;i<hourinfo.length;i++){
- if(index == hourinfo[i][0]){
- var nextindex = hourinfo[i][0]+1;
- var myaddvalue = dangvalue-hourinfo[i][1];
- if(myaddvalue<0){
- hourinfo[i][1]=myaddvalue;
- }else{
- for(var t = nextindex;t<max;t++){
-
- var myvalue = hourinfo[t][1];
- var addvalue = myaddvalue+parseInt(myvalue);
-
- if(addvalue>23){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<minuteinfo.length;i++){
- if(index == minuteinfo[i][0]){
- var nextindex = parseInt(minuteinfo[i][0])+1;
- var addnum = dangvalue-parseInt(minuteinfo[i][1]);
- if(addnum<0){
- minuteinfo[i][1]=addnum
- }
- else{
- for(var t = nextindex;t<max;t++){
- var myhourvalue = hourinfo[t][1];
- var myminutevalue = minuteinfo[t][1];
-
- var addvalue = addnum+parseInt(myminutevalue);
-
- if(addvalue>=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;
- })
- })
-
- })
- })
-
- });
-
- $('.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()
- // console.log(url)
-
- // })
-
-
-
-
- })
-
-
-
- function addItem(label,classname,cent){
-
- var html = ['<'+label+' class='+classname+'>'];
- html.push(cent);
- html.push('</'+label+'>');
-
- return html.join("")
-
- }
-
- function addLi(html){
- var li = ['<li>'];
- li.push(html);
- li.push('</li>');
- li = li.join("");
- return li
- }
-
-
-
-
- function addTime(time){
- var time = time.split(":");
- var newHour = parseInt(time[0]),
- newMinute = parseInt(time[1]);
- var html = ['<select class="hour">'];
- for(var i=0;i<24;i++){
- if(i==newHour){
- //..a
- if(i<10){
- html.push('<option selected value='+i+'>0'+i+'</option>')
- }else{
- html.push('<option selected value='+i+'>'+i+'</option>')
- }
- }else{
- if(i<10){
- html.push('<option value='+i+'>0'+i+'</option>')
- }else{
- html.push('<option value='+i+'>'+i+'</option>')
- }
-
- }
- }
- html.push('</select style="width: 50px">:<select class="minute">')
- for(var t=0;t<60;t++){
- if(t==newMinute){
- if(t<10){
- html.push('<option selected value='+t+'>0'+t+'</option>')
- }else{
- html.push('<option selected value='+t+'>'+t+'</option>')
- }
-
- }else{
- if(t<10){
- html.push('<option value='+t+'>0'+t+'</option>')
- }else{
- html.push('<option value='+t+'>'+t+'</option>')
- }
-
- }
- }
- html.push('</select>');
- 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 = ['<select style="width: 50px" class="updown">'],
- alltype = ['上','下','上下','不停']
- for(var i = 0;i<4;i++){
- if(typeid==alltype[i]){html.push('<option selected value='+alltypeid[i]+'>'+alltype[i]+'</option>')}
- else{html.push('<option value = '+alltypeid[i]+'>'+alltype[i]+'</option>')}
- }
- html.push('</select>');
- html = html.join("")
- return html
- }
-
- function addMouth(maxNum,num){
- var html = ['<select style="width: 55px" class="mouth">'];
- for(var i in maxNum){
- if(i==num){
- html.push('<option selected value = '+i+'>'+maxNum[i]+'</option>')
- // html.push('<option selected value = '+i+'>-</option>')
- }else{
- html.push('<option value='+i+'>'+maxNum[i]+'</option>')
-
- }
- };
- html.push("</select>");
- if(maxNum<=0){
- html=['-'];
- }
- html = html.join("")
- return html;
- }
-
- function addTd(html){
- var td = ['<td>'];
- td.push(html);
- td.push('</td>');
- td = td.join("")
- return td;
- }
- function addTr(html){
- var tr = ['<tr>'];
- tr.push(html)
- tr.push('</tr>');
-
- tr = tr.join("")
-
- return tr;
-
- }
-
- jQuery.fn.outerHTML = function(s) {
- return (s) ? this.before(s).remove() : $("<Hill_man>").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('</'+lable+'>');
- 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
- }
- function out_login(){
- window.location='login.html';
- }
|