index.js 2.5 KB

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