myCenter.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. // let token = wx.getStorageSync('token');
  73. let token = cacheGet('token');
  74. if (token != null && token != '') {
  75. this.setData({
  76. canIUseGetUserProfile: false,
  77. nickName: wx.getStorageSync('nickName'),
  78. avatarUrl: wx.getStorageSync('imgUrl'),
  79. hasUserInfo: true
  80. })
  81. wx.getSetting({
  82. withSubscriptions: true,
  83. success (res) {
  84. console.log(res.subscriptionsSetting);
  85. if(res.subscriptionsSetting.itemSettings['aGohosyMWmBOdzkjlD34qMRIsAPb2cVY6juinVIevgg','Zz1KCbvRe893kLn9YOH5JmTpNhBuPHoda-MCBpHyWyY','8JCTOvJtdQhfs0LFbYrF_Q2Djq6-WEozkWcv_4MEtgM'] == 'accept'){
  86. }else{
  87. wx.showModal({
  88. title: '提示',
  89. content: '点击确定订阅消息,获取最新消息',
  90. success (res) {
  91. if (res.confirm) {
  92. wx.requestSubscribeMessage({
  93. tmplIds: ['aGohosyMWmBOdzkjlD34qMRIsAPb2cVY6juinVIevgg','Zz1KCbvRe893kLn9YOH5JmTpNhBuPHoda-MCBpHyWyY','8JCTOvJtdQhfs0LFbYrF_Q2Djq6-WEozkWcv_4MEtgM'],
  94. success (res) {
  95. if(res['aGohosyMWmBOdzkjlD34qMRIsAPb2cVY6juinVIevgg','Zz1KCbvRe893kLn9YOH5JmTpNhBuPHoda-MCBpHyWyY','8JCTOvJtdQhfs0LFbYrF_Q2Djq6-WEozkWcv_4MEtgM']=='accept'){
  96. wx.showToast({
  97. title: '订阅成功',
  98. icon: 'success',
  99. duration: 2000
  100. })
  101. }
  102. }
  103. })
  104. } else if (res.cancel) {
  105. console.log('用户点击取消')
  106. }
  107. }
  108. })
  109. }
  110. }
  111. })
  112. } else {
  113. this.setData({
  114. hasUserInfo: false,
  115. canIUseGetUserProfile: true
  116. })
  117. }
  118. if (typeof this.getTabBar === 'function' &&
  119. this.getTabBar()) {
  120. this.getTabBar().setData({
  121. selected: 4
  122. })
  123. }
  124. // 获取用户角色
  125. request({
  126. url: '/mini/worker/getUserType',
  127. method: 'GET',
  128. data: {
  129. userId: wx.getStorageSync('userid')
  130. }
  131. }).then(res => {
  132. if (res.result) {
  133. let userType = res.data;
  134. if ("0" == userType || "2" == userType) {
  135. // 显示工单维修菜单
  136. this.setData({
  137. showWorkOrder: true
  138. });
  139. }
  140. if("-1"!=userType){
  141. this.setData({
  142. showCeenter : true
  143. })
  144. }
  145. }
  146. });
  147. },
  148. onHide() {
  149. if (typeof this.getTabBar === 'function' &&
  150. this.getTabBar()) {
  151. this.getTabBar().setData({
  152. selected: -1
  153. })
  154. }
  155. },
  156. onLoad() {
  157. var windowWidth = wx.getSystemInfoSync().windowWidth;
  158. var windowHeight = wx.getSystemInfoSync().windowHeight;
  159. //rpx与px单位之间的换算 : 750/windowWidth = 屏幕的高度(rpx)/windowHeight
  160. var scroll_height = 750*windowHeight/windowWidth;
  161. this.setData({
  162. scroll_height:scroll_height
  163. })
  164. // let token = wx.getStorageSync('token');
  165. let token = cacheGet('token');
  166. if (token != null && token != '') {
  167. this.setData({
  168. nickName: wx.getStorageSync('nickName'),
  169. avatarUrl: wx.getStorageSync('imgUrl'),
  170. hasUserInfo: true
  171. })
  172. }
  173. // 获取用户角色
  174. // request({
  175. // url: '/mini/worker/getUserType',
  176. // method: 'GET',
  177. // data: {
  178. // userId: wx.getStorageSync('userid')
  179. // }
  180. // }).then(res => {
  181. // if (res.result) {
  182. // let userType = res.data;
  183. // if ("0" == userType || "2" == userType) {
  184. // // 显示工单维修菜单
  185. // this.setData({
  186. // showWorkOrder: true
  187. // });
  188. // }
  189. // if("-1"!=userType){
  190. // this.setData({
  191. // showCeenter : true
  192. // })
  193. // }
  194. // }
  195. // });
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload() {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh() {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom() {
  211. },
  212. /**
  213. * 用户点击右上角分享
  214. */
  215. onShareAppMessage() {
  216. return {
  217. title: '个人中心'
  218. }
  219. },
  220. toLike() {
  221. wx.navigateTo({
  222. url: '/pagesPublic/pages/like/like',
  223. })
  224. },
  225. navto() {
  226. wx.navigateTo({
  227. url: '/pagesPublic/pages/menu/menu',
  228. })
  229. },
  230. // toPersonalData() {
  231. // wx.navigateTo({
  232. // url: '/pagesPublic/pages/personalData/index/personalData',
  233. // })
  234. // },
  235. gotoMyCollection() {
  236. wx.navigateTo({
  237. url: '/pagesPublic/pages/myCollection/myCollection',
  238. })
  239. },
  240. toMyComment() {
  241. wx.navigateTo({
  242. url: '/pagesPublic/pages/myComment/myComment',
  243. })
  244. },
  245. tologin() {
  246. wx.navigateTo({
  247. url: '/pages/login/login',
  248. })
  249. },
  250. toNnzzd(){
  251. wx.navigateTo({
  252. url: '/pagesPublic/pages/nnzzd/nnzzd',
  253. })
  254. },
  255. tohdy(){
  256. wx.navigateTo({
  257. url: '/pages/doings/doings',
  258. })
  259. },
  260. getUserInfo() {
  261. // this.setData({
  262. // nickName: wx.getStorageSync('nickName'),
  263. // avatarUrl: wx.getStorageSync('imgUrl'),
  264. // hasUserInfo: true
  265. // })
  266. },
  267. // logout(){
  268. // this.setData({
  269. // hasUserInfo: false,
  270. // nickName:"",
  271. // avatarUrl:""
  272. // })
  273. // wx.removeStorage({
  274. // key: 'nickName',
  275. // })(option)
  276. // wx.removeStorage({
  277. // key: 'imgUrl',
  278. // })(option)
  279. // }
  280. towxkf(){
  281. },
  282. toznwd(){
  283. wx.navigateTo({
  284. url: '/pages/web/web?url=' + "https://www.cqna.gov.cn/ghwd/znwd/mobile/index.html",
  285. })
  286. },
  287. toshjf(){
  288. wx.navigateToMiniProgram({
  289. appId: 'wxd2ade0f25a874ee2',
  290. success(res) {
  291. // 打开成功
  292. }
  293. })
  294. },
  295. tosbfw(){
  296. wx.navigateToMiniProgram({
  297. appId: 'wx6163d215ef686f78',
  298. success(res) {
  299. // 打开成功
  300. }
  301. })
  302. },
  303. togjj(){
  304. wx.navigateToMiniProgram({
  305. appId: 'wx0bff7955e6e8b2bb',
  306. success(res) {
  307. // 打开成功
  308. }
  309. })
  310. },
  311. todzzz(){
  312. wx.navigateToMiniProgram({
  313. appId: 'wx635c548ecb74c1af',
  314. success(res) {
  315. // 打开成功
  316. }
  317. })
  318. },
  319. toswfw(){
  320. wx.navigateToMiniProgram({
  321. appId: 'wx2eec5fb00157a603',
  322. success(res) {
  323. // 打开成功
  324. }
  325. })
  326. },
  327. gotopjj(){
  328. wx.navigateToMiniProgram({
  329. appId: 'wx567d9a62933f5fde',
  330. success(res) {
  331. // 打开成功
  332. }
  333. })
  334. }
  335. })