index.js 7.6 KB

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