shopPage.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. platform:1,
  104. isAllProdType: true
  105. },
  106. callBack: (res) => {
  107. wx.hideLoading()
  108. this.setData({
  109. shopProdList: res.records
  110. })
  111. }
  112. }
  113. http.request(params)
  114. },
  115. // 设置页面标题
  116. setNavTitle() {
  117. wx.setNavigationBarTitle({
  118. title: this.data.shopInfo.shopName
  119. })
  120. },
  121. /**
  122. * 生命周期函数--监听页面加载
  123. */
  124. onLoad: function(options) {
  125. wx.showLoading({
  126. title: '',
  127. mask: true,
  128. })
  129. if (options.shopId) {
  130. this.setData({
  131. shopId: options.shopId
  132. })
  133. wx.setStorageSync("currShopId", options.shopId);
  134. } else {
  135. this.setData({
  136. shopId: wx.getStorageSync("currShopId")
  137. })
  138. }
  139. this.getShopInfo()
  140. },
  141. /**
  142. * 跳转店铺详情
  143. */
  144. toShopInfo() {
  145. wx.navigateTo({
  146. url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopId,
  147. })
  148. },
  149. /**
  150. * 生命周期函数--监听页面初次渲染完成
  151. */
  152. onReady: function() {
  153. },
  154. /**
  155. * 生命周期函数--监听页面显示
  156. */
  157. onShow: function() {
  158. },
  159. /**
  160. * 生命周期函数--监听页面隐藏
  161. */
  162. onHide: function() {
  163. },
  164. /**
  165. * 生命周期函数--监听页面卸载
  166. */
  167. onUnload: function() {
  168. },
  169. /**
  170. * 页面相关事件处理函数--监听用户下拉动作
  171. */
  172. onPullDownRefresh: function() {
  173. },
  174. /**
  175. * 页面上拉触底事件的处理函数
  176. */
  177. onReachBottom: function() {
  178. },
  179. /**
  180. * 用户点击右上角分享
  181. */
  182. onShareAppMessage: function() {
  183. },
  184. // 页面滚动事件
  185. onPageScroll: function(e) {
  186. var _this = this
  187. if (e.scrollTop > 80) {
  188. _this.setData({
  189. topFlag: true
  190. })
  191. } else {
  192. _this.setData({
  193. topFlag: false
  194. })
  195. }
  196. }
  197. })