index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // pages/mine/index.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. toolHeight: app.globalData.statusBarHeight,
  9. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  10. roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : [],
  11. avatar: '',
  12. name: '',
  13. phone: '',
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. wx.login({
  20. success: (res) => {
  21. console.log(res.code)
  22. }
  23. })
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow() {
  29. const roleCodeList = wx.getStorageSync('roleCodeList')
  30. let loginStatus = wx.getStorageSync('loginStatus')
  31. this.setData({
  32. roleCodeList: roleCodeList ? roleCodeList : [],
  33. loginStatus: loginStatus ? loginStatus : false,
  34. avatar: wx.getStorageSync('avatar') ? wx.getStorageSync('avatar') : '/images/headerImg.png',
  35. name: wx.getStorageSync('name') ? wx.getStorageSync('name') : '未填写',
  36. phone: wx.getStorageSync('phone') ? wx.getStorageSync('phone') : '手机号',
  37. })
  38. // let selected = 2
  39. // //动态tabbar
  40. // if (roleCodeList == 'bizAdmin') {
  41. // this.getTabBar().setData({
  42. // list: app.globalData.allList[0].list2,
  43. // })
  44. // selected = 4
  45. // } else if (roleCodeList == 'send') {
  46. // this.getTabBar().setData({
  47. // list: app.globalData.allList[0].list3,
  48. // })
  49. // selected = 1
  50. // } else if (roleCodeList == 'sale') {
  51. // this.getTabBar().setData({
  52. // list: app.globalData.allList[0].list4,
  53. // })
  54. // } else if (roleCodeList == 'customer') {
  55. // this.getTabBar().setData({
  56. // list: app.globalData.allList[0].list5,
  57. // })
  58. // } else if (roleCodeList == 'driver' || roleCodeList == '') {
  59. // this.getTabBar().setData({
  60. // list: app.globalData.allList[0].list1,
  61. // })
  62. // }
  63. // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  64. // this.getTabBar().setData({
  65. // selected: selected
  66. // })
  67. // }
  68. },
  69. //获取用户信息
  70. getInfo: function () {
  71. },
  72. //绑定微信
  73. bindingWX: function () {
  74. let _this = this;
  75. if (this.data.loginStatus) {
  76. wx.showModal({
  77. title: '提示',
  78. content: '确定绑定该微信账号?',
  79. success: function (res) {
  80. if (res.confirm) {
  81. wx.login({
  82. success: (res) => {
  83. app.request.POST({
  84. url: app.API.bindingWX,
  85. params: {
  86. 'id': wx.getStorageSync('id'),
  87. 'js_code': res.code
  88. },
  89. page: _this,
  90. isLoadingTxt: '绑定中...',
  91. isSubmitting: true,
  92. successFun: true
  93. }).then(res => {
  94. wx.showToast({
  95. title: '绑定成功',
  96. icon: 'success',
  97. duration: 2000,
  98. complete: function () {
  99. setTimeout(() => {
  100. wx.navigateBack()
  101. }, 1500) //延迟时间
  102. }
  103. })
  104. })
  105. },
  106. })
  107. }
  108. }
  109. })
  110. } else {
  111. wx.showToast({
  112. title: '您还未登录!',
  113. icon: 'none',
  114. duration: 1500,
  115. mask: true
  116. })
  117. }
  118. },
  119. toLogin: function () { //跳转至账号登录页面
  120. wx.navigateTo({
  121. url: '../login/index?page=mine',
  122. })
  123. },
  124. // 菜单页面跳转
  125. toLink: function (e) {
  126. if (this.data.loginStatus) {
  127. wx.navigateTo({
  128. url: e.currentTarget.dataset.url,
  129. })
  130. } else {
  131. wx.showToast({
  132. icon: 'none',
  133. title: '登录后可操作',
  134. duration: 1500
  135. })
  136. }
  137. },
  138. //退出登录
  139. logout: function (e) {
  140. let _this = this
  141. if (this.data.loginStatus) {
  142. wx.showModal({
  143. title: '提示',
  144. content: '确定退出登录?',
  145. success: function (res) {
  146. if (res.confirm) {
  147. app.request.GET({
  148. url: app.API.logout,
  149. page: _this,
  150. successFun: true
  151. }).then(res => {
  152. wx.clearStorageSync()
  153. _this.setData({
  154. loginStatus: false
  155. })
  156. _this.onShow()
  157. // _this.getTabBar().setData({
  158. // list: app.globalData.allList[0].list1,
  159. // })
  160. wx.showToast({
  161. title: '退出成功',
  162. icon: 'success',
  163. duration: 2000,
  164. complete: function () {
  165. setTimeout(function () {
  166. // wx.reLaunch({
  167. // url: '/pages/login/index',
  168. // })
  169. }, 1500) //延迟时间
  170. }
  171. })
  172. })
  173. }
  174. }
  175. })
  176. } else {
  177. app.util.checkForm('登录后可操作')
  178. }
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide() {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload() {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh() {
  194. },
  195. /**
  196. * 页面上拉触底事件的处理函数
  197. */
  198. onReachBottom() {
  199. },
  200. /**
  201. * 用户点击右上角分享
  202. */
  203. onShareAppMessage() {
  204. }
  205. })