index.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. const _Http = getApp().globalData.http;
  2. let DataCarousel = null,
  3. funs = {};
  4. Page({
  5. data: {
  6. msgCount: 1,
  7. subassembly: [], //首页部件
  8. msgList: [], //消息列表
  9. capsule: wx.getMenuButtonBoundingClientRect(), //胶囊位置信息
  10. },
  11. onLoad(options) {
  12. this.refreshData() //更新权限等信息
  13. },
  14. /* 更新站点信息 */
  15. refreshData() {
  16. this.setData({
  17. user: wx.getStorageSync('userMsg')
  18. })
  19. if (wx.getStorageSync('userauth').length != 0) {
  20. let authList = {},
  21. gridList = [];
  22. const apps = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报', '销售线索', '营销物料']),
  23. paths = [{
  24. label: "通告",
  25. name: "wnotice",
  26. path: "/pages/annunciate/index",
  27. icon: "icon-a-shouyejingangqutonggao"
  28. }, {
  29. label: "商学院",
  30. name: "warchives_sc",
  31. path: "/pages/classroom/index",
  32. icon: "icon-a-shangxueyuanxuexi"
  33. }, {
  34. label: "营销物料",
  35. name: "warchives",
  36. path: "/pages/tabbar/smartStore/index",
  37. icon: "icon-a-shouyejingangquyingxiaowuliao"
  38. }, {
  39. label: "销售线索",
  40. name: "worderclue",
  41. path: "/pages/threadedTree/index",
  42. icon: "icon-xiaoshouxiansuo"
  43. }, {
  44. label: "推广素材",
  45. name: "wpopularize",
  46. path: "/pages/promotional/index",
  47. icon: "icon-a-shouyejingangqutuiguangsucai"
  48. }, {
  49. label: "提报",
  50. name: "wsubmitedit",
  51. path: "/pages/submission/index",
  52. icon: "icon-a-tibaoguanlitibao"
  53. }];
  54. apps.forEach(v => {
  55. v.apps.forEach(s => {
  56. authList[s.name] = {
  57. options: s.meta.auth.map(a => a.option),
  58. optionnames: s.meta.auth.map(a => a.optionname),
  59. }
  60. if (authList[s.name].options.some(s => s == "read")) {
  61. if (s.name == "worderclue") {
  62. //更新销售线索徽标数据
  63. funs.getCount = () => {
  64. const index = this.data.gridList.findIndex(v => v.label == '销售线索');
  65. if (index == -1) return;
  66. _Http.basic({
  67. "classname": "saletool.orderclue.web.orderclue",
  68. "method": "getCount",
  69. "content": {
  70. "nocache": true,
  71. "status": "待跟进"
  72. }
  73. }, false).then(res => {
  74. if (res.data.count == 0) res.data.count = '';
  75. if (res.data.count > 99) res.data.count = '99+';
  76. try {
  77. this.data.gridList[index].count = res.data.count;
  78. } catch (e) {}
  79. this.setData({
  80. gridList: this.data.gridList
  81. })
  82. })
  83. };
  84. } else if (s.name == "wnotice" && s.meta.wedgits.find(a => a.wedgit == 'homenoticelist')) {
  85. //更新通告数据
  86. funs.queryNoticeList = () => {
  87. _Http.basic({
  88. "classname": "saletool.notice.notice",
  89. "method": "queryNoticeList",
  90. "content": {
  91. "nocache": true,
  92. "pageNumber": 1,
  93. "pageSize": 3
  94. }
  95. }, false).then(res => {
  96. if (res.msg != '成功') return;
  97. this.setData({
  98. annunciateList: res.data,
  99. unreadNum: res.total - res.tips.readNum
  100. })
  101. });
  102. };
  103. }
  104. let data = paths.find(k => {
  105. return k.name == s.name
  106. });
  107. if (data) {
  108. data.isneedpay = s.isneedpay;
  109. gridList.push(data)
  110. }
  111. }
  112. })
  113. });
  114. this.setData({
  115. gridList
  116. });
  117. for (const key in funs) {
  118. funs[key]()
  119. };
  120. /* 获取首页banner */
  121. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  122. if (banner) this.setData({
  123. bannerList: banner.ads
  124. });
  125. wx.setStorageSync('authList', authList)
  126. } else {
  127. setTimeout(this.refreshData, 10);
  128. }
  129. },
  130. /* 宫格区域应用程序 */
  131. applications(e) {
  132. const {
  133. item
  134. } = e.currentTarget.dataset,
  135. userType = wx.getStorageSync('userMsg').usertype,
  136. isLeader = userType == 21 || userType == 22;
  137. console.log("跳转", item)
  138. //应用是否开通,开通直接跳转
  139. if (!item.isneedpay) {
  140. wx.showModal({
  141. title: '提示',
  142. content: `当前模块未付费,是否付费使用?`,
  143. confirmText: "前往付费",
  144. cancelText: isLeader ? "取消" : "提醒付费",
  145. complete: (res) => {
  146. if (res.confirm) {
  147. _Http.basic({
  148. "classname": "system.payorder.payorder",
  149. "method": "createOrder",
  150. "content": {},
  151. }).then(res => {
  152. console.log("新建订单", res)
  153. if (res.msg != '成功') return wx.showToast({
  154. title: res.msg,
  155. icon: "none",
  156. mask: true
  157. });
  158. wx.navigateTo({
  159. url: '/pages/teams/addOrder?sys_payorderid=' + res.data.sys_payorderid
  160. })
  161. })
  162. }
  163. if (res.cancel) {
  164. if (!isLeader) _Http.basic({
  165. "classname": "system.payorder.payorder",
  166. "method": "sendMessage",
  167. "content": {
  168. "sys_payorderid": ""
  169. }
  170. }).then(s => {
  171. wx.showToast({
  172. title: '已发送消息到主体主账号',
  173. icon: "none"
  174. })
  175. })
  176. }
  177. }
  178. })
  179. } else {
  180. if (item.label == "营销物料") {
  181. wx.switchTab({
  182. url: item.path
  183. });
  184. } else {
  185. wx.navigateTo({
  186. url: item.path
  187. });
  188. }
  189. }
  190. },
  191. /* 去消息详情 */
  192. toMsg(e) {
  193. const {
  194. item
  195. } = e.currentTarget.dataset;
  196. wx.navigateTo({
  197. url: '/pages/tabbar/message/details?id=' + item.messageid,
  198. })
  199. },
  200. /* 去通告 */
  201. toAnnunciate() {
  202. this.applications({
  203. currentTarget: {
  204. dataset: {
  205. item: this.data.gridList.find(v => v.name == '通告')
  206. }
  207. }
  208. })
  209. },
  210. /* banner */
  211. bannerClick(e) {
  212. const {
  213. item
  214. } = e.currentTarget.dataset,
  215. hyperlink = item.hyperlink.split(":");
  216. if (hyperlink[0] == 'path') wx.navigateTo({
  217. url: hyperlink[1]
  218. })
  219. },
  220. onShow() {
  221. this.getTabBar().init();
  222. for (const key in funs) {
  223. funs[key]()
  224. }
  225. /* 获取最新信息 */
  226. _Http.basic({
  227. "classname": "system.message.Message",
  228. "method": "queryMessage",
  229. content: {
  230. nocache: true,
  231. pageSize: 5,
  232. type: "",
  233. where: {}
  234. },
  235. }, false).then(res => {
  236. if (res.msg != '成功') return wx.showToast({
  237. title: res.msg,
  238. icon: "none"
  239. })
  240. this.setData({
  241. msgList: res.data,
  242. notice: res.data[0]
  243. })
  244. if (this.data.msgList.length > 2) {
  245. clearInterval(DataCarousel);
  246. DataCarousel = setInterval(() => {
  247. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  248. this.setData({
  249. msgCount: count + 1,
  250. notice: this.data.msgList[count]
  251. })
  252. }, 5000)
  253. }
  254. });
  255. },
  256. onHide() {
  257. clearInterval(DataCarousel);
  258. },
  259. })