start.js 12.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
// pages/start/start.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status: '',
    clientState: false,
    elcheeState: false,
    report_state: false,
    share_state: false,
    PublishId: '',
    imgUrl: '',
    GoId: '',
    show_state: true,
    allinfo:''
  },

  //登录
  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为保单分享
              wx.navigateTo({
                url: '/pages/index/verigyCode/verigyCode?PublishId=' + res.data.data.PublishId,
              })
              this.setData({
                share_state: true
              })
            } 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为文章分享

              console.log(8080)
              wx.navigateTo({
                url: '/pages/index/ArticleDetails/ArticleDetails?NewsId=' + res.data.data.NewsId + '&GoId=' + res.data.data.GoId + '&show_state=' + this.data.show_state
              })
              this.setData({
                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'
                  })
                } else if (res.data.data.UserType === 4 && res.data.data.UserType == user_index) {
                  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 {
                  if (app.globalData.UserType == 2) {
                    if (app.globalData.user_index != 2) {
                      if (this.data.share_state) {
                        this.setData({
                          clientState: false,
                        })
                      } else {
                        this.setData({
                          clientState: true,
                        })
                      }
                    }
                  } else if (app.globalData.UserType != 4) {
                    if (app.globalData.user_index == 4) {
                      this.setData({
                        elcheeState: true
                      })
                      this.getCode()
                    }
                    if (app.globalData.user_index == 2) {
                      wx.showToast({
                        title: '没有权限',
                        icon: 'none'
                      })
                    }
                  } else if (app.globalData.UserType == 3 || app.globalData.UserType == 4) {
                    if (app.globalData.user_index == 2) {
                      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
            })
            this.getCode()
          }
        } else if (app.globalData.UserType == 4) {
          if (app.globalData.user_index != 4) {
            this.setData({
              elcheeState: true
            })
            this.getCode()
          } 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) => {
      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() {
    console.log(that.data.PubilshId, 'aa')
    let that = this;
    that.setData({
      report_state: false
    })
    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)
      })
    }
  },


  getCode() {
    let that = this;
    let url = 'pubilc/Dimension';
    let params = {}
    app.post(url, params).then((res) => {
      if (res.data.code == 200) {
        that.setData({
          imgUrl: res.data.data.picurl
        })
        console.log(res.data.data.picurl)
      }
    }).catch((errMsg) => {
      console.log(errMsg)
    })
  },


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

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {


    if (options.status) {
      let allinfo = wx.getStorageSync('allinfo');
      console.log('111', allinfo)
      this.setData({
        status: options.status,
        sharetext: options.sharetext ? options.sharetext : '',
        show_state: options.show_state ? options.show_state : true,
        allinfo:allinfo
      })
    }
    console.log('onload', options, options.status)
    var that = this
    if (options.status != undefined) {
      wx.login({
        success: (res) => {
          let url = 'pubilc/sign';
          let params = {
            code: res.code,
            status: this.data.status
          }
          app.post(url, params).then((res) => {
<<<<<<< HEAD
            console.log('打印', options)
            app.globalData.UserType = res.data.data.UserType
            app.globalData.UserId = res.data.data.UserId
            // if (res.data.data.UserType == 3) {
            //   wx.switchTab({
            //     url: '/pages/index/index',
            //   })
            // } else if (res.data.data.UserType == 4) {
            //   wx.switchTab({
            //     url: '../personalCenter/personalCenter'
            //   })
            // }


            if (res.data.data.checkstatus == '3') { //3为文章分享

              console.log(8080)
              wx.navigateTo({
                url: '/pages/index/ArticleDetails/ArticleDetails?NewsId=' + res.data.data.NewsId + '&GoId=' + res.data.data.GoId + '&show_state=' + this.data.show_state
              })
              this.setData({
                GoId: res.data.data.GoId
              })
            } else if (res.data.data.checkstatus == '1') { //1为保单分享
            console.log('9090',that.data.allinfo)
              wx.navigateTo({
                url: '/pages/index/verigyCode/verigyCode?PublishId=' + res.data.data.PublishId,
               // url: '/pages/index/summaryList2/summaryList2?allinfo='+that.data.allinfo,
              
              })
              this.setData({
                share_state: true
              })
            }
            
=======
            app.globalData.UserType = res.data.data.UserType
            app.globalData.UserId = res.data.data.UserId
            if (res.data.data.UserType == 3) {
              wx.switchTab({
                url: '/pages/index/index',
              })
            } else if (res.data.data.UserType == 4) {
              wx.switchTab({
                url: '../personalCenter/personalCenter'
              })
            }
>>>>>>> 511162467aac66731406e50ab6098dae056c9a2f
          }).catch((errMsg) => {
            console.log(errMsg)
          })
        }
      });
    }
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})