Browse Source

feat():修改bug

geek 4 years ago
parent
commit
fe523cd616

+ 6 - 0
api/user.js

@@ -10,6 +10,12 @@ class store extends request{
         const res = await this.postRequest(`${this.BASE_URL}User/save`, data)
         return res.data;
     }
+
+    static async getMobile(data) {
+        const res = await this.postRequest(`${this.BASE_URL}User/getMobile`, data)
+        return res.data;
+    }
+
     static async updateUserInfo(name,birthday,avatar,sex){
         const res = await this.getRequest(`${this.BASE_URL}User/editUser?name=${name}&birthday=${birthday}&avatar=${avatar}&sex=${sex}`)
     }

+ 13 - 0
app.js

@@ -55,6 +55,19 @@ App({
     this.setUserInfo(info.userInfo)
     return info.userInfo
   },
+  getPhoneNumber: async function(data){
+    let _self = this;
+    let res = await wxp.login()
+    console.log(res)
+    if (!res.code){
+      return
+    }
+    data['code'] = res.code
+    let info =  await userApi.getMobile(data)
+    console.log(info)
+    _self.setUserInfo(info.userInfo)
+    return info.userInfo;
+  },
   setUserInfo: function(userInfo){
     wx.setStorage({
       data: userInfo,

+ 64 - 20
pages/appointment/appointment.js

@@ -23,21 +23,21 @@ Page({
     orderTime: "",
     orderTimeHeight: 0,
     days: [],
-    hasMobile: false
-
-
+    hasMobile: false,
+    mobile: ''
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: async function (options) {
-    var shopId = options.shopId;
-    var productId = options.productId
-    var productImg = options.productImg;
-    var productName = options.productName;
-    var price = options.price;
-
+    console.log(options)
+    let shopId = options.shopId;
+    let productId = options.productId
+    let product = await productApi.getProductById(productId);
+    let productImg = product.info.productImg;
+    let productName = product.info.productName;
+    let price = product.info.currentPrice;
     this.setData({
       shopId,
       productId,
@@ -45,8 +45,16 @@ Page({
       productName,
       price
     })
-
-
+    let userInfo = await app.getWxUserInfo()
+    if (userInfo) {
+      this.setData({
+        userInfo: userInfo,
+        hasUserInfo: true,
+        hasMobile: userInfo.mobile ? true : false,
+        mobile: userInfo.mobile
+      })
+    }
+    await this.createTimeList();
   },
   checkAuth: async function () {
     const self = this
@@ -55,24 +63,61 @@ Page({
       wx.redirectTo({
         url: '/pages/prompt/prompt?page=' + this.route,
       })
+      return
+    }
+    if (!self.data.orderTime){
+      wx.showModal({
+        title: '提示',
+        content: '请选择预约时间',
+        showCancel:false,
+      })
+      return
     }
     let data = {
       productId: self.data.productId,
       storeId: self.data.shopId,
       appointmentTime: self.data.orderTime,
       num: self.data.peopleNum,
-      mobile: 15656942279
+      mobile: self.data.mobile
     }
     const rs = await orderApi.createOrder(data)
-    console.log(rs)
     let orderId = rs.orderId;
-
-    wx.navigateTo({
-      url: '../order/order?status=2&id=' + orderId,
+    wx.requestPayment({
+      timeStamp: rs.timeStamp,
+      nonceStr: rs.nonceStr,
+      package: rs.package,
+      signType: rs.signType,
+      paySign: rs.paySign,
+      success (res) { 
+        console.log(res)
+        wx.navigateTo({
+          url: '../order/order?id=' + orderId,
+        })
+      },
+      fail (res) { 
+        wx.navigateTo({
+          url: '../order/order?id=' + orderId,
+        })
+      }
     })
   },
-  getMobile: function (params) {
-
+  getMobile: async function (params) {
+    console.log(params);
+    let _self = this
+    const data = {
+      encryptedData:params.detail.encryptedData,
+      iv: params.detail.iv
+    }
+    const userInfo = await app.getPhoneNumber(data)
+    console.log(userInfo)
+    let hasMobile = false
+    if (userInfo.mobile > 1) {
+      hasMobile:true
+    }
+    _self.setData({
+      hasMobile: hasMobile,
+      mobile: userInfo.mobile
+    })
   },
 
   onSlideChangeEnd: function (e) {
@@ -92,6 +137,7 @@ Page({
     var date = await storeApi.getStoreAppointTime(storeId);
     var days = date.date;
     console.log(days)
+    console.log(price)
     const tabs = createTimeApi.createTimeList(openTime, closeTime, days, price);
     console.log(tabs)
     this.setData({
@@ -169,8 +215,6 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: async function () {
-
-    this.createTimeList();
   },
 
   /**

+ 4 - 1
pages/appointment/appointment.wxml

@@ -47,7 +47,10 @@
         </mp-tabs>
 
     </view>
-    <view class="product-mobile card f17"><button type="primary" wx:if="{{!hasMobile}}" bindtap = "getMobile">点击获取手机号</button></view>
+    <view class="product-mobile card f17">
+        <button type="primary" wx:if="{{!hasMobile}}" bindgetphonenumber = "getMobile" open-type="getPhoneNumber">获取手机号</button>
+        <button type="primary" wx:if="{{hasMobile}}">{{mobile}}</button>
+    </view>
 
     <view class="appointment card" url="" hover-class="appointment-hover" open-type="navigate">
         <view class="btn" bindtap="checkAuth">

+ 0 - 4
pages/person/person.js

@@ -15,8 +15,6 @@ Page({
    */
   onLoad: async function (options) {
     let userInfo = await app.getWxUserInfo()
-    console.log(2222222222222)
-    console.log(userInfo);
     if (userInfo) {
       this.setData({
         userInfo: userInfo,
@@ -37,8 +35,6 @@ Page({
    */
   onShow: async function () {
     let userInfo = await app.getWxUserInfo()
-    console.log(2222222222222)
-    console.log(userInfo);
     if (userInfo) {
       this.setData({
         userInfo: userInfo,

+ 1 - 0
pages/person/person.wxml

@@ -7,6 +7,7 @@
                 </image>
             </view>
             <view class="tel c-707070 fw300">{{userInfo.mobile}}</view>
+            <button open-type="getPhoneNumber" bindgetphonenumber="getmobile" class="login-btn" >获取手机号</button>
         </view>
         <view class="head-img">
             <image class="" src="{{userInfo.avatar}}">

+ 4 - 1
pages/prompt/prompt.js

@@ -79,7 +79,6 @@ Page({
   getInfo : async function(e){
     const _self = this
     let userInfo = e.detail.userInfo
-    console.log(userInfo)
     userInfo['encryptedData'] = e.detail.encryptedData
     userInfo['iv'] = e.detail.iv
     let info = await app.wxLogin(userInfo);
@@ -108,6 +107,10 @@ Page({
       })
     }
 
+    wx.redirectTo({
+      url: '/'+_self.data.fromPage,
+    })
+
     console.log(_self.data.fromPage)
    
   }

+ 5 - 4
pages/shopinfo/shopinfo.js

@@ -139,13 +139,14 @@ Page({
         })
     },
     guide: function(e){
+        const self = this;
+        var lat = parseFloat(self.data.shopInfo.latitude);
+        var lon = parseFloat(self.data.shopInfo.longitude);
         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,
@@ -163,8 +164,8 @@ Page({
                     wx.setStorageSync('lon', longitude)
                     wx.setStorageSync('lat', latitude)
                     wx.openLocation({
-                        latitude:latitude,
-                        longitude: longitude,
+                        latitude:lat,
+                        longitude: lon,
                       })
                   }
                 })

+ 10 - 2
project.config.json

@@ -26,8 +26,9 @@
     "checkSiteMap": true,
     "uploadWithSourceMap": true,
     "compileHotReLoad": false,
-    "useMultiFrameRuntime": false,
+    "useMultiFrameRuntime": true,
     "useApiHook": true,
+    "useApiHostProcess": true,
     "babelSetting": {
       "ignore": [],
       "disablePlugins": [],
@@ -45,7 +46,7 @@
   },
   "compileType": "miniprogram",
   "libVersion": "2.10.4",
-  "appid": "wxac26792ea601584c",
+  "appid": "wx70aacbcde632b624",
   "projectname": "zy",
   "debugOptions": {
     "hidedInDevtools": []
@@ -87,6 +88,13 @@
         {
           "name": "pages/prompt/prompt",
           "pathName": "pages/prompt/prompt",
+          "query": "",
+          "scene": null
+        },
+        {
+          "name": "pages/appointment/appointment",
+          "pathName": "pages/appointment/appointment",
+          "query": "shopId=1&productId=1",
           "scene": null
         }
       ]

+ 1 - 1
utils/request.js

@@ -4,7 +4,7 @@ class request {
     static BASE_URL = 'https://llzlovesh.top/api/'
     static HEAD = {
         "Content-Type": "application/json",
-        "token": wx.getStorageSync('token')
+        "token": 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MTI5NTc0MDQsImV4cCI6NDA3MDg4MDAwMCwidXNlcklkIjoxMjM0NTY3ODksInZpc2l0b3IiOiJ2aXNpdG9yNjAyM2M2ZGNkZmIwNiIsImlzQWRtaW4iOjAsImFkbWluSWQiOjB9.ojdQ3bieXuJ5sKCesjVfutwDpp8f8oL0-fSJMP72XZc'
     }
     static constructor() {