<template> <view class=""> <view class="check-message-detail"> <view class="detail-content"> <view class="detail-item" > <text class="title">设备类型</text> <text>{{info.deviceTypeName}}</text> </view> <view class="detail-item" > <text class="title">设备编号</text> <text>{{info.devcode}}</text> </view> <view class="detail-item" > <text class="title">设备位置</text> <text>{{info.position}}</text> </view> <view class="detail-item" > <text class="title">井编号</text> <text>{{wellInfo.wellCode}}</text> </view> <view class="detail-item" > <text class="title">井类型</text> <text>{{wellInfo.wellTypeName}}</text> </view> <view class="detail-item" > <text class="title">井名称</text> <text>{{wellInfo.wellName}}</text> </view> <view class="detail-item" > <text class="title">设备状态</text> <text :style="{color: info.color}">{{info.onlineStateName}}</text> </view> <view class="detail-item" > <text class="title">安装时间</text> <text>{{info.installDate}}</text> </view> <view class="detail-item" > <text class="title">设备图片</text> <image :src="imgUrl" mode="widthFix" style="width: 160rpx;"></image> </view> <view class="detail-item" > <text class="title">设备经纬度</text> <view> <view> {{wellInfo.coordinateY}} </view> <view> {{wellInfo.coordinateX}} </view> </view> </view> <view class="map-info"> <map :show-location='true' :scale="scale" style="width: 100%; height:100%;" :latitude="latitude" :longitude="longitude" :markers="marker"></map> </view> </view> </view> </view> </template> <script> import { getDeviceDetail, getWellInfo } from '@/api/check.js' export default { data() { return { latitude: '',//纬度 longitude: '',//经度 marker: [ { id:0, latitude: '',//纬度 longitude: '',//经度 iconPath: '../../static/checkIcon/manhole-line.png', //显示的图标 rotate:0, // 旋转度数 width:30, //宽 height:30, //高 // title:'我在这里',//标注点名 alpha:0.5, //透明度 callout:{//自定义标记点上方的气泡窗口 点击有效 content:'',//文本 color:'#ffffff',//文字颜色 fontSize:14,//文本大小 borderRadius:15,//边框圆角 borderWidth:'10', bgColor:'#0ca2e8',//背景颜色 display:'ALWAYS',//常显 }, }], info: uni.getStorageSync('checkrow') ||{}, wellInfo: {}, imgUrl:'', scale:3 ,// 缩放地图 } }, async onLoad() { // 获取到自己的位置 await wx.getLocation({ type:'gcj02', success:(res)=>{ this.latitude = res.latitude; this.longitude = res.longitude; }, fail: (err) => { console.log(err,'地理位置错误') } }) // 获取到井详情 const res = await getWellInfo({id:this.info.wellId}) this.wellInfo = res if(this.info.deviceTypeName === '燃气智能监测终端'){ this.imgUrl = '../../static/checkIcon/gas-terminal.jpg' }else if (this.info.deviceTypeName === '井盖状态监测仪') { this.imgUrl = '../../static/checkIcon/manhole.jpg' }else if (this.info.deviceTypeName === '液位监测仪') { this.imgUrl = '../../static/checkIcon/liquid.jpg' } // 将获取的值赋值给markers this.marker[0].latitude = res.latGaode this.marker[0].longitude = res.lngGaode this.marker[0].callout.content = this.info.deviceTypeName // 根据不同设备换取不同的地图图标 if (this.info.onlineStateName === '在线') { if(this.info.deviceTypeName === '燃气智能监测终端'){ this.marker[0].iconPath = '../../static/checkIcon/gas-line.png' }else if (this.info.deviceTypeName === '井盖状态监测仪') { this.marker[0].iconPath = '../../static/checkIcon/manhole-line.png' }else if (this.info.deviceTypeName === '液位监测仪') { this.marker[0].iconPath = '../../static/checkIcon/level-line.png' } }else if (this.info.onlineStateName === '离线'){ if(this.info.deviceTypeName === '燃气智能监测终端'){ this.marker[0].iconPath = '../../static/checkIcon/gas-offine.png' }else if (this.info.deviceTypeName === '井盖状态监测仪') { this.marker[0].iconPath = '../../static/checkIcon/manhole-offline.png' }else if (this.info.deviceTypeName === '液位监测仪') { this.marker[0].iconPath = '../../static/checkIcon/level-offline.png' } }else { if(this.info.deviceTypeName === '燃气智能监测终端'){ this.marker[0].iconPath = '../../static/checkIcon/gas-report.png' }else if (this.info.deviceTypeName === '井盖状态监测仪') { this.marker[0].iconPath = '../../static/checkIcon/manhole-report.png' }else if (this.info.deviceTypeName === '液位监测仪') { this.marker[0].iconPath = '../../static/checkIcon/level-report.png' } } }, watch: { // 算出地图缩放 longitude: { handler (newName, oldName) { let coordinateArr = [] coordinateArr.push(Number(this.marker[0].longitude)) // 点位经度 coordinateArr.push(this.longitude) // 自己位置经度 coordinateArr = coordinateArr.sort((max,next) => { // 排序 return next - max }) let scaleNumber = coordinateArr[0] - coordinateArr[1] // 求距离 if(Math.ceil(scaleNumber) === 1){ this.scale = Math.floor((20 - 10 + 1) *Math.random()) + 10; // 随机缩放10到20 }else if (Math.ceil(scaleNumber) === 2) { this.scale = Math.floor((5) *Math.random()) + 5; // 随机缩放5到10 }else if (Math.ceil(scaleNumber) > 2) { this.scale = Math.floor((3) *Math.random()) + 2; // 随机缩放3到5 } }, immediate: true } } } </script> <style lang="scss" scoped> .check-message-detail { padding: 18rpx; height: 100%; .title { font-weight: 600; } .detail-content { padding: 22rpx; background-color: #fff; border-radius: 10rpx; } .detail-item { display: flex; justify-content: space-between; margin-bottom: 44rpx; } } .map-info { width: 100%; height: 460rpx; } </style>