index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // index.js
  2. let myPro = require("../../../utils/wxRequest.js");
  3. let util = require("../../../utils/util.js");
  4. Page({
  5. data: {
  6. loading: false // 全局loading
  7. },
  8. onLoad: function (options) {
  9. // Do some initialize when page load.
  10. },
  11. onShow: function () {
  12. // Do something when page show.
  13. let that = this;
  14. that.setData({
  15. userInfo: getApp().globalData.userInfo
  16. });
  17. // console.log('用户信息',that.data.userInfo)
  18. // 店铺
  19. wx.getStorage({
  20. key: "store",
  21. success: function(res){
  22. that.setData({
  23. store: JSON.parse(res.data)
  24. })
  25. }
  26. });
  27. },
  28. onReady: function () {
  29. // Do something when page ready.
  30. },
  31. onHide: function () {
  32. // Do something when page hide.
  33. },
  34. onUnload: function () {
  35. // Do something when page close.
  36. },
  37. onPullDownRefresh: function () {
  38. // Do something when pull down.
  39. },
  40. onReachBottom: function () {
  41. // Do something when page reach bottom.
  42. },
  43. onPageScroll: function () {
  44. // Do something when page scroll
  45. },
  46. onResize: function () {
  47. // Do something when page resize
  48. },
  49. // 手机号授权
  50. getPhoneNumber(event){
  51. let that = this;
  52. if(event.detail.errMsg == "getPhoneNumber:ok"){
  53. console.log("手机号授权",event);
  54. // return;
  55. let params = {
  56. openid: getApp().globalData.openid,
  57. session_key: getApp().globalData.session_key,
  58. encryptedData: event.detail.encryptedData,
  59. iv: event.detail.iv,
  60. nickname: getApp().globalData.userInfo.nickname,
  61. sex: getApp().globalData.userInfo.sex,
  62. thumb: getApp().globalData.userInfo.thumb,
  63. store_id: that.data.store ? that.data.store.id : 1 // 门店id
  64. };
  65. myPro.wxRequest("user/v2/wxlogin","POST",params).then(res=>{
  66. // 存下token
  67. getApp().globalData.token = res.result.token;
  68. wx.setStorage({
  69. key: "token",
  70. data: res.result.token
  71. });
  72. // 存在会员
  73. getApp().globalData.is_member = res.result.user.is_member; // 会员 0否 1是
  74. // 存下角色
  75. if(res.result.user.store){
  76. getApp().globalData.role = 1 // 有店铺,即为门店
  77. };
  78. wx.reLaunch({
  79. url: '/pages/index/index'
  80. });
  81. }).catch(err=>{
  82. console.log("报错信息",err);
  83. wx.showToast({
  84. title: err,
  85. icon: "none"
  86. })
  87. });
  88. }
  89. },
  90. // 去手机号登录
  91. toPhoneLogin(){
  92. let that = this;
  93. wx.navigateTo({
  94. url: "/pages/login/phone/index"
  95. })
  96. },
  97. });