1
0

index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. unPaymentNum: res.data.countMap.unPaymentNum,
  46. unTakeNum: res.data.countMap.unTakeNum,
  47. unEvalNum: res.data.countMap.unEvalNum
  48. });
  49. }
  50. });
  51. },
  52. onHide: function () {
  53. // 页面隐藏
  54. },
  55. onUnload: function () {
  56. // 页面关闭
  57. },
  58. bindMobile:function(){
  59. wx.navigateTo({
  60. url: '../../auth/newuser/newuser'
  61. })
  62. },
  63. goLogin(){
  64. user.loginByWeixin().then(res => {
  65. this.setData({
  66. userInfo: res.data.userInfo
  67. });
  68. app.globalData.userInfo = res.data.userInfo;
  69. app.globalData.token = res.data.token;
  70. }).catch((err) => {
  71. console.log(err)
  72. });
  73. },
  74. exitLogin: function () {
  75. wx.showModal({
  76. title: '',
  77. confirmColor: '#b4282d',
  78. content: '退出登录?',
  79. success: function (res) {
  80. if (res.confirm) {
  81. wx.removeStorageSync('token');
  82. wx.removeStorageSync('userInfo');
  83. app.globalData.userInfo = {
  84. nickName: '点击头像登录',
  85. avatarUrl: 'https://www.meiping123.com/upload/20171125/1721207662403.png'
  86. };
  87. wx.switchTab({
  88. url: '/pages/index/index'
  89. });
  90. }
  91. }
  92. })
  93. }
  94. })