智慧农业后台管理页面
xiebin
2022-08-25 a140d8c8fc7576c7b136b7df2ab9fcfcd1edfbd1
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
<template>
    <div @click="bodyClick($event)" style="position: relative; height: 100%;">
        <plot-map ref="plotMap" style="position: absolute; width: 100%; height: 100%;"></plot-map>
 
        <div class="top">
            <div class="logo">
                <img src="../../../public/mg.png" />
            </div>
            <div class="farm-info">
                <div class="farm-name">
                    <span>{{ farmInfo.farmName }}</span>
                </div>
                <div class="farm-area">
                    <span>地块总面积:</span>
                    <span style="font-size: 16px;font-weight: bold;">&nbsp;{{landAreaInfo.zarea}}亩</span>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span>在田面积:</span>
                    <span style="font-size: 16px;font-weight: bold;">&nbsp;{{landAreaInfo.sarea}}亩</span>
                </div>
            </div>
            <div class="out" @click="goToBack">
                <img src="../../../public/img/out.png" />
                <span>&nbsp;&nbsp;返回</span>
            </div>
        </div>
 
        <div class="farm-plant">
            <div class="title">
                <span>种养品种 · {{ this.plotPlantBreed.length }}种</span>
            </div>
            <div class="content">
                <div class="list-item" v-for="(item, index) in plotPlantBreed" :key="index">
                    <div class="item-img">
                        <img :src="item.url" />
                        <span>{{ item.strainName }}</span>
                    </div>
                    <div class="item-num">{{ item.area }}亩</div>
                </div>
            </div>
        </div>
 
        <div class="land-info">
            <div class="content">
                <div>
                    有轮廓的地块:
                    <span
                        style="font-size: 26px;font-weight: bold;color: #5ABF78;"
                    >{{landIsAreaStatistic.length > 0 ? landIsAreaStatistic[0] : 0}}</span>
                </div>
 
                <div>
                    无轮廓的地块:
                    <span
                        style="font-size: 26px;font-weight: bold;color: #E3B745;"
                    >{{landIsAreaStatistic.length > 1 ? landIsAreaStatistic[1] : 0}}</span>
                </div>
            </div>
        </div>
 
        <div class="farm-land">
            <div class="title">
                <span>地块 · {{ this.pageLand.total }}个</span>
            </div>
            <div class="content">
                <div
                    class="list-item"
                    v-for="(item, index) in landList"
                    :key="index"
                    @click="setCenter(item)"
                >
                    <div class="item-img">
                        <img :src="item.url" />
                        <span>{{ item.landName }}</span>
                    </div>
                    <div class="item-num">{{ item.landArea }}亩</div>
                </div>
            </div>
        </div>
 
        <div class="plot-detail-popup" v-show="cPShow" ref="showCP">
            <div class="close-plot-popup" @click="closePlotPopup">
                <i class="el-icon-close" style="color: #fff;"></i>
            </div>
 
            <div class="header">
                <div class="plot-name">
                    <div v-show="!plotNameEditShow">
                        <div
                            class="name"
                            style="font-weight: bold;"
                        >{{ currentPlotDetails.landName }}</div>
                        <i
                            @click="plotNameEditShow=true"
                            class="el-icon-edit-outline edit-btn"
                            title="编辑地块名称"
                            style="margin-left: 9px;"
                        ></i>
                    </div>
 
                    <div v-show="plotNameEditShow" class="edit-name">
                        <el-input style="flex: 1;" v-model="currentPlotName" size="small"></el-input>
                        <div class="btn-grounp">
                            <span class="edit-btn" @click="editName">保存</span>
 
                            <span style="color: #999;">|</span>
 
                            <span
                                class="edit-btn"
                                @click="plotNameEditShow=fasle"
                                style="color: #acdcd0;"
                            >取消</span>
                        </div>
                    </div>
                </div>
                <div class="plot-area-type">
                    <div class="l">
                        占地面积:{{ currentPlotDetails.landArea }}{{ currentPlotDetails.dica }}
                        <span
                            class="type"
                        >{{ currentPlotDetails.dic }}</span>
                    </div>
                    <div class="r" @click="goToPlotDetail">
                        进入地块
                        <i class="el-icon-arrow-right"></i>
                    </div>
                </div>
            </div>
 
            <div class="body">
                <div
                    v-show="cPPBreed.length > 0"
                    class="list"
                    v-for="(item, index) in cPPBreed"
                    :key="index"
                >
                    <div class="l">
                        <img :src="item.url" />
                        {{ item.strainName }}
                    </div>
                    <div
                        class="r"
                    >{{ item.createTime }}{{ item.plantingWay == 0 ? "移摘" : item.plantingWay == 1 ? "播种" : "秧苗" }}</div>
                </div>
 
                <div
                    v-show="cPPBreed.length == 0"
                    style="height: 100%; display: flex; align-items: center; justify-content: center;"
                >暂无种养品种</div>
            </div>
        </div>
    </div>
</template>
 
<script>
import { mapGetters } from "vuex"
import { getList } from "@/api/farmplant/farmplant"
import { getList as getLandList, selectCount, getLandIsAreaStatistic, submit } from "@/api/land/land"
import { getDetails } from "@/api/farm/farm"
export default {
    components: {
    },
    data () {
        return {
            page: {
                pageSize: 100,
                currentPage: 1,
                total: 0,
            },
            pageLand: {
                pageSize: 100,
                currentPage: 1,
                total: 0,
            },
            farmPlantList: [],
 
            // 数据合并后的种养品种
            plotPlantBreed: [],
 
            // 当前地块种养品种
            cPPBreed: [],
 
            // 当前地块对应弹框
            cPShow: false,
 
            // 当前点击地块详情
            currentPlotDetails: {},
            currentPlotName: "",
 
            // 名称编辑是否显示
            plotNameEditShow: false,
 
            plotClickNum: 0,
 
            landList: [],
            farmInfo: {},
            landAreaInfo: {},
            landIsAreaStatistic: [],
        }
 
    },
    computed: {
        ...mapGetters(["userInfo","$farmId"]),
    },
    created () {
        //获取种样品列表
        this.getFarmPlantList(this.page)
        //获取地块列表
        this.getLandList(this.pageLand)
        //获取农场信息
        this.getFarmInfo()
        //获取统计面积信息
        this.getLandCount()
        //获取地块轮廓统计信息
        this.getLandIsAreaStatistic()
    },
    methods: {
        //获取种养品列表
        getFarmPlantList (page, params = {}) {
            params['farmId'] = this.$farmId
            params['status'] = 1
            this.loading = true
            getList(
                page.currentPage,
                page.pageSize,
                Object.assign(params)
            ).then((res) => {
                const data = res.data.data
                this.page.total = data.total
                this.farmPlantList = data.records
 
                let arr = []
                this.farmPlantList.forEach(item => {
                    if (arr.length > 0) {
                        let result = arr.some(it => {
                            if (item.strainName == it.strainName) {
                                it.area += Number(item.area)
 
                                return true
                            }
                        })
 
                        if (!result) {
                            arr.push({
                                strainName: item.strainName,
                                area: Number(item.area),
                                url: item.url
                            })
                        }
                    } else {
                        arr.push({
                            strainName: item.strainName,
                            area: Number(item.area),
                            url: item.url
                        })
                    }
                })
 
                this.plotPlantBreed = arr
 
 
                this.loading = false
 
 
 
                // this.selectionClear()
            })
        },
        //获取地块列表
        getLandList (page, params = {}) {
            params['farmId'] = this.$farmId
            params['tenantId'] = this.userInfo.tenant_id
            this.loading = true
            getLandList(
                page.currentPage,
                page.pageSize,
                Object.assign(params)
            ).then((res) => {
                const data = res.data.data
 
                data.records.forEach(item => {
                    if (item.landRange != '' || item.landRange != null) {
                        item.landRange = item.landRange.replace(/POLYGON\(\(/g, '')
                        item.landRange = item.landRange.replace(/\)\)/g, '')
 
                        const arr = item.landRange.split(',')
                        var brr = []
                        arr.forEach(it => {
                            brr.push(it.split(' '))
                        })
 
                        this.$refs.plotMap.addPlotPolygon(brr, item)
                    }
                })
 
                this.pageLand.total = data.total
                this.landList = data.records
                this.loading = false
                // this.selectionClear()
            })
        },
        //返回上一页
        goToBack () {
            this.$router.go(-1)
        },
        //获取农场信息
        getFarmInfo () {
            var that = this
            getDetails(this.$farmId).then(res => {
                that.farmInfo = res.data.data
            })
        },
        //获取统计面积信息
        getLandCount () {
            selectCount(this.$farmId).then(res => {
                this.landAreaInfo = res.data.data
            })
        },
        //获取地块轮廓统计信息
        getLandIsAreaStatistic () {
            getLandIsAreaStatistic(this.$farmId).then(res => {
                console.log(res)
                this.landIsAreaStatistic = res.data.data
            })
        },
 
        // 地块定位
        setCenter (item) {
            this.$refs.plotMap.setPlotCenter(item)
        },
 
        plotDetailsPopupShow (params) {
            this.currentPlotDetails = params
            this.currentPlotName = params.landName
 
            let arr = []
 
            this.farmPlantList.forEach((item, index) => {
                if (params.id == item.landId) {
                    arr.push(item)
                }
            })
 
            this.cPPBreed = arr
 
            this.cPShow = true
        },
 
        bodyClick (e) {
            if (this.plotClickNum == 0) {
                this.plotClickNum++
                return
            }
 
            if (this.$refs.showCP) {
                console.log(1)
                let isSelf = this.$refs.showCP.contains(e.target)
                if (!isSelf) {
                    this.plotClickNum = 0
                    this.cPShow = false
                }
            }
        },
 
        editName () {
            if (this.currentPlotName == "") {
                this.$message({
                    message: '地块名称不能为空',
                    type: "warning",
                })
                return
            }
 
            submit({
                id: this.currentPlotDetails.id,
                landName: this.currentPlotName
            }).then(res => {
                if (res.data.code == 200) {
                    this.currentPlotDetails.landName = this.currentPlotName
                    this.$refs.plotMap.setPlotAttr(this.currentPlotDetails)
                    this.landList.some(item => {
                        if (item.id == this.currentPlotDetails.id) {
                            item.landName = this.currentPlotDetails.landName
                            return true
                        }
                    })
 
                    this.plotNameEditShow = false
 
                    this.$message({
                        message: '地块名称修改成功',
                        type: "success",
                    })
                }
            })
        },
 
        closePlotPopup () {
            this.plotClickNum = 0
            this.plotNameEditShow = false
            this.cPShow = false
        },
 
        goToPlotDetail () {
            this.landList.some(item => {
                if (item.id == this.currentPlotDetails.id) {
                    var arr = []
                    this.$store.state.tags.tagList.forEach((item) => {
                        if (item.label != "地块详情") {
                            arr.push(item)
                        }
                    })
                    this.$store.state.tags.tagList = arr
 
                    this.$router.push({
                        path: `/LandDetail`,
                        query: item,
                    })
                    return true
                }
            })
        }
    }
}
</script>
 
<style lang="scss" scope>
.top {
    position: absolute;
    top: 0;
    width: 100%;
    height: 80px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
 
    .logo {
        position: absolute;
        left: 36px;
        top: 12px;
 
        img {
            height: 55px;
        }
    }
 
    .farm-info {
        height: 100%;
        width: 100%;
 
        .farm-name {
            width: 100%;
            height: 33px;
            font-size: 25px;
            font-weight: bold;
            color: #5abf78;
            text-align: center;
            padding-top: 13px;
        }
 
        .farm-area {
            width: 100%;
            height: 19px;
            font-size: 14px;
            font-weight: 400;
            color: #ffffff;
            text-align: center;
            padding-top: 6px;
        }
    }
 
    .out {
        width: 136px;
        height: 33px;
        line-height: 33px;
        background: rgba(236, 95, 89, 0.8);
        border-radius: 4px 4px 4px 4px;
        opacity: 1;
        border: 1px solid #ec5f59;
        position: absolute;
        top: 24px;
        right: 33px;
        text-align: center;
        cursor: pointer;
 
        img {
            width: 12px;
            height: 18px;
            position: relative;
            top: 4px;
        }
 
        span {
            font-size: 14px;
            color: #ffffff;
            font-weight: 400;
        }
    }
}
 
.land-info {
    width: 100%;
    position: absolute;
    top: 112px;
 
    .content {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: auto;
        padding: 0 40px;
        width: 431px;
        height: 56px;
        background: rgba(0, 0, 0, 0.5);
        border-radius: 28px 28px 28px 28px;
        font-size: 16px;
        font-weight: 400;
        color: #ffffff;
 
        & > div {
            display: flex;
            align-items: center;
        }
    }
}
 
.farm-plant {
    position: absolute;
    left: 30px;
    top: 242px;
    z-index: 99;
 
    width: 292px;
    height: 550px;
 
    .title {
        width: 292px;
        height: 50px;
        background: #5abf78;
        border-radius: 4px 4px 0px 0px;
        opacity: 1;
        line-height: 50px;
        font-size: 17px;
        font-weight: bold;
        color: #ffffff;
 
        span {
            margin-left: 20px;
        }
    }
 
    .content {
        width: 292px;
        height: calc(100% - 50px);
        background: rgba(8, 85, 30, 0.9);
        // height: 500px;
        border-radius: 4px 4px 0px 0px;
        opacity: 0.9;
        padding-bottom: 30px;
 
        overflow-x: hidden;
        overflow-y: auto;
 
        .list-item {
            width: 252px;
            margin: auto;
            display: flex;
            height: 64px;
            line-height: 64px;
            border-bottom: 1px solid #cccccc;
            flex-flow: row nowrap;
            justify-content: space-between;
 
            .item-img {
                margin-left: 5px;
                display: flex;
 
                img {
                    margin-top: 12px;
                    width: 40px;
                    height: 40px;
                    background: #2389ef;
                    border-radius: 84px 84px 84px 84px;
                    opacity: 1;
                }
 
                span {
                    margin-left: 11px;
                    font-size: 14px;
                    font-weight: 400;
                    color: #ffffff;
                }
            }
 
            .item-num {
                font-size: 14px;
                font-weight: 400;
                color: #ffffff;
            }
        }
    }
}
 
.farm-land {
    position: absolute;
    right: 30px;
    top: 242px;
 
    z-index: 99;
 
    width: 292px;
    height: 550px;
 
    .title {
        width: 292px;
        height: 50px;
        background: #5abf78;
        border-radius: 4px 4px 0px 0px;
        opacity: 1;
        line-height: 50px;
        font-size: 17px;
        font-weight: bold;
        color: #ffffff;
 
        span {
            margin-left: 20px;
        }
    }
 
    .content {
        width: 292px;
        height: calc(100% - 50px);
        background: rgba(8, 85, 30, 0.9);
        // height: 500px;
 
        border-radius: 4px 4px 0px 0px;
        opacity: 0.9;
        padding-bottom: 30px;
 
        overflow-x: hidden;
        overflow-y: auto;
 
        .list-item {
            width: 252px;
            margin: auto;
            display: flex;
            height: 64px;
            line-height: 64px;
            border-bottom: 1px solid #cccccc;
            flex-flow: row nowrap;
            justify-content: space-between;
            cursor: pointer;
 
            .item-img {
                margin-left: 5px;
                display: flex;
 
                img {
                    margin-top: 12px;
                    width: 40px;
                    height: 40px;
                    background: #2389ef;
                    border-radius: 84px 84px 84px 84px;
                    opacity: 1;
                }
 
                span {
                    margin-left: 11px;
                    font-size: 14px;
                    font-weight: 400;
                    color: #ffffff;
                }
            }
 
            .item-num {
                font-size: 14px;
                font-weight: 400;
                color: #ffffff;
            }
        }
    }
}
 
.plot-detail-popup {
    position: fixed;
    top: 50%;
    left: 50%;
 
    width: 462px;
    height: 262px;
 
    transform: translate(-50%, -50%);
    z-index: 11;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
 
    .close-plot-popup {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: -10px;
        right: -10px;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #ccc;
    }
 
    .header {
        display: flex;
        flex-direction: column;
        padding: 10px 20px;
        height: 80px;
        background: #2cd2a9;
        color: #fff;
        border-radius: 8px 8px 0 0;
        box-sizing: border-box;
 
        & > div {
            flex: 1;
            display: flex;
            align-items: center;
        }
 
        .plot-name {
            & > div {
                display: flex;
                align-items: center;
            }
 
            .edit-btn {
                cursor: pointer;
            }
 
            .edit-name {
                width: 100%;
                background: rgba(0, 0, 0, 0.15);
                border-radius: 4px;
 
                .btn-grounp {
                    margin-right: 15px;
                    display: flex;
                    align-items: center;
                    justify-content: space-around;
                    width: 80px;
                    font-size: 14px;
                }
            }
        }
 
        .plot-area-type {
            justify-content: space-between;
            font-size: 14px;
 
            .l {
                color: #e7f7f3;
 
                .type {
                    padding: 2px 10px;
                    border-radius: 11px;
                    background-color: #31bd9a;
                }
            }
 
            .r {
                cursor: pointer;
            }
        }
    }
 
    .body {
        padding: 10px 20px;
        height: calc(100% - 80px);
        background: rgba(0, 0, 0, 0);
        box-sizing: border-box;
        overflow-x: hidden;
        overflow-y: auto;
        border-radius: 0 0 8px 8px;
 
        .list:first-child {
            margin: 0;
        }
 
        .list {
            margin-top: 10px;
            padding: 0 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 50px;
            background: #fff;
            font-size: 14px;
 
            .l {
                display: flex;
                align-items: center;
                color: #2cd2a9;
 
                img {
                    margin-right: 10px;
                    width: 30px;
                    height: 30px;
                }
            }
 
            .r {
                color: #999;
            }
        }
    }
}
</style>