Newer
Older
smartcity_env_front / src / views / device / detailDevice.vue
StephanieGitHub on 27 Jul 2021 6 KB MOD:设备管理、报警阈值管理
<!--设备详情-->
<template>
  <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" :fullscreen="false" width="60%" append-to-body>
    <el-form ref="dataForm" :model="deviceForm" label-well-code="right" size="mini" label-width="100px">
      <div class="form-div">
        <div class="form-left">
          <el-row :gutter="10">
            <el-col :span="24">
              <el-form-item label="设备编号" prop="deviceNo">
                <span class="form-value">{{deviceForm.deviceNo}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="点位名称" prop="deviceName">
                <span class="form-value">{{deviceForm.deviceName}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="24">
              <el-form-item label="详细地址" prop="position">
                <span class="form-value">{{deviceForm.position}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="24">
              <el-form-item label="安装时间" prop="installDate">
                <span class="form-value">{{deviceForm.installDate}}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="24">
              <el-form-item label="备注" prop="notes">
                <span class="form-value">{{deviceForm.notes}}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div class="form-right">
          <map-view ref="map" :center="center">
            <l-marker v-if="marker!=null" :lat-lng="marker" :icon="iconOptions"/>
          </map-view>
        </div>
      </div>
    </el-form>
    <div class="data-div">
      <div class="data-title" style="">
        <div>实时数据(更新时间:{{realData.ts}})</div>
        <div>
          <el-button title="刷新数据" type="text" size="small" icon="el-icon-refresh" @click="fetchRealData()"/>
        </div>
      </div>
      <div v-for="item of dataForm" :key="item.value" class="box-div">
        <div class="box-wrap">
          <div class="title">{{item.name}}</div>
          <div class="value" v-loading="dataLoading">{{realData[item.value]}}<span class="unit">{{item.unit}}</span></div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { addDevice, updateDevice } from '@/api/environment/device'
import { Uploadimg } from '@/api/common'
import { getAreaList, getAreaByDept } from '@/api/system/area'
import ChoosePointDialog from "../mapViews/choosePointDialog";
import DeptSelect from "../../components/DeptSelect/index";
import MapView from "../mapViews/mapView";
import LMarker from "vue2-leaflet/src/components/LMarker";
import { icon } from 'leaflet'

export default {
  name: 'DetailDevice',
  components: {LMarker, MapView, DeptSelect, ChoosePointDialog},
  data() {
    return {
      dialogFormVisible: false, // 对话框是否显示
      dialogStatus: '', // 对话框类型:create,update,detail
      deviceForm: {
        id: '', // id
        deviceNo: '', // 编号
        deviceName: '', // 名称
        areaName: '', // 设备类型
        position: '', // 详细地址
        lng: '', // 经度
        lat: '', // 纬度
        deptName: '', // 权属单位
        installDate: '', // 安装时间
        notes: '' // 备注
      }, // 表单
      dataForm:[
        {name: 'PM2.5', unit:'ug/m³', value:'pm25'},
        {name: 'PM10', unit:'ug/m³', value:'pm10'},
        {name: 'TSP', unit:'ug/m³', value:'tsp'},
        {name: '噪声', unit:'db', value:'noise'},
        {name: '风速', unit:'m/s', value:'windSpeed'},
        {name: '风力', unit:'级', value:'windPower'},
        {name: '风向', unit:'°', value:'windDirection'},
        {name: '温度', unit:'℃', value:'temperature'},
        {name: '湿度', unit:'%RH', value:'humidity'},
        {name: '气压', unit:'kpa', value:'pressure'},
      ], // 数据表格式
      realData:{}, // 实时数据
      dialogTitle: '设备详情', // 表头显示标题
      center: null,
      marker:null,
      dataLoading: false,
      iconOptions: icon({
        iconUrl: require('../../assets/icons/icon-position.png'), // 图片路径
        iconSize: [32], // 图片大小
        iconAnchor: [16, 32] // 偏移x,y,针对图片的左上角
      }) // 图标配置
    }
  },
  created() {
  },
  methods: {
    /**
     * 初始化对话框
     * @param dialogStatus 对话框类型
     * @param dialogFormVisible 对话框是否可见
     * @param row 内容参数(编辑和详情需要)
     */
    initDialog: function(row = null) {
      this.dialogFormVisible = true
      if(row){
        this.deviceForm = row
        this.title = row.deviceNo+'设备详情'
        if(row.lng && row.lat){
          const lat = parseFloat(row.lat)
          const lng = parseFloat(row.lng)
          this.marker = L.latLng(lat, lng)
          this.center = L.latLng(lat, lng)
        }
        this.fetchRealData()
      }
    },
    fetchRealData(){
      const deviceNo = this.deviceForm.deviceNo
      this.dataLoading = true
      // TODO: 请求数据
      this.realData = {
        pm25:13.4,
        pm10:16.1,
        tsp:21.6,
        noise:70.8,
        windSpeed:0.0,
        windDirection:233.0,
        windPower:0.0,
        temperature:30.4,
        humidity:58.1,
        pressure:100.4,
        ts:'2021-07-27 09:15:00 '
      }
      this.dataLoading = false
    },
    cancel: function() {
      this.dialogFormVisible = false
      this.$emit('watchChild')
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .el-select{
    width: 100%;
  }
  .el-date-editor{
    width: 100%;
  }
  .form-div{
    width:100%;
    height:100%;
    display:flex;
    justify-content: space-between;
  }
  .form-left{
    flex:1;
    height:100%;
  }
  .form-right{
    flex:1;
    height:230px;
    .avatar{
      margin-bottom: 10px;
    }
    text-align: center;
  }
  .data-div{
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    .data-title{
      width: 100%;
      padding:10px;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .box-div{
      width:20%;
      padding:5px;
      .box-wrap{
        box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
        border: 1px solid #f0f0f0;
        padding: 10px 5px;
        .title{
          line-height: 2;
          font-size:16px;
          font-weight: 400;
        }
        .value{
          font-size: 18px;
          font-weight:800;
          line-height: 1.5;
          .unit{
            margin-left: 5px;
            font-size: 14px;
            font-weight: 400;
          }
        }
      }

    }
  }
</style>