index.js 11 KB

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