mileageMapModal.vue 11.9 KB
<template>
	<v-layout>
		<template slot="breadcrumb">
			<el-breadcrumb-item>统计报表</el-breadcrumb-item>
			<el-breadcrumb-item>里程详情</el-breadcrumb-item>
			<div class="box" style="width:100%;">
				<div class="right" style="float:right;width:60px;">
				    <el-tooltip class="item" effect="dark"  placement="right-start">
				    	<div slot="content">有源设备来判断停驶<br/>"近2天停驶"定义有源设备12<X≤48小时速度等于0;<br/>"近7天停驶"定义有源设备12<X≤168小时速度等于0;<br/>"超长停驶"定义有源设备>168小时速度等于0;</div>
				      <el-button style="border:0px;" icon="el-icon-question"></el-button>
				    </el-tooltip>
				</div>    
			</div>
			<p style="font-weight:bold; padding-top: 10px;font-size:20px;">里程详情</p>
			<p>用于展示用户的基本信息和行程信息</p>
		</template>
		<template slot="main">
			<div class="ibox ibox-search">
				<!-- 表单查询 -->

				<el-form :inline="true" ref="form" :model="form" >
					<el-form-item >
						<el-button-group >
							<el-button size="small" :type="timeRange==-1?'primary':''" @click="timeRange=-1">
						  		全部
							</el-button>
						  	<el-button size="small" :type="timeRange==1?'primary':''" @click="timeRange=1">
						  		昨日
						  	</el-button>
							<el-button size="small" :type="timeRange==7?'primary':''" @click="timeRange=7">
								本周
							</el-button>
						  	<el-button size="small" :type="timeRange==-7?'primary':''" @click="timeRange=-7">	上周
						  	</el-button>
						  	<el-button size="small" :type="timeRange==30?'primary':''" @click="timeRange=30">	本月
						  	</el-button>
						  	<el-button size="small" :type="timeRange==-30?'primary':''" @click="timeRange=-30">	上月
						  	</el-button>
						</el-button-group >  
					</el-form-item>		
					<el-form-item prop="dateRange">
						<el-date-picker
							v-model="form.dateRange"
							value-format="yyyy-MM-dd"
							size="small"
					      	type="daterange"
					      	range-separator="至"
					      	start-placeholder="开始日期"
					      	end-placeholder="结束日期">
					    </el-date-picker>
					</el-form-item>					
					
					<el-form-item prop="queryTerm">
						<el-input placeholder="请输入对应条件值" v-model="form.queryTerm" size="small" class="input-with-select" clearable>
						    <el-select v-model="form.queryType" slot="prepend" style="width:100px;" placeholder="请选择" size="small">
						      <el-option label="设备号" value="1"></el-option>
						    </el-select>
						</el-input>
					</el-form-item>		
					
					<el-form-item>
					    <el-button type="primary" @click="onSubmit" size="small">查询</el-button>
					</el-form-item>
					<el-form-item>
					    <el-button type="primary" @click="resetForm('form')" size="small">重置</el-button>
					</el-form-item>
				</el-form>
				<!-- 表单查询 /-->
            </div>
            <div class="ibox">
            	<div class="ibox-title">
            		<el-button type="primary" plain size="small" class="pull-right ibox-ctrl" @click="exportExcel">导出excel&nbsp;<i class="fa fa-download"></i></el-button>
            	</div>
            	<div class="ibox-content">
            		<el-table
					    :data="tableData"
					    border
					    size="small"
					    v-loading="loading"
					    style="width: 100%">	<!-- @selection-change="selectChange"> -->

					  <!--  <el-table-column type="selection" width="40" align="center"></el-table-column> -->
						<el-table-column fixed type="index" label="序号" :index="getIndex" align="center" width="70"></el-table-column>
						<el-table-column fixed prop="sqbh" label="工单号" min-width="160" align="center"></el-table-column>
						<el-table-column fixed prop="name" label="姓名" min-width="160" align="center"></el-table-column>
						<el-table-column prop="sn" label="设备号" min-width="100" align="center"></el-table-column>
						<el-table-column fixed prop="standno" label="车架号" min-width="180" align="center"></el-table-column>
						<el-table-column prop="begintime" label="行驶开始时间" min-width="160" align="center"></el-table-column>
						<el-table-column prop="endtime" label="行驶结束时间" min-width="160" align="center"></el-table-column>
						<el-table-column prop="durationFormat" label="行驶时长" min-width="160" align="center"></el-table-column>
						<el-table-column prop="distance" label="行驶里程(km)" min-width="100" align="center"></el-table-column>
						<el-table-column fixed="right"  label="操作" min-width="160" align="center">
							<template slot-scope="scope">
								<el-button @click="gotoMonitor(scope.row)" type="text" size="medium">查看轨迹</el-button>
							</template>
						</el-table-column>

					</el-table>
					<div class="table-page-wrap">
					    <el-pagination
					      @size-change="handleSizeChange"
					      @current-change="handleCurrentChange"
					      :current-page="currentPage"
					      :page-sizes="[10, 20, 30, 40]"
					      :page-size="pageSize"
					      layout="total, sizes, prev, pager, next, jumper"
					      :total="total">
					    </el-pagination>
					</div>
            	</div>
            	<div class="ibox-content" style="height: 300px; padding: 20px">
            		<div class="ibox-title">
            			<h3 class="pull-left">趋势图</h3>
            		
            		</div>
	                <canvas id="mileageFlowChart"></canvas>
	            </div>
            </div>
		</template>
	</v-layout>
</template>
<script>
import Chart from 'chart.js/dist/Chart.min.js';
import vDateRange from 'components/DateRange.vue'
const vVechicleSelect = () => import(/* webpackChunkName: "vVechicleSelect" */ 'components/VechicleSelect.vue');
import {exportExcel} from 'utils'
import {services} from '../../api'

import mileageChart from './mileageChart.js';

const REPORT_SERVICE =  services.report;
export default{
	data(){
		return {
			loading: true,
			currentPage: 1,
			pageSize: 10,
			total: 0,
			tableData: [],
			chart: null,
			timeRange:-1,
			activePeriod:2,
			chartId:'mileageFlowChart',
			newVal:null,
			form: {
				dateRange: [],
		        queryType: '1',
		        queryTerm: ''
			},
			selectedIds: []
		}
	},
	created(){
		this.getData();
		this.draw();
	},
	methods: {
		getIndex(index){
			return (this.currentPage-1)*this.pageSize+index+1;
		},
		getData(curr=this.currentPage, size=this.pageSize){
			this.loading = true;
			let params = this.getParams();
			if(params.sn){
				params.sn = params.sn
			}else{
				params.sn = this.$route.query.sn;

			}
			if(!params.timeBegin){
				if(this.newVal){
					params.timeRange = this.newVal
				}else if(this.$route.query.timeRange){
					params.timeRange = this.$route.query.timeRange
					this.timeRange = this.$route.query.timeRange
				}else{
					params.timeRange = this.timeRange;
				} 

			}
			
			
			params.currentPage = curr;
			params.pageSize = size;
			/*if(){
				params.timeRange = this.timeRange;
			}*/
			REPORT_SERVICE.journeysDetailTotal(params).then((response)=>{
				if(Array.isArray(response.data)){
					this.tableData = response.data;
					this.total = response.recordsTotal;
				}else{
					this.tableData = [];
					this.total = 0;
				}
				this.loading = false;
			});
			
		},
		createChart(chartId, chartData) {
			this.chart && this.chart.destroy();
			
		    const ctx = document.getElementById(chartId);
		    
		    this.chart = new Chart(ctx, {
		      type: chartData.type,
		      data: chartData.data,
		      options: chartData.options
		    });
		},
		draw(){
			let getParam = this.getParams();
			if(getParam.sn){
				getParam.sn = getParam.sn
			}else{
				getParam.sn = this.$route.query.sn;

			}
			if(!getParam.timeBegin){
				if(this.newVal){
					getParam.timeRange = this.newVal
				}else if(this.$route.query.timeRange){
					getParam.timeRange = this.$route.query.timeRange
					this.timeRange = this.$route.query.timeRange
				}else{
					getParam.timeRange = this.timeRange;
				} 

			}
			REPORT_SERVICE.getGraphic(getParam).then((response)=>{
			  	if(response.returnCode == 0){
			  		const labelArr = [];
					const dataArr = [];
				
			  		response.data.forEach((obj)=>{
			  			labelArr.push(obj.date);
		  				dataArr.push(obj.journey); 
			  		});

			  		mileageChart.data.labels = labelArr;
			  		mileageChart.data.datasets[0].data = dataArr;
			  		
			  		this.createChart(this.chartId, mileageChart);
			  	}
			});
		},
		resetForm(formName) {
        	this.$refs[formName].resetFields();
        	this.timeRange=-1;
        	
		},
		getParams(){
			const form = this.form;
			const params = {};
			/*if(form.sTime){
				params.sTime = moment(form.sTime).startOf('day').format('YYYY-MM-DD HH:mm:ss');
			}
			if(form.eTime){
				params.eTime = moment(form.eTime).endOf('day').format('YYYY-MM-DD HH:mm:ss');
			}*/
			if(form.dateRange && form.dateRange.length){
				params.timeBegin = moment(form.dateRange[0]).format('YYYY-MM-DD HH:mm:ss');
				params.timeEnd = moment(form.dateRange[1]).format('YYYY-MM-DD 23:59:59');
			}
			if(form.equipmentType){
				params.equipmentType = form.equipmentType;
			}
			if(form.connectionType){
				params.connectionType = form.connectionType;
			}
			if(form.groupId){
				params.groupId = form.groupId;
			}
			if(form.classIdList){
				params.classIdList = form.classIdList;
			}
			const queryTerm = form.queryTerm.trim();
			if(queryTerm){
				switch(form.queryType){
					case '1':
						params.sn = queryTerm;
						break;
					case '2':
						params.standNo = queryTerm;
						break;	
					case '3':
						params.name = queryTerm;
						break;	
					case '4':
						params.workOrderNo = queryTerm;
						break;				
				}
			}
			
			if(params.sn){
				params.sn = params.sn
			}else{
				params.sn = this.$route.query.sn;

			}
			return params;
		},
		gotoMonitor(row){
      		/*let snO = {
      			name: row.name,
      			standNo: row.standno,
      			sn: row.sn,
      			begintime:row.begintime,
      		}
      		//this.$router.push({ name: 'monitor', params: { snArr: [snO], mode: 'replay' }})
      		let routeData = this.$router.resolve({ path: '/monitor/monitor', query: { snArr: JSON.stringify([snO]), mode: 'replay' }});
			window.open(routeData.href, '_blank');*/
			window.open(`#/monitor/replay?sn=${row.sn}&name=${row.name}&standno=${row.standno}&begintime=${row.begintime}&endtime=${row.endtime}`)
    },
		/*dateRangeChange(dateArr){console.log(dateArr)
			if(dateArr && dateArr.length){
				this.form.sTime = dateArr[0].format('YYYY-MM-DD HH:mm:ss');
				this.form.eTime = dateArr[1].format('YYYY-MM-DD HH:mm:ss');
			}else{
				this.form.sTime = '';
				this.form.eTime = '';
			}
		},*/
		/*selectChange(selection){
			this.selectedIds = [];
			selection.map((obj)=>{
				this.selectedIds.push(obj.id)
			});
			
		},*/
		vechicleChange(groupId, classId){
			this.form.groupId = groupId;
			this.form.classIdList = classId;
		},
		handleSizeChange(val) {
	      	this.pageSize = val;
	        this.getData(this.currentPage,this.pageSize)
	    },
      	handleCurrentChange(val) {
      		this.currentPage = val;
        	this.getData(val)
      	},
      	onSubmit(){
      		this.currentPage = 1;
      		this.pageSize = 10;
      		this.getData();
      		this.draw();
      	},
      	exportExcel(){
      		let params = this.getParams()
      		const url = 'report/journeys/detail/export';
      		if(!params.timeBegin){
				if(this.newVal){
					params.timeRange = this.newVal
				}else if(this.$route.query.timeRange){
					params.timeRange = this.$route.query.timeRange
					this.timeRange = this.$route.query.timeRange
				}else{
					params.timeRange = this.timeRange;
				} 

			}
      		if(this.tableData==""){
				return;
			}else{
				/*if(this.selectedIds.length){
	      			params.idList = this.selectedIds.join(',')
	      			exportExcel(url, params)
	      		}else{*/
	      			exportExcel(url, params)
	      		//}
			}
      		
      	}
    },
    watch: {
		timeRange(newVal){	
			this.newVal = newVal
		},
		
	},
	components:{
		vDateRange,
		vVechicleSelect
	}
}
</script>
<style lang="scss">
	
</style>