纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

99 lines
3.0 KiB

// pages/index/index.js
import { getUserInfo } from "../../api/user"
const event = require('../../../utils/event')
const app = getApp()
Component({
options: {
addGlobalClass: true,
multipleSlots: true
},
/**
* 页面的初始数据
*/
data: {
userInfo: app.accountInfo,
height: app.globalData.fragmentHeight - 100,
tabIndex: 0,
tabList: [
{id: 0, name: '供货单', badge: 0, value: 'supply' },
{id: 1, name: '采购单', badge: 0, value: 'purchase'},
{id: 2, name: '生产单', badge: 0, value: 'production' }
],
loading: true
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () {
event.on('EventMessage', this, this.onEvent)
},
detached: function () {
event.remove('EventMessage', this)
}
},
methods: {
onRestart: function () {
if(this.data.loading){
this.initAccountInfo()
}
var fragment = this.selectComponent('#' + this.data.tabList[this.data.tabIndex].value)
if (fragment) {
fragment.onRestart()
}
},
onEvent: function (message) {
if (message.what == 888) {
this.initAccountInfo()
}
},
initAccountInfo: function(){
if(app.accountInfo && app.accountInfo.position == 'ORDINARY'){
this.setData({
loading: false,
userInfo: app.accountInfo, height: app.globalData.safeFragmentHeight - 100,
tabList: [
{id: 0, name: '生产中', badge: 0, value: 'supply', status: 0 },
{id: 1, name: '待生产', badge: 0, value: 'purchase', status: 1 },
{id: 2, name: '已完成', badge: 0, value: 'production', status: 3 },
{id: 3, name: '已终止', badge: 0, value: 'termination', status: 6 }
]
})
} else {
this.setData({ loading: false, userInfo: app.accountInfo, height: app.globalData.safeFragmentHeight - 100 })
}
// 您的申请正在处理,请等待,轮询去查询userInfo
if(app.accountInfo && app.accountInfo.applicationStatus == 0){
this.fetchUserInfo()
}
},
onTabChange: function (event) {
if (this.data.tabIndex == Number(event.detail.index)) {
return
}
this.setData({ tabIndex: event.detail.index})
var fragment = this.selectComponent('#' + this.data.tabList[this.data.tabIndex].value)
if (fragment) {
fragment.onRestart()
}
},
fetchUserInfo: function(){
getUserInfo().then(result => {
app.accountInfo = result.data
if(result.data.enterpriseId && result.data.applicationStatus == 1){
this.initAccountInfo()
} else {
var that = this
setTimeout(function () { that.fetchUserInfo() }, 3000)
}
}).catch(err => {
console.log(err)
})
},
loginFrom: function(){
wx.navigateTo({ url: '/pages/index/index' })
},
applyFrom: function(){
wx.navigateTo({ url: '/pages/htmls/saas/index' })
}
}
})