| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- const _Http = getApp().globalData.http;
- let DataCarousel = null;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- site: getApp().globalData.site,
- bannerList: [], //banner列表
- user: {},
- annunciateList: [], //通告列表
- gridList: [],
- unreadNum: 0, //通告未读
- notice: "",
- msgCount: 1,
- subassembly: [], //首页部件
- msgList: [], //消息列表
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.refreshData() //更新权限等信息
- this.setData({ //获取胶囊位置信息
- capsule: wx.getMenuButtonBoundingClientRect()
- })
- },
- /* 更新站点信息 */
- refreshData() {
- this.setData({
- user: wx.getStorageSync('userMsg')
- })
- /* 首页宫格授权查询 */
- if (wx.getStorageSync('userauth').length != 0) {
- let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报', '销售线索', '营销物料', '销售目标', '客户管理', '项目管理', '销售预测']),
- gridList = [],
- subassembly = [];
- console.log(auth)
- auth.forEach(v => {
- switch (v.systemmodulename) {
- case "通告":
- gridList.push({
- name: "通告",
- path: "/pages/annunciate/index",
- icon: "icon-a-shouyejingangqutonggao",
- apps: v.apps
- });
- if (v.apps[0].meta.wedgits.some(value => value.wedgit == 'homenoticelist')) subassembly.push('homenoticelist');
- this.setData({
- annunciateAuthList: v.apps[0].meta.auth.map(v => v.optionname)
- });
- break;
- case "推广素材":
- gridList.push({
- name: "推广素材",
- path: "/pages/promotional/index",
- icon: "icon-a-shouyejingangqutuiguangsucai",
- apps: v.apps
- })
- break;
- case "商学院":
- gridList.push({
- name: "商学院",
- path: "/pages/college/index",
- icon: "icon-a-shangxueyuanxuexi",
- apps: v.apps
- })
- break;
- case "提报":
- gridList.push({
- name: "提报",
- path: "/pages/submission/index",
- icon: "icon-a-tibaoguanlitibao",
- apps: v.apps
- })
- break;
- case "营销物料":
- gridList.push({
- name: "营销物料",
- path: "/pages/tabbar/smartStore/index",
- icon: "icon-a-shouyejingangquyingxiaowuliao",
- apps: v.apps
- })
- break;
- case "销售目标":
- gridList.push({
- name: "销售目标",
- path: "/packageA/target/index",
- icon: "icon-xiaochengxu_xiaoshoumubiao",
- apps: v.apps
- })
- break;
- case "公海线索":
- gridList.push({
- name: "公海线索",
- path: "/packageA/publicClue/index",
- icon: "icon-xiaochengxu_xiaoshoumubiao",
- apps: v.apps
- })
- break;
- /* 二期应用分界线 */
- case "客户管理":
- v.apps.forEach(value => {
- switch (value.name) {
- //客户
- case "wCustomer":
- if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
- name: "客户",
- path: "/packageA/setclient/index",
- icon: "icon-kehu",
- apps: {}
- })
- getApp().globalData.auth.wCustomer = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- //公海客户
- case "wPublicCustomer":
- if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
- name: "公海客户",
- path: "/packageA/publicCustomer/index",
- icon: "icon-xiaochengxutongxunlu",
- apps: {}
- })
- getApp().globalData.auth.wPublicCustomer = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- }
- })
- break;
- case "项目管理":
- v.apps.forEach(value => {
- switch (value.name) {
- //项目商机
- case "wproject":
- if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
- name: "项目商机",
- path: "/packageA/project/index",
- icon: "icon-xiangmushangji",
- apps: {}
- })
- getApp().globalData.auth.wproject = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- //竞争对手
- case "wcompetitor":
- if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
- name: "竞争对手",
- path: "/packageA/opponent/index",
- icon: "icon-xiaochengxutongxunlu",
- apps: {}
- })
- getApp().globalData.auth.wcompetitor = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- //报价单
- case "woffer":
- if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
- name: "报价单",
- path: "/packageA/offers/index",
- icon: "icon-xiangmubaojia",
- apps: {}
- })
- getApp().globalData.auth.woffer = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- //合同
- case "wcontract":
- if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
- name: "合同",
- path: "/packageA/contract/index",
- icon: "icon-hetong",
- apps: {}
- })
- getApp().globalData.auth.wcontract = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- };
- });
- break;
- case "销售线索":
- v.apps.forEach(value => {
- switch (value.name) {
- //销售线索
- case "worderclue":
- if (value.meta.auth.some(r => r.option == 'read')) {
- gridList.push({
- name: "销售线索",
- path: "/packageA/saleClue/index",
- icon: "icon-xiaoshouxiansuo",
- apps: {}
- })
- setTimeout(this.getCount, 100);
- }
- getApp().globalData.auth.worderclue = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- //公海线索
- case "worderclue_public":
- if (value.meta.auth.some(r => r.option == 'read')) {
- gridList.push({
- name: "公海线索",
- path: "/packageA/publicClue/index",
- icon: "icon-xiaochengxu_xiaoshoumubiao",
- apps: {}
- })
- }
- getApp().globalData.auth.worderclue_public = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- //市场活动
- case "wmarketing_activity":
- if (value.meta.auth.some(r => r.option == 'read')) {
- gridList.push({
- name: "市场活动",
- path: "/packageA/activity/index",
- icon: "icon-xiaochengxutongxunlu",
- apps: {}
- })
- }
- getApp().globalData.auth.wmarketing_activity = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- };
- });
- break;
- case "销售预测":
- v.apps.forEach(value => {
- switch (value.name) {
- //销售线索
- case "forecast":
- if (value.meta.auth.some(r => r.option == 'read')) {
- gridList.push({
- name: "销售预测",
- path: "/packageA/salesForecasting/index",
- icon: "icon-xiaochengxu_xiaoshouyuce",
- apps: {}
- })
- }
- getApp().globalData.auth.forecast = {
- options: value.meta.auth.map(a => a.option),
- optionnames: value.meta.auth.map(a => a.optionname),
- }
- break;
- };
- });
- break;
- default:
- console.log(v);
- break;
- };
- });
- if (!['美大'].includes(this.data.site)) {
- gridList.push({
- name: "联系人",
- path: "/packageA/contacts/index",
- icon: "icon-xiaochengxutongxunlu",
- apps: {}
- })
- /* gridList.push({
- name: "任务",
- path: "/packageA/work/index",
- icon: "icon-xiaochengxu_xiaoshouyuce",
- apps: {}
- }) */
- }
- /* 首页小组件查询 */
- try {
- let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
- if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
- } catch (e) {
- this.setData({
- gridList,
- subassembly: []
- })
- }
- this.setData({
- gridList,
- subassembly
- })
- } else {
- setTimeout(this.refreshData, 10);
- return;
- }
- /* 获取首页banner */
- let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
- if (banner) this.setData({
- bannerList: banner.ads
- })
- this.queryNoticeList(0); //获取通告列表
- },
- /* 销售线索待办 */
- getCount() {
- const index = this.data.gridList.findIndex(v => v.name == '销售线索');
- 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
- })
- })
- },
- /* 查看通告详情 */
- toAnnunciateDetails(e) {
- const {
- item
- } = e.currentTarget.dataset;
- let authList = this.data.annunciateAuthList;
- wx.navigateTo({
- url: `/pages/annunciate/details?id=${item.sat_noticeid}&auth=${authList}`,
- })
- },
- /* 获取通告列表 */
- queryNoticeList(i) {
- if (i == 5) return;
- let obj = this.data.gridList.find(v => v.name == '通告');
- if (!obj || obj.apps.length == 0) return;
- _Http.basic({
- id: 20221111090904,
- "content": {
- "nocache": true,
- "pageNumber": 1,
- "pageSize": 3
- }
- }, false).then(res => {
- if (res.msg != '成功') return this.queryNoticeList(i + 1);
- this.setData({
- annunciateList: res.data,
- unreadNum: res.total - res.tips.readNum
- })
- });
- },
- /* 获取最新信息 */
- queryMessage(i = 0) {
- _Http.basic({
- "classname": "system.message.Message",
- "method": "queryMessage",
- content: {
- nocache: true,
- pageNumber: 1,
- pageSize: 5,
- pageTotal: 1,
- type: "",
- where: {}
- },
- }, false).then(res => {
- if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
- title: res.msg,
- icon: "none"
- })
- this.setData({
- msgList: res.data,
- notice: res.data[0]
- })
- if (this.data.msgList.length > 2) this.startDataCarousel();
- })
- },
- /* 开启消息轮播 */
- startDataCarousel() {
- 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)
- },
- /* 宫格区域应用程序 */
- applications(e) {
- const {
- item
- } = e.currentTarget.dataset;
- const url = `${item.path}?auth=${JSON.stringify(item.apps)}`
- if (item.name == "营销物料") {
- wx.switchTab({
- url
- });
- } else {
- wx.navigateTo({
- url
- });
- }
- },
- /* 去消息详情 */
- 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.name == '通告')
- }
- }
- })
- },
- /* 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();
- if (this.data.msgList.length > 2) this.startDataCarousel();
- this.getCount(); //更新徽标数据
- this.queryMessage(0); //更新最新消息
- this.queryNoticeList(0); //获取通告列表
- },
- onHide() {
- clearInterval(DataCarousel);
- },
- onShareAppMessage() {}
- })
|