luck 2 ani în urmă
părinte
comite
a9dec32e87

+ 97 - 90
app.js

@@ -1,9 +1,9 @@
 // app.js
-var projectMode=1;//0代表开发模式(本地环境),1代表测试模式(线上测试环境),2代表线上模式(正式运行环境)
-var info=wx.getSystemInfoSync();
-if(info.platform!="devtools"&&projectMode==0){projectMode=1}
+var projectMode = 1;//0代表开发模式(本地环境),1代表测试模式(线上测试环境),2代表线上模式(正式运行环境)
+var info = wx.getSystemInfoSync();
+if (info.platform != "devtools" && projectMode == 0) { projectMode = 1 }
 var envVersion = `${__wxConfig.envVersion}`;//develop	开发版,trial	体验版,release	正式版
-if(envVersion=='release'){projectMode=2}
+if (envVersion == 'release') { projectMode = 2 }
 import api from './utils/api'
 App({
   onLaunch() {
@@ -11,13 +11,13 @@ App({
     wx.cloud.init({
       traceUser: true,
     })
-    
 
 
+    wx.setStorageSync('islocation', false)
     const logs = wx.getStorageSync('logs') || []
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs)
-    var that=this;
+    var that = this;
 
     this.getLocation();
 
@@ -26,108 +26,115 @@ App({
     // 登录
 
     wx.checkSession({
-      success: res=> {
+      success: res => {
         console.log(res)
       },
-      fail:(res)=>{
+      fail: (res) => {
       }
     })
-  
+
 
     this.globalData.btnInfo = wx.getMenuButtonBoundingClientRect()
-    console.log(this.globalData.btnInfo,'按钮信息');
-    
+    console.log(this.globalData.btnInfo, '按钮信息');
+
   },
   globalData: {
     userInfo: null,
-    btnInfo:null,
-    status:['可下单','服务中','已满柜','暂停服务'],
-    baseAppUrl: projectMode==2 ? 'https://wash.nanodreamtech.com/':(projectMode==1 ?'https://wash.nanodreamtech.com/':'http://127.0.0.1:8000/'),
-    location:""
+    btnInfo: null,
+    status: ['可下单', '服务中', '已满柜', '暂停服务'],
+    baseAppUrl: projectMode == 2 ? 'https://wash.nanodreamtech.com/' : (projectMode == 1 ? 'https://wash.nanodreamtech.com/' : 'http://127.0.0.1:8000/'),
+    location: "",
+    islocation: true
+  },
+  api: api,
+
+  getLocation(e) {
+    var that = this;
+    wx.getLocation({
+      success(res) {
+        console.log('开启后台定位', res)
+       
+          console.log('location change', res)
+          that.globalData.location = res;
+          wx.setStorageSync('latitude', res.latitude)
+          wx.setStorageSync('longitude', res.longitude)
+         
+          wx.checkSession({
+            success: res => {
+             
+            },
+            fail: (res) => {
+              that.login(res.latitude, res.longitude).then(function (res) { })
+            }
+        
+        })
+      },fail(res) {
+        console.log('开启后台定位失败', res)
+        that.globalData.islocation = false;
+        wx.setStorageSync('islocation', true)
+        wx.showLoading({
+          title: '请授权获取地址。',
+        })
+        setTimeout(function () {
+            wx.hideLoading();
+          }, 2000)
+        
+    
+      }
+    })
   },
-  api:api,
-
-  getLocation(e){
-    var that=this;
-    wx.startLocationUpdateBackground({
-        success(res) {
-          console.log('开启后台定位', res)
-          wx.onLocationChange(function(res) {
-            console.log('location change', res)
-            that.globalData.location=res;
-
-
-   
-            that.login(res.latitude,res.longitude).then(function(res){
-              if(res.code!=200){
-                
-              }
-
-
-            },function(err){
-
-            })
-
 
-          })
+  login(lat = "", lng = "") {
+    var that = this;
+    return new Promise((resolve, reject) => {
+      console.log(3333333)
+      wx.checkSession({
+        success: (res) => {
+          console.log(444444)
         },
-        fail(res) {
-          console.log('开启后台定位失败', res)
+        fail: (res) => {
+          wx.login({
+            success: res => {
+              console.log(res)
+              // 发送 res.code 到后台换取 openId, sessionKey, unionId
+              that.api.useApi(that.globalData.baseAppUrl + "api/login", {
+                code: res.code,
+                lat: lat,
+                lng: lng,
+                appid: wx.getAppBaseInfo().host.appId
+              }, "post").then(function (res) {
+                wx.showLoading({
+                  title: '登录中',
+                })
+                if (res.code != 200) {
+                  setTimeout(function () {
+                    that.login(lat, lng);
+                  }, 1000);
+                } else {
+                  wx.hideLoading();
+                  wx.setStorageSync('token', res.message.token);
+                  wx.setStorageSync('uid', res.message.user_id);
+                  wx.setStorageSync('exp_time', res.message.exp_time);
+                  wx.setStorageSync('seisson_key', res.message.session_key);
+                  wx.setStorageSync('nid', res.message.network_id);//当前网点选择id
+                  resolve(res);
+                }
+
+
+
+              }).catch(function (err) {
+                console.log(222);
+              })
+            }
+          })
         }
-      })
-},
 
-  login(lat="",lng=""){
-    var that=this;
-   return new Promise((resolve,reject)=>{
-    console.log(3333333)
-    wx.checkSession({
-      success: (res) => {
-        console.log(444444)
-      },
-      fail:(res)=>{
-        wx.login({
-          success: res => {
-          console.log(res)
-            // 发送 res.code 到后台换取 openId, sessionKey, unionId
-            that.api.useApi(that.globalData.baseAppUrl+"api/login",{
-              code:res.code,
-              lat:lat,
-              lng:lng,
-              appid:wx.getAppBaseInfo().host.appId
-            },"post").then(function(res){
-              wx.showLoading({
-                title: '登录中',
-              })
-              if(res.code!=200){
-                setTimeout(function(){
-                  that.login(lat,lng);
-                },1000);
-              }else{
-                wx.hideLoading();
-                wx.setStorageSync('token', res.message.token);
-                wx.setStorageSync('uid', res.message.user_id);
-                wx.setStorageSync('seisson_key', res.message.session_key);
-                wx.setStorageSync('nid', res.message.network_id);//当前网点选择id
-                resolve(res);
-              }
-          
-    
-            
-            }).catch(function(err){
-              console.log(222);
-            })
-          }
-        })
-      }
+      })
 
-    })
 
 
-   
-   })
+    })
   }
- 
 
 })
 

+ 27 - 2
pages/home/map/list.js

@@ -16,7 +16,7 @@ Page({
    */
   onLoad: function (options) {
       this.workDesc();
-      that.setData({
+      this.setData({
         status:app.globalData.status
       })
   },
@@ -98,6 +98,31 @@ bindKeyInput: function (e) {
     inputValue: e.detail.value
   })
 },
-
+setworke(e){
+  console.log(e);
+  const network_id=e.target.dataset.id;
+  var that=this;
+  app.api.useApi(app.globalData.baseAppUrl+"api/user/"+network_id+"/setNetwork",{
+  },"post").then(function(res){
+    if (res.code == 200) {
+      wx.showLoading({
+        title: '网点设置成功',
+      })
+      wx.setStorageSync('nid', network_id);
+      setTimeout(function () {
+        wx.switchTab({
+          url: '/pages/tabber/home/index',
+        })
+        
+        }, 3000)
+
+ 
+     
+     
+    }
+  }).catch(function(err){
+    console.log(222);
+  })
+}
 
 })

+ 1 - 1
pages/home/map/list.wxml

@@ -18,7 +18,7 @@
     </view>
     <view class="group3" wx:for="{{workelist}}">
       <view class="block1">
-        <view class="wrap1">
+        <view class="wrap1" bindtap="setworke" data-id="{{item.id}}">
           <text lines="1" class="info1">{{item.title}}</text>
           <view class="main1">
             <view class="wrap2">

+ 15 - 4
pages/home/map/map.js

@@ -175,14 +175,25 @@ this.setData({
 },
 //设置网点
 setworke(e){
-  app.api.useApi(app.globalData.baseAppUrl+"api/user",{
-    network_id:e.target.dataset.id,
-
-  },"get").then(function(res){
+  const network_id=e.target.dataset.id;
+  var that=this;
+  app.api.useApi(app.globalData.baseAppUrl+"api/user/"+network_id+"/setNetwork",{
+  },"post").then(function(res){
     if (res.code == 200) {
       wx.showLoading({
         title: '网点设置成功',
       })
+      wx.setStorageSync('nid', network_id);
+      setTimeout(function () {
+        wx.switchTab({
+          url: '/pages/tabber/home/index',
+        })
+        
+        }, 3000)
+
+ 
+     
+     
     }
   }).catch(function(err){
     console.log(222);

+ 1 - 1
pages/home/map/map.wxml

@@ -14,7 +14,7 @@
 </view>
 
 <view class="contioner" hover-class="none" hover-stop-propagation="false" style="width: 100%; height: 100%;">
-    <map name="" longitude="{{location.longitude}}" latitude="{{location.latitude}}" bindmarkertap="markertap" markers="{{mapworkelist}}" show-location style="width: 100%; height: 100%;" wx:if="{{hasMarkers}}" scale="10"></map>
+    <map name="" longitude="{{location.longitude}}" latitude="{{location.latitude}}" bindmarkertap="markertap" markers="{{mapworkelist}}" show-location style="width: 100%; height: 100%;"  wx:if="{{hasMarkers}}" scale="10"></map>
 </view>
 <view class="footerBox flex ju-b" wx:if="{{show}}" bindtap="setworke" data-id="{{workedesc.id}}">
         <view class="le">

+ 26 - 0
pages/my/address/address.js

@@ -1,4 +1,5 @@
 // pages/my/address/address.js
+const app =getApp();
 Page({
 
     /**
@@ -6,6 +7,9 @@ Page({
      */
     data: {
         addressList:[{}]
+    },
+    onLoad:function(){
+
     },
     addSite(e){
         let {parmise} = e.currentTarget.dataset
@@ -13,6 +17,28 @@ Page({
         wx.navigateTo({
           url: './addSite/addSite?parmise='+parmise,
         })
+    },
+
+    //获取地址列表
+    address(){
+        app.api.useApi(app.globalData.baseAppUrl + "api/network/desc", {
+            network_id: 1,
+        }, "get").then(function (res) {
+            if (res.code != 200) {
+                wx.showLoading({
+                    title: '地址加载失败' + res.status,
+                })
+            } else {
+                that.setData({
+                    worke: res.message.data
+                })
+            }
+
+            wx.hideLoading();
+
+        }).catch(function (err) {
+            console.log(222);
+        })
     }
 
 })

+ 61 - 39
pages/tabber/home/index.js

@@ -1,5 +1,5 @@
 // pages/tabber/home/index.js
-const  app = getApp();
+const app = getApp();
 
 Page({
 
@@ -21,61 +21,75 @@ Page({
                 url: '/image/home/xidifanwei.png',
                 text: '洗涤范围'
             }
-            
+
         ],
         current: 3,
         btnInfo: app.globalData.btnInfo,
         topShow: true,
-        worke:[]
+        worke: [],
+        status: "",
+        islocation: ""
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
+
+    },
+    onShow: function (options) {
+        this.setData({
+            islocation: wx.getStorageSync('islocation'),
+            status: app.globalData.status
+        })
         this.workDesc();
+    },
+    onReady: function () {
+
     },
     //网点详情
-    workDesc:function(){
-        var that=this;
-        var nid=wx.getStorageSync('nid');
-        if(!nid){
+    workDesc: function () {
+        var that = this;
+        var nid = wx.getStorageSync('nid');
+        if (!nid) {
             that.setData({
-                worke:{'title':'请选择网点','institution_id':0,'business_status':'不可下单','distance':0}
+                worke: { 'title': '请选择网点', 'institution_id': 0, 'business_status': '不可下单', 'distance': 0 }
             })
             return false;
         }
         app.api.useApi(app.globalData.baseAppUrl + "api/network/desc", {
             network_id: nid,
-          }, "get").then(function (res) {
+        }, "get").then(function (res) {
             if (res.code != 200) {
                 wx.showLoading({
-                    title: '网点加载失败'+res.status,
-                  })
+                    title: '网点加载失败' + res.status,
+                })
             } else {
-             that.dsetData({
-                worke:res.message.data
-             })
+                that.setData({
+                    worke: res.message.data
+                })
             }
 
             wx.hideLoading();
 
-          }).catch(function (err) {
+        }).catch(function (err) {
             console.log(222);
-          })
-
+        })
     },
-    toMap(){
+    toMap() {
         wx.navigateTo({
-          url: '/pages/home/map/map',
+            url: '/pages/home/map/map',
         })
     },
-    placeOrder(){
+    placeOrder() {
+        if (this.data.islocation) {
+            this.getLocation()
+        }
         wx.navigateTo({
-          url: '/pages/order/placeOrder/placeOrder',
+            url: '/pages/order/placeOrder/placeOrder',
         })
     },
-   
+
 
     close() {
         this.setData({
@@ -92,29 +106,37 @@ Page({
         console.log(1);
     },
 
-    getLocation(e){
-        var that=this;
-        wx.startLocationUpdateBackground({
+    getLocation(e) {
+        var that = this;
+        wx.getLocation({
             success(res) {
-              console.log('开启后台定位', res)
-              wx.onLocationChange(function(res) {
-                console.log('location change', res)
-                that.setData({
-                    location:res
-                })
+                console.log('开启后台定位', res)
+              
+                    console.log('location change', res)
+                    that.setData({
+                        location: res,
+                        islocation: true,
+                    })
 
-                app.api.useApi(app.globalData.baseAppUrl+"api").then(function(res){
-                   console.log(res)
+                    app.api.useApi(app.globalData.baseAppUrl + "api").then(function (res) {
+                        console.log(res)
 
-                },function(error){
-                    console.log(error);
-                })
-              })
+                    }, function (error) {
+                        console.log(error);
+                    })
+                
             },
             fail(res) {
-              console.log('开启后台定位失败', res)
+                console.log('开启后台定位失败', res);
+                that.setData({
+                    islocation: true
+                })
+                wx.showLoading({
+                    title: '开启后台定位失败,请重试。',
+                })
+                return false;
             }
-          })
+        })
     }
 
 

+ 2 - 2
pages/tabber/home/index.wxml

@@ -13,7 +13,7 @@
             <view class="content">
                 <view class="tit">{{worke.title}}</view>
                 <view class="message">离您最近|距离{{worke.distance}}米</view>
-                <view class="tags">{{worke.business_status}}</view>
+                <view class="tags">{{status[worke.signing_status]}}</view>
             </view>
         </view>
 
@@ -40,7 +40,7 @@
 <!-- or gray -->
 <view class="btns skyBlue " bindtap="placeOrder">
 
-    <text>下单洗衣</text>
+    <text>{{!islocation?'下单洗衣':'请先开启定位'}}</text>
     <view class="tips flex">活动活动活动活动</view>
 </view>
 

+ 14 - 6
utils/api.js

@@ -1,21 +1,22 @@
 // api接口请求封装
 
 var useApi = (url, data = {}, method = "get") => {
-
+var that=this;
+var requrestTask=wx.request
     console.log(url);
     return new Promise((resolve, reject) => {
-        wx.request({
+        requrestTask ({
             url: `${url}`, // 云端正式服
             data,
             method,
             header: {
-                Authorization: wx.getStorageSync('token') || '',
+                'Authorization': 'Bearer '+wx.getStorageSync('token') || '',
                 'content-type': 'application/json',
             },
             dataType: 'json', // 添加这个配置
             success(res) {
-                // wx.hideLoading()
                 resolve(res.data)
+                
             },
             fail(err) {
                 // wx.hideLoading()
@@ -28,11 +29,18 @@ var useApi = (url, data = {}, method = "get") => {
             complete() {
                 wx.hideLoading(333)
                 wx.hideLoading({ //因为showToast、hideLoading不能同时使用
-                    fail() { }
+                    fail() {}
                 })
             }
+        }).onHeadersReceived(res=>{
+          if(res && res.header && res.header.Authorization) {
+            console.log("获取requestTask",res)
+            wx.setStorageSync("token", res.header.Authorization);
+          }
         })
+
     })
+    
 }
 
 
@@ -42,6 +50,6 @@ module.exports = {
         console.log(1);
         return useApi('', data)
 
-    }
+    },
 
 }