派生自 wuyushui/SewerAndRainNetwork

陈泽平
2021-05-31 38bcd6306f20787e394347a34e50fcf80b265fc6
src/components/base-page/enterprise-emergency/events-reported/ReportLocationPoint.vue
@@ -1,78 +1,58 @@
<template>
    <div class="location-lon-and-lat">
        <!--        <el-row>-->
        <!--            <el-form :model="lonlatpos" label-width="60px">-->
        <!--                <el-col :span="12">-->
        <!--                    <el-form-item label="经度:">-->
        <!--                        <el-input type="text" v-model="lonlatpos.longPos"></el-input>-->
        <!--                    </el-form-item>-->
        <!--                </el-col>-->
        <!--                <el-col :span="12">-->
        <!--                    <el-form-item label="纬度:">-->
        <!--                        <el-input type="text" v-model="lonlatpos.latPos"></el-input>-->
        <!--                    </el-form-item>-->
        <!--                </el-col>-->
        <!--            </el-form>-->
        <!--            <el-row>-->
        <!--                <el-col :span="12" style="text-align: center;margin: 5px 0">-->
        <!--                    <el-button type="primary" size="small" @click="mapPoints">精确定位</el-button>-->
        <!--                </el-col>-->
        <!--                <el-col :span="12" style="text-align: center;margin: 5px 0">-->
        <!--                    <el-button type="primary" size="small" @click="dataPoints">数据识取</el-button>-->
        <!--                </el-col>-->
        <!--            </el-row>-->
        <!--        </el-row>-->
        <el-form :model="lonlatpos" label-width="60px">
            <el-row class="pipe-line-search">
                <el-col :span="12">
                    <el-form-item label="经度:">
                        <el-input v-model="lonlatpos.longPos"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="纬度:">
                        <el-input v-model="lonlatpos.latPos"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-row>
            <el-col :span="12" style="text-align: center;margin: 5px 0">
                <el-button type="primary" size="small" @click="mapPoints">精确定位</el-button>
            </el-col>
            <el-col :span="12" style="text-align: center;margin: 5px 0">
                <el-button type="primary" size="small" @click="dataPoints">数据识取</el-button>
            </el-col>
        </el-row>
        <el-row class="place-bottom" style="text-align: right;margin: 5px">
            <el-button type="primary" @click="confirm" size="small">确认</el-button>
        </el-row>
    </div>
  <div class="location-lon-and-lat">
    <el-form :model="positionLocationForm" label-width="60px">
      <el-row class="pipe-line-search">
        <el-col :span="12">
          <el-form-item label="经度:">
            <el-input v-model="positionLocationForm.longPos"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="纬度:">
            <el-input v-model="positionLocationForm.latPos"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <el-col :span="12" style="text-align: center;margin: 5px 0">
        <el-button type="primary" size="small" @click="mapPoints">精确定位</el-button>
      </el-col>
      <el-col :span="12" style="text-align: center;margin: 5px 0">
        <el-button type="primary" size="small" @click="dataPoints">位置拾取</el-button>
      </el-col>
    </el-row>
    <el-row style="text-align: right;margin: 5px">
      <el-button type="primary" @click="confirm" size="small">确认</el-button>
    </el-row>
  </div>
</template>
<script>
import { pulseEffect } from '../../../../utils/utils'
import iconUrl from '../../../../../public/assets/images/map/marker-icon.png'
import eventBus from '../../../../eventBus'
import { publicLocationStore } from './ReportLocation'
export default {
  name: 'ReportLocationPoint',
  data () {
    return {
      // 经纬度定位
      lonlatpos: {
      positionLocationForm: {
        longPos: '',
        latPos: ''
      },
      marker: null
      marker: window.L.layerGroup().addTo(window.map),
      layersGroupArrList: []
    }
  },
  methods: {
    // 精确定位
    mapPoints () {
      window.map.on('click', (e) => {
        this.lonlatpos.longPos = parseFloat(e.latlng.lng).toFixed(8)
        this.lonlatpos.latPos = parseFloat(e.latlng.lat).toFixed(8)
        this.positionLocationForm.longPos = parseFloat(e.latlng.lng).toFixed(8)
        this.positionLocationForm.latPos = parseFloat(e.latlng.lat).toFixed(8)
        const as = [e.latlng.lat, e.latlng.lng]
        // console.log(as)
        window.map.setView(as, 17)
@@ -84,62 +64,64 @@
            iconAnchor: [13, 20]
          })
        })
        // 添加点数据
        window.map.addLayer(this.marker)
        this.layersGroupArrList.push(this.marker)
        // 事件结束 关闭点击事件
        window.map.off('click')
      })
    },
    // 通过数据定位
    dataPoints () {
      // this.lonlatpos.latPos = ''
      // this.lonlatpos.longPos = ''
      if (this.lonlatpos.latPos !== '' && this.lonlatpos.longPos !== '') {
        const as = [this.lonlatpos.latPos, this.lonlatpos.longPos]
      if (this.positionLocationForm.latPos !== '' && this.positionLocationForm.longPos !== '') {
        const as = [this.positionLocationForm.latPos, this.positionLocationForm.longPos]
        window.map.setView(as, 17)
        pulseEffect(as)
        this.marker = window.L.marker(as, {
          icon: window.L.icon({
            iconUrl: iconUrl,
            iconSize: [30, 40],
            iconAnchor: [15, 20]
            iconSize: [26, 40],
            iconAnchor: [13, 20]
          })
        })
        window.map.addLayer(this.marker)
        this.layersGroupArrList.push(this.marker)
      } else {
        this.$message('请输入识取经纬度')
      }
    },
    // 点击确认按钮事件
    confirm () {
      // 循环数据 清除 图层添加的点数据
      for (let i = 0; i < this.layersGroupArrList.length; i++) {
        window.map.removeLayer(this.layersGroupArrList[i])
      }
      window.mapManager.clearHighlight()
      window.map.removeLayer(this.marker)
      // window.map.removeLayer(this.marker)
      eventBus.$emit('location-setChange', true)
      this.lonlatpos.longPos = ''
      this.lonlatpos.latPos = ''
      // 事件上报 位置信息 存储数据库
      const data = {
        ID: '',
        EventID: '',
        EventPipeline: '',
        EventPipeSeg: '',
        EventAffType: '',
        EventAffCode: '',
        EventAffPointNum: '',
        EventPosX: this.positionLocationForm.longPos,
        EventPosY: this.positionLocationForm.latPos,
        AcquisitionPeople: '',
        AcquisitionDate: ''
      }
      // 通过方法 存储数据 进行 数据库存储数据
      publicLocationStore(data)
      // 确定点数据 位置信息 进行数据 的置空
      this.positionLocationForm.longPos = ''
      this.positionLocationForm.latPos = ''
    }
  }
}
</script>
<style lang="less" scoped>
    .place-box {
        display: flex;
        align-items: center;
        justify-content: space-around;
    }
    .place {
        text-align: center;
        .place-top {
            display: flex;
            align-items: center;
            justify-content: space-around;
            .place-right {
                .el-button {
                    margin: 15px;
                }
            }
        }
    }
</style>