riku
2025-03-05 7b52f30bc471b7f433eea950f77ecb74a87d867c
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
<template>
  <!-- <el-button
    type="primary"
    icon="Memo"
    class="el-button-custom p-events-auto"
    @click="dialogVisible = !dialogVisible"
  >
    溯源清单
  </el-button> -->
  <CardDialog
    v-model="dialogVisible"
    title="溯源清单"
    draggable
    :modal="false"
    width="400px"
  >
    <template #default>
      <div v-show="!nextPage">
        <div>
          <el-text size="small" type="warning">
            共计{{ sceneStore.sceneList.length }}个点位,其中{{
              sceneTypeSummary
            }}
          </el-text>
        </div>
        <!-- <div v-for="(t, i) in closestScene" :key="i"> -->
        <el-text
          v-for="(t, i) in closestScene"
          :key="i"
          size="small"
          type="warning"
        >
          {{ t }}
        </el-text>
        <!-- </div> -->
        <!-- <el-row> 共计{{ sceneStore.sceneList.length }}个点位,其中 </el-row> -->
        <el-row class="scene-table">
          <!-- <el-col :span="20"> -->
          <el-table
            :data="sceneStore.sceneList"
            table-layout="fixed"
            size="small"
            height="30vh"
            :show-overflow-tooltip="true"
            border
            row-class-name="t-row"
            cell-class-name="t-cell"
            header-row-class-name="t-header-row"
            header-cell-class-name="t-header-cell"
            @row-click="handleRowClick"
            @filter-change="handleFilterChange"
          >
            <el-table-column type="index" label="#" width="25" />
            <el-table-column
              prop="type"
              label="类型"
              width="56"
              column-key="type"
              :filters="sceneTypeFilter"
              :filter-method="filterHandler"
            />
            <el-table-column prop="name" label="名称" />
            <!-- <el-table-column prop="location" label="地址" /> -->
            <el-table-column
              prop="districtName"
              label="区县"
              align="center"
              width="54"
            />
            <!-- <el-table-column label="管理" width="70" align="center">
            <template #default="{ row }">
              <el-button
                type="primary"
                size="small"
                class="el-button-custom"
                @click="deleteDevice(row)"
                >删除</el-button
              >
            </template>
          </el-table-column> -->
          </el-table>
          <!-- </el-col> -->
        </el-row>
      </div>
      <div v-show="nextPage">
        <DescriptionsList v-if="selectedScene" title="场景详情">
          <template #extra>
            <el-button
              @click="nextPage = false"
              icon="back"
              type="primary"
              size="small"
              class="el-button-custom p-events-auto"
              >返回</el-button
            >
          </template>
          <DescriptionsListItem label="名称" :content="selectedScene.name" />
          <DescriptionsListItem label="类型" :content="selectedScene.type" />
          <DescriptionsListItem
            label="区县"
            :content="selectedScene.districtName"
          />
          <DescriptionsListItem
            label="地址"
            :content="selectedScene.location"
          />
          <DescriptionsListItem
            label="经纬度"
            :content="selectedScene.longitude + ', ' + selectedScene.latitude"
          />
          <DescriptionsListItem
            label="靠近站点"
            :content="selectedScene.closestDevice.name"
          />
          <DescriptionsListItem
            label="相距站点"
            :content="selectedScene.closestDevice.dis + '米'"
          />
        </DescriptionsList>
      </div>
    </template>
    <template #footer>
      <!-- <el-row justify="start" align="middle" class="p-b-2 one-row"> -->
      <!-- <el-text size="small" type="warning">搜索范围</el-text>
        <el-input
          class="input-radius m-h-2"
          size="small"
          v-model="sceneStore.radius"
          :min="1"
        />
        <el-text size="small" type="warning">
          公里以内,结果{{ sceneStore.sceneList.length }}条</el-text
        > -->
 
      <!-- </el-row> -->
    </template>
  </CardDialog>
</template>
<script>
import { sceneTypes, sceneIcon } from '@/constant/scene-types';
import marks from '@/utils/map/marks';
import { useFetchData } from '@/composables/fetchData';
import { mapStores } from 'pinia';
import { useSceneStore } from '@/stores/scene';
import { useToolboxStore } from '@/stores/toolbox';
import MapUtil from '@/utils/map/util';
import calculate from '@/utils/map/calculate';
 
let layer = undefined;
const devices = [
  {
    name: '程桥站',
    typeId: 20,
    type: 'type',
    longitude: 121.362928,
    latitude: 31.192925
  },
  {
    name: '华阳站',
    typeId: 20,
    type: '市控点',
    longitude: 121.424603,
    latitude: 31.223644
  },
  {
    name: '仙霞站',
    typeId: 19,
    type: '国控点',
    longitude: 121.394775,
    latitude: 31.203982
  }
];
 
export default {
  setup() {
    const { loading, fetchData } = useFetchData();
    return { loading, fetchData };
  },
  props: {
    modelValue: Boolean
  },
  emits: ['update:modelValue'],
  data() {
    return {
      dialogVisible: false,
      onConfirm: undefined,
      showSceneTypes: [],
      nextPage: false,
      selectedScene: undefined
    };
  },
  computed: {
    ...mapStores(useSceneStore),
    ...mapStores(useToolboxStore),
    sceneTypeFilter() {
      return sceneTypes()
        .filter((v) => {
          return !v.disabled;
        })
        .map((v) => {
          return { text: v.label, value: v.label };
        });
    },
    showSceneList() {
      if (this.showSceneTypes.length == 0) {
        return this.sceneStore.sceneList;
      } else {
        return this.sceneStore.sceneList.filter((v) => {
          return this.showSceneTypes.indexOf(v.type) != -1;
        });
      }
    },
    // 搜索结果场景类型统计
    sceneTypeSummary() {
      const typeMap = new Map();
      this.sceneStore.sceneList.forEach((s) => {
        if (!typeMap.has(s.type)) {
          typeMap.set(s.type, []);
        }
        typeMap.get(s.type).push(s);
      });
 
      let summary = '';
      typeMap.forEach((v, k) => {
        summary += `${k}${v.length}个、`;
      });
      summary = summary.slice(0, summary.length - 1);
 
      return summary;
    },
    // 计算距离给定点位最近的场景
    closestScene() {
      let txt = [];
      devices.forEach((d) => {
        let minDistance, scene;
        this.sceneStore.sceneList.forEach((s) => {
          const dis = calculate.getDistance(
            s.longitude,
            s.latitude,
            d.longitude,
            d.latitude
          );
          if (!minDistance || dis < minDistance) {
            minDistance = dis;
            scene = s;
          }
          if (!s.closestDevice || dis < s.closestDevice.dis) {
            s.closestDevice = {
              name: d.name,
              dis: Math.round(dis)
            };
          }
        });
        if (minDistance) {
          minDistance = Math.round(minDistance);
        }
        if (scene) {
          txt.push(`距${d.name}最近的为${scene.name},距离${minDistance}米;`);
        }
      });
 
      return txt;
    }
  },
  watch: {
    dialogVisible(nv) {
      if (layer) {
        if (!nv) {
          MapUtil.removeViews(layer);
        } else {
          MapUtil.addViews(layer);
        }
      }
    },
    // 'sceneStore.sceneList': {
    //   handler(nV, oV) {
    //     if (nV != oV) {
    //       this.dialogVisible = true;
    //       this.drawMarks(nV);
    //     }
    //   },
    //   deep: true
    // },
    showSceneList(nV, oV) {
      if (nV != oV) {
        this.nextPage = false;
        this.dialogVisible = true;
        this.drawMarks(nV);
      }
    },
    'toolboxStore.sceneSearchStatus': {
      handler(nV) {
        if (!nV) {
          this.dialogVisible = false;
        }
      },
      deep: true
    }
  },
  methods: {
    drawMarks(sceneList) {
      if (layer != undefined) {
        MapUtil.removeViews(layer);
        layer = undefined;
      }
      if (sceneList.length != 0) {
        const icons = [];
        sceneList.forEach((s) => {
          icons.push(sceneIcon(s.typeId));
        });
        layer = marks.createLabelMarks(icons, sceneList, false);
      }
    },
    handleRowClick(row, col, event) {
      this.nextPage = true;
      this.selectedScene = row;
      MapUtil.setCenter([row.longitude, row.latitude], true);
    },
    filterHandler(value, row, column) {
      const property = column['property'];
      return row[property] === value;
    },
    handleFilterChange(newFilters) {
      // console.log(newFilters);
      this.showSceneTypes = newFilters['type'];
    }
  }
};
</script>
<style scoped>
.scene-table {
  /* background-color: antiquewhite; */
}
 
.input-radius {
  width: 36px;
  height: 16px;
}
 
/* .ff-content-medium .ff-border-top {
  padding: 0px 0px var(--bevel-length-2) 0px;
} */
 
::v-deep .el-table {
  --el-table-bg-color: transparent;
  --el-table-row-hover-bg-color: var(--select_color);
  --el-table-current-row-bg-color: var(--select_color);
  /* --el-table-current-row-bg-color: #7dff5d96; */
  --el-table-text-color: var(--font-color);
}
 
::v-deep .t-row {
  cursor: pointer;
  background-color: transparent !important;
}
 
.t-cell {
}
 
.t-header-row {
}
 
::v-deep .t-header-cell {
  background-color: var(--bg-color-2) !important;
  color: white !important;
}
</style>