var page_size = 10;
var page_status = 0;
var cur_url='';
var cur_sel_bus_group='0';
/*======================网络请求的Ajax的代码=======================*/
// 创建一个Ajax对象
if (window.ActiveXObject) {
var myreq = new ActiveXObject("Microsoft.XMLHTTP");
} else {
var myreq = new XMLHttpRequest();
}
function ZZLog(str){
var isLog=true;
if(isLog){
console.log(str);
}
}
function selectPage(){
page_size = $("#select_curpage").val();
page_status = 1;
}
/**
*
* @param {Object} myURL 返回数据URL接口
* @param {Object} myURL2 当前的URL
*/
document.addEventListener('DOMContentLoaded', function() {
carList_html = $("#carList").html();
// 设置出发日期为当前日期
page_size = getPar('page_size');
if(!page_size){
page_size = $("#select_curpage").val();
}else{
$("#select_curpage").val(page_size);
}
var currpage=getPar('currpage');
var start_area = getPar('start_area');
var end_area = getPar('end_area');
var line = getPar('line');
var start_date = getPar('start_date');
var end_date = getPar('end_date');
var select_status = getPar('run_status');
var bus_type = getPar('bus_type');
var bus_group = getPar('bus_group');
if(currpage || start_area || end_area || line || start_date || end_date || select_status || bus_group){
if(currpage==""){
currpage=1;
}
var tnowtime = getDateTime(4);
$('#start_area').val(start_area);
$('#end_area').val(end_area);
$('#prod').val(line);
$('#id-date-picker-1').val(start_date);
$('#id-date-picker-2').val(end_date);
$("#select_status").val(select_status);
$("#bus_type").val(bus_type);
$('#bus_group').val(bus_group);
cur_sel_bus_group=bus_group;
var tnowtime = getDateTime(4);
var myURL = "./st-xm/Api/runInfoControll.php?method=getRunList&currpage=" + currpage + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date + "&run_status=" + select_status + "&bus_type=" + bus_type+"&bus_group="+bus_group;
var myURL2 = "./carList.html?method=getRunList&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date + "&run_status=" + select_status + "&bus_type=" + bus_type+"&bus_group="+bus_group;
cur_url=myURL2;
get_virtual_user_list(myURL, myURL2);
}else{
$("#id-date-picker-1").val(getDateTime(11));
$("#id-date-picker-2").val(getDateTime(11));
click_search();
}
}, false);
// 请求方法,传入URL
function get_virtual_user_list(myURL, myURL2) {
ZZLog(myURL);
var tnowtime = getDateTime(4);
if (myURL.indexOf('?') >= 0) {
myURL += '&tt=' + tnowtime;
} else {
myURL += '?tt=' + tnowtime;
}
$.getJSON(myURL, function(httpData) {
ZZLog(httpData);
if (httpData['code'] != '0') {
$('#carList').html('');
alert(httpData['info']);
return;
}
if (httpData['run_list'].length <= 0) {
$("#carList").html('');
$('#test').html('');
return;
}
$("#carList").html('');
$('#test').html('');
var total = httpData['total'];
$("#select_curpage_all").val(total);
var carList = httpData['run_list'];
var carListHTML = ''
for (var i = 0; i < carList.length; i++) {
var tempDict = carList[i];
var tempHTML = carList_html;
tempHTML = tempHTML.replace('[dict-json]',JSON.stringify(tempDict));
tempHTML = tempHTML.replace('[data-statu]', tempDict['run_status']);
tempHTML = tempHTML.replace('[car_number]',tempDict['car_number']);
tempHTML = tempHTML.replace('[run_date]', tempDict['run_date']);
tempHTML = tempHTML.replace('[QDH]', tempDict['prod_name']);
tempHTML = tempHTML.replace('[name]', tempDict['run_id']);
tempHTML = tempHTML.replace('[线路]', tempDict['property'] + ' ' + tempDict['prod_name']);
tempHTML = tempHTML.replace('[出发日期]', tempDict['run_date']);
tempHTML = tempHTML.replace('[出发站点时间]', tempDict['start_time'] + ' ' + tempDict['res_name']);
var car_no=tempDict['car_number'];
car_no=(Array(2).join(0)+car_no).slice(-2);
tempHTML = tempHTML.replace('[车次]', car_no);
tempHTML = tempHTML.replace('[座位总数]', tempDict['seat_count']);
tempHTML = tempHTML.replace('[已售座位]', tempDict['sale_seat']);
if (tempDict['saled_count'].trim() == "0" && tempDict['max_count'].trim() == "0") {
tempHTML = tempHTML.replace('[已售人数]', '-');
} else {
// tempHTML = tempHTML.replace('[已售]', tempDict['saled_count'] + '/' + tempDict['max_count']);
tempHTML = tempHTML.replace('[已售人数]', tempDict['saled_count']);
}
tempHTML = tempHTML.replace('[运营状态]', tempDict['run_status']);
tempHTML = tempHTML.replace('[收客状态]', tempDict['receiving']);
var caozuoStr = ''
caozuoStr += '查看 ';
caozuoStr += '修改 ';
tempHTML = tempHTML.replace('[操作]', caozuoStr);
carListHTML += tempHTML;
}
$("#carList").html(carListHTML);
$('.one').css('display', 'table-row');
var bus_group_list=httpData['bus_group_list'];
var busgrouphtml='';
for (var i=0,m=bus_group_list.length;i1){
$('#update_car_no').addClass('update_car_no');
$('#update_car_no').attr('data-statu','false');
}else if(arr_bool_QDH.length==1 && (temp_QDH=="上海-千岛湖" || temp_QDH=="千岛湖-上海" || temp_QDH=="上海市-千岛湖" || temp_QDH=="千岛湖-上海市")){
$('#update_car_no').removeClass('update_car_no');
$('#update_car_no').attr('data-statu','true');
}else{
$('#update_car_no').addClass('update_car_no');
$('#update_car_no').attr('data-statu','false');
}
if(arr_bool_statu.indexOf('false')!=-1){
$('#five_del').addClass('del');
$('#five_del').attr('data-statu','false');
}else if(arr_bool_statu.indexOf('true')!=-1){
$('#five_del').removeClass('del');
$('#five_del').attr('data-statu','true');
}else{
$('#five_del').addClass('del');
$('#five_del').attr('data-statu','false');
}
}
//
//结束日期value改变的时候触发
$(document).ready(function() {
var date = new Date();
$('#id-date-picker-2').val(getDateTime(9));
$('#id-date-picker-1').change(function() {
//开始日期
var start_date = $('#id-date-picker-1').val();
if (start_date.trim().length <= 0) {
alert('请选择开始日期!!!');
return;
}
//结束日期
var end_date = $('#id-date-picker-2').val();
if (end_date.trim().length < 0) {
alert('请选择结束日期');
return;
}
// 判断日期是否合理
var date1 = new Date(start_date.replace(/\-/g, '/'));
var date2 = new Date(end_date.replace(/\-/g, '/'));
if (date1>date2 || end_date=="") {
$('#id-date-picker-2').val(start_date);
}
});
$('#id-date-picker-2').change(function() {
//开始日期
var start_date = $('#id-date-picker-1').val();
if (start_date.trim().length <= 0) {
alert('请选择开始日期!!!');
return;
}
//结束日期
var end_date = $('#id-date-picker-2').val();
if (end_date.trim().length < 0) {
alert('请选择结束日期');
return;
}
// 判断日期是否合理
var date1 = new Date(start_date.replace(/\-/g, '/'));
var date2 = new Date(end_date.replace(/\-/g, '/'));
if (date2 < date1) {
alert('结束日期必须大于开始日期!!!');
$('#id-date-picker-2').val('');
return;
}
});
});
//查询按钮click事件
function click_search(){
$('#update_car_no').addClass('update_car_no');
$('#update_car_no').attr('data-statu','false');
$('#five_del').addClass('del');
$('#five_del').attr('data-statu','false');
$('.ace')[0].checked=false;
//出发地
var start_area = $('#start_area').val();
//目的地
var end_area = $('#end_area').val();
//线路
var line = $('#prod').val();
//开始日期
var start_date = $('#id-date-picker-1').val();
if (start_date.trim().length <= 0) {
alert('请选择开始日期!!!');
return;
}
//结束日期
var end_date = $('#id-date-picker-2').val();
if (end_date.trim().length <= 0) {
alert('请选择结束日期!!!');
return;
}
// 判断日期是否合理
var date1 = new Date(start_date.replace(/\-/g, '/'));
var date2 = new Date(end_date.replace(/\-/g, '/'));
if (date2 < date1) {
alert('结束日期必须大于开始日期!!!');
return;
}
//运营状态
var select_status = $("#select_status").val();
if(page_status == 1){
var currpage=getPar('currpage');
}else{
var currpage=1;
}
if (!currpage) {
currpage = '1'
}
//车辆类型
var bus_type = $("#bus_type").val();
var bus_group = $('#bus_group').val();
var tnowtime = getDateTime(4);
var myURL = "./st-xm/Api/runInfoControll.php?method=getRunList&currpage=1&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date + "&run_status=" + select_status + "&bus_type=" + bus_type+"&bus_group="+bus_group;
var myURL2 = "./carList.html?method=getRunList&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date + "&run_status=" + select_status + "&bus_type=" + bus_type+"&bus_group="+bus_group;
cur_url=myURL2;
get_virtual_user_list(myURL, myURL2);
}
//点击审核等按钮
function click_five_btn(btn_value) {
//先拿到run_id
var arr_run_ids = new Array();
var temp_run_id=0;
var temp_run_date='';
var temp_line='';
$('.ace').each(function(index, item) {
if (this.checked && index != 0) {
var car_number=$(this).attr('data-carno');
var run_id=$(this).attr('name');
var cstr1="{"+run_id+","+car_number+"}";
arr_run_ids.push(cstr1);
temp_line=$(this).attr('data_QDH');
temp_run_id=$(this).attr('name');
temp_run_date=$(this).attr('data-date');
}
});
if (arr_run_ids.length <= 0) {
alert('请勾选!!!');
return;
}
if(btn_value=="update_car_no"){
var statu=$('#update_car_no').attr('data-statu');
if(statu=='true'){
ZZLog('可用');
var line=temp_line;
var run_id=temp_run_id;
var run_date=temp_run_date;
var next_url="update_car_no.html?line="+line+"&run_id="+run_id+"&start_date="+run_date;
window.open(next_url);
}else{
ZZLog('不可用');
}
}else{
if(btn_value=="4"){
var va_4=$('#five_del').attr('data-statu');
if(va_4!="true"){
alert('只有待审核的才可删除!!!');
return;
}
}
var run_id_str = arr_run_ids.join(',');
ZZLog("/st-xm/Api/run_status_update.php?allrunid=" + run_id_str + "&status=" + btn_value);
$.getJSON("/st-xm/Api/run_status_update.php?allrunid=" + run_id_str + "&status=" + btn_value, function(data) {
ZZLog(data);
if (data.errcode == 0) {
alert("操作成功");
// click_search();
location.replace(cur_url);
} else {
alert(data.errinfo);
}
})
}
}
function getPar(par) {
//获取当前URL
var local_url = document.location.href;
local_url = decodeURI(local_url);
//获取要取得的get参数位置
var get = local_url.indexOf(par + "=");
if (get == -1) {
return false;
}
//截取字符串
var get_par = local_url.slice(par.length + get + 1);
//判断截取后的字符串是否还有其他get参数
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;
//alert(tNowTime);
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;
case 10: //昨日日期
var dateStr=getDateTime(0);
var t_temp_sdate = dateStr.split('-');
var now = new Date(t_temp_sdate[0], t_temp_sdate[1], t_temp_sdate[2]);
now.setDate(now.getDate() - 0 - 1);
var year = ";" + now.getFullYear() + ";";
var month = ";" + now.getMonth() + ";";
var day = ";" + now.getDate() + ";";
if(year.length < 4) {
year = "0" + year;
}
if(month.length < 4) {
month = "0" + month;
}
if(day.length < 4) {
day = "0" + day;
}
var datestr = year + "-" + month + "-" + day;
datestr = datestr.replace(/;/g, "");
return datestr;
break;
case 11: //明日日期
var dateStr=getDateTime(0);
var t_temp_sdate = dateStr.split('-');
var now = new Date(t_temp_sdate[0], t_temp_sdate[1], t_temp_sdate[2]);
now.setDate(now.getDate() - 0 + 1);
var year = ";" + now.getFullYear() + ";";
var month = ";" + now.getMonth() + ";";
var day = ";" + now.getDate() + ";";
if(year.length < 4) {
year = "0" + year;
}
if(month.length < 4) {
month = "0" + month;
}
if(day.length < 4) {
day = "0" + day;
}
var datestr = year + "-" + month + "-" + day;
datestr = datestr.replace(/;/g, "");
return datestr;
break;
default:
cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
break;
}
cNewTimeStr = cNewTimeStr.replace(/;/g, "");
return cNewTimeStr;
}