123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- // pages/nais/nais.js
- import {
- imgUrl
- } from "../api/request"
- import {
- cacheGet
- } from "../../utils/cacheUtil"
- import {
- baseUrl,
- request
- } from "../../pages/api/canteen-request.js"
- let app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- canIUseGetUserProfile: true,
- nickName: "",
- avatarUrl: "",
- hasUserInfo: false,
- imgUrl: imgUrl,
- show: false,
- showWorkOrder: false,
- showCeenter:false,
- scroll_height:""
- },
- // 自定义函数
- toCanteen: function (e) {
- wx.navigateTo({
- url: '/pages/ourCanteen/ourCanteen'
- })
- },
- toWorkOrder: function (e) {
- wx.navigateTo({
- url: '/pagesPublic/pages/work-order/work-order'
- });
- },
- handleAction() {
- var that = this
- wx.showActionSheet({
- itemList: ['退出登录'],
- success(res) {
- // console.log(res.tapIndex)
- wx.clearStorageSync();
- that.setData({
- show: false,
- canIUseGetUserProfile: true,
- hasUserInfo: false
- })
- },
- fail(res) {
- // console.log(res.errMsg)
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: 4
- })
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- /*wx.showModal({
- title: '提示',
- content: '提示用户订阅消息',
- success (res) {
- if (res.confirm) {
- console.log('用户点击确定')
- wx.requestSubscribeMessage({
- tmplIds: ['aGohosyMWmBOdzkjlD34qMRIsAPb2cVY6juinVIevgg'],
- success (res) {
- }
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })*/
- // let token = wx.getStorageSync('token');
- let token = cacheGet('token');
- if (token != null && token != '') {
- this.setData({
- canIUseGetUserProfile: false,
- nickName: wx.getStorageSync('nickName'),
- avatarUrl: wx.getStorageSync('imgUrl'),
- hasUserInfo: true
- })
- } else {
- this.setData({
- hasUserInfo: false,
- canIUseGetUserProfile: true
- })
- }
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: 4
- })
- }
- // 获取用户角色
- request({
- url: '/mini/worker/getUserType',
- method: 'GET',
- data: {
- userId: wx.getStorageSync('userid')
- }
- }).then(res => {
- if (res.result) {
- let userType = res.data;
- if ("0" == userType || "2" == userType) {
- // 显示工单维修菜单
- this.setData({
- showWorkOrder: true
- });
- }
- if("-1"!=userType){
- this.setData({
- showCeenter : true
- })
- }
- }
- });
- },
- onHide() {
- if (typeof this.getTabBar === 'function' &&
- this.getTabBar()) {
- this.getTabBar().setData({
- selected: -1
- })
- }
- },
- onLoad() {
- var windowWidth = wx.getSystemInfoSync().windowWidth;
- var windowHeight = wx.getSystemInfoSync().windowHeight;
- //rpx与px单位之间的换算 : 750/windowWidth = 屏幕的高度(rpx)/windowHeight
- var scroll_height = 750*windowHeight/windowWidth;
- this.setData({
- scroll_height:scroll_height
- })
- // let token = wx.getStorageSync('token');
- let token = cacheGet('token');
- if (token != null && token != '') {
- this.setData({
- nickName: wx.getStorageSync('nickName'),
- avatarUrl: wx.getStorageSync('imgUrl'),
- hasUserInfo: true
- })
- }
- // 获取用户角色
- request({
- url: '/mini/worker/getUserType',
- method: 'GET',
- data: {
- userId: wx.getStorageSync('userid')
- }
- }).then(res => {
- if (res.result) {
- let userType = res.data;
- if ("0" == userType || "2" == userType) {
- // 显示工单维修菜单
- this.setData({
- showWorkOrder: true
- });
- }
- if("-1"!=userType){
- this.setData({
- showCeenter : true
- })
- }
- }
- });
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- return {
- title: '个人中心'
- }
- },
- toLike() {
- wx.navigateTo({
- url: '/pagesPublic/pages/like/like',
- })
- },
- navto() {
- wx.navigateTo({
- url: '/pagesPublic/pages/menu/menu',
- })
- },
- // toPersonalData() {
- // wx.navigateTo({
- // url: '/pagesPublic/pages/personalData/index/personalData',
- // })
- // },
- gotoMyCollection() {
- wx.navigateTo({
- url: '/pagesPublic/pages/myCollection/myCollection',
- })
- },
- toMyComment() {
- wx.navigateTo({
- url: '/pagesPublic/pages/myComment/myComment',
- })
- },
- tologin() {
- wx.navigateTo({
- url: '/pages/login/login',
- })
- },
- getUserInfo() {
- // this.setData({
- // nickName: wx.getStorageSync('nickName'),
- // avatarUrl: wx.getStorageSync('imgUrl'),
- // hasUserInfo: true
- // })
- },
- // logout(){
- // this.setData({
- // hasUserInfo: false,
- // nickName:"",
- // avatarUrl:""
- // })
- // wx.removeStorage({
- // key: 'nickName',
- // })(option)
- // wx.removeStorage({
- // key: 'imgUrl',
- // })(option)
- // }
- })
|