Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

644 rader
16 KiB

  1. function getweek (){
  2. var week = "week=";
  3. var weeknum = '';
  4. for(var i = 1;i<$(".weeklist input").length;i++){
  5. if($(".weeklist input").eq(i).is(":checked")){weeknum+=$(".weeklist input").eq(i).val()}
  6. }
  7. if(weeknum==''){
  8. return false;
  9. }
  10. return week+=weeknum;
  11. }
  12. function getalltime(){
  13. var allstation = "allstation=";
  14. for(var i = 0;i<$(".replace-lineinfo tr").length;i++){
  15. var allattr = [];
  16. 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());
  17. var astationid = $(".replace-lineinfo tr").eq(i).children("td:eq(1)").attr("alineid");
  18. var aupdowntype = $(".replace-lineinfo tr").eq(i).children("td:eq(2)").children("select").val();
  19. var amouth = $(".replace-lineinfo tr").eq(i).children("td:eq(3)").children("select").val();
  20. if(amouth==null){amouth=0;}
  21. allattr.push(astationid);
  22. allattr.push(atime);
  23. allattr.push(aupdowntype);
  24. allattr.push(amouth);
  25. var astation = '{' +allattr.join() + '}'
  26. allstation+=astation;
  27. };
  28. return allstation;
  29. }
  30. function getallcar(){
  31. var allcar = "allcar=";
  32. for(var i = 0;i<$(".car-select").length;i++){
  33. var allattr = [];
  34. var acartype = $(".car-select").eq(i).children(".car-item").val();
  35. var acarnum = $(".car-select").eq(i).children("input").val();
  36. var acarseat = $(".car-select").eq(i).children(".ifseat").val();
  37. allattr.push(acartype);
  38. allattr.push(acarnum);
  39. allattr.push(acarseat);
  40. var acar = '{' +allattr.join() + '}'
  41. allcar+=acar;
  42. }
  43. return allcar;
  44. }
  45. function gettickettype(){
  46. var allticket = "allticket=";
  47. // var starareaid = $(".stararea").eq(0).attr("starareaid");
  48. // var endareaid = $(".endarea").eq(0).attr("endareaid");
  49. //console.log(starareaid)
  50. var judge = false;
  51. for(var i = 0;i<$(".ticket_sel").length;i++){
  52. if($(".ticket_sel").eq(i).is(":checked")){
  53. judge=true ;
  54. var index = $(".ticket_sel").eq(i).parent().parent().index();
  55. var allattr=[];
  56. var starareaid = $(".adult").eq(index).children(".stararea").attr("starareaid");
  57. var endareaid = $(".adult").eq(index).children(".endarea").attr("endareaid");
  58. var seatid = $(".adult").eq(index).children(".seatid").attr("seatid");
  59. var crowd = $(".adult").eq(index).children(".crowdid").attr("crowdid");
  60. if(!crowd){crowd=0;}
  61. var aticketnum = $(".adult").eq(index).children(".ticketnum").children("input").val();
  62. allattr.push(starareaid);
  63. allattr.push(endareaid);
  64. allattr.push(seatid);
  65. allattr.push(crowd);
  66. allattr.push(aticketnum);
  67. var aticket = '{' +allattr.join() + '}'
  68. allticket+=aticket;
  69. }
  70. }
  71. if(judge==false){
  72. return false;
  73. }
  74. return allticket
  75. }
  76. $(document).ready(function(){
  77. $(".startime").on("change",function(){
  78. if($(".startime").val()!=''||$(".endtime").val()!=''){
  79. $(".data-erro").html("");
  80. }
  81. })
  82. $(".endtime").on("change",function(){
  83. if($(".startime").val()!=''||$(".endtime").val()!=''){
  84. $(".data-erro").html("");
  85. }
  86. })
  87. $(".add-cartype").on("click",function(){
  88. $(".car-erro").html("")
  89. })
  90. // $(".ticket_sel").on("click",function(){
  91. // $(".ticket-erro").html("")
  92. // })
  93. $(".allweek").on("change",function(){
  94. if($(this)[0].checked){
  95. $(".aday").each(function(){this.checked=true;})
  96. }else{
  97. $(".aday").each(function(){this.checked=false;})
  98. }
  99. })
  100. $(".aday").on("change",function(){
  101. $(".allweek")[0].checked=false;
  102. $(".week-erro").html("")
  103. })
  104. $(".line-item").hide();
  105. var ticket1 = $(".adult").outerHTML();
  106. $(".adult").remove();
  107. var ticket2 = $(".noble").outerHTML();
  108. var addcar = $(".car-select").outerHTML();
  109. $(".car-select").remove();
  110. $(".storage").on("click",function(){
  111. var week = getweek ();
  112. if($(".add-line").val()==''){
  113. $(".addline-erro").html("必填项");
  114. return;
  115. };
  116. if($(".startime").val()==''||$(".endtime").val()==''){
  117. $(".data-erro").html("必填项")
  118. return;
  119. };
  120. if(week==false){
  121. $(".week-erro").html("必填项");
  122. return;
  123. };
  124. if($(".car-type").html()==''){
  125. $(".car-erro").html("必填项");
  126. return;
  127. }
  128. if(gettickettype()==false){
  129. $(".ticket-erro").html("必填项");
  130. return;
  131. };
  132. var lineid = getval(".add-line","lineid");
  133. var startime = getval(".startime","val");
  134. var endtime = getval(".endtime","val");
  135. var alltime = getalltime();
  136. var allcar = getallcar();
  137. var allticket = gettickettype();
  138. var sellday = getval(".sellday","val");
  139. var all = getdata(lineid,startime,endtime,week,alltime,allcar,allticket,sellday);
  140. // if(/week=\s+/.test(week)){
  141. // console.log("weektrue");
  142. // }else{
  143. // alert("bitian") ;
  144. // return;
  145. // }
  146. //console.log(week);
  147. //console.log(startime);
  148. //console.log(endtime);
  149. //console.log($(".add-line").html());
  150. //console.log(allcar);
  151. //console.log(allticket);
  152. $.getJSON("st-xm/Api/run_bus_new_save.php?"+all,function(data){
  153. if(data.errcode==0){
  154. location.href="carList.html";
  155. }else{
  156. alert(data.errinfo);
  157. console.log(all)
  158. }
  159. })
  160. //location.href="st-xm/Api/run_bus_new_save.php?"+all;
  161. //$.getJSON("st-xm/Api/run_bus_new_save.php?"+all,function(){
  162. // console.log("st-xm/Api/run_bus_new_save.php?"+all)
  163. //})
  164. })
  165. $('.add-line').on('keyup',function(ev){
  166. var val = this.value;
  167. $.getJSON("st-xm/Api/addCarTime.php?method=searchline&word="+val,function(data){
  168. $(".line-item").show();
  169. var html = [];
  170. $.each(data,function(i,v){
  171. html.push('<li lineid='+v.lineid+'>'+v.name+'</li>')
  172. });
  173. $(".line-item").html(html.join(""));
  174. $(".line-item>li").on("click",function(){
  175. $(".addline-erro").html("")
  176. $(".add-cartype").unbind();
  177. var val = $(this).attr("lineid");
  178. $('.add-line').val($(this).html()).attr("lineid",$(this).attr("lineid"));
  179. $(".line-item").html("");
  180. $.getJSON("st-xm/Api/addCarTime.php?method=throughstation&lineid="+val,function(data){
  181. $(".car-type").html("")
  182. $(".line-item").hide();
  183. var linehtml = [];
  184. var tickethtml = [];
  185. $(".add-cartype").on("click",function(){
  186. $(".car-erro").html("")
  187. var cartype = [];
  188. $.each(data.addcartype,function(i,v){
  189. var acar = additemall("option",v.cartype,{"value":v.id});
  190. cartype.push(acar);
  191. })
  192. var acartype = addcar.replace("cartype",cartype.join());
  193. $(".car-type").append(acartype);
  194. $(".car-select .del").unbind();
  195. $(".car-select .del").on("click",function(){
  196. $(this).parent().remove();
  197. });
  198. });
  199. $.each(data.station,function(i,v){
  200. var td1= addTd(addTime(v.DATE_TIME));
  201. var td2= additemall("td",v.SITES,{alineid:v.RES_ID});
  202. if(i==0){var td3= addTd('<select style="width: 50px" disabled><option value="108">上</option></select>')}
  203. else{var td3=addTd(addUpdownType(v.UP_DOWN_TYPE))};
  204. var td4 = addTd(addMouth(v.TICKET_GATE,v.CHECKPORT));
  205. linehtml.push(addItem("tr","aline",td1.concat(td2,td3,td4)))
  206. });
  207. $.each(data.ticket,function(i,v){
  208. if(v.SEAT=="普通座"){
  209. var seatid = 72;
  210. }else if(v.SEAT=="贵宾座"){
  211. var seatid = 73;
  212. }else if(v.SEAT=="儿童特票座"){
  213. var seatid = 74;
  214. };
  215. if(v.CROWD=="成人"){
  216. var crowdid = 159;
  217. }else if(v.CROWD=="儿童"){
  218. var crowdid = 160;
  219. }else if(v.CROWD=="老人"){
  220. var crowdid = 161;
  221. }else if(v.CROWD=="军残"){
  222. var crowdid = 162;
  223. }else{
  224. var crowdid=0;
  225. };
  226. // if(i==0){
  227. var atciket = ticket1.replace(/SID|EID|START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID|aseatid|acrowdid/g,function(match){
  228. switch(match){
  229. case "SID":
  230. return v.SID;
  231. case "EID":
  232. return v.EID;
  233. case "aseatid":
  234. return seatid;
  235. case "acrowdid":
  236. return crowdid;
  237. case "START_AREA":
  238. return v.START_AREA;
  239. case "END_AREA":
  240. return v.END_AREA;
  241. case "SEAT":
  242. return v.SEAT;
  243. case "CROWD":
  244. return v.CROWD;
  245. case "MAX_COUNT":
  246. return v.MAX_COUNT;
  247. case "PROD_ID":
  248. return v.PROD_ID;
  249. case "PRICE":
  250. return v.PRICE;
  251. }
  252. })
  253. tickethtml.push(atciket)
  254. // }else{
  255. // var atciket = ticket1.replace(/SID|EID|START_AREA|END_AREA|SEAT|CROWD|PRICE|MAX_COUNT|PROD_ID|aseatid|acrowdid/g,function(match){
  256. // switch(match){
  257. // case "SID":
  258. // return v.SID;
  259. // case "EID":
  260. // return v.EID;
  261. // case "aseatid":
  262. // return seatid;
  263. // case "acrowdid":
  264. // return crowdid;
  265. // case "START_AREA":
  266. // return "";
  267. // case "END_AREA":
  268. // return "";
  269. // case "SEAT":
  270. // return v.SEAT;
  271. // case "CROWD":
  272. // return v.CROWD;
  273. // case "MAX_COUNT":
  274. // return v.MAX_COUNT;
  275. // case "PROD_ID":
  276. // return v.PROD_ID;
  277. // case "PRICE":
  278. // return v.PRICE;
  279. // }
  280. // })
  281. // tickethtml.push(atciket)
  282. // }
  283. });
  284. $(".replace-lineinfo").html(linehtml).attr("lineid",data.station[1].PROD_ID);
  285. $(".able-ticket").html(tickethtml.join());
  286. $(".ticket_sel").on("click",function(){
  287. $(".ticket-erro").html("");
  288. })
  289. var hourinfo = [];
  290. $.each($('.hour'),function(i,v){
  291. var val = $('.hour').eq(i).val()
  292. if(val<10){
  293. val="0"+val;
  294. }
  295. var arr = [i,val]
  296. hourinfo.push(arr)
  297. })
  298. var minuteinfo = [];
  299. $.each($('.minute'),function(i,v){
  300. var val = $('.minute').eq(i).val()
  301. if(val<10){
  302. val="0"+val;
  303. }
  304. var arr = [i,val]
  305. minuteinfo.push(arr)
  306. })
  307. $(".hour").on("change",function(){
  308. var index = $(this).parent().parent().index();
  309. var max = $(".hour").length;
  310. var dangvalue = $(this).val();
  311. for(var i = 0;i<hourinfo.length;i++){
  312. if(index == hourinfo[i][0]){
  313. var nextindex = hourinfo[i][0]+1;
  314. var myaddvalue = dangvalue-hourinfo[i][1];
  315. if(myaddvalue<0){
  316. hourinfo[i][1]=myaddvalue;
  317. }else{
  318. for(var t = nextindex;t<max;t++){
  319. var myvalue = hourinfo[t][1];
  320. var addvalue = myaddvalue+parseInt(myvalue);
  321. if(addvalue>23){addvalue-=24}{
  322. $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addvalue).attr("selected","true")
  323. hourinfo[t][1]=addvalue;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. hourinfo[index][1]=dangvalue;
  330. })
  331. $(".minute").on("change",function(){
  332. var index = $(this).parent().parent().index();
  333. var max = $(".minute").length;
  334. var dangvalue = parseInt($(this).val());
  335. for(var i = 0;i<minuteinfo.length;i++){
  336. if(index == minuteinfo[i][0]){
  337. var nextindex = parseInt(minuteinfo[i][0])+1;
  338. var addnum = dangvalue-parseInt(minuteinfo[i][1]);
  339. if(addnum<0){
  340. minuteinfo[i][1]=addnum
  341. }
  342. else{
  343. for(var t = nextindex;t<max;t++){
  344. var myhourvalue = hourinfo[t][1];
  345. var myminutevalue = minuteinfo[t][1];
  346. var addvalue = addnum+parseInt(myminutevalue);
  347. if(addvalue>=60){addvalue-=60; var addhour = parseInt(hourinfo[t][1])+1;}
  348. if(typeof addhour=="undefined"){
  349. $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true")
  350. minuteinfo[t][1]=addvalue;
  351. }else{
  352. $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true")
  353. minuteinfo[t][1]=addvalue;
  354. $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addhour).attr("selected","true");
  355. hourinfo[t][1]=addhour;
  356. }
  357. }
  358. }
  359. }
  360. }
  361. minuteinfo[index][1]=dangvalue;
  362. })
  363. })
  364. })
  365. })
  366. });
  367. $('.date-picker').datepicker({autoclose:true}).next().on('click', function(){
  368. $(this).prev().focus();
  369. });
  370. $('.allweek').on('change',function(){
  371. if($(this).is(":checked")){
  372. for(var i=0;i<$(".week").length;i++){
  373. $(".week").eq(i).click()
  374. }
  375. }else{
  376. for(var i=0;i<$(".week").length;i++){
  377. $(".week").eq(i).removeAttr("checked");
  378. }
  379. }
  380. })
  381. // $(".storage").on("click",function(){
  382. // var lineid = 'lineid='+$(".add-line").attr('dataid');
  383. // var time = 'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val();
  384. // var pass = [];
  385. // (function(){
  386. // var line =[];
  387. // for(var i = 0;i<$(".aline").length;i++){
  388. // var aline = [];
  389. // aline.push("time="+$(".aline").eq(i).find(".hour").val()+":"+$(".aline").eq(i).find(".minute").val());
  390. // aline.push("site="+$(".aline").find("td").eq(1).html());
  391. // aline.push("updown="+$(".aline").find(".updown").val());
  392. // aline.push("mouth="+$(".aline").find(".mouth").val());
  393. // line.push(aline.join(""));
  394. // }
  395. // })()
  396. // url = 'lineid='+$(".add-line").attr('dataid')+'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val()
  397. // console.log(url)
  398. // })
  399. })
  400. function addItem(label,classname,cent){
  401. var html = ['<'+label+' class='+classname+'>'];
  402. html.push(cent);
  403. html.push('</'+label+'>');
  404. return html.join("")
  405. }
  406. function addLi(html){
  407. var li = ['<li>'];
  408. li.push(html);
  409. li.push('</li>');
  410. li = li.join("");
  411. return li
  412. }
  413. function addTime(time){
  414. var time = time.split(":");
  415. var newHour = parseInt(time[0]),
  416. newMinute = parseInt(time[1]);
  417. var html = ['<select class="hour">'];
  418. for(var i=0;i<24;i++){
  419. if(i==newHour){
  420. //..a
  421. if(i<10){
  422. html.push('<option selected value='+i+'>0'+i+'</option>')
  423. }else{
  424. html.push('<option selected value='+i+'>'+i+'</option>')
  425. }
  426. }else{
  427. if(i<10){
  428. html.push('<option value='+i+'>0'+i+'</option>')
  429. }else{
  430. html.push('<option value='+i+'>'+i+'</option>')
  431. }
  432. }
  433. }
  434. html.push('</select style="width: 50px">:<select class="minute">')
  435. for(var t=0;t<60;t++){
  436. if(t==newMinute){
  437. if(t<10){
  438. html.push('<option selected value='+t+'>0'+t+'</option>')
  439. }else{
  440. html.push('<option selected value='+t+'>'+t+'</option>')
  441. }
  442. }else{
  443. if(t<10){
  444. html.push('<option value='+t+'>0'+t+'</option>')
  445. }else{
  446. html.push('<option value='+t+'>'+t+'</option>')
  447. }
  448. }
  449. }
  450. html.push('</select>');
  451. html = html.join("")
  452. return html
  453. }
  454. function addUpdownType(type){
  455. var typeid= null;
  456. var alltypeid = [108,109,110,114]
  457. if(type==108){typeid="上"}
  458. else if(type==109){typeid="上下"}
  459. else if(type==110){typeid="下"}
  460. else if(type==114){typeid="不停"}
  461. var html = ['<select style="width: 50px" class="updown">'],
  462. alltype = ['上','下','上下','不停']
  463. for(var i = 0;i<4;i++){
  464. if(typeid==alltype[i]){html.push('<option selected value='+alltypeid[i]+'>'+alltype[i]+'</option>')}
  465. else{html.push('<option value = '+alltypeid[i]+'>'+alltype[i]+'</option>')}
  466. }
  467. html.push('</select>');
  468. html = html.join("")
  469. return html
  470. }
  471. function addMouth(maxNum,num){
  472. var html = ['<select style="width: 55px" class="mouth">'];
  473. for(var i in maxNum){
  474. if(i==num){
  475. html.push('<option selected value = '+i+'>'+maxNum[i]+'</option>')
  476. // html.push('<option selected value = '+i+'>-</option>')
  477. }else{
  478. html.push('<option value='+i+'>'+maxNum[i]+'</option>')
  479. }
  480. };
  481. html.push("</select>");
  482. if(maxNum<=0){
  483. html=['-'];
  484. }
  485. html = html.join("")
  486. return html;
  487. }
  488. function addTd(html){
  489. var td = ['<td>'];
  490. td.push(html);
  491. td.push('</td>');
  492. td = td.join("")
  493. return td;
  494. }
  495. function addTr(html){
  496. var tr = ['<tr>'];
  497. tr.push(html)
  498. tr.push('</tr>');
  499. tr = tr.join("")
  500. return tr;
  501. }
  502. jQuery.fn.outerHTML = function(s) {
  503. return (s) ? this.before(s).remove() : $("<Hill_man>").append(this.eq(0).clone()).html();
  504. }
  505. function additemall(lable,cen,attr){
  506. 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) +'>'];
  507. html.push(cen);
  508. html.push('</'+lable+'>');
  509. return html.join("")
  510. }
  511. function getdata(){
  512. var val = [];
  513. Array.prototype.push.apply(val,arguments);
  514. return val.join("&");
  515. }
  516. function getval(dom,value){
  517. var val = null;
  518. if(value=="val"||value=="value"){val =$(dom).eq(0).val()}
  519. else if(value == "html"){val = $(dom).eq(0).html()}
  520. else {val = $(dom).eq(0).attr(value);var name = value;return name + "=" +val;}
  521. var name = $(dom).eq(0).attr("name");
  522. return name + "=" +val
  523. }
  524. function out_login(){
  525. window.location='login.html';
  526. }