| | |
| | | var url = null; |
| | | var uploadUrl = null; |
| | | var deptId = null; |
| | | var PatrolList = null; |
| | | var ImgFile = null; |
| | | var dateTime; |
| | | var longitude; //百度地图(BD-09)经度 |
| | | var latitude; //百度地图(BD-09)纬度 |
| | | var x_pi = 3.14159265358979324 * 3000.0 / 180.0; |
| | | var pi = 3.1415926535897932384626; |
| | | var a = 6378245.0; |
| | | var ee = 0.00669342162296594323; |
| | | var longitude; //高德地图(GCJ-02)经度 |
| | | var latitude; //高德地图(GCJ-02)纬度 |
| | | var X_PI = 3.1415926535897932384626 * 3000.0 / 180.0; |
| | | // 定义常量 |
| | | var PI = 3.1415926535897932384626; |
| | | var AXIS = 6378245.0; // 地球长半轴 |
| | | var OFFSET = 0.00669342162296594323; // 扁率 |
| | | |
| | | //电子巡更记录 |
| | | var data = { |
| | | "interfaceId": "5601", |
| | | "outId": "10601", |
| | | "interfaceId": "5105", |
| | | "outId": "10105", |
| | | "reqDateTime": new Date(), |
| | | "tokenAuth": "", |
| | | "data": { |
| | |
| | | }; |
| | | //电子巡更打卡 |
| | | var data1 = { |
| | | "interfaceId": "5602", |
| | | "outId": "10602", |
| | | "interfaceId": "5106", |
| | | "outId": "10106", |
| | | "reqDateTime": new Date(), |
| | | "tokenAuth": "", |
| | | "data": { |
| | |
| | | }; |
| | | //巡更照片查看 |
| | | var data2 = { |
| | | "interfaceId": "5603", |
| | | "outId": "10603", |
| | | "interfaceId": "5107", |
| | | "outId": "10107", |
| | | "reqDateTime": new Date(), |
| | | "tokenAuth": "", |
| | | "data": { |
| | |
| | | function init() { |
| | | var user = JSON.parse(localStorage.getItem('user')); |
| | | var selectDeptId = JSON.parse(localStorage.getItem('selectDeptId')); |
| | | url = user.url + "/api-phone/v35/gateway"; |
| | | uploadUrl = user.url + "/api-phone/v35/upload-img" |
| | | url = user.url + "/api/phone/v1/gateway"; |
| | | uploadUrl = user.url + "/api/phone/v1/patrol-img"; |
| | | data.tokenAuth = user.tokenAuth; |
| | | data1.tokenAuth = user.tokenAuth; |
| | | data1.data.userName = user.cname; |
| | | data2.tokenAuth = user.tokenAuth; |
| | | data.data.deptId = selectDeptId; |
| | | data1.data.deptId = selectDeptId; |
| | | |
| | | deptId = selectDeptId; |
| | | if(deptId == null){ |
| | | deptId = user.deptId |
| | | } |
| | | data.data.deptId = deptId; |
| | | data1.data.deptId = deptId; |
| | | dateTime = getDate(new Date()) |
| | | document.getElementById("date").value = dateTime; |
| | | if(user.userType != "30"){ |
| | | document.getElementById('cameraImgBtn').remove(); |
| | | } |
| | | //获取巡更记录 |
| | | getPatrolList() |
| | | |
| | |
| | | function getPatrolList() { |
| | | //赋值参数的日期 |
| | | data.data.dateTime = dateTime; |
| | | console.log(JSON.stringify(data.data), "电子巡更记录", "security-patrol") |
| | | mui.ajax(url, { |
| | | type: "POST", |
| | | dataType: "json", |
| | |
| | | html += '<div class="date">' + item.createTime + '</div><div class="r-btn" id = "' + item.id + |
| | | '">查看照片</div></div>'; |
| | | html += '<div class="cards"><div class="cd"><div class="con user">' |
| | | html += '<div class="tit">打卡人</div><div class="txt">' + item.userName + '</div></div></div>'; |
| | | html += '<div class="tit">打卡人</div><div class="txt">' + item.createBy + '</div></div></div>'; |
| | | html += '<div class="cd"><div class="con loc"><div class="tit">坐标</div>' |
| | | html += '<div class="txt">' + item.longitude + ', ' + item.latitude + |
| | | '</div></div></div></div></div></li>' |
| | | }) |
| | | } else { |
| | | html += '<li><div class="item"><div class="top">' |
| | | html += '<div class="date">暂无巡更记录</div><div class="r-btn" id = "0">查看照片</div></div>'; |
| | | html += '<div class="cards"><div class="cd"><div class="con user">' |
| | | html += '<div class="tit">打卡人</div><div class="txt">--</div></div></div>'; |
| | | html += '<div class="cd"><div class="con loc"><div class="tit">坐标</div>' |
| | | html += '<div class="txt">0, 0</div></div></div></div></div></li>' |
| | | html += |
| | | '<li><div class="item"><div style="text-align: center;font-size: 20px;color:#dd524d;padding-top: 16px;">暂无巡检记录信息</div></div></li>'; |
| | | } |
| | | $("#recordList").html(html) |
| | | } |
| | |
| | | success: function(result) { |
| | | if (result.code == "0000") { |
| | | ImgFile = result.data; |
| | | var html = '<img src="' + ImgFile.base64Img + '" alt="" class="img" />'; |
| | | var html = '<img src="' + ImgFile.imgName + '" alt="" class="img" />'; |
| | | $('#viewerImg').html(html); |
| | | } else { |
| | | // var html = '<img src="" alt="" class="img" />'; |
| | |
| | | |
| | | //上传照片 |
| | | function uploadImg(path) { |
| | | console.log("patrol") |
| | | //转圈等待框 |
| | | var wt = plus.nativeUI.showWaiting(); |
| | | //上传 |
| | |
| | | } |
| | | }); |
| | | //业务类型 |
| | | task.addData("bizType", "02"); |
| | | task.addData("deptId", deptId); |
| | | //图片信息 |
| | | task.addFile(path, { |
| | | key: "uploadkey" |
| | |
| | | if (result.code == "0000") { |
| | | // mui.toast(result.msg); |
| | | setInterval(getPatrolList(), 500) |
| | | |
| | | } else { |
| | | mui.toast(result.msg); |
| | | } |
| | |
| | | } |
| | | |
| | | // function getLatLon() { |
| | | // console.log("2") |
| | | // plus.geolocation.getCurrentPosition(function(position) { |
| | | // longitude = position.coords.longitude; // 经度 |
| | | // latitude = position.coords.latitude; // 纬度 |
| | |
| | | function getLatLon() { |
| | | plus.geolocation.getCurrentPosition(showLocation, function(e) { |
| | | mui.alert("获取定位信息失败,请先打开定位开关!", '提示', ["确定"], function() {}, "div"); |
| | | }, { |
| | | geocode: true |
| | | }); |
| | | },{ geocode: false}); |
| | | |
| | | } |
| | | |
| | | //处理定位后的信息 |
| | | function showLocation(r) { |
| | | var bd09 = ""; |
| | | if (r.coordsType == 'gcj02') { |
| | | if (r.coordsType == 'bd09') { |
| | | //国测局坐标转百度坐标 |
| | | bd09 = gcj02_To_Bd09(r.coords.longitude, r.coords.latitude); |
| | | } else if (r.coordsType == 'wgs84') { |
| | | //wgs84转百度坐标 |
| | | bd09 = wgs84_To_Bd09(r.coords.longitude, r.coords.latitude); |
| | | bd09 = wgs84_To_Gcj02(r.coords.longitude, r.coords.latitude); |
| | | } else { |
| | | bd09 = r.coords.longitude + "," + r.coords.latitude |
| | | } |
| | |
| | | ret += (20.0 * Math.sin(lon * pi) + 40.0 * Math.sin(lon / 3.0 * pi)) * 2.0 / 3.0; |
| | | ret += (150.0 * Math.sin(lon / 12.0 * pi) + 300.0 * Math.sin(lon / 30.0 * pi)) * 2.0 / 3.0; |
| | | return ret; |
| | | } |
| | | |
| | | //获取定位 |
| | | function getLatLon() { |
| | | plus.geolocation.getCurrentPosition(showLocation, function(e) { |
| | | mui.alert("获取定位信息失败,请先打开定位开关!", '提示', ["确定"], function() {}, "div"); |
| | | },{ geocode: false}); |
| | | |
| | | } |
| | | |
| | | //处理定位后的信息 |
| | | function showLocation(r) { |
| | | console.log(r.coordsType) |
| | | var gcj02 = ""; |
| | | if (r.coordsType == 'bd09') { |
| | | //国测局坐标转百度坐标 |
| | | gcj02 = bd09_To_Gcj02(r.coords.longitude, r.coords.latitude); |
| | | } else if (r.coordsType == 'wgs84') { |
| | | //wgs84转百度坐标 |
| | | gcj02 = wgs84_To_Gcj02(r.coords.longitude, r.coords.latitude); |
| | | } else { |
| | | gcj02 = r.coords.longitude + "," + r.coords.latitude |
| | | } |
| | | var location = gcj02.split(","); |
| | | longitude = location[0]; |
| | | latitude = location[1]; |
| | | } |
| | | |
| | | /** |
| | | * WGS84转GCJ02(GPS坐标转火星坐标) |
| | | * @param {number} lng - WGS84经度 |
| | | * @param {number} lat - WGS84纬度 |
| | | * @returns {Object} 包含lng, lat的GCJ02坐标 |
| | | */ |
| | | function wgs84_To_Gcj02(lng, lat) { |
| | | if (outOfChina(lng, lat)) { |
| | | return { lng, lat }; |
| | | } |
| | | |
| | | var dLat = transformLat(lng - 105.0, lat - 35.0); |
| | | var dLng = transformLng(lng - 105.0, lat - 35.0); |
| | | |
| | | var radLat = lat / 180.0 * PI; |
| | | var magic = Math.sin(radLat); |
| | | magic = 1 - OFFSET * magic * magic; |
| | | |
| | | var sqrtMagic = Math.sqrt(magic); |
| | | dLat = (dLat * 180.0) / ((AXIS * (1 - OFFSET)) / (magic * sqrtMagic) * PI); |
| | | dLng = (dLng * 180.0) / (AXIS / sqrtMagic * Math.cos(radLat) * PI); |
| | | |
| | | var mgLat = lat + dLat; |
| | | var mgLng = lng + dLng; |
| | | |
| | | return mgLng+","+ mgLat; |
| | | } |
| | | |
| | | /** |
| | | * 判断坐标是否在中国之外 |
| | | */ |
| | | function outOfChina(lng, lat) { |
| | | return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271; |
| | | } |
| | | |
| | | /** |
| | | * 纬度转换 |
| | | */ |
| | | function transformLat(lng, lat) { |
| | | let ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + |
| | | 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng)); |
| | | |
| | | ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * |
| | | Math.sin(2.0 * lng * PI)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.sin(lat * PI) + 40.0 * |
| | | Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0; |
| | | ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * |
| | | Math.sin(lat * PI / 30.0)) * 2.0 / 3.0; |
| | | |
| | | return ret; |
| | | } |
| | | |
| | | /** |
| | | * 经度转换 |
| | | */ |
| | | function transformLng(lng, lat) { |
| | | var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + |
| | | 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng)); |
| | | |
| | | ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * |
| | | Math.sin(2.0 * lng * PI)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.sin(lng * PI) + 40.0 * |
| | | Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0; |
| | | ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * |
| | | Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0; |
| | | |
| | | return ret; |
| | | } |
| | | |
| | | /** |
| | | * BD-09 转 GCJ-02(百度坐标转火星坐标) |
| | | * @param {number} bdLng - 百度经度 |
| | | * @param {number} bdLat - 百度纬度 |
| | | * @returns {Object} 包含lng, lat的GCJ-02坐标 |
| | | */ |
| | | function bd09_To_Gcj02(bdLng, bdLat) { |
| | | var x = bdLng - 0.0065; |
| | | var y = bdLat - 0.006; |
| | | var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI); |
| | | var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI); |
| | | |
| | | var gcjLng = z * Math.cos(theta); |
| | | var gcjLat = z * Math.sin(theta); |
| | | |
| | | return gcjLng+","+ gcjLat ; |
| | | } |