analogbilling.js 22.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
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 += "<option value='[\"" + data[i].code + "\"]'>" + data[i].name + "</option>";
            }
//          var plnosStr = JSON.stringify(plNos);
//          html = '<option value=' + plnosStr + ' selected>全部</option>' + html;
            $("#parkIds").append(html);
            $('#parkIds').selectpicker('render');
            $('#parkIds').trigger('change');
        },
        //设置车辆类型下拉框
	    setCarTypeSelect: function (datas) {
	        $('#carType').empty();
	        var html = '';
	
	        $.each(datas, function (index, data) {
	            html += "<option value='" + data.codeValue + "'>" + data.codeValueName + "</option>";
	        })
	
	        //html = '<option value="" selected >全部</option>' + 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 = '<thead>'
                                    +'<tr>'
                                        +'<th> 车型 </th>'
                                        +'<th> 适用日期 </th>'
                                        +'<th> 单日限价 </th>'
                                        +'<th> 单次限价 </th>'
                                        +'<th> 单次免费时长 </th>'
                                        +'<th> 跨时间段规则 </th>'
                                    +'</tr>'
                                    +'</thead>';
            var tableBody = '<tbody>';
        	$.each(data, function (index, item) {
        	    var fristFreeTime = item.fristFreeTime/60;
        	    if(fristFreeTime<=0){
                    fristFreeTime = '不限';
                }
                tableBody += '<tr>'
                                        +'<td> '+fun.carTypeFormatter(item.carType) +' </td>'
                                        +'<td> '+fun.applyDateTypeFormatter(item.applyDateType) +' </td>'
                                        +'<td> '+fun.chargeFormatter(item.dayMaxCharge) +' </td>'
                                        +'<td> '+fun.chargeFormatter(item.maxCharge) +' </td>'
                                        +'<td> '+fristFreeTime +' 分钟</td>'
                                        +'<td> '+fun.crossTimeRuleTypeFormatter(item.crossTimeRuleType) +' </td>'
                                    +'</tr>';
            });
            tableBody+='</tbody>';
            ruleTable.html(tableHead+tableBody);
        	//load  ruleDetailTable
        	var ruleDetailTable = $("#ruleDetailTable");
        	var tableHead = '<thead>'
                                    +'<tr>'
                                        +'<th> 开始时间</th>'
                                        +'<th> 结束时间 </th>'
                                        +'<th> 时长限制 </th>'
                                        +'<th> 计费类型 </th>'
                                        +'<th> 费率 </th>'
                                        +'<th> 单位免费时长 </th>'
                                    +'</tr>'
                                    +'</thead>';
            var tableBody = '<tbody>';
            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 += '<tr>'
                                        +'<td> '+fun.timeFormatter(item.billingRuleConfigs[i].startTime) +' </td>'
                                        +'<td> '+fun.timeFormatter(item.billingRuleConfigs[i].endTime) +' </td>'
                                        +'<td> '+(fun.formatterSecondToHour(item.billingRuleConfigs[i].startBillingTime))+'-'+(fun.formatterSecondToHour(item.billingRuleConfigs[i].endBillingTime)) +'小时 </td>'
                                        +'<td> '+fun.billingConfigTypeFormatter(item.billingRuleConfigs[i].billingConfigType) +' </td>'
                                        +'<td> '+fun.chargeFormatter(item.billingRuleConfigs[i].unitRate)+'/'+fun.unitFormatter(item.billingRuleConfigs[i].unit) +' </td>'
                                        +'<td> '+unitFreeTime+'</td>'
                                    +'</tr>';
        		}
                
            });
            tableBody+='</tbody>';
            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");
});