1
0

index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. if (wx.getStorageSync('storeId')) {
  31. util.request(api.ChooseStoreId, {
  32. storeId: wx.getStorageSync('storeId'),
  33. merchSn: wx.getStorageSync('merchSn')
  34. }, 'POST').then(function (res) {
  35. if (res.errno === 0) {
  36. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  37. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  38. that.reLoad();
  39. }
  40. });
  41. }
  42. util.request(api.getCurUser, {
  43. userInfo: app.globalData.userInfo
  44. }, 'POST').then(function (res) {
  45. if (res.errno === 0) {
  46. that.setData({
  47. curUser: res.data
  48. });
  49. }
  50. });
  51. // 查询骑手信息
  52. util.request(api.UcenterIndex, {}).then(function (res) {
  53. if (res.errno === 0) {
  54. if (res.data.countMap.orders > 0) {
  55. that.setData({
  56. unPayNum: res.data.countMap.unPayNum,
  57. unPaymentNum: res.data.countMap.unPaymentNum,
  58. unTakeNum: res.data.countMap.unTakeNum,
  59. unEvalNum: res.data.countMap.unEvalNum
  60. });
  61. }
  62. }
  63. });
  64. } else {
  65. wx.navigateTo({
  66. url: '/pages/auth/btnAuth/btnAuth',
  67. })
  68. }
  69. },
  70. onHide: function () {
  71. // 页面隐藏
  72. },
  73. onUnload: function () {
  74. // 页面关闭
  75. },
  76. reLoad: function () {
  77. let that = this;
  78. if (wx.getStorageSync('storeId')) {
  79. if (wx.getStorageSync('userId')) {
  80. wx.request({
  81. url: api.updateLoginUser,
  82. data: {
  83. userId: wx.getStorageSync('userId'), storeId: wx.getStorageSync('storeId'), merchSn: wx.getStorageSync('merchSn')
  84. },
  85. method: 'POST',
  86. header: {
  87. 'Content-Type': 'application/json'
  88. },
  89. success: function (wxRes) {
  90. if (wxRes.data.errno === 0) {
  91. // console.log("用户信息更新成功");
  92. }
  93. },
  94. fail: function (err) {
  95. console.log("failed");
  96. }
  97. });
  98. }
  99. }
  100. },
  101. bindMobile:function(){
  102. wx.navigateTo({
  103. url: '../../auth/newuser/newuser'
  104. })
  105. },
  106. // goLogin(){
  107. // user.loginByWeixin().then(res => {
  108. // this.setData({
  109. // userInfo: res.data.data.userInfo
  110. // });
  111. // app.globalData.userInfo = res.data.data.userInfo;
  112. // app.globalData.token = res.data.token;
  113. // }).catch((err) => {
  114. // console.log(err)
  115. // });
  116. // },
  117. allOrder() {
  118. wx.navigateTo({
  119. url: '/pages/ucenter/order/order'
  120. })
  121. },
  122. exitLogin: function () {
  123. wx.showModal({
  124. title: '',
  125. confirmColor: '#b4282d',
  126. content: '退出登录?',
  127. success: function (res) {
  128. if (res.confirm) {
  129. wx.removeStorageSync('token');
  130. wx.removeStorageSync('userInfo');
  131. app.globalData.userInfo = {
  132. nickName: '点击头像登录',
  133. avatarUrl: 'http://120.76.26.84:80/group1/M00/00/02/rBJEdVvr3_eAJe0WAAAB_us54MA728.png'
  134. };
  135. wx.switchTab({
  136. url: '/pages/index/index'
  137. });
  138. }
  139. }
  140. })
  141. }
  142. })