Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

432 wiersze
11 KiB

  1. //var val =null;
  2. $(document).ready(function(){
  3. var ticket1 = $(".adult").html();
  4. var ticket2 = $(".noble").html();
  5. // var hour = $(".hour").html(),
  6. // minute = $(".minute").html(),
  7. // place = $(".place").html(),
  8. // entry = $(".entry").html(),
  9. // mouth = $(".mouth").html();
  10. //console.log(hour)
  11. //$(".replace-lineinfo").hide()
  12. $('.add-line').on('keyup',function(ev){
  13. var val = this.value;
  14. if(/[a-zA-Z]+/.test(val)){
  15. //console.log(1)
  16. $.getJSON("json/"+val+".html?rand="+Math.random(),function(data){
  17. //console.log(2);
  18. //console.log(data);
  19. var html = [];
  20. $.each(data,function(i,v){
  21. html.push('<li dataid='+v.lineid+'>'+v.name+'</li>')
  22. });
  23. //console.log(this)
  24. $(".line-item").html(html.join(""));
  25. $(".line-item>li").on("click",function(){
  26. var val = $(this).html().replace(/[^a-zA-Z]+/,'');
  27. $('.add-line').val($(this).html()).attr("dataid",$(this).attr("dataid"));
  28. $(".line-item").html("");
  29. $.getJSON('json/'+val+'.html?rand='+Math.random(),function(data){
  30. var linehtml = [];
  31. //console.log(1);
  32. //console.log(lineInfoFormat);
  33. var tickethtml = [];
  34. $.each(data,function(i,v){
  35. // console.log(v.lineId);
  36. if(typeof v.lineId=="undefined"){
  37. var td1= addTd(addTime(v.time));
  38. var td2= addTd(v.site);
  39. if(i==0){var td3= addTd('<select disabled><option>上</option></select>')}
  40. else{var td3=addTd(addUpdownType(v.type))};
  41. var td4 = addTd(addMouth(v.maxcheck,v.check));
  42. linehtml.push(addItem("tr","aline",td1.concat(td2,td3,td4)))
  43. }else{
  44. var line = v.line.split("-"),
  45. ticket11= ticket1.replace("出发地",line[0]).replace("目的地",line[1]),
  46. ticket22 = ticket2,
  47. arr = [],
  48. ticket=null,
  49. judge=false;
  50. $.each(v,function(key,value){
  51. if(key=="child"){
  52. var child=["child","","儿童"];
  53. Array.prototype.push.apply(child,value.split(","));
  54. arr.push(child);
  55. };
  56. if(key=="noble"){
  57. var noble=["noble","贵宾","成人"];
  58. Array.prototype.push.apply(noble,value.split(","));
  59. arr.push(noble);
  60. };
  61. if(key=="adult"){
  62. var adult=["adult","普通","成人"];
  63. Array.prototype.push.apply(adult,value.split(","));
  64. arr.push(adult);
  65. };
  66. });
  67. //var myticket1 = ticket1.replace("出发地",line[0]).replace("目的地",line[1]);
  68. for(var i = 0;i<arr.length;i++){
  69. if(judge==false){
  70. //myticket1.replace("座位",arr[i][0]).replace("人群",arr[i][1]).replace("零售价",arr[i][2].replace("ticketnum",arr[]))
  71. ticket = ticket11.replace(/座位|人群|零售价|ticketnum|ticketval/g,function(match){
  72. switch(match){
  73. case "座位":
  74. return arr[i][1];
  75. case "人群":
  76. return arr[i][2];
  77. case "零售价":
  78. return arr[i][3];
  79. case "ticketnum":
  80. return arr[i][4];
  81. case "ticketval":
  82. return arr[i][0]
  83. }
  84. })
  85. judge=true;
  86. tickethtml.push(addTr(ticket));
  87. }
  88. else{
  89. ticket=ticket2.replace(/座位|人群|零售价|ticketnum|ticketval/g,function(match){
  90. switch(match){
  91. case "座位":
  92. return arr[i][1];
  93. case "人群":
  94. return arr[i][2];
  95. case "零售价":
  96. return arr[i][3];
  97. case "ticketnum":
  98. return arr[i][4];
  99. case "ticketval":
  100. return arr[i][0]
  101. }
  102. })
  103. tickethtml.push(addTr(ticket))
  104. }
  105. }
  106. $(".able-ticket").html(addTr(tickethtml.join("")))
  107. }
  108. })
  109. $(".replace-lineinfo").html(linehtml);
  110. var hourinfo = [];
  111. $.each($('.hour'),function(i,v){
  112. var val = $('.hour').eq(i).val()
  113. var arr = [i,val]
  114. hourinfo.push(arr)
  115. })
  116. var minuteinfo = [];
  117. $.each($('.minute'),function(i,v){
  118. var val = $('.minute').eq(i).val()
  119. var arr = [i,val]
  120. minuteinfo.push(arr)
  121. })
  122. $(".hour").on("change",function(){
  123. var index = $(this).parent().parent().index();
  124. var max = $(".hour").length;
  125. var dangvalue = $(this).val();
  126. for(var i = 0;i<hourinfo.length;i++){
  127. if(index == hourinfo[i][0]){//获得下标
  128. var nextindex = hourinfo[i][0]+1;
  129. var myaddvalue = dangvalue-hourinfo[i][1];
  130. if(myaddvalue<0){
  131. hourinfo[i][1]=myaddvalue;
  132. }else{
  133. for(var t = nextindex;t<max;t++){
  134. var myvalue = hourinfo[t][1];//获得下一个input值
  135. var addvalue = myaddvalue+parseInt(myvalue);
  136. if(addvalue>23){addvalue-=24}{
  137. $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addvalue).attr("selected","true")
  138. hourinfo[t][1]=addvalue;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. hourinfo[index][1]=dangvalue;
  145. })
  146. $(".minute").on("change",function(){
  147. var index = $(this).parent().parent().index();
  148. var max = $(".minute").length;
  149. var dangvalue = parseInt($(this).val());
  150. for(var i = 0;i<minuteinfo.length;i++){
  151. if(index == minuteinfo[i][0]){//获得下标
  152. var nextindex = parseInt(minuteinfo[i][0])+1;
  153. var addnum = dangvalue-parseInt(minuteinfo[i][1]);
  154. if(addnum<0){minuteinfo[i][1]=addnum}
  155. else{
  156. for(var t = nextindex;t<max;t++){
  157. var myhourvalue = hourinfo[t][1];
  158. var myminutevalue = minuteinfo[t][1];
  159. var addvalue = addnum+parseInt(myminutevalue);
  160. if(addvalue>=60){addvalue-=60; var addhour = parseInt(hourinfo[t][1])+1;}
  161. if(typeof addhour=="undefined"){
  162. $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true")
  163. minuteinfo[t][1]=addvalue;
  164. }else{
  165. $(".minute").eq(t).find("option").removeAttr("selected");$(".minute").eq(t).find("option").eq(addvalue).attr("selected","true")
  166. minuteinfo[t][1]=addvalue;
  167. $(".hour").eq(t).find("option").removeAttr("selected");$(".hour").eq(t).find("option").eq(addhour).attr("selected","true");
  168. hourinfo[t][1]=addhour;
  169. }
  170. }
  171. }
  172. }
  173. }
  174. minuteinfo[index][1]=dangvalue;
  175. })
  176. })
  177. })
  178. })
  179. }
  180. });
  181. $(".add-cartype").on("click",function(){
  182. $.getJSON("json/cartype.html?rand="+Math.random(),function(data){
  183. var car = [];
  184. $.each(data,function(i,v){
  185. car.push('<option value='+v.id+'>'+v.cartype+'</option>');
  186. });
  187. car = addItem('select','car-item',car.join(""));
  188. var carnumoption = [];
  189. for(var i = 1;i<=data[0].count;i++){
  190. carnumoption.push('<option value='+i+'>'+i+'</option>')
  191. }
  192. var carnum = addItem('select','car-num',carnumoption.join(""));
  193. var ifseat = [];
  194. if(data[0].ifSeat==0){
  195. ifseat.push('<option value="sel">可选</option><option value="nosel">不可选</option>');
  196. }else if(data[0].ifSeat==1){
  197. ifseat.push('<option value="sel">可选</option>');
  198. }else if(data[0].ifSeat==2){
  199. ifseat.push('<option value="nosel">不可选</option>');
  200. }
  201. ifseat=addItem("select","ifseat",ifseat.join(""))
  202. var del = addItem('span','del','删除')
  203. var all = car.concat(carnum,ifseat,del);
  204. var div = addItem('div','car-select',all);
  205. $(".car-type").append(div);
  206. $(".del").on("click",function(){
  207. $(this).parent().remove();
  208. })
  209. $(".car-item").on("change",function(){
  210. var count = null;
  211. var ifseat = null;
  212. var val = this.value;
  213. $.each(data,function(i,v){
  214. if(val==v.id){
  215. count=v.count;
  216. ifseat=v.ifSeat
  217. }
  218. });
  219. var selnum = [];
  220. for(var i = 1;i<=count;i++){
  221. selnum.push('<option>'+i+'</option>')
  222. }
  223. $(this).parent().find(".car-num").html(selnum.join("")).removeAttr("disabled");
  224. if(ifseat==0){
  225. $(this).parent().find(".if-seat").html('<option value="sel">可选</option><option value="nosel">不可选</option>').removeAttr("disabled");
  226. }
  227. else if(ifseat==1){
  228. $(this).parent().find(".if-seat").html('<option value="sel">可选</option>').removeAttr("disabled");
  229. }
  230. else if(ifseat==1){
  231. $(this).parent().find(".if-seat").html('<option value="nosel">不可选</option>').removeAttr("disabled");
  232. }
  233. })
  234. })
  235. })
  236. $('.date-picker').datepicker({autoclose:true}).next().on('click', function(){
  237. $(this).prev().focus();
  238. });
  239. $('.allweek').on('change',function(){
  240. if($(this).is(":checked")){
  241. for(var i=0;i<$(".week").length;i++){
  242. $(".week").eq(i).click()
  243. }
  244. }else{
  245. for(var i=0;i<$(".week").length;i++){
  246. $(".week").eq(i).removeAttr("checked");
  247. }
  248. }
  249. })
  250. $(".storage").on("click",function(){
  251. var lineid = 'lineid='+$(".add-line").attr('dataid');
  252. var time = 'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val();
  253. var pass = [];
  254. (function(){
  255. var line =[];
  256. for(var i = 0;i<$(".aline").length;i++){
  257. var aline = [];
  258. aline.push("time="+$(".aline").eq(i).find(".hour").val()+":"+$(".aline").eq(i).find(".minute").val());
  259. aline.push("site="+$(".aline").find("td").eq(1).html());
  260. aline.push("updown="+$(".aline").find(".updown").val());
  261. aline.push("mouth="+$(".aline").find(".mouth").val());
  262. line.push(aline.join(""));
  263. }
  264. })()
  265. url = 'lineid='+$(".add-line").attr('dataid')+'time='+$("#id-date-picker-1").val()+'-'+$("#id-date-picker-2").val()
  266. })
  267. })
  268. function addItem(label,classname,cent){
  269. var html = ['<'+label+' class='+classname+'>'];
  270. html.push(cent);
  271. html.push('</'+label+'>');
  272. return html.join("")
  273. }
  274. function addLi(html){
  275. var li = ['<li>'];
  276. li.push(html);
  277. li.push('</li>');
  278. li = li.join("");
  279. return li
  280. }
  281. function addTime(time){
  282. var time = time.split(":");
  283. var newHour = parseInt(time[0]),
  284. newMinute = parseInt(time[1]);
  285. var html = ['<select class="hour">'];
  286. for(var i=0;i<24;i++){
  287. if(i==newHour){
  288. html.push('<option selected value='+i+'>'+i+'</option>')}
  289. else{html.push('<option value='+i+'>'+i+'</option>')}
  290. }
  291. html.push('</select>:<select class="minute">')
  292. for(var t=0;t<60;t++){
  293. if(t==newMinute){
  294. html.push('<option selected value='+t+'>'+t+'</option>')
  295. }else{
  296. html.push('<option value='+t+'>'+t+'</option>')
  297. }
  298. }
  299. html.push('</select>');
  300. html = html.join("")
  301. return html
  302. }
  303. function addUpdownType(type){
  304. var html = ['<select class="updown">'],
  305. alltype = ['上','下','上下','不停']
  306. for(var i = 0;i<4;i++){
  307. if(type==alltype[i]){html.push('<option selected>'+alltype[i]+'</option>')}
  308. else{html.push('<option>'+alltype[i]+'</option>')}
  309. }
  310. html.push('</select>');
  311. html = html.join("")
  312. return html
  313. }
  314. function addMouth(maxNum,num){
  315. var html = ['<select class="mouth">'];
  316. for(var i = 1;i<=maxNum;i++){
  317. if(i==num){
  318. html.push('<option selected>'+i+'</option>')
  319. }else{
  320. html.push('<option>'+i+'</option>')
  321. }
  322. };
  323. html.push("</select>");
  324. html = html.join("")
  325. return html;
  326. }
  327. function addTd(html){
  328. var td = ['<td>'];
  329. td.push(html);
  330. td.push('</td>');
  331. td = td.join("")
  332. return td;
  333. }
  334. function addTr(html){
  335. var tr = ['<tr>'];
  336. tr.push(html)
  337. tr.push('</tr>');
  338. tr = tr.join("")
  339. return tr;
  340. }