var plNos = []; (function () { var mydate = new Date(); var year = mydate.getFullYear(); //获取当前年份(2位) $("#timeinStartDate").val( moment().subtract('days', 2).format('YYYY-MM-DD hh:mm')); $("#timeinEndDate").val( moment().subtract('days', 0).format('YYYY-MM-DD hh:mm')); $("#timeinStartDate").datetimepicker({ endDate: moment(year+'-12-29').subtract('seconds', 0).format('YYYY-MM-DD hh:mm'), format: 'yyyy-mm-dd hh:ii', minView: 0, minuteStep:1, autoclose: true, forceParse: false, locale: "zh-CN", language: 'zh-CN', pickerPosition: "bottom-left" }).on("changeDate", function (ev) { var startval = moment($("#timeinStartDate").val()).add('days', 0).format('YYYY-MM-DD HH:mm'); var val = moment($("#timeinStartDate").val()).add('days', 2).format('YYYY-MM-DD HH:mm'); // console.log(startval+ ' '+val) $("#timeinEndDate").datetimepicker("setStartDate", startval); $("#timeinEndDate").datetimepicker("setEndDate", val); $("#timeinEndDate").val(val) $('#timeinEndDate').datetimepicker('update'); $("#timeinEndDate").datetimepicker({ format: 'yyyy-MM-dd hh:ii', autoclose: true, forceParse: false, locale: "zh-CN", language: 'zh-CN', pickerPosition: "bottom-left" }); });; $("#timeinEndDate").datetimepicker({ startDate: moment().subtract('days', 2).format('YYYY-MM-DD hh:mm'), endDate: moment().subtract('days', 0).format('YYYY-MM-DD hh:mm'), format: 'yyyy-mm-dd hh:ii', autoclose: true, forceParse: false, minView: 0, minuteStep:1, locale: "zh-CN", language: 'zh-CN', pickerPosition: "bottom-left" }); $('#echart_con').css('width',$(window).width()-245+'px'); var myChart = echarts.init(document.getElementById('echart_con')); //条件查询 $(document).on('click', '#queryBtn', function() { if(!fun.validateParams()){ return; }; fun.initTable(); }); var fun = { //初始下拉框 init:function () { //初始化停车场下拉框 fun.initPark(); //初始化车辆类型下拉框 fn.getCarType(fun.setCarTypeSelect); /*if(!fun.validateParams()){ return; };*/ //ajax 下拉框和出场类型后 请求table表格和图例 //fun.initEcharts(); }, validateParams: function(){ var carNo = $("#carNo").val().trim(); if(!/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/.test(carNo)||carNo.length<7) { swal({title:"提示",text:"请输入正确的车牌号!",type:"warning",timer:3000,allowOutsideClick:true}); return false; } var plNosTemp = $("#parkIds").val(); if(plNosTemp == "" || plNosTemp == null){ swal({title:"提示",text:"停车场必选!",type:"warning",timer:3000,allowOutsideClick:true}); return false; } var carType = $("#carType").val(); if(carType == "" || carType == null){ swal({title:"提示",text:"车辆类型必选!",type:"warning",timer:3000,allowOutsideClick:true}); return false; } var inTime = $("#timeinStartDate").val(); if(inTime == "" || inTime == null){ swal({title:"提示",text:"进场时间必选!",type:"warning",timer:3000,allowOutsideClick:true}); return false; } var outTime = $("#timeinEndDate").val(); if(outTime == "" || outTime == null){ swal({title:"提示",text:"出场时间必选!",type:"warning",timer:3000,allowOutsideClick:true}); return false; } return true; }, //初始化停车场下拉框 initPark: function () { var data = fn.getParkLot(); $("#parkIds").empty(); var html = ''; plNos = []; for (var i = 0; i < data.length; i++) { plNos.push(data[i].code); html += ""; } // var plnosStr = JSON.stringify(plNos); // html = '' + html; $("#parkIds").append(html); $('#parkIds').selectpicker('render'); $('#parkIds').trigger('change'); }, //设置车辆类型下拉框 setCarTypeSelect: function (datas) { $('#carType').empty(); var html = ''; $.each(datas, function (index, data) { html += ""; }) //html = '' + html; $('#carType').append(html); $('#carType').selectpicker('refresh'); fun.initTable(); }, initBilling:function(data){ //load parkFee var divs = $(".col_right_li_mon"); //费用 var totalFee = (data.parkFee/100).toFixed(2)+""; var frontFee = totalFee.substring(0,totalFee.length-3); var afterFee = totalFee.substring(totalFee.length-3,totalFee.length); divs.eq(0).find("span").eq(0).text(frontFee); divs.eq(0).find("span").eq(1).text(afterFee+" 元"); //停车时长 var second = parseInt(data.parkDuration); var duration = formatSeconds(second); var patrn = /\d+(\.\d+)?/g; var nums = duration.match(patrn); divs.eq(1).find("span").eq(0).text(nums[0]); divs.eq(1).find("span").eq(1).text(duration.substr(nums[0].length,duration.length)); //车牌号 divs.eq(2).text(data.carNo); //停车场 var parkName = $("#parkIds").find("option:selected").text(); divs.eq(3).text(parkName); $(".col_right_li_mon_ellipsis").attr("title",parkName); var billingLogId = data.billingLogId; fun.initEcharts(billingLogId); }, initTable:function () { var plNosTemp = $("#parkIds").val(); plNos = JSON.parse(plNosTemp); var inTime = $("#timeinStartDate").val()+':00'; var outTime = $("#timeinEndDate").val()+':00'; var carType = $("#carType").val(); var carNo = $("#carNo").val().trim(); var req = { sysCode: sysComm.sysCode, plNo: plNos[0], carType:carType, carNo:carNo, inTime:new Date(inTime.replace(new RegExp(/-/gm) ,"/")), outTime:new Date(outTime.replace(new RegExp(/-/gm) ,"/")), isShowLog:1 }; var opt = { method: 'post', url: dataUrl.util.queryBillingRuleByPlNoAndCarType(), data: JSON.stringify(req), contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (res) { if (res.code=='8888') { if(res.data.length>0){ fun.loadTable(res.data); } } else{ swal({title:"提示",text:res.msg,type:"warning",timer:3000,allowOutsideClick:true}); return ; } } }; sysAjax(opt); var opt2 = { method: 'post', url: dataUrl.util.billing(), data: JSON.stringify(req), contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (res) { if (res.code=='8888') { fun.initBilling(res.data); } else{ swal({title:"提示",text:res.msg,type:"warning",timer:3000,allowOutsideClick:true}); return ; } } }; sysAjax(opt2); }, loadTable:function(data){ //load ruleTable var ruleTable = $("#ruleTable"); var tableHead = '' +'' +' 车型 ' +' 适用日期 ' +' 单日限价 ' +' 单次限价 ' +' 单次免费时长 ' +' 跨时间段规则 ' +'' +''; var tableBody = ''; $.each(data, function (index, item) { var fristFreeTime = item.fristFreeTime/60; if(fristFreeTime<=0){ fristFreeTime = '不限'; } tableBody += '' +' '+fun.carTypeFormatter(item.carType) +' ' +' '+fun.applyDateTypeFormatter(item.applyDateType) +' ' +' '+fun.chargeFormatter(item.dayMaxCharge) +' ' +' '+fun.chargeFormatter(item.maxCharge) +' ' +' '+fristFreeTime +' 分钟' +' '+fun.crossTimeRuleTypeFormatter(item.crossTimeRuleType) +' ' +''; }); tableBody+=''; ruleTable.html(tableHead+tableBody); //load ruleDetailTable var ruleDetailTable = $("#ruleDetailTable"); var tableHead = '' +'' +' 开始时间' +' 结束时间 ' +' 时长限制 ' +' 计费类型 ' +' 费率 ' +' 单位免费时长 ' +'' +''; var tableBody = ''; var num = 1; $.each(data, function (index, item) { for(var i=0;i<(item.billingRuleConfigs).length;i++){ var unitFreeTime = item.billingRuleConfigs[i].unitFreeTime/60; if(unitFreeTime<=0){ unitFreeTime = '不限'; }else{ unitFreeTime += '分钟'; } tableBody += '' +' '+fun.timeFormatter(item.billingRuleConfigs[i].startTime) +' ' +' '+fun.timeFormatter(item.billingRuleConfigs[i].endTime) +' ' +' '+(fun.formatterSecondToHour(item.billingRuleConfigs[i].startBillingTime))+'-'+(fun.formatterSecondToHour(item.billingRuleConfigs[i].endBillingTime)) +'小时 ' +' '+fun.billingConfigTypeFormatter(item.billingRuleConfigs[i].billingConfigType) +' ' +' '+fun.chargeFormatter(item.billingRuleConfigs[i].unitRate)+'/'+fun.unitFormatter(item.billingRuleConfigs[i].unit) +' ' +' '+unitFreeTime+'' +''; } }); tableBody+=''; ruleDetailTable.html(tableHead+tableBody); }, formatterSecondToHour:function(value){ if(value == null){ return ""; } return value/60/60; }, timeFormatter: function (value) { if (value == null) { return ""; } else { return DateUtils.long2String(value, 3); } }, dateFormatter: function (value) { if (value == null) { return ""; } else { return DateUtils.long2String(value, 1); } }, billingConfigTypeFormatter:function(value){ var result=""; if (value == null ) { return "-"; } switch (value) { case 1: result = '按时'; break; case 2: result = '按次'; break; default: result = '未知'; } return result; }, unitFormatter:function(value){ var result=""; if (value == null ) { return "-"; } switch (value) { case 1: result = '分钟'; break; case 2: result = '15分钟'; break; case 3: result = '30分钟'; break; case 4: result = '60分钟'; break; case 5: result = '次'; break; default: result = '未知'; } return result; }, carTypeFormatter:function(value){ var result=""; if (value == null ) { return "-"; } switch (value) { case 1: result = '大型车'; break; case 2: result = '小型车'; break; default: result = '未知'; } return result; }, applyDateTypeFormatter:function(value){ var result=""; if (value == null ) { return "-"; } switch (value) { case -1: result = '不限'; break; case 1: result = '工作日'; break; case 2: result = '非工作日'; break; default: result = '未知'; } return result; }, //分-元 chargeFormatter:function(value){ if (value == null||value<0 ) { return "不限"; } return (value/100).toFixed(2)+"元"; }, //分-元(不带单位) feeFormatter:function(value){ if (value == null ) { return 0; } return (value/100).toFixed(2); }, //跨时间段规则类型 crossTimeRuleTypeFormatter:function(value){ var result=""; if (value == null ) { return "-"; } switch (value) { case 1: result = '前置匹配'; break; case 2: result = '后置匹配'; break; case 3: result = '完全匹配'; break; default: result = '未知'; } return result; }, initEcharts:function (billingLogId) { // 指定图表的配置项和数据 var option = { color:['#1890FF','#5fe98f','#fdc94d'], tooltip: { // trigger: 'item', // formatter: function (params) { // return '我的'+params.seriesName+':'+params.value+'元'; // } trigger: 'axis' }, legend: { left: 'center', y:'bottom', data: ['停车费用'] }, xAxis: { type: 'category', axisLabel: { interval: 0, rotate:30,//倾斜度 -90 至 90 默认为0 show: true, textStyle: { color: 'rgba(0,0,0,0.5)', fontSize:'12px', fontFamily:'微软雅黑' } }, // splitNumber:10, // minInterval:2, axisTick: { show: false, }, splitLine:{ lineStyle:{ color:'rgba(0,0,0,0.1)', } }, axisLine: { show: true, lineStyle: { color: 'rgba(0,0,0,0.1)', // width: 1,//这里是为了突出显示加上的 } }, data: ['2017-10-10', '2017-10-10', '2017-10-10', '2017-10-10', '2017-10-10', '2017-10-10', '2017-10-10', '2017-10-10', '2017-10-10'] }, grid: { x: '1%', right: '4%', y2: '30%', y:'2%', containLabel: true }, yAxis: { type: 'value', axisLabel: { show: true, textStyle: { color: 'rgba(0,0,0,0.5)', fontSize:'12px', fontFamily:'微软雅黑' } }, axisTick: { show: false, }, splitLine:{ lineStyle:{ color:'rgba(0,0,0,0.1)', } }, axisLine: { show: true, lineStyle: { color: 'rgba(0,0,0,0.1)', // width: 1,//这里是为了突出显示加上的 } }, }, series: [ { name: '停车费用', type: 'line', data: [11, 32, 91, 27, 81, 247, 41, 51,61], markPoint:{ symbolSize :13, itemStyle:{ normal:{ color:'#ff0202' } }, data:[] } } ] }; // 使用刚指定的配置项和数据显示图表。 //myChart.setOption(option); //费用计算明细ajax请求函数 fun.feeDetailAjax(option, myChart,billingLogId); }, feeDetailAjax:function(option,myChart,billingLogId){ // billingLogId = 'fa8d84e6ec88456ca096cbbca0a94a5a'; if(billingLogId==null || billingLogId == ""){ return; } var req = { sysCode: sysComm.sysCode, id:billingLogId }; var opt = { method: 'post', async: false, url: dataUrl.util.queryBillingLogForLineChart(), data: JSON.stringify(req), contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (res) { if (res.code=='8888') { //fun.loadTable(res.data); if(res.data.length<1){ return; } var dates = []; var realFeeOfDays = []; var points=[]; $.each(res.data.feeRecordChart,function(index,item){ dates.push(item.xName); realFeeOfDays.push(item.yFee); }); $.each(res.data.pointMarkBeans,function(index,item){ points.push(item); }); option.xAxis.data = dates; option.series[0].data = realFeeOfDays; option.series[0].markPoint.data =points; } else{ swal({title:"提示",text:res.msg,type:"warning",timer:3000,allowOutsideClick:true}); return ; } } }; sysAjax(opt); myChart.setOption(option,true); myChart.resize(); } }; fun.init(); window.onresize = function () { $('#echart_con').css('width',$(window).width()-245+'px'); myChart.resize(); } })(); function formatSeconds(value) { var theTime = parseInt(value);// 秒 var theTime1 = 0;// 分 var theTime2 = 0;// 小时 var theTime3 = 0;//天 // alert(theTime); if(theTime<60){ return theTime+'秒'; } if (theTime >= 60) { theTime1 = parseInt(theTime / 60); theTime = parseInt(theTime % 60); // alert(theTime1+"-"+theTime); if (theTime1 >= 60) { theTime2 = parseInt(theTime1 / 60); theTime1 = parseInt(theTime1 % 60); if(theTime2 >= 24){ theTime3 = parseInt(theTime2/24); theTime2 = parseInt(theTime2%24); } } } var result = ''; if (theTime1 > 0) { result = "" + parseInt(theTime1) + "分钟" + result; } if (theTime2 > 0) { result = "" + parseInt(theTime2) + "小时" + result; } if (theTime3 > 0) { result = "" + parseInt(theTime3) + "天" + result; } return result; }; //隐藏显示 查询条件 搜索框 hide-common-style documentBindFunc.on('click',".ITD-search-morebtn",function(){ $(".hide-common-style").toggleClass("display-none"); });