From 082613d446e29e4ec1c16bfaa52345106a498b23 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 08 Nov 2022 09:03:49 +0800
Subject: [PATCH] 农事操作隐藏后四个,地图模式2d改为3d

---
 src/views/mapPattern/index.vue |  414 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 394 insertions(+), 20 deletions(-)

diff --git a/src/views/mapPattern/index.vue b/src/views/mapPattern/index.vue
index 89376b7..d178ba1 100644
--- a/src/views/mapPattern/index.vue
+++ b/src/views/mapPattern/index.vue
@@ -1,6 +1,7 @@
 <template>
-    <div style="position: relative; height: 100%;">
+    <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" />
@@ -22,12 +23,13 @@
                 <span>&nbsp;&nbsp;返回</span>
             </div>
         </div>
+
         <div class="farm-plant">
             <div class="title">
-                <span>种养品种 · {{ this.page.total }}种</span>
+                <span>种养品种 · {{ this.plotPlantBreed.length }}种</span>
             </div>
             <div class="content">
-                <div class="list-item" v-for="(item, index) in farmPlantList" :key="index">
+                <div class="list-item" v-for="(item, index) in plotPlantBreed" :key="index">
                     <div class="item-img">
                         <img :src="item.url" />
                         <span>{{ item.strainName }}</span>
@@ -36,29 +38,36 @@
                 </div>
             </div>
         </div>
+
         <div class="land-info">
             <div class="content">
                 <div>
                     有轮廓的地块:
                     <span
                         style="font-size: 26px;font-weight: bold;color: #5ABF78;"
-                    >{{landIsAreaStatistic[0]}}</span>
+                    >{{landIsAreaStatistic.length > 0 ? landIsAreaStatistic[0] : 0}}</span>
                 </div>
 
                 <div>
                     无轮廓的地块:
                     <span
                         style="font-size: 26px;font-weight: bold;color: #E3B745;"
-                    >{{landIsAreaStatistic[1]}}</span>
+                    >{{landIsAreaStatistic.length > 1 ? landIsAreaStatistic[1] : 0}}</span>
                 </div>
             </div>
         </div>
+
         <div class="farm-land">
             <div class="title">
-                <span>地块 · {{ this.pageLand.total }}种</span>
+                <span>地块 · {{ this.pageLand.total }}个</span>
             </div>
             <div class="content">
-                <div class="list-item" v-for="(item, index) in landList" :key="index">
+                <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>
@@ -67,13 +76,85 @@
                 </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 } from "@/api/land/land"
+import { getList as getLandList, selectCount, getLandIsAreaStatistic, submit } from "@/api/land/land"
 import { getDetails } from "@/api/farm/farm"
 export default {
     components: {
@@ -81,27 +162,54 @@
     data () {
         return {
             page: {
-                pageSize: 10,
+                pageSize: 100,
                 currentPage: 1,
                 total: 0,
             },
             pageLand: {
-                pageSize: 10,
+                pageSize: 100,
                 currentPage: 1,
                 total: 0,
             },
             farmPlantList: [],
+
+            // 数据合并后的种养品种
+            plotPlantBreed: [],
+
+            // 当前地块种养品种
+            cPPBreed: [],
+
+            // 当前地块对应弹框
+            cPShow: false,
+
+            // 当前点击地块详情
+            currentPlotDetails: {},
+            currentPlotName: "",
+
+            // 名称编辑是否显示
+            plotNameEditShow: false,
+
+            plotClickNum: 0,
+
             landList: [],
             farmInfo: {},
             landAreaInfo: {},
-            landIsAreaStatistic: [0, 0],
+            landIsAreaStatistic: [],
         }
 
     },
     computed: {
-        ...mapGetters(["userInfo"]),
+        ...mapGetters(["userInfo", "$farmId"]),
     },
     created () {
+        if (this.$farmId == 0){
+          if (sessionStorage.getItem("myFarmId")){
+            this.$store.commit("SET_FARMID",JSON.parse(sessionStorage.getItem("myFarmId")))
+          }
+        }
+        window.addEventListener('beforeunload', () => {
+          sessionStorage.setItem('myFarmId', JSON.stringify(this.$farmId))
+        })
         //获取种样品列表
         this.getFarmPlantList(this.page)
         //获取地块列表
@@ -116,7 +224,8 @@
     methods: {
         //获取种养品列表
         getFarmPlantList (page, params = {}) {
-            params['farmId'] = this.userInfo.farmId
+            params['farmId'] = this.$farmId
+            params['status'] = 1
             this.loading = true
             getList(
                 page.currentPage,
@@ -126,13 +235,51 @@
                 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
+                        })
+                    }
+                })
+
+                arr.forEach((e)=>{
+                    e.area = e.area.toFixed(3)
+                })
+
+                this.plotPlantBreed = arr
+
                 this.loading = false
+
+
+
                 // this.selectionClear()
             })
         },
         //获取地块列表
         getLandList (page, params = {}) {
-            params['farmId'] = this.userInfo.farmId
+          const that = this
+            params['farmId'] = this.$farmId
             params['tenantId'] = this.userInfo.tenant_id
             this.loading = true
             getLandList(
@@ -152,8 +299,7 @@
                         arr.forEach(it => {
                             brr.push(it.split(' '))
                         })
-
-                        this.$refs.plotMap.addPlotPolygon(brr, item)
+                      that.$refs.plotMap.addPlotPolygon(brr, item)
                     }
                 })
 
@@ -165,31 +311,128 @@
         },
         //返回上一页
         goToBack () {
+            this.$EventBus.$emit("getFarmObj", this.farmInfo);
             this.$router.go(-1)
         },
         //获取农场信息
         getFarmInfo () {
             var that = this
-            getDetails(this.userInfo.farmId).then(res => {
+            getDetails(this.$farmId).then(res => {
                 that.farmInfo = res.data.data
             })
         },
         //获取统计面积信息
         getLandCount () {
-            selectCount(this.userInfo.farmId).then(res => {
+            selectCount(this.$farmId).then(res => {
                 this.landAreaInfo = res.data.data
             })
         },
         //获取地块轮廓统计信息
         getLandIsAreaStatistic () {
-            getLandIsAreaStatistic(this.userInfo.farmId).then(res => {
-                console.log(res)
+            getLandIsAreaStatistic(this.$farmId).then(res => {
                 this.landIsAreaStatistic = res.data.data
+            })
+        },
+
+        // 地块定位
+        setCenter (item) {
+            console.log(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) {
+                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;
@@ -414,6 +657,7 @@
             border-bottom: 1px solid #cccccc;
             flex-flow: row nowrap;
             justify-content: space-between;
+            cursor: pointer;
 
             .item-img {
                 margin-left: 5px;
@@ -444,4 +688,134 @@
         }
     }
 }
+
+.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>

--
Gitblit v1.9.3