index.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. let _Http = getApp().globalData.http,
  2. DataCarousel = null;
  3. Page({
  4. data: {
  5. appid: "wxc1b6ae925ac1d06a",
  6. bannerList: [], //banner列表
  7. gridList: [],
  8. notice: "",
  9. msgCount: 1,
  10. msgList: [], //消息列表
  11. },
  12. onLoad(options) {
  13. this.setData({ //获取胶囊位置信息
  14. capsule: wx.getMenuButtonBoundingClientRect()
  15. })
  16. this.refreshData() //更新权限等信息
  17. this.getTabBar().unReadMessageCount(); //更新信息数量
  18. },
  19. /* 更新站点信息 */
  20. refreshData() {
  21. this.setData({
  22. user: wx.getStorageSync('userMsg')
  23. })
  24. if (wx.getStorageSync('userauth').length != 0) {
  25. let authList = {},
  26. entrance = [{
  27. label: "E-订单",
  28. appid: "wxc1b6ae925ac1d06a",
  29. icon: "work-E-dingdan",
  30. list: getedd()
  31. }];
  32. //E订单
  33. function getedd() {
  34. let paths = [{
  35. name: "商城",
  36. path: "/packageA/market/index",
  37. icon: "work-shangcheng"
  38. }, {
  39. name: "销售订单",
  40. path: "/packageA/orderForm/index",
  41. icon: "work-dingdan"
  42. }, {
  43. name: "账户",
  44. path: "/packageA/account/index",
  45. icon: "work-zhanghu"
  46. }, {
  47. name: "促销活动",
  48. path: "/packageA/activity/index",
  49. icon: "work-cuxiaohuodong"
  50. }, {
  51. name: "购物车",
  52. path: "/packageA/shopping/index",
  53. icon: "work-gouwuche"
  54. }, {
  55. name: "打款凭证",
  56. path: "/packageA/remitVoucher/index",
  57. icon: "work-dakuanpingzheng"
  58. },{
  59. name: "退返申请",
  60. path: "/packageA/returnOne/index",
  61. icon: "work-shujuchaxun"
  62. },{
  63. name: "发货单",
  64. path: "/packageA/dispatchBill/index",
  65. icon: "icon-shouhuo"
  66. }];
  67. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货与库存", "业绩查询"]),
  68. list = [];
  69. edd.forEach(v => {
  70. v.apps.forEach(s => {
  71. authList[s.name] = {
  72. options: s.meta.auth.map(a => a.option),
  73. optionnames: s.meta.auth.map(a => a.optionname),
  74. }
  75. if (authList[s.name].options.some(s => s == "read")) {
  76. let i = paths.findIndex(k => k.name == s.meta.title);
  77. if (i != -1) {
  78. paths[i].index = i;
  79. list.push(paths[i])
  80. }
  81. }
  82. })
  83. });
  84. return dye(list.sort((a, b) => a.index - b.index))
  85. };
  86. //染色
  87. function dye(list) {
  88. let colorList = [{
  89. color: "#3874F6",
  90. bColor: "#F0F3FF",
  91. }, {
  92. color: "#5AB73F",
  93. bColor: "#F4FAEF",
  94. }, {
  95. color: "#F29C37",
  96. bColor: "#FCF6EF",
  97. }, {
  98. color: "#EB4B5C",
  99. bColor: "#FDF1ED",
  100. }, {
  101. color: "#3874F6",
  102. bColor: "#F0F3FF",
  103. }, {
  104. color: "#F29C37",
  105. bColor: "#FCF6EF",
  106. }, {
  107. color: "#EB4B5C",
  108. bColor: "#FDF1ED",
  109. }, {
  110. color: "#3874F6",
  111. bColor: "#F0F3FF",
  112. }, {
  113. color: "#5AB73F",
  114. bColor: "#F4FAEF",
  115. }, {
  116. color: "#F29C37",
  117. bColor: "#FCF6EF",
  118. }, {
  119. color: "#5AB73F",
  120. bColor: "#F4FAEF",
  121. }, {
  122. color: "#3874F6",
  123. bColor: "#F0F3FF",
  124. }, {
  125. color: "#F29C37",
  126. bColor: "#FCF6EF",
  127. }, {
  128. color: "#EB4B5C",
  129. bColor: "#FDF1ED",
  130. }, {
  131. color: "#5AB73F",
  132. bColor: "#F4FAEF",
  133. }];
  134. return list.map((v, i) => {
  135. return {
  136. ...v,
  137. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  138. }
  139. })
  140. };
  141. wx.setStorageSync('auth', authList)
  142. this.setData({
  143. entrance,
  144. auth: JSON.stringify(authList),
  145. userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
  146. site: JSON.stringify(wx.getStorageSync('siteP'))
  147. })
  148. /* 获取首页banner */
  149. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  150. if (banner) this.setData({
  151. bannerList: banner.ads
  152. })
  153. } else {
  154. setTimeout(this.refreshData, 10);
  155. return;
  156. }
  157. },
  158. /* 获取最新信息 */
  159. queryMessage(i = 0) {
  160. _Http.basic({
  161. "classname": "system.message.Message",
  162. "method": "queryMessage",
  163. content: {
  164. nocache: true,
  165. pageNumber: 1,
  166. pageSize: 5,
  167. pageTotal: 1,
  168. type: "",
  169. where: {}
  170. },
  171. }, false).then(res => {
  172. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  173. title: res.msg,
  174. icon: "none"
  175. })
  176. this.setData({
  177. msgList: res.data,
  178. notice: res.data[0]
  179. })
  180. if (this.data.msgList.length > 2) this.startDataCarousel();
  181. })
  182. },
  183. /* 开启消息轮播 */
  184. startDataCarousel() {
  185. clearInterval(DataCarousel);
  186. DataCarousel = setInterval(() => {
  187. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  188. this.setData({
  189. msgCount: count + 1,
  190. notice: this.data.msgList[count]
  191. })
  192. }, 5000)
  193. },
  194. /* 去消息详情 */
  195. toMsg(e) {
  196. const {
  197. item
  198. } = e.currentTarget.dataset;
  199. wx.navigateTo({
  200. url: '/pages/tabbar/message/details?id=' + item.messageid,
  201. })
  202. },
  203. /* banner */
  204. bannerClick(e) {
  205. const {
  206. item
  207. } = e.currentTarget.dataset,
  208. hyperlink = item.hyperlink.split(":");
  209. if (hyperlink[0] == 'path') wx.navigateTo({
  210. url: hyperlink[1]
  211. })
  212. },
  213. onShow() {
  214. this.getTabBar().init();
  215. if (this.data.msgList.length > 2) this.startDataCarousel();
  216. this.queryMessage(0); //更新最新消息
  217. },
  218. onHide() {
  219. clearInterval(DataCarousel);
  220. },
  221. onReady() {
  222. // this.setListHeight();
  223. },
  224. /* 设置页面高度 */
  225. setListHeight() {
  226. this.selectComponent("#ListBox").setHeight(".grld-title", this);
  227. },
  228. onShareAppMessage() {}
  229. })