纸通宝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.
 

145 lines
4.9 KiB

// pages/administ/index.js
import Scene from './scene'
import { getMessageList } from "../../api/saas"
import { headerFactoryId } from "../../api/user"
const event = require('../../utils/event')
const app = getApp()
import config from './config';
const items = [
{
text: config.pro1Name,
children: config.pro1,
},
{
text: config.pro2Name,
children: config.pro2,
},
{
text: config.pro3Name,
disabled: true,
children: config.pro3,
},
];
Scene({
/**
* 页面的初始数据
*/
data: {
safeBottom: app.globalData.safeBottom,
fragment: app.globalData.safeFragmentHeight,
userInfo: null,
tabList: [
{ index: 0, value: 'process', badge: 0, name: '采购', blue: '/assets/tabbar/process-blue.png', gray: '/assets/tabbar/process-gray.png' },
{ index: 1, value: 'storage', badge: 0, name: '库存', blue: '/assets/tabbar/storage-blue.png', gray: '/assets/tabbar/storage-gray.png' },
{ index: 2, value: 'agent', badge: 0, name: '代卖', blue: '/assets/tabbar/mall-blue.png', gray: '/assets/tabbar/mall-gray.png' },
{ index: 3, value: 'home', badge: 0, name: '我的', blue: '/assets/tabbar/home-blue.png', gray: '/assets/tabbar/home-gray.png' }
],
tabIndex: 0,
zIndex: 9,
setInter: null,
factoryId: '12313K78978KK',
factoryName: '',
factoryList: [
{id: '12313000KK12K', name: '济州岛打包站'},
{id: '12313K78978KK', name: '福州道打包站'},
{id: '1231345500KKK', name: '钟落潭打包站'},
{id: '12345678978KK', name: '鹤山常服打包站'},
{id: '123sdfsdf00KKK', name: '合剂打包站'},
{id: '1231332K78978K', name: '永宁街打包站'},
{id: '123242K78978KK', name: '河西路打包站'},
{id: '12313378978KK5', name: '成林道打包站'}
],
items,
mainActiveIndex: 0,
activeId: 0,
visible: false
},
/************************************** 初始化流程 ********************************************/
onLoad: function (options) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate()
updateManager.onUpdateReady(function () {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
})
this.setData({
userInfo: app.userInfo,
factoryName: app.userInfo.factoryName,
customBar: app.globalData.CustomBar || (app.globalData.isIos ? 64 : 60),
fragment: (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight),
safeBottom: app.globalData.safeBottom
})
event.on('EventMessage', this, this.onEvent)
this.data.setInter = setInterval(this.fetchMessage, 10000)
},
/************************************** 生命周期函数--监听页面初次渲染完成 ********************************************/
onShow: function () {
var pageView = this.selectComponent('#' + this.data.tabList[this.data.tabIndex].value)
if (pageView) {
pageView.onRestart()
}
},
onChange: function ({detail}) {
this.setData({ tabIndex: detail })
this.onShow()
},
stopTouchMove: function(e){
return false
},
onEvent: function (message) {
if (message.what == 888) {
this.onUnload()
}
},
fetchMessage: function(){
getMessageList({ productType: 'ZTB_FACTORY', status: 0 }).then(result => {
if(result.data && result.data.records && result.data.records.length){
let pages = getCurrentPages() //当前页面栈
let nowPage = pages[pages.length - 1] //当前页面
if(nowPage.onNotice){
nowPage.onNotice(result.data.records[0])
}
}
})
},
/************************************** changeFactory ********************************************/
onPopupChange: function({detail}){
this.setData({zIndex: detail})
},
showFactoryList: function(){
this.setData({ visible: !this.data.visible })
if (this.data.tabIndex == 0) {
var pageView = this.selectComponent('#' + this.data.tabList[this.data.tabIndex].value)
pageView.onClose()
}
},
changeFactory: function(e){
var item = this.data.factoryList[e.currentTarget.dataset.index]
wx.showLoading({ title: '正在切换', mask: true })
headerFactoryId(item.id)
var pageView = this.selectComponent('#' + this.data.tabList[this.data.tabIndex].value)
if (pageView && this.data.tabIndex != 3) {
pageView.fetchStatisticsInfo(true)
}
event.emit('EventMessage', { what: 999, desc: 'changeFactory' })
this.setData({ visible: false, factoryId: item.id, factoryName: item.name })
},
onHide: function(){
this.setData({ visible: false })
},
onClickNav({ detail }) {
this.setData({ mainActiveIndex: detail.index || 0 });
},
onClickItem({ detail }) {
this.setData({ activeId: detail.id });
},
onUnload: function(){
event.remove('EventMessage', this)
if(this.data.setInter) {
clearInterval(this.data.setInter)
this.data.setInter = null
}
}
})