geek 4 anni fa
parent
commit
77db566e4d

+ 2 - 2
api/store.js

@@ -6,8 +6,8 @@ class store extends request {
     //     console.log(res);
     // }
 
-    static async getStoreList(page = 1, pageSize = 10) {
-        const res = await this.getRequest(`${this.BASE_URL}Store/index?page=${page}&pageSize=${pageSize}`, this._defaultHeader)
+    static async getStoreList(page = 1, pageSize = 10,otherParam = '') {
+        const res = await this.getRequest(`${this.BASE_URL}Store/index?page=${page}&pageSize=${pageSize}`+otherParam, this._defaultHeader)
         return res.data;
     }
     static async getStoreById(id) {

+ 12 - 1
pages/index/index.js

@@ -30,7 +30,8 @@ Page({
   onLoad: async function () {
     const self = this
     const tokenData = await commonApi.getToken();
-    if (tokenData.token) {
+
+    if (tokenData.token && !requestApi.HEAD.token) {
       wx.setStorageSync('token', tokenData.token)
       requestApi.HEAD.token = tokenData.token
     }
@@ -50,6 +51,8 @@ Page({
               console.log(res)
               const latitude = res.latitude
               const longitude = res.longitude
+              wx.setStorageSync('lon', longitude)
+              wx.setStorageSync('lat', latitude)
               const rs = await storeApi.getNearStore(latitude, longitude)
               console.log(rs.info);
               self.setData({
@@ -65,6 +68,12 @@ Page({
     // this.getProductHeight()
   },
   onShow: async function () {
+    const self = this
+    const tokenData = await commonApi.getToken();
+    if (tokenData.token && !requestApi.HEAD.token) {
+      wx.setStorageSync('token', tokenData.token)
+      requestApi.HEAD.token = tokenData.token
+    }
     var tabs = await this.getProductList();
     this.setData({
       tabs
@@ -155,6 +164,8 @@ Page({
         console.log(res)
         const latitude = res.latitude
         const longitude = res.longitude
+        wx.setStorageSync('lon', longitude)
+        wx.setStorageSync('lat', latitude)
         const speed = res.speed
         const accuracy = res.accuracy
         const rs = await storeApi.getNearStore(latitude, longitude)

+ 1 - 1
pages/order/order.wxml

@@ -47,4 +47,4 @@
         <view class="pay-btn" wx:if="{{order.status==1}}">确认支付</view>
         <view class="delete-btn" bindtap="deleteOrder" wx:if="{{order.status==3}}">删除订单</view>
     </view>
-</view>
+</view>

+ 3 - 6
pages/personorder/personorder.js

@@ -18,7 +18,7 @@ Page({
         title: '全部'
       },
       {
-        title: '消费'
+        title: '消费'
       },
       {
         title: '待评价'
@@ -40,9 +40,6 @@ Page({
         url: '/pages/prompt/prompt?page=' + this.route,
       })
     }
-
-
-
   },
 
   // 获取全部列表
@@ -179,7 +176,7 @@ Page({
       activeTab: index,
       pageNo: [1, 1, 1, 1]
     })
-    if (index == 0) {
+    if(index==0){
       this.getAllOrderList()
       return
     }
@@ -331,4 +328,4 @@ Page({
       url: '../appointment/appointment?' + 'shopId=' + shopId + '&productId=' + productId + '&productImg=' + productImg + '&productName=' + productName + '&price=' + price,
     })
   }
-})
+})

+ 40 - 6
pages/shop/shop.js

@@ -17,12 +17,46 @@ Page({
    */
   onLoad: async function (options) {
     
-    var rs = await storeApi.getStoreList(1, 5);
-  
-    console.log(rs)
-    this.setData({
-      shopList: rs.list,
-      
+    
+    wx.getSetting({
+      success: async (res) => {
+        let authSetting = res.authSetting
+        if (authSetting['scope.userLocation']) {
+          console.log('已授权地理位置')
+          let lon = wx.getStorageSync('lon')
+          let lat =   wx.getStorageSync('lat')
+          let rs = await storeApi.getStoreList(1, 5,`&lon=${lon}&lat=${lat}`);
+          this.setData({
+            shopList: rs.list,
+            
+          })
+          // 已授权
+        } else {
+          // 未授权
+          console.log('未授权地理位置');
+          wx.getLocation({
+            type: 'wgs84',
+            async success(res) {
+              console.log(res)
+              const latitude = res.latitude
+              const longitude = res.longitude
+              wx.setStorageSync('lon', longitude)
+              wx.setStorageSync('lat', latitude)
+              const rs = await storeApi.getNearStore(latitude, longitude)
+              console.log(rs.info);
+              self.setData({
+                locationFlag: true,
+                storeInfo: rs.info
+              })
+              let shopList = await storeApi.getStoreList(1, 5,`&lon=${longitude}&lat=${latitude}`);
+              this.setData({
+                shopList: shopList.shopList,
+                
+              })
+            }
+          })
+        }
+      }
     })
   },
  

+ 34 - 0
pages/shopinfo/shopinfo.js

@@ -137,5 +137,39 @@ Page({
         wx.navigateTo({
             url: '../product/product?shopId=' + shopId + '&productId=' + productId,
         })
+    },
+    guide: function(e){
+        wx.getSetting({
+            success: async (res) => {
+              let authSetting = res.authSetting
+              if (authSetting['scope.userLocation']) {
+                console.log('已授权地理位置')
+                let lon = wx.getStorageSync('lon')
+                let lat =   wx.getStorageSync('lat')
+                wx.openLocation({
+                  latitude:lat,
+                  longitude: lon,
+                })
+                // 已授权
+              } else {
+                // 未授权
+                console.log('未授权地理位置');
+                wx.getLocation({
+                  type: 'wgs84',
+                  async success(res) {
+                    console.log(res)
+                    const latitude = res.latitude
+                    const longitude = res.longitude
+                    wx.setStorageSync('lon', longitude)
+                    wx.setStorageSync('lat', latitude)
+                    wx.openLocation({
+                        latitude:latitude,
+                        longitude: longitude,
+                      })
+                  }
+                })
+              }
+            }
+          })
     }
 })

+ 1 - 1
pages/shopinfo/shopinfo.wxml

@@ -22,7 +22,7 @@
          <mp-icon icon="cellphone" size="18" class="icon"></mp-icon>
          {{shopInfo.mobile}}
       </view>
-      <view class="address f13 fw300 padding40">
+      <view class="address f13 fw300 padding40" bindtap="guide">
          <view class="">
 
             <mp-icon icon="location" size="18" class="icon"></mp-icon>