index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. gridList.push({
  92. name: "打款凭证",
  93. path: "/packageA/remitVoucher/index",
  94. color: "#F29C37",
  95. bColor: "#FCF6EF",
  96. icon: "icon-shujuchaxun"
  97. })
  98. gridList.push({
  99. name: "工具借用",
  100. path: "/packageA/borrow/index",
  101. color: "#F29C37",
  102. bColor: "#FCF6EF",
  103. icon: "icon-shujuchaxun"
  104. })
  105. /* ------------------------------- */
  106. gridList.push({
  107. name: "数据查询",
  108. path: "#",
  109. color: "#F29C37",
  110. bColor: "#FCF6EF",
  111. icon: "icon-shujuchaxun"
  112. })
  113. this.setData({
  114. gridList
  115. })
  116. } else {
  117. setTimeout(this.refreshData, 10);
  118. return;
  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. },
  126. /* 获取最新信息 */
  127. queryMessage(i = 0) {
  128. _Http.basic({
  129. "classname": "system.message.Message",
  130. "method": "queryMessage",
  131. content: {
  132. nocache: true,
  133. pageNumber: 1,
  134. pageSize: 5,
  135. pageTotal: 1,
  136. type: "",
  137. where: {}
  138. },
  139. }, false).then(res => {
  140. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  141. title: res.msg,
  142. icon: "none"
  143. })
  144. this.setData({
  145. msgList: res.data,
  146. notice: res.data[0]
  147. })
  148. if (this.data.msgList.length > 2) this.startDataCarousel();
  149. })
  150. },
  151. /* 开启消息轮播 */
  152. startDataCarousel() {
  153. clearInterval(DataCarousel);
  154. DataCarousel = setInterval(() => {
  155. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  156. this.setData({
  157. msgCount: count + 1,
  158. notice: this.data.msgList[count]
  159. })
  160. }, 5000)
  161. },
  162. /* 去消息详情 */
  163. toMsg(e) {
  164. const {
  165. item
  166. } = e.currentTarget.dataset;
  167. wx.navigateTo({
  168. url: '/pages/tabbar/message/details?id=' + item.messageid,
  169. })
  170. },
  171. /* banner */
  172. bannerClick(e) {
  173. const {
  174. item
  175. } = e.currentTarget.dataset,
  176. hyperlink = item.hyperlink.split(":");
  177. if (hyperlink[0] == 'path') wx.navigateTo({
  178. url: hyperlink[1]
  179. })
  180. },
  181. onShow() {
  182. this.getTabBar().init();
  183. if (this.data.msgList.length > 2) this.startDataCarousel();
  184. this.queryMessage(0); //更新最新消息
  185. },
  186. onHide() {
  187. clearInterval(DataCarousel);
  188. },
  189. onReady() {
  190. this.setListHeight();
  191. },
  192. /* 设置页面高度 */
  193. setListHeight() {
  194. this.selectComponent("#ListBox").setHeight(".grld-title", this);
  195. },
  196. onShareAppMessage() {}
  197. })