Commit 8b4559e6 by weijiguang

修改首页获取位置逻辑

parent aae89676
......@@ -4,7 +4,7 @@
<image src="../../static/imgs/banner.png"></image>
<view class="shop-info" :style="'top:120rpx'">
<view class="shop-box">
<text @click="openShow" class="shop-name">{{ shopInfo.name }}</text>
<text @click="showArea" class="shop-name">{{ shopInfo.name }}</text>
<u-icon name="arrow-right" class="arrow-right-select" color="#FFFFFF"></u-icon>
</view>
<view v-if="shopInfo.distance" class="distance">距您{{ shopInfo.distance }}</view>
......@@ -82,14 +82,23 @@ export default {
},
},
created() {
this.getLocation()
},
onLoad: async function () {
User.getAddress()
$EventBus.$off('getMenuList')
$EventBus.$on('getMenuList', (data) => {
this.shopInfo = data;
this.getMenuList(data.id)
uni.getSetting({
success: (res) => {
// 已经授权位置不获取默认店铺
if(res.authSetting['scope.userLocation']){
User.getLocation((state, params) => {
if(state != 1) {
return;
}
this.getShopMenus(params);
});
} else {
this.getShopMenus();
this.authLocation();
}
}
})
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
......@@ -114,6 +123,14 @@ export default {
}
},
methods: {
getShopMenus(params) {
$EventBus.$off('getMenuList');
$EventBus.$on('getMenuList', (data) => {
this.shopInfo = data;
this.getMenuList(data.id);
});
User.getShopInfo(params);
},
openQrcode() {
// 不生成二维码
if(['2', '3'].indexOf(this.orderInfo.state) != -1){
......@@ -131,26 +148,29 @@ export default {
}
})
},
openShow() {
const postion = uni.getStorageSync('location');
if (postion) {
Order.getShop(postion).then(res => {
const data = res.data.data
const two = data[0].children
const three = two[0].children
this.columns = [[...data], [...two], [...three]]
this.show = true
})
return
}
this.getLocation((data) => {
Order.getShop(data).then(res => {
const data = res.data.data
const two = data[0].children
const three = two[0].children
this.columns = [[...data], [...two], [...three]]
this.show = true
showArea() {
uni.getSetting({
success: (res) => {
// 已经授权位置不获取默认店铺
if(res.authSetting['scope.userLocation']) {
User.getLocation((state, params) => {
console.log("showArea, state:"+state+", params:" + JSON.stringify(params));
this.showAreaDialog(params);
});
} else {
console.log("showArea no location" );
this.showAreaDialog();
}
}
})
},
showAreaDialog(params) {
Order.getShop(params).then(res => {
const data = res.data.data;
const two = data[0].children;
const three = two[0].children;
this.columns = [[...data], [...two], [...three]];
this.show = true;
})
},
changeHandler() { },
......@@ -172,16 +192,18 @@ export default {
}
},
// 获取定位授权
getLocation(callback) {
authLocation(callback) {
uni.getSetting({
success: (res) => {
// console.log(res.authSetting['scope.userLocation']);
if (!res.authSetting['scope.userLocation']) {
uni.authorize({
scope: 'scope.userLocation',
success: () => { //1.1 允许授权
User.getLocation(data => {
callback ? callback(data) : User.getAddress()
// console.log("允许授权位置");
User.getLocation((state, params) => {
if(state != 1){
return;
}
callback ? callback(params) : this.getShopMenus(params);
});
},
fail: (err) => { //1.2 拒绝授权
......@@ -190,11 +212,17 @@ export default {
uni.showToast({ "title" : "获取位置失败,请打开位置授权", icon : 'error' })
}
})
} else {
User.getLocation(data => {
callback && callback(data)
});
}
// if (res.authSetting['scope.userLocation']) {
// console.log("以前允许授权位置");
// User.getLocation((state, params) => {
// if(state != 1){
// return;
// }
// callback && callback(params);
// });
// } else {
// }
}
})
},
......
......@@ -20,8 +20,7 @@
<view class="order1">我的订单</view>
<view class="order2">点击查看订单</view>
<view>
<image class="orderImg" src="../../static/imgs/myOrder.png">
</image>
<image class="orderImg" src="../../static/imgs/myOrder.png"></image>
</view>
</view>
<view class="right_box">
......@@ -51,8 +50,7 @@
<h3>常用功能</h3>
<view class="function_item">
<u-icon name="server-fill" color="#000000" size="16"></u-icon>
<button class="function_item_text" open-type="contact" bindcontact="handleContact"
session-from="sessionFrom">联系客服</button>
<button class="function_item_text" open-type="contact" bindcontact="handleContact" session-from="sessionFrom">联系客服</button>
<u-icon name="arrow-right" class="function_item_icon" color="#000000" size="12"></u-icon>
</view>
</view>
......
......@@ -12,38 +12,35 @@ export default {
lat: res.latitude,
lng: res.longitude,
};
if(params.lat && params.lng) {
Store.commit('saveLocation', params);
uni.setStorage({ key: 'location', data: params });
callback && callback(params);
// return params;
} else {
params = uni.getStorageSync('location');
}
callback && callback(1, params);
},
fail: function (res) {
uni.showToast({
title: '获取地址失败,将导致部分功能不可用',
icon: 'none',
});
const params = uni.getStorageSync('location');
callback && callback(0, params);
},
});
},
// 获取默认店铺
getAddress(params) {
return uni.$u.http
.get('/weixin/getShop', {
params,
})
// 获取店铺信息
getShopInfo(params) {
return uni.$u.http.get('/weixin/getShop', { params })
.then((res) => {
console.log("get shop:"+JSON.stringify(res.data.data));
if (res.data.code == 200) {
Store.commit('saveShopInfo', res.data.data);
uni.setStorage({ key: 'shopData', data: res.data.data });
if (res.data.data) {
$EventBus.$emit('getMenuList', res.data.data);
}
}
return res;
})
.catch((err) => {
}).catch((err) => {
console.log("get shop error");
return err;
});
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment