myCenter.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // pages/nais/nais.js
  2. import {
  3. imgUrl
  4. } from "../api/request"
  5. import {
  6. cacheGet
  7. } from "../../utils/cacheUtil"
  8. import {
  9. baseUrl,
  10. request
  11. } from "../../pages/api/canteen-request.js"
  12. let app = getApp();
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. canIUseGetUserProfile: true,
  19. nickName: "",
  20. avatarUrl: "",
  21. hasUserInfo: false,
  22. imgUrl: imgUrl,
  23. show: false,
  24. showWorkOrder: false,
  25. showCeenter:false,
  26. scroll_height:""
  27. },
  28. // 自定义函数
  29. toCanteen: function (e) {
  30. wx.navigateTo({
  31. url: '/pages/ourCanteen/ourCanteen'
  32. })
  33. },
  34. toWorkOrder: function (e) {
  35. wx.navigateTo({
  36. url: '/pagesPublic/pages/work-order/work-order'
  37. });
  38. },
  39. handleAction() {
  40. var that = this
  41. wx.showActionSheet({
  42. itemList: ['退出登录'],
  43. success(res) {
  44. // console.log(res.tapIndex)
  45. wx.clearStorageSync();
  46. that.setData({
  47. show: false,
  48. canIUseGetUserProfile: true,
  49. hasUserInfo: false
  50. })
  51. },
  52. fail(res) {
  53. // console.log(res.errMsg)
  54. }
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady() {
  61. if (typeof this.getTabBar === 'function' &&
  62. this.getTabBar()) {
  63. this.getTabBar().setData({
  64. selected: 4
  65. })
  66. }
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow() {
  72. wx.showModal({
  73. title: '提示',
  74. content: '提示用户订阅消息',
  75. success (res) {
  76. if (res.confirm) {
  77. console.log('用户点击确定')
  78. wx.requestSubscribeMessage({
  79. tmplIds: ['0Rh0woW2g6Mu6SDwDSs4x2pm6b5Re0xo_7Ugc_3pJps'],
  80. success (res) {
  81. }
  82. })
  83. } else if (res.cancel) {
  84. console.log('用户点击取消')
  85. }
  86. }
  87. })
  88. // let token = wx.getStorageSync('token');
  89. let token = cacheGet('token');
  90. if (token != null && token != '') {
  91. this.setData({
  92. canIUseGetUserProfile: false,
  93. nickName: wx.getStorageSync('nickName'),
  94. avatarUrl: wx.getStorageSync('imgUrl'),
  95. hasUserInfo: true
  96. })
  97. } else {
  98. this.setData({
  99. hasUserInfo: false,
  100. canIUseGetUserProfile: true
  101. })
  102. }
  103. if (typeof this.getTabBar === 'function' &&
  104. this.getTabBar()) {
  105. this.getTabBar().setData({
  106. selected: 4
  107. })
  108. }
  109. // 获取用户角色
  110. request({
  111. url: '/mini/worker/getUserType',
  112. method: 'GET',
  113. data: {
  114. userId: wx.getStorageSync('userid')
  115. }
  116. }).then(res => {
  117. if (res.result) {
  118. let userType = res.data;
  119. if ("0" == userType || "2" == userType) {
  120. // 显示工单维修菜单
  121. this.setData({
  122. showWorkOrder: true
  123. });
  124. }
  125. if("-1"!=userType){
  126. this.setData({
  127. showCeenter : true
  128. })
  129. }
  130. }
  131. });
  132. },
  133. onHide() {
  134. if (typeof this.getTabBar === 'function' &&
  135. this.getTabBar()) {
  136. this.getTabBar().setData({
  137. selected: -1
  138. })
  139. }
  140. },
  141. onLoad() {
  142. var windowWidth = wx.getSystemInfoSync().windowWidth;
  143. var windowHeight = wx.getSystemInfoSync().windowHeight;
  144. //rpx与px单位之间的换算 : 750/windowWidth = 屏幕的高度(rpx)/windowHeight
  145. var scroll_height = 750*windowHeight/windowWidth;
  146. this.setData({
  147. scroll_height:scroll_height
  148. })
  149. // let token = wx.getStorageSync('token');
  150. let token = cacheGet('token');
  151. if (token != null && token != '') {
  152. this.setData({
  153. nickName: wx.getStorageSync('nickName'),
  154. avatarUrl: wx.getStorageSync('imgUrl'),
  155. hasUserInfo: true
  156. })
  157. }
  158. // 获取用户角色
  159. request({
  160. url: '/mini/worker/getUserType',
  161. method: 'GET',
  162. data: {
  163. userId: wx.getStorageSync('userid')
  164. }
  165. }).then(res => {
  166. if (res.result) {
  167. let userType = res.data;
  168. if ("0" == userType || "2" == userType) {
  169. // 显示工单维修菜单
  170. this.setData({
  171. showWorkOrder: true
  172. });
  173. }
  174. if("-1"!=userType){
  175. this.setData({
  176. showCeenter : true
  177. })
  178. }
  179. }
  180. });
  181. },
  182. /**
  183. * 生命周期函数--监听页面卸载
  184. */
  185. onUnload() {
  186. },
  187. /**
  188. * 页面相关事件处理函数--监听用户下拉动作
  189. */
  190. onPullDownRefresh() {
  191. },
  192. /**
  193. * 页面上拉触底事件的处理函数
  194. */
  195. onReachBottom() {
  196. },
  197. /**
  198. * 用户点击右上角分享
  199. */
  200. onShareAppMessage() {
  201. return {
  202. title: '个人中心'
  203. }
  204. },
  205. toLike() {
  206. wx.navigateTo({
  207. url: '/pagesPublic/pages/like/like',
  208. })
  209. },
  210. navto() {
  211. wx.navigateTo({
  212. url: '/pagesPublic/pages/menu/menu',
  213. })
  214. },
  215. // toPersonalData() {
  216. // wx.navigateTo({
  217. // url: '/pagesPublic/pages/personalData/index/personalData',
  218. // })
  219. // },
  220. gotoMyCollection() {
  221. wx.navigateTo({
  222. url: '/pagesPublic/pages/myCollection/myCollection',
  223. })
  224. },
  225. toMyComment() {
  226. wx.navigateTo({
  227. url: '/pagesPublic/pages/myComment/myComment',
  228. })
  229. },
  230. tologin() {
  231. wx.navigateTo({
  232. url: '/pages/login/login',
  233. })
  234. },
  235. getUserInfo() {
  236. // this.setData({
  237. // nickName: wx.getStorageSync('nickName'),
  238. // avatarUrl: wx.getStorageSync('imgUrl'),
  239. // hasUserInfo: true
  240. // })
  241. },
  242. // logout(){
  243. // this.setData({
  244. // hasUserInfo: false,
  245. // nickName:"",
  246. // avatarUrl:""
  247. // })
  248. // wx.removeStorage({
  249. // key: 'nickName',
  250. // })(option)
  251. // wx.removeStorage({
  252. // key: 'imgUrl',
  253. // })(option)
  254. // }
  255. })