index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. let _Http = getApp().globalData.http,
  2. DataCarousel = null;
  3. Page({
  4. data: {
  5. bannerList: [], //banner列表
  6. gridList: [],
  7. notice: "",
  8. msgCount: 1,
  9. msgList: [], //消息列表
  10. },
  11. onLoad(options) {
  12. this.setData({ //获取胶囊位置信息
  13. capsule: wx.getMenuButtonBoundingClientRect()
  14. })
  15. this.refreshData() //更新权限等信息
  16. },
  17. /* 更新站点信息 */
  18. refreshData() {
  19. this.setData({
  20. user: wx.getStorageSync('userMsg')
  21. })
  22. /* 首页宫格授权查询 */
  23. if (wx.getStorageSync('userauth').length != 0) {
  24. let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], []),
  25. gridList = [],
  26. authList = {};
  27. wx.setStorageSync('auth', authList)
  28. gridList.push({
  29. name: "商城",
  30. path: "/packageA/market/index",
  31. color: "#F29C37",
  32. bColor: "#FCF6EF",
  33. icon: "icon-shangcheng"
  34. })
  35. gridList.push({
  36. name: "销售订单",
  37. path: "/packageA/orderForm/index",
  38. color: "#5AB73F",
  39. bColor: "#F4FAEF",
  40. icon: "icon-dingdan"
  41. })
  42. gridList.push({
  43. name: "收货",
  44. path: "/packageA/shipment/index",
  45. color: "#3874F6",
  46. bColor: "#F0F3FF",
  47. icon: "icon-shouhuo"
  48. })
  49. gridList.push({
  50. name: "业绩目标",
  51. path: "/packageA/target/index",
  52. color: "#5AB73F",
  53. bColor: "#F4FAEF",
  54. icon: "icon-yejimubiao"
  55. })
  56. gridList.push({
  57. name: "账户",
  58. path: "/packageA/account/index",
  59. color: "#EB4B5C",
  60. bColor: "#FDF1ED",
  61. icon: "icon-zhanghu"
  62. })
  63. gridList.push({
  64. name: "促销活动",
  65. path: "/packageA/activity/index",
  66. color: "#3874F6",
  67. bColor: "#F0F3FF",
  68. icon: "icon-cuxiaohuodong"
  69. })
  70. gridList.push({
  71. name: "工具查询",
  72. path: "/packageA/tool/index",
  73. color: "#EB4B5C",
  74. bColor: "#FDF1ED",
  75. icon: "icon-kaipiao"
  76. })
  77. gridList.push({
  78. name: "购物车",
  79. path: "/packageA/shopping/index",
  80. color: "#EB4B5C",
  81. bColor: "#FDF1ED",
  82. icon: "icon-kaipiao"
  83. })
  84. gridList.push({
  85. name: "开票",
  86. path: "/packageA/invoice/index",
  87. color: "#EB4B5C",
  88. bColor: "#FDF1ED",
  89. icon: "icon-kaipiao"
  90. })
  91. /* ------------------------------- */
  92. gridList.push({
  93. name: "数据查询",
  94. path: "#",
  95. color: "#F29C37",
  96. bColor: "#FCF6EF",
  97. icon: "icon-shujuchaxun"
  98. })
  99. /* ------------------------------- */
  100. this.setData({
  101. gridList
  102. })
  103. } else {
  104. setTimeout(this.refreshData, 10);
  105. return;
  106. }
  107. /* 获取首页banner */
  108. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  109. if (banner) this.setData({
  110. bannerList: banner.ads
  111. })
  112. },
  113. /* 获取最新信息 */
  114. queryMessage(i = 0) {
  115. _Http.basic({
  116. "classname": "system.message.Message",
  117. "method": "queryMessage",
  118. content: {
  119. nocache: true,
  120. pageNumber: 1,
  121. pageSize: 5,
  122. pageTotal: 1,
  123. type: "",
  124. where: {}
  125. },
  126. }, false).then(res => {
  127. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  128. title: res.msg,
  129. icon: "none"
  130. })
  131. this.setData({
  132. msgList: res.data,
  133. notice: res.data[0]
  134. })
  135. if (this.data.msgList.length > 2) this.startDataCarousel();
  136. })
  137. },
  138. /* 开启消息轮播 */
  139. startDataCarousel() {
  140. clearInterval(DataCarousel);
  141. DataCarousel = setInterval(() => {
  142. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  143. this.setData({
  144. msgCount: count + 1,
  145. notice: this.data.msgList[count]
  146. })
  147. }, 5000)
  148. },
  149. /* 去消息详情 */
  150. toMsg(e) {
  151. const {
  152. item
  153. } = e.currentTarget.dataset;
  154. wx.navigateTo({
  155. url: '/pages/tabbar/message/details?id=' + item.messageid,
  156. })
  157. },
  158. /* banner */
  159. bannerClick(e) {
  160. const {
  161. item
  162. } = e.currentTarget.dataset,
  163. hyperlink = item.hyperlink.split(":");
  164. if (hyperlink[0] == 'path') wx.navigateTo({
  165. url: hyperlink[1]
  166. })
  167. },
  168. onShow() {
  169. this.getTabBar().init();
  170. if (this.data.msgList.length > 2) this.startDataCarousel();
  171. this.queryMessage(0); //更新最新消息
  172. },
  173. onHide() {
  174. clearInterval(DataCarousel);
  175. },
  176. onReady() {
  177. this.setListHeight();
  178. },
  179. /* 设置页面高度 */
  180. setListHeight() {
  181. this.selectComponent("#ListBox").setHeight(".grld-title", this);
  182. },
  183. onShareAppMessage() {}
  184. })