Commit 8b4559e6 by weijiguang

修改首页获取位置逻辑

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