| var url = null; | 
| var uploadUrl = null; | 
| var PatrolList = null; | 
| var ImgFile = null; | 
| var dateTime; | 
| var longitude = null; //百度地图(BD-09)经度 | 
| var latitude = null; //百度地图(BD-09)纬度 | 
| //电子巡更记录 | 
| var data = { | 
|     "interfaceId": "5601", | 
|     "outId": "10601", | 
|     "reqDateTime": new Date(), | 
|     "tokenAuth": "", | 
|     "data": { | 
|         "deptId": "", | 
|         "dataTime": "", | 
|     } | 
| }; | 
| //电子巡更打卡 | 
| var data1 = { | 
|     "interfaceId": "5602", | 
|     "outId": "10602", | 
|     "reqDateTime": new Date(), | 
|     "tokenAuth": "", | 
|     "data": { | 
|         "deptId": "", | 
|         "latitude": "", | 
|         "longitude": "", | 
|         "imgName": "", | 
|     } | 
| }; | 
| //巡更照片查看 | 
| var data2 = { | 
|     "interfaceId": "5603", | 
|     "outId": "10603", | 
|     "reqDateTime": new Date(), | 
|     "tokenAuth": "", | 
|     "data": { | 
|         "id": "", | 
|     } | 
| }; | 
|   | 
| 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" | 
|     data.tokenAuth = user.tokenAuth; | 
|     data1.tokenAuth = user.tokenAuth; | 
|     data2.tokenAuth = user.tokenAuth; | 
|     data.data.deptId = selectDeptId; | 
|     data1.data.deptId = selectDeptId; | 
|     dateTime = getDate(new Date()) | 
|     document.getElementById("date").value = dateTime; | 
|     //获取巡更记录 | 
|     getPatrolList() | 
|   | 
| } | 
|   | 
| //默认获取当前日期(yyyy-MM-dd) | 
| function getDate(date) { | 
|     var year = date.getFullYear(); | 
|     var month, day; | 
|     month = date.getMonth() + 1; | 
|     if (month > 0 && month <= 9) { | 
|         month = "0" + month; | 
|     } | 
|     day = date.getDate(); | 
|     if (day > 0 && day <= 9) { | 
|         day = "0" + day; | 
|     } | 
|     return year + "-" + month + "-" + day | 
| } | 
| //加减天数 | 
| function addAndReduceMonth(tag) { | 
|   | 
|     var date = new Date(dateTime); | 
|     date = date.setDate(date.getDate() + tag); | 
|     date = new Date(date); | 
|     dateTime = getDate(date); | 
|     document.getElementById("date").value = dateTime; | 
|     //获取巡更记录 | 
|     getPatrolList() | 
| } | 
|   | 
| //选择日期 | 
| function chooseDate() { | 
|     var dtpicker = new mui.DtPicker({ | 
|         type: "date", //设置日历初始视图模式  | 
|         // beginDate: new Date(2015, 04, 25), //设置开始日期  | 
|         // endDate: new Date(2016, 04, 25), //设置结束日期  | 
|         value: dateTime | 
|     }) | 
|     var time = dateTime; | 
|     dtpicker.show(function(e) { | 
|         dateTime = e.value; | 
|         document.getElementById("date").value = e.value | 
|         if(time != dateTime){ | 
|             getPatrolList(); | 
|         } | 
|     }) | 
| } | 
| //获取巡更记录 | 
| function getPatrolList() { | 
|     //赋值参数的日期 | 
|     data.data.dataTime = dateTime; | 
|     console.log(JSON.stringify(data.data),"电子巡更记录","security-patrol") | 
|     mui.ajax(url, { | 
|         type: "POST", | 
|         dataType: "json", | 
|         crossDomain: true, | 
|         contentType: "application/json;charset=utf-8", | 
|         data: JSON.stringify(data), | 
|         success: function(result) { | 
|             if (result.code == "0000") { | 
|                 PatrolList = result.data; | 
|                 renderPatrol(); | 
|             } else { | 
|                 renderPatrol(); | 
|                 mui.toast(result.msg); | 
|                 // console.log(JSON.stringify(result)) | 
|             } | 
|         }, | 
|         error: function() { | 
|             mui.alert("系统繁忙,请重试!", "提示", ["确定"], function() {}, "div") | 
|         } | 
|     }) | 
|   | 
|     // PatrolList = [{ | 
|     //         "id": "57", | 
|     //         "userName": "程娟", | 
|     //         "longitude": "34.585", | 
|     //         "latitude": "114.235", | 
|     //         "createTime": "1976-03-03 16:41:41" | 
|     //     }, | 
|     //     { | 
|     //         "id": "1", | 
|     //         "userName": "冯军", | 
|     //         "longitude": "34.585", | 
|     //         "latitude": "114.235", | 
|     //         "createTime": "1981-01-06 17:40:24" | 
|     //     }, | 
|     //     { | 
|     //         "id": "99", | 
|     //         "userName": "黎洋", | 
|     //         "longitude": "114.235", | 
|     //         "latitude": "34.585", | 
|     //         "createTime": "1991-04-04 23:06:09" | 
|     //     } | 
|     // ] | 
|   | 
| } | 
|   | 
| function renderPatrol() { | 
|     var html = ''; | 
|     if (PatrolList && PatrolList.length > 0) { | 
|         $.each(PatrolList, function(index, item) { | 
|             html += '<li><div class="item"><div class="top">' | 
|             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="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" style="text-align: center;font-size: 20px;color:#dd524d;padding-top: 18px;">暂无巡更信息</div></li>'; | 
|     } | 
|     $("#recordList").html(html) | 
| } | 
|   | 
| mui('.mui-scroll-wrapper').scroll({ | 
|     indicators: true, //是否显示滚动条 | 
|     deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏 | 
|     bounce: false, //是否启用回弹 | 
|     deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006 | 
| }); | 
|   | 
| mui(".mui-content").on("tap", ".g-date_box .prev", function() { | 
|     var curDate = document.getElementById("date").value; | 
|     addAndReduceMonth(-1) | 
|     // document.getElementById("date").value = e.value | 
| }); | 
| mui(".mui-content").on("tap", ".g-date_box .next", function() { | 
|     var curDate = document.getElementById("date").value; | 
|     addAndReduceMonth(1) | 
|     // document.getElementById("date").value = e.value | 
| }); | 
|   | 
| //查看照片 | 
| mui(".mui-content").on("tap", ".ul-cardb1 li .r-btn", function() { | 
|     var id = this.getAttribute('id'); | 
|     data2.data.id = id; | 
|     mui.ajax(url, { | 
|         type: "POST", | 
|         dataType: "json", | 
|         crossDomain: true, | 
|         contentType: "application/json;charset=utf-8", | 
|         data: JSON.stringify(data2), | 
|         success: function(result) { | 
|             if (result.code == "0000") { | 
|                 ImgFile = result.data; | 
|                 var html = '<img src="' + ImgFile.base64Img + '" alt="" class="img" />'; | 
|                 $('#viewerImg').html(html); | 
|             } else { | 
|                 // var html = '<img src="" alt="" class="img" />'; | 
|                 // $('#viewerImg').html(html); | 
|                 mui.toast(result.msg); | 
|             } | 
|         }, | 
|         error: function() { | 
|             mui.alert("系统繁忙,请重试!", "提示", ["确定"], function() {}, "div") | 
|         } | 
|     }) | 
|     $('.m-pop').css('display', 'flex'); | 
| }); | 
| //关闭照片 | 
| $('.pop-bg,.m-pop .close').click(function(e) { | 
|     e.stopPropagation(); | 
|     $('.m-pop').fadeOut(); | 
| }); | 
|   | 
| //使用相机拍照 | 
| function cameraImg() { | 
|     var cmr = plus.camera.getCamera(); | 
|     cmr.captureImage(function(p) { | 
|         //成功 | 
|         plus.io.resolveLocalFileSystemURL(p, function(entry) { | 
|             var path = entry.toLocalURL(); //获得图片路径 | 
|             uploadImg(path); | 
|         }, function(e) { | 
|             mui.toast("读取拍照图片错误,请重试!"); | 
|         }); | 
|     }, function(e) { | 
|         mui.toast("拍照失败,请重试!"); | 
|     }); | 
| } | 
|   | 
| //上传照片 | 
| function uploadImg(path) { | 
|     //转圈等待框 | 
|     var wt = plus.nativeUI.showWaiting(); | 
|     //上传 | 
|     var task = plus.uploader.createUpload(uploadUrl, { | 
|             method: "POST" | 
|         }, | 
|         function(t, status) { //上传完成 | 
|             if (status == 200) { | 
|                 // var html = ''; | 
|                 var obj = JSON.parse(t.responseText); | 
|                 mui.toast("上传成功!"); | 
|                 data1.data.imgName = obj.data.fileName; | 
|                 //关闭转圈等待框 | 
|                 wt.close(); | 
|                 //电子巡更打卡 | 
|                 patrolClock(); | 
|             } else { | 
|                 mui.toast("上传失败,请重试!"); | 
|                 //关闭转圈等待框 | 
|                 wt.close(); | 
|             } | 
|         }); | 
|     //业务类型 | 
|     task.addData("bizType", "02"); | 
|     //图片信息 | 
|     task.addFile(path, { | 
|         key: "uploadkey" | 
|     }); | 
|     task.start(); | 
| } | 
|   | 
| //电子巡更打卡 | 
| function patrolClock() { | 
|     data1.data.latitude = latitude; | 
|     data1.data.longitude = longitude | 
|     mui.ajax(url, { | 
|         type: "POST", | 
|         dataType: "json", | 
|         crossDomain: true, | 
|         contentType: "application/json;charset=utf-8", | 
|         data: JSON.stringify(data1), | 
|         success: function(result) { | 
|             if (result.code == "0000") { | 
|                 mui.toast(result.msg); | 
|             } else { | 
|                 mui.toast(result.msg); | 
|             } | 
|         }, | 
|         error: function() { | 
|             mui.alert("系统繁忙,请重试!", "提示", ["确定"], function() {}, "div") | 
|         } | 
|     }) | 
| } | 
|   | 
| // function getLatLon() { | 
| //     plus.geolocation.getCurrentPosition(function(position) { | 
| //         longitude = position.coords.longitude; // 经度 | 
| //         latitude = position.coords.latitude; // 纬度 | 
|   | 
| //     }, function(e) { | 
| //         mui.alert("获取定位信息失败,请先打开定位开关!", '提示', ["确定"], function() {}, "div"); | 
| //     }, { | 
| //         geocode: true | 
| //     }); | 
| // } | 
|   | 
|   | 
| //获取定位 | 
| function getLatLon() { | 
|     plus.geolocation.getCurrentPosition(showLocation, function(e) { | 
|         mui.alert("获取定位信息失败,请先打开定位开关!", '提示', ["确定"], function() {}, "div"); | 
|     }, { | 
|         geocode: true | 
|     }); | 
| } | 
|   | 
| //处理定位后的信息 | 
| function showLocation(r) { | 
|     var bd09 = ""; | 
|     if (r.coordsType == 'gcj02') { | 
|         //国测局坐标转百度坐标 | 
|         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); | 
|     } else { | 
|         bd09 = r.coords.longitude + "," + r.coords.latitude | 
|     } | 
|     var location = bd09.split(","); | 
|     longitude = location[0]; | 
|     latitude = location[1]; | 
| } | 
| //国测局坐标(即火星坐标gcj02) 转化为百度坐标(即BD-09) | 
| function gcj02_To_Bd09(gcj_lon, gcj_lat) { | 
|     var x = gcj_lon, | 
|         y = gcj_lat; | 
|     var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi); | 
|     var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi); | 
|     var bd_lon = z * Math.cos(theta) + 0.0065; | 
|     var bd_lat = z * Math.sin(theta) + 0.006; | 
|     return bd_lon + "," + bd_lat; | 
| } | 
| //地球坐标(即wgs84) 转化为百度坐标(即BD-09) | 
| function wgs84_To_Bd09(wgs_lon, wgs_lat) { | 
|     //第一次转换(wgs84转gcj02) | 
|     var dlat = transformlat(wgs_lon - 105.0, wgs_lat - 35.0); | 
|     var dlng = transformlon(wgs_lon - 105.0, wgs_lat - 35.0); | 
|     var radlat = wgs_lat / 180.0 * pi; | 
|     var magic = Math.sin(radlat); | 
|     magic = 1 - ee * magic * magic; | 
|     var sqrtmagic = Math.sqrt(magic); | 
|     dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi); | 
|     dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi); | 
|     var mglat = wgs_lat + dlat; | 
|     var mglng = wgs_lon + dlng; | 
|   | 
|     //第二次转换(gcj02转bd09) | 
|     var z = Math.sqrt(mglng * mglng + mglat * mglat) + 0.00002 * Math.sin(mglat * x_pi); | 
|     var theta = Math.atan2(mglat, mglng) + 0.000003 * Math.cos(mglng * x_pi); | 
|     var bd_lon = z * Math.cos(theta) + 0.0065; | 
|     var bd_lat = z * Math.sin(theta) + 0.006; | 
|     return bd_lon + "," + bd_lat; | 
| } | 
|   | 
| function transformlat(lat, lon) { | 
|     var ret = -100.0 + 2.0 * lon + 3.0 * lat + 0.2 * lat * lat + 0.1 * lon * lat + 0.2 * Math.sqrt(Math.abs(lon)); | 
|     ret += (20.0 * Math.sin(6.0 * lon * pi) + 20.0 * Math.sin(2.0 * lon * 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 transformlon(lat, lon) { | 
|     var ret = 300.0 + lon + 2.0 * lat + 0.1 * lon * lon + 0.1 * lon * lat + 0.1 * Math.sqrt(Math.abs(lon)); | 
|     ret += (20.0 * Math.sin(6.0 * lon * pi) + 20.0 * Math.sin(2.0 * lon * pi)) * 2.0 / 3.0; | 
|     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; | 
| } |