index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. this.setData({
  28. userInfo: app.globalData.userInfo,
  29. });
  30. util.request(api.getCurUser, {
  31. userInfo: app.globalData.userInfo
  32. }, 'POST').then(function (res) {
  33. if (res.errno === 0) {
  34. that.setData({
  35. curUser: res.data
  36. });
  37. }
  38. });
  39. // 查询骑手信息
  40. util.request(api.UcenterIndex, {}).then(function (res) {
  41. if (res.errno === 0) {
  42. if (res.data.countMap.orders > 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. } else {
  53. wx.navigateTo({
  54. url: '/pages/auth/btnAuth/btnAuth',
  55. })
  56. }
  57. },
  58. onHide: function () {
  59. // 页面隐藏
  60. },
  61. onUnload: function () {
  62. // 页面关闭
  63. },
  64. bindMobile:function(){
  65. wx.navigateTo({
  66. url: '../../auth/newuser/newuser'
  67. })
  68. },
  69. // goLogin(){
  70. // user.loginByWeixin().then(res => {
  71. // this.setData({
  72. // userInfo: res.data.data.userInfo
  73. // });
  74. // app.globalData.userInfo = res.data.data.userInfo;
  75. // app.globalData.token = res.data.token;
  76. // }).catch((err) => {
  77. // console.log(err)
  78. // });
  79. // },
  80. allOrder() {
  81. wx.navigateTo({
  82. url: '/pages/ucenter/order/order'
  83. })
  84. },
  85. exitLogin: function () {
  86. wx.showModal({
  87. title: '',
  88. confirmColor: '#b4282d',
  89. content: '退出登录?',
  90. success: function (res) {
  91. if (res.confirm) {
  92. wx.removeStorageSync('token');
  93. wx.removeStorageSync('userInfo');
  94. app.globalData.userInfo = {
  95. nickName: '点击头像登录',
  96. avatarUrl: 'http://120.76.26.84:80/group1/M00/00/02/rBJEdVvr3_eAJe0WAAAB_us54MA728.png'
  97. };
  98. wx.switchTab({
  99. url: '/pages/index/index'
  100. });
  101. }
  102. }
  103. })
  104. }
  105. })