zhashaonan 6 år sedan
förälder
incheckning
3aa7c9f480

+ 3 - 88
app.js

@@ -1,96 +1,11 @@
 //app.js
-const api = require('./config.js');
-
+import WxAuthor from './utils/WxAuthor'
 App({
-  host: api.host,
   onLaunch: function () {
     let self = this;
     // 登录
-    wx.login({
-      success: res => {
-        wx.request({
-          url: self.host,
-          data: {
-            act: "login",
-            op: "ministart",
-            code: res.code,
-            client_type: "mini"
-          },
-          success: function (res) {
-            self.globalData.userId.openid = res.data.datas.openid;
-            self.globalData.userId.unionid = res.data.datas.unionid;
-            // 获取用户信息
-            wx.getSetting({
-              success: res => {
-                if (res.authSetting['scope.userInfo']) {
-                  wx.getUserInfo({
-                    success: res => {
-                      self.globalData.userInfo = res.userInfo;
-                      self.globalData.userInfo.nickname = res.userInfo.nickName;
-                      let userInfo = Object.assign({}, self.globalData.userId, self.globalData.userInfo);
-                      wx.request({
-                        url: self.host,
-                        method: 'GET',
-                        data: {
-                          user_info: userInfo,
-                          act: "login",
-                          op: "wxauthen",
-                          client_type: "mini"
-                        },
-                        success: function (res) {
-                          wx.setStorageSync('session_id', res.data.datas.HPHPSESSID);
-                          if (res.statusCode == 200) {
-                            let len = getCurrentPages().length
-                            let currentPage = getCurrentPages()[len - 1]
-                            let params = ''
-                            if (currentPage.options) {
-                              for (let k in currentPage.options) {
-                                params = params + k + '=' + currentPage.options[k] + '&'
-                              }
-                              params = params.slice(0, params.length - 1)
-                            }
-                            let current_url = "/" + currentPage['route']
-                            if (params) {
-                              current_url = current_url + '?' + params
-                            }
-                            console.log('current_url:', current_url);
-                            wx.reLaunch({
-                              url: current_url
-                            });
-                          }
-                          else {
-
-                          }
-                        }
-                      })
-                      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
-                      // 所以此处加入 callback 以防止这种情况
-                      if (this.userInfoReadyCallback) {
-                        this.userInfoReadyCallback(res)
-                      }
-                    }
-                  })
-                }
-                else {
-                  
-                  let len = getCurrentPages().length
-                  let currentPage = getCurrentPages()[len - 1].route
-                  console.log('currentPage:', getCurrentPages()[len - 1]);
-                  if(currentPage.indexOf('shareBonus/shareBonus') != -1) {
-                    wx.navigateTo({
-                      url: `/pages/login/login`
-                    });
-                    return;
-                  }
-                  return;
-                }
-              }
-            })
-          }
-        })
-        // 发送 res.code 到后台换取 openId, sessionKey, unionId
-      }
-    })
+    new WxAuthor(self)
+ 
   },
   globalData: {
     userId: {

+ 0 - 2
config.js

@@ -19,8 +19,6 @@ function getReq(data, callback, method) {
       'Cookie': 'MPHPSESSID=' + session_id
     }
   }
-
-
   return wx.request({
     url: api,
     data,

BIN
image/empty.png


+ 57 - 0
pages/components/auth/auth.js

@@ -0,0 +1,57 @@
+// pages/components/auth/auth.js
+const api = require('../../../config');
+let app = getApp();
+Component({
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+
+  },
+
+  /**
+   * 组件的初始数据
+   */
+  data: {
+
+  },
+
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    userInfoHandler(e) {
+      let self = this
+      if (e.detail.errMsg == "getUserInfo:ok") {
+        app.globalData.userInfo = e.detail.userInfo;
+        app.globalData.userInfo.nickname = e.detail.userInfo.nickName;
+        let userInfo = Object.assign({}, app.globalData.userId, app.globalData.userInfo);
+        wx.request({
+          url: api.host,
+          method: 'GET',
+          data: {
+            user_info: userInfo,
+            act: "login",
+            op: "wxauthen",
+            client_type: "mini"
+          },
+          success: function (res) {
+            wx.setStorageSync('session_id', res.data.datas.HPHPSESSID);
+            if (res.statusCode == 200) {
+              self.triggerEvent('getAuth', {
+                userInfo
+              })
+            }
+            else {
+              wx.showToast({
+                icon: 'none',
+                title: '登陆失败',
+                duration: 2000
+              })
+            }
+          }
+        })
+      }
+    }
+  }
+})

+ 4 - 0
pages/components/auth/auth.json

@@ -0,0 +1,4 @@
+{
+  "component": true,
+  "usingComponents": {}
+}

+ 5 - 0
pages/components/auth/auth.wxml

@@ -0,0 +1,5 @@
+<!--pages/components/auth/auth.wxml-->
+<view class="auth_container">
+  <image class="auth_bg" src="../../../image/empty.png"></image>
+  <button style='margin-top:80rpx;width:60%;height: 92rpx;background: #2b2b2b;color: #fff;' open-type="getUserInfo" bindgetuserinfo="userInfoHandler">立即授权</button>
+</view>

+ 18 - 0
pages/components/auth/auth.wxss

@@ -0,0 +1,18 @@
+/* pages/components/auth/auth.wxss */
+.auth_container {
+  position: fixed;
+  left: 0;
+  right: 0;
+  top: 0;
+  bottom: 0;
+  z-index: 9999;
+  padding-top: 40rpx;
+  box-sizing: border-box;
+  background: #fff;
+}
+.auth_bg {
+  display: block;
+  width: 523rpx;
+  height: 300rpx;
+  margin: auto;
+}

+ 1 - 5
pages/details/details.js

@@ -63,11 +63,7 @@ Page({
       WxParse.wxParse('article', 'html', str, that);
     });
   },
-  shareBonus() {
-    wx.navigateTo({
-      url: `/pages/shareBonus/shareBonus?type_sn=58841537878020836581&relay_id=111`
-    })
-  },
+  
   getDatas(goods_id) {
 
     let fromSource = recordSource(app, `act=goods_common&op=index&goods_id=${goods_id}&client_type=mini`)

+ 6 - 0
pages/details/details.wxml

@@ -17,7 +17,13 @@
     </swiper>
   </view>
   <view class="place-bacd9"></view>
+
+
+  
   <!-- <view bindtap="toWebView">查看详情</view> -->
+
+
+
   <view class="promotion_header align_center" wx:if="{{getOneSummary['act_type'] == 2}}">
     <view class="promotion_single">限时特价</view>
     <view>还剩

+ 4 - 1
pages/details/details.wxss

@@ -710,8 +710,9 @@
   position: absolute;
   display: flex;
   align-items: center;
+  justify-content: center;
   width: 100rpx;
-  right: 0rpx;
+  right: 0;
   top: 0;
   bottom: 0;
 }
@@ -719,6 +720,8 @@
   width: 16rpx;
   height: 30rpx;
   position: absolute;
+  top: 50%;
+  margin-top: -15rpx;
   right: 30rpx;
 }
 .ensure_desc_text {

+ 1 - 15
pages/index/index.js

@@ -18,22 +18,13 @@ Page({
   onShow: function () {
     if (!this.data.firstLoad) {
       app.setFromSource(this.data.fromSource)
-      if (app.globalData.backLogin) {
-        app.globalData.backLogin = false;
-        // this.getDatas(0)
-        this.req_tabs(); // old
-      }
     }
-    // if (app.globalData.backLogin && !this.data.firstLoad) {
-    //   app.globalData.backLogin = false;
-    //   this.getDatas(0)
-    // }
   },
 
   onLoad: function () {
     this.req_tabs(); // old
-    // this.getDatas(0)
   },
+ 
   getDatas(special_id) {
     let fromSource = recordSource(app, 'act=special&op=index&special_id=0&page=10&curpage=1&client_type=mini')
     wx.showLoading({
@@ -120,12 +111,8 @@ Page({
     if (this.data.isSendProp) {
       return;
     }
-
     let surplus_special_num = this.data.surplus_special.length;
     if (surplus_special_num > 0) {
-      // wx.showLoading({
-      //   title: '加载中'
-      // });
       this.setData({
         isSendProp: true
       });
@@ -139,7 +126,6 @@ Page({
       this.setData({
         isSendProp: false
       });
-      // wx.hideLoading();
     }
   }
 })

+ 0 - 10
pages/login/login.js

@@ -14,7 +14,6 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-    console.log('loginoptions:', options);
     let url = options.url || ''
     this.setData({
       url
@@ -81,15 +80,6 @@ Page({
           wx.setStorageSync('session_id', res.data.datas.HPHPSESSID);
           if (res.statusCode == 200) {
             app.globalData.backLogin = true;
-            let len = getCurrentPages().length
-            let prev = getCurrentPages()[len - 2]
-            if (prev['route'].indexOf('shareBonus/shareBonus') != -1) {
-              let { type_sn, relay_id } = prev.options
-              wx.reLaunch({
-                url: `/pages/shareBonus/shareBonus?type_sn=${type_sn}&relay_id=${relay_id}`
-              })
-              return
-            }
             wx.navigateBack();
           }
           else {

+ 11 - 18
pages/person/person.js

@@ -22,7 +22,8 @@ Page({
     evaluate_count: 0, // 已收货 40
     bonus_total: 0,
     fromSource: '',
-    firstLoad: true
+    firstLoad: true,
+    userInfo: app.globalData.userInfo
   },
 
   /**
@@ -42,27 +43,19 @@ Page({
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow: function () {
-  
-
-    
-    const count = this.data.login_count;
-    if (!app.globalData.userInfo && count <= 2) {
+  getAuth(e) {
+    let { userInfo } = e.detail
+    if (userInfo) {
       this.setData({
-        login_count: this.data.login_count + 1
+        userInfo
       })
-      wx.navigateTo({
-        url: '/pages/login/login'
-      });
-      return;
-    }
-    if (!app.globalData.userInfo && count > 2) {
-      this.setData({
-        login_count: 1
-      })
-      wx.switchTab({
+      wx.reLaunch({
         url: '/pages/index/index'
       });
+    }
+  },
+  onShow: function () {
+    if(!app.globalData.userInfo) {
       return;
     }
     let fromSource = this.data.fromSource

+ 4 - 1
pages/person/person.json

@@ -1,3 +1,6 @@
 {
-    "navigationBarTitleText": "我"
+    "navigationBarTitleText": "我",
+    "usingComponents": {
+      "auth": "../components/auth/auth"
+    }
 }

+ 1 - 3
pages/person/person.wxml

@@ -1,4 +1,5 @@
 <view>
+  <auth wx:if="{{!userInfo}}" bind:getAuth="getAuth"></auth>
   <view class="person_header">
     <div class="card">
       <image class="card_bg" src="../../image/person/card_bg.png"></image>
@@ -9,9 +10,6 @@
           <view class="mt30">
             <text class="bonus_balance_detail" bindtap='skip_bonus_rule'>红包使用规则></text>
           </view>
-         
-        
-        <!-- <view class="use_bonus_rules" bindtap='skip_bonus_rule'>红包使用规则></view> -->
       </view>
     </div>
   </view>

+ 20 - 2
pages/shareBonus/shareBonus.js

@@ -21,6 +21,8 @@ Page({
     input_msg: '',
     result_msg: '留言',
     summarys: false,
+    userInfo: null,
+    options: ''
   },
 
   /**
@@ -28,15 +30,31 @@ Page({
    */
   onLoad: function (options) {
     let self = this
+    this.setData({
+      options
+    })
     app.userInfoReadyCallback = res => {
-      console.log('res:', res);
       if (app.globalData.userInfo) {
         self.init(options)
+        self.setData({
+          userInfo: app.globalData.userInfo
+        })
       }
     }
-
     if (app.globalData.userInfo) {
       self.init(options)
+      self.setData({
+        userInfo: app.globalData.userInfo
+      })
+    }
+  },
+  getAuth(e) {
+    let { userInfo } = e.detail
+    if (userInfo) {
+      this.init(this.data.options)
+      this.setData({
+        userInfo
+      })
     }
   },
   init(options) {

+ 2 - 1
pages/shareBonus/shareBonus.json

@@ -1,6 +1,7 @@
 {
   "component": true,
   "usingComponents": {
-    "twoColumns":"../components/blocks/twoColumns/twoColumns"
+    "twoColumns":"../components/blocks/twoColumns/twoColumns",
+    "auth": "../components/auth/auth"
   }
 }

+ 1 - 0
pages/shareBonus/shareBonus.wxml

@@ -1,5 +1,6 @@
 <!--pages/pandaBonus/pandaBonus.wxml-->
 <view>
+  <auth wx:if="{{!userInfo}}" bind:getAuth="getAuth"></auth>
   <!-- 活动未开始 -->
   <view class="default_container" wx:if="{{bonus_state == 'unstart'}}">
     <view class="dot_left"></view>

+ 1 - 1
pages/shopCart/shopCart.wxml

@@ -82,7 +82,7 @@
             <text class="original_price line-through ml10">天猫价{{item['goods_summary']['goods_price']}}</text>
           </view>
         </view>
-        <view class='num_handle'>
+        <view class='num_handle default_num_handle'>
           <text class='handle_btn' bindtap='goods_num_handle' data-goodsid="{{item['goods_id']}}" data-cartid="{{item['cart_id']}}"
             data-function='minus' data-num="{{item['goods_num']}}">-</text>
           <block>

+ 14 - 17
pages/shopCart/shopCart.wxss

@@ -66,6 +66,13 @@
 }
 .goods_content {
   max-width: 400rpx;
+  height: 160rpx;
+  position: relative;
+}
+.goods_content .goods_price{
+  position: absolute;
+  left: 0;
+  bottom: 0;
 }
 .icon_empty {
   display: inline-block;
@@ -88,28 +95,15 @@
   color: #999;
   position: relative;
 }
-/* .original_price::after {
-  content: "";
-  position: absolute;
-  top: 15rpx;
-  right: 0;
-  left: 0;
-  height: 3rpx;
-  background: #929292;
-} */
+
 .bonus_price {
   font-weight: bold;
   font-size: 30rpx;
   color: #333;
 }
-/* .original_price {
-  font-size: 24rpx;
-  color:#999;
-  margin:0 10rpx; 
-} */
+
 .cart_item {
   background: #ffffff;
-  /* margin-bottom: 8rpx; */
   position: relative;
   padding: 20rpx 0;
   display: flex;
@@ -149,12 +143,15 @@
 }
 .num_handle {
   position: absolute;
-  bottom: 20rpx;
+  bottom: 38rpx;
   right: 10rpx;
   font-size: 0;
   /* border: 1px solid #CFCFCF; */
   /* border-radius: 6rpx; */
 }
+.num_handle.default_num_handle {
+  bottom: 20rpx;
+}
 .handle_btn {
     color: #999;
     display: inline-block;
@@ -164,7 +161,7 @@
     font-size: 40rpx;
 }
 .num {
-    font-size: 30rpx;
+    font-size: 40rpx;
     display: inline-block;
     /* vertical-align: middle; */
     width: 40rpx;

+ 5 - 2
utils/Bundle.js

@@ -18,14 +18,14 @@ export default class Bundle {
 
   createOrders() {
     let arr = []
-    this.goods_list.map(item => {
+    this.goods_list.forEach(item => {
       if(item['bl_id'] > 0) {
         // 有套餐, 生成套餐数据
         let data = this.createBuildings(item)
         data = Object.assign({}, item, data)
         // data['goods_num'] = item['goods_num']
         let totalPrice = 0;
-        data['goods'].map(value => {
+        data['goods'].forEach(value => {
           value['goods_summary'] = this.sumary.get(value['goods_id'])
           value['goods_summary']['goods_price'] = parseFloat(value['goods_summary']['goods_price'])
           totalPrice += value['goods_summary']['goods_price']
@@ -36,6 +36,9 @@ export default class Bundle {
       else {
         let defaultData = this.createDefault(item)
         item['goods_summary'] = defaultData
+        item['goods_summary']['bonus_price'] = parseFloat(item['goods_summary']['bonus_price'])
+        item['goods_summary']['goods_promotion_price'] = parseFloat(item['goods_summary']['goods_promotion_price'])
+        item['goods_summary']['goods_price'] = parseFloat(item['goods_summary']['goods_price'])
         arr.push(item)
       }
     })

+ 106 - 0
utils/WxAuthor.js

@@ -0,0 +1,106 @@
+const getReq = require('../config.js').getReq
+const api = require('../config.js').host
+
+export default class WxAuthor {
+  constructor(app) {
+    this.target = app
+    this.init()
+  }
+  // 首先wx.login
+  init() {
+    wx.login({
+      success: res => {
+        this.ministart(res.code)
+      }
+    })
+  }
+  // 拿到code 请求act=login op=ministart
+  ministart(code) {
+    let params = {
+      act: "login",
+      op: "ministart",
+      code
+    }
+    getReq(params, res => {
+      let { openid, unionid } = res.datas
+      this.setId(openid, unionid)
+      // 获取用户授权设置信息
+      this.getSetting()
+    })
+  }
+
+  getSetting() {
+    wx.getSetting({
+      success: res => {
+        if (res.authSetting['scope.userInfo']) {
+          this.getUserInfo()
+        }
+        else {
+          return 
+        }
+      }
+    })
+  }
+
+  getUserInfo() {
+    wx.getUserInfo({
+      success: res => {
+        this.setUserInfo(res.userInfo, res.userInfo.nickName)
+        let userInfo = Object.assign({}, this.target.globalData.userId, this.target.globalData.userInfo)
+        this.wxauthen(userInfo)
+      }
+    })
+  }
+  wxauthen(userInfo) {
+    let params = {
+      user_info: userInfo,
+      act: "login",
+      op: "wxauthen"
+    }
+    getReq(params, res => {
+      wx.setStorageSync('session_id', res.datas.HPHPSESSID)
+      if (res.code == 200) {
+        let url = this.getUrl()
+        wx.reLaunch({
+          url
+        })
+      }
+      else {
+        wx.showToast({
+              icon: 'none',
+              title: '登陆失败',
+              duration: 2000
+            })
+      }
+    })
+  }
+
+  getUrl() {
+    let len = getCurrentPages().length
+    let currentPage = getCurrentPages()[len - 1]
+    let params = ''
+    if (currentPage.options) {
+      for (let k in currentPage.options) {
+        params = params + k + '=' + currentPage.options[k] + '&'
+      }
+      params = params.slice(0, params.length - 1)
+    }
+    let current_url = "/" + currentPage['route']
+    if (params) {
+      current_url = current_url + '?' + params
+    }
+    return current_url
+  }
+
+  // 设置用户信息
+  setUserInfo(userInfo, nickName) {
+    this.target.globalData.userInfo = userInfo
+    this.target.globalData.userInfo.nickname = nickName
+  }
+
+  //设置openid, unionid
+  setId(openid, unionid) {
+    this.target.globalData.userId.openid = openid
+    this.target.globalData.userId.unionid = unionid
+  }
+}