resident.vue 9.04 KB
<template>
	<v-full-layout>
		<template slot="breadcrumb">
			<el-breadcrumb-item>常驻地</el-breadcrumb-item>
		</template>
		<template slot="main">
			<div class="map-wrap" >
				<div id="map" class="map-container" v-loading="mapLoading"></div>
				<map-controll></map-controll>
				<div class="controll-wrap">
					<div class="search-box" :class="resultBoxHidden?'active':''">
						<h3>常驻地</h3>
						<p class="info">{{name}}/{{standno}}/{{sn}}</p>
						<el-form ref="form" :model="form" :rules="rules" :inline="false" size="mini"  class="form">
					  		<el-form-item label="查询范围" prop="timerange">
								<el-select v-model="form.daterange" placeholder="请选择" size="small" style="width: 280px">
							      <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-form-item>
				  			<!-- <el-form-item label="查询时段" prop="timerange">
				  											<el-select v-model="form.timerange" placeholder="请选择" size="small" style="width: 280px">
				  										      <el-option label="上午(06:00~12:00)" value="1"></el-option>
				  										      <el-option label="下午(12:00~21:00)" value="2"></el-option>
				  										      <el-option label="夜晚(21:00~06:00)" value="3"></el-option>
				  										      <el-option label="全天(00:00~24:00)" value="4"></el-option>
				  										    </el-select>
				  			</el-form-item> -->
				  			
				  			<el-form-item class="submit-el-form-item">
							    <el-button type="primary" @click="searchSubmit" size="small" :loading="isSearching">查询</el-button>
							</el-form-item>
				  		</el-form>
					</div>
					<div class="result-box" :class="resultBoxHidden?'':'active'">
						<div class="result-box-head">
							<el-button class="pull-left" size="mini" type="text" @click="resultBoxHidden=true;">返回“查询”</el-button>
							<el-button class="pull-right" size="mini" type="text" @click="exportExcel">导出Excel</el-button>
							<span>常驻地({{resultList.length}})</span>
						</div>
						
						<ul class="stay-list">
							<li class="stay-list-item" v-for="item in resultList"  @click="openMapInfoWindow(item.idx)">
								<p class="addr">{{item.transferAddress}}</p>
								<p class="datetime">驻留次数:<span>{{item.totalTimes}}次</span> | 驻留时长:<span>{{item.totalDurationString}}</span></p>
							</li>
							<li v-show="!resultList.length">
								<p class="text-center">无数据</p>
							</li>
							<!-- <infinite-loading v-if="needInfinite" @infinite="infiniteHandler" ref="infiniteLoading">
								<span slot="no-more">没有更多数据了</span>
								<span slot="no-results">无结果</span>
							</infinite-loading> -->
						</ul>
					</div>
				</div>
			</div>
		</template>
	</v-full-layout>
</template>
<script>
	import store from '../../vuex/store.js'
	import remoteLoad from 'utils/remoteLoad.js'
	import mapService from 'utils/mapService.js'
	import 'utils/mapEvent.js'
	import EventBus from '../../event-bus'
	import {services} from '../../api'
	import mock from '../../mock'
	const MONITOR_SERVICE =  services.monitor;
	const BUSINESS_SERVICE =  services.business;
	import {CONSTANT} from '../../constant'
	import InfiniteLoading from 'vue-infinite-loading';
	import {exportExcel} from 'utils';
	import MapControll from './MapControll.vue'

	export default{
		data(){
			return {
				sn: this.$route.query.sn,
				name: this.$route.query.name,
				standno: this.$route.query.standno,
				AMap: null,
				mapObj: null,
				mapLoading: false,
				isInitMap: false,
				searchText: '',
				searchType: 'sn',
				isSearching: false,
				resultBoxHidden: true,
				form: {
					daterange: '1',
					timerange: '4',
				},
				needInfinite: true,
				params: {},
				currentPage: 1,
				pageSize: 10,
				total: 100,
				maxPage: 10,
				resultList: [],
			}
		},
		mounted(){
			store.dispatch('setFullsize', true)
		},
		methods: {

			initMap(){
				let check = ()=>{
					this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded);

					return setTimeout(()=>{
				      	if('AMap' in window && typeof AMap.Map == 'function' && !this.mapObj){
				      		window.AMap = AMap;
				      		this.mapObj = mapService.init('map');
				      		
				      		//this.bindEvent();
							  this.isInitMap = true;
							  this.drawPoi()
						}else{
							this.checkMapLoaded = check()
						}
				    }, 100)
				}
				this.checkMapLoaded = check();
			},
			pickDate(beforeDays){
				this.form.dateRange = [moment().subtract(beforeDays, 'days'),moment().subtract(1, 'days')]
			},
			searchSubmit(){
				this.$refs.form.validate((valid, field)=>{
	    			if(valid){
	    				this.isSearching = true;
	    				
	    				let params = {
	    					sn: this.sn,
	    					timeRange: this.form.daterange,
							times: this.form.timerange,
	    				}
	    				
	    				MONITOR_SERVICE.getResidentByRealTime(params).then((res)=>{
							if(res.returnCode == 0){
								const data = res.data;
								if(data.length){
									data.forEach((item, idx)=>{
										item.idx = idx;
									});
									this.resultList = data;
									EventBus.$emit('uiMap.resident.draw', data);
									
									this.resultBoxHidden = false;
								}else{
									this.$message({
						              type: 'info',
						              message: '暂无数据'
						            });
						            EventBus.$emit('uiMap.resident.destroy', data);
								}
								this.isSearching = false;
							}
						});
	    			}else{
	    				return false;
	    			}
	    		});
			},
			infiniteHandler($state){
				if(this.currentPage> this.maxPage){
					$state.complete();
					return;
				}
				
				this.params.currentPage = this.currentPage;
				this.params.pageSize = this.pageSize;
				this.params.status = 1;


				this.currentPage++;
				$state.loaded();
				setTimeout(()=>{
					this.resultList = this.resultList.concat([{
						addr: '甘肃省酒泉市肃州区海马福仕达中瑞汽车',
						date: '2018-11-20 15:19:21',
						restTime: '25小时26分钟25秒'
					}])
				},10000)
				
				return;
				DEVICE_SERVICE.getDeviceList(this.params).then((res)=>{
					const data = res.data;
					if(data && data.length){
						const arr = []
						data.forEach((item) => {
							arr.push({
								label: item.name,
								value: item.id
							})
						})
						if(this.options[0] && 'label' in this.options[0]){
							this.options = this.options.concat(arr);
						}else{
							this.options = arr
						}
						
						this.total = res.recordsTotal;
						this.maxPage = Math.ceil(this.total/this.pageSize);
						this.currentPage++;
						this.$refs.infiniteLoading.$emit('$InfiniteLoading:loaded');
					}else{
						this.$refs.infiniteLoading.$emit('$InfiniteLoading:complete');
						this.options = []
					}
				})
			},
			exportExcel(){
				if(this.exporting) return;
				if(this.resultList.length){
					let paramArr = [];
					this.resultList.forEach((dataItem)=>{
						let paramItem = {};
						for(let key in dataItem){
							switch(key){
								case 'name':
								case 'shopName':
								case 'sn':
								case 'sqbh':
								case 'standNo':
								case 'totalDurationString':
								case 'transferAddress':
									paramItem[key] = dataItem[key]?dataItem[key]:'';
									break;
								case 'totalTimes':
									paramItem[key] = dataItem[key]?(dataItem[key]+'次'):'';
									break;
								/*case 'transferAddress':
									paramItem.address = dataItem.transferAddress?dataItem.transferAddress:'';
									break;*/
							}
						}
						paramArr.push(paramItem);
					});

					exportExcel('track/exportVMData', {
	                    jsonStr: encodeURI(JSON.stringify(paramArr)),
	                    vmExportType: 4
	                }, 'post');
	                this.exporting = false;
	            }else{
	            	this.$message({
		              type: 'error',
		              message: '导出数据为空'
		            });
	            }
			},
			openMapInfoWindow(idx){
				EventBus.$emit('uiMap.resident.openInfoWindow', idx)
			},
			drawPoi(){
				BUSINESS_SERVICE.getPOI({
					sn: this.sn
				}).then((res)=>{
					if(res.returnCode === '0'){
						if(res.data && res.data.length){
							res.data.forEach((item)=>{
								let marker = mapService.createPOIMarker(mapService.getLngLat(item.lng, item.lat), this.mapObj)
								let infoWindow = mapService.bindPOIInfoWindow(marker, this.mapObj, item)
							})
						}
					}
				})
			}
		},
		async created () {
			if(window.AMap){
				this.initMap();
			}else{
		      	await remoteLoad(`${CONSTANT.AMAP_URL}`).then(()=>{
		      		remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(()=>{
		      			this.initMap();
		      		})
		      	})
		      	
		    }

		    
		    EventBus.$on('uiMap.historyLocation.transferSuccess', (data)=>{
		   		this.resultList = [].concat(data);
		   	});
		},
		beforeDestroy(){
			

		},
		components: {
			MapControll
		}
	}
</script>
<style scoped>
	/*样式写在  scss/monitor.scss*/
</style>