mileageStatistics.vue 14.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
<template>
	<v-layout>
		<template slot="breadcrumb">
			<div style="width: 100%;height: 100%;z-index: 1000;"></div>
			<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/>
				    		设备号在该查询条件下的总行程次数<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" label='日里程搜索' style='margin-top:15px'>
								<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" style="margin-top: -12px;" 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" style="padding:10px;">无结果</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>
            		<el-button type="primary" plain size="small" class="pull-right ibox-ctrl" @click="isAppear=true">日里程导出</el-button>
            		<div class="date" v-if='isAppear'>
            			<div class="date-box">
            				<span>选择日期</span>
							<el-date-picker
								v-model="dateRange"
								value-format="yyyy-MM-dd"
								size="small"
						      	type="daterange"
						      	range-separator="至"
						      	start-placeholder="开始日期"
						      	end-placeholder="结束日期"
						      	:picker-options="pickerOptions">
						   </el-date-picker>
						   <p v-if='flag'>导出数据超过{{limitDays}}天</p>
						</div>
						<div class="datebtn">   
						   <el-button type="primary" plain size="small" class="pull-right ibox-ctrl" @click="exportDate">导出</el-button>
            				<el-button plain size="small" class="pull-right ibox-ctrl" @click="isAppear=false">取消</el-button>
            			</div> 
            		</div> 
            	</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="tripcount" label="总行驶次数" min-width="120" 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="details(scope.row.sn)" 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>
		</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 { mapGetters, mapActions } from 'vuex'

const REPORT_SERVICE =  services.report;
export default{
	data(){
		return {
			pickerOptions: {
          		disabledDate(time) {
            	return time.getTime() > Date.now();
          		}
          	},	
			loading: true,
			currentPage: 1,
			pageSize: 10,
			total: 0,
			tableData: [],
			dateRange:[],
			flag:false,
			isAppear:false,
			form: {
		        queryType: '1',
		        queryTerm: '',
		        queryOnlyType:'1',
		        queryOnlyTerm:'',
		        showResult: false,
				isSearching: false,
				result: []
			},
			selectedIds: [],
			//limitDays: 60
		}
	},
	created(){
		this.getData();

	},
	computed: {
		...mapGetters([
		  'isGq'
		]),
		limitDays(){
			return this.isGq?90:60
		}
	},
	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.journeysList(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.journeysTotal(param).then((response)=>{
				if(response.data){
					//this.tableData = response.data;
					this.total = response.data;
				}else{
					//this.tableData = [];
					this.total = 0;
				}
				this.loading = false;
			});
		},
		resetForm(formName) {
        	this.$refs[formName].resetFields();
        	this.$refs.vechicle.resetSelet();
		},
		getParams(){
			const form = this.form;
			const params = {};
			if(form.groupId){
				params.groupId = form.groupId;
			}
			if(form.classIdList){
				params.classId = form.classIdList;
			}
			if(this.dateRange && this.dateRange.length){
				params.timeBegin = moment(this.dateRange[0]).format('YYYY-MM-DD HH:mm:ss');
				params.timeEnd = moment(this.dateRange[1]).format('YYYY-MM-DD HH:mm:ss');
			}
			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;
		},
		exportDate(){
			if(this.dateRange && this.dateRange.length){
				let timeUpdate=this.timeUpdate;
					if(timeUpdate(this.dateRange)){
						this.flag = true;
					}else{
						this.flag = false;
						let getParam = this.getParams()
			      		const url = 'report/journeys/dailyExport';
			      		if(this.selectedIds.length){
							getParam.idList = this.selectedIds.join(',')
						}				
						if(this.selectedIds.length){
				      		exportExcel(url,getParam)
				      	}else{
				      		exportExcel(url, getParam)
				      	}

					}
			}
		},
		timeUpdate(val){
			let sTime=new Date(val[0]).getTime();
			let eTime=new Date(val[1]).getTime();
			let reduceDate=(eTime-sTime)/1000/60/60/24;
			if(reduceDate>this.limitDays){
				return true;
			}
		},
		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(snItem.sn)){
				  //sn = this.form.queryOnlyTerm.substr(0, this.form.queryOnlyTerm.length-1)
				sn = snItem.sn.split('/')[0]
      		}else{
      			sn = snItem.sn;
      		}
      		if(this.form.queryOnlyTerm!=''){
      			this.$router.push({path:"mileageMapModal",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();
      	},
      	details(sn){
			this.$router.push({path:"mileageMapModal",query: {sn:sn,timeRange:-1}})
		},
      	/*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:"mileageMapModal",query: {sn:sn}})

      		}
      		
      	},*/
      	exportExcel(){
      		let getParam = this.getParams()
      		const url = 'report/journeys/export';
      		if(this.selectedIds.length){
				getParam.idList = this.selectedIds.join(',')
			}				
      		REPORT_SERVICE.journeysCheckExport(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;
 		}
	},
	watch: {
		/* isGq(newVal){
			if(newVal){
				this.limitDays = 90;
			}
		} */
	},
	components:{
		vDateRange,
		vVechicleSelect
	}
}
</script>
<style scoped>
	.date{
		width: 470px;
		height: 150px;
		position: absolute;
		right: 0;
		top: 37%;
		border:1px solid #ccc;
		background: #fff;
		z-index: 999;
	}
	.date-box{
		margin-top: 25px;
		width: 100%;
	}
	.date-box span{
		margin-left: 25px;
		color:#606266;
	}
	.date-box p{
		margin-left: 25px;
		color: red;
	}
	.datebtn{
		margin-top: 15px;
	}
</style>