shopPage.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // pages/shopPage/shopPage.js
  2. var http = require('../../utils/http.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. shopId: 0,
  9. shopInfo: {},
  10. indicatorDots: true,
  11. indicatorColor: '#d1e5fb',
  12. indicatorActiveColor: '#1b7dec',
  13. autoplay: true,
  14. interval: 2000,
  15. duration: 1000,
  16. indexImgs: [],
  17. topFlag: false,
  18. isCollection: false,
  19. shopProdList: [],
  20. },
  21. //加载轮播图
  22. getIndexImgs() {
  23. var shopId = this.data.shopId
  24. //加载轮播图
  25. var params = {
  26. url: `/indexImgs/${shopId}`,
  27. method: "GET",
  28. data: {},
  29. callBack: (res) => {
  30. this.setData({
  31. indexImgs: res,
  32. // seq: res
  33. });
  34. wx.hideLoading();
  35. }
  36. };
  37. http.request(params);
  38. },
  39. // 跳转店铺详情页
  40. toShopInfo(e) {
  41. const shopId = e.currentTarget.dataset.shopid
  42. wx.navigateTo({
  43. url: '/pages/shopInfo/shopInfo?shopId=' + shopId,
  44. })
  45. },
  46. // 跳转店内搜索页
  47. toShopSearchPage: function(e) {
  48. wx.navigateTo({
  49. url: '/pages/shopSearch/shopSearch?shopId=' + e.currentTarget.dataset.shopid,
  50. })
  51. },
  52. // 跳转所有商品页
  53. toShopProds(e) {
  54. wx.navigateTo({
  55. url: '/pages/shopProds/shopProds?shopId=' + e.currentTarget.dataset.shopid,
  56. })
  57. },
  58. // 收藏/取消收藏
  59. addOrCannelCollection() {
  60. this.setData({
  61. isCollection: !this.data.isCollection
  62. })
  63. },
  64. // 跳转商品详情页
  65. toProdPage: function(e) {
  66. var prodid = e.currentTarget.dataset.prodid;
  67. if (prodid) {
  68. wx.navigateTo({
  69. url: '/pages/prod/prod?prodid=' + prodid,
  70. })
  71. }
  72. },
  73. // 获取店铺信息
  74. getShopInfo: function() {
  75. var ths = this;
  76. //热门搜索
  77. var params = {
  78. url: "/shop/headInfo",
  79. method: "GET",
  80. data: {
  81. shopId: ths.data.shopId
  82. },
  83. callBack: function(res) {
  84. wx.hideLoading()
  85. ths.setData({
  86. shopInfo: res,
  87. })
  88. wx.setStorageSync("shopInfo", res)
  89. ths.setNavTitle()
  90. ths.getIndexImgs()
  91. ths.getShopProds()
  92. },
  93. };
  94. http.request(params);
  95. },
  96. // 获取店铺商品
  97. getShopProds() {
  98. var params = {
  99. url: '/search/searchProdPage',
  100. method: 'GET',
  101. data: {
  102. shopId: this.data.shopId,
  103. isAllProdType: true
  104. },
  105. callBack: (res) => {
  106. wx.hideLoading()
  107. this.setData({
  108. shopProdList: res.records
  109. })
  110. }
  111. }
  112. http.request(params)
  113. },
  114. // 设置页面标题
  115. setNavTitle() {
  116. wx.setNavigationBarTitle({
  117. title: this.data.shopInfo.shopName
  118. })
  119. },
  120. /**
  121. * 生命周期函数--监听页面加载
  122. */
  123. onLoad: function(options) {
  124. wx.showLoading({
  125. title: '',
  126. mask: true,
  127. })
  128. if (options.shopId) {
  129. this.setData({
  130. shopId: options.shopId
  131. })
  132. wx.setStorageSync("currShopId", options.shopId);
  133. } else {
  134. this.setData({
  135. shopId: wx.getStorageSync("currShopId")
  136. })
  137. }
  138. this.getShopInfo()
  139. },
  140. /**
  141. * 跳转店铺详情
  142. */
  143. toShopInfo() {
  144. wx.navigateTo({
  145. url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopId,
  146. })
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function() {
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function() {
  157. },
  158. /**
  159. * 生命周期函数--监听页面隐藏
  160. */
  161. onHide: function() {
  162. },
  163. /**
  164. * 生命周期函数--监听页面卸载
  165. */
  166. onUnload: function() {
  167. },
  168. /**
  169. * 页面相关事件处理函数--监听用户下拉动作
  170. */
  171. onPullDownRefresh: function() {
  172. },
  173. /**
  174. * 页面上拉触底事件的处理函数
  175. */
  176. onReachBottom: function() {
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage: function() {
  182. },
  183. // 页面滚动事件
  184. onPageScroll: function(e) {
  185. var _this = this
  186. if (e.scrollTop > 80) {
  187. _this.setData({
  188. topFlag: true
  189. })
  190. } else {
  191. _this.setData({
  192. topFlag: false
  193. })
  194. }
  195. }
  196. })