daka(e) { var that = this; var layer = { msg: function(txt) { that.messageshow(txt); } } var $ = { ajax: function(e) { that.uniajax(e); }, } var temp = that.btntxt; var state = that.wxstate; if (state == 1) { ceshi(); } else { layer.msg("微信地理位置正在加载,请等待加载完成再次点击。"); var data = { AccountNo:0, SignTime:0, Longitude:0, Latitude:0, Adress:"", Remark:"" }; var result= [123,60]; data.Longitude = result[0]; data.Latitude = result[1]; data.Adress ="测试地址"; data.Remark = that.Remark; if(data.Remark.length<1){ layer.msg("请输入备注!"); return; } //获取用户信息 var userinfo=uni.getStorageSync('op'+that.edition); data.AccountNo = userinfo.UserName; savedata(data); return false; } //begin 保存数据 function convercoordinate(longitude,latitude,callback){ //转换地图坐标系 $.ajax({ url: ' https://restapi.amap.com/v3/assistant/coordinate/convert?locations=' + longitude + ',' + latitude + '&coordsys=gps&output=json&key=887692dac57ab8b8be9ebd2d01379dde', dataType: 'JSON', method: 'GET', success: function(data) { console.log(data); data = data.data; if (data.status == 1) { var result = data.locations.split(","); console.log(result[0] + '***' + result[1]); //输出转换后的坐标 callback(result); } } }); } function getconvercoordinateAddress(result,callback) { //获取详细地址 $.ajax({ url: 'https://restapi.amap.com/v3/geocode/regeo?output=json&location=' + result[0] + ',' + result[1] + '&key=887692dac57ab8b8be9ebd2d01379dde&radius=1000&extensions=all', dataType: 'JSON', method: 'GET', success: function (data) { console.log(data); var address = data.regeocode.formatted_address; callback(address); } }); } function savedata(data){ function ToFormData(d){var c=new FormData();var b=Object.keys(d);for(var a=0;a<b.length;a++){c.append(b[a],d[b[a]]||"")}return c}; var data = ToFormData(data); $.ajax({ url: 'http://localhost:11519/API/BFKQ/Add', dataType: 'JSON', method: 'POST', data:data, success: function (res) { //debugger; if(res.msg=="添加成功") { layer.msg("打卡成功!"); that.loadList(); }else{ layer.msg("打卡失败!"); } } }); } //end function ceshi() { console.log(1111); //微信获取地址开始 //根据微信信息获取地址位置 wx.getLocation({ type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function(res) { that.btntxt = "正在获取位置信息...请稍候..."; var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90 var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。 console.log(longitude + ',' + latitude); //--- convercoordinate(longitude,latitude,function(result){ getconvercoordinateAddress (result,function(address){ var data = { AccountNo:0, SignTime:0, Longitude:0, Latitude:0, Adress:"" }; data.Longitude = result[0]; data.Latitude = result[1]; data.Adress =address; //获取用户信息 var userinfo=uni.getStorageSync('op'+that.edition); data.AccountNo = userinfo.UserName; savedata(data); }) }); }, fail: function(res) { layer.msg("获取当前位置错误,请检查是否打开获取地理位置权限"); that.btntxt = temp; }, cancel: function(res) { layer.msg("获取当前位置错误,请检查是否打开获取地理位置权限"); } }); //微信获取地址结束 }; },
mounted() { function loadjs(src, callback) { var t = document.getElementsByTagName("script"); for (var i = 0; i < t.length; i++) { var dd = t[i].src; if(dd.indexOf('jweixin-1.4.0.js')!=-1 ||dd.indexOf('maps?v=1.4.4')!=-1 ) { return; } } var tag = document.createElement("script"); tag.type = 'text/javascript'; tag.src = src; tag.onload = function(e, b, c) { callback(); }; document.head.appendChild(tag); } var that = this; loadjs("http://webapi.amap.com/maps?v=1.4.4&key=887692dac57ab8b8be9ebd2d01379dde", function() { loadjs("../../static/wxjs/jweixin-1.4.0.js", function() { //初始化001 wx //var state = 0; wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: 'xxx', // 必填,公众号的唯一标识 timestamp: 13456789, // 必填,生成签名的时间戳 nonceStr: 'xxx', // 必填,生成签名的随机串 signature: '123465789', // 必填,签名 jsApiList: ['checkJsApi', 'getLocation', 'getNetworkType' ] // 必填,需要使用的JS接口列表 }); wx.ready(function() { wx.checkJsApi({ jsApiList: ['getLocation', 'getNetworkType'], success: function(res) { //state = 1; that.wxstate = 1; //只有在微信浏览器中 } }); }); //001end }); }); },