index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //index.js
  2. //获取应用实例
  3. var http = require("../../utils/http.js");
  4. var config = require("../../utils/config.js");
  5. const app = getApp()
  6. Page({
  7. data: {
  8. indicatorDots: true,
  9. indicatorColor: '#d1e5fb',
  10. indicatorActiveColor: '#1b7dec',
  11. autoplay: true,
  12. interval: 2000,
  13. duration: 1000,
  14. indexImgs: [],
  15. seq: 0,
  16. news: [],
  17. taglist: [],
  18. sts: 0,
  19. },
  20. //事件处理函数
  21. bindViewTap: function() {
  22. wx.navigateTo({
  23. url: '../logs/logs'
  24. })
  25. },
  26. onLoad: function() {
  27. this.getAllData();
  28. },
  29. // 页面滚动到指定位置指定元素固定在顶部
  30. onPageScroll: function(e) { //监听页面滚动
  31. this.setData({
  32. scrollTop: e.scrollTop
  33. })
  34. },
  35. toProdPage: function(e) {
  36. var prodid = e.currentTarget.dataset.prodid;
  37. if (prodid) {
  38. wx.navigateTo({
  39. url: '/pages/prod/prod?prodid=' + prodid,
  40. })
  41. }
  42. },
  43. toCouponCenter: function() {
  44. wx.showToast({
  45. icon:"none",
  46. title: '该功能未开源'
  47. })
  48. },
  49. // 跳转搜索页
  50. toSearchPage: function() {
  51. wx.navigateTo({
  52. url: '/pages/search-page/search-page',
  53. })
  54. },
  55. //跳转商品活动页面
  56. toClassifyPage: function(e) {
  57. var url = '/pages/prod-classify/prod-classify?sts=' + e.currentTarget.dataset.sts;
  58. var id = e.currentTarget.dataset.id;
  59. var title = e.currentTarget.dataset.title;
  60. if (id) {
  61. url += "&tagid=" + id + "&title=" + title;
  62. }
  63. wx.navigateTo({
  64. url: url
  65. })
  66. },
  67. //跳转公告列表页面
  68. onNewsPage: function() {
  69. wx.navigateTo({
  70. url: '/pages/recent-news/recent-news',
  71. })
  72. },
  73. onShow: function() {
  74. wx.getSetting({
  75. success(res) {
  76. if (!res.authSetting['scope.userInfo']) {
  77. wx.navigateTo({
  78. url: '/pages/login/login',
  79. })
  80. }
  81. }
  82. })
  83. },
  84. getAllData() {
  85. http.getCartCount(); //重新计算购物车总数量
  86. this.getIndexImgs();
  87. this.getNoticeList();
  88. this.getTag();
  89. },
  90. //加载轮播图
  91. getIndexImgs() {
  92. //加载轮播图
  93. var params = {
  94. url: "/indexImgs",
  95. method: "GET",
  96. data: {},
  97. callBack: (res) => {
  98. this.setData({
  99. indexImgs: res,
  100. seq: res
  101. });
  102. }
  103. };
  104. http.request(params);
  105. },
  106. getNoticeList() {
  107. // 加载公告
  108. var params = {
  109. url: "/shop/notice/topNoticeList",
  110. method: "GET",
  111. data: {},
  112. callBack: (res) => {
  113. this.setData({
  114. news: res,
  115. });
  116. }
  117. };
  118. http.request(params);
  119. },
  120. // 加载商品标题分组列表
  121. getTag() {
  122. var params = {
  123. url: "/prod/tag/prodTagList",
  124. method: "GET",
  125. data: {},
  126. callBack: (res) => {
  127. this.setData({
  128. taglist: res,
  129. });
  130. for (var i = 0; i < res.length; i++) {
  131. this.getTagProd(res[i].id, i);
  132. }
  133. }
  134. };
  135. http.request(params);
  136. },
  137. getTagProd(id, index) {
  138. var param = {
  139. url: "/prod/prodListByTagId",
  140. method: "GET",
  141. data: {
  142. tagId: id,
  143. size: 6
  144. },
  145. callBack: (res) => {
  146. var taglist = this.data.taglist;
  147. taglist[index].prods = res.records
  148. this.setData({
  149. taglist: taglist,
  150. });
  151. }
  152. };
  153. http.request(param);
  154. },
  155. /**
  156. * 页面相关事件处理函数--监听用户下拉动作
  157. */
  158. // onPullDownRefresh: function () {
  159. // wx.request({
  160. // url: '',
  161. // data: {},
  162. // method: 'GET',
  163. // success: function (res) { },
  164. // fail: function (res) { },
  165. // complete: function (res) {
  166. // wx.stopPullDownRefresh();
  167. // }
  168. // })
  169. // },
  170. onPullDownRefresh: function() {
  171. // wx.showNavigationBarLoading() //在标题栏中显示加载
  172. //模拟加载
  173. var ths = this;
  174. setTimeout(function() {
  175. ths.getAllData();
  176. // wx.hideNavigationBarLoading() //完成停止加载
  177. wx.stopPullDownRefresh() //停止下拉刷新
  178. }, 100);
  179. },
  180. /**
  181. * 跳转至商品详情
  182. */
  183. showProdInfo: function(e) {
  184. let relation = e.currentTarget.dataset.relation;
  185. if (relation) {
  186. wx.navigateTo({
  187. url: 'pages/prod/prod',
  188. })
  189. }
  190. }
  191. })