index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var user = require('../../../utils/user.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. userInfo: {
  8. nickName: '点击登录',
  9. avatarUrl: '/static/images/my.png'
  10. },
  11. order: {
  12. unpaid: 0,
  13. unship: 0,
  14. unrecv: 0,
  15. uncomment: 0
  16. },
  17. hasLogin: false
  18. },
  19. onLoad: function(options) {
  20. // 页面初始化 options为页面跳转所带来的参数
  21. },
  22. onReady: function() {
  23. },
  24. onShow: function() {
  25. //获取用户的登录信息
  26. if (app.globalData.hasLogin) {
  27. let userInfo = wx.getStorageSync('userInfo');
  28. this.setData({
  29. userInfo: userInfo,
  30. hasLogin: true
  31. });
  32. let that = this;
  33. util.request(api.UserIndex).then(function(res) {
  34. if (res.errno === 0) {
  35. that.setData({
  36. order: res.data.order
  37. });
  38. }
  39. });
  40. }
  41. },
  42. onHide: function() {
  43. // 页面隐藏
  44. },
  45. onUnload: function() {
  46. // 页面关闭
  47. },
  48. goLogin() {
  49. if (!this.data.hasLogin) {
  50. wx.navigateTo({
  51. url: "/pages/auth/login/login"
  52. });
  53. }
  54. },
  55. goOrder() {
  56. if (this.data.hasLogin) {
  57. try {
  58. wx.setStorageSync('tab', 0);
  59. } catch (e) {
  60. }
  61. wx.navigateTo({
  62. url: "/pages/ucenter/order/order"
  63. });
  64. } else {
  65. wx.navigateTo({
  66. url: "/pages/auth/login/login"
  67. });
  68. }
  69. },
  70. goOrderIndex(e) {
  71. if (this.data.hasLogin) {
  72. let tab = e.currentTarget.dataset.index
  73. let route = e.currentTarget.dataset.route
  74. try {
  75. wx.setStorageSync('tab', tab);
  76. } catch (e) {
  77. }
  78. wx.navigateTo({
  79. url: route,
  80. success: function(res) {},
  81. fail: function(res) {},
  82. complete: function(res) {},
  83. })
  84. } else {
  85. wx.navigateTo({
  86. url: "/pages/auth/login/login"
  87. });
  88. };
  89. },
  90. goCoupon() {
  91. if (this.data.hasLogin) {
  92. wx.navigateTo({
  93. url: "/pages/ucenter/couponList/couponList"
  94. });
  95. } else {
  96. wx.navigateTo({
  97. url: "/pages/auth/login/login"
  98. });
  99. };
  100. },
  101. goGroupon() {
  102. if (this.data.hasLogin) {
  103. wx.navigateTo({
  104. url: "/pages/groupon/myGroupon/myGroupon"
  105. });
  106. } else {
  107. wx.navigateTo({
  108. url: "/pages/auth/login/login"
  109. });
  110. };
  111. },
  112. goCollect() {
  113. if (this.data.hasLogin) {
  114. wx.navigateTo({
  115. url: "/pages/ucenter/collect/collect"
  116. });
  117. } else {
  118. wx.navigateTo({
  119. url: "/pages/auth/login/login"
  120. });
  121. };
  122. },
  123. goFeedback(e) {
  124. if (this.data.hasLogin) {
  125. wx.navigateTo({
  126. url: "/pages/ucenter/feedback/feedback"
  127. });
  128. } else {
  129. wx.navigateTo({
  130. url: "/pages/auth/login/login"
  131. });
  132. };
  133. },
  134. goFootprint() {
  135. if (this.data.hasLogin) {
  136. wx.navigateTo({
  137. url: "/pages/ucenter/footprint/footprint"
  138. });
  139. } else {
  140. wx.navigateTo({
  141. url: "/pages/auth/login/login"
  142. });
  143. };
  144. },
  145. goAddress() {
  146. if (this.data.hasLogin) {
  147. wx.navigateTo({
  148. url: "/pages/ucenter/address/address"
  149. });
  150. } else {
  151. wx.navigateTo({
  152. url: "/pages/auth/login/login"
  153. });
  154. };
  155. },
  156. bindPhoneNumber: function(e) {
  157. if (e.detail.errMsg !== "getPhoneNumber:ok") {
  158. // 拒绝授权
  159. return;
  160. }
  161. if (!this.data.hasLogin) {
  162. wx.showToast({
  163. title: '绑定失败:请先登录',
  164. icon: 'none',
  165. duration: 2000
  166. });
  167. return;
  168. }
  169. util.request(api.AuthBindPhone, {
  170. iv: e.detail.iv,
  171. encryptedData: e.detail.encryptedData
  172. }, 'POST').then(function(res) {
  173. if (res.errno === 0) {
  174. wx.showToast({
  175. title: '绑定手机号码成功',
  176. icon: 'success',
  177. duration: 2000
  178. });
  179. }
  180. });
  181. },
  182. goAfterSale: function() {
  183. if (this.data.hasLogin) {
  184. wx.navigateTo({
  185. url: "/pages/ucenter/aftersaleList/aftersaleList"
  186. });
  187. } else {
  188. wx.navigateTo({
  189. url: "/pages/auth/login/login"
  190. });
  191. };
  192. },
  193. aboutUs: function() {
  194. wx.navigateTo({
  195. url: '/pages/about/about'
  196. });
  197. },
  198. goHelp: function () {
  199. wx.navigateTo({
  200. url: '/pages/help/help'
  201. });
  202. },
  203. exitLogin: function() {
  204. wx.showModal({
  205. title: '',
  206. confirmColor: '#b4282d',
  207. content: '退出登录?',
  208. success: function(res) {
  209. if (!res.confirm) {
  210. return;
  211. }
  212. util.request(api.AuthLogout, {}, 'POST');
  213. app.globalData.hasLogin = false;
  214. wx.removeStorageSync('token');
  215. wx.removeStorageSync('userInfo');
  216. wx.reLaunch({
  217. url: '/pages/index/index'
  218. });
  219. }
  220. })
  221. }
  222. })