|
@@ -16,7 +16,8 @@ Page({
|
|
|
groupBanner: {},
|
|
|
storeName: '',
|
|
|
showPop: false,//活动弹窗
|
|
|
- couponVo: {}
|
|
|
+ couponVo: {},
|
|
|
+ storeId: ''
|
|
|
},
|
|
|
showCouponPop() {
|
|
|
let that = this;
|
|
@@ -70,8 +71,7 @@ Page({
|
|
|
},
|
|
|
onLoad: function (options) {
|
|
|
let that = this;
|
|
|
- wx.setStorageSync("navUrl", "/pages/index/index")
|
|
|
- that.syncStore();
|
|
|
+ wx.setStorageSync("navUrl", "/pages/index/index");
|
|
|
},
|
|
|
onReady: function () {
|
|
|
// 页面渲染完成
|
|
@@ -79,8 +79,14 @@ Page({
|
|
|
onShow: function () {
|
|
|
// 页面显示
|
|
|
let that = this;
|
|
|
- wx.setStorageSync("navUrl", "/pages/index/index")
|
|
|
- that.syncStore();
|
|
|
+ wx.setStorageSync("navUrl", "/pages/index/index");
|
|
|
+ if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
|
|
|
+ that.syncStore();
|
|
|
+ } else {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/auth/btnAuth/btnAuth',
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
onHide: function () {
|
|
|
// 页面隐藏
|
|
@@ -132,37 +138,36 @@ Page({
|
|
|
syncStore: function () {
|
|
|
let that = this;
|
|
|
if (!wx.getStorageSync('storeId')) {
|
|
|
- util.getLocation((lng, lat) => {
|
|
|
- wx.setStorageSync('location', JSON.stringify({ lng, lat }));
|
|
|
- util.request(api.NearbyList, { longitude: lng, latitude: lat }).then((res) => {
|
|
|
- let nlist = res.data;
|
|
|
- if (!nlist.length) {
|
|
|
- wx.removeStorageSync('nearStoreList');
|
|
|
- wx.removeStorageSync('storeId');
|
|
|
- wx.removeStorageSync('storeVo');
|
|
|
- that.setData({
|
|
|
- storeName: '附近暂无门店'
|
|
|
- })
|
|
|
- } else {
|
|
|
- that.setData({
|
|
|
- storeName: nlist[0].storeName
|
|
|
- })
|
|
|
- that.chooseStore(nlist[0].id)
|
|
|
- wx.setStorageSync('nearStoreList', JSON.stringify(nlist));
|
|
|
- wx.setStorageSync('storeVo', JSON.stringify(nlist[0]));
|
|
|
- }
|
|
|
- that.reLoad();
|
|
|
- })
|
|
|
- })
|
|
|
- } else if (wx.getStorageSync('storeVo')
|
|
|
- && wx.getStorageSync('storeVo').length > 0) {
|
|
|
+ util.getLocation((lng, lat) => {
|
|
|
+ wx.setStorageSync('location', JSON.stringify({ lng, lat }));
|
|
|
+ util.request(api.NearbyList, { longitude: lng, latitude: lat }).then((res) => {
|
|
|
+ let nlist = res.data;
|
|
|
+ if (!nlist.length) {
|
|
|
+ wx.removeStorageSync('nearStoreList');
|
|
|
+ wx.removeStorageSync('storeId');
|
|
|
+ wx.removeStorageSync('storeVo');
|
|
|
+ that.setData({
|
|
|
+ storeName: '附近暂无门店'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ that.setData({
|
|
|
+ storeName: nlist[0].storeName,
|
|
|
+ storeId: nlist[0].id
|
|
|
+ })
|
|
|
+ that.chooseStore(nlist[0].id);
|
|
|
+ wx.setStorageSync('nearStoreList', JSON.stringify(nlist));
|
|
|
+ wx.setStorageSync('storeVo', JSON.stringify(nlist[0]));
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ } else {
|
|
|
var storeVo = JSON.parse(wx.getStorageSync('storeVo'));
|
|
|
that.chooseStore(storeVo.id);
|
|
|
that.setData({
|
|
|
- storeName: storeVo.storeName
|
|
|
- })
|
|
|
- that.reLoad();
|
|
|
- }
|
|
|
+ storeName: storeVo.storeName,
|
|
|
+ storeId: storeVo.id
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
// 更新门店Id
|
|
|
chooseStore: function (storeId) {
|
|
@@ -170,6 +175,7 @@ Page({
|
|
|
util.request(api.ChooseStoreId, { storeId: storeId }, 'POST').then(function (res) {
|
|
|
if (res.errno === 0) {
|
|
|
wx.setStorageSync('storeId', storeId);
|
|
|
+ that.reLoad();
|
|
|
}
|
|
|
});
|
|
|
},
|