var mygrid = '';
var mycargrid = '';
var mydrivergrid = '';
var alllineposition = null;
var myalineposition = null;
var mycarposition = null;
var mydriverposition = null;
var sort_id = 0;
var type_id = 0;
var page_size = 10;
var cur_sel_bus_group='0';
function ZZLog(str){
var isLog=true;
if(isLog){
console.log(str);
}
}
$(document).ready(function() {
$('#id-date-picker-1').val(getDateTime(0)); // 默认当前日期
$('#id-date-picker-2').val(getDateTime(11)); // 默认明日日期
//$.getJSON("http://192.168.6.132/st-xm/Api/busInfoControll.php?method=getBusList&user_id=1&currpage=2&page_size=20&start_area=上海&end_area=北京&line=sb001&strat_date=2016-05-05&end_date=2016-09-09",function(data){ZZLog(data)})
mygrid = $(".line-info").html(),
mycargrid = $(".acar").outerHTML(),
mydrivergrid = $(".adriver").outerHTML(),
alllineposition = null,
myalineposition = null,
mycarposition = null,
mydriverposition = null;
$(".line-info").remove();
$(".acar").remove();
$(".adriver").remove();
var currpage = getPar('currpage');
var start_date = getPar('start_date');
var end_date = getPar('end_date');
var bus_type = getPar('bus_type');
var bus_group = getPar('bus_group');//线路组合
if(!currpage && !start_date) {
click_search();
}else {
if(currpage==""){
currpage=1;
}
var start_area = getPar('start_area');
var end_area = getPar('end_area');
var line = getPar('line');
var sort = getPar('sort_id');
var type = getPar('type_id');
if(type) {
type_id = type;
}
if(sort) {
sort_id =sort;
}
if(start_area) {
$('#start_area').val(start_area);
}
if(end_area) {
$('#end_area').val(end_area);
}
if(line) {
$('#prod').val(line);
}
if(start_date) {
$('#id-date-picker-1').val(start_date);
}
if(end_date) {
$('#id-date-picker-2').val(end_date);
}
if(bus_type) {
$('#bus_type').val(bus_type);
}
if(bus_group){
$('#bus_group').val(bus_group);
cur_sel_bus_group=bus_group;
}
var url = "./st-xm/Api/busInfoControll.php?method=getBusList&type_id=" + type_id +"&sort_id=" + sort_id + "&currpage=" + currpage + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date+ "&bus_type=" + bus_type+"&bus_group="+bus_group;
var page_url = "./branchmoney.html?method=getBusList&user_id=1&type_id=" + type_id +"&sort_id=" + sort_id + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date + "&bus_type=" + bus_type+"&bus_group="+bus_group;
get_url_data(url, page_url);
}
})
// 日期符法判断
$(document).ready(function() {
$('#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) {
$(this).val(start_date);
// $('#id-date-picker-2').val(start_date);
// alert('结束日期必须大于开始日期!!!');
// $('#id-date-picker-2').val('');
// return;
}
});
$('#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(date2 < date1) {
$('#id-date-picker-2').val(start_date);
// alert('结束日期必须大于开始日期!!!');
// $('#id-date-picker-1').val('');
// return;
}
});
});
//点击查询
$(document).ready(function() {
$(".searchbtn").on("click", function() {
type_id = 0;
sort_id = 0;
click_search();
});
});
// 复选框事件
function select_checked(index) {
//index=0最上面的全选 index=1表示的是下面所有的
var cur_check = $('.ace')[0];
var checkList = $('.ace');
var checkCount = checkList.length - 1;
var true_count = 0;
for(var i = 1; i < checkList.length; i++) {
if(index == '0') {
checkList[i].checked = cur_check.checked;
} else {
if(checkList[i].checked == false) {
cur_check.checked = false
} else {
true_count = true_count + 1;
}
}
}
//判断下面是否选中完
if(checkCount == true_count) {
cur_check.checked = true;
}
}
function click_search() {
//开始日期
var start_date = $('#id-date-picker-1').val();
cur_sel_bus_group=$('#bus_group').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 line = $('#prod').val();
var start_area = $('#start_area').val();
var end_area = $('#end_area').val();
var bus_type = $('#bus_type').val();
var bus_group = $('#bus_group').val();
// type_id 就是全部,未派,已派的id 须加一个参数
//..
var url = "./st-xm/Api/busInfoControll.php?method=getBusList&type_id=" + type_id +"&sort_id=" + sort_id+ "&currpage=1&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date + "&bus_type=" + bus_type+"&bus_group="+bus_group;
var page_url = "./branchmoney.html?method=getBusList&user_id=1&type_id=" + type_id+"&sort_id=" + sort_id + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date + "&bus_type=" + bus_type+"&bus_group="+bus_group;
get_url_data(url, page_url);
}
function get_url_data(url, page_url) {
ZZLog('调度url=' + url);
$.getJSON(url, function(data) {
ZZLog(data);
if(data.code == 0 || data.code == "0") {
var busgrouphtml='';
$.each(data['bus_group_list'],function(i,v){
var tempHTML='';
tempHTML=tempHTML.replace('value="0"','value='+v['group_id']);
tempHTML=tempHTML.replace('全部',v['group_name']);
busgrouphtml+=tempHTML;
});
$('#bus_group').html(busgrouphtml);
$('#bus_group').val(cur_sel_bus_group);
var alllisthtml = [];
var tnowtime = Math.round(1000000);
$.each(data.run_no_list, function(i, v) {
//ZZLog(v)
var aline = mygrid.replace(/lineid|line|godate|gotime|carnum|cartime|seat|bus_type|sold|cartype|drivername|costtotale|sendbutton/g, function(match) {
switch(match) {
case "lineid":
return v.id;
case "line":
return v.property + v.prod_name;
case "godate":
return v.run_date;
case "gotime":
return v.run_time;
case "carnum":
var carnum=(Array(2).join(0)+v.bus_order_id).slice(-2);
return carnum;
case "seat":
return v.res_name;
case "bus_type":
return v.bus_type;
case "sold":
var order_url = "order_list.html?tt=" + tnowtime +
"&timelimit=" + '出发时间' +
"&starttime=" + v.run_date +
"&endtime=" + v.run_date +
"&ordersource=" + '' +
"&bus_type=" + '' +
"&orderstatus=" + '' +
"&paystatus=" + '' +
"&billingstatus=" + '' +
"&mealbounce=" + '' +
"&refund=" + '' +
"&moresearch=" + '' +
"&start_area=" + '' +
"&end_area=" + '' +
"&line=" + encodeURIComponent(v.prod_name)
+"&currpage="+'1'
+
"&pagesize=" + '10' +
"&search_bus_no=" + v.bus_order_id +
"&run_time=" + v.run_time;
var tmp_url = ''+v.saled_count+'';
//add by qius on 20170925
tmp_url += '
上下车人数';
return tmp_url;
case "cartype":
return '
' + v.send_bus_res_name + '
carnamecarseat ';
case "drivername":
return '' + v.send_bus_driver_res_name + '
H952712345679812 ';
case "costtotale":
var ht_str=v.cost_total_price+"";
return ht_str;
case "sendbutton":
if( v.send_bus_res_id > 0 && v.send_bus_driver_res_id > 0 ) {
return "发送";
} else {
return '';
}
};
});
alllisthtml.push(addItem("tr", "alinedrag", aline));
});
$(".replace-lineinfo").html(alllisthtml);
var carhtml = [];
$.each(data.vehicle_list, function(i, v) {
var acar = mycargrid.replace(/carid|carnum|carname|carseat/g, function(match) {
switch(match) {
case "carid":
return v.res_id;
case "carnum":
return v.vihicle_number;
case "carname":
return v.vihicle_brand;
case "carseat":
return v.vihicle_seat;
};
})
carhtml.push(acar);
})
$(".carinfodata").html(carhtml);
var driverhtml = [];
$.each(data.driver_list, function(i, v) {
var driver = mydrivergrid.replace(/driverid|drivername|drivernum|driverphone/g, function(match) {
switch(match) {
case "driverid":
return v.res_id;
case "drivername":
return v.driver_name;
case "drivernum":
return v.driver_number;
case "driverphone":
return v.driver_phone;
};
})
driverhtml.push(driver);
})
$(".driverinfodata").html(driverhtml);
adddriverinEvent();
// adddriveroutEvent();
addcarinEvent();
// addcaroutEvent();
$('#zpage').html('');
getPager(page_url, data.total, data.currpage, page_size, "zpage", "currpage");
}
});
}
var temp_run_id=0;
var temp_bus_order_id=0;
var temp_start_end_area_length=0;
var temp_method_type=0; //结算方式
var temp_remark=''; // 备注
function click_edite(run_id,bus_order_id,bus_type){
temp_run_id=run_id;
temp_bus_order_id=bus_order_id;
temp_method_type=0;
// $('input[type="radio"][name="type"][value="130"]').attr("checked","checked");
var url="./st-xm/Api/busInfoControll.php?method=selectPOI&run_id="+run_id+"&bus_order_id="+bus_order_id;
ZZLog(url);
$.getJSON(url,function(res_data){
ZZLog(res_data);
center_show($('.update_cost_price'));
if(res_data['code']!="0"){
alert(res_data['info']);return;
}
var start_end_areaList=res_data['start_end_areaList'];
var real_start_end=res_data['real_start_end_area'];
temp_start_end_area_length=start_end_areaList.length;
var is_real_area=false;
if(start_end_areaList.length>0){
var HTML='';
for (var i=0,m=start_end_areaList.length;i[上海-乌镇]';
} else {
var check_txt = '';
if( (is_real_area == false && bus_type ==255 && i==1)||(is_real_area == true && bus_type ==256 )) { check_txt = 'checked="checked"'; }
area_HTML='[上海-乌镇]';
}
var tempHTML=area_HTML;
var s_e_id=dict['start_area_id']+","+dict['end_area_id'];
var s_e_area=dict['start_area']+"-"+dict['end_area'];
tempHTML=tempHTML.replace('[value]',s_e_id);
tempHTML=tempHTML.replace('[SID]',dict['start_area_id']);
tempHTML=tempHTML.replace('[EID]',dict['end_area_id']);
tempHTML=tempHTML.replace('[上海-乌镇]',s_e_area);
HTML+=tempHTML
}
$('#start_end_area').html(HTML);
// if(start_end_areaList.length==1){
// $('#start_end_area').css('display','none');
// }else{
// $('#start_end_area').css('display','block');
// }
var HTML2='';
var total_cost_price=0;
var t_prod_name=$('#edit_'+run_id).attr('data-area');
var t_total_price=$('#edit_'+run_id).attr('data-total-price'); // 成本总价
var t_seat_total_price=0; //车座结算的总价只用显示
$('#seat_line').text(t_prod_name);
for (var i=start_end_areaList.length-1;i>=0;i--) {
var dict=start_end_areaList[i];
total_cost_price+=parseInt(dict['cost_price']);
var area_HTML='';
area_HTML='';
area_HTML+='[start_end_area]';
area_HTML+='';
area_HTML+='
';
var tempHTML=area_HTML;
t_seat_total_price+=parseInt(dict['every_total_price'])*parseInt(dict['real_sale']);
tempHTML=tempHTML.replace('[value]',dict['real_sale']==0?0:dict['every_total_price']);
tempHTML=tempHTML.replace('[real_sale]',dict['real_sale']);
tempHTML=tempHTML.replace('[start_end_area]',dict['start_area']+'-'+dict['end_area']+" x"+dict['real_sale']+"");
tempHTML=tempHTML.replace('[start_end_area_id]',dict['start_area_id']+'-'+dict['end_area_id']);
HTML2+=tempHTML
}
HTML2+='成本总价:'+t_seat_total_price+'元';
$('#car_seat_every_price').html(HTML2);
}else{
$('#start_end_area').html('');
$('#car_seat_every_price').html('');
}
change_radio_area(run_id,bus_order_id,temp_method_type);
});
}
// 改变结算方式
var temp_cur_type=130;
function change_type(type_value){
temp_cur_type=type_value;
$('#cost_remark').val('');
if(type_value==129){
show_change_by_type(2);
if(temp_method_type==129){
$('#cost_remark').val(temp_remark);
}
}else{
show_change_by_type(1);
if(temp_method_type==130){
$('#cost_remark').val(temp_remark);
}
}
}
function show_change_by_type(type){
if(type==1){
$('#start_end_area').css('display','block');
$('#col_1').css('display','block');
$('#car_seat_line').css('display','none');
$('#car_seat_price').css('display','none');
}else{
$('#car_seat_line').css('display','block');
$('#car_seat_price').css('display','block');
$('#start_end_area').css('display','none');
$('#col_1').css('display','none');
}
}
// 改变出发地目的地
function change_radio_area(run_id,bus_order_id,method_id){
//1,{233198,1,6,9172},{200,200,20,20,20,20,10,10,129},这是备注信息333
// run_id=233198;
// bus_order_id=2;
var s_id=$('input[type="radio"][name="area"]:checked').attr('data-SID');
var e_id=$('input[type="radio"][name="area"]:checked').attr('data-EID');
// s_id=6;
// e_id=9172;
var url="./st-xm/Api/busInfoControll.php?method=selectCost&run_id="+run_id+"&bus_order_id="+bus_order_id+"&start_area_id="+s_id+"&end_area_id="+e_id;
ZZLog(url);
$.getJSON(url,function(res_data){
ZZLog(res_data);
if(res_data['code']!="0"){
alert(res_data['info']);return;
}
var costList=res_data['costList'];
$('#cost_price').val('0');
$('#car_price').val('0');
$('#driver_subsidies').val('0');
$('#oil_price').val('0');
$('#food_price').val('0');
$('#road_bridge_price').val('0');
$('#sleep_price').val('0');
$('#cost_remark').val('');
if(costList.length>0){
var dict=costList[0];
$('input[type="radio"][name="type"][value="'+dict['pay_method_id']+'"]').attr("checked",'checked');
var temp_s_e_id=dict['start_area_id']+","+dict['end_area_id'];
$('input[type="radio"][name="area"][value="'+dict['temp_s_e_id']+'"]').attr("checked",'checked');
$('#cost_price').val(dict['cost_price']);
$('#car_price').val(dict['car_price']);
$('#driver_subsidies').val(dict['driver_subsidies']);
$('#oil_price').val(dict['oil_price']);
$('#food_price').val(dict['food_price']);
$('#road_bridge_price').val(dict['road_bridge_price']);
$('#sleep_price').val(dict['sleep_price']);
$('#cost_remark').val(parseInt(dict['pay_method_id'])==130?dict['cost_remark']:"");
temp_remark=dict['cost_remark'];
}
})
}
function update_price(type){
if(type==1){
var car_price=$('#car_price').val();
var driver_subsidies=$('#driver_subsidies').val();
var oil_price=$('#oil_price').val();
var food_price=$('#food_price').val();
var road_bridge_price=$('#road_bridge_price').val();
var sleep_price=$('#sleep_price').val();
if(car_price==""){car_price=0;}
if(driver_subsidies==""){driver_subsidies=0;}
if(oil_price==""){oil_price=0;}
if(food_price==""){food_price=0;}
if(road_bridge_price==""){road_bridge_price=0;}
if(sleep_price==""){sleep_price=0;}
var sum_price=parseInt(car_price);
sum_price+=parseInt(driver_subsidies);
sum_price+=parseInt(oil_price);
sum_price+=parseInt(food_price);
sum_price+=parseInt(road_bridge_price);
sum_price+=parseInt(sleep_price);
$('#cost_price').val(sum_price);
}else{
var sum_price=0;
$('.start_area_2').each(function(index,domEle){
var t_price=$(domEle).val();
var t_sale_count=$(domEle).attr('data-real-sale');
if(isNaN(t_price) || t_price==""){
t_price=0;
}
sum_price+=parseInt(t_price)*parseInt(t_sale_count);
});
$('#car_seat_total_price').text(sum_price);
}
}
// 点击结算保存
$(document).ready(function(){
$('#btn_update_cost_price').on('click',function(e){
if($(this).text()=="保存中..."){
return;
}
$(this).text("保存中");
var cost_price=$('#cost_price').val()!=""?$('#cost_price').val():0;
var car_price=$('#car_price').val()!=""?$('#car_price').val():0;
var driver_subsidies=$('#driver_subsidies').val()!=""?$('#driver_subsidies').val():0;
var oil_price=$('#oil_price').val()!=""?$('#oil_price').val():0;
var food_price=$('#food_price').val()!=""?$('#food_price').val():0;
var road_bridge_price=$('#road_bridge_price').val()!=""?$('#road_bridge_price').val():0;
var sleep_price=$('#sleep_price').val()!=""?$('#sleep_price').val():0;
var cost_remark=$('#cost_remark').val()!=""?$('#cost_remark').val():"";
var s_id=$('input[name="area"]:checked').attr('data-SID');
var e_id=$('input[name="area"]:checked').attr('data-EID');
// temp_run_id=233198;
// temp_bus_order_id=2;
// s_id=6;
// e_id=9172;
var type=$('input[name="type"]:checked').val();
// 拼接参数
var str_main="{"+temp_run_id+","+temp_bus_order_id+","+s_id+","+e_id+"}";
var str_info1="{"+cost_price+","+car_price+","+driver_subsidies+","+oil_price+","+food_price+","+road_bridge_price+","+sleep_price+"}";
var str_info2="";
$('.start_area_2').each(function(index,domEle){
var t_every_price=$(domEle).val();
var t_area_id=$(domEle).attr('data-area-id').replace('-',',');
var t_real_sale=$(domEle).attr('data-real-sale');
str_info2+="{"+temp_run_id+","+temp_bus_order_id+","+t_area_id+","+t_real_sale+","+t_every_price+"}";
});
var str_remark="{"+cost_remark+"}";
ZZLog(str_main+","+str_info1+","+str_info2+","+str_remark);
var str_method='';
if(temp_cur_type==130){
str_method='update_car';
}
if(temp_cur_type==129){
str_method='update_seat';
}
var url="./st-xm/Api/busInfoControll.php?method=updateCost&str_method="+str_method+""+"&str_main="+str_main+"&str_info1="+str_info1+"&str_info2="+str_info2+"&str_remark="+str_remark;
ZZLog(url);
$.getJSON(url,function(res_data){
ZZLog(res_data);
if(res_data['code']!="0"){
alert(res_data['info']);return;
}
alert('保存成功');
click_cancel(null,'.update_cost_price');
refersh_cur_page();
});
});
})
//加载公司
$(document).ready(function() {
var url = "./st-xm/Api/busInfoControll.php?method=getCompanyList";
var company_HTML = '';
$.getJSON(url, function(res_data) {
var HTML = '';
var com_list = res_data['company_list'];
for(var i = 0, m = com_list.length; i < m; i++) {
var dict = com_list[i];
var tempHTML = '';
tempHTML = tempHTML.replace('0', dict['res_id']);
tempHTML = tempHTML.replace('全部', dict['res_name']);
HTML += tempHTML;
}
$('#car_company').html(HTML);
$('#driver_company').html(HTML);
});
});
//type : 0 全部 1 未派 2 已派
function getList(type) {
// 保存类型
type_id = type;
click_search();
//..
}
function sort(type) {
sort_id = type;
click_search();
}
function reset() {
//先拿到run_id
var arr_run_ids = new Array();
var puts = $('.ace');
for(var i = 0; i < puts.length; i++) {
if(puts[i].checked && i != 0) {
arr_run_ids.push($(puts[i]).val());
}
}
if(arr_run_ids.length <= 0) {
alert('请勾选!!!');
return;
}
var run_id_str = arr_run_ids.join(',');
var url = "./st-xm/Api/busInfoControll.php?method=reset&idstr=" + run_id_str;
$.getJSON(url, function(res_data) {
if(res_data['code'] != "0") {
refersh_cur_page();
alert(res_data['info']);
return;
}
alert('操作成功!!!');
$('.ace')[0].checked = false;
// click_search();
refersh_cur_page();
//开始日期
car_change('');
driver_change('');
});
}
function refersh_cur_page(){
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 line = $('#prod').val();
var start_area = $('#start_area').val();
var end_area = $('#end_area').val();
var bus_type = $('#bus_type').val();
var page_url = "./branchmoney.html?method=getBusList&type_id=" + type_id+"&sort_id=" + sort_id + "&page_size=" + page_size + "&start_area=" + start_area + "&end_area=" + end_area + "&line=" + line + "&start_date=" + start_date + "&end_date=" + end_date+"&bus_type="+bus_type;
var listURL=encodeURI(page_url);
window.location.href=listURL;
}
//锁定
function lock() {
//先拿到run_id
var arr_run_ids = new Array();
var puts = $('.ace');
for(var i = 0; i < puts.length; i++) {
if(puts[i].checked && i != 0) {
arr_run_ids.push($(puts[i]).val());
}
}
if(arr_run_ids.length <= 0) {
alert('请勾选!!!');
return;
}
var run_id_str = arr_run_ids.join(',');
var url = "./st-xm/Api/busInfoControll.php?method=lock&idstr=" + run_id_str;
$.getJSON(url, function(res_data) {
if(res_data['code'] != "0") {
alert(res_data['info']);
}
alert('操作成功!!!');
$('.ace')[0].checked = false;
// click_search();
// location.replace(location.href);
refersh_cur_page();
car_change('');
driver_change('');
});
}
//解锁
function unlock() {
//先拿到run_id
var arr_run_ids = new Array();
var puts = $('.ace');
for(var i = 0; i < puts.length; i++) {
if(puts[i].checked && i != 0) {
arr_run_ids.push($(puts[i]).val());
}
}
if(arr_run_ids.length <= 0) {
alert('请勾选!!!');
return;
}
var run_id_str = arr_run_ids.join(',');
var url = "./st-xm/Api/busInfoControll.php?method=unlock&idstr=" + run_id_str;
$.getJSON(url, function(res_data) {
if(res_data['code'] != "0") {
alert(res_data['info']);
}
alert('操作成功!!!');
$('.ace')[0].checked = false;
// click_search();
// location.replace(location.href);
refersh_cur_page();
car_change('');
driver_change('');
});
}
//公司值发生改变
var car_key_word = '';
var car_company = '';
function car_company_change(value) {
car_company = value;
car_load_html(car_key_word, car_company);
}
//车辆值改变
function car_change(value) {
car_key_word = value;
car_load_html(car_key_word, car_company);
}
//..车辆加载
function car_load_html(key_word, company) {
var url = "./st-xm/Api/busInfoControll.php?method=getVehicleList&key_word=" + key_word + "&company=" + company;
$.getJSON(url, function(res_data) {
ZZLog('车辆' + url);
ZZLog(res_data);
var carhtml = [];
$.each(res_data.vehicle_list, function(i, v) {
var acar = mycargrid.replace(/carid|carnum|carname|carseat/g, function(match) {
switch(match) {
case "carid":
return v.res_id;
case "carnum":
return v.vihicle_number;
case "carname":
return v.vihicle_brand;
case "carseat":
return v.vihicle_seat;
};
})
carhtml.push(acar);
})
$(".carinfodata").html(carhtml);
addcarinEvent();
// addcaroutEvent();
});
}
//点击了三个固定的
function click_show_div(objName, self_obj) {
var obj = $(objName);
if (obj.css('display') == 'none') {
center_show(obj);
} else {
obj.css('display', 'none');
}
}
//点击了第二级
function click_two_show_div(father_name, self_name) {
var father = $(father_name);
var self = $(self_name);
father.css('display', 'none');
center_show(self);
}
//点击了关闭
function click_cancel(father_name, self_name) {
if (father_name) {
var father = $(father_name);
center_show(father);
} else {
$('.mask').css('display', 'none');
}
$(self_name).css('display', 'none');
}
//居中显示
var tempDiv = null;
function center_show(show_div) {
tempDiv = show_div;
//显示蒙板
show_div.css('display', 'block');
show_div.css('z-index', 10);
show_div.css('background-color', 'white');
show_div.css('position', 'fixed');
var w = show_div.css('width');
var h = show_div.css('height');
w = w.substr(0, w.length - 2);
h = h.substr(0, h.length - 2);
// var s_left=(window.screen.availWidth-w)/2 +"px";
// var s_top=(window.screen.availHeight-h)/2 +'px';
var s_left = (window.innerWidth - w) / 2 + 'px';
var s_top = (window.innerHeight - h) / 2 + 'px';
show_div.css('left', s_left);
show_div.css('top', s_top);
$('.mask').css('display', 'block');
}
//点击蒙板
function hide_all() {
$('.mask').css('display', 'none');
tempDiv.css('display', 'none');
}
//司机公司改变
var driver_key_word = '';
var driver_company = '';
function driver_company_change(value) {
driver_company = value;
driver_load_html(driver_key_word, driver_company);
}
//司机值改变
function driver_change(value) {
driver_key_word = value;
driver_load_html(driver_key_word, driver_company);
}
//..司机加载
function driver_load_html(key_word, company) {
var url = "./st-xm/Api/busInfoControll.php?method=getDriverList&&key_word=" + key_word + "&company=" + company;
$.getJSON(url, function(res_data) {
ZZLog('司机' + url);
ZZLog(res_data);
var driverhtml = [];
$.each(res_data.driver_list, function(i, v) {
var driver = mydrivergrid.replace(/driverid|drivername|drivernum|driverphone/g, function(match) {
switch(match) {
case "driverid":
return v.res_id;
case "drivername":
return v.driver_name;
case "drivernum":
return v.driver_number;
case "driverphone":
return v.driver_phone;
};
})
driverhtml.push(driver);
})
$(".driverinfodata").html(driverhtml);
adddriverinEvent();
// adddriveroutEvent();
});
}
function addcaroutEvent() {
mycarposition = getrect($(".carinfodata").get(0));
$(".all-lineinfo .acar").on("mousedown", function(e) {
e.stopPropagation();
var that = $(this);
var thathtml = $(this).outerHTML();
var myxy = addItemid("div", "acar", "onlyout", $(this).html());
$(this).addClass("opcity");
var thisxy = getPosition(this);
$('body').append(myxy);
var onlyout = document.getElementById("onlyout");
onlyout.style.position = "absolute";
onlyout.style.left = thisxy[0] + "px";
onlyout.style.top = thisxy[1] + "px";
xy = getPosition(onlyout);
mouseX = e.pageX,
mouseY = e.pageY,
delaX = mouseX - xy[0],
delaY = mouseY - xy[1];
$(document).on('mousemove', function(e) {
onlyout.style.left = (e.pageX - delaX) + 'px';
onlyout.style.top = (e.pageY - delaY) + 'px';
var x = e.pageX,
y = e.pageY;
if(exist(x, y, mycarposition)) {
$(".carinfodata").addClass("curred");
} else {
$(".carinfodata").removeClass("curred");
}
})
$(document).on("mouseup", function(e) {
var x = e.pageX,
y = e.pageY;
if(exist(x, y, mycarposition)) {
$.getJSON("st-xm/Api/busInfoControll.php?method=vehicleDispatch&bus_id=" + that.parent().parent().find("input").val() + "&res_id=" + that.children(".car-show").attr("dataid"), function(data) {
if(data.code == 0) {
ZZLog(data.info)
$("#onlyout").remove();
$(".opcity").remove();
$(".carinfodata").removeClass("curred");
$(document).unbind();
} else {
ZZLog(data.info);
$(".alinedrag").removeClass("curred");
$("#onlyout").remove();
$(".opcity").removeClass("opcity")
$(document).unbind();
}
})
} else {
$("#onlyout").remove();
$(".opcity").removeClass("opcity")
$(document).unbind();
}
})
})
}
function addcarinEvent() {
mycarposition = getrect($(".carinfodata").get(0));
myalineposition = [];
alllineposition = getrect($(".alldrag").get(0));
for(var i = 0; i < $(".alinedrag").length; i++) {
myalineposition.push(getrect($(".alinedrag").get(i)))
};
$(".carinfodata .acar").on("mousedown", function(e) {
e.stopPropagation();
var thathtml = $(this).outerHTML();
var that = $(this);
myxy = addItemid("div", "acar", "onlyin", $(this).html());
$(this).addClass("opcity");
var thisxy = getPosition1(this);
// ZZLog(typeof that);
$('body').append(myxy);
var onlyin = document.getElementById("onlyin");
onlyin.style.position = "absolute";
onlyin.style.left = thisxy[0] + "px";
onlyin.style.top = thisxy[1] + "px";
xy = getPosition(onlyin),
mouseX = e.pageX,
mouseY = e.pageY,
delaX = mouseX - xy[0],
delaY = mouseY - xy[1];
$(document).on('mousemove', function(e) {
onlyin.style.left = (e.pageX - delaX) + 'px';
onlyin.style.top = (e.pageY - delaY) + 'px';
var x = e.pageX,
y = e.pageY;
if(exist(x, y, alllineposition)) {
$(".alinedrag").removeClass("curred");
$(".alinedrag").eq(existArr(x, y, myalineposition)).addClass("curred");
} else {
$(".alinedrag").removeClass("curred");
}
});
$(document).on('mouseup', function(e) {
var x = e.pageX,
y = e.pageY;
if(exist(x, y, alllineposition)) {
var tr = $(".alinedrag").eq(existArr(x, y, myalineposition));
var id = tr.find("input").val();
var url="st-xm/Api/busInfoControll.php?method=vehicleDispatch&bus_id=" + id + "&res_id=" + that.children(".car-show").attr("dataid");
ZZLog(url);
$.getJSON(url, function(data) {
ZZLog(data);
if(data.code == "0") {
ZZLog(data.info);
tr.children(".cardrap").html(thathtml);
$(".alinedrag").removeClass("curred");
$("#onlyin").remove();
$(document).unbind();
$(".opcity").removeClass("opcity");
$(".all-lineinfo .acar").unbind();
// addcaroutEvent();
// 调派成功之后刷新当前页面
// location.replace(location.href);
refersh_cur_page();
} else {
ZZLog(data.info);
alert(data.info);
$(".alinedrag").removeClass("curred");
$("#onlyin").remove();
$(".opcity").removeClass("opcity");
$(document).unbind();
}
});
} else {
$("#onlyin").remove();
$(".opcity").removeClass("opcity");
$(document).unbind();
}
});
});
}
function adddriveroutEvent() {
mydriverposition = getrect($(".driverinfodata").get(0));
ZZLog(mydriverposition)
$(".all-lineinfo .adriver").on("mousedown", function(e) {
//ZZLog(0)
e.stopPropagation();
var that = $(this);
var thathtml = $(this).outerHTML();
var myxy = addItemid("div", "adriver", "onlyout", $(this).html());
$(this).addClass("opcity");
var thisxy = getPosition(this);
$('body').append(myxy);
var onlyout = document.getElementById("onlyout");
onlyout.style.position = "absolute";
onlyout.style.left = thisxy[0] + "px";
onlyout.style.top = thisxy[1] + "px";
xy = getPosition(onlyout);
mouseX = e.pageX,
mouseY = e.pageY,
delaX = mouseX - xy[0],
delaY = mouseY - xy[1];
$(document).on('mousemove', function(e) {
onlyout.style.left = (e.pageX - delaX) + 'px';
onlyout.style.top = (e.pageY - delaY) + 'px';
var x = e.pageX,
y = e.pageY;
if(exist(x, y, mydriverposition)) {
$(".driverinfodata").addClass("curgreen");
} else {
$(".driverinfodata").removeClass("curgreen");
}
})
$(document).on("mouseup", function(e) {
var x = e.pageX,
y = e.pageY;
if(exist(x, y, mydriverposition)) {
$.getJSON("st-xm/Api/busInfoControll.php?method=driverDispatch&bus_id=" + that.parent().parent().find("input").val() + "&res_id=" + that.children(".adriver-show").attr("dataid"), function(data) {
ZZLog(data)
if(data.code == 0) {
ZZLog(data.info);
$("#onlyout").remove();
$(".opcity").remove();
$(".driverinfodata").removeClass("curgreen");
$(document).unbind();
} else {
ZZLog(data.info)
$("#onlyout").remove();
$(".driverinfodata").removeClass("curgreen");
$(".opcity").removeClass("opcity")
$(document).unbind();
}
})
} else {
$("#onlyout").remove();
$(".opcity").removeClass("opcity")
$(document).unbind();
}
})
})
}
function adddriverinEvent() {
mydriverposition = getrect($(".driverinfodata").get(0));
myalineposition = [];
alllineposition = getrect($(".alldrag").get(0));
for(var i = 0; i < $(".alinedrag").length; i++) {
myalineposition.push(getrect($(".alinedrag").get(i)))
};
$(".driverinfodata .adriver").on("mousedown", function(e) {
e.stopPropagation();
var that = $(this);
var thathtml = $(this).outerHTML(),
myxy = addItemid("div", "adriver", "onlyin", $(this).html());
$(this).addClass("opcity");
var thisxy = getPosition1(this);
ZZLog(typeof that);
$('body').append(myxy);
var onlyin = document.getElementById("onlyin");
onlyin.style.position = "absolute";
onlyin.style.left = thisxy[0] + "px";
onlyin.style.top = thisxy[1] + "px";
xy = getPosition(onlyin),
mouseX = e.pageX,
mouseY = e.pageY,
delaX = mouseX - xy[0],
delaY = mouseY - xy[1];
$(document).on('mousemove', function(e) {
onlyin.style.left = (e.pageX - delaX) + 'px';
onlyin.style.top = (e.pageY - delaY) + 'px';
var x = e.pageX,
y = e.pageY;
if(exist(x, y, alllineposition)) {
$(".alinedrag").removeClass("curgreen");
$(".alinedrag").eq(existArr(x, y, myalineposition)).addClass("curgreen");
} else {
$(".alinedrag").removeClass("curgreen");
}
});
$(document).on('mouseup', function(e) {
var x = e.pageX,
y = e.pageY;
if(exist(x, y, alllineposition)) {
var tr = $(".alinedrag").eq(existArr(x, y, myalineposition));
var id = tr.find("input").val();
var url2="st-xm/Api/busInfoControll.php?method=driverDispatch&bus_id=" + id + "&res_id=" + that.children(".adriver-show").attr("dataid");
ZZLog(url2);
$.getJSON(url2, function(data) {
if(data.code == 0) {
ZZLog(data.info)
tr.children(".driverdrap").html(thathtml);
$(".alinedrag").removeClass("curgreen");
$(".opcity").removeClass("opcity");
$("#onlyin").remove();
$(document).unbind();
$(".all-lineinfo .adriver").unbind();
// adddriveroutEvent();
} else {
ZZLog(data.info)
alert(data.info);
$(".alinedrag").removeClass("curgreen");
$("#onlyin").remove();
$(".opcity").removeClass("opcity");
$(document).unbind();
}
});
} else {
$("#onlyin").remove();
$(".opcity").removeClass("opcity");
$(document).unbind();
}
});
});
}
function existArr(x, y, area) {
for(var i = 0; i < area.length; i++) {
if(x > area[i][0] && x < area[i][2] && y > area[i][1] && y < area[i][3]) {
return i
}
}
}
function exist(x, y, area) {
if(x > area[0] && x < area[2] && y > area[1] && y < area[3]) {
return true
} else {
return false
}
}
function getrect(dom) {
var rect = [];
that = dom,
one = getPosition(dom);
rect.push(one[0], one[1], one[0] + dom.offsetWidth, one[1] + dom.offsetHeight);
return rect
}
function getPosition(obj) {
//ZZLog($(obj));
var topValue = 0,
leftValue = 0;
var finalvalue = [];
while(obj) {
leftValue += obj.offsetLeft;
topValue += obj.offsetTop;
obj = obj.offsetParent;
}
finalvalue.push(leftValue, topValue);
return finalvalue;
}
function getPosition1(obj) {
ZZLog();
//var topValue = 0,
// leftValue = 0;
//var finalvalue = [];
// while (obj) {
// leftValue += obj.offsetLeft;
// topValue += obj.offsetTop;
// obj = obj.offsetParent;
// }
// finalvalue.push(leftValue, topValue);
return [$(obj).offset().left, $(obj).offset().top];
}
function position(x, y, area) {
for(var i = 0; i < area.length; i++) {
if(x > area[i][0] && x < area[i][2] && y > area[i][1] && y < area[i][3]) {
ZZLog(x + "," + y + "," + area[i])
return true;
} else {
ZZLog(x + "," + y + "," + area[i])
return false;
}
}
}
function addItem(label, classname, cent) {
var html = ['<' + label + ' class="' + classname + '">'];
html.push(cent);
html.push('' + label + '>');
return html.join("")
}
function addItemid(label, classname, id, cent) {
var html = ['<' + label + ' class="' + classname + '" id=' + id + '>'];
html.push(cent);
html.push('' + label + '>');
return html.join("")
}
jQuery.fn.outerHTML = function(s) {
return(s) ? this.before(s).remove() : $("").append(this.eq(0).clone()).html();
}
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 d = getDateTime(0);
d = new Date(d);
d = +d - 1000*60*60*24;
d = new Date(d);
//return d;
//格式化
var year = ";" + d.getFullYear() + ";";
var month = ";" + (d.getMonth()+0+1) + ";";
var day = ";" + d.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 d=getDateTime(0);
d = new Date(d);
d = +d + 1000*60*60*24;
d = new Date(d);
//return d;
//格式化
var year = ";" + d.getFullYear() + ";";
var month = ";" + (d.getMonth()+0+1) + ";";
var day = ";" + d.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;
}
//add by qiusong on 2017.09.25
function disp_run_bus_passenger( run_id, bus_order_id ) {
$.ajax({
url: './st-xm/Api/run_bus_passengers_static.php',
type: "post",
data: {
run_id: run_id,
bus_order_id: bus_order_id
},
dataType: "json",
success: function (data) {
if (data.code == 0) {
var disp_table_html = '站点 | 上车 | 下车 |
';
for(var i = 0; i < data.data.length; i++) {
disp_table_html += '' + data.data[i].RES_NAME + ' | ' + data.data[i].up_num + ' | ' + data.data[i].down_num + ' |
';
}
disp_table_html += '
';
swal({
title: '上下车信息',
type: 'info',
html: disp_table_html,
showCloseButton: true
});
return;
} else {
swal(
'获取信息失败',
data.info,
'error'
);
return;
}
},
fail: function (data) {
swal(
'获取信息失败',
data.info,
'error'
);
return;
}
});
}