index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var user = require('../../../services/user.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. unPayNum:0,
  8. unTakeNum:0,
  9. unEvalNum:0,
  10. userInfo: {},
  11. curUser:{},
  12. },
  13. onLoad: function (options) {
  14. // 页面初始化 options为页面跳转所带来的参数
  15. let that = this;
  16. },
  17. onReady: function () {
  18. },
  19. onShow: function () {
  20. let that = this;
  21. let userInfo = wx.getStorageSync('userInfo');
  22. let token = wx.getStorageSync('token');
  23. // 页面显示
  24. if (userInfo && token) {
  25. app.globalData.userInfo = userInfo;
  26. app.globalData.token = token;
  27. }
  28. this.setData({
  29. userInfo: app.globalData.userInfo,
  30. });
  31. util.request(api.getCurUser, {
  32. userInfo: app.globalData.userInfo
  33. }, 'POST').then(function (res) {
  34. if (res.errno === 0) {
  35. that.setData({
  36. curUser: res.data
  37. });
  38. }
  39. });
  40. // 查询骑手信息
  41. util.request(api.UcenterIndex, {}).then(function (res) {
  42. if (res.errno === 0) {
  43. that.setData({
  44. unPayNum: res.data.countMap.unPayNum,
  45. unTakeNum: res.data.countMap.unTakeNum,
  46. unEvalNum: res.data.countMap.unEvalNum
  47. });
  48. }
  49. });
  50. },
  51. onHide: function () {
  52. // 页面隐藏
  53. },
  54. onUnload: function () {
  55. // 页面关闭
  56. },
  57. bindMobile:function(){
  58. wx.navigateTo({
  59. url: '../../auth/newuser/newuser'
  60. })
  61. },
  62. goLogin(){
  63. user.loginByWeixin().then(res => {
  64. this.setData({
  65. userInfo: res.data.userInfo
  66. });
  67. app.globalData.userInfo = res.data.userInfo;
  68. app.globalData.token = res.data.token;
  69. }).catch((err) => {
  70. console.log(err)
  71. });
  72. },
  73. exitLogin: function () {
  74. wx.showModal({
  75. title: '',
  76. confirmColor: '#b4282d',
  77. content: '退出登录?',
  78. success: function (res) {
  79. if (res.confirm) {
  80. wx.removeStorageSync('token');
  81. wx.removeStorageSync('userInfo');
  82. app.globalData.userInfo = {
  83. nickName: '点击头像登录',
  84. avatarUrl: 'https://www.meiping123.com/upload/20171125/1721207662403.png'
  85. };
  86. wx.switchTab({
  87. url: '/pages/index/index'
  88. });
  89. }
  90. }
  91. })
  92. }
  93. })