const _Http = getApp().globalData.http; import { vIndate } from "../../../utils/pay" let DataCarousel = null, funs = {}; Page({ data: { msgCount: 1, subassembly: [], //首页部件 msgList: [], //消息列表 capsule: wx.getMenuButtonBoundingClientRect(), //胶囊位置信息 }, onLoad(options) { this.refreshData() //更新权限等信息 getApp().globalData.http.refreshData = this.refreshData.bind(this); vIndate(); }, /* 更新站点信息 */ refreshData() { this.setData({ user: wx.getStorageSync('userMsg') }) if (wx.getStorageSync('userauth').length != 0) { let authList = {}, gridList = []; const apps = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报', '销售线索', '营销物料']), paths = [{ label: "通告", name: "wnotice", path: "/pages/annunciate/index", icon: "icon-a-shouyejingangqutonggao" }, { label: "商学院", name: "warchives_sc", path: "/pages/classroom/index", icon: "icon-a-shangxueyuanxuexi" }, { label: "营销物料", name: "warchives", path: "/pages/tabbar/smartStore/index", icon: "icon-a-shouyejingangquyingxiaowuliao" }, { label: "销售线索", name: "worderclue", path: "/pages/threadedTree/index", icon: "icon-xiaoshouxiansuo" }, { label: "推广素材", name: "wpopularize", path: "/pages/promotional/index", icon: "icon-a-shouyejingangqutuiguangsucai" }, { label: "提报", name: "wsubmitedit", path: "/pages/submission/index", icon: "icon-a-tibaoguanlitibao" }]; apps.forEach(v => { v.apps.forEach(s => { authList[s.name] = { options: s.meta.auth.map(a => a.option), optionnames: s.meta.auth.map(a => a.optionname), } if (authList[s.name].options.some(s => s == "read")) { if (s.name == "worderclue") { //更新销售线索徽标数据 funs.getCount = () => { const index = this.data.gridList.findIndex(v => v.label == '销售线索'); if (index == -1) return; _Http.basic({ "classname": "saletool.orderclue.web.orderclue", "method": "getCount", "content": { "nocache": true, "status": "待跟进" } }, false).then(res => { if (res.data.count == 0) res.data.count = ''; if (res.data.count > 99) res.data.count = '99+'; try { this.data.gridList[index].count = res.data.count; } catch (e) {} this.setData({ gridList: this.data.gridList }) }) }; } else if (s.name == "wnotice" && s.meta.wedgits.find(a => a.wedgit == 'homenoticelist')) { //更新通告数据 funs.queryNoticeList = () => { _Http.basic({ "classname": "saletool.notice.notice", "method": "queryNoticeList", "content": { "nocache": true, "pageNumber": 1, "pageSize": 3 } }, false).then(res => { if (res.msg != '成功') return; this.setData({ annunciateList: res.data, unreadNum: res.total - res.tips.readNum }) }); }; } let data = paths.find(k => { return k.name == s.name }); if (data) { data.isneedpay = s.isneedpay; gridList.push(data) } } }) }); this.setData({ gridList }); for (const key in funs) { funs[key]() }; /* 获取首页banner */ let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top"); if (banner) this.setData({ bannerList: banner.ads }); wx.setStorageSync('authList', authList) wx.setStorageSync('gridList', gridList) } else { setTimeout(this.refreshData, 10); } }, /* 宫格区域应用程序 */ applications(e) { getApp().globalData.evidence(e.currentTarget.dataset.item) }, /* 去消息详情 */ toMsg(e) { const { item } = e.currentTarget.dataset; wx.navigateTo({ url: '/pages/tabbar/message/details?id=' + item.messageid, }) }, /* 去通告 */ toAnnunciate() { this.applications({ currentTarget: { dataset: { item: this.data.gridList.find(v => v.label == '通告') } } }) }, /* banner */ bannerClick(e) { const { item } = e.currentTarget.dataset, hyperlink = item.hyperlink.split(":"); if (hyperlink[0] == 'path') wx.navigateTo({ url: hyperlink[1] }) }, onShow() { this.getTabBar().init(); for (const key in funs) { funs[key]() } /* 获取最新信息 */ _Http.basic({ "classname": "system.message.Message", "method": "queryMessage", content: { nocache: true, pageSize: 5, type: "", where: {} }, }, false).then(res => { if (res.msg != '成功') return wx.showToast({ title: res.msg, icon: "none" }) this.setData({ msgList: res.data, notice: res.data[0] }) if (this.data.msgList.length > 2) { clearInterval(DataCarousel); DataCarousel = setInterval(() => { let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0; this.setData({ msgCount: count + 1, notice: this.data.msgList[count] }) }, 5000) } }); }, onHide() { clearInterval(DataCarousel); }, })