// pages/stock/index.js import Dialog from '../../../components/dialog/dialog' import { finalizeToken } from "../../api/user" const util = require('../../../utils/util') const event = require('../../../utils/event.js') const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, /** * 页面的初始数据 */ data: { height: app.globalData.safeFragmentHeight, firstShow: false, userInfo: null, avatarUrl: '/assets/image/ygImg.png', creditInfo: { availableCreditLine: 0, creditLine: 0, usedCreditLine: 0.00 } }, lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached: function () { event.on('EventMessage', this, this.onEvent) }, detached: function () { event.remove('EventMessage', this) } }, methods: { // resume的处理; onRestart: function () { this.setUserInfo() this.fetchCreditInfo() this.data.firstShow = true }, onEvent: function (message) { if (message.what == 82) { // 认证成功 } else if (message.what == 888) { this.setData({creditInfo: { availableCreditLine: 0, creditLine: 0, usedCreditLine: 0.00 }}) } }, setUserInfo: function(){ if(!app.accountInfo){ return } var nickname = '' if(app.accountInfo.isAuth) { nickname = app.accountInfo.realName.substring(0, 14) } else if(!util.isEmpty(app.accountInfo.nickname)){ nickname = app.accountInfo.nickname.substring(0, 14) } else if(!util.isEmpty(app.accountInfo.realName)){ nickname = app.accountInfo.realName.substring(0, 14) } this.setData({ avatarUrl: util.isEmpty(app.accountInfo.avatarUrl) ? '/assets/image/ygImg.png' : app.accountInfo.avatarUrl, userInfo: app.accountInfo, userName: nickname, height: app.globalData.safeFragmentHeight }) }, toUserInfo: function(){ if(!app.accountInfo){ return } if(!app.accountInfo.isAuth){ wx.navigateTo({ url: '/pages/home/authory/index' }) } }, fetchCreditInfo: function(){ if(!app.accountInfo || util.isEmpty(app.accountInfo.enterpriseId)){ return } getCreditInfo({enterpriseId: app.accountInfo.enterpriseId}).then(result => { this.setData({ creditInfo: result.data }) }).catch(error => { }) }, orderList: function(){ wx.navigateTo({ url: '/pages/mall/order-list/index' }) }, tipApply: function(){ wx.navigateTo({ url: '/pages/htmls/credit/index' }) }, loginOut: function () { Dialog.confirm({ title: '温馨提示', message: '确定退出云印通账号?' }).then(() => { wx.removeStorageSync('Authorization') app.globalData.token = null app.accountInfo = null this.setData({ userInfo: null, avatarUrl: '/assets/image/ygImg.png', creditInfo: { availableCreditLine: 0, creditLine: 0, usedCreditLine: 0.00 }}) finalizeToken() event.emit('EventMessage', { what: 888, desc: 'Logout' }) }) } } })