resident.vue
9.73 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
<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, index) in resultList"
:key="index"
@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 mapService from "@/utils/mapBService.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";
import { GET_RESIDENT_LOCATION } from "@/api/services/monitor";
export default {
data() {
return {
sn: this.$route.query.sn,
name: this.$route.query.name,
standno: this.$route.query.standno,
locationType: this.$route.query.locationType,
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() {
this.initBMap();
},
methods: {
async initBMap() {
this.mapObj = await mapService.init("map");
window.AMap = this.mapObj;
this.isInitMap = true;
},
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,
locationType:
this.locationType === "bsLocation"
? 2
: this.locationType === "gpsLocation"
? 1
: "",
// times: this.form.timerange,
times: 4, // 无时间段选项 默认传全天(4)
};
this.params = params;
GET_RESIDENT_LOCATION(params).then((res) => {
if (res.code == 200) {
const data = res.data;
if (data.length) {
data.forEach((item, idx) => {
item.idx = idx;
item.name = item.ownerName || "--";
item.sn = item.sn || "--";
item.vin = item.vin || "--";
item.transferAddress = item.address || "--"; // 取后端返回address
});
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) {
exportExcel(
"/trialdrive/monitor/exportResident",
{ ...this.params },
"get",
"",
true
);
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) => {
console.log(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() {
EventBus.$on("uiMap.historyLocation.transferSuccess", (data) => {
this.resultList = [].concat(data);
});
},
beforeDestroy() {},
components: {
MapControll,
},
};
</script>
<style scoped>
/*样式写在 scss/monitor.scss*/
</style>