You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

378 lines
9.9 KiB

  1. //每页显示的数据个数
  2. var pagesize = 10;
  3. var tttHTML = '';
  4. window.onload = function(){
  5. iflogin();
  6. var nowDay = getDateTime(0);
  7. $('#id-date-picker-1').val(nowDay);
  8. var cur = "";
  9. var currpage = getPar("currpage");
  10. var start_area = "";
  11. var end_area = "";
  12. var go_time = "";
  13. var start_area_text = "";
  14. var end_area_text = "";
  15. if(!currpage){
  16. cur = 1;
  17. start_area = $('#start_area').attr('changeid');
  18. start_area_text = $('#start_area').text();
  19. end_area = $('#end_area').attr('changeid');
  20. end_area_text = $('#end_area').text();
  21. go_time = $('#id-date-picker-1').val();
  22. }else{
  23. cur = currpage;
  24. start_area = getPar('start_area');
  25. $('#start_area').attr('changeid',start_area);
  26. end_area = getPar('end_area');
  27. $('#end_area').attr('changeid',end_area);
  28. go_time = getPar('go_time');
  29. $('#id-date-picker-1').val(go_time);
  30. start_area_text = getPar('start_area_text');
  31. $('#start_area').val(start_area_text);
  32. end_area_text = getPar('end_area_text');
  33. $('#end_area').val(end_area_text);
  34. }
  35. tttHTML = $('#list').html();
  36. searchBtnClicked(cur,start_area,end_area,go_time,start_area_text,end_area_text);
  37. }
  38. //出发地检索
  39. function startAreaSearch(startid,self_id){
  40. var start_area = $("#start_area").val();
  41. $.ajax({
  42. url:'./zz-fx/control.php',
  43. type: "post",
  44. data: {
  45. area_name:start_area,
  46. type:"retrieval_area"
  47. },
  48. dataType: "json",
  49. success: function (data) {
  50. if(data.code == 0){
  51. console.log(data);
  52. createHtml(data.list,self_id)
  53. }
  54. },
  55. fail: function (data) {
  56. // 此处放失败后执行的代码
  57. }
  58. });
  59. }
  60. //筛选列表
  61. function createHtml(data,select_id){
  62. var temp ="";
  63. for (var i = 0; i < data.length; i++) {
  64. temp +='<div class="content" area_id="'+data[i].id+'">'+data[i].area_name+'</div>'
  65. }
  66. $(".select_content_"+select_id).html(temp);
  67. $(".content").click(function(){
  68. var line = $(this).text();
  69. var value = $(this).attr('area_id');
  70. $("#"+select_id).val(line);
  71. $("#"+select_id).attr('changeid',value);
  72. })
  73. }
  74. $("#start_area").click(function(e){
  75. e.stopPropagation();
  76. $(".select_content_start_area").removeClass("hide");
  77. $(".select_content_end_area").addClass("hide");
  78. });
  79. $("#end_area").click(function(a){
  80. a.stopPropagation();
  81. $(".select_content_end_area").removeClass("hide");
  82. $(".select_content_start_area").addClass("hide");
  83. });
  84. $(document).click(function(){
  85. if(!$(".select_content_start_area").hasClass("hide")){
  86. $(".select_content_start_area").addClass("hide");
  87. }
  88. if(!$(".select_content_end_area").hasClass("hide")){
  89. $(".select_content_end_area").addClass("hide");
  90. }
  91. })
  92. //目的地检索
  93. function endAreaSearch(endid,self_id){
  94. var end_area = $("#end_area").val();
  95. $.ajax({
  96. url:'./zz-fx/control.php',
  97. type: "post",
  98. data: {
  99. area_name:end_area,
  100. type:"retrieval_area"
  101. },
  102. dataType: "json",
  103. success: function (data) {
  104. if(data.code == 0){
  105. createHtml(data.list,self_id)
  106. }
  107. },
  108. fail: function (data) {
  109. // 此处放失败后执行的代码
  110. }
  111. });
  112. }
  113. //查询按钮
  114. function searchBtnClicked(cur,start_area,end_area,go_time,start_area_text,end_area_text){
  115. if(!cur){
  116. cur = 1;
  117. }
  118. if(!start_area||!end_area||!go_time||!start_area_text||!end_area_text){
  119. start_area = $('#start_area').attr('changeid');
  120. end_area = $('#end_area').attr('changeid');
  121. go_time = $('#id-date-picker-1').val();
  122. start_area_text = $('#start_area').val();
  123. end_area_text = $('#end_area').val();
  124. }
  125. if (start_area_text=="") {
  126. start_area="";
  127. }
  128. if (end_area_text=="") {
  129. end_area="";
  130. }
  131. $.ajax({
  132. url:'./zz-fx/control.php', //请求地址
  133. type: "post", //请求方式
  134. // data: data, //请求参数
  135. data:{
  136. type:"retrieval_through",
  137. start_area:start_area,
  138. end_area:end_area,
  139. go_time:go_time,
  140. bus_type:255,
  141. run_type:0,
  142. currpage:cur,
  143. pagesize:pagesize
  144. },
  145. async:false,
  146. dataType: "json",
  147. success: function (data) {
  148. console.log(data);
  149. if(data.code == 0){
  150. var sum = data.totalnum;
  151. if (sum == 0) {
  152. window.wxc.xcConfirm("没有相关线路!", window.wxc.xcConfirm.typeEnum.info);
  153. }
  154. var tag = "test";
  155. var sendurl = './through_bus.html?start_area='+start_area+'&end_area='+end_area+'&go_time='+go_time+'&start_area_text='+start_area_text+'&end_area_text='+end_area_text;
  156. getPager(sendurl, sum, cur, pagesize,tag,'currpage');
  157. reloadInfo(data);
  158. }
  159. },
  160. fail: function (date) {
  161. window.wxc.xcConfirm("查询失败!", window.wxc.xcConfirm.typeEnum.info);
  162. }
  163. });
  164. if(cur!=1){
  165. var start_area = getPar('start_area');
  166. $('#start_area').attr('changeid',start_area);
  167. var end_area = getPar('end_area');
  168. $('#end_area').attr('changeid',end_area);
  169. var go_time = getPar('go_time');
  170. $('#id-date-picker-1').val(go_time);
  171. var start_area_text = getPar('start_area_text');
  172. $('#start_area').val(start_area_text);
  173. var end_area_text = getPar('end_area_text');
  174. $('#end_area').val(end_area_text);
  175. }
  176. }
  177. //加载数据
  178. function reloadInfo(data){
  179. var list = data.list;
  180. var newHTML='';
  181. for(var i=0;i<list.length;i++){
  182. var tempHTML=tttHTML;
  183. tempHTML=tempHTML.replace('[出发日期]',list[i].run_date);
  184. tempHTML=tempHTML.replace('[出发时间]',list[i].start_time);
  185. tempHTML=tempHTML.replace('[出发地]',list[i].start_area_name);
  186. tempHTML=tempHTML.replace('[目的地]',list[i].end_area_name);
  187. tempHTML=tempHTML.replace('[座位等级]',list[i].site_type);
  188. tempHTML=tempHTML.replace('[价格]',list[i].price);
  189. var str = '<a target="_Blank" href="./pay_order.html?run_id='+list[i].run_id + '&start_area_id='+list[i].start_area_id+'&end_area_id='+list[i].end_area_id+'">预订</a>';
  190. tempHTML=tempHTML.replace('[操作]',str);
  191. newHTML+=tempHTML;
  192. $('#list_info').show();
  193. }
  194. $('#list').html(newHTML);
  195. }
  196. //交换出发地和目的地
  197. function changePosition(){
  198. //取值
  199. var strid = '';
  200. var strtext = '';
  201. var start_area_id = $('#start_area').attr('changeid');
  202. var start_area_text = $('#start_area').val();
  203. var end_area_id = $('#end_area').attr('changeid');
  204. var end_area_text = $('#end_area').val();
  205. //替换
  206. strid = start_area_id;
  207. start_area_id = end_area_id;
  208. end_area_id = strid;
  209. strtext = start_area_text;
  210. start_area_text = end_area_text;
  211. end_area_text = strtext;
  212. $('#start_area').attr('changeid',start_area_id);
  213. $('#start_area').val(start_area_text);
  214. $('#end_area').attr('changeid',end_area_id);
  215. $('#end_area').val(end_area_text);
  216. }
  217. //得到url上的参数
  218. function getPar(par){
  219. var local_url = document.location.href;
  220. local_url = decodeURI(local_url);
  221. var get = local_url.indexOf(par +"=");
  222. if(get == -1){
  223. return false;
  224. }
  225. var get_par = local_url.slice(par.length + get + 1);
  226. var nextPar = get_par.indexOf("&");
  227. if(nextPar != -1){
  228. get_par = get_par.slice(0, nextPar);
  229. }
  230. return get_par;
  231. }
  232. //获取时间
  233. function getDateTime(nTypeFlag) {
  234. var tNowTime = new Date();
  235. var myYear = ';' + tNowTime.getFullYear() + ';';
  236. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  237. var myDay = ';' + tNowTime.getDate() + ';';
  238. var myHour = ';' + tNowTime.getHours() + ';';
  239. var myMinu = ';' + tNowTime.getMinutes() + ';';
  240. var mySecond = ';' + tNowTime.getSeconds() + ';';
  241. if(myMonth.length < 4) myMonth = '0' + myMonth;
  242. if(myDay.length < 4) myDay = '0' + myDay;
  243. if(myHour.length < 4) myHour = '0' + myHour;
  244. if(myMinu.length < 4) myMinu = '0' + myMinu;
  245. if(mySecond.length < 4) mySecond = '0' + mySecond;
  246. var cNewTimeStr;
  247. switch(nTypeFlag + 1 - 1) {
  248. case 0:
  249. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  250. break;
  251. case 1:
  252. cNewTimeStr = myYear + myMonth + myDay;
  253. break;
  254. case 2:
  255. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  256. break;
  257. case 3:
  258. cNewTimeStr = myHour + myMinu + mySecond;
  259. break;
  260. case 4:
  261. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  262. break;
  263. case 5:
  264. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  265. break;
  266. case 6:
  267. cNewTimeStr = myYear;
  268. break;
  269. case 7:
  270. cNewTimeStr = myYear + '-' + myMonth;
  271. break;
  272. case 8: //得到上一个月的今天
  273. var date = getDateTime(0);
  274. var arr = date.split('-');
  275. var year = arr[0]; //获取当前日期的年份
  276. var month = arr[1]; //获取当前日期的月份
  277. var day = arr[2]; //获取当前日期的日
  278. var days = new Date(year, month, 0);
  279. days = days.getDate(); //获取当前日期中月的天数
  280. var year2 = year;
  281. var month2 = parseInt(month) - 1;
  282. if(month2 == 0) {
  283. year2 = parseInt(year2) - 1;
  284. month2 = 12;
  285. }
  286. var day2 = day;
  287. var days2 = new Date(year2, month2, 0);
  288. days2 = days2.getDate();
  289. if(day2 > days2) {
  290. day2 = days2;
  291. }
  292. if(month2 < 10) {
  293. month2 = '0' + month2;
  294. }
  295. cNewTimeStr = year2 + '-' + month2 + '-' + day2;
  296. break;
  297. case 9: //得到下一个月的今天
  298. var date = getDateTime(0);
  299. var arr = date.split('-');
  300. var year = arr[0]; //获取当前日期的年份
  301. var month = arr[1]; //获取当前日期的月份
  302. var day = arr[2]; //获取当前日期的日
  303. var days = new Date(year, month, 0);
  304. days = days.getDate(); //获取当前日期中的月的天数
  305. var year2 = year;
  306. var month2 = parseInt(month) + 1;
  307. if(month2 == 13) {
  308. year2 = parseInt(year2) + 1;
  309. month2 = 1;
  310. }
  311. var day2 = day;
  312. var days2 = new Date(year2, month2, 0);
  313. days2 = days2.getDate();
  314. if(day2 > days2) {
  315. day2 = days2;
  316. }
  317. if(month2 < 10) {
  318. month2 = '0' + month2;
  319. }
  320. var t2 = year2 + '-' + month2 + '-' + day2;
  321. return t2;
  322. break;
  323. default:
  324. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  325. break;
  326. }
  327. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  328. return cNewTimeStr;
  329. }