import {
wxp} from '../../../utils/index'
// 点击签到——客户授权——调取签到接口
sign(){
// 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope
let _this = this
wxp.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
// 1、没有授权,先申请
wxp.authorize({
scope: 'scope.userLocation',
}).then(data=>{
_this.signApi()
})
}else{
//已授权
_this.signApi()
}
}
})
},
signApi(){
//获取经纬度
wxp.getLocation({
type: 'wgs84',
}).then(res=>{
wx.http('/api/order/wechat/process/masterSign',{
orderId:this.data.id,
lng1:this.data.info.longitude,
lat1:this.data.info.latitude,
lng2:res.longitude,
lat2:res.latitude,
address:this.data.info.orderClient.clientAddress,
items:[]
},"POST").then(data=>{
wx.showToast({
title: '签到成功',
})
setTimeout(()=>{
wx.navigateTo({
url: '/pages/order/finish-order/finish-order?id='+this.data.id,
})
},1000)
})
})
}
在app.json文件中,pages同级添加获取微信信息的用途描述
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序签到"
}
}