|
-
- //var val =null;
-
- $(document).ready(function(){
- var ticket1 = $(".adult").html();
- var ticket2 = $(".noble").html();
- // 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('<li dataid='+v.lineid+'>'+v.name+'</li>')
- });
- //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('<select disabled><option>上</option></select>')}
- 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;i<arr.length;i++){
- if(judge==false){
- //myticket1.replace("座位",arr[i][0]).replace("人群",arr[i][1]).replace("零售价",arr[i][2].replace("ticketnum",arr[]))
- ticket = ticket11.replace(/座位|人群|零售价|ticketnum|ticketval/g,function(match){
- switch(match){
- case "座位":
- return arr[i][1];
- case "人群":
- return arr[i][2];
- case "零售价":
- return arr[i][3];
- case "ticketnum":
- return arr[i][4];
- case "ticketval":
- return arr[i][0]
- }
- })
- judge=true;
- tickethtml.push(addTr(ticket));
- }
- else{
- ticket=ticket2.replace(/座位|人群|零售价|ticketnum|ticketval/g,function(match){
- switch(match){
- case "座位":
- return arr[i][1];
- case "人群":
- return arr[i][2];
- case "零售价":
- return arr[i][3];
- case "ticketnum":
- return arr[i][4];
- case "ticketval":
- return arr[i][0]
- }
- })
- tickethtml.push(addTr(ticket))
- }
- }
-
- $(".able-ticket").html(addTr(tickethtml.join("")))
-
-
- }
- })
- $(".replace-lineinfo").html(linehtml);
-
-
- 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;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];//获得下一个input值
- 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;
- })
- })
-
- })
- })
- }
- });
-
-
-
- $(".add-cartype").on("click",function(){
-
- $.getJSON("json/cartype.html?rand="+Math.random(),function(data){
-
- var car = [];
- $.each(data,function(i,v){
- car.push('<option value='+v.id+'>'+v.cartype+'</option>');
- });
- car = addItem('select','car-item',car.join(""));
-
- var carnumoption = [];
- for(var i = 1;i<=data[0].count;i++){
- carnumoption.push('<option value='+i+'>'+i+'</option>')
- }
- var carnum = addItem('select','car-num',carnumoption.join(""));
-
- var ifseat = [];
- if(data[0].ifSeat==0){
- ifseat.push('<option value="sel">可选</option><option value="nosel">不可选</option>');
- }else if(data[0].ifSeat==1){
- ifseat.push('<option value="sel">可选</option>');
- }else if(data[0].ifSeat==2){
- ifseat.push('<option value="nosel">不可选</option>');
- }
- 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('<option>'+i+'</option>')
- }
-
- $(this).parent().find(".car-num").html(selnum.join("")).removeAttr("disabled");
- if(ifseat==0){
- $(this).parent().find(".if-seat").html('<option value="sel">可选</option><option value="nosel">不可选</option>').removeAttr("disabled");
- }
- else if(ifseat==1){
- $(this).parent().find(".if-seat").html('<option value="sel">可选</option>').removeAttr("disabled");
- }
- else if(ifseat==1){
- $(this).parent().find(".if-seat").html('<option value="nosel">不可选</option>').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('</'+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){
- html.push('<option selected value='+i+'>'+i+'</option>')}
- else{html.push('<option value='+i+'>'+i+'</option>')}
- }
- html.push('</select>:<select class="minute">')
- for(var t=0;t<60;t++){
- if(t==newMinute){
- html.push('<option selected value='+t+'>'+t+'</option>')
- }else{
- html.push('<option value='+t+'>'+t+'</option>')
- }
- }
- html.push('</select>');
- html = html.join("")
- return html
- }
- function addUpdownType(type){
- var html = ['<select class="updown">'],
- alltype = ['上','下','上下','不停']
- for(var i = 0;i<4;i++){
- if(type==alltype[i]){html.push('<option selected>'+alltype[i]+'</option>')}
- else{html.push('<option>'+alltype[i]+'</option>')}
- }
- html.push('</select>');
- html = html.join("")
- return html
- }
-
- function addMouth(maxNum,num){
- var html = ['<select class="mouth">'];
- for(var i = 1;i<=maxNum;i++){
- if(i==num){
- html.push('<option selected>'+i+'</option>')
- }else{
- html.push('<option>'+i+'</option>')
- }
- };
- html.push("</select>");
- 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;
-
- }
|