1
0

index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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).then(function (res) {
  32. if (res.errno === 0) {
  33. that.setData({
  34. curUser: res.data
  35. });
  36. }
  37. });
  38. // 查询骑手信息
  39. util.request(api.UcenterIndex, {}).then(function (res) {
  40. if (res.errno === 0) {
  41. that.setData({
  42. unPayNum: res.data.countMap.unPayNum,
  43. unTakeNum: res.data.countMap.unTakeNum,
  44. unEvalNum: res.data.countMap.unEvalNum
  45. });
  46. }
  47. });
  48. },
  49. onHide: function () {
  50. // 页面隐藏
  51. },
  52. onUnload: function () {
  53. // 页面关闭
  54. },
  55. bindMobile:function(){
  56. wx.navigateTo({
  57. url: '../../auth/newuser/newuser'
  58. })
  59. },
  60. goLogin(){
  61. user.loginByWeixin().then(res => {
  62. this.setData({
  63. userInfo: res.data.userInfo
  64. });
  65. app.globalData.userInfo = res.data.userInfo;
  66. app.globalData.token = res.data.token;
  67. }).catch((err) => {
  68. console.log(err)
  69. });
  70. },
  71. exitLogin: function () {
  72. wx.showModal({
  73. title: '',
  74. confirmColor: '#b4282d',
  75. content: '退出登录?',
  76. success: function (res) {
  77. if (res.confirm) {
  78. wx.removeStorageSync('token');
  79. wx.removeStorageSync('userInfo');
  80. app.globalData.userInfo = {
  81. nickName: '点击头像登录',
  82. avatarUrl: 'https://www.meiping123.com/upload/20171125/1721207662403.png'
  83. };
  84. wx.switchTab({
  85. url: '/pages/index/index'
  86. });
  87. }
  88. }
  89. })
  90. }
  91. })