index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. toLimitedTimeOffer: function(e) {
  69. wx.showToast({
  70. icon:"none",
  71. title: '该功能未开源'
  72. })
  73. },
  74. //跳转公告列表页面
  75. onNewsPage: function() {
  76. wx.navigateTo({
  77. url: '/pages/recent-news/recent-news',
  78. })
  79. },
  80. onShow: function() {
  81. },
  82. getAllData() {
  83. http.getCartCount(); //重新计算购物车总数量
  84. this.getIndexImgs();
  85. this.getNoticeList();
  86. this.getTag();
  87. },
  88. //加载轮播图
  89. getIndexImgs() {
  90. //加载轮播图
  91. var params = {
  92. url: "/indexImgs",
  93. method: "GET",
  94. data: {},
  95. callBack: (res) => {
  96. this.setData({
  97. indexImgs: res,
  98. seq: res
  99. });
  100. }
  101. };
  102. http.request(params);
  103. },
  104. getNoticeList() {
  105. // 加载公告
  106. var params = {
  107. url: "/shop/notice/topNoticeList",
  108. method: "GET",
  109. data: {},
  110. callBack: (res) => {
  111. this.setData({
  112. news: res,
  113. });
  114. }
  115. };
  116. http.request(params);
  117. },
  118. /**
  119. * 加入购物车
  120. */
  121. addToCart(e) {
  122. const prodId = e.currentTarget.dataset.prodid
  123. const ths = this
  124. wx.showLoading();
  125. var params = {
  126. url: "/prod/prodInfo",
  127. method: "GET",
  128. data: {
  129. prodId
  130. },
  131. callBack: (res) => {
  132. var params = {
  133. url: "/p/shopCart/changeItem",
  134. method: "POST",
  135. data: {
  136. basketId: 0,
  137. count: 1,
  138. prodId: res.prodId,
  139. shopId: res.shopId,
  140. skuId: res.skuList[0].skuId
  141. },
  142. callBack: function(res) {
  143. ths.setData({
  144. totalCartNum: ths.data.totalCartNum + ths.data.prodNum
  145. });
  146. wx.hideLoading();
  147. http.getCartCount(); //重新计算购物车总数量
  148. wx.showToast({
  149. title: "加入购物车成功",
  150. icon: "none"
  151. })
  152. }
  153. };
  154. http.request(params);
  155. }
  156. };
  157. http.request(params);
  158. },
  159. // 加载商品标题分组列表
  160. getTag() {
  161. var params = {
  162. url: "/prod/tag/prodTagList",
  163. method: "GET",
  164. data: {},
  165. callBack: (res) => {
  166. this.setData({
  167. taglist: res,
  168. });
  169. for (var i = 0; i < res.length; i++) {
  170. this.getTagProd(res[i].id, i);
  171. }
  172. }
  173. };
  174. http.request(params);
  175. },
  176. getTagProd(id, index) {
  177. var param = {
  178. url: "/prod/prodListByTagId",
  179. method: "GET",
  180. data: {
  181. tagId: id,
  182. size: 6
  183. },
  184. callBack: (res) => {
  185. var taglist = this.data.taglist;
  186. taglist[index].prods = res.records
  187. this.setData({
  188. taglist: taglist,
  189. });
  190. }
  191. };
  192. http.request(param);
  193. },
  194. /**
  195. * 页面相关事件处理函数--监听用户下拉动作
  196. */
  197. // onPullDownRefresh: function () {
  198. // wx.request({
  199. // url: '',
  200. // data: {},
  201. // method: 'GET',
  202. // success: function (res) { },
  203. // fail: function (res) { },
  204. // complete: function (res) {
  205. // wx.stopPullDownRefresh();
  206. // }
  207. // })
  208. // },
  209. onPullDownRefresh: function() {
  210. // wx.showNavigationBarLoading() //在标题栏中显示加载
  211. //模拟加载
  212. var ths = this;
  213. setTimeout(function() {
  214. ths.getAllData();
  215. // wx.hideNavigationBarLoading() //完成停止加载
  216. wx.stopPullDownRefresh() //停止下拉刷新
  217. }, 100);
  218. },
  219. /**
  220. * 跳转至商品详情
  221. */
  222. showProdInfo: function(e) {
  223. let relation = e.currentTarget.dataset.relation;
  224. if (relation) {
  225. wx.navigateTo({
  226. url: 'pages/prod/prod',
  227. })
  228. }
  229. }
  230. })