speedAlarm.vue 12.4 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/><br/>
				    		默认为15s<br/><br/>
				    		超速开始时间:<br/><br/>
				    		当连续两个上点的速度>=90km/h时,取第一个上点的上点时间作为该段超速记录的超速开始时间<br/><br/>
				    		超速结束时间:<br/><br/>
				    		当连续两个上点的速度<=90km/h时,取第一个上点的上点时间作为该段超速记录的超速结束时间<br/><br/>
				    		平均车速:<br/><br/>
				    		即超速区间内的平均时速;平均车速 = 超速区间内所有上点的速度之和÷上点数<br/><br/>
				    	</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" style="padding: 0">
				<!-- 表单查询 -->
				<el-form :inline="true" ref="form" :model="form" >
					<div style="width: 100%; border-bottom: 1px solid #e7eaec;">
						<div class="ibox-title" style="padding-bottom: 0">							
	            			<h3 class="pull-left" style="margin-top:5px;margin-left:20px;padding:18px;border-bottom: 2px solid #094;">昨日报警</h3>
		            		<el-form-item class="pull-right ibox-ctrl" style="margin-bottom:0 ">
								<el-input placeholder="工单/车架/姓名" v-model="form.queryOnlyTerm" size="small" class="input-with-select " >
								    <el-select v-model="form.queryOnlyType" slot="prepend" style="width:100px;" placeholder="请选择" size="small">
								      <el-option label="设备号" value="1"></el-option>
								      <el-option label="车架号" value="2"></el-option>
								      <el-option label="姓名" value="3"></el-option>
								      <el-option label="工单号" value="4"></el-option>
								    </el-select>
								    <el-button :loading="form.isSearching"  slot="append" icon="el-icon-search" @click="searchSubmit()" ><!-- @click="onJump" -->
								    </el-button>
								</el-input>
							</el-form-item>
	            		</div>
            		</div>
            		<!--搜索結果-->
            		<div class="searchResult pull-right" v-show="form.showResult">
						<el-row>
							<el-col  class="">
								<div class="sr-box">
				                    <div class="sr-content">
				                        <el-row v-for="item in form.result" :key="item.standNo" style="border-bottom: 1px solid #e7eaec; padding-bottom: 15px;">
				                        	<p>{{item.name}}/{{item.standNo}}</p>
				                        	<el-button style="margin-left: 20px" size="small" v-for="snItem in item.snList" 
				                        		:key="snItem.sn"
				                        		:type="snItem.selected?'primary':''" 
				                        		@click="toggleSn(item, snItem)"
				                        	>
				                        		{{snItem.sn}}
				                        	</el-button>
				                        </el-row>
				                        <el-row v-show="!form.result.length">无结果</el-row>
				                    </div>
				                </div>
							</el-col>
						</el-row>	
					</div>
					<!-- 车辆分组分类组件 -->
					
						<v-vechicle-select ref="vechicle" style="padding-left:20px;margin-top: 20px;" label="车辆分组/分类" @onVechicleChange="vechicleChange"></v-vechicle-select>
						<!-- 车辆分组分类组件 /-->
						
						<el-form-item style=
						"margin-top: 20px;" 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-option label="车架号" value="2"></el-option>
							      <el-option label="姓名" value="3"></el-option>
							      <el-option label="设备号" value="4"></el-option>
							    </el-select>

							</el-input>
						</el-form-item>	
						
							<el-form-item style=
						"margin-top: 20px;">
							    <el-button type="primary" @click="onSubmit" size="small">查询</el-button>
							</el-form-item>
							<el-form-item style=
						"margin-top: 20px;">
							    <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"
					    @selection-change="selectChange"
					    style="width: 100%">

					    <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="100" align="center"></el-table-column>
						<el-table-column prop="durationFormat" label="超速时长" min-width="160" align="center"></el-table-column>
						<el-table-column prop="averagespeed" label="平均车速 km/h" min-width="160" align="center"></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>
		</template>
	</v-layout>
</template>
<script>
import vDateRange from 'components/DateRange.vue'
const vVechicleSelect = () => import(/* webpackChunkName: "vVechicleSelect" */ 'components/VechicleSelect.vue');
import {exportExcel} from 'utils'
import {services} from '../../api'
import { Message } from 'element-ui';

const REPORT_SERVICE =  services.report;
export default{
	data(){
		return {
			loading: true,
			currentPage: 1,
			pageSize: 10,
			total: 0,
			tableData: [],
			form: {
		        queryType: '1',
		        queryTerm: '',	
		        queryOnlyType:'1',
		        queryOnlyTerm:'',
		        showResult: false,
				isSearching: false,
				result: []
			},
			selectedIds: []
		}
	},
	created(){
		this.getData();

	},
	computed: {
		
	},
	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();
			let param=this.getParams();
			params.currentPage = curr;
			params.pageSize = size;
			REPORT_SERVICE.overspeedList(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;
			});
			REPORT_SERVICE.overspeedTotal(param).then((response)=>{
				if(response.data){
					//this.tableData = response.data;
					this.total = response.data;
				}else{
					//this.tableData = [];
					this.total = 0;
				}
				this.loading = false;
			});
		},
		getParams(){
			const form = this.form;
			const params = {};
			if(form.classIdList){
				params.classId = form.classIdList;
			}
			if(form.groupId){
				params.groupId = form.groupId;
			}
			const queryTerm = form.queryTerm.trim();
			if(queryTerm){
				switch(form.queryType){
					case '1':
						params.sqbh = queryTerm;
						break;
					case '2':
						params.standno = queryTerm;
						break;	
					case '3':
						params.name = queryTerm;
						break;	
					case '4':
						params.sn = queryTerm;
						break;				
				}
			}			
			return params;
		},
		resetForm(formName) {
        	this.$refs[formName].resetFields();
        	this.$refs.vechicle.resetSelet();
        	this.form.groupId="";
        	this.form.classIdList="";
		},
		searchSubmit(e){
			/*if(e.keyCode === 8){
            	this.form.showResult = false; 
        	}else{*/
        		
        		REPORT_SERVICE.getCriteriaTreeList({
				term: this.form.queryOnlyTerm,
				type: this.form.queryOnlyType
			}).then((res)=>{
				//res = mock.getCriteriaTreeList
				
				if(res.returnCode == 0){
					let _result = res.data;

					_result.forEach((item)=>{
						let sns = item.sns;
						item.selected = false;
						item.snList = this.getSns(sns.substr(1, sns.length-2));
					});

					this.form.result = _result;
					this.form.isSearching = false;
					this.form.showResult = true;

					this.needSelectedCache = false;
				}
			});
        	//}
			
			
		},
		getSns(snsStr){
			let arr = snsStr.split(',');
			return arr.map((o)=>{
				return {
					sn: o.split('-')[1],
					selected: false
				};
			});
		},
		
		toggleSn(item, snItem){
			this.form.queryOnlyTerm = snItem.sn		
			this.form.showResult = false;
			let reg=/^\d+$/;
      		let sn
      		if(!reg.test(this.form.queryOnlyTerm)){
				  //sn = this.form.queryOnlyTerm.substr(0, this.form.queryOnlyTerm.length-1)
				  sn = snItem.sn.split('/')[0]
      		}else{
      			sn = this.form.queryOnlyTerm;
      		}
      		if(this.form.queryOnlyTerm!=''){
      			this.$router.push({path:"singleDevice",query: {sn:sn}})

      		}

		},	
		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();
      	},
      	/*onJump(){
      		let reg=/^\d+$/;
      		let sn
      		if(!reg.test(this.form.queryOnlyTerm)){
      			sn = this.form.queryOnlyTerm.substr(0, this.form.queryOnlyTerm.length-1)
      		}else{
      			sn = this.form.queryOnlyTerm;
      		}
      		if(this.form.queryOnlyTerm!=''){
      			this.$router.push({path:"singleDevice",query: {sn:sn}})

      		}
      		
      	},*/
      	singleDevice(){
      		let sn = this.form.queryOnlyTerm
      		if(this.form.queryOnlyTerm!=""){
      			this.$router.push({path:"singleDevice",query: {sn: sn}})

      		}
      		
      	},
      	exportExcel(){
      		let getParam = this.getParams();
			const url = 'report/overspeed/export';
			if(this.selectedIds.length){
				getParam.idList = this.selectedIds.join(',')
			}		
			REPORT_SERVICE.overspeedCheckExport(getParam).then((response)=>{
				if(response.message=="成功"){
					if(this.tableData==""){
						return;
					}else{
						if(this.selectedIds.length){
							
	      					exportExcel(url,getParam)
	      				}else {
	      					exportExcel(url, getParam)
	      				}
					}
						
					
				}
				else{
					return;

				}	
			});
      		
      		
      		
      	}
    },
     mounted(){
    	document.onclick = () => {
           this.form.showResult = false;
 		}
    },
	components:{
		vDateRange,
		vVechicleSelect
	}
}
</script>
<style lang="scss">
	
</style>