|
- //每页显示的数据个数
- var pagesize = 10;
- var tttHTML = '';
-
- window.onload = function(){
- iflogin();
- var nowDay = getDateTime(0);
- $('#id-date-picker-1').val(nowDay);
-
- var cur = "";
- var currpage = getPar("currpage");
-
- var start_area = "";
- var end_area = "";
- var go_time = "";
- var start_area_text = "";
- var end_area_text = "";
-
- if(!currpage){
- cur = 1;
- start_area = $('#start_area').attr('changeid');
-
- start_area_text = $('#start_area').text();
-
- end_area = $('#end_area').attr('changeid');
-
- end_area_text = $('#end_area').text();
-
- go_time = $('#id-date-picker-1').val();
-
- }else{
- cur = currpage;
- start_area = getPar('start_area');
- $('#start_area').attr('changeid',start_area);
-
- end_area = getPar('end_area');
- $('#end_area').attr('changeid',end_area);
-
- go_time = getPar('go_time');
- $('#id-date-picker-1').val(go_time);
-
- start_area_text = getPar('start_area_text');
- $('#start_area').val(start_area_text);
-
- end_area_text = getPar('end_area_text');
- $('#end_area').val(end_area_text);
-
- }
- tttHTML = $('#list').html();
- searchBtnClicked(cur,start_area,end_area,go_time,start_area_text,end_area_text);
- }
-
-
- //出发地检索
- function startAreaSearch(startid,self_id){
- var start_area = $("#start_area").val();
- $.ajax({
- url:'./zz-fx/control.php',
- type: "post",
- data: {
- area_name:start_area,
- type:"retrieval_area"
- },
- dataType: "json",
- success: function (data) {
- if(data.code == 0){
- console.log(data);
- createHtml(data.list,self_id)
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
-
- //筛选列表
- function createHtml(data,select_id){
- var temp ="";
- for (var i = 0; i < data.length; i++) {
- temp +='<div class="content" area_id="'+data[i].id+'">'+data[i].area_name+'</div>'
- }
- $(".select_content_"+select_id).html(temp);
- $(".content").click(function(){
- var line = $(this).text();
- var value = $(this).attr('area_id');
- $("#"+select_id).val(line);
- $("#"+select_id).attr('changeid',value);
- })
- }
-
- $("#start_area").click(function(e){
- e.stopPropagation();
- $(".select_content_start_area").removeClass("hide");
- $(".select_content_end_area").addClass("hide");
- });
-
- $("#end_area").click(function(a){
- a.stopPropagation();
- $(".select_content_end_area").removeClass("hide");
- $(".select_content_start_area").addClass("hide");
- });
-
- $(document).click(function(){
- if(!$(".select_content_start_area").hasClass("hide")){
- $(".select_content_start_area").addClass("hide");
- }
- if(!$(".select_content_end_area").hasClass("hide")){
- $(".select_content_end_area").addClass("hide");
- }
- })
-
-
- //目的地检索
- function endAreaSearch(endid,self_id){
- var end_area = $("#end_area").val();
- $.ajax({
- url:'./zz-fx/control.php',
- type: "post",
- data: {
- area_name:end_area,
- type:"retrieval_area"
- },
- dataType: "json",
- success: function (data) {
- if(data.code == 0){
- createHtml(data.list,self_id)
- }
- },
- fail: function (data) {
- // 此处放失败后执行的代码
- }
- });
- }
-
- //查询按钮
- function searchBtnClicked(cur,start_area,end_area,go_time,start_area_text,end_area_text){
- if(!cur){
- cur = 1;
- }
- if(!start_area||!end_area||!go_time||!start_area_text||!end_area_text){
- start_area = $('#start_area').attr('changeid');
-
- end_area = $('#end_area').attr('changeid');
-
- go_time = $('#id-date-picker-1').val();
-
- start_area_text = $('#start_area').val();
-
- end_area_text = $('#end_area').val();
-
- }
-
- if (start_area_text=="") {
- start_area="";
- }
- if (end_area_text=="") {
- end_area="";
- }
- $.ajax({
- url:'./zz-fx/control.php', //请求地址
- type: "post", //请求方式
- // data: data, //请求参数
- data:{
- type:"retrieval_through",
- start_area:start_area,
- end_area:end_area,
- go_time:go_time,
- bus_type:255,
- run_type:0,
- currpage:cur,
- pagesize:pagesize
- },
- async:false,
- dataType: "json",
- success: function (data) {
- console.log(data);
- if(data.code == 0){
- var sum = data.totalnum;
- if (sum == 0) {
- window.wxc.xcConfirm("没有相关线路!", window.wxc.xcConfirm.typeEnum.info);
- }
- var tag = "test";
- 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;
- getPager(sendurl, sum, cur, pagesize,tag,'currpage');
- reloadInfo(data);
- }
- },
- fail: function (date) {
- window.wxc.xcConfirm("查询失败!", window.wxc.xcConfirm.typeEnum.info);
- }
- });
- if(cur!=1){
- var start_area = getPar('start_area');
- $('#start_area').attr('changeid',start_area);
-
- var end_area = getPar('end_area');
- $('#end_area').attr('changeid',end_area);
-
- var go_time = getPar('go_time');
- $('#id-date-picker-1').val(go_time);
-
- var start_area_text = getPar('start_area_text');
- $('#start_area').val(start_area_text);
-
- var end_area_text = getPar('end_area_text');
- $('#end_area').val(end_area_text);
- }
- }
-
- //加载数据
- function reloadInfo(data){
- var list = data.list;
- var newHTML='';
- for(var i=0;i<list.length;i++){
- var tempHTML=tttHTML;
- tempHTML=tempHTML.replace('[出发日期]',list[i].run_date);
- tempHTML=tempHTML.replace('[出发时间]',list[i].start_time);
- tempHTML=tempHTML.replace('[出发地]',list[i].start_area_name);
- tempHTML=tempHTML.replace('[目的地]',list[i].end_area_name);
- tempHTML=tempHTML.replace('[座位等级]',list[i].site_type);
- tempHTML=tempHTML.replace('[价格]',list[i].price);
- 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>';
- tempHTML=tempHTML.replace('[操作]',str);
- newHTML+=tempHTML;
- $('#list_info').show();
- }
- $('#list').html(newHTML);
-
- }
-
- //交换出发地和目的地
- function changePosition(){
- //取值
- var strid = '';
- var strtext = '';
- var start_area_id = $('#start_area').attr('changeid');
- var start_area_text = $('#start_area').val();
- var end_area_id = $('#end_area').attr('changeid');
- var end_area_text = $('#end_area').val();
-
- //替换
- strid = start_area_id;
- start_area_id = end_area_id;
- end_area_id = strid;
- strtext = start_area_text;
- start_area_text = end_area_text;
- end_area_text = strtext;
-
- $('#start_area').attr('changeid',start_area_id);
- $('#start_area').val(start_area_text);
- $('#end_area').attr('changeid',end_area_id);
- $('#end_area').val(end_area_text);
-
- }
-
- //得到url上的参数
- function getPar(par){
- var local_url = document.location.href;
- local_url = decodeURI(local_url);
- var get = local_url.indexOf(par +"=");
- if(get == -1){
- return false;
- }
- var get_par = local_url.slice(par.length + get + 1);
- var nextPar = get_par.indexOf("&");
- if(nextPar != -1){
- get_par = get_par.slice(0, nextPar);
- }
- return get_par;
- }
-
- //获取时间
- function getDateTime(nTypeFlag) {
- var tNowTime = new Date();
- var myYear = ';' + tNowTime.getFullYear() + ';';
- var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
- var myDay = ';' + tNowTime.getDate() + ';';
- var myHour = ';' + tNowTime.getHours() + ';';
- var myMinu = ';' + tNowTime.getMinutes() + ';';
- var mySecond = ';' + tNowTime.getSeconds() + ';';
-
- if(myMonth.length < 4) myMonth = '0' + myMonth;
- if(myDay.length < 4) myDay = '0' + myDay;
- if(myHour.length < 4) myHour = '0' + myHour;
- if(myMinu.length < 4) myMinu = '0' + myMinu;
- if(mySecond.length < 4) mySecond = '0' + mySecond;
-
- var cNewTimeStr;
- switch(nTypeFlag + 1 - 1) {
- case 0:
- cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
- break;
- case 1:
- cNewTimeStr = myYear + myMonth + myDay;
- break;
- case 2:
- cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
- break;
- case 3:
- cNewTimeStr = myHour + myMinu + mySecond;
- break;
- case 4:
- cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
- break;
- case 5:
- cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
- break;
- case 6:
- cNewTimeStr = myYear;
- break;
- case 7:
- cNewTimeStr = myYear + '-' + myMonth;
- break;
- case 8: //得到上一个月的今天
- var date = getDateTime(0);
- var arr = date.split('-');
- var year = arr[0]; //获取当前日期的年份
- var month = arr[1]; //获取当前日期的月份
- var day = arr[2]; //获取当前日期的日
- var days = new Date(year, month, 0);
- days = days.getDate(); //获取当前日期中月的天数
- var year2 = year;
- var month2 = parseInt(month) - 1;
- if(month2 == 0) {
- year2 = parseInt(year2) - 1;
- month2 = 12;
- }
- var day2 = day;
- var days2 = new Date(year2, month2, 0);
- days2 = days2.getDate();
- if(day2 > days2) {
- day2 = days2;
- }
- if(month2 < 10) {
- month2 = '0' + month2;
- }
- cNewTimeStr = year2 + '-' + month2 + '-' + day2;
- break;
- case 9: //得到下一个月的今天
- var date = getDateTime(0);
- var arr = date.split('-');
- var year = arr[0]; //获取当前日期的年份
- var month = arr[1]; //获取当前日期的月份
- var day = arr[2]; //获取当前日期的日
- var days = new Date(year, month, 0);
- days = days.getDate(); //获取当前日期中的月的天数
- var year2 = year;
- var month2 = parseInt(month) + 1;
- if(month2 == 13) {
- year2 = parseInt(year2) + 1;
- month2 = 1;
- }
- var day2 = day;
- var days2 = new Date(year2, month2, 0);
- days2 = days2.getDate();
- if(day2 > days2) {
- day2 = days2;
- }
- if(month2 < 10) {
- month2 = '0' + month2;
- }
-
- var t2 = year2 + '-' + month2 + '-' + day2;
- return t2;
- break;
- default:
- cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
- break;
- }
-
- cNewTimeStr = cNewTimeStr.replace(/;/g, "");
-
- return cNewTimeStr;
-
- }
|