guoshilong
2023-10-27 2311b03aee9db1bebacdd2ced13c071efda6a011
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
<template>
    <view class="container">
        <!--顶部导航栏-->
        <view class="customizeBar">
            <u-navbar placeholder title="变形监测" autoBack bgColor="#5887f9" titleStyle="color:#ffffff"
                leftIconColor="#ffffff" safeAreaInsetTop>
            </u-navbar>
        </view>
 
        <!--筛选栏-->
        <view class="top-bar">
            <mySearch v-if="mySearchShow" :defaultValue="adBase" :keyWord="query.res_nm" @getKey="getSearchKey"
                @regionChange="regionChange" @basinChange="basinChange">
            </mySearch>
            <uFilter :top="filterTop" :menuList="dropDownData" :defaultModel="defaultSelected" @submit='dropDownConfirm'
                @reset='resetDropDown'></uFilter>
        </view>
 
        <view class="data-list">
            <view class="data-item" v-for="(item,index) in dataList" :key="index">
                <dataItem :item="item" type="bx">
 
                </dataItem>
            </view>
 
 
            <u-loading-page :loading="loadingPage"></u-loading-page>
            <u-loading-icon text="加载中" textSize="18" :show="loadingIcon"></u-loading-icon>
 
        </view>
 
    </view>
</template>
 
<script>
    import uFilter from "@/subPackage/dbSafety/components/filterBar.vue"
    import mySearch from "@/subPackage/dbSafety/components/my-search.vue"
    import dataItem from "@/subPackage/dbSafety/components/dataItem.vue"
    import {
        bizDictionary
    } from "@/api/system/dict"
    import {
        dropDownData
    } from "@/subPackage/dbSafety/const/dropDownData.js"
    import {
        getLatestSySlData
    } from "@/api/dataCenter/dbSafety/dbSafety"
    import {
        reservoirList
    } from "@/api/dataCenter/reservoir/reservoir"
    export default {
        components: {
            mySearch,
            uFilter,
            dataItem
        },
 
        data() {
            return {
                //当用户没有行政区划时为false,隐藏搜索框
                mySearchShow: true,
                //当前登录用户的行政区划
                adBase: uni.getStorageSync("adCodeBase"),
                //查询参数
                query: {},
                //下拉选项
                dropDownData: dropDownData,
                //默认选中
                defaultSelected: {},
 
                //列表数据
                dataList: [],
 
                page: {
                    pageSize: 48,
                    pageNo: 1
                },
 
                loadingPage: false,
                loadingIcon: false,
            }
        },
        computed: {
            //自适应计算筛选栏高度
            filterTop() {
                const info = uni.getWindowInfo()
                const statusBar = info.statusBarHeight
                return 69 - (statusBar / 2)
            }
        },
        created() {
 
        },
        mounted() {
 
        },
        onLoad(option) {
            this.initDict()
        },
        onShow() {
 
        },
        onReachBottom() {
            this.page.pageNo += 1
            this.getDataList()
        },
        methods: {
            //初始化字典
            initDict() {
                bizDictionary({
                    code: "RES_LABEL"
                }).then(res => {
                    let data = res.data
                    let obj = this.dropDownData[0].children.find(e => e.label == "标签")
                    obj.option = []
 
                    data.forEach(e => {
                        obj.option.push({
                            label: e.dictValue,
                            value: `${e.dictKey}`
                        })
                    })
                    this.initDefault()
                    this.buildRegion(this.adBase)
                })
            },
 
            //初始化默认选择
            initDefault() {
                this.defaultSelected = {
                    //排序
                    is_order: "1",
                    //是否有数据
                    is_has_data: "y",
                    //工程规模
                    eng_scal: "",
                    //是否病险
                    danger_stat: "",
                    //标签
                    label_str: "",
                    //收藏
                    collect: "",
                }
 
                Object.assign(this.query, this.defaultSelected)
 
            },
 
            //获取输入框搜索条件
            getSearchKey(key) {
                this.query.res_nm = key
                this.reload()
            },
 
            //行政区划改变
            regionChange(region) {
                this.buildRegion(region)
            },
 
            //流域变更
            basinChange(basin) {
                console.log("流域:", basin)
                this.query.bas_guid = basin.name
                this.reload()
            },
 
            //下拉选择项
            dropDownConfirm(data) {
                console.log("下拉选择项:", data)
                this.page.pageNo = 1
 
                let objKey = Object.keys(data)
 
                objKey.forEach(key => {
                    if (data["label_str"] && key == "label_str") {
                        this.query[key] = data[key].join(",")
                    } else {
                        this.query[key] = data[key]
                    }
                })
                console.log(this.query, "---------")
                this.getDataList()
            },
 
            //重置下拉选项
            resetDropDown() {
                this.initDefault()
                this.reload()
            },
 
            //重新加载
            reload() {
                this.page.pageNo = 1
                this.getDataList()
            },
 
            //获取列表数据
            async getDataList() {
 
                if (this.page.pageNo == 1) {
                    this.dataList = []
                    this.loadingPage = !this.loadingPage
                } else {
                    this.loadingIcon = !this.loadingIcon
                }
 
                let params = {}
                Object.assign(params, this.query, this.page, this.getResIds())
 
                console.log("查询条件", Object.assign(params, this.query, this.page, this.getResIds()))
 
                const res = await getLatestSySlData(params)
                let data = res.data
                console.log(res, "-----")
 
                let arr = await this.buildArr(data)
                this.dataList = this.dataList.concat(arr)
 
                if (this.page.pageNo == 1) {
                    this.loadingPage = !this.loadingPage
                } else {
                    this.loadingIcon = !this.loadingIcon
                }
 
                console.log("最终数据", this.dataList)
            },
 
            getResIds() {
                if (this.query.collect == 1) {
                    this.collectResIds = this.userInfo.detail.collect ? this.userInfo.detail.collect : 0
                    this.collectResIds = this.collectResIds.split(",").map(e => `${e}`).join(",")
                } else {
                    this.collectResIds = ""
                }
                return {
                    res_str: this.collectResIds
                }
            },
 
            //构建arr
            async buildArr(data) {
                let resCds = []
                let arr = []
 
                //遍历sy列表
                data.sy.forEach((sy, index) => {
 
                    //判断sl列表中是否有相同的res_cd
                    const sl = data.sl.find(v => v.res_cd === sy.res_cd)
 
                    //有则把sl数据添加进arr中
                    if (sl) {
                        arr.push({
                            sy: sy,
                            sl: sl
                        })
                    } else {
                        arr.push({
                            sy: sy,
                            sl: {}
                        })
                    }
 
                    resCds.push(sy.res_cd)
                })
 
                arr.forEach(item => {
                    item.sy.children.sort((a, b) => a.cd - b.cd)
 
                    item.sy.children.forEach(item => {
                        if (item.trend == '1') {
                            item.iconClass = 'icon-wendushangsheng'
                        } else if (item.trend == '-1') {
                            item.iconClass = 'icon-wenduxiajiang'
                        } else if (item.trend == '0') {
                            item.iconClass = 'icon-a-youjiantouzhixiangyoujiantou'
                        }
                    })
                })
 
                //遍历渗流数组
                data.sl.forEach((sl, index) => {
 
                    //判断arr中是否已有相同的sl数据
                    const sy = arr.find(v => {
 
                        if (v.sl.res_cd) {
                            return v.sl.res_cd === sl.res_cd
                        } else {
                            return false
                        }
                    })
                    if (sy) {
 
                    } else {
                        arr.push({
                            sy: {},
                            sl: sl
                        })
                    }
                    resCds.push(sl.res_cd)
                })
 
                console.log(arr, "------------")
                console.log(resCds, "/*/*/*")
                const res_cds = resCds.map(e => `'${e}'`).join(",")
                const res = await reservoirList(999, 1, {
                    res_cds
                })
 
                let reservoirData = res.data.data
                //循环arr,从reservoirData中获取当前水位,昨日雨量
                arr.forEach(item => {
                    reservoirData.forEach(reservoir => {
                        if (item.sy.res_cd == reservoir.res_cd || item.sl.res_cd == reservoir.res_cd) {
 
 
                            reservoir.current_site_image = ''
                            reservoir.current_site_image_index = ''
                            reservoir.imagesArray = []
 
                            if (reservoir.station_image && reservoir.station_image.trim().length > 0) {
 
                                let arr = []
 
                                if (reservoir.station_image.indexOf(',') != -1) {
                                    arr = reservoir.station_image.split(',').map(arrItem => {
                                        if (arrItem.indexOf('~') != -1) {
                                            if (arrItem.split('~').length > 2) {
                                                arrItem = arrItem.split('~')
                                            } else {
                                                let cur = arrItem.split('~')
                                                cur.push(this.publicPath +
                                                    'img/emptyImg.514374af.png')
                                                arrItem = cur
                                            }
                                        }
 
                                        return arrItem
                                    })
                                } else {
                                    if (reservoir.station_image.indexOf('~') != -1) {
                                        if (reservoir.station_image.split('~').length > 2) {
                                            arr = [reservoir.station_image.split('~')]
                                        } else {
                                            let cur = reservoir.station_image.split('~')
                                            cur.push(this.publicPath + 'img/emptyImg.514374af.png')
                                            arr = [cur]
                                        }
                                    }
                                }
 
                                if (arr && arr.length > 0) {
                                    arr.forEach(arrItem => {
 
                                        let urlStr = arrItem[2]
 
                                        if (urlStr.indexOf(
                                                'http://183.95.190.143:9096/images') != -
                                            1) {
                                            urlStr = urlStr.replace(
                                                'http://183.95.190.143:9096/images',
                                                'https://sk.hubeishuiyi.cn/imgWLW/images')
                                        }
 
                                        if (urlStr.indexOf(
                                                'http://223.75.53.106:8891/skjgimages') != -
                                            1) {
                                            urlStr = urlStr.replace(
                                                `http://223.75.53.106:8891/skjgimages`,
                                                `https://sk.hubeishuiyi.cn/imgLK/skjgimages`
                                            )
                                        }
 
                                        reservoir.imagesArray.push({
                                            title: arrItem[1],
                                            url: urlStr
                                        })
                                    })
                                }
 
                                reservoir.current_site_image = reservoir.imagesArray.length > 0 ?
                                    reservoir.imagesArray[0] :
                                    ''
                                reservoir.current_site_image_index = reservoir.imagesArray.length > 0 ?
                                    0 : ''
                                reservoir.current_site_image.url = reservoir.current_site_image.url
                                    .replace(/\\/g, "/");
                            }
 
 
 
 
 
 
                            if (reservoir.rz && reservoir.rz_1h) {
                                reservoir.powerIconShow = true
                                if (reservoir.rz - reservoir.rz_1h > 0) {
                                    reservoir.iconClass = 'icon-wendushangsheng'
                                } else if (reservoir.rz - reservoir.rz_1h < 0) {
                                    reservoir.iconClass = 'icon-wenduxiajiang'
                                }
                            } else {
                                reservoir.powerIconShow = false
                            }
                            item.reservoir = reservoir
                        }
                    })
                })
                return arr
            },
 
            //对行政区划进行处理
            buildRegion(region) {
                delete this.query.city_cd
                delete this.query.county_cd
                delete this.query.town_cd
 
                if (region.adGrad == 4) {
                    this.query.town_cd = region.adCode
                }
                //市
                if (region.adGrad == 2) {
                    this.query.city_cd = region.adCode
                }
                //区
                if (region.adGrad == 3) {
                    this.query.county_cd = region.adCode
                }
 
                this.adBase = region
 
                this.reload()
            }
 
        }
    }
</script>
 
<style scoped lang="scss">
    .container {
 
        .container {
            min-height: 100vh;
        }
 
        .top-bar {
            width: 100%;
            display: flex;
            justify-content: space-around;
            // position: fixed;
            // top: 200rpx;
            flex-direction: column;
            position: -webkit-sticky;
            position: sticky;
            top: calc(var(--status-bar-height) + 80rpx);
            // top: 80rpx;
        }
    }
</style>