获取当前定位,订单确认页面自动带出默认地址
This commit is contained in:
parent
12221e22fe
commit
c68e810350
|
|
@ -11,8 +11,8 @@ export default {
|
|||
})
|
||||
// request 触发前拼接 url
|
||||
// args.url = 'https://www.opsoul.com' + args.url;
|
||||
// args.url = 'http://192.168.2.42:80' + args.url;
|
||||
args.url = 'http://127.0.0.1:80' + args.url;
|
||||
args.url = 'http://120.79.136.57' + args.url;
|
||||
// args.url = 'http://127.0.0.1:80' + args.url;
|
||||
if (args.data) {
|
||||
args.data.deptId = globalData.deptId;
|
||||
args.data.from = globalData.from;
|
||||
|
|
@ -43,49 +43,73 @@ export default {
|
|||
}
|
||||
})
|
||||
},
|
||||
authAndGetLocation() {
|
||||
async authAndGetLocation() {
|
||||
let _this = this;
|
||||
// 通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope
|
||||
wx.getSetting({
|
||||
success(res) {
|
||||
if (!res.authSetting['scope.userLocation']) {
|
||||
let wxGetSettinsRes = await wx.getSetting();
|
||||
if (!wxGetSettinsRes.authSetting['scope.userLocation']) {
|
||||
// 用户授权
|
||||
wx.authorize({
|
||||
scope: 'scope.userLocation',
|
||||
success() {
|
||||
let authRes = await wx.authorize({
|
||||
scope: 'scope.userLocation'
|
||||
})
|
||||
if (authRes && authRes.errMsg.indexOf('ok') != -1) {
|
||||
// 用户已经同意, 后续调用此接口不会弹窗询问
|
||||
_this.wxGetLocation();
|
||||
},
|
||||
fail() {
|
||||
// 用户已经拒绝过授权
|
||||
wx.openSetting({
|
||||
success(res) {
|
||||
if (res['scope.userLocation']) {
|
||||
_this.wxGetLocation();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
await _this.wxGetLocation();
|
||||
} else {
|
||||
_this.wxGetLocation();
|
||||
// 用户已经拒绝过授权
|
||||
let wxOpenSettingRes = await wx.openSetting()
|
||||
if (wxOpenSettingRes && wxOpenSettingRes.authSetting && wxOpenSettingRes.authSetting['scope.userLocation']) {
|
||||
await _this.wxGetLocation();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await _this.wxGetLocation();
|
||||
}
|
||||
},
|
||||
async wxGetLocation() {
|
||||
console.log("获取定位")
|
||||
let res = await wx.getLocation({
|
||||
type: 'gcj02'
|
||||
})
|
||||
let areaRes = await this.baiduGetLoacation(res.latitude, res.longitude);
|
||||
areaRes = areaRes.data;
|
||||
if (areaRes) {
|
||||
let areaArr = [areaRes.provinceArea, areaRes.cityArea, areaRes.countryArea];
|
||||
let curLocation = {
|
||||
area: areaArr,
|
||||
updateTimes: new Date().getTime()
|
||||
}
|
||||
uni.setStorageSync('curLocation', curLocation);
|
||||
}
|
||||
},
|
||||
async getCurArea() {
|
||||
let curLocation = uni.getStorageSync('curLocation');
|
||||
if (curLocation && curLocation.updateTimes) {
|
||||
let curTimes = new Date().getTime();
|
||||
let deltaSeconds = curTimes - Number(curLocation.updateTimes);
|
||||
if (deltaSeconds >= 15 * 60 * 1000) {
|
||||
// 设定重新获取定位的时间间隔为15分钟
|
||||
await this.wxGetLocation();
|
||||
curLocation = uni.getStorageSync('curLocation');
|
||||
}
|
||||
} else {
|
||||
await this.wxGetLocation();
|
||||
curLocation = uni.getStorageSync('curLocation');
|
||||
}
|
||||
if (curLocation && curLocation.area) {
|
||||
return curLocation.area;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
async baiduGetLoacation(latitude, longitude) {
|
||||
let res = await uni.request({
|
||||
url: '/tool/baidu/getLocation',
|
||||
method: 'POST',
|
||||
data: {
|
||||
location: latitude + ',' + longitude
|
||||
}
|
||||
})
|
||||
},
|
||||
wxGetLocation() {
|
||||
wx.getLocation({
|
||||
type: 'gcj02',
|
||||
success(res) {
|
||||
const latitude = res.latitude
|
||||
const longitude = res.longitude
|
||||
console.log(res)
|
||||
// uni.setStorageSync('userLocation', res);
|
||||
},
|
||||
complete(res) {
|
||||
console.log(res)
|
||||
}
|
||||
})
|
||||
return res[1].data;
|
||||
},
|
||||
async login() {
|
||||
let userInfo = await wx.getUserProfile({
|
||||
|
|
@ -104,7 +128,7 @@ export default {
|
|||
// 第一次从服务端获取用户信息
|
||||
let wxGetUserRes = await this.qryUserInfo(openId);
|
||||
// 获取失败则获取微信信息再调用注册接口
|
||||
if (!wxGetUserRes.data) {
|
||||
if (!wxGetUserRes.data && wxGetUserRes.code === 0) {
|
||||
// 注册完成后再次从服务端获取用户信息
|
||||
let registerRes = await this.registerUser({
|
||||
openId: openId,
|
||||
|
|
|
|||
|
|
@ -113,13 +113,15 @@
|
|||
beforeDestroy() {
|
||||
this.offBindEvent();
|
||||
},
|
||||
onReady() {
|
||||
this.loadData();
|
||||
async onReady() {
|
||||
await this.$request.authAndGetLocation();
|
||||
await this.loadData();
|
||||
},
|
||||
methods: {
|
||||
async loadData() {
|
||||
// 加载区域信息
|
||||
this.loadRegionList();
|
||||
this.getCurAreaArr();
|
||||
// 加载热门商品
|
||||
let hotGoodsRes = await this.$request.getHotGoods({
|
||||
pageNum: 1,
|
||||
|
|
@ -143,6 +145,15 @@
|
|||
offBindEvent() {
|
||||
uni.$off('index_showProductDetail');
|
||||
},
|
||||
async getCurAreaArr() {
|
||||
let areaArr = await this.$request.getCurArea();
|
||||
if (areaArr) {
|
||||
this.searchInfo.area = areaArr;
|
||||
} else {
|
||||
// 默认选中第一个
|
||||
this.searchInfo.area = [regionList[0], subRegionList[0], subSubRegionList[0]];
|
||||
}
|
||||
},
|
||||
async loadCategoryList() {
|
||||
let typeList = await this.$request.listByStep();
|
||||
typeList = typeList.data;
|
||||
|
|
@ -173,8 +184,6 @@
|
|||
this.areaList.push(regionList);
|
||||
this.areaList.push(subRegionList);
|
||||
this.areaList.push(subSubRegionList);
|
||||
// 默认选中第一个,因此将第一个区域默认加入查询条件中
|
||||
this.searchInfo.area = [regionList[0], subRegionList[0], subSubRegionList[0]];
|
||||
},
|
||||
regionChange(e) {
|
||||
this.areaMultiIndex = e.detail.value;
|
||||
|
|
|
|||
|
|
@ -105,9 +105,6 @@
|
|||
this.inParam = option;
|
||||
this.loadData(option);
|
||||
},
|
||||
onShow() {
|
||||
this.$request.authAndGetLocation();
|
||||
},
|
||||
onShareAppMessage(e) {
|
||||
let shareInfo = null;
|
||||
if (e && e.target && e.target.dataset) {
|
||||
|
|
|
|||
|
|
@ -135,11 +135,20 @@
|
|||
async loadData() {
|
||||
this.pageNum = this.$globalData.initPageNum;
|
||||
this.pageSize = this.$globalData.initPageSize;
|
||||
this.loadCategoryList();
|
||||
await this.loadRegionList();
|
||||
this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0], this.areaList[2][0]]
|
||||
// 获取当前定位
|
||||
await this.getCurAreaArr();
|
||||
this.loadCategoryList();
|
||||
this.searchGoods();
|
||||
},
|
||||
async getCurAreaArr() {
|
||||
let areaArr = await this.$request.getCurArea();
|
||||
if (areaArr) {
|
||||
this.searchInfo.area = areaArr;
|
||||
} else {
|
||||
this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0], this.areaList[2][0]]
|
||||
}
|
||||
},
|
||||
async reloadData(params = {}) {
|
||||
this.pageNum = this.$globalData.initPageNum;
|
||||
this.workerInfos = [];
|
||||
|
|
|
|||
|
|
@ -177,12 +177,22 @@
|
|||
},
|
||||
methods: {
|
||||
async loadData(params) {
|
||||
this.loadDefaultAddress();
|
||||
// this.pickedProductList = await this.$api.data('pickedProductList');
|
||||
this.pickedProductList = params.pickedProductList;
|
||||
this.loadTotalPrice();
|
||||
this.timeRangeList = this.$globalData.timeRangeList;
|
||||
this.timeRange = this.timeRangeList[0];
|
||||
},
|
||||
async loadDefaultAddress() {
|
||||
let res = await this.$request.getAddressList({
|
||||
customerId: this.$request.getCurUserInfo().customerId,
|
||||
isDefault: 1
|
||||
});
|
||||
if (res && res.data &&res.data.length) {
|
||||
this.formInfo.defaultAddress = res.data[0];
|
||||
}
|
||||
},
|
||||
loadTotalPrice() {
|
||||
// 计算totalprice
|
||||
this.pickedProductList.forEach((obj) => {
|
||||
|
|
|
|||
|
|
@ -167,13 +167,22 @@
|
|||
this.loadData();
|
||||
},
|
||||
methods: {
|
||||
loadData() {
|
||||
async loadData() {
|
||||
this.pageNum = this.$globalData.initPageNum;
|
||||
this.pageSize = this.$globalData.initPageSize;
|
||||
this.loadCategoryList();
|
||||
this.loadRegionList();
|
||||
// 获取当前定位
|
||||
await this.getCurAreaArr();
|
||||
this.loadProductData();
|
||||
},
|
||||
async getCurAreaArr() {
|
||||
let areaArr = await this.$request.getCurArea();
|
||||
if (areaArr) {
|
||||
this.chosenArea = areaArr;
|
||||
this.taskConditions[0].value = this.chosenArea[2].areaId;
|
||||
}
|
||||
},
|
||||
async loadProductData(params = {}) {
|
||||
params.pageNum = this.pageNum;
|
||||
params.pageSize = this.pageSize;
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@
|
|||
searchInfo: {},
|
||||
areaList: [],
|
||||
areaMultiIndex: [0, 0, 0],
|
||||
categoryList: [],
|
||||
stickyTop: this.CustomBar
|
||||
}
|
||||
},
|
||||
|
|
@ -144,9 +145,18 @@
|
|||
this.shopInfo = res.data;
|
||||
this.loadCategoryList();
|
||||
await this.loadRegionList();
|
||||
this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0], this.areaList[2][0]]
|
||||
// 获取当前定位
|
||||
await this.getCurAreaArr();
|
||||
this.searchGoods();
|
||||
},
|
||||
async getCurAreaArr() {
|
||||
let areaArr = await this.$request.getCurArea();
|
||||
if (areaArr) {
|
||||
this.searchInfo.area = areaArr;
|
||||
} else {
|
||||
this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0], this.areaList[2][0]];
|
||||
}
|
||||
},
|
||||
async loadProductData(params = {}) {
|
||||
params = {
|
||||
status: 0,
|
||||
|
|
|
|||
Loading…
Reference in New Issue