start.js 10.1 KB
// pages/start/start.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status: '',
    clientState: false,
    elcheeState: false,
    report_state: false,
    PublishId: '',
  },

  //登录
  start(e) {
    app.globalData.userInfo = e.detail.userInfo
    var user_index = parseInt(e.target.dataset.user)
    app.globalData.user_index = user_index

    var that = this
    wx.login({
      success: (res) => {
        let url = 'pubilc/sign';
        let params = {
          code: res.code,
          status: that.data.status //分享进入的需要此参数
        }
        app.post(url, params).then((res) => {
          console.log('start', res.data.data.UserType, res.data.data.checkstatus, res.data.data.PublishId)
          if (res.data.code == '200') {
            app.globalData.OpenId = res.data.data.OpenId;
            app.globalData.UserId = res.data.data.UserId;
            app.globalData.UserStatus = res.data.data.UserStatus; //用户状态(1初次登录,2多次登录)"
            app.globalData.UserType = res.data.data.UserType; //用户类型(2为普通会员,3为顾问,4为推广)
            app.globalData.checkstatus = res.data.data.checkstatus; //分享参数(0无,1保单,2注册,3文章)
            res.data.data.PublishId ? that.setData({
              PublishId: res.data.data.PublishId
            }):''
            
            if (res.data.data.UserType == 4) {
              app.globalData.temp_UserType = 3
            }

            if (res.data.data.type == '-3') { //-3已经注册过了
              wx.switchTab({
                url: '../index/index'
              })
            } else if (res.data.data.type == '-2') { //分享参数读取失败
              wx.navigateTo({
                url: '../index/index'
              })
            } else if (res.data.data.checkstatus == '1') { //1为保单分享
              // that.reportInfo(res.data.data.PublishId)
              wx.navigateTo({
                url: '/pages/index/summaryList2/summaryList2?PublishId=' + res.data.data.PublishId,
              })
            } else if (res.data.data.checkstatus == '2') { //2为注册分享
              wx.navigateTo({
                url: '/pages/index/register/register?sharetext=' + that.data.sharetext,
              })
            } else if (res.data.data.checkstatus == '3') { //3为文章分享
              wx.navigateTo({
                url: '/pages/index/ArticleDetails/ArticleDetails?NewsId=' + res.data.data.NewsId + '&GoId=' + res.data.data.GoId
              })
            } else if (res.data.data.checkstatus == undefined) { //分享失败

            } else {
              //无分享参数
              if (res.data.data.UserStatus == 1) { //用户状态(1初次登录需要授权,2多次登录不需要授权)
                that.getpower(); //用户授权
              } else {
                if (res.data.data.UserType === 2 && res.data.data.UserType == user_index) { //2:客户,3:顾问,4:推广语
                  wx.switchTab({
                    url: '../personalCenter/personalCenter'
                  })
                  // if (app.globalData.user_index != 2) {
                  //   this.setData({
                  //     clientState: true,
                  //   })
                  // } else if (app.globalData.user_index == 2) {
                  //   wx.switchTab({
                  //     url: '../personalCenter/personalCenter'
                  //   })
                  // }
                } else if (res.data.data.UserType === 4 && res.data.data.UserType == user_index) {
                  wx.switchTab({
                    url: '../personalCenter/personalCenter'
                  })
                  // if (app.globalData.user_index != 4) {
                  //   this.setData({
                  //     elcheeState: true
                  //   })
                  // } else if (app.globalData.user_index == 4) {
                  //   wx.switchTab({
                  //     url: '../personalCenter/personalCenter'
                  //   })
                  // }
                } else if (res.data.data.UserType === 3 && res.data.data.UserType == user_index || app.globalData.temp_UserType == user_index) {
                  wx.switchTab({
                    url: '../index/index',
                  })
                } else {
                  // wx.showToast({
                  //   title: '没有权限',
                  //   icon: 'none'
                  // })
                  if (app.globalData.UserType == 2) {
                    if (app.globalData.user_index != 2) {
                      this.setData({
                        clientState: true,
                      })
                    }
                  } else if (app.globalData.UserType != 4) {
                    if (app.globalData.user_index == 4) {
                      this.setData({
                        elcheeState: true
                      })
                    }
                  } else if (app.globalData.UserType == 3) {
                    if (app.globalData.user_index != 3) {
                      wx.showToast({
                        title: '没有权限',
                        icon: 'none'
                      })
                    }

                  }

                }
              }
            }
          }
        }).catch((errMsg) => {
          console.log(errMsg)
        })
      }
    });
  },

  cancleMask() {
    this.setData({
      clientState: false,
    })
  },

  cancleMask2() {
    this.setData({
      elcheeState: false
    })
  },

  cancleMask3() {
    this.setData({
      report_state: false
    })
  },

  getpower() { //用户授权
    let that = this;
    let url = 'pubilc/impower';
    let param = {
      OpenId: app.globalData.OpenId,
      NickName: app.globalData.userInfo.nickName,
      PicUrl: app.globalData.userInfo.avatarUrl
    }
    app.post(url, param).then((res) => {
      console.log(res, app.globalData.UserType)
      if (res.data.code == 200) {
        app.globalData.UserId = res.data.data.UserId;
        app.globalData.UserType = res.data.data.UserType;
        if (app.globalData.UserType == 2) {
          if (app.globalData.user_index != 2) {
            this.setData({
              clientState: true,
            })
          } else if (app.globalData.user_index == 2) {
            wx.switchTab({
              url: '../personalCenter/personalCenter'
            })
          } else if (app.globalData.user_index == 4) {
            this.setData({
              elcheeState: true
            })
          }
        } else if (app.globalData.UserType == 4) {
          if (app.globalData.user_index != 4) {
            this.setData({
              elcheeState: true
            })
          } else if (app.globalData.user_index == 4) {
            wx.switchTab({
              url: '../personalCenter/personalCenter'
            })
          }
        } else if (app.globalData.UserType == 3) {
          wx.switchTab({
            url: '../indexs/index/index',
          })
        }

        // else if (app.globalData.UserType == 3) {
        //   wx.switchTab({
        //     url: '../indexs/index/index',
        //   })
        // } else if (app.globalData.UserType == 4) {
        //   this.setData({
        //     elcheeState: true
        //   })
        // } else if (app.globalData.UserType == 3) {
        //   wx.switchTab({
        //     url: '../indexs/index/index',
        //   })
        // }

      }
    }).catch((errMsg) => {})
  },

  //注册顾问
  register() {
    wx.navigateTo({
      url: '../index/register/register'
    })
  },

  //客户中心
  clientCenter() {
    wx.switchTab({
      url: '../personalCenter/personalCenter',
    })
  },


  //体检报告详情检测
  reportInfo(PublishId) {
    let that = this;
    let url = 'member/publishverify';
    that.setData({
      PublishId: PublishId
    })
    app.post(url, {
      PubilshId: PublishId,
      UserId: app.globalData.UserId
    }).then((res) => {
      console.log('detail', res, PublishId)
      if (res.data.code == 200) {
        this.setData({
          type: res.data.data.type,
          mobile: res.data.data.mobile
        })
        if (res.data.data.type == -1) {
          this.setData({
            report_state: true
          })
        } else {
          wx.navigateTo({
            url: '/pages/index/summaryList2/summaryList2?PublishId=' + PublishId,
          })
        }
      }
    }).catch((errMsg) => {
      console.log(errMsg)
    })
  },


  //体检报告详情检测
  reportInfo2() {
    let that = this;
    console.log(that.data.PubilshId)
    if (that.data.code == '') {
      wx.showToast({
        title: '请输入验证码',
        icon: 'none'
      })
    } else {
      let url = 'member/publishverify';
      let params = {
        PubilshId: that.data.PubilshId,
        UserId: app.globalData.UserId,
        code: that.data.code
      }
      app.post(url, params).then((res) => {
        console.log(res)
        if (res.data.code == 200) {
          wx.navigateTo({
            url: '/pages/index/summaryList2/summaryList2?PublishId=' + that.data.PubilshId,
          })
        }
      }).catch((errMsg) => {
        console.log(errMsg)
      })
    }
  },


  setCode(e) {
    this.setData({
      code: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (options.status) {
      this.setData({
        status: options.status,
        sharetext: options.sharetext
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})